From d874ad8cc3cb7ce63b6dadef5841ab449f68d134 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Wed, 9 Nov 2022 00:52:07 +0100 Subject: [PATCH] Make GETFLASHW code more universal --- EXRAIL2.cpp | 6 +++++- FSH.h | 18 ++++++++++++++---- GITHUB_SHA.h | 2 +- version.h | 4 +++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/EXRAIL2.cpp b/EXRAIL2.cpp index 9095de8..d4961c7 100644 --- a/EXRAIL2.cpp +++ b/EXRAIL2.cpp @@ -90,9 +90,13 @@ LookList * RMFT2::onDeactivateLookup=NULL; LookList * RMFT2::onRedLookup=NULL; LookList * RMFT2::onAmberLookup=NULL; LookList * RMFT2::onGreenLookup=NULL; - #define GET_OPCODE GETFLASH(RMFT2::RouteCode+progCounter) +#ifdef ARDUINO_ARCH_AVR #define GET_OPERAND(n) GETFLASHW(RMFT2::RouteCode+progCounter+1+(n*3)) +#else +#define GET_OPERAND(n) GETOPW(RMFT2::RouteCode+progCounter+1+(n*3)) +#define GETOPW(A) (((uint32_t)A)%2 ? GETFLASH((const byte *)A) | (GETFLASH(1+(const byte *)A)<<8) : GETFLASHW(A)) +#endif #define SKIPOP progCounter+=3 diff --git a/FSH.h b/FSH.h index ea54554..38cc052 100644 --- a/FSH.h +++ b/FSH.h @@ -37,7 +37,9 @@ * */ #include + #if defined(ARDUINO_ARCH_MEGAAVR) + #ifdef F #undef F #endif @@ -48,18 +50,26 @@ typedef char FSH; #define FLASH #define strlen_P strlen #define strcpy_P strcpy + #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32) + typedef __FlashStringHelper FSH; #define GETFLASH(addr) pgm_read_byte(addr) -#define GETFLASHW(addr) (*(const unsigned int8_t *)(addr)) | ((*(const unsigned int8_t *)(addr+1)) << 8) +// pgm_read_word is buggy if addr is odd but here +// we do only read well aligned addrs, the others are +// taken care about in the GET_OPERAND(n) macro in EXRAIL2.cpp. +#define GETFLASHW(addr) pgm_read_word(addr) #ifdef FLASH #undef FLASH #endif #define FLASH PROGMEM -#else + +#else // AVR and AVR compat here + typedef __FlashStringHelper FSH; #define GETFLASH(addr) pgm_read_byte_near(addr) #define GETFLASHW(addr) pgm_read_word_near(addr) #define FLASH PROGMEM -#endif -#endif + +#endif // flash stuff +#endif // FSH diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index e870d25..6413eb5 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "devel-202211071020Z" +#define GITHUB_SHA "devel-202211082310Z" diff --git a/version.h b/version.h index 43e48e9..f272e1d 100644 --- a/version.h +++ b/version.h @@ -4,7 +4,9 @@ #include "StringFormatter.h" -#define VERSION "4.2.4" +#define VERSION "4.2.5" +// 4.2.5 Make GETFLASHW code more universal +// FIX: Withrottle roster index // Ethernet start improvement and link detection // 4.2.4 ESP32 experimental BT support // More DC configurations possible and lower frequency