diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/eeprom_24cxx.c | 86 | ||||
-rw-r--r-- | firmware/eeprom_settings.c | 8 | ||||
-rw-r--r-- | firmware/export/eeprom_24cxx.h | 6 |
3 files changed, 56 insertions, 44 deletions
diff --git a/firmware/drivers/eeprom_24cxx.c b/firmware/drivers/eeprom_24cxx.c index 33c02f1bc8..75521ce2db 100644 --- a/firmware/drivers/eeprom_24cxx.c +++ b/firmware/drivers/eeprom_24cxx.c | |||
@@ -103,9 +103,9 @@ static void sw_i2c_ack(void) | |||
103 | DELAY; | 103 | DELAY; |
104 | } | 104 | } |
105 | 105 | ||
106 | static int sw_i2c_getack(void) | 106 | static bool sw_i2c_getack(void) |
107 | { | 107 | { |
108 | int ret = 1; | 108 | bool ret = true; |
109 | int count = 10; | 109 | int count = 10; |
110 | 110 | ||
111 | SCL_LO; | 111 | SCL_LO; |
@@ -119,7 +119,7 @@ static int sw_i2c_getack(void) | |||
119 | 119 | ||
120 | if (SDA) | 120 | if (SDA) |
121 | /* ack failed */ | 121 | /* ack failed */ |
122 | ret = 0; | 122 | ret = false; |
123 | 123 | ||
124 | SCL_LO; | 124 | SCL_LO; |
125 | SCL_OUTPUT; | 125 | SCL_OUTPUT; |
@@ -132,22 +132,23 @@ static int sw_i2c_getack(void) | |||
132 | 132 | ||
133 | static void sw_i2c_outb(unsigned char byte) | 133 | static void sw_i2c_outb(unsigned char byte) |
134 | { | 134 | { |
135 | int i; | 135 | int i; |
136 | |||
137 | /* clock out each bit, MSB first */ | ||
138 | for ( i=0x80; i; i>>=1 ) { | ||
139 | SCL_LO; | ||
140 | DELAY; | ||
141 | if ( i & byte ) | ||
142 | SDA_HI; | ||
143 | else | ||
144 | SDA_LO; | ||
145 | DELAY; | ||
146 | SCL_HI; | ||
147 | DELAY; | ||
148 | } | ||
149 | 136 | ||
150 | // SDA_LO; | 137 | /* clock out each bit, MSB first */ |
138 | for ( i=0x80; i; i>>=1 ) | ||
139 | { | ||
140 | SCL_LO; | ||
141 | DELAY; | ||
142 | if ( i & byte ) | ||
143 | SDA_HI; | ||
144 | else | ||
145 | SDA_LO; | ||
146 | DELAY; | ||
147 | SCL_HI; | ||
148 | DELAY; | ||
149 | } | ||
150 | |||
151 | // SDA_LO; | ||
151 | } | 152 | } |
152 | 153 | ||
153 | static unsigned char sw_i2c_inb(void) | 154 | static unsigned char sw_i2c_inb(void) |
@@ -274,7 +275,7 @@ void eeprom_24cxx_init(void) | |||
274 | sw_i2c_init(); | 275 | sw_i2c_init(); |
275 | } | 276 | } |
276 | 277 | ||
277 | bool eeprom_24cxx_read_byte(unsigned int address, char *c) | 278 | int eeprom_24cxx_read_byte(unsigned int address, char *c) |
278 | { | 279 | { |
279 | int ret; | 280 | int ret; |
280 | char byte; | 281 | char byte; |
@@ -283,29 +284,31 @@ bool eeprom_24cxx_read_byte(unsigned int address, char *c) | |||
283 | if (address >= EEPROM_SIZE) | 284 | if (address >= EEPROM_SIZE) |
284 | { | 285 | { |
285 | logf("EEPROM address: %d", address); | 286 | logf("EEPROM address: %d", address); |
286 | return false; | 287 | return -9; |
287 | } | 288 | } |
288 | 289 | ||
289 | *c = 0; | 290 | *c = 0; |
290 | do { | 291 | do |
292 | { | ||
291 | ret = sw_i2c_read(address, &byte); | 293 | ret = sw_i2c_read(address, &byte); |
292 | if (ret < 0) | 294 | if (ret < 0) |
293 | { | 295 | { |
296 | /* keep between {} as logf is whitespace in normal builds */ | ||
294 | logf("EEPROM Fail: %d/%d", ret, address); | 297 | logf("EEPROM Fail: %d/%d", ret, address); |
295 | } | 298 | } |
296 | } while (ret < 0 && count--) ; | 299 | } while (ret < 0 && count--); |
297 | 300 | ||
298 | if (ret < 0) | 301 | if (ret < 0) |
299 | { | 302 | { |
300 | logf("EEPROM RFail: %d/%d", ret, address); | 303 | logf("EEPROM RFail: %d/%d", ret, address); |
301 | return false; | 304 | return ret; |
302 | } | 305 | } |
303 | 306 | ||
304 | *c = byte; | 307 | *c = byte; |
305 | return true; | 308 | return 0; |
306 | } | 309 | } |
307 | 310 | ||
308 | bool eeprom_24cxx_write_byte(unsigned int address, char c) | 311 | int eeprom_24cxx_write_byte(unsigned int address, char c) |
309 | { | 312 | { |
310 | int ret; | 313 | int ret; |
311 | int count = 100; | 314 | int count = 100; |
@@ -313,41 +316,50 @@ bool eeprom_24cxx_write_byte(unsigned int address, char c) | |||
313 | if (address >= EEPROM_SIZE) | 316 | if (address >= EEPROM_SIZE) |
314 | { | 317 | { |
315 | logf("EEPROM address: %d", address); | 318 | logf("EEPROM address: %d", address); |
316 | return false; | 319 | return -9; |
317 | } | 320 | } |
318 | 321 | ||
319 | do { | 322 | do |
323 | { | ||
320 | ret = sw_i2c_write_byte(address, c); | 324 | ret = sw_i2c_write_byte(address, c); |
325 | if (ret < 0) | ||
326 | { | ||
327 | /* keep between {} as logf is whitespace in normal builds */ | ||
328 | logf("EEPROM Fail: %d/%d", ret, address); | ||
329 | } | ||
321 | } while (ret < 0 && count--) ; | 330 | } while (ret < 0 && count--) ; |
322 | 331 | ||
323 | if (ret < 0) | 332 | if (ret < 0) |
324 | { | 333 | { |
325 | logf("EEPROM WFail: %d/%d", ret, address); | 334 | logf("EEPROM WFail: %d/%d", ret, address); |
326 | return false; | 335 | return ret; |
327 | } | 336 | } |
328 | 337 | ||
329 | return true; | 338 | return 0; |
330 | } | 339 | } |
331 | 340 | ||
332 | bool eeprom_24cxx_read(unsigned char address, void *dest, int length) | 341 | int eeprom_24cxx_read(unsigned char address, void *dest, int length) |
333 | { | 342 | { |
334 | char *buf = (char *)dest; | 343 | char *buf = (char *)dest; |
344 | int ret = 0; | ||
335 | int i; | 345 | int i; |
336 | 346 | ||
337 | for (i = 0; i < length; i++) | 347 | for (i = 0; i < length; i++) |
338 | { | 348 | { |
339 | if (!eeprom_24cxx_read_byte(address+i, &buf[i])) | 349 | ret = eeprom_24cxx_read_byte(address+i, &buf[i]); |
340 | return false; | 350 | if (ret < 0) |
351 | return ret; | ||
341 | } | 352 | } |
342 | 353 | ||
343 | return true; | 354 | return ret; |
344 | } | 355 | } |
345 | 356 | ||
346 | bool eeprom_24cxx_write(unsigned char address, const void *src, int length) | 357 | int eeprom_24cxx_write(unsigned char address, const void *src, int length) |
347 | { | 358 | { |
348 | const char *buf = (const char *)src; | 359 | const char *buf = (const char *)src; |
349 | int count = 10; | 360 | int count = 10; |
350 | int i, ok; | 361 | int i; |
362 | bool ok; | ||
351 | 363 | ||
352 | while (count-- > 0) | 364 | while (count-- > 0) |
353 | { | 365 | { |
@@ -369,9 +381,9 @@ bool eeprom_24cxx_write(unsigned char address, const void *src, int length) | |||
369 | } | 381 | } |
370 | 382 | ||
371 | if (ok) | 383 | if (ok) |
372 | return true; | 384 | return 0; |
373 | } | 385 | } |
374 | 386 | ||
375 | return false; | 387 | return -1; |
376 | } | 388 | } |
377 | 389 | ||
diff --git a/firmware/eeprom_settings.c b/firmware/eeprom_settings.c index 43f519d3fa..e472f4df07 100644 --- a/firmware/eeprom_settings.c +++ b/firmware/eeprom_settings.c | |||
@@ -37,7 +37,7 @@ static void reset_config(void) | |||
37 | 37 | ||
38 | bool eeprom_settings_init(void) | 38 | bool eeprom_settings_init(void) |
39 | { | 39 | { |
40 | bool ret; | 40 | int ret; |
41 | uint32_t sum; | 41 | uint32_t sum; |
42 | 42 | ||
43 | eeprom_24cxx_init(); | 43 | eeprom_24cxx_init(); |
@@ -54,7 +54,7 @@ bool eeprom_settings_init(void) | |||
54 | ret = eeprom_24cxx_read(0, &firmware_settings, | 54 | ret = eeprom_24cxx_read(0, &firmware_settings, |
55 | sizeof(struct eeprom_settings)); | 55 | sizeof(struct eeprom_settings)); |
56 | 56 | ||
57 | if (!ret) | 57 | if (ret < 0) |
58 | { | 58 | { |
59 | memset(&firmware_settings, 0, sizeof(struct eeprom_settings)); | 59 | memset(&firmware_settings, 0, sizeof(struct eeprom_settings)); |
60 | firmware_settings.initialized = false; | 60 | firmware_settings.initialized = false; |
@@ -92,7 +92,7 @@ bool eeprom_settings_init(void) | |||
92 | 92 | ||
93 | bool eeprom_settings_store(void) | 93 | bool eeprom_settings_store(void) |
94 | { | 94 | { |
95 | bool ret; | 95 | int ret; |
96 | uint32_t sum; | 96 | uint32_t sum; |
97 | 97 | ||
98 | if (!firmware_settings.initialized || !detect_flashed_rockbox()) | 98 | if (!firmware_settings.initialized || !detect_flashed_rockbox()) |
@@ -108,7 +108,7 @@ bool eeprom_settings_store(void) | |||
108 | ret = eeprom_24cxx_write(0, &firmware_settings, | 108 | ret = eeprom_24cxx_write(0, &firmware_settings, |
109 | sizeof(struct eeprom_settings)); | 109 | sizeof(struct eeprom_settings)); |
110 | 110 | ||
111 | if (!ret) | 111 | if (ret < 0) |
112 | firmware_settings.initialized = false; | 112 | firmware_settings.initialized = false; |
113 | 113 | ||
114 | return ret; | 114 | return ret; |
diff --git a/firmware/export/eeprom_24cxx.h b/firmware/export/eeprom_24cxx.h index d4f00818e2..bc0f444f7e 100644 --- a/firmware/export/eeprom_24cxx.h +++ b/firmware/export/eeprom_24cxx.h | |||
@@ -24,9 +24,9 @@ | |||
24 | #define EEPROM_SIZE 128 | 24 | #define EEPROM_SIZE 128 |
25 | 25 | ||
26 | void eeprom_24cxx_init(void); | 26 | void eeprom_24cxx_init(void); |
27 | bool eeprom_24cxx_read_byte(unsigned int address, char *c); | 27 | int eeprom_24cxx_read_byte(unsigned int address, char *c); |
28 | bool eeprom_24cxx_read(unsigned char address, void *dest, int length); | 28 | int eeprom_24cxx_read(unsigned char address, void *dest, int length); |
29 | bool eeprom_24cxx_write(unsigned char address, const void *src, int length); | 29 | int eeprom_24cxx_write(unsigned char address, const void *src, int length); |
30 | 30 | ||
31 | #endif | 31 | #endif |
32 | 32 | ||