]> git.earman.xyz Git - sensor-watch.git/commitdiff
lcd autodetect: use buttons as a backup option
authorJoey Castillo <joeycastillo@utexas.edu>
Sat, 15 Mar 2025 13:48:53 +0000 (09:48 -0400)
committerJoey Castillo <joeycastillo@utexas.edu>
Sat, 15 Mar 2025 13:48:53 +0000 (09:48 -0400)
movement.c
watch-library/hardware/watch/watch_slcd.c

index cf978a4e2ad4d31d296f13182e4e63add0ad631d..eba069c736adc0d6e1b0988405068bca733b8f97 100644 (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);
 
index 13df0babdafa3ca27fbc146b8d0c51b5363d9658..9a089a7c45022ffb913e6a00a4f01239ba41a499 100644 (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);
     }