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;
date_time.unit.day++;
}
}
- watch_rtc_set_date_time(date_time);
+ movement_set_utc_date_time(date_time);
}
watch_rtc_enable(true);
}
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;
void set_time_face_resign(void *context) {
(void) context;
- watch_set_led_off();
movement_store_settings();
+ movement_request_tick_frequency(1);
}
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;
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;
+++ /dev/null
-////< @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);
-
-/** @} */
}
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();
}
// 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;
}
// 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) {
--- /dev/null
+////< @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);
+
+/** @} */
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;
_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