summaryrefslogtreecommitdiff
path: root/tmk_core/common
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2019-11-06 08:04:50 +1100
committerNick Brassel <nick@tzarc.org>2020-01-24 12:45:58 +1100
commitd13ada11622977bcc0b530212b4405229805016d (patch)
tree3f8874ac3c9b5950b1fed6ac4d0081a268d9f487 /tmk_core/common
parent6ff093efbee21d3f64f5b4bfdbc66d4648490523 (diff)
Add customisable EEPROM driver selection (#7274)
- uprintf -> dprintf - Fix atsam "vendor" eeprom. - Bump Kinetis K20x to 64 bytes, too. - Rollback Kinetis to 32 bytes as partitioning can only be done once. Add warning about changing the value. - Change RAM-backed "fake" EEPROM implementations to match eeconfig's current usage. - Add 24LC128 by request.
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/arm_atsam/eeprom.c13
-rw-r--r--tmk_core/common/chibios/eeprom_stm32.c6
-rw-r--r--tmk_core/common/chibios/eeprom_teensy.c25
-rw-r--r--tmk_core/common/eeconfig.c10
-rw-r--r--tmk_core/common/eeprom.h9
-rw-r--r--tmk_core/common/test/eeprom.c6
6 files changed, 48 insertions, 21 deletions
diff --git a/tmk_core/common/arm_atsam/eeprom.c b/tmk_core/common/arm_atsam/eeprom.c
index 44a0bf4d76..a69f382823 100644
--- a/tmk_core/common/arm_atsam/eeprom.c
+++ b/tmk_core/common/arm_atsam/eeprom.c
@@ -16,9 +16,12 @@
#include "eeprom.h"
-#define EEPROM_SIZE 32
+#ifndef EEPROM_SIZE
+# include "eeconfig.h"
+# define EEPROM_SIZE (((EECONFIG_SIZE+3)/4)*4) // based off eeconfig's current usage, aligned to 4-byte sizes, to deal with LTO
+#endif
-static uint8_t buffer[EEPROM_SIZE];
+__attribute__((aligned(4))) static uint8_t buffer[EEPROM_SIZE];
uint8_t eeprom_read_byte(const uint8_t *addr) {
uintptr_t offset = (uintptr_t)addr;
@@ -40,7 +43,7 @@ uint32_t eeprom_read_dword(const uint32_t *addr) {
return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8) | (eeprom_read_byte(p + 2) << 16) | (eeprom_read_byte(p + 3) << 24);
}
-void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
+void eeprom_read_block(void *buf, const void *addr, size_t len) {
const uint8_t *p = (const uint8_t *)addr;
uint8_t * dest = (uint8_t *)buf;
while (len--) {
@@ -62,7 +65,7 @@ void eeprom_write_dword(uint32_t *addr, uint32_t value) {
eeprom_write_byte(p, value >> 24);
}
-void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
+void eeprom_write_block(const void *buf, void *addr, size_t len) {
uint8_t * p = (uint8_t *)addr;
const uint8_t *src = (const uint8_t *)buf;
while (len--) {
@@ -86,7 +89,7 @@ void eeprom_update_dword(uint32_t *addr, uint32_t value) {
eeprom_write_byte(p, value >> 24);
}
-void eeprom_update_block(const void *buf, void *addr, uint32_t len) {
+void eeprom_update_block(const void *buf, void *addr, size_t len) {
uint8_t * p = (uint8_t *)addr;
const uint8_t *src = (const uint8_t *)buf;
while (len--) {
diff --git a/tmk_core/common/chibios/eeprom_stm32.c b/tmk_core/common/chibios/eeprom_stm32.c
index 926b581c6b..ea51989728 100644
--- a/tmk_core/common/chibios/eeprom_stm32.c
+++ b/tmk_core/common/chibios/eeprom_stm32.c
@@ -173,7 +173,7 @@ void eeprom_update_dword(uint32_t *Address, uint32_t Value) {
}
}
-void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
+void eeprom_read_block(void *buf, const void *addr, size_t len) {
const uint8_t *p = (const uint8_t *)addr;
uint8_t * dest = (uint8_t *)buf;
while (len--) {
@@ -181,7 +181,7 @@ void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
}
}
-void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
+void eeprom_write_block(const void *buf, void *addr, size_t len) {
uint8_t * p = (uint8_t *)addr;
const uint8_t *src = (const uint8_t *)buf;
while (len--) {
@@ -189,7 +189,7 @@ void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
}
}
-void eeprom_update_block(const void *buf, void *addr, uint32_t len) {
+void eeprom_update_block(const void *buf, void *addr, size_t len) {
uint8_t * p = (uint8_t *)addr;
const uint8_t *src = (const uint8_t *)buf;
while (len--) {
diff --git a/tmk_core/common/chibios/eeprom_teensy.c b/tmk_core/common/chibios/eeprom_teensy.c
index a4093fb3ba..0fab9f73d6 100644
--- a/tmk_core/common/chibios/eeprom_teensy.c
+++ b/tmk_core/common/chibios/eeprom_teensy.c
@@ -50,7 +50,17 @@
// (aligned to 2 or 4 byte boundaries) has twice the endurance
// compared to writing 8 bit bytes.
//
-# define EEPROM_SIZE 32
+# ifndef EEPROM_SIZE
+# define EEPROM_SIZE 32
+# endif
+
+/*
+ ^^^ Here be dragons:
+ NXP AppNote AN4282 section 3.1 states that partitioning must only be done once.
+ Once EEPROM partitioning is done, the size is locked to this initial configuration.
+ Attempts to modify the EEPROM_SIZE setting may brick your board.
+*/
+
// Writing unaligned 16 or 32 bit data is handled automatically when
// this is defined, but at a cost of extra code size. Without this,
@@ -517,8 +527,11 @@ void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
#else
// No EEPROM supported, so emulate it
-# define EEPROM_SIZE 32
-static uint8_t buffer[EEPROM_SIZE];
+# ifndef EEPROM_SIZE
+# include "eeconfig.h"
+# define EEPROM_SIZE (((EECONFIG_SIZE+3)/4)*4) // based off eeconfig's current usage, aligned to 4-byte sizes, to deal with LTO
+# endif
+__attribute__((aligned(4))) static uint8_t buffer[EEPROM_SIZE];
uint8_t eeprom_read_byte(const uint8_t *addr) {
uint32_t offset = (uint32_t)addr;
@@ -540,7 +553,7 @@ uint32_t eeprom_read_dword(const uint32_t *addr) {
return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8) | (eeprom_read_byte(p + 2) << 16) | (eeprom_read_byte(p + 3) << 24);
}
-void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
+void eeprom_read_block(void *buf, const void *addr, size_t len) {
const uint8_t *p = (const uint8_t *)addr;
uint8_t * dest = (uint8_t *)buf;
while (len--) {
@@ -562,7 +575,7 @@ void eeprom_write_dword(uint32_t *addr, uint32_t value) {
eeprom_write_byte(p, value >> 24);
}
-void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
+void eeprom_write_block(const void *buf, void *addr, size_t len) {
uint8_t * p = (uint8_t *)addr;
const uint8_t *src = (const uint8_t *)buf;
while (len--) {
@@ -589,7 +602,7 @@ void eeprom_update_dword(uint32_t *addr, uint32_t value) {
eeprom_write_byte(p, value >> 24);
}
-void eeprom_update_block(const void *buf, void *addr, uint32_t len) {
+void eeprom_update_block(const void *buf, void *addr, size_t len) {
uint8_t * p = (uint8_t *)addr;
const uint8_t *src = (const uint8_t *)buf;
while (len--) {
diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c
index 7cec4bd7df..fe56c57d11 100644
--- a/tmk_core/common/eeconfig.c
+++ b/tmk_core/common/eeconfig.c
@@ -9,6 +9,10 @@
# include "eeprom_stm32.h"
#endif
+#if defined(EEPROM_DRIVER)
+# include "eeprom_driver.h"
+#endif
+
/** \brief eeconfig enable
*
* FIXME: needs doc
@@ -32,6 +36,9 @@ void eeconfig_init_quantum(void) {
#ifdef STM32_EEPROM_ENABLE
EEPROM_Erase();
#endif
+#if defined(EEPROM_DRIVER)
+ eeprom_driver_erase();
+#endif
eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
eeprom_update_byte(EECONFIG_DEBUG, 0);
eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0);
@@ -81,6 +88,9 @@ void eeconfig_disable(void) {
#ifdef STM32_EEPROM_ENABLE
EEPROM_Erase();
#endif
+#if defined(EEPROM_DRIVER)
+ eeprom_driver_erase();
+#endif
eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF);
}
diff --git a/tmk_core/common/eeprom.h b/tmk_core/common/eeprom.h
index fcd1667c06..8a81e70668 100644
--- a/tmk_core/common/eeprom.h
+++ b/tmk_core/common/eeprom.h
@@ -1,23 +1,24 @@
#ifndef TMK_CORE_COMMON_EEPROM_H_
#define TMK_CORE_COMMON_EEPROM_H_
-#if defined(__AVR__)
+#if defined(__AVR__) && !defined(EEPROM_DRIVER)
# include <avr/eeprom.h>
#else
# include <stdint.h>
+# include <stdlib.h>
uint8_t eeprom_read_byte(const uint8_t *__p);
uint16_t eeprom_read_word(const uint16_t *__p);
uint32_t eeprom_read_dword(const uint32_t *__p);
-void eeprom_read_block(void *__dst, const void *__src, uint32_t __n);
+void eeprom_read_block(void *__dst, const void *__src, size_t __n);
void eeprom_write_byte(uint8_t *__p, uint8_t __value);
void eeprom_write_word(uint16_t *__p, uint16_t __value);
void eeprom_write_dword(uint32_t *__p, uint32_t __value);
-void eeprom_write_block(const void *__src, void *__dst, uint32_t __n);
+void eeprom_write_block(const void *__src, void *__dst, size_t __n);
void eeprom_update_byte(uint8_t *__p, uint8_t __value);
void eeprom_update_word(uint16_t *__p, uint16_t __value);
void eeprom_update_dword(uint32_t *__p, uint32_t __value);
-void eeprom_update_block(const void *__src, void *__dst, uint32_t __n);
+void eeprom_update_block(const void *__src, void *__dst, size_t __n);
#endif
#endif /* TMK_CORE_COMMON_EEPROM_H_ */
diff --git a/tmk_core/common/test/eeprom.c b/tmk_core/common/test/eeprom.c
index 44a0bf4d76..5c8e69dae3 100644
--- a/tmk_core/common/test/eeprom.c
+++ b/tmk_core/common/test/eeprom.c
@@ -40,7 +40,7 @@ uint32_t eeprom_read_dword(const uint32_t *addr) {
return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8) | (eeprom_read_byte(p + 2) << 16) | (eeprom_read_byte(p + 3) << 24);
}
-void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
+void eeprom_read_block(void *buf, const void *addr, size_t len) {
const uint8_t *p = (const uint8_t *)addr;
uint8_t * dest = (uint8_t *)buf;
while (len--) {
@@ -62,7 +62,7 @@ void eeprom_write_dword(uint32_t *addr, uint32_t value) {
eeprom_write_byte(p, value >> 24);
}
-void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
+void eeprom_write_block(const void *buf, void *addr, size_t len) {
uint8_t * p = (uint8_t *)addr;
const uint8_t *src = (const uint8_t *)buf;
while (len--) {
@@ -86,7 +86,7 @@ void eeprom_update_dword(uint32_t *addr, uint32_t value) {
eeprom_write_byte(p, value >> 24);
}
-void eeprom_update_block(const void *buf, void *addr, uint32_t len) {
+void eeprom_update_block(const void *buf, void *addr, size_t len) {
uint8_t * p = (uint8_t *)addr;
const uint8_t *src = (const uint8_t *)buf;
while (len--) {