summaryrefslogtreecommitdiffstats
path: root/tmk_core/common/chibios
diff options
context:
space:
mode:
authorskullY <skullydazed@gmail.com>2019-08-30 11:19:03 -0700
committerskullydazed <skullydazed@users.noreply.github.com>2019-08-30 15:01:52 -0700
commitb624f32f944acdc59dcb130674c09090c5c404cb (patch)
treebc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /tmk_core/common/chibios
parent61af76a10d00aba185b8338604171de490a13e3b (diff)
clang-format changes
Diffstat (limited to 'tmk_core/common/chibios')
-rw-r--r--tmk_core/common/chibios/bootloader.c63
-rw-r--r--[-rwxr-xr-x]tmk_core/common/chibios/eeprom_stm32.c142
-rw-r--r--[-rwxr-xr-x]tmk_core/common/chibios/eeprom_stm32.h64
-rw-r--r--tmk_core/common/chibios/eeprom_teensy.c782
-rw-r--r--[-rwxr-xr-x]tmk_core/common/chibios/flash_stm32.c162
-rw-r--r--[-rwxr-xr-x]tmk_core/common/chibios/flash_stm32.h15
-rw-r--r--tmk_core/common/chibios/printf.c277
-rw-r--r--tmk_core/common/chibios/printf.h59
-rw-r--r--tmk_core/common/chibios/sleep_led.c128
-rw-r--r--tmk_core/common/chibios/suspend.c46
-rw-r--r--tmk_core/common/chibios/timer.c46
11 files changed, 827 insertions, 957 deletions
diff --git a/tmk_core/common/chibios/bootloader.c b/tmk_core/common/chibios/bootloader.c
index f9895237b9..4cf5dae7e6 100644
--- a/tmk_core/common/chibios/bootloader.c
+++ b/tmk_core/common/chibios/bootloader.c
@@ -7,63 +7,62 @@
/* STM32 */
/* This code should be checked whether it runs correctly on platforms */
-#define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
+# define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
extern uint32_t __ram0_end__;
-#define BOOTLOADER_MAGIC 0xDEADBEEF
-#define MAGIC_ADDR (unsigned long*)(SYMVAL(__ram0_end__) - 4)
-
+# define BOOTLOADER_MAGIC 0xDEADBEEF
+# define MAGIC_ADDR (unsigned long *)(SYMVAL(__ram0_end__) - 4)
/** \brief Jump to the bootloader
*
* FIXME: needs doc
*/
void bootloader_jump(void) {
- *MAGIC_ADDR = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader
- NVIC_SystemReset();
+ *MAGIC_ADDR = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader
+ NVIC_SystemReset();
}
/** \brief Enter bootloader mode if requested
*
* FIXME: needs doc
*/
-void enter_bootloader_mode_if_requested(void) {
- unsigned long* check = MAGIC_ADDR;
- if(*check == BOOTLOADER_MAGIC) {
- *check = 0;
- __set_CONTROL(0);
- __set_MSP(*(__IO uint32_t*)STM32_BOOTLOADER_ADDRESS);
- __enable_irq();
+void enter_bootloader_mode_if_requested(void) {
+ unsigned long *check = MAGIC_ADDR;
+ if (*check == BOOTLOADER_MAGIC) {
+ *check = 0;
+ __set_CONTROL(0);
+ __set_MSP(*(__IO uint32_t *)STM32_BOOTLOADER_ADDRESS);
+ __enable_irq();
- typedef void (*BootJump_t)(void);
- BootJump_t boot_jump = *(BootJump_t*)(STM32_BOOTLOADER_ADDRESS + 4);
- boot_jump();
- while(1);
- }
- }
+ typedef void (*BootJump_t)(void);
+ BootJump_t boot_jump = *(BootJump_t *)(STM32_BOOTLOADER_ADDRESS + 4);
+ boot_jump();
+ while (1)
+ ;
+ }
+}
#elif defined(KL2x) || defined(K20x) /* STM32_BOOTLOADER_ADDRESS */
/* Kinetis */
-#if defined(KIIBOHD_BOOTLOADER)
+# if defined(KIIBOHD_BOOTLOADER)
/* Kiibohd Bootloader (MCHCK and Infinity KB) */
-#define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000
+# define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000
const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff";
-void bootloader_jump(void) {
- __builtin_memcpy((void *)VBAT, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic));
- // request reset
- SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk;
+void bootloader_jump(void) {
+ __builtin_memcpy((void *)VBAT, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic));
+ // request reset
+ SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk;
}
-#else /* defined(KIIBOHD_BOOTLOADER) */
+# else /* defined(KIIBOHD_BOOTLOADER) */
/* Default for Kinetis - expecting an ARM Teensy */
-#include "wait.h"
+# include "wait.h"
void bootloader_jump(void) {
- wait_ms(100);
- __BKPT(0);
+ wait_ms(100);
+ __BKPT(0);
}
-#endif /* defined(KIIBOHD_BOOTLOADER) */
+# endif /* defined(KIIBOHD_BOOTLOADER) */
#else /* neither STM32 nor KINETIS */
-__attribute__((weak))
-void bootloader_jump(void) {}
+__attribute__((weak)) void bootloader_jump(void) {}
#endif
diff --git a/tmk_core/common/chibios/eeprom_stm32.c b/tmk_core/common/chibios/eeprom_stm32.c
index 4b1abc968d..926b581c6b 100755..100644
--- a/tmk_core/common/chibios/eeprom_stm32.c
+++ b/tmk_core/common/chibios/eeprom_stm32.c
@@ -24,7 +24,7 @@
* the functionality use the EEPROM_Init() function. Be sure that by reprogramming
* of the controller just affected pages will be deleted. In other case the non
* volatile data will be lost.
-******************************************************************************/
+ ******************************************************************************/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
@@ -32,23 +32,22 @@
uint8_t DataBuf[FEE_PAGE_SIZE];
/*****************************************************************************
-* Delete Flash Space used for user Data, deletes the whole space between
-* RW_PAGE_BASE_ADDRESS and the last uC Flash Page
-******************************************************************************/
+ * Delete Flash Space used for user Data, deletes the whole space between
+ * RW_PAGE_BASE_ADDRESS and the last uC Flash Page
+ ******************************************************************************/
uint16_t EEPROM_Init(void) {
// unlock flash
FLASH_Unlock();
// Clear Flags
- //FLASH_ClearFlag(FLASH_SR_EOP|FLASH_SR_PGERR|FLASH_SR_WRPERR);
+ // FLASH_ClearFlag(FLASH_SR_EOP|FLASH_SR_PGERR|FLASH_SR_WRPERR);
return FEE_DENSITY_BYTES;
}
/*****************************************************************************
-* Erase the whole reserved Flash Space used for user Data
-******************************************************************************/
-void EEPROM_Erase (void) {
-
+ * Erase the whole reserved Flash Space used for user Data
+ ******************************************************************************/
+void EEPROM_Erase(void) {
int page_num = 0;
// delete all pages from specified start page to the last page
@@ -58,16 +57,15 @@ void EEPROM_Erase (void) {
} while (page_num < FEE_DENSITY_PAGES);
}
/*****************************************************************************
-* Writes once data byte to flash on specified address. If a byte is already
-* written, the whole page must be copied to a buffer, the byte changed and
-* the manipulated buffer written after PageErase.
-*******************************************************************************/
-uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte) {
-
+ * Writes once data byte to flash on specified address. If a byte is already
+ * written, the whole page must be copied to a buffer, the byte changed and
+ * the manipulated buffer written after PageErase.
+ *******************************************************************************/
+uint16_t EEPROM_WriteDataByte(uint16_t Address, uint8_t DataByte) {
FLASH_Status FlashStatus = FLASH_COMPLETE;
uint32_t page;
- int i;
+ int i;
// exit if desired address is above the limit (e.G. under 2048 Bytes for 4 pages)
if (Address > FEE_DENSITY_BYTES) {
@@ -78,27 +76,25 @@ uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte) {
page = FEE_ADDR_OFFSET(Address) / FEE_PAGE_SIZE;
// if current data is 0xFF, the byte is empty, just overwrite with the new one
- if ((*(__IO uint16_t*)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))) == FEE_EMPTY_WORD) {
-
+ if ((*(__IO uint16_t *)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))) == FEE_EMPTY_WORD) {
FlashStatus = FLASH_ProgramHalfWord(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address), (uint16_t)(0x00FF & DataByte));
} else {
-
// Copy Page to a buffer
- memcpy(DataBuf, (uint8_t*)FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE), FEE_PAGE_SIZE); // !!! Calculate base address for the desired page
+ memcpy(DataBuf, (uint8_t *)FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE), FEE_PAGE_SIZE); // !!! Calculate base address for the desired page
// check if new data is differ to current data, return if not, proceed if yes
- if (DataByte == *(__IO uint8_t*)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))) {
+ if (DataByte == *(__IO uint8_t *)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))) {
return 0;
}
// manipulate desired data byte in temp data array if new byte is differ to the current
DataBuf[FEE_ADDR_OFFSET(Address) % FEE_PAGE_SIZE] = DataByte;
- //Erase Page
+ // Erase Page
FlashStatus = FLASH_ErasePage(FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE));
// Write new data (whole page) to flash if data has been changed
- for(i = 0; i < (FEE_PAGE_SIZE / 2); i++) {
+ for (i = 0; i < (FEE_PAGE_SIZE / 2); i++) {
if ((__IO uint16_t)(0xFF00 | DataBuf[FEE_ADDR_OFFSET(i)]) != 0xFFFF) {
FlashStatus = FLASH_ProgramHalfWord((FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE)) + (i * 2), (uint16_t)(0xFF00 | DataBuf[FEE_ADDR_OFFSET(i)]));
}
@@ -107,98 +103,86 @@ uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte) {
return FlashStatus;
}
/*****************************************************************************
-* Read once data byte from a specified address.
-*******************************************************************************/
-uint8_t EEPROM_ReadDataByte (uint16_t Address) {
-
+ * Read once data byte from a specified address.
+ *******************************************************************************/
+uint8_t EEPROM_ReadDataByte(uint16_t Address) {
uint8_t DataByte = 0xFF;
// Get Byte from specified address
- DataByte = (*(__IO uint8_t*)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address)));
+ DataByte = (*(__IO uint8_t *)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address)));
return DataByte;
}
/*****************************************************************************
-* Wrap library in AVR style functions.
-*******************************************************************************/
-uint8_t eeprom_read_byte (const uint8_t *Address)
-{
- const uint16_t p = (const uint32_t) Address;
+ * Wrap library in AVR style functions.
+ *******************************************************************************/
+uint8_t eeprom_read_byte(const uint8_t *Address) {
+ const uint16_t p = (const uint32_t)Address;
return EEPROM_ReadDataByte(p);
}
-void eeprom_write_byte (uint8_t *Address, uint8_t Value)
-{
- uint16_t p = (uint32_t) Address;
+void eeprom_write_byte(uint8_t *Address, uint8_t Value) {
+ uint16_t p = (uint32_t)Address;
EEPROM_WriteDataByte(p, Value);
}
-void eeprom_update_byte (uint8_t *Address, uint8_t Value)
-{
- uint16_t p = (uint32_t) Address;
+void eeprom_update_byte(uint8_t *Address, uint8_t Value) {
+ uint16_t p = (uint32_t)Address;
EEPROM_WriteDataByte(p, Value);
}
-uint16_t eeprom_read_word (const uint16_t *Address)
-{
- const uint16_t p = (const uint32_t) Address;
- return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8);
+uint16_t eeprom_read_word(const uint16_t *Address) {
+ const uint16_t p = (const uint32_t)Address;
+ return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p + 1) << 8);
}
-void eeprom_write_word (uint16_t *Address, uint16_t Value)
-{
- uint16_t p = (uint32_t) Address;
- EEPROM_WriteDataByte(p, (uint8_t) Value);
- EEPROM_WriteDataByte(p + 1, (uint8_t) (Value >> 8));
+void eeprom_write_word(uint16_t *Address, uint16_t Value) {
+ uint16_t p = (uint32_t)Address;
+ EEPROM_WriteDataByte(p, (uint8_t)Value);
+ EEPROM_WriteDataByte(p + 1, (uint8_t)(Value >> 8));
}
-void eeprom_update_word (uint16_t *Address, uint16_t Value)
-{
- uint16_t p = (uint32_t) Address;
- EEPROM_WriteDataByte(p, (uint8_t) Value);
- EEPROM_WriteDataByte(p + 1, (uint8_t) (Value >> 8));
+void eeprom_update_word(uint16_t *Address, uint16_t Value) {
+ uint16_t p = (uint32_t)Address;
+ EEPROM_WriteDataByte(p, (uint8_t)Value);
+ EEPROM_WriteDataByte(p + 1, (uint8_t)(Value >> 8));
}
-uint32_t eeprom_read_dword (const uint32_t *Address)
-{
- const uint16_t p = (const uint32_t) Address;
- return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8)
- | (EEPROM_ReadDataByte(p+2) << 16) | (EEPROM_ReadDataByte(p+3) << 24);
+uint32_t eeprom_read_dword(const uint32_t *Address) {
+ const uint16_t p = (const uint32_t)Address;
+ return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p + 1) << 8) | (EEPROM_ReadDataByte(p + 2) << 16) | (EEPROM_ReadDataByte(p + 3) << 24);
}
-void eeprom_write_dword (uint32_t *Address, uint32_t Value)
-{
- uint16_t p = (const uint32_t) Address;
- EEPROM_WriteDataByte(p, (uint8_t) Value);
- EEPROM_WriteDataByte(p+1, (uint8_t) (Value >> 8));
- EEPROM_WriteDataByte(p+2, (uint8_t) (Value >> 16));
- EEPROM_WriteDataByte(p+3, (uint8_t) (Value >> 24));
+void eeprom_write_dword(uint32_t *Address, uint32_t Value) {
+ uint16_t p = (const uint32_t)Address;
+ EEPROM_WriteDataByte(p, (uint8_t)Value);
+ EEPROM_WriteDataByte(p + 1, (uint8_t)(Value >> 8));
+ EEPROM_WriteDataByte(p + 2, (uint8_t)(Value >> 16));
+ EEPROM_WriteDataByte(p + 3, (uint8_t)(Value >> 24));
}
-void eeprom_update_dword (uint32_t *Address, uint32_t Value)
-{
- uint16_t p = (const uint32_t) Address;
- uint32_t existingValue = EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8)
- | (EEPROM_ReadDataByte(p+2) << 16) | (EEPROM_ReadDataByte(p+3) << 24);
- if(Value != existingValue){
- EEPROM_WriteDataByte(p, (uint8_t) Value);
- EEPROM_WriteDataByte(p+1, (uint8_t) (Value >> 8));
- EEPROM_WriteDataByte(p+2, (uint8_t) (Value >> 16));
- EEPROM_WriteDataByte(p+3, (uint8_t) (Value >> 24));
+void eeprom_update_dword(uint32_t *Address, uint32_t Value) {
+ uint16_t p = (const uint32_t)Address;
+ uint32_t existingValue = EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p + 1) << 8) | (EEPROM_ReadDataByte(p + 2) << 16) | (EEPROM_ReadDataByte(p + 3) << 24);
+ if (Value != existingValue) {
+ EEPROM_WriteDataByte(p, (uint8_t)Value);
+ EEPROM_WriteDataByte(p + 1, (uint8_t)(Value >> 8));
+ EEPROM_WriteDataByte(p + 2, (uint8_t)(Value >> 16));
+ EEPROM_WriteDataByte(p + 3, (uint8_t)(Value >> 24));
}
}
void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
- const uint8_t *p = (const uint8_t *)addr;
- uint8_t *dest = (uint8_t *)buf;
+ const uint8_t *p = (const uint8_t *)addr;
+ uint8_t * dest = (uint8_t *)buf;
while (len--) {
*dest++ = eeprom_read_byte(p++);
}
}
void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
- uint8_t *p = (uint8_t *)addr;
+ uint8_t * p = (uint8_t *)addr;
const uint8_t *src = (const uint8_t *)buf;
while (len--) {
eeprom_write_byte(p++, *src++);
@@ -206,7 +190,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) {
- uint8_t *p = (uint8_t *)addr;
+ uint8_t * p = (uint8_t *)addr;
const uint8_t *src = (const uint8_t *)buf;
while (len--) {
eeprom_write_byte(p++, *src++);
diff --git a/tmk_core/common/chibios/eeprom_stm32.h b/tmk_core/common/chibios/eeprom_stm32.h
index 083eb16ee6..e689145954 100755..100644
--- a/tmk_core/common/chibios/eeprom_stm32.h
+++ b/tmk_core/common/chibios/eeprom_stm32.h
@@ -31,53 +31,53 @@
// HACK ALERT. This definition may not match your processor
// To Do. Work out correct value for EEPROM_PAGE_SIZE on the STM32F103CT6 etc
#if defined(EEPROM_EMU_STM32F303xC)
- #define MCU_STM32F303CC
+# define MCU_STM32F303CC
#elif defined(EEPROM_EMU_STM32F103xB)
- #define MCU_STM32F103RB
+# define MCU_STM32F103RB
#elif defined(EEPROM_EMU_STM32F072xB)
- #define MCU_STM32F072CB
+# define MCU_STM32F072CB
#else
- #error "not implemented."
+# error "not implemented."
#endif
#ifndef EEPROM_PAGE_SIZE
- #if defined (MCU_STM32F103RB)
- #define FEE_PAGE_SIZE (uint16_t)0x400 // Page size = 1KByte
- #define FEE_DENSITY_PAGES 2 // How many pages are used
- #elif defined (MCU_STM32F103ZE) || defined (MCU_STM32F103RE) || defined (MCU_STM32F103RD) || defined (MCU_STM32F303CC) || defined(MCU_STM32F072CB)
- #define FEE_PAGE_SIZE (uint16_t)0x800 // Page size = 2KByte
- #define FEE_DENSITY_PAGES 4 // How many pages are used
- #else
- #error "No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)."
- #endif
+# if defined(MCU_STM32F103RB)
+# define FEE_PAGE_SIZE (uint16_t)0x400 // Page size = 1KByte
+# define FEE_DENSITY_PAGES 2 // How many pages are used
+# elif defined(MCU_STM32F103ZE) || defined(MCU_STM32F103RE) || defined(MCU_STM32F103RD) || defined(MCU_STM32F303CC) || defined(MCU_STM32F072CB)
+# define FEE_PAGE_SIZE (uint16_t)0x800 // Page size = 2KByte
+# define FEE_DENSITY_PAGES 4 // How many pages are used
+# else
+# error "No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)."
+# endif
#endif
#ifndef EEPROM_START_ADDRESS
- #if defined (MCU_STM32F103RB) || defined(MCU_STM32F072CB)
- #define FEE_MCU_FLASH_SIZE 128 // Size in Kb
- #elif defined (MCU_STM32F103ZE) || defined (MCU_STM32F103RE)
- #define FEE_MCU_FLASH_SIZE 512 // Size in Kb
- #elif defined (MCU_STM32F103RD)
- #define FEE_MCU_FLASH_SIZE 384 // Size in Kb
- #elif defined (MCU_STM32F303CC)
- #define FEE_MCU_FLASH_SIZE 256 // Size in Kb
- #else
- #error "No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)."
- #endif
+# if defined(MCU_STM32F103RB) || defined(MCU_STM32F072CB)
+# define FEE_MCU_FLASH_SIZE 128 // Size in Kb
+# elif defined(MCU_STM32F103ZE) || defined(MCU_STM32F103RE)
+# define FEE_MCU_FLASH_SIZE 512 // Size in Kb
+# elif defined(MCU_STM32F103RD)
+# define FEE_MCU_FLASH_SIZE 384 // Size in Kb
+# elif defined(MCU_STM32F303CC)
+# define FEE_MCU_FLASH_SIZE 256 // Size in Kb
+# else
+# error "No MCU type specified. Add something like -DMCU_STM32F103RB to your compiler arguments (probably in a Makefile)."
+# endif
#endif
// DONT CHANGE
// Choose location for the first EEPROM Page address on the top of flash
#define FEE_PAGE_BASE_ADDRESS ((uint32_t)(0x8000000 + FEE_MCU_FLASH_SIZE * 1024 - FEE_DENSITY_PAGES * FEE_PAGE_SIZE))
-#define FEE_DENSITY_BYTES ((FEE_PAGE_SIZE / 2) * FEE_DENSITY_PAGES - 1)
-#define FEE_LAST_PAGE_ADDRESS (FEE_PAGE_BASE_ADDRESS + (FEE_PAGE_SIZE * FEE_DENSITY_PAGES))
-#define FEE_EMPTY_WORD ((uint16_t)0xFFFF)
-#define FEE_ADDR_OFFSET(Address)(Address * 2) // 1Byte per Word will be saved to preserve Flash
+#define FEE_DENSITY_BYTES ((FEE_PAGE_SIZE / 2) * FEE_DENSITY_PAGES - 1)
+#define FEE_LAST_PAGE_ADDRESS (FEE_PAGE_BASE_ADDRESS + (FEE_PAGE_SIZE * FEE_DENSITY_PAGES))
+#define FEE_EMPTY_WORD ((uint16_t)0xFFFF)
+#define FEE_ADDR_OFFSET(Address) (Address * 2) // 1Byte per Word will be saved to preserve Flash
// Use this function to initialize the functionality
uint16_t EEPROM_Init(void);
-void EEPROM_Erase (void);
-uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte);
-uint8_t EEPROM_ReadDataByte (uint16_t Address);
+void EEPROM_Erase(void);
+uint16_t EEPROM_WriteDataByte(uint16_t Address, uint8_t DataByte);
+uint8_t EEPROM_ReadDataByte(uint16_t Address);
-#endif /* __EEPROM_H */
+#endif /* __EEPROM_H */
diff --git a/tmk_core/common/chibios/eeprom_teensy.c b/tmk_core/common/chibios/eeprom_teensy.c
index 9061b790c4..a4093fb3ba 100644
--- a/tmk_core/common/chibios/eeprom_teensy.c
+++ b/tmk_core/common/chibios/eeprom_teensy.c
@@ -21,10 +21,10 @@
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
- * 1. The above copyright notice and this permission notice shall be
+ * 1. The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
- * 2. If the Software is incorporated into a build system that allows
+ * 2. If the Software is incorporated into a build system that allows
* selection among a list of target devices, then similar target
* devices manufactured by PJRC.COM must be included in the list of
* target devices and selectable in the same manner.
@@ -39,7 +39,6 @@
* SOFTWARE.
*/
-
#if defined(K20x) /* chip selection */
/* Teensy 3.0, 3.1, 3.2; mchck; infinity keyboard */
@@ -51,7 +50,7 @@
// (aligned to 2 or 4 byte boundaries) has twice the endurance
// compared to writing 8 bit bytes.
//
-#define EEPROM_SIZE 32
+# define EEPROM_SIZE 32
// Writing unaligned 16 or 32 bit data is handled automatically when
// this is defined, but at a cost of extra code size. Without this,
@@ -59,286 +58,271 @@
// absolutely sure all 16 and 32 bit writes will be aligned, you can
// remove the extra unnecessary code.
//
-#define HANDLE_UNALIGNED_WRITES
+# define HANDLE_UNALIGNED_WRITES
// Minimum EEPROM Endurance
// ------------------------
-#if (EEPROM_SIZE == 2048) // 35000 writes/byte or 70000 writes/word
- #define EEESIZE 0x33
-#elif (EEPROM_SIZE == 1024) // 75000 writes/byte or 150000 writes/word
- #define EEESIZE 0x34
-#elif (EEPROM_SIZE == 512) // 155000 writes/byte or 310000 writes/word
- #define EEESIZE 0x35
-#elif (EEPROM_SIZE == 256) // 315000 writes/byte or 630000 writes/word
- #define EEESIZE 0x36
-#elif (EEPROM_SIZE == 128) // 635000 writes/byte or 1270000 writes/word
- #define EEESIZE 0x37
-#elif (EEPROM_SIZE == 64) // 1275000 writes/byte or 2550000 writes/word
- #define EEESIZE 0x38
-#elif (EEPROM_SIZE == 32) // 2555000 writes/byte or 5110000 writes/word
- #define EEESIZE 0x39
-#endif
+# if (EEPROM_SIZE == 2048) // 35000 writes/byte or 70000 writes/word
+# define EEESIZE 0x33
+# elif (EEPROM_SIZE == 1024) // 75000 writes/byte or 150000 writes/word
+# define EEESIZE 0x34
+# elif (EEPROM_SIZE == 512) // 155000 writes/byte or 310000 writes/word
+# define EEESIZE 0x35
+# elif (EEPROM_SIZE == 256) // 315000 writes/byte or 630000 writes/word
+# define EEESIZE 0x36
+# elif (EEPROM_SIZE == 128) // 635000 writes/byte or 1270000 writes/word
+# define EEESIZE 0x37
+# elif (EEPROM_SIZE == 64) // 1275000 writes/byte or 2550000 writes/word
+# define EEESIZE 0x38
+# elif (EEPROM_SIZE == 32) // 2555000 writes/byte or 5110000 writes/word
+# define EEESIZE 0x39
+# endif
/** \brief eeprom initialization
*
* FIXME: needs doc
*/
-void eeprom_initialize(void)
-{
- uint32_t count=0;
- uint16_t do_flash_cmd[] = {
- 0xf06f, 0x037f, 0x7003, 0x7803,
- 0xf013, 0x0f80, 0xd0fb, 0x4770};
- uint8_t status;
-
- if (FTFL->FCNFG & FTFL_FCNFG_RAMRDY) {
- // FlexRAM is configured as traditional RAM
- // We need to reconfigure for EEPROM usage
- FTFL->FCCOB0 = 0x80; // PGMPART = Program Partition Command
- FTFL->FCCOB4 = EEESIZE; // EEPROM Size
- FTFL->FCCOB5 = 0x03; // 0K for Dataflash, 32K for EEPROM backup
- __disable_irq();
- // do_flash_cmd() must execute from RAM. Luckily the C syntax is simple...
- (*((void (*)(volatile uint8_t *))((uint32_t)do_flash_cmd | 1)))(&(FTFL->FSTAT));
- __enable_irq();
- status = FTFL->FSTAT;
- if (status & (FTFL_FSTAT_RDCOLERR|FTFL_FSTAT_ACCERR|FTFL_FSTAT_FPVIOL)) {
- FTFL->FSTAT = (status & (FTFL_FSTAT_RDCOLERR|FTFL_FSTAT_ACCERR|FTFL_FSTAT_FPVIOL));
- return; // error
- }
- }
- // wait for eeprom to become ready (is this really necessary?)
- while (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) {
- if (++count > 20000) break;
- }
-}
-
-#define FlexRAM ((uint8_t *)0x14000000)
+void eeprom_initialize(void) {
+ uint32_t count = 0;
+ uint16_t do_flash_cmd[] = {0xf06f, 0x037f, 0x7003, 0x7803, 0xf013, 0x0f80, 0xd0fb, 0x4770};
+ uint8_t status;
+
+ if (FTFL->FCNFG & FTFL_FCNFG_RAMRDY) {
+ // FlexRAM is configured as traditional RAM
+ // We need to reconfigure for EEPROM usage
+ FTFL->FCCOB0 = 0x80; // PGMPART = Program Partition Command
+ FTFL->FCCOB4 = EEESIZE; // EEPROM Size
+ FTFL->FCCOB5 = 0x03; // 0K for Dataflash, 32K for EEPROM backup
+ __disable_irq();
+ // do_flash_cmd() must execute from RAM. Luckily the C syntax is simple...
+ (*((void (*)(volatile uint8_t *))((uint32_t)do_flash_cmd | 1)))(&(FTFL->FSTAT));
+ __enable_irq();
+ status = FTFL->FSTAT;
+ if (status & (FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL)) {
+ FTFL->FSTAT = (status & (FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL));
+ return; // error
+ }
+ }
+ // wait for eeprom to become ready (is this really necessary?)
+ while (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) {
+ if (++count > 20000) break;
+ }
+}
+
+# define FlexRAM ((uint8_t *)0x14000000)
/** \brief eeprom read byte
*
* FIXME: needs doc
*/
-uint8_t eeprom_read_byte(const uint8_t *addr)
-{
- uint32_t offset = (uint32_t)addr;
- if (offset >= EEPROM_SIZE) return 0;
- if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
- return FlexRAM[offset];
+uint8_t eeprom_read_byte(const uint8_t *addr) {
+ uint32_t offset = (uint32_t)addr;
+ if (offset >= EEPROM_SIZE) return 0;
+ if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
+ return FlexRAM[offset];
}
/** \brief eeprom read word
*
* FIXME: needs doc
*/
-uint16_t eeprom_read_word(const uint16_t *addr)
-{
- uint32_t offset = (uint32_t)addr;
- if (offset >= EEPROM_SIZE-1) return 0;
- if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
- return *(uint16_t *)(&FlexRAM[offset]);
+uint16_t eeprom_read_word(const uint16_t *addr) {
+ uint32_t offset = (uint32_t)addr;
+ if (offset >= EEPROM_SIZE - 1) return 0;
+ if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
+ return *(uint16_t *)(&FlexRAM[offset]);
}
/** \brief eeprom read dword
*
* FIXME: needs doc
*/
-uint32_t eeprom_read_dword(const uint32_t *addr)
-{
- uint32_t offset = (uint32_t)addr;
- if (offset >= EEPROM_SIZE-3) return 0;
- if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
- return *(uint32_t *)(&FlexRAM[offset]);
+uint32_t eeprom_read_dword(const uint32_t *addr) {
+ uint32_t offset = (uint32_t)addr;
+ if (offset >= EEPROM_SIZE - 3) return 0;
+ if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
+ return *(uint32_t *)(&FlexRAM[offset]);
}
/** \brief eeprom read block
*
* FIXME: needs doc
*/
-void eeprom_read_block(void *buf, const void *addr, uint32_t len)
-{
- uint32_t offset = (uint32_t)addr;
- uint8_t *dest = (uint8_t *)buf;
- uint32_t end = offset + len;
-
- if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
- if (end > EEPROM_SIZE) end = EEPROM_SIZE;
- while (offset < end) {
- *dest++ = FlexRAM[offset++];
- }
+void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
+ uint32_t offset = (uint32_t)addr;
+ uint8_t *dest = (uint8_t *)buf;
+ uint32_t end = offset + len;
+
+ if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
+ if (end > EEPROM_SIZE) end = EEPROM_SIZE;
+ while (offset < end) {
+ *dest++ = FlexRAM[offset++];
+ }
}
/** \brief eeprom is ready
*
* FIXME: needs doc
*/
-int eeprom_is_ready(void)
-{
- return (FTFL->FCNFG & FTFL_FCNFG_EEERDY) ? 1 : 0;
-}
+int eeprom_is_ready(void) { return (FTFL->FCNFG & FTFL_FCNFG_EEERDY) ? 1 : 0; }
/** \brief flexram wait
*
* FIXME: needs doc
*/
-static void flexram_wait(void)
-{
- while (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) {
- // TODO: timeout
- }
+static void flexram_wait(void) {
+ while (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) {
+ // TODO: timeout
+ }
}
/** \brief eeprom_write_byte
*
* FIXME: needs doc
*/
-void eeprom_write_byte(uint8_t *addr, uint8_t value)
-{
- uint32_t offset = (uint32_t)addr;
+void eeprom_write_byte(uint8_t *addr, uint8_t value) {
+ uint32_t offset = (uint32_t)addr;
- if (offset >= EEPROM_SIZE) return;
- if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
- if (FlexRAM[offset] != value) {
- FlexRAM[offset] = value;
- flexram_wait();
- }
+ if (offset >= EEPROM_SIZE) return;
+ if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
+ if (FlexRAM[offset] != value) {
+ FlexRAM[offset] = value;
+ flexram_wait();
+ }
}
/** \brief eeprom write word
*
* FIXME: needs doc
*/
-void eeprom_write_word(uint16_t *addr, uint16_t value)
-{
- uint32_t offset = (uint32_t)addr;
-
- if (offset >= EEPROM_SIZE-1) return;
- if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
-#ifdef HANDLE_UNALIGNED_WRITES
- if ((offset & 1) == 0) {
-#endif
- if (*(uint16_t *)(&FlexRAM[offset]) != value) {
- *(uint16_t *)(&FlexRAM[offset]) = value;
- flexram_wait();
- }
-#ifdef HANDLE_UNALIGNED_WRITES
- } else {
- if (FlexRAM[offset] != value) {
- FlexRAM[offset] = value;
- flexram_wait();
- }
- if (FlexRAM[offset + 1] != (value >> 8)) {
- FlexRAM[offset + 1] = value >> 8;
- flexram_wait();
- }
- }
-#endif
+void eeprom_write_word(uint16_t *addr, uint16_t value) {
+ uint32_t offset = (uint32_t)addr;
+
+ if (offset >= EEPROM_SIZE - 1) return;
+ if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
+# ifdef HANDLE_UNALIGNED_WRITES
+ if ((offset & 1) == 0) {
+# endif
+ if (*(uint16_t *)(&FlexRAM[offset]) != value) {
+ *(uint16_t *)(&FlexRAM[offset]) = value;
+ flexram_wait();
+ }
+# ifdef HANDLE_UNALIGNED_WRITES
+ } else {
+ if (FlexRAM[offset] != value) {
+ FlexRAM[offset] = value;
+ flexram_wait();
+ }
+ if (FlexRAM[offset + 1] != (value >> 8)) {
+ FlexRAM[offset + 1] = value >> 8;
+ flexram_wait();
+ }
+ }
+# endif
}
/** \brief eeprom write dword
*
* FIXME: needs doc
*/
-void eeprom_write_dword(uint32_t *addr, uint32_t value)
-{
- uint32_t offset = (uint32_t)addr;
-
- if (offset >= EEPROM_SIZE-3) return;
- if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
-#ifdef HANDLE_UNALIGNED_WRITES
- switch (offset & 3) {
- case 0:
-#endif
- if (*(uint32_t *)(&FlexRAM[offset]) != value) {
- *(uint32_t *)(&FlexRAM[offset]) = value;
- flexram_wait();
- }
- return;
-#ifdef HANDLE_UNALIGNED_WRITES
- case 2:
- if (*(uint16_t *)(&FlexRAM[offset]) != value) {
- *(uint16_t *)(&FlexRAM[offset]) = value;
- flexram_wait();
- }
- if (*(uint16_t *)(&FlexRAM[offset + 2]) != (value >> 16)) {
- *(uint16_t *)(&FlexRAM[offset + 2]) = value >> 16;
- flexram_wait();
- }
- return;
- default:
- if (FlexRAM[offset] != value) {
- FlexRAM[offset] = value;
- flexram_wait();
- }
- if (*(uint16_t *)(&FlexRAM[offset + 1]) != (value >> 8)) {
- *(uint16_t *)(&FlexRAM[offset + 1]) = value >> 8;
- flexram_wait();
- }
- if (FlexRAM[offset + 3] != (value >> 24)) {
- FlexRAM[offset + 3] = value >> 24;
- flexram_wait();
- }
- }
-#endif
+void eeprom_write_dword(uint32_t *addr, uint32_t value) {
+ uint32_t offset = (uint32_t)addr;
+
+ if (offset >= EEPROM_SIZE - 3) return;
+ if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
+# ifdef HANDLE_UNALIGNED_WRITES
+ switch (offset & 3) {
+ case 0:
+# endif
+ if (*(uint32_t *)(&FlexRAM[offset]) != value) {
+ *(uint32_t *)(&FlexRAM[offset]) = value;
+ flexram_wait();
+ }
+ return;
+# ifdef HANDLE_UNALIGNED_WRITES
+ case 2:
+ if (*(uint16_t *)(&FlexRAM[offset]) != value) {
+ *(uint16_t *)(&FlexRAM[offset]) = value;
+ flexram_wait();
+ }
+ if (*(uint16_t *)(&FlexRAM[offset + 2]) != (value >> 16)) {
+ *(uint16_t *)(&FlexRAM[offset + 2]) = value >> 16;
+ flexram_wait();
+ }
+ return;
+ default:
+ if (FlexRAM[offset] != value) {
+ FlexRAM[offset] = value;
+ flexram_wait();
+ }
+ if (*(uint16_t *)(&FlexRAM[offset + 1]) != (value >> 8)) {
+ *(uint16_t *)(&FlexRAM[offset + 1]) = value >> 8;
+ flexram_wait();
+ }
+ if (FlexRAM[offset + 3] != (value >> 24)) {
+ FlexRAM[offset + 3] = value >> 24;
+ flexram_wait();
+ }
+ }
+# endif
}
/** \brief eeprom write block
*
* FIXME: needs doc
*/
-void eeprom_write_block(const void *buf, void *addr, uint32_t len)
-{
- uint32_t offset = (uint32_t)addr;
- const uint8_t *src = (const uint8_t *)buf;
-
- if (offset >= EEPROM_SIZE) return;
- if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
- if (len >= EEPROM_SIZE) len = EEPROM_SIZE;
- if (offset + len >= EEPROM_SIZE) len = EEPROM_SIZE - offset;
- while (len > 0) {
- uint32_t lsb = offset & 3;
- if (lsb == 0 && len >= 4) {
- // write aligned 32 bits
- uint32_t val32;
- val32 = *src++;
- val32 |= (*src++ << 8);
- val32 |= (*src++ << 16);
- val32 |= (*src++ << 24);
- if (*(uint32_t *)(&FlexRAM[offset]) != val32) {
- *(uint32_t *)(&FlexRAM[offset]) = val32;
- flexram_wait();
- }
- offset += 4;
- len -= 4;
- } else if ((lsb == 0 || lsb == 2) && len >= 2) {
- // write aligned 16 bits