From 3ffa7c298f87757d273e20fc1e80455f9c8ba278 Mon Sep 17 00:00:00 2001 From: etrinh Date: Mon, 29 Jun 2020 22:51:46 +0200 Subject: [PATCH] Fix #73 Add ability to override config.h with define NO_KNX_CONFIG --- src/knx/config.h | 4 ++++ src/stm32_platform.cpp | 24 +++++++++++++++--------- src/stm32_platform.h | 4 ++-- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/knx/config.h b/src/knx/config.h index 2554c3b..c877cdf 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 \ No newline at end of file diff --git a/src/stm32_platform.cpp b/src/stm32_platform.cpp index fd7160f..8ebda2f 100644 --- a/src/stm32_platform.cpp +++ b/src/stm32_platform.cpp @@ -1,14 +1,14 @@ #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) { } @@ -24,20 +24,26 @@ void Stm32Platform::restart() uint8_t * Stm32Platform::getEepromBuffer(uint16_t size) { - delete [] 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[i]; - return eepromPtr; + eepromPtr[i] = eeprom_buffered_read_byte(i); + return eepromPtr; } void Stm32Platform::commitToEeprom() { - if(eepromPtr == nullptr) + if(eepromPtr == nullptr || eepromSize == 0) return; - for (uint16_t i = 0; i < eepromSize; ++i) - EEPROM.update(i, eepromPtr[i]); + 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..40f29e6 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