From f880114da5273479303700940ad9593f341476ef Mon Sep 17 00:00:00 2001 From: etrinh Date: Tue, 30 Jun 2020 14:58:53 +0200 Subject: [PATCH 1/2] Stm32 port (#71) * Fix Stm32 Eeprom handler Fix missing parenthesis Fix some type consistencies * Fix #73 Add ability to override config.h with define NO_KNX_CONFIG * change tabs to space * coding style Co-authored-by: etrinh --- src/knx/bits.h | 2 +- src/knx/config.h | 4 ++++ src/knx_facade.h | 4 ++-- src/stm32_platform.cpp | 33 ++++++++++++++++++++------------- src/stm32_platform.h | 4 ++-- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/knx/bits.h b/src/knx/bits.h index 565d24c..61d0d45 100644 --- a/src/knx/bits.h +++ b/src/knx/bits.h @@ -39,7 +39,7 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode); #define getbyte(x,n) (*(((uint8_t*)&(x))+n)) #define htons(x) ( (getbyte(x,0)<<8) | getbyte(x,1) ) -#define htonl(x) ( (getbyte(x,0)<<24) | getbyte(x,1)<<16) | (getbyte(x,2)<<8) | getbyte(x,3) ) +#define htonl(x) ( (getbyte(x,0)<<24) | (getbyte(x,1)<<16) | (getbyte(x,2)<<8) | getbyte(x,3) ) #define ntohs(x) htons(x) #define ntohl(x) htonl(x) diff --git a/src/knx/config.h b/src/knx/config.h index 2554c3b..59ee9c4 100644 --- a/src/knx/config.h +++ b/src/knx/config.h @@ -1,5 +1,7 @@ #pragma once +#ifndef NO_KNX_CONFIG + #ifdef ARDUINO_ARCH_SAMD #define SPI_SS_PIN 10 #define GPIO_GDO2_PIN 9 @@ -19,3 +21,5 @@ #ifdef USE_USB #define USE_CEMI_SERVER #endif + +#endif diff --git a/src/knx_facade.h b/src/knx_facade.h index 44afb4a..548f36e 100644 --- a/src/knx_facade.h +++ b/src/knx_facade.h @@ -198,12 +198,12 @@ template class KnxFacade : private SaveRestore _bau.deviceObject().bauNumber(value); } - void orderNumber(const char* value) + void orderNumber(const uint8_t* value) { _bau.deviceObject().orderNumber(value); } - void hardwareType(uint8_t* value) + void hardwareType(const uint8_t* value) { _bau.deviceObject().hardwareType(value); } diff --git a/src/stm32_platform.cpp b/src/stm32_platform.cpp index 4d2d92c..e05ab34 100644 --- a/src/stm32_platform.cpp +++ b/src/stm32_platform.cpp @@ -1,20 +1,20 @@ #include "stm32_platform.h" #ifdef ARDUINO_ARCH_STM32 -#include +#include #include "knx/bits.h" -Stm32Platform::Stm32Platform() : ArduinoPlatform(&Serial2), eepromPtr(nullptr), eepromSize(0) +Stm32Platform::Stm32Platform() : ArduinoPlatform(&Serial2) { } -Stm32Platform::Stm32Platform( HardwareSerial* s) : ArduinoPlatform(s), eepromPtr(nullptr), eepromSize(0) +Stm32Platform::Stm32Platform( HardwareSerial* s) : ArduinoPlatform(s) { } Stm32Platform::~Stm32Platform() { - delete [] eepromPtr; + delete [] _eepromPtr; } void Stm32Platform::restart() @@ -24,19 +24,26 @@ void Stm32Platform::restart() uint8_t * Stm32Platform::getEepromBuffer(uint16_t size) { - delete [] eepromPtr; - eepromPtr = new uint8_t[size]; - for (uint16_t i = 0; i < size; ++i) - eepromPtr[i] = EEPROM[i]; - return eepromPtr; + if (size > E2END + 1) + { + fatalError(); + } + _eepromSize = size; + delete [] _eepromPtr; + _eepromPtr = new uint8_t[size]; + eeprom_buffer_fill(); + for (uint16_t i = 0; i < size; ++i) + _eepromPtr[i] = eeprom_buffered_read_byte(i); + return _eepromPtr; } void Stm32Platform::commitToEeprom() { - if(eepromPtr == nullptr) - return; - for (uint16_t i = 0; i < eepromSize; ++i) - EEPROM.update(i, eepromPtr[i]); + if(_eepromPtr == nullptr || _eepromSize == 0) + return; + for (uint16_t i = 0; i < _eepromSize; ++i) + eeprom_buffered_write_byte(i, _eepromPtr[i]); + eeprom_buffer_flush(); } #endif diff --git a/src/stm32_platform.h b/src/stm32_platform.h index d8c6faa..04870ec 100644 --- a/src/stm32_platform.h +++ b/src/stm32_platform.h @@ -15,8 +15,8 @@ public: uint8_t* getEepromBuffer(uint16_t size); void commitToEeprom(); private: - uint8_t *eepromPtr; - uint16_t eepromSize; + uint8_t *_eepromPtr = nullptr; + uint16_t _eepromSize = 0; }; #endif From fda8e64425ac862dc84f91f1c73615459b359f3d Mon Sep 17 00:00:00 2001 From: etrinh Date: Wed, 1 Jul 2020 10:39:30 +0200 Subject: [PATCH 2/2] Add support for lambda for more platforms (#74) * Fix Stm32 Eeprom handler Fix missing parenthesis Fix some type consistencies * Fix #73 Add ability to override config.h with define NO_KNX_CONFIG * change tabs to space * coding style * Allow lambda on platforms which support it, can be forced with HAS_FUNCTIONAL 0/1 * remove automatic detection of functional due to breakage with some platforms: In file included from /home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/bits/char_traits.h:39:0, from /home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/string:40, from /home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/stdexcept:39, from /home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/array:39, from /home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/tuple:39, from /home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/functional:54, from /home/travis/arduino_ide/libraries/Adafruit_Test_Library/src/knx/group_object.h:37, from /home/travis/arduino_ide/libraries/Adafruit_Test_Library/src/knx/group_object_table_object.h:4, from /home/travis/arduino_ide/libraries/Adafruit_Test_Library/src/knx/bau_systemB.h:8, from /home/travis/arduino_ide/libraries/Adafruit_Test_Library/src/knx/bau07B0.h:4, from /home/travis/arduino_ide/libraries/Adafruit_Test_Library/src/knx_facade.h:12, from /home/travis/arduino_ide/libraries/Adafruit_Test_Library/src/knx.h:86, from /home/travis/build/thelsing/knx/examples/knx-bme680/knx-bme680.ino:4: /home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2 min(const _Tp& __a, const _Tp& __b, _Compare __comp) ^ /home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:265:56: error: macro "max" passed 3 arguments, but takes just 2 max(const _Tp& __a, const _Tp& __b, _Compare __comp) ^ To be investigated... Co-authored-by: etrinh --- src/knx/group_object.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/knx/group_object.h b/src/knx/group_object.h index 0e71b96..3578c39 100644 --- a/src/knx/group_object.h +++ b/src/knx/group_object.h @@ -19,7 +19,15 @@ enum ComFlag class GroupObject; -#ifdef __linux__ +#ifndef HAS_FUNCTIONAL +# if defined(__linux__) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_STM32) +# define HAS_FUNCTIONAL 1 +# else +# define HAS_FUNCTIONAL 0 +# endif +#endif + +#if HAS_FUNCTIONAL #include typedef std::function GroupObjectUpdatedHandler; #else