From 14dc56936637b28e36534b4ccca7c352332699ce Mon Sep 17 00:00:00 2001 From: Asbelos Date: Wed, 6 Jul 2022 17:05:34 +0100 Subject: [PATCH] Moved CPU type detection to defines.h And fixed up BIG_RAM/HAS_ENOUGH_RAM issues. --- CommandDistributor.cpp | 4 ++-- CommandStation-EX.ino | 5 +++++ DCCTimer.h | 38 --------------------------------- defines.h | 48 ++++++++++++++++++++++++++++++++++++------ 4 files changed, 49 insertions(+), 46 deletions(-) diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index 9c3dba4..1d558c7 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -31,14 +31,14 @@ #include "TrackManager.h" -#ifdef BIG_RAM +#if WIFI_ON || ETHERNET_ON || defined(SERIAL1_COMMANDS) || defined(SERIAL2_COMMANDS) || defined(SERIAL3_COMMANDS) // use a buffer to allow broadcast #define BUFFER broadcastBufferWriter #define FLUSH broadcastBufferWriter->flush(); #define SHOVE(type) broadcastToClients(type); StringBuffer * CommandDistributor::broadcastBufferWriter=new StringBuffer(); #else - // on a UNO/NANO write direct to Serial and ignore flush/shove + // on a single USB connection config, write direct to Serial and ignore flush/shove #define BUFFER &Serial #define FLUSH #define SHOVE(type) diff --git a/CommandStation-EX.ino b/CommandStation-EX.ino index cd23f0e..a1ff739 100644 --- a/CommandStation-EX.ino +++ b/CommandStation-EX.ino @@ -47,6 +47,11 @@ */ #include "DCCEX.h" + +#ifdef CPU_TYPE_ERROR +#error CANNOT COMPILE - DCC++ EX ONLY WORKS WITH THE ARCHITECTURES LISTED IN defines.h +#endif + #ifdef WIFI_WARNING #warning You have defined that you want WiFi but your hardware has not enough memory to do that, so WiFi DISABLED #endif diff --git a/DCCTimer.h b/DCCTimer.h index 4ad507c..ebd22a8 100644 --- a/DCCTimer.h +++ b/DCCTimer.h @@ -86,42 +86,4 @@ private: }; -//////////////////////////////////////////////////////////////////////////////// -// Create a cpu type we can share and -// gigure out if we have enough memory for advanced features -// so define HAS_ENOUGH_MEMORY until proved otherwise. -#define HAS_ENOUGH_MEMORY -#define HAS_AVR_WDT - -#if defined(ARDUINO_AVR_UNO) -#define ARDUINO_TYPE "UNO" -#undef HAS_ENOUGH_MEMORY -#elif defined(ARDUINO_AVR_NANO) -#define ARDUINO_TYPE "NANO" -#undef HAS_ENOUGH_MEMORY -#elif defined(ARDUINO_AVR_MEGA) -#define ARDUINO_TYPE "MEGA" -#elif defined(ARDUINO_AVR_MEGA2560) -#define ARDUINO_TYPE "MEGA" -#elif defined(ARDUINO_ARCH_MEGAAVR) -#define ARDUINO_TYPE "MEGAAVR" -#elif defined(ARDUINO_TEENSY32) -#define ARDUINO_TYPE "TEENSY32" -#elif defined(ARDUINO_TEENSY35) -#define ARDUINO_TYPE "TEENSY35" -#elif defined(ARDUINO_TEENSY36) -#define ARDUINO_TYPE "TEENSY36" -#elif defined(ARDUINO_TEENSY40) -#define ARDUINO_TYPE "TEENSY40" -#elif defined(ARDUINO_TEENSY41) -#define ARDUINO_TYPE "TEENSY41" -#elif defined(ARDUINO_ARCH_ESP8266) -#define ARDUINO_TYPE "ESP8266" -#undef HAS_AVR_WDT -#elif defined(ARDUINO_ARCH_ESP32) -#define ARDUINO_TYPE "ESP32" -#undef HAS_AVR_WDT -#else -#error CANNOT COMPILE - DCC++ EX ONLY WORKS WITH THE ARCHITECTURES LISTED IN DCCTimer.h -#endif #endif diff --git a/defines.h b/defines.h index 9ce154d..d34f963 100644 --- a/defines.h +++ b/defines.h @@ -35,16 +35,52 @@ #endif #endif +//////////////////////////////////////////////////////////////////////////////// +// Create a cpu type we can share and +// figure out if we have enough memory for advanced features +// so define HAS_ENOUGH_MEMORY until proved otherwise. +#define HAS_ENOUGH_MEMORY +#define HAS_AVR_WDT + +#if defined(ARDUINO_AVR_UNO) +#define ARDUINO_TYPE "UNO" +#undef HAS_ENOUGH_MEMORY +#elif defined(ARDUINO_AVR_NANO) +#define ARDUINO_TYPE "NANO" +#undef HAS_ENOUGH_MEMORY +#elif defined(ARDUINO_AVR_MEGA) +#define ARDUINO_TYPE "MEGA" +#elif defined(ARDUINO_AVR_MEGA2560) +#define ARDUINO_TYPE "MEGA" +#elif defined(ARDUINO_ARCH_MEGAAVR) +#define ARDUINO_TYPE "MEGAAVR" +#elif defined(ARDUINO_TEENSY32) +#define ARDUINO_TYPE "TEENSY32" +#elif defined(ARDUINO_TEENSY35) +#define ARDUINO_TYPE "TEENSY35" +#elif defined(ARDUINO_TEENSY36) +#define ARDUINO_TYPE "TEENSY36" +#elif defined(ARDUINO_TEENSY40) +#define ARDUINO_TYPE "TEENSY40" +#elif defined(ARDUINO_TEENSY41) +#define ARDUINO_TYPE "TEENSY41" +#elif defined(ARDUINO_ARCH_ESP8266) +#define ARDUINO_TYPE "ESP8266" +#undef HAS_AVR_WDT +#elif defined(ARDUINO_ARCH_ESP32) +#define ARDUINO_TYPE "ESP32" +#undef HAS_AVR_WDT +#else +#define CPU_TYPE_ERROR +#endif + //////////////////////////////////////////////////////////////////////////////// // // WIFI_ON: All prereqs for running with WIFI are met // Note: WIFI_CHANNEL may not exist in early config.h files so is added here if needed. -#if defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_SAMD_ZERO) || defined(TEENSYDUINO) || defined(ARDUINO_AVR_NANO_EVERY) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) - #define BIG_RAM -#endif #if ENABLE_WIFI - #if defined(BIG_RAM) + #if defined(HAS_ENOUGH_MEMORY) #define WIFI_ON true #ifndef WIFI_CHANNEL #define WIFI_CHANNEL 1 @@ -58,7 +94,7 @@ #endif #if ENABLE_ETHERNET - #if defined(BIG_RAM) + #if defined(HAS_ENOUGH_MEMORY) #define ETHERNET_ON true #else #define ETHERNET_WARNING @@ -80,7 +116,7 @@ #define WIFI_SERIAL_LINK_SPEED 115200 #if __has_include ( "myAutomation.h") - #if defined(BIG_RAM) || defined(DISABLE_EEPROM) + #if defined(HAS_ENOUGH_MEMORY) || defined(DISABLE_EEPROM) #define EXRAIL_ACTIVE #else #define EXRAIL_WARNING