aboutsummaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-09-15 09:21:36 +0100
committerGitHub <noreply@github.com>2021-09-15 01:21:36 -0700
commitfa141a5a8fc3b3f439385db990ec34ad3bbbcb16 (patch)
tree6b8f1107ab2f3b896ebef97ef30156a2e9eae3e1 /tmk_core
parentb63453a75bc3e49802c7df1d2ff5b2ea95a5354f (diff)
downloadqmk_firmware-fa141a5a8fc3b3f439385db990ec34ad3bbbcb16.tar.gz
qmk_firmware-fa141a5a8fc3b3f439385db990ec34ad3bbbcb16.zip
Migrate STM32_EEPROM_ENABLE to use EEPROM_DRIVER (#14433)
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/common/chibios/eeprom_stm32.c57
-rw-r--r--tmk_core/common/test/rules.mk1
2 files changed, 10 insertions, 48 deletions
diff --git a/tmk_core/common/chibios/eeprom_stm32.c b/tmk_core/common/chibios/eeprom_stm32.c
index 1fdf8c1e2..acc6a4851 100644
--- a/tmk_core/common/chibios/eeprom_stm32.c
+++ b/tmk_core/common/chibios/eeprom_stm32.c
@@ -620,48 +620,11 @@ uint16_t EEPROM_ReadDataWord(uint16_t Address) {
620} 620}
621 621
622/***************************************************************************** 622/*****************************************************************************
623 * Wrap library in AVR style functions. 623 * Bind to eeprom_driver.c
624 *******************************************************************************/ 624 *******************************************************************************/
625uint8_t eeprom_read_byte(const uint8_t *Address) { return EEPROM_ReadDataByte((const uintptr_t)Address); } 625void eeprom_driver_init(void) { EEPROM_Init(); }
626 626
627void eeprom_write_byte(uint8_t *Address, uint8_t Value) { EEPROM_WriteDataByte((uintptr_t)Address, Value); } 627void eeprom_driver_erase(void) { EEPROM_Erase(); }
628
629void eeprom_update_byte(uint8_t *Address, uint8_t Value) { EEPROM_WriteDataByte((uintptr_t)Address, Value); }
630
631uint16_t eeprom_read_word(const uint16_t *Address) { return EEPROM_ReadDataWord((const uintptr_t)Address); }
632
633void eeprom_write_word(uint16_t *Address, uint16_t Value) { EEPROM_WriteDataWord((uintptr_t)Address, Value); }
634
635void eeprom_update_word(uint16_t *Address, uint16_t Value) { EEPROM_WriteDataWord((uintptr_t)Address, Value); }
636
637uint32_t eeprom_read_dword(const uint32_t *Address) {
638 const uint16_t p = (const uintptr_t)Address;
639 /* Check word alignment */
640 if (p % 2) {
641 /* Not aligned */
642 return (uint32_t)EEPROM_ReadDataByte(p) | (uint32_t)(EEPROM_ReadDataWord(p + 1) << 8) | (uint32_t)(EEPROM_ReadDataByte(p + 3) << 24);
643 } else {
644 /* Aligned */
645 return EEPROM_ReadDataWord(p) | (EEPROM_ReadDataWord(p + 2) << 16);
646 }
647}
648
649void eeprom_write_dword(uint32_t *Address, uint32_t Value) {
650 uint16_t p = (const uintptr_t)Address;
651 /* Check word alignment */
652 if (p % 2) {
653 /* Not aligned */
654 EEPROM_WriteDataByte(p, (uint8_t)Value);
655 EEPROM_WriteDataWord(p + 1, (uint16_t)(Value >> 8));
656 EEPROM_WriteDataByte(p + 3, (uint8_t)(Value >> 24));
657 } else {
658 /* Aligned */
659 EEPROM_WriteDataWord(p, (uint16_t)Value);
660 EEPROM_WriteDataWord(p + 2, (uint16_t)(Value >> 16));
661 }
662}
663
664void eeprom_update_dword(uint32_t *Address, uint32_t Value) { eeprom_write_dword(Address, Value); }
665 628
666void eeprom_read_block(void *buf, const void *addr, size_t len) { 629void eeprom_read_block(void *buf, const void *addr, size_t len) {
667 const uint8_t *src = (const uint8_t *)addr; 630 const uint8_t *src = (const uint8_t *)addr;
@@ -670,14 +633,14 @@ void eeprom_read_block(void *buf, const void *addr, size_t len) {
670 /* Check word alignment */ 633 /* Check word alignment */
671 if (len && (uintptr_t)src % 2) { 634 if (len && (uintptr_t)src % 2) {
672 /* Read the unaligned first byte */ 635 /* Read the unaligned first byte */
673 *dest++ = eeprom_read_byte(src++); 636 *dest++ = EEPROM_ReadDataByte((const uintptr_t)src++);
674 --len; 637 --len;
675 } 638 }
676 639
677 uint16_t value; 640 uint16_t value;
678 bool aligned = ((uintptr_t)dest % 2 == 0); 641 bool aligned = ((uintptr_t)dest % 2 == 0);
679 while (len > 1) { 642 while (len > 1) {
680 value = eeprom_read_word((uint16_t *)src); 643 value = EEPROM_ReadDataWord((const uintptr_t)((uint16_t *)src));
681 if (aligned) { 644 if (aligned) {
682 *(uint16_t *)dest = value; 645 *(uint16_t *)dest = value;
683 dest += 2; 646 dest += 2;
@@ -689,7 +652,7 @@ void eeprom_read_block(void *buf, const void *addr, size_t len) {
689 len -= 2; 652 len -= 2;
690 } 653 }
691 if (len) { 654 if (len) {
692 *dest = eeprom_read_byte(src); 655 *dest = EEPROM_ReadDataByte((const uintptr_t)src);
693 } 656 }
694} 657}
695 658
@@ -700,7 +663,7 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) {
700 /* Check word alignment */ 663 /* Check word alignment */
701 if (len && (uintptr_t)dest % 2) { 664 if (len && (uintptr_t)dest % 2) {
702 /* Write the unaligned first byte */ 665 /* Write the unaligned first byte */
703 eeprom_write_byte(dest++, *src++); 666 EEPROM_WriteDataByte((uintptr_t)dest++, *src++);
704 --len; 667 --len;
705 } 668 }
706 669
@@ -712,15 +675,13 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) {
712 } else { 675 } else {
713 value = *(uint8_t *)src | (*(uint8_t *)(src + 1) << 8); 676 value = *(uint8_t *)src | (*(uint8_t *)(src + 1) << 8);
714 } 677 }
715 eeprom_write_word((uint16_t *)dest, value); 678 EEPROM_WriteDataWord((uintptr_t)((uint16_t *)dest), value);
716 dest += 2; 679 dest += 2;
717 src += 2; 680 src += 2;
718 len -= 2; 681 len -= 2;
719 } 682 }
720 683
721 if (len) { 684 if (len) {
722 eeprom_write_byte(dest, *src); 685 EEPROM_WriteDataByte((uintptr_t)dest, *src);
723 } 686 }
724} 687}
725
726void eeprom_update_block(const void *buf, void *addr, size_t len) { eeprom_write_block(buf, addr, len); }
diff --git a/tmk_core/common/test/rules.mk b/tmk_core/common/test/rules.mk
index 48632a095..73d2302da 100644
--- a/tmk_core/common/test/rules.mk
+++ b/tmk_core/common/test/rules.mk
@@ -16,6 +16,7 @@ eeprom_stm32_tiny_INC := $(eeprom_stm32_INC)
16eeprom_stm32_large_INC := $(eeprom_stm32_INC) 16eeprom_stm32_large_INC := $(eeprom_stm32_INC)
17 17
18eeprom_stm32_SRC := \ 18eeprom_stm32_SRC := \
19 $(TOP_DIR)/drivers/eeprom/eeprom_driver.c \
19 $(TMK_PATH)/common/test/eeprom_stm32_tests.cpp \ 20 $(TMK_PATH)/common/test/eeprom_stm32_tests.cpp \
20 $(TMK_PATH)/common/test/flash_stm32_mock.c \ 21 $(TMK_PATH)/common/test/flash_stm32_mock.c \
21 $(TMK_PATH)/common/chibios/eeprom_stm32.c 22 $(TMK_PATH)/common/chibios/eeprom_stm32.c