]> git.earman.xyz Git - sensor-watch.git/commitdiff
Minor fixes to settings faces to work with the new rtc mode
authorAlessandro Genova <ales.genova@gmail.com>
Sun, 27 Jul 2025 01:42:31 +0000 (21:42 -0400)
committerAlessandro Genova <ales.genova@gmail.com>
Sat, 3 Jan 2026 01:02:36 +0000 (20:02 -0500)
watch-faces/settings/finetune_face.c
watch-faces/settings/set_time_face.c
watch-faces/settings/settings_face.c
watch-library/hardware/watch/rtc32.h [deleted file]
watch-library/hardware/watch/watch_deepsleep.c
watch-library/shared/watch/rtc32.h [new file with mode: 0644]
watch-library/simulator/watch/watch_rtc.c

index 7567f9fce0ab8e307148204fedce3460126e1316..4c77c4ea550261d7e8582f0ae5736e7df3a956a8 100644 (file)
@@ -106,7 +106,7 @@ static void finetune_adjust_subseconds(int delta) {
     watch_rtc_enable(false);
     delay_ms(delta);
     if (delta > 500) {
-        watch_date_time_t date_time = watch_rtc_get_date_time();
+        watch_date_time_t date_time = movement_get_utc_date_time();
         date_time.unit.second = (date_time.unit.second + 1) % 60;
         if (date_time.unit.second == 0) { // Overflow
             date_time.unit.minute = (date_time.unit.minute + 1) % 60;
@@ -116,7 +116,7 @@ static void finetune_adjust_subseconds(int delta) {
                     date_time.unit.day++;
             }
         }
-        watch_rtc_set_date_time(date_time);
+        movement_set_utc_date_time(date_time);
     }
     watch_rtc_enable(true);
 }
