1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-24 08:36:14 +01:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Travis Farmer
b1be657e44
Merge 8223d30892 into d46a6f092a 2023-11-07 19:31:20 +00:00
travis-farmer
8223d30892
added XGIGA config for giga experimental 2023-11-07 14:30:52 -05:00
travis-farmer
6b731d6f5d
fixed timers, still only two tracks 2023-11-07 13:12:33 -05:00
3 changed files with 45 additions and 15 deletions

View File

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

View File

@ -35,12 +35,21 @@ unsigned long MotorDriver::globalOverloadStart = 0;
volatile portreg_t shadowPORTA;
volatile portreg_t shadowPORTB;
volatile portreg_t shadowPORTC;
#if defined(ARDUINO_ARCH_STM32)
#if defined(ARDUINO_ARCH_STM32) || (defined(ARDUINO_GIGA) && defined(XGIGA))
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 **");
@ -58,7 +67,7 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i
getFastPin(F("SIG"),signalPin,fastSignalPin);
pinMode(signalPin, OUTPUT);
#ifndef ARDUINO_GIGA // no giga
#if !defined(ARDUINO_GIGA) || (defined(ARDUINO_GIGA) && defined(XGIGA)) // no giga
fastSignalPin.shadowinout = NULL;
if (HAVE_PORTA(fastSignalPin.inout == &PORTA)) {
DIAG(F("Found PORTA pin %d"),signalPin);
@ -97,7 +106,7 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i
getFastPin(F("SIG2"),signalPin2,fastSignalPin2);
pinMode(signalPin2, OUTPUT);
#ifndef ARDUINO_GIGA // no giga
#if !defined(ARDUINO_GIGA) || (defined(ARDUINO_GIGA) && defined(XGIGA)) // no giga
fastSignalPin2.shadowinout = NULL;
if (HAVE_PORTA(fastSignalPin2.inout == &PORTA)) {
DIAG(F("Found PORTA pin %d"),signalPin2);
@ -508,7 +517,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) // yes giga
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // yes giga
(void)type;
(void)input; // no warnings please
@ -520,6 +529,8 @@ 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

View File

@ -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) // yes giga
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // 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) // yes giga
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // yes giga
#define isHIGH(fastpin) ((PinStatus)digitalRead(fastpin)==1)
#define isLOW(fastpin) ((PinStatus)digitalRead(fastpin)==0)
#else // no giga
@ -82,6 +82,25 @@ 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.
@ -121,13 +140,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)
#if defined(__IMXRT1062__) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32) || (defined(ARDUINO_GIGA) && defined(XGIGA))
typedef uint32_t portreg_t;
#else
typedef uint8_t portreg_t;
#endif
#if defined(ARDUINO_GIGA) // yes giga
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // yes giga
typedef int FASTPIN;
@ -165,7 +184,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) // yes giga
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // yes giga
__attribute__((always_inline)) inline void setSignal( bool high) {
digitalWrite(signalPin, high);
if (dualSignal) digitalWrite(signalPin2, !high);