mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-24 08:36:14 +01:00
Compare commits
1 Commits
b1be657e44
...
4edde2d2f5
Author | SHA1 | Date | |
---|---|---|---|
|
4edde2d2f5 |
|
@ -45,8 +45,8 @@ INTERRUPT_CALLBACK interruptHandler=0;
|
|||
|
||||
//HardwareTimer* timer = NULL;
|
||||
//HardwareTimer* timerAux = NULL;
|
||||
HardwareTimer timer(TIM3);
|
||||
HardwareTimer timerAux(TIM2);
|
||||
HardwareTimer timer(TIM2);
|
||||
HardwareTimer timerAux(TIM3);
|
||||
|
||||
static bool tim2ModeHA = false;
|
||||
static bool tim3ModeHA = false;
|
||||
|
@ -97,9 +97,9 @@ void DCCTimer::setPWM(byte pin, bool high) {
|
|||
tim3ModeHA = true;
|
||||
}
|
||||
if (high)
|
||||
TIM3->CCMR1 = (TIM3->CCMR1 & ~TIM_CCMR1_OC1M_Msk) | TIM_CCMR1_OC1M_0;
|
||||
TIM2->CCMR1 = (TIM2->CCMR1 & ~TIM_CCMR1_OC1M_Msk) | TIM_CCMR1_OC1M_0;
|
||||
else
|
||||
TIM3->CCMR1 = (TIM3->CCMR1 & ~TIM_CCMR1_OC1M_Msk) | TIM_CCMR1_OC1M_1;
|
||||
TIM2->CCMR1 = (TIM2->CCMR1 & ~TIM_CCMR1_OC1M_Msk) | TIM_CCMR1_OC1M_1;
|
||||
break;
|
||||
case 13:
|
||||
if (!tim2ModeHA) {
|
||||
|
@ -107,9 +107,9 @@ void DCCTimer::setPWM(byte pin, bool high) {
|
|||
tim2ModeHA = true;
|
||||
}
|
||||
if (high)
|
||||
TIM2->CCMR1 = (TIM2->CCMR1 & ~TIM_CCMR1_OC1M_Msk) | TIM_CCMR1_OC1M_0;
|
||||
TIM3->CCMR1 = (TIM3->CCMR1 & ~TIM_CCMR1_OC1M_Msk) | TIM_CCMR1_OC1M_0;
|
||||
else
|
||||
TIM2->CCMR1 = (TIM2->CCMR1 & ~TIM_CCMR1_OC1M_Msk) | TIM_CCMR1_OC1M_1;
|
||||
TIM3->CCMR1 = (TIM3->CCMR1 & ~TIM_CCMR1_OC1M_Msk) | TIM_CCMR1_OC1M_1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,21 +35,12 @@ unsigned long MotorDriver::globalOverloadStart = 0;
|
|||
volatile portreg_t shadowPORTA;
|
||||
volatile portreg_t shadowPORTB;
|
||||
volatile portreg_t shadowPORTC;
|
||||
#if defined(ARDUINO_ARCH_STM32) || (defined(ARDUINO_GIGA) && defined(XGIGA))
|
||||
#if defined(ARDUINO_ARCH_STM32)
|
||||
volatile portreg_t shadowPORTD;
|
||||
volatile portreg_t shadowPORTE;
|
||||
volatile portreg_t shadowPORTF;
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_GIGA) && defined(XGIGA)
|
||||
#define STM_PORT(X) (((uint32_t)(X) >> 4) & 0xF)
|
||||
#define STM_PIN(X) ((uint32_t)(X) & 0xF)
|
||||
#define STM_GPIO_PIN(X) ((uint16_t)(1<<STM_PIN(X)))
|
||||
#define digitalPinToBitMask(p) (STM_GPIO_PIN(digitalPinToPinName(p)))
|
||||
#define portOutputRegister(P) (&(P->ODR))
|
||||
#define portInputRegister(P) (&(P->IDR))
|
||||
#endif
|
||||
|
||||
MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, int16_t brake_pin,
|
||||
byte current_pin, float sense_factor, unsigned int trip_milliamps, int16_t fault_pin) {
|
||||
const FSH * warnString = F("** WARNING **");
|
||||
|
@ -67,7 +58,7 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i
|
|||
getFastPin(F("SIG"),signalPin,fastSignalPin);
|
||||
pinMode(signalPin, OUTPUT);
|
||||
|
||||
#if !defined(ARDUINO_GIGA) || (defined(ARDUINO_GIGA) && defined(XGIGA)) // no giga
|
||||
#ifndef ARDUINO_GIGA // no giga
|
||||
fastSignalPin.shadowinout = NULL;
|
||||
if (HAVE_PORTA(fastSignalPin.inout == &PORTA)) {
|
||||
DIAG(F("Found PORTA pin %d"),signalPin);
|
||||
|
@ -106,7 +97,7 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i
|
|||
getFastPin(F("SIG2"),signalPin2,fastSignalPin2);
|
||||
pinMode(signalPin2, OUTPUT);
|
||||
|
||||
#if !defined(ARDUINO_GIGA) || (defined(ARDUINO_GIGA) && defined(XGIGA)) // no giga
|
||||
#ifndef ARDUINO_GIGA // no giga
|
||||
fastSignalPin2.shadowinout = NULL;
|
||||
if (HAVE_PORTA(fastSignalPin2.inout == &PORTA)) {
|
||||
DIAG(F("Found PORTA pin %d"),signalPin2);
|
||||
|
@ -517,7 +508,7 @@ unsigned int MotorDriver::mA2raw( unsigned int mA) {
|
|||
|
||||
void MotorDriver::getFastPin(const FSH* type,int pin, bool input, FASTPIN & result) {
|
||||
// DIAG(F("MotorDriver %S Pin=%d,"),type,pin);
|
||||
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // yes giga
|
||||
#if defined(ARDUINO_GIGA) // yes giga
|
||||
(void)type;
|
||||
(void)input; // no warnings please
|
||||
|
||||
|
@ -529,8 +520,6 @@ void MotorDriver::getFastPin(const FSH* type,int pin, bool input, FASTPIN & res
|
|||
PortGroup *port = digitalPinToPort(pin);
|
||||
#elif defined(ARDUINO_ARCH_STM32)
|
||||
GPIO_TypeDef *port = digitalPinToPort(pin);
|
||||
#elif defined(ARDUINO_GIGA)
|
||||
auto * port = ((GPIO_TypeDef *)(GPIOA_BASE + (GPIOB_BASE - GPIOA_BASE) * (digitalPinToPinName(pin) >> 4)));
|
||||
#else
|
||||
uint8_t port = digitalPinToPort(pin);
|
||||
#endif
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
// use powers of two so we can do logical and/or on the track modes in if clauses.
|
||||
enum TRACK_MODE : byte {TRACK_MODE_NONE = 1, TRACK_MODE_MAIN = 2, TRACK_MODE_PROG = 4,
|
||||
TRACK_MODE_DC = 8, TRACK_MODE_DCX = 16, TRACK_MODE_EXT = 32};
|
||||
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // yes giga
|
||||
#if defined(ARDUINO_GIGA) // yes giga
|
||||
|
||||
#define setHIGH(fastpin) digitalWrite(fastpin,1)
|
||||
#define setLOW(fastpin) digitalWrite(fastpin,0)
|
||||
|
@ -39,7 +39,7 @@ enum TRACK_MODE : byte {TRACK_MODE_NONE = 1, TRACK_MODE_MAIN = 2, TRACK_MODE_PRO
|
|||
#define setHIGH(fastpin) *fastpin.inout |= fastpin.maskHIGH
|
||||
#define setLOW(fastpin) *fastpin.inout &= fastpin.maskLOW
|
||||
#endif // giga
|
||||
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // yes giga
|
||||
#if defined(ARDUINO_GIGA) // yes giga
|
||||
#define isHIGH(fastpin) ((PinStatus)digitalRead(fastpin)==1)
|
||||
#define isLOW(fastpin) ((PinStatus)digitalRead(fastpin)==0)
|
||||
#else // no giga
|
||||
|
@ -82,25 +82,6 @@ enum TRACK_MODE : byte {TRACK_MODE_NONE = 1, TRACK_MODE_MAIN = 2, TRACK_MODE_PRO
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_GIGA) && defined(XGIGA)
|
||||
#define PORTA GPIOA->ODR
|
||||
#define HAVE_PORTA(X) X
|
||||
#define PORTB GPIOB->ODR
|
||||
#define HAVE_PORTB(X) X
|
||||
#define PORTC GPIOC->ODR
|
||||
#define HAVE_PORTC(X) X
|
||||
#define PORTD GPIOD->ODR
|
||||
#define HAVE_PORTD(X) X
|
||||
#if defined(GPIOE)
|
||||
#define PORTE GPIOE->ODR
|
||||
#define HAVE_PORTE(X) X
|
||||
#endif
|
||||
#if defined(GPIOF)
|
||||
#define PORTF GPIOF->ODR
|
||||
#define HAVE_PORTF(X) X
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// if macros not defined as pass-through we define
|
||||
// them here as someting that is valid as a
|
||||
// statement and evaluates to false.
|
||||
|
@ -140,13 +121,13 @@ public:
|
|||
byte invpin = UNUSED_PIN;
|
||||
};
|
||||
|
||||
#if defined(__IMXRT1062__) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32) || (defined(ARDUINO_GIGA) && defined(XGIGA))
|
||||
#if defined(__IMXRT1062__) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32)
|
||||
typedef uint32_t portreg_t;
|
||||
#else
|
||||
typedef uint8_t portreg_t;
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // yes giga
|
||||
#if defined(ARDUINO_GIGA) // yes giga
|
||||
typedef int FASTPIN;
|
||||
|
||||
|
||||
|
@ -184,7 +165,7 @@ class MotorDriver {
|
|||
// otherwise the call from interrupt context can undo whatever we do
|
||||
// from outside interrupt
|
||||
void setBrake( bool on, bool interruptContext=false);
|
||||
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // yes giga
|
||||
#if defined(ARDUINO_GIGA) // yes giga
|
||||
__attribute__((always_inline)) inline void setSignal( bool high) {
|
||||
digitalWrite(signalPin, high);
|
||||
if (dualSignal) digitalWrite(signalPin2, !high);
|
||||
|
|
Loading…
Reference in New Issue
Block a user