From 72599244663897aabcf8e02f1235177b51850a0d Mon Sep 17 00:00:00 2001 From: travis-farmer Date: Sat, 21 Oct 2023 04:10:50 -0400 Subject: [PATCH] It Compiles! --- DCCTimerGiga.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++---- MotorDriver.cpp | 2 ++ MotorDriver.h | 17 +++++++------ defines.h | 12 ++++------ 4 files changed, 72 insertions(+), 21 deletions(-) diff --git a/DCCTimerGiga.cpp b/DCCTimerGiga.cpp index 59bb4f7..6c38d45 100644 --- a/DCCTimerGiga.cpp +++ b/DCCTimerGiga.cpp @@ -28,12 +28,10 @@ // ATTENTION: this file only compiles on a STM32 based boards // Please refer to DCCTimer.h for general comments about how this class works // This is to avoid repetition and duplication. -#ifdef ARDUINO_GIGA +#if defined(ARDUINO_GIGA) #include "DCCTimer.h" -#ifdef DEBUG_ADC -#include "TrackManager.h" -#endif + #include "DIAG.h" /////////////////////////////////////////////////////////////////////////////////////////////// @@ -196,6 +194,62 @@ void DCCTimer::reset() { WDT.CTRLA=0x4; while(true){} }*/ +INTERRUPT_CALLBACK interruptHandler=0; + + +void DCCTimer::begin(INTERRUPT_CALLBACK callback) { + interruptHandler=callback; + noInterrupts(); + interrupts(); +} + +bool DCCTimer::isPWMPin(byte pin) { + (void) pin; + return false; // TODO what are the relevant pins? +} + +void DCCTimer::setPWM(byte pin, bool high) { + (void) pin; + (void) high; + // TODO what are the relevant pins? + } + +void DCCTimer::clearPWM() { + // Do nothing unless we implent HA +} + +void DCCTimer::getSimulatedMacAddress(byte mac[6]) { + volatile uint32_t *serno1 = (volatile uint32_t *)0x1FFF7A10; + volatile uint32_t *serno2 = (volatile uint32_t *)0x1FFF7A14; + // volatile uint32_t *serno3 = (volatile uint32_t *)0x1FFF7A18; + + volatile uint32_t m1 = *serno1; + volatile uint32_t m2 = *serno2; + mac[0] = m1 >> 8; + mac[1] = m1 >> 0; + mac[2] = m2 >> 24; + mac[3] = m2 >> 16; + mac[4] = m2 >> 8; + mac[5] = m2 >> 0; +} +volatile int DCCTimer::minimum_free_memory=__INT_MAX__; + +// Return low memory value... +int DCCTimer::getMinimumFreeMemory() { + noInterrupts(); // Disable interrupts to get volatile value + int retval = freeMemory(); + interrupts(); + return retval; +} + +int DCCTimer::freeMemory() { + char top; + return (int)(1024); +} + +void DCCTimer::reset() { + // do nothing for now +} int16_t ADCee::ADCmax() { diff --git a/MotorDriver.cpp b/MotorDriver.cpp index 20e146c..2618f8c 100644 --- a/MotorDriver.cpp +++ b/MotorDriver.cpp @@ -510,7 +510,9 @@ void MotorDriver::getFastPin(const FSH* type,int pin, bool input, FASTPIN & res #if defined(ARDUINO_GIGA) (void)type; (void)input; // no warnings please + result = pin; + #else (void) type; // avoid compiler warning if diag not used above. #if defined(ARDUINO_ARCH_SAMD) diff --git a/MotorDriver.h b/MotorDriver.h index 07e7895..1f50887 100644 --- a/MotorDriver.h +++ b/MotorDriver.h @@ -30,18 +30,17 @@ // 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}; -#ifdef ARDUINO_GIGA -//#include -//extern gpio_t digitalPinToGpio(int P); -#define setHIGH(fastpin) digitalWrite(fastpin, 1) -#define setLOW(fastpin) digitalWrite(fastpin, 0) +#if defined(ARDUINO_GIGA) + +#define setHIGH(fastpin) digitalWrite(fastpin,1) +#define setLOW(fastpin) digitalWrite(fastpin,0) #else #define setHIGH(fastpin) *fastpin.inout |= fastpin.maskHIGH #define setLOW(fastpin) *fastpin.inout &= fastpin.maskLOW #endif -#if defined(ARDUINO_GIGA) -#define isHIGH(fastpin) (digitalRead(fastpin)==1) -#define isLOW(fastpin) (digitalRead(fastpin)==0) +#if defined(ARDUINO_GIGA) +#define isHIGH(fastpin) ((PinStatus)digitalRead(fastpin)==1) +#define isLOW(fastpin) ((PinStatus)digitalRead(fastpin)==0) #else #define isHIGH(fastpin) (*fastpin.inout & fastpin.maskHIGH) #define isLOW(fastpin) (!isHIGH(fastpin)) @@ -128,7 +127,7 @@ typedef uint8_t portreg_t; #endif #if defined(ARDUINO_GIGA) -typedef pin_size_t FASTPIN; +typedef int FASTPIN; #else diff --git a/defines.h b/defines.h index 3a71dc0..72430c5 100644 --- a/defines.h +++ b/defines.h @@ -148,17 +148,13 @@ // #define I2C_USE_WIRE // #endif #elif defined(ARDUINO_ARCH_MBED_GIGA) - #define ARDUINO_TYPE "ARDUINO_GIGA" + #define ARDUINO_TYPE "Giga" #ifndef DISABLE_EEPROM #define DISABLE_EEPROM #endif - //#ifndef ENABLE_ETHERNET - //#define ENABLE_ETHERNET - //#endif - // STM32 support for native I2C is awaiting development - // #ifndef I2C_USE_WIRE - // #define I2C_USE_WIRE - // #endif + #if !defined(I2C_USE_WIRE) + #define I2C_USE_WIRE + #endif #define SDA I2C_SDA #define SCL I2C_SCL