Add ability to override config.h with define NO_KNX_CONFIG
This commit is contained in:
etrinh 2020-06-29 22:51:46 +02:00
parent 83d4758024
commit 3ffa7c298f
3 changed files with 21 additions and 11 deletions

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#ifndef NO_KNX_CONFIG
#ifdef ARDUINO_ARCH_SAMD #ifdef ARDUINO_ARCH_SAMD
#define SPI_SS_PIN 10 #define SPI_SS_PIN 10
#define GPIO_GDO2_PIN 9 #define GPIO_GDO2_PIN 9
@ -19,3 +21,5 @@
#ifdef USE_USB #ifdef USE_USB
#define USE_CEMI_SERVER #define USE_CEMI_SERVER
#endif #endif
#endif

View File

@ -1,14 +1,14 @@
#include "stm32_platform.h" #include "stm32_platform.h"
#ifdef ARDUINO_ARCH_STM32 #ifdef ARDUINO_ARCH_STM32
#include <EEPROM.h> #include <stm32_eeprom.h>
#include "knx/bits.h" #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) uint8_t * Stm32Platform::getEepromBuffer(uint16_t size)
{ {
delete [] eepromPtr; if (size > E2END + 1) {
fatalError();
}
eepromSize = size; eepromSize = size;
delete [] eepromPtr;
eepromPtr = new uint8_t[size]; eepromPtr = new uint8_t[size];
eeprom_buffer_fill();
for (uint16_t i = 0; i < size; ++i) for (uint16_t i = 0; i < size; ++i)
eepromPtr[i] = EEPROM[i]; eepromPtr[i] = eeprom_buffered_read_byte(i);
return eepromPtr; return eepromPtr;
} }
void Stm32Platform::commitToEeprom() void Stm32Platform::commitToEeprom()
{ {
if(eepromPtr == nullptr) if(eepromPtr == nullptr || eepromSize == 0)
return; return;
for (uint16_t i = 0; i < eepromSize; ++i) for (uint16_t i = 0; i < eepromSize; ++i) {
EEPROM.update(i, eepromPtr[i]); eeprom_buffered_write_byte(i, eepromPtr[i]);
}
eeprom_buffer_flush();
} }
#endif #endif

View File

@ -15,8 +15,8 @@ public:
uint8_t* getEepromBuffer(uint16_t size); uint8_t* getEepromBuffer(uint16_t size);
void commitToEeprom(); void commitToEeprom();
private: private:
uint8_t *eepromPtr; uint8_t *eepromPtr = nullptr;
uint16_t eepromSize; uint16_t eepromSize = 0;
}; };
#endif #endif