mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-02-18 23:16:03 +01:00
added XGIGA config for giga experimental
This commit is contained in:
parent
6b731d6f5d
commit
8223d30892
@ -35,12 +35,21 @@ 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)
|
#if defined(ARDUINO_ARCH_STM32) || (defined(ARDUINO_GIGA) && defined(XGIGA))
|
||||||
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 **");
|
||||||
@ -58,7 +67,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);
|
||||||
|
|
||||||
#ifndef ARDUINO_GIGA // no giga
|
#if !defined(ARDUINO_GIGA) || (defined(ARDUINO_GIGA) && defined(XGIGA)) // 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);
|
||||||
@ -97,7 +106,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);
|
||||||
|
|
||||||
#ifndef ARDUINO_GIGA // no giga
|
#if !defined(ARDUINO_GIGA) || (defined(ARDUINO_GIGA) && defined(XGIGA)) // 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);
|
||||||
@ -508,7 +517,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) // yes giga
|
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // yes giga
|
||||||
(void)type;
|
(void)type;
|
||||||
(void)input; // no warnings please
|
(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);
|
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
|
||||||
|
@ -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) // yes giga
|
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // 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) // yes giga
|
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // 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,6 +82,25 @@ 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.
|
||||||
@ -121,13 +140,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)
|
#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;
|
typedef uint32_t portreg_t;
|
||||||
#else
|
#else
|
||||||
typedef uint8_t portreg_t;
|
typedef uint8_t portreg_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ARDUINO_GIGA) // yes giga
|
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // yes giga
|
||||||
typedef int FASTPIN;
|
typedef int FASTPIN;
|
||||||
|
|
||||||
|
|
||||||
@ -165,7 +184,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) // yes giga
|
#if defined(ARDUINO_GIGA) && !defined(XGIGA) // 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);
|
||||||
|
Loading…
Reference in New Issue
Block a user