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
#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

View File

@ -1,14 +1,14 @@
#include "stm32_platform.h"
#ifdef ARDUINO_ARCH_STM32
#include <EEPROM.h>
#include <stm32_eeprom.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)
{
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

View File

@ -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