#pragma once #include #include #include "MyFRAM_I2C.h" namespace MY_FRAMCONTROL { consteval uint32_t sizeofObject (const auto &data) { return sizeof(data); } consteval uint32_t lengthStructure (const auto &data, const size_t N) { return sizeofObject(data)/N; } constinit uint8_t TWI_BUFFER_SIZE {BUFFER_LENGTH-2}; // 'BUFFER_LENGTH' in twi.h abzüglich 2 Bytes Speicherzellenadressierung } /* I2C Addr | wire0/wire1 | | Capacity in kBit | | | Object for length determination etc. | | | | initial address of object in FRAM | | | | | */ template class MyFramControl { }; // allg. Template template class MyFramControl // non array Template Spezialisierung template class MyFramControl // array Template Spezialisierung { static_assert((10<=BUFFER_LENGTH), "TWI buffer size smaller than 10 is possible but not practical, Wire src twi.h" ); static_assert(((initObjAddr+sizeof(myObj)) < (1024UL*memorySize/8)), "Object to large or Addr to high" ); private: MyFRAM_I2C fram; uint32_t calcMemberAddr (const uint32_t objStartIndex, const uint32_t memberOffset) { using namespace MY_FRAMCONTROL; return initObjAddr + (objStartIndex*lengthStructure(myObj,N)) + memberOffset; } public: MyFramControl() = default; void readTo (T(&otherObj)[N]) { fram.read(initObjAddr, otherObj); } };