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 <etrinh@zdionline.net>
This commit is contained in:
etrinh 2020-06-30 14:58:53 +02:00 committed by GitHub
parent 4677044f46
commit f880114da5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 18 deletions

View File

@ -39,7 +39,7 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode);
#define getbyte(x,n) (*(((uint8_t*)&(x))+n)) #define getbyte(x,n) (*(((uint8_t*)&(x))+n))
#define htons(x) ( (getbyte(x,0)<<8) | getbyte(x,1) ) #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 ntohs(x) htons(x)
#define ntohl(x) htonl(x) #define ntohl(x) htonl(x)

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

@ -198,12 +198,12 @@ template <class P, class B> class KnxFacade : private SaveRestore
_bau.deviceObject().bauNumber(value); _bau.deviceObject().bauNumber(value);
} }
void orderNumber(const char* value) void orderNumber(const uint8_t* value)
{ {
_bau.deviceObject().orderNumber(value); _bau.deviceObject().orderNumber(value);
} }
void hardwareType(uint8_t* value) void hardwareType(const uint8_t* value)
{ {
_bau.deviceObject().hardwareType(value); _bau.deviceObject().hardwareType(value);
} }

View File

@ -1,20 +1,20 @@
#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)
{ {
} }
Stm32Platform::~Stm32Platform() Stm32Platform::~Stm32Platform()
{ {
delete [] eepromPtr; delete [] _eepromPtr;
} }
void Stm32Platform::restart() void Stm32Platform::restart()
@ -24,19 +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)
eepromPtr = new uint8_t[size]; {
for (uint16_t i = 0; i < size; ++i) fatalError();
eepromPtr[i] = EEPROM[i]; }
return eepromPtr; _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() 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