Improved API for Comm Handler, Started implementing 24C EEprom Driver
authorandre Ebersold <andre.ebersold@free.fr>
Sat, 18 Nov 2023 17:17:11 +0000 (18:17 +0100)
committerandre Ebersold <andre.ebersold@free.fr>
Sat, 18 Nov 2023 17:17:11 +0000 (18:17 +0100)
Communication/CommunicationHandler.cpp
Communication/CommunicationHandler.h
HAL/AVR/AvrEeprom.cpp
HAL/AVR/AvrEeprom.h
HAL/Abstract/IEeprom.h
HAL/Abstract/II2C.h
HAL/Drivers/CMakeLists.txt
HAL/Drivers/Eeprom24C32_64.cpp [new file with mode: 0644]
HAL/Drivers/Eeprom24C32_64.h [new file with mode: 0644]
HAL/Drivers/Eeprom32C32_64.cpp [deleted file]
HAL/Drivers/Eeprom32C32_64.h [deleted file]

index d9468d541e8b53bff1a13b365a5eef05e0c27d5e..95f113f148ccbff335af2069aff4a38651a85370 100644 (file)
@@ -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<const Uint8_t *>(_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)
 {
index ebcad76b4617e438d80347011357b6bec4b8ffb2..3421a5ba8cf481c54f611fc1cedd00f5459d9b69 100644 (file)
@@ -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;
index cd6042ff48dcea2f446dcff065ff22dc500d1d94..1fced253487fd8c24ec82e41d5281e165e377fbd 100644 (file)
@@ -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)
index 0f6841e01ccf4f4631abc6afa855147a0eab76dd..87bf866e6e1a216c59300a0da9aea73f185b9338 100644 (file)
@@ -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
index d9cac0ad7427f145f819800c9d1572132e107f08..0ca03ea42e070af5deb2b0543e31d9b05b5688a7 100644 (file)
@@ -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
index 092f99ebe2bd41e208c9d1354f79291349714290..db7e5e5900369f1aeb50f599703017f090076964 100644 (file)
@@ -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
index 7759086b3411a0ea32971abc08d70b0b682de2a7..e9cadd1c69f56763b1f962b8c80ddf3a4d3b56f2 100644 (file)
@@ -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 (file)
index 0000000..fb2815c
--- /dev/null
@@ -0,0 +1,49 @@
+#include <Utils/StdTypes.h>
+
+#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<Uint8_t>(_addr>>8);
+    _Buff[1] = static_cast<Uint8_t>(_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<Uint8_t>(_addr>>8);
+    _Buff[1] = static_cast<Uint8_t>(_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 (file)
index 0000000..176f172
--- /dev/null
@@ -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 (file)
index 1e5b1a8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Commande ECHO activ\82e.
diff --git a/HAL/Drivers/Eeprom32C32_64.h b/HAL/Drivers/Eeprom32C32_64.h
deleted file mode 100644 (file)
index 1e5b1a8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Commande ECHO activ\82e.