lcd autodetect: use buttons as a backup option

This commit is contained in:
Joey Castillo 2025-03-15 09:48:53 -04:00
parent e9ede6f060
commit c1efea4db7
2 changed files with 21 additions and 1 deletions

View File

@ -672,6 +672,9 @@ void app_setup(void) {
watch_rtc_register_alarm_callback(cb_alarm_fired, alarm_time, ALARM_MATCH_SS);
}
// LCD autodetect uses the buttons as a a failsafe, so we should run it before we enable the button interrupts
watch_enable_display();
if (movement_state.le_mode_ticks != -1) {
watch_disable_extwake_interrupt(HAL_GPIO_BTN_ALARM_pin());
@ -740,7 +743,6 @@ void app_setup(void) {
watch_enable_buzzer();
watch_enable_leds();
watch_enable_display();
movement_request_tick_frequency(1);

View File

@ -73,6 +73,13 @@ void watch_discover_lcd_type(void) {
HAL_GPIO_SLCD3_pmuxen(HAL_GPIO_PMUX_ADC);
HAL_GPIO_SLCD4_pmuxen(HAL_GPIO_PMUX_ADC);
// as a failsafe, we have button inputs: MODE for classic, ALARM for new.
// (think: left button, backwards in time: classic; right button, forward, new: custom)
HAL_GPIO_BTN_MODE_in();
HAL_GPIO_BTN_MODE_pulldown();
HAL_GPIO_BTN_ALARM_in();
HAL_GPIO_BTN_ALARM_pulldown();
/// TODO: Remove this and the watch_set_led_off below; it's here for testing (people will see red if their LCD was undetectable)
watch_set_led_red();
@ -103,6 +110,17 @@ void watch_discover_lcd_type(void) {
if (valid_frames_classic > 16 || valid_frames_custom > 16) {
break;
}
// The failsafe: if our detection isn't working, the user can tell us which display is installed.
if (HAL_GPIO_BTN_MODE_read()) {
_installed_display = WATCH_LCD_TYPE_CLASSIC;
goto valid_display_detected;
}
if (HAL_GPIO_BTN_ALARM_read()) {
_installed_display = WATCH_LCD_TYPE_CUSTOM;
goto valid_display_detected;
}
delay_ms(4);
}