Skip to content

Commit e156f8f

Browse files
committed
Update doc and examples.
1 parent be39537 commit e156f8f

File tree

4 files changed

+46
-47
lines changed

4 files changed

+46
-47
lines changed

README.md

+38-39
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ I2C bus speed.
7676

7777
## Constructor
7878

79-
### JC_EEPROM(eeprom_size_t devCap, byte nDev, unsigned int pgSize, byte busAddr)
79+
### JC_EEPROM(eeprom_size_t devCap, uint8_t nDev, uint16_t pgSize, uint8_t busAddr)
8080
##### Description
8181
Instantiates an external EEPROM object.
8282
##### Syntax
83-
`JC_EEPROM myEEPROM(eeprom_size_t devCap, byte nDev, unsigned int pgSize, byte busAddr));`
83+
`JC_EEPROM myEEPROM(eeprom_size_t devCap, uint8_t nDev, uint16_t pgSize, uint8_t busAddr));`
8484
##### Parameters
8585
**devCap** *(eeprom_size_t)*: The size of one EEPROM device in k-bits. Choose a value from the eeprom_size_t enumeration above.
86-
**nDev** *(byte)*: The number of EEPROM devices on the bus. Note that if there are multiple EEPROM devices on the bus, they must be identical and each must have its address pins strapped properly.
87-
**pgSize** *(unsigned int)*: The EEPROM page size in bytes. Consult the datasheet if you are unsure of the page size.
88-
**busAddr** *(byte)*: The base I2C bus address for the EEPROM(s). 0x50 is a common value and this parameter can be omitted, in which case 0x50 will be used as the default.
86+
**nDev** *(uint8_t)*: The number of EEPROM devices on the bus. Note that if there are multiple EEPROM devices on the bus, they must be identical and each must have its address pins strapped properly.
87+
**pgSize** *(uint16_t)*: The EEPROM page size in bytes. Consult the datasheet if you are unsure of the page size.
88+
**busAddr** *(uint8_t)*: The base I2C bus address for the EEPROM(s). 0x50 is a common value and this parameter can be omitted, in which case 0x50 will be used as the default.
8989
##### Example
9090
```c++
9191
JC_EEPROM myEEPROM(kbits_256, 2, 64); //two 24LC256 EEPROMS on the bus
@@ -101,31 +101,31 @@ Initializes the library. Call this method once in the setup code. begin() does a
101101
##### Parameters
102102
**freq** *(twiClockFreq_t)*: The desired I2C bus speed, `JC_EEPROM::twiClock100kHz` or `JC_EEPROM::twiClock400kHz`. Can be omitted in which case it will default to `twiClock100kHz`. **NOTE:** When using 400kHz, if there are other devices on the bus they must all support a 400kHz bus speed. **Secondly**, the other devices should be initialized first, as other libraries may not support adjusting the bus speed. To ensure the desired speed is set, call the JC_EEPROM.begin() function *after* initializing all other I2C devices.
103103
##### Returns
104-
I2C I/O status, zero if successful *(byte)*. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of other return codes.
104+
I2C I/O status, zero if successful *(uint8_t)*. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of other return codes.
105105
##### Example
106106
```c++
107107
JC_EEPROM myEEPROM(kbits_256, 2, 64);
108-
byte i2cStat = myEEPROM.begin(JC_EEPROM::twiClock400kHz);
108+
uint8_t i2cStat = myEEPROM.begin(JC_EEPROM::twiClock400kHz);
109109
if ( i2cStat != 0 ) {
110110
//there was a problem
111111
}
112112
```
113-
### write(unsigned long addr, byte* values, unsigned int nBytes)
113+
### write(uint32_t addr, uint8_t* values, uint16_t nBytes)
114114
##### Description
115115
Write one or more bytes to external EEPROM.
116116
##### Syntax
117-
`myEEPROM.write(unsigned long addr, byte* values, byte nBytes);`
117+
`myEEPROM.write(uint32_t addr, uint8_t* values, uint16_t nBytes);`
118118
##### Parameters
119-
**addr** *(unsigned long)*: The beginning EEPROM location to write.
120-
**values** _(byte*)_: Pointer to an array containing the data to write.
121-
**nBytes** *(unsigned int)*: The number of bytes to write.
119+
**addr** *(uint32_t)*: The beginning EEPROM location to write.
120+
**values** _(uint8_t*)_: Pointer to an array containing the data to write.
121+
**nBytes** *(uint16_t)*: The number of bytes to write.
122122
##### Returns
123-
I2C I/O status, zero if successful *(byte)*. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of other return codes. Returns a status of EEPROM_ADDR_ERR if the I/O would extend past the top of the EEPROM address space.
123+
I2C I/O status, zero if successful *(uint8_t)*. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of other return codes. Returns a status of EEPROM_ADDR_ERR if the I/O would extend past the top of the EEPROM address space.
124124
##### Example
125125
```c++
126-
byte myData[10];
126+
uint8_t myData[10];
127127
//write 10 bytes starting at location 42
128-
byte i2cStat = myEEPROM.write(42, myData, 10);
128+
uint8_t i2cStat = myEEPROM.write(42, myData, 10);
129129
if ( i2cStat != 0 ) {
130130
//there was a problem
131131
if ( i2cStat == EEPROM_ADDR_ERR) {
@@ -136,37 +136,37 @@ if ( i2cStat != 0 ) {
136136
}
137137
}
138138
```
139-
### write(unsigned long addr, byte value)
139+
### write(uint32_t addr, uint8_t value)
140140
##### Description
141141
Writes a single byte to external EEPROM.
142142
##### Syntax
143-
`myEEPROM.write(unsigned long addr, byte value);`
143+
`myEEPROM.write(uint32_t addr, uint8_t value);`
144144
##### Parameters
145-
**addr** *(unsigned long)*: The EEPROM location to write.
146-
**values** _(byte)_: The value to write.
145+
**addr** *(uint32_t)*: The EEPROM location to write.
146+
**values** _(uint8_t)_: The value to write.
147147
##### Returns
148148
Same as multiple-byte write() above.
149149
##### Example
150150
```c++
151151
//write the value 16 to EEPROM location 314.
152-
byte i2cStat = myEEPROM.write(314, 16);
152+
uint8_t i2cStat = myEEPROM.write(314, 16);
153153
```
154-
### read(unsigned long addr, byte* values, unsigned int nBytes)
154+
### read(uint32_t addr, uint8_t* values, uint16_t nBytes)
155155
##### Description
156156
Reads one or more bytes from external EEPROM into an array supplied by the caller.
157157
##### Syntax
158-
`myEEPROM.read(unsigned long addr, byte* values, byte nBytes);`
158+
`myEEPROM.read(uint32_t addr, uint8_t* values, uint16_t nBytes);`
159159
##### Parameters
160-
**addr** *(unsigned long)*: The beginning EEPROM location to read from.
161-
**values** _(byte*)_: Pointer to an array to receive the data.
162-
**nBytes** *(unsigned int)*: The number of bytes to read.
160+
**addr** *(uint32_t)*: The beginning EEPROM location to read from.
161+
**values** _(uint8_t*)_: Pointer to an array to receive the data.
162+
**nBytes** *(uint16_t)*: The number of bytes to read.
163163
##### Returns
164-
I2C I/O status, zero if successful *(byte)*. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of other return codes. Returns a status of EEPROM_ADDR_ERR if the I/O would extend past the top of the EEPROM address space.
164+
I2C I/O status, zero if successful *(uint8_t)*. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of other return codes. Returns a status of EEPROM_ADDR_ERR if the I/O would extend past the top of the EEPROM address space.
165165
##### Example
166166
```c++
167-
byte myData[10];
167+
uint8_t myData[10];
168168
//read 10 bytes starting at location 42
169-
byte i2cStat = myEEPROM.read(42, myData, 10);
169+
uint8_t i2cStat = myEEPROM.read(42, myData, 10);
170170
if ( i2cStat != 0 ) {
171171
//there was a problem
172172
if ( i2cStat == EEPROM_ADDR_ERR) {
@@ -177,21 +177,20 @@ if ( i2cStat != 0 ) {
177177
}
178178
}
179179
```
180-
### read(unsigned long addr)
180+
### read(uint32_t addr)
181181
##### Description
182182
Reads a single byte from external EEPROM.
183183
##### Syntax
184-
`myEEPROM.read(unsigned long addr);`
184+
`myEEPROM.read(uint32_t addr);`
185185
##### Parameters
186-
**addr** *(unsigned long)*: The EEPROM location to read from.
186+
**addr** *(uint32_t)*: The EEPROM location to read from.
187187
##### Returns
188-
The data read from EEPROM or an error code *(int)*. To distinguish error values from valid data, error values are returned as negative numbers. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of return codes. Returns a status of EEPROM_ADDR_ERR if the I/O would extend past the top of the EEPROM address space.
188+
The data read from EEPROM or an error code *(int16_t)*. To distinguish error values from valid data, error values are returned as negative numbers. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of return codes. Returns a status of EEPROM_ADDR_ERR if the I/O would extend past the top of the EEPROM address space.
189189

190190
##### Example
191191
```c++
192-
int myData;
193192
//read a byte from location 42
194-
int readValue = myEEPROM.read(42);
193+
int16_t readValue = myEEPROM.read(42);
195194
if ( readValue < 0 ) {
196195
//there was a problem
197196
if ( -readValue == EEPROM_ADDR_ERR) {
@@ -206,18 +205,18 @@ else {
206205
}
207206
```
208207

209-
### update(unsigned long addr, byte value)
208+
### update(uint32_t addr, uint8_t value)
210209
##### Description
211210
Updates a single byte in external EEPROM. Like `write(addr, value)` except first reads the location from EEPROM and only writes `value` if it differs from the current value stored at the given location, to reduce wear on the EEPROM.
212211
##### Syntax
213-
`myEEPROM.update(unsigned long addr, byte value);`
212+
`myEEPROM.update(uint32_t addr, uint8_t value);`
214213
##### Parameters
215-
**addr** *(unsigned long)*: The EEPROM location to update.
216-
**values** _(byte)_: The value to write.
214+
**addr** *(uint32_t)*: The EEPROM location to update.
215+
**values** _(uint8_t)_: The value to write.
217216
##### Returns
218217
Same as multiple-byte write() above.
219218
##### Example
220219
```c++
221220
// update the value in EEPROM location 314 to 16.
222-
byte i2cStat = myEEPROM.update(314, 16);
221+
uint8_t i2cStat = myEEPROM.update(314, 16);
223222
```

examples/eepromTest/eepromTest.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void eeErase(uint8_t chunk, uint32_t startAddr, uint32_t endAddr)
101101
chunk &= 0xFC; // force chunk to be a multiple of 4
102102
uint8_t data[chunk];
103103
Serial << F("Erasing...") << endl;
104-
for (int i = 0; i < chunk; i++) data[i] = 0xFF;
104+
for (int16_t i = 0; i < chunk; i++) data[i] = 0xFF;
105105
uint32_t msStart = millis();
106106

107107
for (uint32_t a = startAddr; a <= endAddr; a += chunk) {
@@ -128,7 +128,7 @@ void dump(uint32_t startAddr, uint32_t nBytes)
128128
if ( a < 16 * 16 ) Serial << '0';
129129
if ( a < 16 ) Serial << '0';
130130
Serial << _HEX(a) << ' ';
131-
for ( int c = 0; c < 16; c++ ) {
131+
for ( int16_t c = 0; c < 16; c++ ) {
132132
if ( d[c] < 16 ) Serial << '0';
133133
Serial << _HEX( d[c] ) << ( c == 7 ? " " : " " );
134134
}

examples/struct/struct.ino

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
#include <Streaming.h> // https://github.com/janelia-arduino/Streaming
1010

1111
struct myStruct {
12-
int a;
13-
long b;
12+
int16_t a;
13+
int32_t b;
1414
float c;
1515
double d;
16-
byte e;
16+
uint8_t e;
1717
bool f;
1818
};
1919

@@ -27,12 +27,12 @@ void setup()
2727

2828
Serial << "Writing\n";
2929
myStruct w { 1, 2, 3, 4, 5, true };
30-
eep.write(0, reinterpret_cast<byte*>(&w), sizeof(w));
30+
eep.write(0, reinterpret_cast<uint8_t*>(&w), sizeof(w));
3131
printStruct(w);
3232

3333
Serial << "Reading\n";
3434
myStruct r;
35-
eep.read(0, reinterpret_cast<byte*>(&r), sizeof(r));
35+
eep.read(0, reinterpret_cast<uint8_t*>(&r), sizeof(r));
3636
printStruct(r);
3737
}
3838

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=JC_EEPROM
2-
version=1.0.4
2+
version=1.0.5
33
author=Jack Christensen <[email protected]>
44
maintainer=Jack Christensen <[email protected]>
55
sentence=Arduino library to support external I2C EEPROMs.

0 commit comments

Comments
 (0)