From cd12e25eabceb57bb92607187a14bb859330d0c1 Mon Sep 17 00:00:00 2001 From: andre Ebersold Date: Sat, 18 Nov 2023 18:17:11 +0100 Subject: [PATCH] Improved API for Comm Handler, Started implementing 24C EEprom Driver --- Communication/CommunicationHandler.cpp | 42 ++++++++++++++++------ Communication/CommunicationHandler.h | 13 ++++++- HAL/AVR/AvrEeprom.cpp | 6 ++++ HAL/AVR/AvrEeprom.h | 4 +++ HAL/Abstract/IEeprom.h | 7 ++-- HAL/Abstract/II2C.h | 5 ++- HAL/Drivers/CMakeLists.txt | 1 + HAL/Drivers/Eeprom24C32_64.cpp | 49 ++++++++++++++++++++++++++ HAL/Drivers/Eeprom24C32_64.h | 31 ++++++++++++++++ HAL/Drivers/Eeprom32C32_64.cpp | 1 - HAL/Drivers/Eeprom32C32_64.h | 1 - 11 files changed, 143 insertions(+), 17 deletions(-) create mode 100644 HAL/Drivers/Eeprom24C32_64.cpp create mode 100644 HAL/Drivers/Eeprom24C32_64.h delete mode 100644 HAL/Drivers/Eeprom32C32_64.cpp delete mode 100644 HAL/Drivers/Eeprom32C32_64.h diff --git a/Communication/CommunicationHandler.cpp b/Communication/CommunicationHandler.cpp index d9468d5..95f113f 100644 --- a/Communication/CommunicationHandler.cpp +++ b/Communication/CommunicationHandler.cpp @@ -90,17 +90,7 @@ CommunicationHandler::parse_msg(const Uint8_t *_msg,const Uint8_t len,eParameter } if ( _msg[pos] == '=' ) { - if (_eType == TYPE_FLOAT) - { - Float32_t result; - result = atof((const char *)(_msg+1+pos)); - m_Params->writeValue(nv,result); - } - else - { - parse_num(_msg+1+pos,len - 1 - pos,val); - m_Params->writeValue(nv,val); - } + writeParameter(nv,_eType,static_cast(_msg + 1 + pos),len - 1 - pos); m_L2->setTxMsg((const uint8_t *)"OK\r\n",4); } else if (_msg[pos] == '?') { @@ -132,6 +122,36 @@ CommunicationHandler::parse_msg(const Uint8_t *_msg,const Uint8_t len,eParameter } } +/// +void CommunicationHandler::readParameter(const Uint8_t paramId) +{ +} +/** + * Read eeprom and send it back to ... + */ +void CommunicationHandler::readEeprom(const Uint16_t _address) +{ +} +/// +void CommunicationHandler::writeParameter(const Uint8_t paramId + ,eParameterType _eType + ,const Uint8_t *_buf + ,Uint8_t len) +{ + if (_eType == TYPE_FLOAT) + { + Float32_t result; + result = atof((const char *)(_buf)); + m_Params->writeValue(paramId,result); + } + else + { + Uint32_t val; + parse_num(_buf,len,val); + m_Params->writeValue(paramId,val); + } +} + void CommunicationHandler::parse_num(const Uint8_t *_msg,const Uint8_t len,Uint32_t &_out) { diff --git a/Communication/CommunicationHandler.h b/Communication/CommunicationHandler.h index ebcad76..3421a5b 100644 --- a/Communication/CommunicationHandler.h +++ b/Communication/CommunicationHandler.h @@ -10,8 +10,19 @@ class CommunicationHandler virtual void run(); private: void parse_msg(const Uint8_t *_msg,const Uint8_t len,eParameterType _eT); - /// + /// Not this is needed void parse_num(const Uint8_t *_msg,const Uint8_t len, Uint32_t &_out); + /// + void readParameter(const Uint8_t paramId); + /** + * Read eeprom and send it back to ... + */ + void readEeprom(const Uint16_t _address); + /// + void writeParameter(const Uint8_t paramId + ,eParameterType _eType + ,const Uint8_t *_buf + ,Uint8_t len); private: IProtocolLayer2 *m_L2; IParameterHandler *m_Params; diff --git a/HAL/AVR/AvrEeprom.cpp b/HAL/AVR/AvrEeprom.cpp index cd6042f..1fced25 100644 --- a/HAL/AVR/AvrEeprom.cpp +++ b/HAL/AVR/AvrEeprom.cpp @@ -33,6 +33,12 @@ AvrEeprom::read(const Uint16_t _addr,const Uint16_t _len,Uint8_t *_dest) *_dest = EEDR; } + +void +AvrEeprom::write(const Uint16_t _addr,Uint8_t _dest) +{ +} + /// Interesting that eeprom is written page wise void AvrEeprom::writePage(const Uint8_t pageCount,const Uint8_t _Offset,const Uint8_t byteCount,Uint8_t *_data) diff --git a/HAL/AVR/AvrEeprom.h b/HAL/AVR/AvrEeprom.h index 0f6841e..87bf866 100644 --- a/HAL/AVR/AvrEeprom.h +++ b/HAL/AVR/AvrEeprom.h @@ -22,6 +22,10 @@ class AvrEeprom : public IEeprom virtual void read( const Uint16_t _addr , const Uint16_t _len , Uint8_t *_dest); + + /// write Byte Eeprom + virtual void write( const Uint16_t _addr + , Uint8_t _dest); /// Interesting that eeprom is written page wise virtual void writePage( const Uint8_t pageCount diff --git a/HAL/Abstract/IEeprom.h b/HAL/Abstract/IEeprom.h index d9cac0a..0ca03ea 100644 --- a/HAL/Abstract/IEeprom.h +++ b/HAL/Abstract/IEeprom.h @@ -15,11 +15,14 @@ class IEeprom /// Initialize virtual void init() = 0; /// Is eeprom busy, might be of interest, as eeprom access is performed through - /// SPI + /// SPI or I2C virtual Bool_t isBusy() = 0; /// read values from Eeprom virtual void read(const Uint16_t _addr,const Uint16_t _len,Uint8_t *_dest); /// Interesting that eeprom is written page wise - virtual void writePage(const Uint8_t pageCount,const Uint8_t _Offset,const Uint8_t byteCount,Uint8_t *_data); + virtual void writePage(const Uint8_t pageCount + ,const Uint8_t _Offset + ,const Uint8_t byteCount + ,Uint8_t *_data); }; #endif diff --git a/HAL/Abstract/II2C.h b/HAL/Abstract/II2C.h index 092f99e..db7e5e5 100644 --- a/HAL/Abstract/II2C.h +++ b/HAL/Abstract/II2C.h @@ -6,11 +6,14 @@ class II2C public: typedef Uint8_t Error_t; II2C() {}; - virtual Error_t write(const Uint8_t argAddress,Uint8_t *argData, Uint8_t argLen) = 0; virtual Error_t read(const Uint8_t argAddress,Uint8_t *argData ,Uint8_t argLen) = 0; + /* + * This works well for DS32 but not EEprom So, maybe I'll get ride of this method + * Also for PN532 it's not really what I need + */ virtual Error_t read( const Uint8_t argAddress , const Uint8_t regAddr , Uint8_t *argData diff --git a/HAL/Drivers/CMakeLists.txt b/HAL/Drivers/CMakeLists.txt index 7759086..e9cadd1 100644 --- a/HAL/Drivers/CMakeLists.txt +++ b/HAL/Drivers/CMakeLists.txt @@ -10,5 +10,6 @@ add_avr_library( LiquidCrystal.cpp PN532Interface_I2C.cpp PN532.cpp + Eeprom24C32_64.cpp ) diff --git a/HAL/Drivers/Eeprom24C32_64.cpp b/HAL/Drivers/Eeprom24C32_64.cpp new file mode 100644 index 0000000..fb2815c --- /dev/null +++ b/HAL/Drivers/Eeprom24C32_64.cpp @@ -0,0 +1,49 @@ +#include + +#include "Abstract/II2C.h" +#include "Abstract/IEEprom.h" +#include "Drivers/Eeprom24C32_64.h" + +EEprom24C32::EEprom24C32(II2C *argI2C,Uint8_t argAddr ) + : m_I2C(argI2C) , m_I2CAddress(argAddr) +{ +} + + +void +EEprom24C32::init() +{ +} +/// Is eeprom busy, might be of interest, as eeprom access is performed through +/// SPI or I2C +Bool_t +EEprom24C32::isBusy() +{ + return false; +} + +/// read values from Eeprom +void +EEprom24C32::read(const Uint16_t _addr,const Uint16_t _len,Uint8_t *_dest) +{ + Uint8_t _Buff[2]; + _Buff[0] = static_cast(_addr>>8); + _Buff[1] = static_cast(_addr & 0x00FF); + m_I2C->write(m_I2CAddress,_Buff,2); + m_I2C->read(m_I2CAddress,_dest,_len); +} + +/// Interesting that eeprom is written page wise +void +EEprom24C32::writePage(const Uint8_t pageCount,const Uint8_t _Offset,const Uint8_t byteCount,Uint8_t *_data) +{ + Uint8_t _Buff[32 + 2]; + // Compute Address + Uint16_t _addr = pageCount * 32 + _Offset; + _Buff[0] = static_cast(_addr>>8); + _Buff[1] = static_cast(_addr & 0x00FF); + for (Uint8_t i = 0 ; i < byteCount ; ++i) + _Buff[i+2] = _data[i]; + m_I2C->write(m_I2CAddress,_Buff,2+byteCount); +} + diff --git a/HAL/Drivers/Eeprom24C32_64.h b/HAL/Drivers/Eeprom24C32_64.h new file mode 100644 index 0000000..176f172 --- /dev/null +++ b/HAL/Drivers/Eeprom24C32_64.h @@ -0,0 +1,31 @@ +#ifndef __EEPROM24C32_H__ +#define __EEPROM24C32_H__ + +class EEprom24C32 : public IEeprom +{ + public: + EEprom24C32(II2C *argI2C,Uint8_t argAddr = 0xA0); + + virtual void init() ; + /// Is eeprom busy, might be of interest, as eeprom access is performed through + /// SPI or I2C + virtual Bool_t isBusy(); + /// read values from Eeprom + virtual void read( const Uint16_t _addr + , const Uint16_t _len + , Uint8_t *_dest ); + /// write Byte Eeprom + virtual void write( const Uint16_t _addr + , Uint8_t _dest); + + /// Interesting that eeprom is written page wise + virtual void writePage( const Uint8_t pageCount + , const Uint8_t _Offset + , const Uint8_t byteCount + , Uint8_t *_data); + private: + II2C *m_I2C; + Uint8_t m_I2CAddress; +}; + +#endif diff --git a/HAL/Drivers/Eeprom32C32_64.cpp b/HAL/Drivers/Eeprom32C32_64.cpp deleted file mode 100644 index 1e5b1a8..0000000 --- a/HAL/Drivers/Eeprom32C32_64.cpp +++ /dev/null @@ -1 +0,0 @@ -Commande ECHO activ‚e. diff --git a/HAL/Drivers/Eeprom32C32_64.h b/HAL/Drivers/Eeprom32C32_64.h deleted file mode 100644 index 1e5b1a8..0000000 --- a/HAL/Drivers/Eeprom32C32_64.h +++ /dev/null @@ -1 +0,0 @@ -Commande ECHO activ‚e. -- 2.30.2