summaryrefslogtreecommitdiffstats
path: root/watch-library/watch/watch_deepsleep.c
diff options
context:
space:
mode:
authorJoey Castillo <jose.castillo@gmail.com>2021-09-27 17:42:27 -0400
committerJoey Castillo <jose.castillo@gmail.com>2021-09-27 17:42:27 -0400
commita65dcf1ec8071878988d5aa0390c5be66ba52a11 (patch)
treeaf1e3a60b50f67160afbb5df0495ea4db3462d1d /watch-library/watch/watch_deepsleep.c
parent751ed9c7a48b78063a0ef2e1d7e79ed03f70560b (diff)
downloadSensor-Watch-a65dcf1ec8071878988d5aa0390c5be66ba52a11.tar.gz
Sensor-Watch-a65dcf1ec8071878988d5aa0390c5be66ba52a11.tar.bz2
Sensor-Watch-a65dcf1ec8071878988d5aa0390c5be66ba52a11.zip
WIP: refactor RTC to use clock mode directly
Diffstat (limited to 'watch-library/watch/watch_deepsleep.c')
-rw-r--r--watch-library/watch/watch_deepsleep.c36
1 files changed, 11 insertions, 25 deletions
diff --git a/watch-library/watch/watch_deepsleep.c b/watch-library/watch/watch_deepsleep.c
index a69ba66c..4294b660 100644
--- a/watch-library/watch/watch_deepsleep.c
+++ b/watch-library/watch/watch_deepsleep.c
@@ -29,24 +29,9 @@
#warning This board revision does not support external wake on BTN_ALARM, so watch_register_extwake_callback will not work with it. Use watch_register_interrupt_callback instead.
#endif
-static void extwake_callback(uint8_t reason);
-ext_irq_cb_t btn_alarm_callback;
-ext_irq_cb_t a2_callback;
-ext_irq_cb_t a4_callback;
-
- static void extwake_callback(uint8_t reason) {
- if (reason & RTC_TAMPID_TAMPID2) {
- if (btn_alarm_callback != NULL) btn_alarm_callback();
- } else if (reason & RTC_TAMPID_TAMPID1) {
- if (a2_callback != NULL) a2_callback();
- } else if (reason & RTC_TAMPID_TAMPID0) {
- if (a4_callback != NULL) a4_callback();
- }
-}
-
void watch_register_extwake_callback(uint8_t pin, ext_irq_cb_t callback, bool level) {
uint32_t pinmux;
- hri_rtc_tampctrl_reg_t config = hri_rtc_get_TAMPCTRL_reg(RTC, 0xFFFFFFFF);
+ hri_rtc_tampctrl_reg_t config = RTC->MODE2.TAMPCTRL.reg;
switch (pin) {
case A4:
@@ -84,16 +69,17 @@ void watch_register_extwake_callback(uint8_t pin, ext_irq_cb_t callback, bool le
gpio_set_pin_function(pin, pinmux);
// disable the RTC
- if (hri_rtcmode0_get_CTRLA_ENABLE_bit(RTC)) {
- hri_rtcmode0_clear_CTRLA_ENABLE_bit(RTC);
- hri_rtcmode0_wait_for_sync(RTC, RTC_MODE0_SYNCBUSY_ENABLE);
- }
+ RTC->MODE2.CTRLA.bit.ENABLE = 0;
+ while (RTC->MODE2.SYNCBUSY.bit.ENABLE);
+
// update the configuration
- hri_rtc_write_TAMPCTRL_reg(RTC, config);
+ RTC->MODE2.TAMPCTRL.reg = config;
// re-enable the RTC
- hri_rtcmode0_set_CTRLA_ENABLE_bit(RTC);
+ RTC->MODE2.CTRLA.bit.ENABLE = 1;
- _extwake_register_callback(&CALENDAR_0.device, extwake_callback);
+ NVIC_ClearPendingIRQ(RTC_IRQn);
+ NVIC_EnableIRQ(RTC_IRQn);
+ RTC->MODE2.INTENSET.reg = RTC_MODE2_INTENSET_TAMPER;
}
void watch_disable_extwake_interrupt(uint8_t pin) {
@@ -176,7 +162,7 @@ void watch_enter_shallow_sleep(char *message) {
_watch_disable_all_peripherals_except_slcd();
// disable tick interrupt
- watch_register_tick_callback(NULL);
+ watch_disable_tick_callback();
// disable brownout detector interrupt, which could inadvertently wake us up.
SUPC->INTENCLR.bit.BOD33DET = 1;
@@ -202,7 +188,7 @@ void watch_enter_deep_sleep() {
// so let's do it!
watch_register_extwake_callback(BTN_ALARM, NULL, true);
- watch_register_tick_callback(NULL);
+ watch_disable_tick_callback();
_watch_disable_all_peripherals_except_slcd();
slcd_sync_deinit(&SEGMENT_LCD_0);
hri_mclk_clear_APBCMASK_SLCD_bit(SLCD);