diff options
Diffstat (limited to 'tmk_core/common/test/eeprom.c')
-rw-r--r-- | tmk_core/common/test/eeprom.c | 83 |
1 files changed, 40 insertions, 43 deletions
diff --git a/tmk_core/common/test/eeprom.c b/tmk_core/common/test/eeprom.c index 61cc039ef..44a0bf4d7 100644 --- a/tmk_core/common/test/eeprom.c +++ b/tmk_core/common/test/eeprom.c | |||
@@ -21,78 +21,75 @@ | |||
21 | static uint8_t buffer[EEPROM_SIZE]; | 21 | static uint8_t buffer[EEPROM_SIZE]; |
22 | 22 | ||
23 | uint8_t eeprom_read_byte(const uint8_t *addr) { | 23 | uint8_t eeprom_read_byte(const uint8_t *addr) { |
24 | uintptr_t offset = (uintptr_t)addr; | 24 | uintptr_t offset = (uintptr_t)addr; |
25 | return buffer[offset]; | 25 | return buffer[offset]; |
26 | } | 26 | } |
27 | 27 | ||
28 | void eeprom_write_byte(uint8_t *addr, uint8_t value) { | 28 | void eeprom_write_byte(uint8_t *addr, uint8_t value) { |
29 | uintptr_t offset = (uintptr_t)addr; | 29 | uintptr_t offset = (uintptr_t)addr; |
30 | buffer[offset] = value; | 30 | buffer[offset] = value; |
31 | } | 31 | } |
32 | 32 | ||
33 | uint16_t eeprom_read_word(const uint16_t *addr) { | 33 | uint16_t eeprom_read_word(const uint16_t *addr) { |
34 | const uint8_t *p = (const uint8_t *)addr; | 34 | const uint8_t *p = (const uint8_t *)addr; |
35 | return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8); | 35 | return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8); |
36 | } | 36 | } |
37 | 37 | ||
38 | uint32_t eeprom_read_dword(const uint32_t *addr) { | 38 | uint32_t eeprom_read_dword(const uint32_t *addr) { |
39 | const uint8_t *p = (const uint8_t *)addr; | 39 | const uint8_t *p = (const uint8_t *)addr; |
40 | return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8) | 40 | return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8) | (eeprom_read_byte(p + 2) << 16) | (eeprom_read_byte(p + 3) << 24); |
41 | | (eeprom_read_byte(p+2) << 16) | (eeprom_read_byte(p+3) << 24); | ||
42 | } | 41 | } |
43 | 42 | ||
44 | void eeprom_read_block(void *buf, const void *addr, uint32_t len) { | 43 | void eeprom_read_block(void *buf, const void *addr, uint32_t len) { |
45 | const uint8_t *p = (const uint8_t *)addr; | 44 | const uint8_t *p = (const uint8_t *)addr; |
46 | uint8_t *dest = (uint8_t *)buf; | 45 | uint8_t * dest = (uint8_t *)buf; |
47 | while (len--) { | 46 | while (len--) { |
48 | *dest++ = eeprom_read_byte(p++); | 47 | *dest++ = eeprom_read_byte(p++); |
49 | } | 48 | } |
50 | } | 49 | } |
51 | 50 | ||
52 | void eeprom_write_word(uint16_t *addr, uint16_t value) { | 51 | void eeprom_write_word(uint16_t *addr, uint16_t value) { |
53 | uint8_t *p = (uint8_t *)addr; | 52 | uint8_t *p = (uint8_t *)addr; |
54 | eeprom_write_byte(p++, value); | 53 | eeprom_write_byte(p++, value); |
55 | eeprom_write_byte(p, value >> 8); | 54 | eeprom_write_byte(p, value >> 8); |
56 | } | 55 | } |
57 | 56 | ||
58 | void eeprom_write_dword(uint32_t *addr, uint32_t value) { | 57 | void eeprom_write_dword(uint32_t *addr, uint32_t value) { |
59 | uint8_t *p = (uint8_t *)addr; | 58 | uint8_t *p = (uint8_t *)addr; |
60 | eeprom_write_byte(p++, value); | 59 | eeprom_write_byte(p++, value); |
61 | eeprom_write_byte(p++, value >> 8); | 60 | eeprom_write_byte(p++, value >> 8); |
62 | eeprom_write_byte(p++, value >> 16); | 61 | eeprom_write_byte(p++, value >> 16); |
63 | eeprom_write_byte(p, value >> 24); | 62 | eeprom_write_byte(p, value >> 24); |
64 | } | 63 | } |
65 | 64 | ||
66 | void eeprom_write_block(const void *buf, void *addr, uint32_t len) { | 65 | void eeprom_write_block(const void *buf, void *addr, uint32_t len) { |
67 | uint8_t *p = (uint8_t *)addr; | 66 | uint8_t * p = (uint8_t *)addr; |
68 | const uint8_t *src = (const uint8_t *)buf; | 67 | const uint8_t *src = (const uint8_t *)buf; |
69 | while (len--) { | 68 | while (len--) { |
70 | eeprom_write_byte(p++, *src++); | 69 | eeprom_write_byte(p++, *src++); |
71 | } | 70 | } |
72 | } | 71 | } |
73 | 72 | ||
74 | void eeprom_update_byte(uint8_t *addr, uint8_t value) { | 73 | void eeprom_update_byte(uint8_t *addr, uint8_t value) { eeprom_write_byte(addr, value); } |
75 | eeprom_write_byte(addr, value); | ||
76 | } | ||
77 | 74 | ||
78 | void eeprom_update_word(uint16_t *addr, uint16_t value) { | 75 | void eeprom_update_word(uint16_t *addr, uint16_t value) { |
79 | uint8_t *p = (uint8_t *)addr; | 76 | uint8_t *p = (uint8_t *)addr; |
80 | eeprom_write_byte(p++, value); | 77 | eeprom_write_byte(p++, value); |
81 | eeprom_write_byte(p, value >> 8); | 78 | eeprom_write_byte(p, value >> 8); |
82 | } | 79 | } |
83 | 80 | ||
84 | void eeprom_update_dword(uint32_t *addr, uint32_t value) { | 81 | void eeprom_update_dword(uint32_t *addr, uint32_t value) { |
85 | uint8_t *p = (uint8_t *)addr; | 82 | uint8_t *p = (uint8_t *)addr; |
86 | eeprom_write_byte(p++, value); | 83 | eeprom_write_byte(p++, value); |
87 | eeprom_write_byte(p++, value >> 8); | 84 | eeprom_write_byte(p++, value >> 8); |
88 | eeprom_write_byte(p++, value >> 16); | 85 | eeprom_write_byte(p++, value >> 16); |
89 | eeprom_write_byte(p, value >> 24); | 86 | eeprom_write_byte(p, value >> 24); |
90 | } | 87 | } |
91 | 88 | ||
92 | void eeprom_update_block(const void *buf, void *addr, uint32_t len) { | 89 | void eeprom_update_block(const void *buf, void *addr, uint32_t len) { |
93 | uint8_t *p = (uint8_t *)addr; | 90 | uint8_t * p = (uint8_t *)addr; |
94 | const uint8_t *src = (const uint8_t *)buf; | 91 | const uint8_t *src = (const uint8_t *)buf; |
95 | while (len--) { | 92 | while (len--) { |
96 | eeprom_write_byte(p++, *src++); | 93 | eeprom_write_byte(p++, *src++); |
97 | } | 94 | } |
98 | } | 95 | } |