Skip to content

Commit a9d2a8e

Browse files
committed
Conflicts: EEPROMEx/EEPROMex.h
2 parents 5638236 + 20b37f1 commit a9d2a8e

File tree

2 files changed

+108
-100
lines changed

2 files changed

+108
-100
lines changed

EEPROMex.h

+98-99
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
#include <avr/eeprom.h>
3030

3131
// Boards with ATmega328, Duemilanove, Uno, UnoSMD, Lilypad - 1024 bytes (1 kilobyte)
32-
// Boards with ATmega1280 or 2560, Arduino Mega series – 4096 bytes (4 kilobytes)
33-
// Boards with ATmega168, Lilypad, old Nano, Diecimila – 512 bytes (1/2 kilobyte)
32+
// Boards with ATmega1280 or 2560, Arduino Mega series – 4096 bytes (4 kilobytes)
33+
// Boards with ATmega168, Lilypad, old Nano, Diecimila – 512 bytes (1/2 kilobyte)
3434

3535
#define EEPROMSizeATmega168 512
3636
#define EEPROMSizeATmega328 1024
@@ -55,112 +55,111 @@
5555

5656
class EEPROMClassEx
5757
{
58-
58+
5959
public:
60-
EEPROMClassEx();
61-
bool isReady();
62-
int writtenBytes();
63-
void setMemPool(int base, int memSize);
64-
void setMaxAllowedWrites(int allowedWrites);
65-
int getAddress(int noOfBytes);
60+
EEPROMClassEx();
61+
bool isReady();
62+
int writtenBytes();
63+
void setMemPool(int base, int memSize);
64+
void setMaxAllowedWrites(int allowedWrites);
65+
int getAddress(int noOfBytes);
6666

67-
uint8_t read(int);
68-
bool readBit(int, byte);
69-
uint8_t readByte(int);
67+
uint8_t read(int);
68+
bool readBit(int, byte);
69+
uint8_t readByte(int);
7070
uint16_t readInt(int);
7171
uint32_t readLong(int);
72-
float readFloat(int);
73-
double readDouble(int);
74-
72+
float readFloat(int);
73+
double readDouble(int);
74+
7575
bool write(int, uint8_t);
76-
bool writeBit(int , uint8_t, bool);
77-
bool writeByte(int, uint8_t);
78-
bool writeInt(int, uint16_t);
79-
bool writeLong(int, uint32_t);
80-
bool writeFloat(int, float);
81-
bool writeDouble(int, double);
82-
83-
bool update(int, uint8_t);
84-
bool updateBit(int , uint8_t, bool);
85-
bool updateByte(int, uint8_t);
86-
bool updateInt(int, uint16_t);
87-
bool updateLong(int, uint32_t);
88-
bool updateFloat(int, float);
89-
bool updateDouble(int, double);
90-
91-
76+
bool writeBit(int , uint8_t, bool);
77+
bool writeByte(int, uint8_t);
78+
bool writeInt(int, uint16_t);
79+
bool writeLong(int, uint32_t);
80+
bool writeFloat(int, float);
81+
bool writeDouble(int, double);
82+
83+
bool update(int, uint8_t);
84+
bool updateBit(int , uint8_t, bool);
85+
bool updateByte(int, uint8_t);
86+
bool updateInt(int, uint16_t);
87+
bool updateLong(int, uint32_t);
88+
bool updateFloat(int, float);
89+
bool updateDouble(int, double);
90+
91+
9292
// Use template for other data formats
9393

9494

95-
template <class T> int readBlock(int address, const T value[], int items)
96-
{
97-
if (!isWriteOk(address+items*sizeof(T))) return 0;
98-
unsigned int i;
99-
for (i = 0; i < (unsigned int)items; i++)
100-
readBlock<T>(address+(i*sizeof(T)),value[i]);
101-
return i;
102-
}
103-
104-
template <class T> int readBlock(int address, const T& value)
105-
{
106-
eeprom_read_block((void*)&value, (const void*)address, sizeof(value));
107-
return sizeof(value);
108-
}
109-
110-
template <class T> int writeBlock(int address, const T value[], int items)
111-
{
112-
if (!isWriteOk(address+items*sizeof(T))) return 0;
113-
unsigned int i;
114-
for (i = 0; i < (unsigned int)items; i++)
115-
writeBlock<T>(address+(i*sizeof(T)),value[i]);
116-
return i;
117-
}
118-
119-
template <class T> int writeBlock(int address, const T& value)
120-
{
121-
if (!isWriteOk(address+sizeof(value))) return 0;
122-
eeprom_write_block((void*)&value, (void*)address, sizeof(value));
123-
return sizeof(value);
124-
}
125-
126-
template <class T> int updateBlock(int address, const T value[], int items)
127-
{
128-
int writeCount=0;
129-
if (!isWriteOk(address+items*sizeof(T))) return 0;
130-
unsigned int i;
131-
for (i = 0; i < (unsigned int)items; i++)
132-
writeCount+= updateBlock<T>(address+(i*sizeof(T)),value[i]);
133-
return writeCount;
134-
}
135-
136-
template <class T> int updateBlock(int address, const T& value)
137-
{
138-
int writeCount=0;
139-
if (!isWriteOk(address+sizeof(value))) return 0;
140-
const byte* bytePointer = (const byte*)(const void*)&value;
141-
for (unsigned int i = 0; i < (unsigned int)sizeof(value); i++) {
142-
if (read(address)!=*bytePointer) {
143-
write(address, *bytePointer);
144-
writeCount++;
145-
}
146-
address++;
147-
bytePointer++;
148-
}
149-
return writeCount;
150-
}
151-
152-
153-
95+
template <class T> int readBlock(int address, const T value[], int items)
96+
{
97+
unsigned int i;
98+
for (i = 0; i < (unsigned int)items; i++)
99+
readBlock<T>(address+(i*sizeof(T)),value[i]);
100+
return i;
101+
}
102+
103+
template <class T> int readBlock(int address, const T& value)
104+
{
105+
eeprom_read_block((void*)&value, (const void*)address, sizeof(value));
106+
return sizeof(value);
107+
}
108+
109+
template <class T> int writeBlock(int address, const T value[], int items)
110+
{
111+
if (!isWriteOk(address+items*sizeof(T))) return 0;
112+
unsigned int i;
113+
for (i = 0; i < (unsigned int)items; i++)
114+
writeBlock<T>(address+(i*sizeof(T)),value[i]);
115+
return i;
116+
}
117+
118+
template <class T> int writeBlock(int address, const T& value)
119+
{
120+
if (!isWriteOk(address+sizeof(value))) return 0;
121+
eeprom_write_block((void*)&value, (void*)address, sizeof(value));
122+
return sizeof(value);
123+
}
124+
125+
template <class T> int updateBlock(int address, const T value[], int items)
126+
{
127+
int writeCount=0;
128+
if (!isWriteOk(address+items*sizeof(T))) return 0;
129+
unsigned int i;
130+
for (i = 0; i < (unsigned int)items; i++)
131+
writeCount+= updateBlock<T>(address+(i*sizeof(T)),value[i]);
132+
return writeCount;
133+
}
134+
135+
template <class T> int updateBlock(int address, const T& value)
136+
{
137+
int writeCount=0;
138+
if (!isWriteOk(address+sizeof(value))) return 0;
139+
const byte* bytePointer = (const byte*)(const void*)&value;
140+
for (unsigned int i = 0; i < (unsigned int)sizeof(value); i++) {
141+
if (read(address)!=*bytePointer) {
142+
write(address, *bytePointer);
143+
writeCount++;
144+
}
145+
address++;
146+
bytePointer++;
147+
}
148+
return writeCount;
149+
}
150+
151+
152+
154153
private:
155-
//Private variables
156-
static int _base;
157-
static int _memSize;
158-
static int _nextAvailableaddress;
159-
static int _writeCounts;
160-
int _allowedWrites;
161-
bool checkWrite(int base,int noOfBytes);
162-
bool isWriteOk(int address);
163-
bool isReadOk(int address);
154+
//Private variables
155+
static int _base;
156+
static int _memSize;
157+
static int _nextAvailableaddress;
158+
static int _writeCounts;
159+
int _allowedWrites;
160+
bool checkWrite(int base,int noOfBytes);
161+
bool isWriteOk(int address);
162+
bool isReadOk(int address);
164163
};
165164

