IoAbstraction
EepromAbstractionWire.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry).
3  * This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
4  */
5 
6 #ifndef IOABSTRACTION_EEPROMABSTRACTIONWIRE_H_
7 #define IOABSTRACTION_EEPROMABSTRACTIONWIRE_H_
8 
14 #include "PlatformDeterminationWire.h"
15 #include "EepromAbstraction.h"
16 #include <TaskManager.h>
17 
23  PAGESIZE_AT24C01,
24  PAGESIZE_AT24C02,
25  PAGESIZE_AT24C04,
26  PAGESIZE_AT24C08,
27  PAGESIZE_AT24C16,
28  PAGESIZE_AT24C32,
29  PAGESIZE_AT24C64,
30  PAGESIZE_AT24C128,
31  PAGESIZE_AT24C256,
32  PAGESIZE_AT24C512
33 };
34 
41 
48 
64  WireType wireImpl;
65  uint8_t eepromAddr;
66  bool errorOccurred;
67  uint8_t pageSize;
68  size_t eepromSize;
69 public:
74  I2cAt24Eeprom(uint8_t address, At24EepromType ty, WireType wireImpl = defaultWireTypePtr);
75  ~I2cAt24Eeprom() override = default;
76 
81  bool hasErrorOccurred() override;
82 
83  uint8_t read8(EepromPosition position) override;
84  void write8(EepromPosition position, uint8_t val) override;
85 
86  uint16_t read16(EepromPosition position) override;
87  void write16(EepromPosition position, uint16_t val) override;
88 
89  uint32_t read32(EepromPosition position) override;
90  void write32(EepromPosition position, uint32_t val) override;
91 
92  void readIntoMemArray(uint8_t* memDest, EepromPosition romSrc, uint8_t len) override;
93  void writeArrayToRom(EepromPosition romDest, const uint8_t* memSrc, uint8_t len) override;
94 private:
95  uint8_t findMaximumInPage(uint16_t romDest, uint8_t len) const;
96  void writeByte(EepromPosition position, uint8_t val);
97  uint8_t readByte(EepromPosition position);
98  void writeAddressWire(uint16_t memAddr, const uint8_t* data = nullptr, int len = 0);
99 };
100 
101 #endif /* IOABSTRACTION_EEPROMABSTRACTIONWIRE_H_ */
Wraps up EEPROM support in a way that is compatible between implementations. For example presently th...
uint16_t EepromPosition
Definition: EepromAbstraction.h:26
uint8_t at24PageFromRomSize(At24EepromType size)
Definition: EepromAbstractionWire.cpp:18
At24EepromType
Definition: EepromAbstractionWire.h:22
size_t at24ActualSizeFromRomSize(At24EepromType size)
Definition: EepromAbstractionWire.cpp:35
Definition: EepromAbstraction.h:33
Definition: EepromAbstractionWire.h:63
bool hasErrorOccurred() override
Definition: EepromAbstractionWire.cpp:60
void writeArrayToRom(EepromPosition romDest, const uint8_t *memSrc, uint8_t len) override
Definition: EepromAbstractionWire.cpp:177
I2cAt24Eeprom(uint8_t address, At24EepromType ty, WireType wireImpl=defaultWireTypePtr)
Definition: EepromAbstractionWire.cpp:52
void write8(EepromPosition position, uint8_t val) override
Definition: EepromAbstractionWire.cpp:81
void write16(EepromPosition position, uint16_t val) override
Definition: EepromAbstractionWire.cpp:92
void write32(EepromPosition position, uint32_t val) override
Definition: EepromAbstractionWire.cpp:109
uint8_t read8(EepromPosition position) override
Definition: EepromAbstractionWire.cpp:77
uint32_t read32(EepromPosition position) override
Definition: EepromAbstractionWire.cpp:101
uint16_t read16(EepromPosition position) override
Definition: EepromAbstractionWire.cpp:86
void readIntoMemArray(uint8_t *memDest, EepromPosition romSrc, uint8_t len) override
Definition: EepromAbstractionWire.cpp:165