From fc31739eb6fdf230a26930e8d42de7a26558aeae Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Tue, 3 Aug 2021 18:00:07 -0400 Subject: WIP deep sleep mode --- watch-library/watch/watch.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'watch-library/watch') diff --git a/watch-library/watch/watch.c b/watch-library/watch/watch.c index 82b7467c..922aeb0a 100644 --- a/watch-library/watch/watch.c +++ b/watch-library/watch/watch.c @@ -271,8 +271,7 @@ static void tick_callback(struct calendar_dev *const dev) { void watch_enable_tick_callback(ext_irq_cb_t callback) { tick_user_callback = callback; - // TODO: rename this method to reflect that it now sets the PER7 interrupt. - _tamper_register_callback(&CALENDAR_0.device, &tick_callback); + _prescaler_register_callback(&CALENDAR_0.device, &tick_callback); } static bool ADC_0_ENABLED = false; @@ -359,8 +358,27 @@ uint32_t watch_get_backup_data(uint8_t reg) { return 0; } -void watch_enter_deep_sleep(){ - // Not yet implemented. - // TODO: enable tamper interrupt on ALARM pin. - // sleep(5); +static void extwake_callback(struct calendar_dev *const dev) { + // this will never get called since we are basically waking from reset +} + +void watch_enter_deep_sleep() { + // enable and configure the external wake interrupt + _extwake_register_callback(&CALENDAR_0.device, &extwake_callback); + _tamper_enable_debounce_asynchronous(&CALENDAR_0.device); + + // disable SLCD + slcd_sync_deinit(&SEGMENT_LCD_0); + hri_mclk_clear_APBCMASK_SLCD_bit(SLCD); + + // TODO: disable other peripherals + + // disable EIC interrupt on ALARM pin (if any) and enable RTC interrupt. + ext_irq_disable(BTN_ALARM); + gpio_set_pin_direction(BTN_ALARM, GPIO_DIRECTION_IN); + gpio_set_pin_pull_mode(BTN_ALARM, GPIO_PULL_DOWN); + gpio_set_pin_function(BTN_ALARM, PINMUX_PA02G_RTC_IN2); + + // go into backup sleep mode + sleep(5); } -- cgit v1.2.3