From 196a2b8301205d553d9925b011050e9ba019d41d Mon Sep 17 00:00:00 2001 From: true Date: Mon, 5 Aug 2024 20:00:12 -0700 Subject: [PATCH] holding BTN1 at boot will now reset settings to default note that they are not stored yet. must go through an edit loop, or change your cursor config, in order to commit the settings to EEPROM. --- firmware/retro_tech_fw/user/main.c | 8 ++++---- firmware/retro_tech_fw/user/src/btn.c | 11 +++++++++-- firmware/retro_tech_fw/user/src/config.c | 8 ++++---- firmware/retro_tech_fw/user/src/config.h | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/firmware/retro_tech_fw/user/main.c b/firmware/retro_tech_fw/user/main.c index cbfefde..53e351e 100644 --- a/firmware/retro_tech_fw/user/main.c +++ b/firmware/retro_tech_fw/user/main.c @@ -93,16 +93,16 @@ int main(void) RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_ADC1 | RCC_APB2Periph_TIM1, ENABLE); - // configure gpio pins + // configure gpio pins, hard buttons (used for settings reset) gpio_init(); + btn_init(); - // get saved settings + // get saved settings, or reset if BTN1 is pushed i2c_init(); - userconf_load(); + userconf_load((BTN_PORT->INDR & (1 << BTN1_PIN)) ? 0 : 1); // configure hardware adc_init(); - btn_init(); led_init(); // configure random diff --git a/firmware/retro_tech_fw/user/src/btn.c b/firmware/retro_tech_fw/user/src/btn.c index 76362e1..820007b 100644 --- a/firmware/retro_tech_fw/user/src/btn.c +++ b/firmware/retro_tech_fw/user/src/btn.c @@ -16,6 +16,7 @@ struct Btn btn[BTN_COUNT] = {0}; void btn_init() { uint8_t i; + uint8_t r; // configure GPIO BTN_PORT->BSHR = (BTN1_PUPD << BTN1_PIN) | (BTN2_PUPD << BTN2_PIN); @@ -29,6 +30,11 @@ void btn_init() btn[0]._pintype = BTN1_PIN | BTN_ACTIVE_LO; btn[1]._pintype = BTN2_PIN; + + // check button, and ignore if held + if (!(BTN_PORT->INDR & (1 << BTN1_PIN))) { + btn[0]._mask |= BTN_IGNORE; + } } void btn_poll() @@ -59,8 +65,8 @@ void btn_poll() // first push? if (!(btn[i]._mask & BTN_PUSH)) { - btn[i]._mask = BTN_PUSH; - if (btn[i].cb_push) { + btn[i]._mask = BTN_PUSH | ignore; + if (btn[i].cb_push && !ignore) { btn[i].cb_push(i); btn[i]._mask |= (BTN_PUSH << 4); } @@ -85,6 +91,7 @@ void btn_poll() } else { // is not pushed if (!(btn[i]._mask & BTN_RELEASE)) { + // note: release will remove ignore status btn[i]._mask = BTN_RELEASE; btn[i]._count = 0; // call callback only if not in ignore state diff --git a/firmware/retro_tech_fw/user/src/config.c b/firmware/retro_tech_fw/user/src/config.c index 7cd889d..eb55d6a 100644 --- a/firmware/retro_tech_fw/user/src/config.c +++ b/firmware/retro_tech_fw/user/src/config.c @@ -29,14 +29,14 @@ static uint16_t checksum() return sum; } -void userconf_load() +void userconf_load(uint8_t force_reset) { uint16_t csum; eeprom_read_bytes(0, 0, (uint8_t *)&userconf, sizeof(userconf)); csum = checksum(); - if ((userconf.checkval != CHECKVAL) || (userconf.checksum != csum)) { + if ((userconf.checkval != CHECKVAL) || (userconf.checksum != csum) || force_reset) { // config is invalid; reset to default userconf.cursor_color = CONF_CURSOR_WHITE; userconf.cursor_flash = 4; // default flash rate @@ -48,8 +48,8 @@ void userconf_load() userconf.ledprog_setting[1][0] = 8; // lite then fade: fade rate userconf.ledprog_setting[1][1] = 192; // lite then fade: hue - userconf.ledprog_setting[2][0] = 255; // twinkle: saturation - userconf.ledprog_setting[2][1] = 4; // twinkle: intensity + userconf.ledprog_setting[2][0] = 127; // twinkle: saturation + userconf.ledprog_setting[2][1] = 6; // twinkle: intensity userconf.ledprog_setting[3][0] = 5; // alternate: offset in 22.5deg increments userconf.ledprog_setting[3][1] = 244; // alternate: hue diff --git a/firmware/retro_tech_fw/user/src/config.h b/firmware/retro_tech_fw/user/src/config.h index 8547b74..0d93b97 100644 --- a/firmware/retro_tech_fw/user/src/config.h +++ b/firmware/retro_tech_fw/user/src/config.h @@ -42,7 +42,7 @@ extern struct UserConf userconf; -void userconf_load(); +void userconf_load(uint8_t force_reset); void userconf_save();