@@ -45,6 +45,9 @@ EEPROMClassEx::EEPROMClassEx()
45
45
* User API
46
46
******************************************************************************/
47
47
48
+ /* *
49
+ * Set starting position and memory size that EEPROMEx may manage
50
+ */
48
51
void EEPROMClassEx::setMemPool (int base, int memSize) {
49
52
// Base can only be adjusted if no addresses have already been issued
50
53
if (_nextAvailableaddress == _base)
@@ -65,12 +68,18 @@ void EEPROMClassEx::setMemPool(int base, int memSize) {
65
68
66
69
}
67
70
71
+ /* *
72
+ * Set global maximum of allowed writes
73
+ */
68
74
void EEPROMClassEx::setMaxAllowedWrites (int allowedWrites) {
69
75
#ifdef _EEPROMEX_DEBUG
70
76
_allowedWrites = allowedWrites;
71
77
#endif
72
78
}
73
79
80
+ /* *
81
+ * Get a new starting address to write to. Adress is negative if not enough space is available
82
+ */
74
83
int EEPROMClassEx::getAddress (int noOfBytes){
75
84
int availableaddress = _nextAvailableaddress;
76
85
_nextAvailableaddress += noOfBytes;
@@ -86,16 +95,25 @@ int EEPROMClassEx::getAddress(int noOfBytes){
86
95
return availableaddress;
87
96
}
88
97
89
-
98
+ /* *
99
+ * Check if EEPROM memory is ready to be accessed
100
+ */
90
101
bool EEPROMClassEx::isReady () {
91
102
return eeprom_is_ready ();
92
103
}
93
104
105
+ /* *
106
+ * Read a single byte
107
+ * This function performs as readByte and is added to be similar to the EEPROM library
108
+ */
94
109
uint8_t EEPROMClassEx::read (int address)
95
110
{
96
111
return readByte (address);
97
112
}
98
113
114
+ /* *
115
+ * Read a single bit
116
+ */
99
117
bool EEPROMClassEx::readBit (int address, byte bit) {
100
118
if (bit> 7 ) return false ;
101
119
if (!isReadOk (address+sizeof (uint8_t ))) return false ;
@@ -104,24 +122,36 @@ bool EEPROMClassEx::readBit(int address, byte bit) {
104
122
return (byteVal & bytePos);
105
123
}
106
124
125
+ /* *
126
+ * Read a single byte
127
+ */
107
128
uint8_t EEPROMClassEx::readByte (int address)
108
129
{
109
130
if (!isReadOk (address+sizeof (uint8_t ))) return 0 ;
110
131
return eeprom_read_byte ((unsigned char *) address);
111
132
}
112
133
134
+ /* *
135
+ * Read a single 16 bits integer
136
+ */
113
137
uint16_t EEPROMClassEx::readInt (int address)
114
138
{
115
139
if (!isReadOk (address+sizeof (uint16_t ))) return 0 ;
116
140
return eeprom_read_word ((uint16_t *) address);
117
141
}
118
142
143
+ /* *
144
+ * Read a single 32 bits integer
145
+ */
119
146
uint32_t EEPROMClassEx::readLong (int address)
120
147
{
121
148
if (!isReadOk (address+sizeof (uint32_t ))) return 0 ;
122
149
return eeprom_read_dword ((unsigned long *) address);
123
150
}
124
151
152
+ /* *
153
+ * Read a single float value
154
+ */
125
155
float EEPROMClassEx::readFloat (int address)
126
156
{
127
157
if (!isReadOk (address+sizeof (float ))) return 0 ;
@@ -130,6 +160,9 @@ float EEPROMClassEx::readFloat(int address)
130
160
return _value;
131
161
}
132
162
163
+ /* *
164
+ * Read a single double value (size will depend on board type)
165
+ */
133
166
double EEPROMClassEx::readDouble (int address)
134
167
{
135
168
if (!isReadOk (address+sizeof (double ))) return 0 ;
@@ -138,53 +171,83 @@ double EEPROMClassEx::readDouble(int address)
138
171
return _value;
139
172
}
140
173
174
+ /* *
175
+ * Write a single byte
176
+ * This function performs as writeByte and is added to be similar to the EEPROM library
177
+ */
141
178
bool EEPROMClassEx::write (int address, uint8_t value)
142
179
{
143
180
return writeByte (address, value);
144
181
}
145
182
183
+ /* *
184
+ * Write a single bit
185
+ */
146
186
bool EEPROMClassEx::writeBit (int address, uint8_t bit, bool value) {
147
187
updateBit (address, bit, value);
148
188
return true ;
149
189
}
150
190
151
-
191
+ /* *
192
+ * Write a single byte
193
+ */
152
194
bool EEPROMClassEx::writeByte (int address, uint8_t value)
153
195
{
154
196
if (!isWriteOk (address+sizeof (uint8_t ))) return false ;
155
197
eeprom_write_byte ((unsigned char *) address, value);
156
198
return true ;
157
199
}
158
200
201
+ /* *
202
+ * Write a single 16 bits integer
203
+ */
159
204
bool EEPROMClassEx::writeInt (int address, uint16_t value)
160
205
{
161
206
if (!isWriteOk (address+sizeof (uint16_t ))) return false ;
162
207
eeprom_write_word ((uint16_t *) address, value);
163
208
return true ;
164
209
}
165
210
211
+ /* *
212
+ * Write a single 32 bits integer
213
+ */
166
214
bool EEPROMClassEx::writeLong (int address, uint32_t value)
167
215
{
168
216
if (!isWriteOk (address+sizeof (uint32_t ))) return false ;
169
217
eeprom_write_dword ((unsigned long *) address, value);
170
218
return true ;
171
219
}
172
220
221
+ /* *
222
+ * Write a single float value
223
+ */
173
224
bool EEPROMClassEx::writeFloat (int address, float value)
174
225
{
175
226
return (writeBlock<float >(address, value)!=0 );
176
227
}
177
228
229
+ /* *
230
+ * Write a single double value (size will depend on board type)
231
+ */
178
232
bool EEPROMClassEx::writeDouble (int address, double value)
179
233
{
180
234
return (writeBlock<float >(address, value)!=0 );
181
235
}
182
236
237
+ /* *
238
+ * Update a single byte
239
+ * The EEPROM will only be overwritten if different. This will reduce wear.
240
+ * This function performs as updateByte and is added to be similar to the EEPROM library
241
+ */
183
242
bool EEPROMClassEx::update (int address, uint8_t value)
184
243
{
185
244
return (updateByte (address, value));
186
245
}
187
246
247
+ /* *
248
+ * Update a single bit
249
+ * The EEPROM will only be overwritten if different. This will reduce wear.
250
+ */
188
251
bool EEPROMClassEx::updateBit (int address, uint8_t bit, bool value)
189
252
{
190
253
if (bit> 7 ) return false ;
@@ -204,31 +267,55 @@ bool EEPROMClassEx::updateBit(int address, uint8_t bit, bool value)
204
267
return true ;
205
268
}
206
269
270
+
271
+ /* *
272
+ * Update a single byte
273
+ * The EEPROM will only be overwritten if different. This will reduce wear.
274
+ */
207
275
bool EEPROMClassEx::updateByte (int address, uint8_t value)
208
276
{
209
277
return (updateBlock<uint8_t >(address, value)!=0 );
210
278
}
211
279
280
+ /* *
281
+ * Update a single 16 bits integer
282
+ * The EEPROM will only be overwritten if different. This will reduce wear.
283
+ */
212
284
bool EEPROMClassEx::updateInt (int address, uint16_t value)
213
285
{
214
286
return (updateBlock<uint16_t >(address, value)!=0 );
215
287
}
216
288
289
+ /* *
290
+ * Update a single 32 bits integer
291
+ * The EEPROM will only be overwritten if different. This will reduce wear.
292
+ */
217
293
bool EEPROMClassEx::updateLong (int address, uint32_t value)
218
294
{
219
295
return (updateBlock<uint32_t >(address, value)!=0 );
220
296
}
221
297
298
+ /* *
299
+ * Update a single float value
300
+ * The EEPROM will only be overwritten if different. This will reduce wear.
301
+ */
222
302
bool EEPROMClassEx::updateFloat (int address, float value)
223
303
{
224
304
return (updateBlock<float >(address, value)!=0 );
225
305
}
226
306
307
+ /* *
308
+ * Update a single double value (size will depend on board type)
309
+ * The EEPROM will only be overwritten if different. This will reduce wear.
310
+ */
227
311
bool EEPROMClassEx::updateDouble (int address, double value)
228
312
{
229
313
return (writeBlock<double >(address, value)!=0 );
230
314
}
231
315
316
+ /* *
317
+ * Performs check to see if writing to a memory address is allowed
318
+ */
232
319
bool EEPROMClassEx::isWriteOk (int address)
233
320
{
234
321
#ifdef _EEPROMEX_DEBUG
@@ -248,6 +335,9 @@ bool EEPROMClassEx::isWriteOk(int address)
248
335
return true ;
249
336
}
250
337
338
+ /* *
339
+ * Performs check to see if reading from a memory address is allowed
340
+ */
251
341
bool EEPROMClassEx::isReadOk (int address)
252
342
{
253
343
#ifdef _EEPROMEX_DEBUG
0 commit comments