From 180132fb70f67ac1d055d8ecfaf25728da0dee09 Mon Sep 17 00:00:00 2001 From: Floris Westerman Date: Sun, 5 Jun 2022 16:29:36 +0200 Subject: [PATCH] Attempt at incorporating EEPROM and rotary encoder fixes --- .vscode/settings.json | 4 ++- keyboards/keychron/q3/chconf.h | 2 ++ keyboards/keychron/q3/config.h | 12 +++++--- keyboards/keychron/q3/halconf.h | 2 +- keyboards/keychron/q3/rev_0121/rev_0121.c | 15 ++++++++++ keyboards/keychron/q3/rev_0121/rules.mk | 1 - platforms/chibios/eeprom_stm32_defs.h | 4 +-- platforms/chibios/eeprom_stm32_l4.c | 2 +- platforms/chibios/flash_stm32.c | 36 +++++++++-------------- quantum/dip_switch.c | 2 +- 10 files changed, 47 insertions(+), 33 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5fedaf477bbf..4c62513907fb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,7 +6,9 @@ "files.exclude": { "**/.build": true, "**/*.hex": true, - "**/*.bin": true + "**/*.bin": true, + "keyboards/[^k]*": true, + "keyboards/k[^e]*": true }, "files.associations": { "*.h": "c", diff --git a/keyboards/keychron/q3/chconf.h b/keyboards/keychron/q3/chconf.h index 0e40bacc420a..d69e2524fcda 100644 --- a/keyboards/keychron/q3/chconf.h +++ b/keyboards/keychron/q3/chconf.h @@ -14,6 +14,8 @@ * along with this program. If not, see . */ + #pragma once + #define CH_CFG_ST_FREQUENCY 10000 #define CH_CFG_OPTIMIZE_SPEED FALSE diff --git a/keyboards/keychron/q3/config.h b/keyboards/keychron/q3/config.h index 3fb203c2675c..0be81f1daf3a 100644 --- a/keyboards/keychron/q3/config.h +++ b/keyboards/keychron/q3/config.h @@ -51,11 +51,11 @@ /* turn off effects when suspended */ #define RGB_DISABLE_WHEN_USB_SUSPENDED -/* We have 2KB EEPROM size on STM32L432 */ -// #define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 2047 +/* Set USB polling rate as 1 milliseconds */ +#define USB_POLLING_INTERVAL_MS 1 -/* Total size of the EEPROM storage in bytes */ -#define TRANSIENT_EEPROM_SIZE 4096 +/* We have 2KB EEPROM size on STM32L432 */ + #define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 2047 // RGB Matrix Animation modes. Explicitly enabled // For full list of effects, see: @@ -107,3 +107,7 @@ #define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH // #define RGB_MATRIX_KEYPRESSES +/* Allow VIA to edit lighting */ +#ifdef VIA_ENABLE +# define VIA_QMK_RGBLIGHT_ENABLE +#endif diff --git a/keyboards/keychron/q3/halconf.h b/keyboards/keychron/q3/halconf.h index 74821ffac718..e490b49e005a 100644 --- a/keyboards/keychron/q3/halconf.h +++ b/keyboards/keychron/q3/halconf.h @@ -17,6 +17,6 @@ #pragma once #define HAL_USE_I2C TRUE -#define PAL_USE_CALLBACKS FALSE +#define PAL_USE_CALLBACKS TRUE #include_next diff --git a/keyboards/keychron/q3/rev_0121/rev_0121.c b/keyboards/keychron/q3/rev_0121/rev_0121.c index 40f3a8494107..7c9808da82d3 100644 --- a/keyboards/keychron/q3/rev_0121/rev_0121.c +++ b/keyboards/keychron/q3/rev_0121/rev_0121.c @@ -167,4 +167,19 @@ bool encoder_update_kb(uint8_t index, bool clockwise) { return true; } +void encoder0_pad_cb(void *param) { + (void)param; + + encoder_insert_state(0); +} + +void keyboard_post_init_kb(void) { + pin_t encoders_pad_a[] = ENCODERS_PAD_A; + pin_t encoders_pad_b[] = ENCODERS_PAD_B; + palEnableLineEvent(encoders_pad_a[0], PAL_EVENT_MODE_BOTH_EDGES); + palEnableLineEvent(encoders_pad_b[0], PAL_EVENT_MODE_BOTH_EDGES); + palSetLineCallback(encoders_pad_a[0], encoder0_pad_cb, NULL); + palSetLineCallback(encoders_pad_b[0], encoder0_pad_cb, NULL); +} + #endif diff --git a/keyboards/keychron/q3/rev_0121/rules.mk b/keyboards/keychron/q3/rev_0121/rules.mk index 2c3e6b177e4c..89879902a710 100644 --- a/keyboards/keychron/q3/rev_0121/rules.mk +++ b/keyboards/keychron/q3/rev_0121/rules.mk @@ -20,7 +20,6 @@ ENCODER_ENABLE = yes # Enable Encoder DIP_SWITCH_ENABLE = yes RGB_MATRIX_ENABLE = yes RGB_MATRIX_DRIVER = CKLED2001 -EEPROM_DRIVER = transient # Enter lower-power sleep mode when on the ChibiOS idle thread OPT_DEFS += -DCORTEX_ENABLE_WFI_IDLE=TRUE diff --git a/platforms/chibios/eeprom_stm32_defs.h b/platforms/chibios/eeprom_stm32_defs.h index 184fcf5f8be5..d5ac2c1cc5d7 100644 --- a/platforms/chibios/eeprom_stm32_defs.h +++ b/platforms/chibios/eeprom_stm32_defs.h @@ -25,7 +25,7 @@ # ifndef FEE_PAGE_COUNT # define FEE_PAGE_COUNT 2 // How many pages are used # endif -# elif defined(STM32F103xE) || defined(STM32F303xC) || defined(STM32F303xE) || defined(STM32F072xB) || defined(STM32F070xB) || defined(STM32L432xx) +# elif defined(STM32F103xE) || defined(STM32F303xC) || defined(STM32F303xE) || defined(STM32F072xB) || defined(STM32F070xB) || defined(STM32L432xx) || defined(STM32L443xx) # ifndef FEE_PAGE_SIZE # define FEE_PAGE_SIZE 0x800 // Page size = 2KByte # endif @@ -47,7 +47,7 @@ # define FEE_MCU_FLASH_SIZE 32 // Size in Kb # elif defined(GD32VF103C8) # define FEE_MCU_FLASH_SIZE 64 // Size in Kb -# elif defined(STM32F103xB) || defined(STM32F072xB) || defined(STM32F070xB) || defined(GD32VF103CB) || defined(STM32L432xx) +# elif defined(STM32F103xB) || defined(STM32F072xB) || defined(STM32F070xB) || defined(GD32VF103CB) || defined(STM32L432xx) || defined(STM32L443xx) # define FEE_MCU_FLASH_SIZE 128 // Size in Kb # elif defined(STM32F303xC) || defined(STM32F401xC) # define FEE_MCU_FLASH_SIZE 256 // Size in Kb diff --git a/platforms/chibios/eeprom_stm32_l4.c b/platforms/chibios/eeprom_stm32_l4.c index 8f33881749bb..edb6d0762d48 100644 --- a/platforms/chibios/eeprom_stm32_l4.c +++ b/platforms/chibios/eeprom_stm32_l4.c @@ -543,4 +543,4 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) { src += write_len; len -= write_len; } -} \ No newline at end of file +} diff --git a/platforms/chibios/flash_stm32.c b/platforms/chibios/flash_stm32.c index 6953a3ead319..6d0478bacf0e 100644 --- a/platforms/chibios/flash_stm32.c +++ b/platforms/chibios/flash_stm32.c @@ -164,15 +164,14 @@ FLASH_Status FLASH_ErasePage(uint32_t Page_Address) { return status; } -#if defined(STM32L4XX) /** - * @brief Programs double words at a specified address. + * @brief Programs a half word at a specified address. * @param Address: specifies the address to be programmed. * @param Data: specifies the data to be programmed. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. */ -FLASH_Status FLASH_ProgramDoubleWord(uint32_t Address, uint64_t Data) { +FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) { FLASH_Status status = FLASH_BAD_ADDRESS; if (IS_FLASH_ADDRESS(Address)) { @@ -180,12 +179,13 @@ FLASH_Status FLASH_ProgramDoubleWord(uint32_t Address, uint64_t Data) { status = FLASH_WaitForLastOperation(ProgramTimeout); if (status == FLASH_COMPLETE) { /* if the previous operation is completed, proceed to program the new data */ - /* disable data cache first */ - FLASH->ACR &= ~FLASH_ACR_DCEN; + +# if defined(FLASH_CR_PSIZE) + FLASH->CR &= ~FLASH_CR_PSIZE; + FLASH->CR |= FLASH_CR_PSIZE_0; +# endif FLASH->CR |= FLASH_CR_PG; - *(__IO uint32_t*)Address = (uint32_t)Data; - __ISB(); - *(__IO uint32_t*)(Address + 4U) = (uint32_t)(Data >> 32); + *(__IO uint16_t*)Address = Data; /* Wait for last operation to be completed */ status = FLASH_WaitForLastOperation(ProgramTimeout); if (status != FLASH_TIMEOUT) { @@ -193,25 +193,20 @@ FLASH_Status FLASH_ProgramDoubleWord(uint32_t Address, uint64_t Data) { FLASH->CR &= ~FLASH_CR_PG; } FLASH->SR = (FLASH_SR_EOP | FLASH_SR_PGERR | FLASH_SR_WRPERR); - /* reset data cache */ - FLASH->ACR |= FLASH_ACR_DCRST; - FLASH->ACR &= ~FLASH_ACR_DCRST; - /* enable data cache */ - FLASH->ACR |= FLASH_ACR_DCEN; } } return status; } -#else +#if defined(STM32L4XX) /** - * @brief Programs a half word at a specified address. + * @brief Programs double words at a specified address. * @param Address: specifies the address to be programmed. * @param Data: specifies the data to be programmed. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. */ -FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) { +FLASH_Status FLASH_ProgramDoubleWord(uint32_t Address, uint64_t Data) { FLASH_Status status = FLASH_BAD_ADDRESS; if (IS_FLASH_ADDRESS(Address)) { @@ -219,13 +214,10 @@ FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) { status = FLASH_WaitForLastOperation(ProgramTimeout); if (status == FLASH_COMPLETE) { /* if the previous operation is completed, proceed to program the new data */ - -# if defined(FLASH_CR_PSIZE) - FLASH->CR &= ~FLASH_CR_PSIZE; - FLASH->CR |= FLASH_CR_PSIZE_0; -# endif FLASH->CR |= FLASH_CR_PG; - *(__IO uint16_t*)Address = Data; + *(__IO uint32_t*)Address = (uint32_t)Data; + __ISB(); + *(__IO uint32_t*)(Address + 4U) = (uint32_t)(Data >> 32); /* Wait for last operation to be completed */ status = FLASH_WaitForLastOperation(ProgramTimeout); if (status != FLASH_TIMEOUT) { diff --git a/quantum/dip_switch.c b/quantum/dip_switch.c index eee29aaf9122..a2a62d7f60f0 100644 --- a/quantum/dip_switch.c +++ b/quantum/dip_switch.c @@ -95,7 +95,7 @@ void dip_switch_read(bool forced) { #ifdef DIP_SWITCH_MATRIX_GRID bool read_raw = false; - if (scan_count < 500) { + if (scan_count < 100) { scan_count++; if (scan_count == 10) { read_raw = true;