IoAbstraction
EepromAbstraction.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 
12 #ifndef _IOABSTRACTION_EEPROMABSTRACTION_H_
13 #define _IOABSTRACTION_EEPROMABSTRACTION_H_
14 
15 #include "PlatformDetermination.h"
16 
17 #ifdef IOA_USE_MBED
18 #include <mbed.h>
19 #elif !defined(BUILD_FOR_PICO_CMAKE)
20 #include <Arduino.h>
21 #endif
22 
26 typedef uint16_t EepromPosition;
27 
34 public:
35  virtual ~EepromAbstraction() {}
36 
40  virtual bool hasErrorOccurred() { return false;}
41 
46  virtual uint8_t read8(EepromPosition position) = 0;
47 
53  virtual void write8(EepromPosition position, uint8_t val) = 0;
54 
59  virtual uint16_t read16(EepromPosition position) = 0;
60 
66  virtual void write16(EepromPosition position, uint16_t val) = 0;
67 
72  virtual uint32_t read32(EepromPosition position) = 0;
73 
79  virtual void write32(EepromPosition position, uint32_t val) = 0;
80 
87  virtual void readIntoMemArray(uint8_t* memDest, EepromPosition romSrc, uint8_t len) = 0;
88 
95  virtual void writeArrayToRom(EepromPosition romDest, const uint8_t* memSrc, uint8_t len) = 0;
96 };
97 
98 // only include the atmel AVR support if it's available on this platform.
99 #ifdef __AVR__
100 
105 class AvrEeprom : public EepromAbstraction {
106 public:
107  virtual ~AvrEeprom() {}
108 
109  virtual uint8_t read8(EepromPosition position);
110  virtual void write8(EepromPosition position, uint8_t val);
111 
112  virtual uint16_t read16(EepromPosition position);
113  virtual void write16(EepromPosition position, uint16_t val);
114 
115  virtual uint32_t read32(EepromPosition position);
116  virtual void write32(EepromPosition position, uint32_t val);
117 
118  virtual void readIntoMemArray(uint8_t* memDest, EepromPosition romSrc, uint8_t len);
119  virtual void writeArrayToRom(EepromPosition romDest, const uint8_t* memSrc, uint8_t len);
120 };
121 
122 #endif
123 
127 class NoEeprom : public EepromAbstraction {
128 public:
129  virtual ~NoEeprom() {}
130 
131  virtual uint8_t read8(__attribute__((unused)) EepromPosition position) {return 0;}
132  virtual void write8(__attribute__((unused)) EepromPosition position, __attribute__((unused)) uint8_t val) {}
133 
134  virtual uint16_t read16(__attribute__((unused)) EepromPosition position) {return 0;}
135  virtual void write16(__attribute__((unused)) EepromPosition position, __attribute__((unused)) uint16_t val) {}
136 
137  virtual uint32_t read32(__attribute__((unused)) EepromPosition position) {return 0;}
138  virtual void write32(__attribute__((unused)) EepromPosition position, __attribute__((unused)) uint32_t val) {}
139 
140  virtual void readIntoMemArray(__attribute__((unused)) uint8_t* memDest, __attribute__((unused)) EepromPosition romSrc, __attribute__((unused)) uint8_t len) {memDest[0]=0;}
141  virtual void writeArrayToRom(__attribute__((unused)) EepromPosition romDest, __attribute__((unused)) const uint8_t* memSrc, __attribute__((unused)) uint8_t len) {}
142 };
143 
144 #endif /* _IOABSTRACTION_EEPROMABSTRACTION_H_ */
uint16_t EepromPosition
Definition: EepromAbstraction.h:26
Definition: EepromAbstraction.h:105
virtual void write8(EepromPosition position, uint8_t val)
Definition: EepromAbstraction.cpp:15
virtual uint8_t read8(EepromPosition position)
Definition: EepromAbstraction.cpp:11
virtual void writeArrayToRom(EepromPosition romDest, const uint8_t *memSrc, uint8_t len)
Definition: EepromAbstraction.cpp:45
virtual void readIntoMemArray(uint8_t *memDest, EepromPosition romSrc, uint8_t len)
Definition: EepromAbstraction.cpp:41
virtual uint16_t read16(EepromPosition position)
Definition: EepromAbstraction.cpp:21
virtual uint32_t read32(EepromPosition position)
Definition: EepromAbstraction.cpp:31
virtual void write32(EepromPosition position, uint32_t val)
Definition: EepromAbstraction.cpp:35
virtual void write16(EepromPosition position, uint16_t val)
Definition: EepromAbstraction.cpp:25
Definition: EepromAbstraction.h:33
virtual void writeArrayToRom(EepromPosition romDest, const uint8_t *memSrc, uint8_t len)=0
virtual bool hasErrorOccurred()
Definition: EepromAbstraction.h:40
virtual uint16_t read16(EepromPosition position)=0
virtual void readIntoMemArray(uint8_t *memDest, EepromPosition romSrc, uint8_t len)=0
virtual void write16(EepromPosition position, uint16_t val)=0
virtual void write8(EepromPosition position, uint8_t val)=0
virtual uint8_t read8(EepromPosition position)=0
virtual void write32(EepromPosition position, uint32_t val)=0
virtual uint32_t read32(EepromPosition position)=0
Definition: EepromAbstraction.h:127