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