1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-24 16:46:13 +01:00

Compare commits

..

1 Commits

Author SHA1 Message Date
Travis Farmer
4edde2d2f5
Merge 832ec44c67 into d46a6f092a 2023-11-07 11:37:54 +00:00
3 changed files with 15 additions and 45 deletions

View File

@ -45,8 +45,8 @@ INTERRUPT_CALLBACK interruptHandler=0;
//HardwareTimer* timer = NULL; //HardwareTimer* timer = NULL;
//HardwareTimer* timerAux = NULL; //HardwareTimer* timerAux = NULL;
HardwareTimer timer(TIM3); HardwareTimer timer(TIM2);
HardwareTimer timerAux(TIM2); HardwareTimer timerAux(TIM3);
static bool tim2ModeHA = false; static bool tim2ModeHA = false;
static bool tim3ModeHA = false; static bool tim3ModeHA = false;
@ -97,9 +97,9 @@ void DCCTimer::setPWM(byte pin, bool high) {
tim3ModeHA = true; tim3ModeHA = true;
} }
if (high) 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 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; break;
case 13: case 13:
if (!tim2ModeHA) { if (!tim2ModeHA) {
@ -107,9 +107,9 @@ void DCCTimer::setPWM(byte pin, bool high) {
tim2ModeHA = true; tim2ModeHA = true;
} }
if (high) 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 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; break;
} }
} }

View File

@ -35,21 +35,12 @@ unsigned long MotorDriver::globalOverloadStart = 0;
volatile portreg_t shadowPORTA; volatile portreg_t shadowPORTA;
volatile portreg_t shadowPORTB; volatile portreg_t shadowPORTB;
volatile portreg_t shadowPORTC; 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 shadowPORTD;
volatile portreg_t shadowPORTE; volatile portreg_t shadowPORTE;
volatile portreg_t shadowPORTF; volatile portreg_t shadowPORTF;
#endif #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, 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) { byte current_pin, float sense_factor, unsigned int trip_milliamps, int16_t fault_pin) {
const FSH * warnString = F("** WARNING **"); 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); getFastPin(F("SIG"),signalPin,fastSignalPin);
pinMode(signalPin, OUTPUT); pinMode(signalPin, OUTPUT);
#if !defined(ARDUINO_GIGA) || (defined(ARDUINO_GIGA) && defined(XGIGA)) // no giga #ifndef ARDUINO_GIGA // no giga
fastSignalPin.shadowinout = NULL; fastSignalPin.shadowinout = NULL;
if (HAVE_PORTA(fastSignalPin.inout == &PORTA)) { if (HAVE_PORTA(fastSignalPin.inout == &PORTA)) {
DIAG(F("Found PORTA pin %d"),signalPin); 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); getFastPin(F("SIG2"),signalPin2,fastSignalPin2);
pinMode(signalPin2, OUTPUT); pinMode(signalPin2, OUTPUT);
#if !defined(ARDUINO_GIGA) || (defined(ARDUINO_GIGA) && defined(XGIGA)) // no giga #ifndef ARDUINO_GIGA // no giga
fastSignalPin2.shadowinout = NULL; fastSignalPin2.shadowinout = NULL;
if (HAVE_PORTA(fastSignalPin2.inout == &PORTA)) { if (HAVE_PORTA(fastSignalPin2.inout == &PORTA)) {
DIAG(F("Found PORTA pin %d"),signalPin2); 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) { void MotorDriver::getFastPin(const FSH* type,int pin, bool input, FASTPIN & result) {
// DIAG(F("MotorDriver %S Pin=%d,"),type,pin); // 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)type;
(void)input; // no warnings please (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); PortGroup *port = digitalPinToPort(pin);
#elif defined(ARDUINO_ARCH_STM32) #elif defined(ARDUINO_ARCH_STM32)
GPIO_TypeDef *port = digitalPinToPort(pin); GPIO_TypeDef *port = digitalPinToPort(pin);
#elif defined(ARDUINO_GIGA)
auto * port = ((GPIO_TypeDef *)(GPIOA_BASE + (GPIOB_BASE - GPIOA_BASE) * (digitalPinToPinName(pin) >> 4)));
#else #else
uint8_t port = digitalPinToPort(pin); uint8_t port = digitalPinToPort(pin);
#endif #endif

View File

@ -31,7 +31,7 @@
// use powers of two so we can do logical and/or on the track modes in if clauses. // 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, 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}; 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 setHIGH(fastpin) digitalWrite(fastpin,1)
#define setLOW(fastpin) digitalWrite(fastpin,0) #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 setHIGH(fastpin) *fastpin.inout |= fastpin.maskHIGH
#define setLOW(fastpin) *fastpin.inout &= fastpin.maskLOW #define setLOW(fastpin) *fastpin.inout &= fastpin.maskLOW
#endif // giga #endif // giga
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // yes giga #if defined(ARDUINO_GIGA) // yes giga
#define isHIGH(fastpin) ((PinStatus)digitalRead(fastpin)==1) #define isHIGH(fastpin) ((PinStatus)digitalRead(fastpin)==1)
#define isLOW(fastpin) ((PinStatus)digitalRead(fastpin)==0) #define isLOW(fastpin) ((PinStatus)digitalRead(fastpin)==0)
#else // no giga #else // no giga
@ -82,25 +82,6 @@ enum TRACK_MODE : byte {TRACK_MODE_NONE = 1, TRACK_MODE_MAIN = 2, TRACK_MODE_PRO
#endif #endif
#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 // if macros not defined as pass-through we define
// them here as someting that is valid as a // them here as someting that is valid as a
// statement and evaluates to false. // statement and evaluates to false.
@ -140,13 +121,13 @@ public:
byte invpin = UNUSED_PIN; 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; typedef uint32_t portreg_t;
#else #else
typedef uint8_t portreg_t; typedef uint8_t portreg_t;
#endif #endif
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // yes giga #if defined(ARDUINO_GIGA) // yes giga
typedef int FASTPIN; typedef int FASTPIN;
@ -184,7 +165,7 @@ class MotorDriver {
// otherwise the call from interrupt context can undo whatever we do // otherwise the call from interrupt context can undo whatever we do
// from outside interrupt // from outside interrupt
void setBrake( bool on, bool interruptContext=false); 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) { __attribute__((always_inline)) inline void setSignal( bool high) {
digitalWrite(signalPin, high); digitalWrite(signalPin, high);
if (dualSignal) digitalWrite(signalPin2, !high); if (dualSignal) digitalWrite(signalPin2, !high);