Skip to content

Commit

Permalink
Attempt at incorporating EEPROM and rotary encoder fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FWest98 committed Jun 5, 2022
1 parent eb8bc32 commit 180132f
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 33 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions keyboards/keychron/q3/chconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#define CH_CFG_ST_FREQUENCY 10000

#define CH_CFG_OPTIMIZE_SPEED FALSE
Expand Down
12 changes: 8 additions & 4 deletions keyboards/keychron/q3/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion keyboards/keychron/q3/halconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
#pragma once

#define HAL_USE_I2C TRUE
#define PAL_USE_CALLBACKS FALSE
#define PAL_USE_CALLBACKS TRUE

#include_next <halconf.h>
15 changes: 15 additions & 0 deletions keyboards/keychron/q3/rev_0121/rev_0121.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion keyboards/keychron/q3/rev_0121/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions platforms/chibios/eeprom_stm32_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion platforms/chibios/eeprom_stm32_l4.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,4 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) {
src += write_len;
len -= write_len;
}
}
}
36 changes: 14 additions & 22 deletions platforms/chibios/flash_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,68 +164,60 @@ 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)) {
/* Wait for last operation to be completed */
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) {
/* if the program operation is completed, disable the PG Bit */
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)) {
/* Wait for last operation to be completed */
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) {
Expand Down
2 changes: 1 addition & 1 deletion quantum/dip_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 180132f

Please sign in to comment.