166165
extern EEPROMClassEx EEPROM;

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The EEPROMex library is an extension of the standard Arduino EEPROM library. It
1212
* Debugging of writing out of memory range.
1313

1414
You can download the library here:
15-
[http://thijs.elenbaas.net/downloads/?did=3](http://thijs.elenbaas.net/downloads/?did=3)
15+
[http://thijs.elenbaas.net/downloads/?did=3](http://thijs.elenbaas.net/downloads)
1616

1717
And find detailed explanation and samples of the functionality here:
1818
[http://thijs.elenbaas.net/2012/07/extended-eeprom-library-for-arduino](http://thijs.elenbaas.net/2012/07/extended-eeprom-library-for-arduino)
@@ -109,6 +109,9 @@ Based on processor:
109109
*EEPROMSizeATmega168
110110
*EEPROMSizeATmega328
111111
*EEPROMSizeATmega1280
112+
*EEPROMSizeATmega32u4
113+
*EEPROMSizeAT90USB1286
114+
*EEPROMSizeMK20DX128
112115
```
113116
Based on board:
114117
```
@@ -119,6 +122,12 @@ Based on board:
119122
*EEPROMSizeMega
120123
*EEPROMSizeDiecimila
121124
*EEPROMSizeNano
125+
*EEPROMSizeTeensy2
126+
*EEPROMSizeLeonardo
127+
*EEPROMSizeMicro
128+
*EEPROMSizeYun
129+
*EEPROMSizeTeensy2pp
130+
*EEPROMSizeTeensy3
122131
```
123132

124133
### EEPROM performance

0 commit comments

Comments
 (0)