Skip to content

Commit cbe2a72

Browse files
committed
- Added Documentation
1 parent 8bcae30 commit cbe2a72

28 files changed

+3511
-6
lines changed

EEPROMex.cpp

+92-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ EEPROMClassEx::EEPROMClassEx()
4545
* User API
4646
******************************************************************************/
4747

48+
/**
49+
* Set starting position and memory size that EEPROMEx may manage
50+
*/
4851
void EEPROMClassEx::setMemPool(int base, int memSize) {
4952
//Base can only be adjusted if no addresses have already been issued
5053
if (_nextAvailableaddress == _base)
@@ -65,12 +68,18 @@ void EEPROMClassEx::setMemPool(int base, int memSize) {
6568

6669
}
6770

71+
/**
72+
* Set global maximum of allowed writes
73+
*/
6874
void EEPROMClassEx::setMaxAllowedWrites(int allowedWrites) {
6975
#ifdef _EEPROMEX_DEBUG
7076
_allowedWrites = allowedWrites;
7177
#endif
7278
}
7379

80+
/**
81+
* Get a new starting address to write to. Adress is negative if not enough space is available
82+
*/
7483
int EEPROMClassEx::getAddress(int noOfBytes){
7584
int availableaddress = _nextAvailableaddress;
7685
_nextAvailableaddress += noOfBytes;
@@ -86,16 +95,25 @@ int EEPROMClassEx::getAddress(int noOfBytes){
8695
return availableaddress;
8796
}
8897

89-
98+
/**
99+
* Check if EEPROM memory is ready to be accessed
100+
*/
90101
bool EEPROMClassEx::isReady() {
91102
return eeprom_is_ready();
92103
}
93104

105+
/**
106+
* Read a single byte
107+
* This function performs as readByte and is added to be similar to the EEPROM library
108+
*/
94109
uint8_t EEPROMClassEx::read(int address)
95110
{
96111
return readByte(address);
97112
}
98113

114+
/**
115+
* Read a single bit
116+
*/
99117
bool EEPROMClassEx::readBit(int address, byte bit) {
100118
if (bit> 7) return false;
101119
if (!isReadOk(address+sizeof(uint8_t))) return false;
@@ -104,24 +122,36 @@ bool EEPROMClassEx::readBit(int address, byte bit) {
104122
return (byteVal & bytePos);
105123
}
106124

125+
/**
126+
* Read a single byte
127+
*/
107128
uint8_t EEPROMClassEx::readByte(int address)
108129
{
109130
if (!isReadOk(address+sizeof(uint8_t))) return 0;
110131
return eeprom_read_byte((unsigned char *) address);
111132
}
112133

134+
/**
135+
* Read a single 16 bits integer
136+
*/
113137
uint16_t EEPROMClassEx::readInt(int address)
114138
{
115139
if (!isReadOk(address+sizeof(uint16_t))) return 0;
116140
return eeprom_read_word((uint16_t *) address);
117141
}
118142

143+
/**
144+
* Read a single 32 bits integer
145+
*/
119146
uint32_t EEPROMClassEx::readLong(int address)
120147
{
121148
if (!isReadOk(address+sizeof(uint32_t))) return 0;
122149
return eeprom_read_dword((unsigned long *) address);
123150
}
124151

152+
/**
153+
* Read a single float value
154+
*/
125155
float EEPROMClassEx::readFloat(int address)
126156
{
127157
if (!isReadOk(address+sizeof(float))) return 0;
@@ -130,6 +160,9 @@ float EEPROMClassEx::readFloat(int address)
130160
return _value;
131161
}
132162

163+
/**
164+
* Read a single double value (size will depend on board type)
165+
*/
133166
double EEPROMClassEx::readDouble(int address)
134167
{
135168
if (!isReadOk(address+sizeof(double))) return 0;
@@ -138,53 +171,83 @@ double EEPROMClassEx::readDouble(int address)
138171
return _value;
139172
}
140173

174+
/**
175+
* Write a single byte
176+
* This function performs as writeByte and is added to be similar to the EEPROM library
177+
*/
141178
bool EEPROMClassEx::write(int address, uint8_t value)
142179
{
143180
return writeByte(address, value);
144181
}
145182

183+
/**
184+
* Write a single bit
185+
*/
146186
bool EEPROMClassEx::writeBit(int address, uint8_t bit, bool value) {
147187
updateBit(address, bit, value);
148188
return true;
149189
}
150190

151-
191+
/**
192+
* Write a single byte
193+
*/
152194
bool EEPROMClassEx::writeByte(int address, uint8_t value)
153195
{
154196
if (!isWriteOk(address+sizeof(uint8_t))) return false;
155197
eeprom_write_byte((unsigned char *) address, value);
156198
return true;
157199
}
158200

201+
/**
202+
* Write a single 16 bits integer
203+
*/
159204
bool EEPROMClassEx::writeInt(int address, uint16_t value)
160205
{
161206
if (!isWriteOk(address+sizeof(uint16_t))) return false;
162207
eeprom_write_word((uint16_t *) address, value);
163208
return true;
164209
}
165210

211+
/**
212+
* Write a single 32 bits integer
213+
*/
166214
bool EEPROMClassEx::writeLong(int address, uint32_t value)
167215
{
168216
if (!isWriteOk(address+sizeof(uint32_t))) return false;
169217
eeprom_write_dword((unsigned long *) address, value);
170218
return true;
171219
}
172220

221+
/**
222+
* Write a single float value
223+
*/
173224
bool EEPROMClassEx::writeFloat(int address, float value)
174225
{
175226
return (writeBlock<float>(address, value)!=0);
176227
}
177228

229+
/**
230+
* Write a single double value (size will depend on board type)
231+
*/
178232
bool EEPROMClassEx::writeDouble(int address, double value)
179233
{
180234
return (writeBlock<float>(address, value)!=0);
181235
}
182236

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+
*/
183242
bool EEPROMClassEx::update(int address, uint8_t value)
184243
{
185244
return (updateByte(address, value));
186245
}
187246

247+
/**
248+
* Update a single bit
249+
* The EEPROM will only be overwritten if different. This will reduce wear.
250+
*/
188251
bool EEPROMClassEx::updateBit(int address, uint8_t bit, bool value)
189252
{
190253
if (bit> 7) return false;
@@ -204,31 +267,55 @@ bool EEPROMClassEx::updateBit(int address, uint8_t bit, bool value)
204267
return true;
205268
}
206269

270+
271+
/**
272+
* Update a single byte
273+
* The EEPROM will only be overwritten if different. This will reduce wear.
274+
*/
207275
bool EEPROMClassEx::updateByte(int address, uint8_t value)
208276
{
209277
return (updateBlock<uint8_t>(address, value)!=0);
210278
}
211279

280+
/**
281+
* Update a single 16 bits integer
282+
* The EEPROM will only be overwritten if different. This will reduce wear.
283+
*/
212284
bool EEPROMClassEx::updateInt(int address, uint16_t value)
213285
{
214286
return (updateBlock<uint16_t>(address, value)!=0);
215287
}
216288

289+
/**
290+
* Update a single 32 bits integer
291+
* The EEPROM will only be overwritten if different. This will reduce wear.
292+
*/
217293
bool EEPROMClassEx::updateLong(int address, uint32_t value)
218294
{
219295
return (updateBlock<uint32_t>(address, value)!=0);
220296
}
221297

298+
/**
299+
* Update a single float value
300+
* The EEPROM will only be overwritten if different. This will reduce wear.
301+
*/
222302
bool EEPROMClassEx::updateFloat(int address, float value)
223303
{
224304
return (updateBlock<float>(address, value)!=0);
225305
}
226306

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+
*/
227311
bool EEPROMClassEx::updateDouble(int address, double value)
228312
{
229313
return (writeBlock<double>(address, value)!=0);
230314
}
231315

316+
/**
317+
* Performs check to see if writing to a memory address is allowed
318+
*/
232319
bool EEPROMClassEx::isWriteOk(int address)
233320
{
234321
#ifdef _EEPROMEX_DEBUG
@@ -248,6 +335,9 @@ bool EEPROMClassEx::isWriteOk(int address)
248335
return true;
249336
}
250337

338+
/**
339+
* Performs check to see if reading from a memory address is allowed
340+
*/
251341
bool EEPROMClassEx::isReadOk(int address)
252342
{
253343
#ifdef _EEPROMEX_DEBUG

EEPROMex.h

+23-4
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,29 @@ class EEPROMClassEx
9191

9292
// Use template for other data formats
9393

94-
94+
/**
95+
* Template function to read multiple items of any type of variable, such as structs
96+
*/
9597
template <class T> int readBlock(int address, const T value[], int items)
9698
{
9799
unsigned int i;
98100
for (i = 0; i < (unsigned int)items; i++)
99101
readBlock<T>(address+(i*sizeof(T)),value[i]);
100102
return i;
101103
}
102-
104+
105+
/**
106+
* Template function to read any type of variable, such as structs
107+
*/
103108
template <class T> int readBlock(int address, const T& value)
104109
{
105110
eeprom_read_block((void*)&value, (const void*)address, sizeof(value));
106111
return sizeof(value);
107112
}
108113

114+
/**
115+
* Template function to write multiple items of any type of variable, such as structs
116+
*/
109117
template <class T> int writeBlock(int address, const T value[], int items)
110118
{
111119
if (!isWriteOk(address+items*sizeof(T))) return 0;
@@ -114,14 +122,21 @@ class EEPROMClassEx
114122
writeBlock<T>(address+(i*sizeof(T)),value[i]);
115123
return i;
116124
}
117-
125+
126+
/**
127+
* Template function to write any type of variable, such as structs
128+
*/
118129
template <class T> int writeBlock(int address, const T& value)
119130
{
120131
if (!isWriteOk(address+sizeof(value))) return 0;
121132
eeprom_write_block((void*)&value, (void*)address, sizeof(value));
122133
return sizeof(value);
123134
}
124-
135+
136+
/**
137+
* Template function to update multiple items of any type of variable, such as structs
138+
* The EEPROM will only be overwritten if different. This will reduce wear.
139+
*/
125140
template <class T> int updateBlock(int address, const T value[], int items)
126141
{
127142
int writeCount=0;
@@ -132,6 +147,10 @@ class EEPROMClassEx
132147
return writeCount;
133148
}
134149

150+
/**
151+
* Template function to update any type of variable, such as structs
152+
* The EEPROM will only be overwritten if different. This will reduce wear.
153+
*/
135154
template <class T> int updateBlock(int address, const T& value)
136155
{
137156
int writeCount=0;
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h1>EEPROMEx documentation</h1>
2+
<p><a href="html/class_e_e_p_r_o_m_class_ex.html">Browse the EEPROMEx documentation</a></p>

0 commit comments

Comments
 (0)