From 5b4a1dd6faa1645622867edc691044f49feb1b77 Mon Sep 17 00:00:00 2001 From: travis-farmer Date: Thu, 19 Oct 2023 16:23:36 -0400 Subject: [PATCH] Keeping up to date --- MotorDriver.cpp | 7 +++++++ MotorDriver.h | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/MotorDriver.cpp b/MotorDriver.cpp index 61e229f..43f5e74 100644 --- a/MotorDriver.cpp +++ b/MotorDriver.cpp @@ -501,9 +501,15 @@ unsigned int MotorDriver::mA2raw( unsigned int mA) { return (int32_t)mA * senseScale / senseFactorInternal; } + void MotorDriver::getFastPin(const FSH* type,int pin, bool input, FASTPIN & result) { // DIAG(F("MotorDriver %S Pin=%d,"),type,pin); (void) type; // avoid compiler warning if diag not used above. +#if defined(ARDUINO_GIGA) + (void)type; + (void)input; // no warnings please + *result = digitalPinToGpio(pin); +#else #if defined(ARDUINO_ARCH_SAMD) PortGroup *port = digitalPinToPort(pin); #elif defined(ARDUINO_ARCH_STM32) @@ -517,6 +523,7 @@ void MotorDriver::getFastPin(const FSH* type,int pin, bool input, FASTPIN & res result.inout = portOutputRegister(port); result.maskHIGH = digitalPinToBitMask(pin); result.maskLOW = ~result.maskHIGH; +#endif // DIAG(F(" port=0x%x, inoutpin=0x%x, isinput=%d, mask=0x%x"),port, result.inout,input,result.maskHIGH); } diff --git a/MotorDriver.h b/MotorDriver.h index 18552a9..80caf1b 100644 --- a/MotorDriver.h +++ b/MotorDriver.h @@ -30,9 +30,14 @@ // 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) +#define setHIGH(fastpin) gpio_write(&fastpin, 1) +#define setLOW(fastpin) gpio_write(&fastpin, 0) +#else #define setHIGH(fastpin) *fastpin.inout |= fastpin.maskHIGH #define setLOW(fastpin) *fastpin.inout &= fastpin.maskLOW +#endif #define isHIGH(fastpin) (*fastpin.inout & fastpin.maskHIGH) #define isLOW(fastpin) (!isHIGH(fastpin)) @@ -117,12 +122,17 @@ typedef uint32_t portreg_t; typedef uint8_t portreg_t; #endif +#if defined(ARDUINO_GIGA) +typedef gpio_t FASTPIN; +#else struct FASTPIN { volatile portreg_t *inout; portreg_t maskHIGH; portreg_t maskLOW; volatile portreg_t *shadowinout; }; +#endif + // The port registers that are shadowing // the real port registers. These are // defined in Motordriver.cpp