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.
This commit is contained in:
true 2024-08-05 20:00:12 -07:00
parent 0191126555
commit 196a2b8301
4 changed files with 18 additions and 11 deletions

View File

@ -93,16 +93,16 @@ int main(void)
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
RCC_APB2Periph_ADC1 | RCC_APB2Periph_TIM1, ENABLE); RCC_APB2Periph_ADC1 | RCC_APB2Periph_TIM1, ENABLE);
// configure gpio pins // configure gpio pins, hard buttons (used for settings reset)
gpio_init(); gpio_init();
btn_init();
// get saved settings // get saved settings, or reset if BTN1 is pushed
i2c_init(); i2c_init();
userconf_load(); userconf_load((BTN_PORT->INDR & (1 << BTN1_PIN)) ? 0 : 1);
// configure hardware // configure hardware
adc_init(); adc_init();
btn_init();
led_init(); led_init();
// configure random // configure random

View File

@ -16,6 +16,7 @@ struct Btn btn[BTN_COUNT] = {0};
void btn_init() void btn_init()
{ {
uint8_t i; uint8_t i;
uint8_t r;
// configure GPIO // configure GPIO
BTN_PORT->BSHR = (BTN1_PUPD << BTN1_PIN) | (BTN2_PUPD << BTN2_PIN); 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[0]._pintype = BTN1_PIN | BTN_ACTIVE_LO;
btn[1]._pintype = BTN2_PIN; 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() void btn_poll()
@ -59,8 +65,8 @@ void btn_poll()
// first push? // first push?
if (!(btn[i]._mask & BTN_PUSH)) { if (!(btn[i]._mask & BTN_PUSH)) {
btn[i]._mask = BTN_PUSH; btn[i]._mask = BTN_PUSH | ignore;
if (btn[i].cb_push) { if (btn[i].cb_push && !ignore) {
btn[i].cb_push(i); btn[i].cb_push(i);
btn[i]._mask |= (BTN_PUSH << 4); btn[i]._mask |= (BTN_PUSH << 4);
} }
@ -85,6 +91,7 @@ void btn_poll()
} else { } else {
// is not pushed // is not pushed
if (!(btn[i]._mask & BTN_RELEASE)) { if (!(btn[i]._mask & BTN_RELEASE)) {
// note: release will remove ignore status
btn[i]._mask = BTN_RELEASE; btn[i]._mask = BTN_RELEASE;
btn[i]._count = 0; btn[i]._count = 0;
// call callback only if not in ignore state // call callback only if not in ignore state

View File

@ -29,14 +29,14 @@ static uint16_t checksum()
return sum; return sum;
} }
void userconf_load() void userconf_load(uint8_t force_reset)
{ {
uint16_t csum; uint16_t csum;
eeprom_read_bytes(0, 0, (uint8_t *)&userconf, sizeof(userconf)); eeprom_read_bytes(0, 0, (uint8_t *)&userconf, sizeof(userconf));
csum = checksum(); csum = checksum();
if ((userconf.checkval != CHECKVAL) || (userconf.checksum != csum)) { if ((userconf.checkval != CHECKVAL) || (userconf.checksum != csum) || force_reset) {
// config is invalid; reset to default // config is invalid; reset to default
userconf.cursor_color = CONF_CURSOR_WHITE; userconf.cursor_color = CONF_CURSOR_WHITE;
userconf.cursor_flash = 4; // default flash rate 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][0] = 8; // lite then fade: fade rate
userconf.ledprog_setting[1][1] = 192; // lite then fade: hue userconf.ledprog_setting[1][1] = 192; // lite then fade: hue
userconf.ledprog_setting[2][0] = 255; // twinkle: saturation userconf.ledprog_setting[2][0] = 127; // twinkle: saturation
userconf.ledprog_setting[2][1] = 4; // twinkle: intensity userconf.ledprog_setting[2][1] = 6; // twinkle: intensity
userconf.ledprog_setting[3][0] = 5; // alternate: offset in 22.5deg increments userconf.ledprog_setting[3][0] = 5; // alternate: offset in 22.5deg increments
userconf.ledprog_setting[3][1] = 244; // alternate: hue userconf.ledprog_setting[3][1] = 244; // alternate: hue

View File

@ -42,7 +42,7 @@ extern struct UserConf userconf;
void userconf_load(); void userconf_load(uint8_t force_reset);
void userconf_save(); void userconf_save();