|
@@ -68,37 +68,6 @@ void eeprom_write_byte(uint8_t *pos, unsigned char value) {
|
68
|
68
|
delay(EEPROM_WRITE_DELAY);
|
69
|
69
|
}
|
70
|
70
|
|
71
|
|
-// WARNING: address is a page address, 6-bit end will wrap around
|
72
|
|
-// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
|
73
|
|
-void eeprom_update_block(const void *pos, void *__dst, size_t n) {
|
74
|
|
- const unsigned eeprom_address = (unsigned)__dst;
|
75
|
|
-
|
76
|
|
- eeprom_init();
|
77
|
|
-
|
78
|
|
- Wire.beginTransmission(eeprom_device_address);
|
79
|
|
- Wire.write(int(eeprom_address >> 8)); // MSB
|
80
|
|
- Wire.write(int(eeprom_address & 0xFF)); // LSB
|
81
|
|
- Wire.endTransmission();
|
82
|
|
-
|
83
|
|
- uint8_t *ptr = (uint8_t*)pos;
|
84
|
|
- uint8_t flag = 0;
|
85
|
|
- Wire.requestFrom(eeprom_device_address, (byte)n);
|
86
|
|
- for (byte c = 0; c < n && Wire.available(); c++)
|
87
|
|
- flag |= Wire.read() ^ ptr[c];
|
88
|
|
-
|
89
|
|
- if (flag) {
|
90
|
|
- Wire.beginTransmission(eeprom_device_address);
|
91
|
|
- Wire.write(int(eeprom_address >> 8)); // MSB
|
92
|
|
- Wire.write(int(eeprom_address & 0xFF)); // LSB
|
93
|
|
- Wire.write((uint8_t*)pos, n);
|
94
|
|
- Wire.endTransmission();
|
95
|
|
-
|
96
|
|
- // wait for write cycle to complete
|
97
|
|
- // this could be done more efficiently with "acknowledge polling"
|
98
|
|
- delay(EEPROM_WRITE_DELAY);
|
99
|
|
- }
|
100
|
|
-}
|
101
|
|
-
|
102
|
71
|
uint8_t eeprom_read_byte(uint8_t *pos) {
|
103
|
72
|
const unsigned eeprom_address = (unsigned)pos;
|
104
|
73
|
|
|
@@ -110,19 +79,4 @@ uint8_t eeprom_read_byte(uint8_t *pos) {
|
110
|
79
|
return Wire.available() ? Wire.read() : 0xFF;
|
111
|
80
|
}
|
112
|
81
|
|
113
|
|
-// Don't read more than 30..32 bytes at a time!
|
114
|
|
-void eeprom_read_block(void* pos, const void *__dst, size_t n) {
|
115
|
|
- const unsigned eeprom_address = (unsigned)__dst;
|
116
|
|
-
|
117
|
|
- eeprom_init();
|
118
|
|
-
|
119
|
|
- Wire.beginTransmission(eeprom_device_address);
|
120
|
|
- Wire.write(int(eeprom_address >> 8)); // MSB
|
121
|
|
- Wire.write(int(eeprom_address & 0xFF)); // LSB
|
122
|
|
- Wire.endTransmission();
|
123
|
|
- Wire.requestFrom(eeprom_device_address, (byte)n);
|
124
|
|
- for (byte c = 0; c < n; c++ )
|
125
|
|
- if (Wire.available()) *((uint8_t*)pos + c) = Wire.read();
|
126
|
|
-}
|
127
|
|
-
|
128
|
82
|
#endif // USE_SHARED_EEPROM && I2C_EEPROM
|