From: Alessandro Genova Date: Sun, 27 Jul 2025 01:42:31 +0000 (-0400) Subject: Minor fixes to settings faces to work with the new rtc mode X-Git-Url: https://git.earman.xyz/?a=commitdiff_plain;h=e942f6768517085849daf4981d62c2c0ddcc9e9b;p=sensor-watch.git Minor fixes to settings faces to work with the new rtc mode --- diff --git a/watch-faces/settings/finetune_face.c b/watch-faces/settings/finetune_face.c index 7567f9f..4c77c4e 100644 --- a/watch-faces/settings/finetune_face.c +++ b/watch-faces/settings/finetune_face.c @@ -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); } diff --git a/watch-faces/settings/set_time_face.c b/watch-faces/settings/set_time_face.c index e273e61..f52c717 100644 --- a/watch-faces/settings/set_time_face.c +++ b/watch-faces/settings/set_time_face.c @@ -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); } diff --git a/watch-faces/settings/settings_face.c b/watch-faces/settings/settings_face.c index 0894ebe..44d70f1 100644 --- a/watch-faces/settings/settings_face.c +++ b/watch-faces/settings/settings_face.c @@ -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 index 52f20d6..0000000 --- a/watch-library/hardware/watch/rtc32.h +++ /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 -#include - -/** - * @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); - -/** @} */ diff --git a/watch-library/hardware/watch/watch_deepsleep.c b/watch-library/hardware/watch/watch_deepsleep.c index a0abe5e..e90150e 100644 --- a/watch-library/hardware/watch/watch_deepsleep.c +++ b/watch-library/hardware/watch/watch_deepsleep.c @@ -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 index 0000000..52f20d6 --- /dev/null +++ b/watch-library/shared/watch/rtc32.h @@ -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 +#include + +/** + * @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); + +/** @} */ diff --git a/watch-library/simulator/watch/watch_rtc.c b/watch-library/simulator/watch/watch_rtc.c index 77463f7..ee410c4 100644 --- a/watch-library/simulator/watch/watch_rtc.c +++ b/watch-library/simulator/watch/watch_rtc.c @@ -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