index e273e61d8add72d2edaa944ff33bb68f79329a45..f52c7179424400fdb0f0ca7c8967b134cd521168 100644 (file)
@@ -108,10 +108,6 @@ bool set_time_face_loop(movement_event_t event, void *context) {
         case EVENT_ALARM_LONG_UP:
             _abort_quick_ticks();
             break;
-        case EVENT_MODE_BUTTON_UP:
-            _abort_quick_ticks();
-            movement_move_to_next_face();
-            return false;
         case EVENT_LIGHT_BUTTON_DOWN:
             current_page = (current_page + 1) % SET_TIME_FACE_NUM_SETTINGS;
             *((uint8_t *)context) = current_page;
@@ -187,6 +183,6 @@ bool set_time_face_loop(movement_event_t event, void *context) {
 
 void set_time_face_resign(void *context) {
     (void) context;
-    watch_set_led_off();
     movement_store_settings();
+    movement_request_tick_frequency(1);
 }
index 0894ebe53ef100789f9c8b94f4a4a4eb027b696f..44d70f1b8737717f2cbe21ca25986d2ff8889b16 100644 (file)
@@ -322,7 +322,7 @@ bool settings_face_loop(movement_event_t event, void *context) {
         case EVENT_MODE_BUTTON_UP:
             movement_force_led_off();
             movement_move_to_next_face();
-            return false;
+            return true;
         case EVENT_ALARM_BUTTON_UP:
             state->settings_screens[state->current_page].advance();
             break;
@@ -339,7 +339,7 @@ bool settings_face_loop(movement_event_t event, void *context) {
         movement_force_led_on(color.red | color.red << 4,
                               color.green | color.green << 4,
                               color.blue | color.blue << 4);
-        return false;
+        return true;
     } else {
         movement_force_led_off();
         return true;
diff --git a/watch-library/hardware/watch/rtc32.h b/watch-library/hardware/watch/rtc32.h
deleted file mode 100644 (file)
index 52f20d6..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-////< @file rtc32.h
-/*
- * MIT License
- *
- * Copyright (c) 2020 Joey Castillo
- * Copyright (c) 2025 Alessandro Genova
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#pragma once
-
-#include <stdint.h>
-#include <stdbool.h>
-
-/**
- * @addtogroup rtc Real-Time Clock
- * @brief Functions for configuring and using the Real-Time Clock peripheral.
- * @details This is the rtc implementation for MODE0 (counter32)
- * @{
- */ 
-
-#define RTC_REFERENCE_YEAR (2020)
-
-typedef union {
-    struct {
-        uint32_t second : 6;    // 0-59
-        uint32_t minute : 6;    // 0-59
-        uint32_t hour : 5;      // 0-23
-        uint32_t day : 5;       // 1-31
-        uint32_t month : 4;     // 1-12
-        uint32_t year : 6;      // 0-63 (representing 2020-2083)
-    } unit;
-    uint32_t reg;               // the bit-packed value as expected by the RTC peripheral's CLOCK register.
-} rtc_date_time_t;
-
-typedef enum rtc_alarm_match_t {
-    ALARM_MATCH_DISABLED = 0,
-    ALARM_MATCH_SS,
-    ALARM_MATCH_MMSS,
-    ALARM_MATCH_HHMMSS,
-} rtc_alarm_match_t;
-
-typedef uint32_t rtc_counter_t;
-
-typedef void (*rtc_cb_t)(uint16_t intflag);
-
-/** @brief Initializes the RTC.
- *  @details Configures the RTC for COUNT32 mode, with a 1 Hz
- *           tick derived from the 1024 Hz clock on GCLK3 (for SAM D devices)
- *           or OSC32KCTRL's most accurate 1024 Hz output (for SAM L devices).
- */
-void rtc_init(void);
-
-/** @brief Enables the RTC.
- */
-void rtc_enable(void);
-
-/** @brief Checks if the RTC is enabled. 
-  * @return true if the RTC is enabled; false if not.
-  */
-bool rtc_is_enabled(void);
-
-/** @brief Set the value of the counter register.
- */
-void rtc_set_counter(rtc_counter_t counter);
-
-/** @brief Returns the value of the counter register.
-  */
-rtc_counter_t rtc_get_counter(void);
-
-/** @brief Configures the RTC alarm callback.
-  * @param callback The function to call when an RTC interrupt occurs. The callback
-  *                 will be passed a bitmask of the interrupt flags, the full contents
-  *                 of the RTC peripheral's INTFLAG register.
-  */
-void rtc_configure_callback(rtc_cb_t callback);
-
-void rtc_enable_compare_interrupt(uint32_t compare_time);
-void rtc_disable_compare_interrupt(void);
-
-/** @} */
index a0abe5eb5e0623c63be840cdfd5b15fbfe7b2eac..e90150ee6c14cefee7ba42cfbccfe71283271067 100644 (file)
@@ -41,7 +41,7 @@ void sleep(const uint8_t mode) {
 }
 
 void watch_register_extwake_callback(uint8_t pin, watch_cb_t callback, bool level) {
-    uint32_t config = RTC->MODE2.TAMPCTRL.reg;
+    uint32_t config = RTC->MODE0.TAMPCTRL.reg;
 
     if (pin == HAL_GPIO_BTN_ALARM_pin()) {
         HAL_GPIO_BTN_ALARM_in();
@@ -71,22 +71,22 @@ void watch_register_extwake_callback(uint8_t pin, watch_cb_t callback, bool leve
     }
 
     // disable the RTC
-    RTC->MODE2.CTRLA.bit.ENABLE = 0;
-    while (RTC->MODE2.SYNCBUSY.bit.ENABLE); // wait for RTC to be disabled
+    RTC->MODE0.CTRLA.bit.ENABLE = 0;
+    while (RTC->MODE0.SYNCBUSY.bit.ENABLE); // wait for RTC to be disabled
 
     // update the configuration
-    RTC->MODE2.TAMPCTRL.reg = config;
+    RTC->MODE0.TAMPCTRL.reg = config;
 
     // re-enable the RTC
-    RTC->MODE2.CTRLA.bit.ENABLE = 1;
+    RTC->MODE0.CTRLA.bit.ENABLE = 1;
 
     NVIC_ClearPendingIRQ(RTC_IRQn);
     NVIC_EnableIRQ(RTC_IRQn);
-    RTC->MODE2.INTENSET.reg = RTC_MODE2_INTENSET_TAMPER;
+    RTC->MODE0.INTENSET.reg = RTC_MODE0_INTENSET_TAMPER;
 }
 
 void watch_disable_extwake_interrupt(uint8_t pin) {
-    uint32_t config = RTC->MODE2.TAMPCTRL.reg;
+    uint32_t config = RTC->MODE0.TAMPCTRL.reg;
 
     if (pin == HAL_GPIO_BTN_ALARM_pin()) {
         btn_alarm_callback = NULL;
@@ -101,14 +101,14 @@ void watch_disable_extwake_interrupt(uint8_t pin) {
     }
 
     // disable the RTC
-    RTC->MODE2.CTRLA.bit.ENABLE = 0;
-    while (RTC->MODE2.SYNCBUSY.bit.ENABLE); // wait for RTC to be disabled
+    RTC->MODE0.CTRLA.bit.ENABLE = 0;
+    while (RTC->MODE0.SYNCBUSY.bit.ENABLE); // wait for RTC to be disabled
 
     // update the configuration
-    RTC->MODE2.TAMPCTRL.reg = config;
+    RTC->MODE0.TAMPCTRL.reg = config;
 
     // re-enable the RTC
-    RTC->MODE2.CTRLA.bit.ENABLE = 1;
+    RTC->MODE0.CTRLA.bit.ENABLE = 1;
 }
 
 void watch_store_backup_data(uint32_t data, uint8_t reg) {
diff --git a/watch-library/shared/watch/rtc32.h b/watch-library/shared/watch/rtc32.h
new file mode 100644 (file)
index 0000000..52f20d6
--- /dev/null
@@ -0,0 +1,98 @@
+////< @file rtc32.h
+/*
+ * MIT License
+ *
+ * Copyright (c) 2020 Joey Castillo
+ * Copyright (c) 2025 Alessandro Genova
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/**
+ * @addtogroup rtc Real-Time Clock
+ * @brief Functions for configuring and using the Real-Time Clock peripheral.
+ * @details This is the rtc implementation for MODE0 (counter32)
+ * @{
+ */ 
+
+#define RTC_REFERENCE_YEAR (2020)
+
+typedef union {
+    struct {
+        uint32_t second : 6;    // 0-59
+        uint32_t minute : 6;    // 0-59
+        uint32_t hour : 5;      // 0-23
+        uint32_t day : 5;       // 1-31
+        uint32_t month : 4;     // 1-12
+        uint32_t year : 6;      // 0-63 (representing 2020-2083)
+    } unit;
+    uint32_t reg;               // the bit-packed value as expected by the RTC peripheral's CLOCK register.
+} rtc_date_time_t;
+
+typedef enum rtc_alarm_match_t {
+    ALARM_MATCH_DISABLED = 0,
+    ALARM_MATCH_SS,
+    ALARM_MATCH_MMSS,
+    ALARM_MATCH_HHMMSS,
+} rtc_alarm_match_t;
+
+typedef uint32_t rtc_counter_t;
+
+typedef void (*rtc_cb_t)(uint16_t intflag);
+
+/** @brief Initializes the RTC.
+ *  @details Configures the RTC for COUNT32 mode, with a 1 Hz
+ *           tick derived from the 1024 Hz clock on GCLK3 (for SAM D devices)
+ *           or OSC32KCTRL's most accurate 1024 Hz output (for SAM L devices).
+ */
+void rtc_init(void);
+
+/** @brief Enables the RTC.
+ */
+void rtc_enable(void);
+
+/** @brief Checks if the RTC is enabled. 
+  * @return true if the RTC is enabled; false if not.
+  */
+bool rtc_is_enabled(void);
+
+/** @brief Set the value of the counter register.
+ */
+void rtc_set_counter(rtc_counter_t counter);
+
+/** @brief Returns the value of the counter register.
+  */
+rtc_counter_t rtc_get_counter(void);
+
+/** @brief Configures the RTC alarm callback.
+  * @param callback The function to call when an RTC interrupt occurs. The callback
+  *                 will be passed a bitmask of the interrupt flags, the full contents
+  *                 of the RTC peripheral's INTFLAG register.
+  */
+void rtc_configure_callback(rtc_cb_t callback);
+
+void rtc_enable_compare_interrupt(uint32_t compare_time);
+void rtc_disable_compare_interrupt(void);
+
+/** @} */
index 77463f747e9840d5ec5e78b083b6453b44bd2969..ee410c4423fb631fd7db5dc4dcea6c8e5ff0ead9 100644 (file)
@@ -64,6 +64,7 @@ watch_cb_t a4_callback;
 static void _watch_increase_counter(void *userData);
 static void _watch_process_periodic_callbacks(void);
 static void _watch_process_comp_callbacks(void);
+static void _watch_rtc_schedule_next_comp(void);
 
 bool _watch_rtc_is_enabled(void) {
     return counter_interval;
@@ -283,7 +284,7 @@ void watch_rtc_disable_comp_callback(uint8_t index) {
     _watch_rtc_schedule_next_comp();
 }
 
-void _watch_rtc_schedule_next_comp(void) {
+static void _watch_rtc_schedule_next_comp(void) {
     scheduled_comp_counter = 0;
 
     // The soonest we can schedule is the next tick