bring in deep sleep / external wake functions
This commit is contained in:
parent
c02c89c880
commit
d0ca6a025a
1
Makefile
1
Makefile
@ -37,6 +37,7 @@ SRCS += \
|
|||||||
./watch-library/shared/watch/watch_common_display.c \
|
./watch-library/shared/watch/watch_common_display.c \
|
||||||
./watch-library/hardware/watch/watch.c \
|
./watch-library/hardware/watch/watch.c \
|
||||||
./watch-library/hardware/watch/watch_adc.c \
|
./watch-library/hardware/watch/watch_adc.c \
|
||||||
|
./watch-library/hardware/watch/watch_deepsleep.c \
|
||||||
./watch-library/hardware/watch/watch_extint.c \
|
./watch-library/hardware/watch/watch_extint.c \
|
||||||
./watch-library/hardware/watch/watch_gpio.c \
|
./watch-library/hardware/watch/watch_gpio.c \
|
||||||
./watch-library/hardware/watch/watch_private.c \
|
./watch-library/hardware/watch/watch_private.c \
|
||||||
|
|||||||
76
app.c
76
app.c
@ -1,4 +1,3 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "watch.h"
|
#include "watch.h"
|
||||||
#include "watch_private.h"
|
#include "watch_private.h"
|
||||||
@ -6,6 +5,15 @@
|
|||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
#include "tusb.h"
|
#include "tusb.h"
|
||||||
#include "watch_usb_cdc.h"
|
#include "watch_usb_cdc.h"
|
||||||
|
#include "tcc.h"
|
||||||
|
|
||||||
|
uint8_t ticks = 0;
|
||||||
|
bool beep = false;
|
||||||
|
|
||||||
|
void cb_tick(void);
|
||||||
|
void cb_mode_btn_interrupt(void);
|
||||||
|
void cb_light_btn_interrupt(void);
|
||||||
|
void cb_alarm_btn_extwake(void);
|
||||||
|
|
||||||
void yield(void) {
|
void yield(void) {
|
||||||
tud_task();
|
tud_task();
|
||||||
@ -13,7 +21,7 @@ void yield(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void app_init(void) {
|
void app_init(void) {
|
||||||
// perform watch initialization first!
|
// initialize the watch hardware.
|
||||||
_watch_init();
|
_watch_init();
|
||||||
|
|
||||||
// check if we are plugged into USB power.
|
// check if we are plugged into USB power.
|
||||||
@ -27,20 +35,68 @@ void app_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void app_setup(void) {
|
void app_setup(void) {
|
||||||
watch_enable_adc();
|
watch_enable_leds();
|
||||||
|
watch_enable_external_interrupts();
|
||||||
|
|
||||||
|
HAL_GPIO_BTN_LIGHT_in();
|
||||||
|
HAL_GPIO_BTN_LIGHT_pulldown();
|
||||||
|
HAL_GPIO_BTN_LIGHT_pmuxen(HAL_GPIO_PMUX_EIC);
|
||||||
|
HAL_GPIO_BTN_MODE_in();
|
||||||
|
HAL_GPIO_BTN_MODE_pulldown();
|
||||||
|
HAL_GPIO_BTN_MODE_pmuxen(HAL_GPIO_PMUX_EIC);
|
||||||
|
|
||||||
|
// Simple test sketch exercises RTC and EIC, plus LEDs, screen and buzzer.
|
||||||
|
// Periodic callback increments the tick counter.
|
||||||
|
watch_rtc_register_periodic_callback(cb_tick, 1);
|
||||||
|
// Light button turns on the LED.
|
||||||
|
watch_register_interrupt_callback(HAL_GPIO_BTN_LIGHT_pin(), cb_light_btn_interrupt, INTERRUPT_TRIGGER_RISING);
|
||||||
|
// Mode button beeps the piezo.
|
||||||
|
watch_register_interrupt_callback(HAL_GPIO_BTN_MODE_pin(), cb_mode_btn_interrupt, INTERRUPT_TRIGGER_RISING);
|
||||||
|
// Alarm buttton resets the tick counter.
|
||||||
|
watch_register_extwake_callback(HAL_GPIO_BTN_ALARM_pin(), cb_alarm_btn_extwake, true);
|
||||||
|
|
||||||
watch_enable_display();
|
watch_enable_display();
|
||||||
|
watch_display_top_left("WA");
|
||||||
|
watch_display_top_right(" 0");
|
||||||
|
watch_display_main_line(" test ");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool app_loop(void) {
|
bool app_loop(void) {
|
||||||
uint16_t vcc = watch_get_vcc_voltage();
|
|
||||||
char buf[7];
|
|
||||||
snprintf(buf, 7, "%6d", vcc);
|
|
||||||
watch_display_main_line(buf);
|
|
||||||
printf("VCC: %d\n", vcc);
|
|
||||||
|
|
||||||
if (usb_is_enabled()) {
|
if (usb_is_enabled()) {
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
if (beep) {
|
||||||
|
watch_buzzer_play_note(BUZZER_NOTE_C8, 100);
|
||||||
|
beep = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char buf[4];
|
||||||
|
sprintf(buf, "%2d", ticks);
|
||||||
|
printf("ticks: %d\n", ticks);
|
||||||
|
watch_display_top_right(buf);
|
||||||
|
|
||||||
|
if (ticks >= 30) {
|
||||||
|
watch_enter_sleep_mode();
|
||||||
|
}
|
||||||
|
|
||||||
|
return !usb_is_enabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cb_tick(void) {
|
||||||
|
ticks = ticks + 1;
|
||||||
|
watch_set_led_off();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cb_light_btn_interrupt(void) {
|
||||||
|
watch_set_led_green();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cb_mode_btn_interrupt(void) {
|
||||||
|
beep = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cb_alarm_btn_extwake(void) {
|
||||||
|
watch_set_led_red();
|
||||||
|
ticks = 0;
|
||||||
}
|
}
|
||||||
@ -22,52 +22,53 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "hpl_systick_config.h"
|
#include "watch_deepsleep.h"
|
||||||
|
#include "app.h"
|
||||||
|
#include "watch.h"
|
||||||
|
#include "watch_private.h"
|
||||||
|
|
||||||
#include "watch_extint.h"
|
void sleep(const uint8_t mode) {
|
||||||
|
PM->SLEEPCFG.bit.SLEEPMODE = mode;
|
||||||
|
|
||||||
// this warning only appears when you `make BOARD=OSO-SWAT-A1-02`. it's annoying,
|
// wait for the mode set to actually take, per SLEEPCFG note in data sheet:
|
||||||
// but i'd rather have it warn us at build-time than fail silently at run-time.
|
// "A small latency happens between the store instruction and actual writing
|
||||||
// besides, no one but me really has any of these boards anyway.
|
// of the SLEEPCFG register due to bridges. Software has to make sure the
|
||||||
#if BTN_ALARM != GPIO(GPIO_PORTA, 2)
|
// SLEEPCFG register reads the wanted value before issuing WFI instruction."
|
||||||
#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.
|
while(PM->SLEEPCFG.bit.SLEEPMODE != mode);
|
||||||
#endif
|
|
||||||
|
|
||||||
void watch_register_extwake_callback(uint8_t pin, ext_irq_cb_t callback, bool level) {
|
__DSB();
|
||||||
uint32_t pinmux;
|
__WFI();
|
||||||
hri_rtc_tampctrl_reg_t config = RTC->MODE2.TAMPCTRL.reg;
|
}
|
||||||
|
|
||||||
switch (pin) {
|
void watch_register_extwake_callback(uint8_t pin, watch_cb_t callback, bool level) {
|
||||||
case A4:
|
uint32_t config = RTC->MODE2.TAMPCTRL.reg;
|
||||||
a4_callback = callback;
|
|
||||||
pinmux = PINMUX_PB00G_RTC_IN0;
|
if (pin == HAL_GPIO_BTN_ALARM_pin()) {
|
||||||
config &= ~(3 << RTC_TAMPCTRL_IN0ACT_Pos);
|
HAL_GPIO_BTN_ALARM_in();
|
||||||
config &= ~(1 << RTC_TAMPCTRL_TAMLVL0_Pos);
|
HAL_GPIO_BTN_ALARM_pulldown();
|
||||||
config |= 1 << RTC_TAMPCTRL_IN0ACT_Pos;
|
HAL_GPIO_BTN_ALARM_pmuxen(HAL_GPIO_PMUX_RTC);
|
||||||
if (level) config |= 1 << RTC_TAMPCTRL_TAMLVL0_Pos;
|
btn_alarm_callback = callback;
|
||||||
break;
|
config &= ~(3 << RTC_TAMPCTRL_IN2ACT_Pos);
|
||||||
case A2:
|
config &= ~(1 << RTC_TAMPCTRL_TAMLVL2_Pos);
|
||||||
a2_callback = callback;
|
config |= 1 << RTC_TAMPCTRL_IN2ACT_Pos;
|
||||||
pinmux = PINMUX_PB02G_RTC_IN1;
|
if (level) config |= 1 << RTC_TAMPCTRL_TAMLVL2_Pos;
|
||||||
config &= ~(3 << RTC_TAMPCTRL_IN1ACT_Pos);
|
} else if (pin == HAL_GPIO_A2_pin()) {
|
||||||
config &= ~(1 << RTC_TAMPCTRL_TAMLVL1_Pos);
|
HAL_GPIO_A2_in();
|
||||||
config |= 1 << RTC_TAMPCTRL_IN1ACT_Pos;
|
HAL_GPIO_A2_pmuxen(HAL_GPIO_PMUX_RTC);
|
||||||
if (level) config |= 1 << RTC_TAMPCTRL_TAMLVL1_Pos;
|
a2_callback = callback;
|
||||||
break;
|
config &= ~(3 << RTC_TAMPCTRL_IN1ACT_Pos);
|
||||||
case BTN_ALARM:
|
config &= ~(1 << RTC_TAMPCTRL_TAMLVL1_Pos);
|
||||||
gpio_set_pin_pull_mode(pin, GPIO_PULL_DOWN);
|
config |= 1 << RTC_TAMPCTRL_IN1ACT_Pos;
|
||||||
btn_alarm_callback = callback;
|
if (level) config |= 1 << RTC_TAMPCTRL_TAMLVL1_Pos;
|
||||||
pinmux = PINMUX_PA02G_RTC_IN2;
|
} else if (pin == HAL_GPIO_A4_pin()) {
|
||||||
config &= ~(3 << RTC_TAMPCTRL_IN2ACT_Pos);
|
HAL_GPIO_A4_in();
|
||||||
config &= ~(1 << RTC_TAMPCTRL_TAMLVL2_Pos);
|
HAL_GPIO_A4_pmuxen(HAL_GPIO_PMUX_RTC);
|
||||||
config |= 1 << RTC_TAMPCTRL_IN2ACT_Pos;
|
a4_callback = callback;
|
||||||
if (level) config |= 1 << RTC_TAMPCTRL_TAMLVL2_Pos;
|
config &= ~(3 << RTC_TAMPCTRL_IN0ACT_Pos);
|
||||||
break;
|
config &= ~(1 << RTC_TAMPCTRL_TAMLVL0_Pos);
|
||||||
default:
|
config |= 1 << RTC_TAMPCTRL_IN0ACT_Pos;
|
||||||
return;
|
if (level) config |= 1 << RTC_TAMPCTRL_TAMLVL0_Pos;
|
||||||
}
|
}
|
||||||
gpio_set_pin_direction(pin, GPIO_DIRECTION_IN);
|
|
||||||
gpio_set_pin_function(pin, pinmux);
|
|
||||||
|
|
||||||
// disable the RTC
|
// disable the RTC
|
||||||
RTC->MODE2.CTRLA.bit.ENABLE = 0;
|
RTC->MODE2.CTRLA.bit.ENABLE = 0;
|
||||||
@ -75,9 +76,9 @@ void watch_register_extwake_callback(uint8_t pin, ext_irq_cb_t callback, bool le
|
|||||||
|
|
||||||
// update the configuration
|
// update the configuration
|
||||||
RTC->MODE2.TAMPCTRL.reg = config;
|
RTC->MODE2.TAMPCTRL.reg = config;
|
||||||
|
|
||||||
// re-enable the RTC
|
// re-enable the RTC
|
||||||
RTC->MODE2.CTRLA.bit.ENABLE = 1;
|
RTC->MODE2.CTRLA.bit.ENABLE = 1;
|
||||||
while (RTC->MODE2.SYNCBUSY.bit.ENABLE); // wait for RTC to be enabled
|
|
||||||
|
|
||||||
NVIC_ClearPendingIRQ(RTC_IRQn);
|
NVIC_ClearPendingIRQ(RTC_IRQn);
|
||||||
NVIC_EnableIRQ(RTC_IRQn);
|
NVIC_EnableIRQ(RTC_IRQn);
|
||||||
@ -85,31 +86,29 @@ void watch_register_extwake_callback(uint8_t pin, ext_irq_cb_t callback, bool le
|
|||||||
}
|
}
|
||||||
|
|
||||||
void watch_disable_extwake_interrupt(uint8_t pin) {
|
void watch_disable_extwake_interrupt(uint8_t pin) {
|
||||||
hri_rtc_tampctrl_reg_t config = hri_rtc_get_TAMPCTRL_reg(RTC, 0xFFFFFFFF);
|
uint32_t config = RTC->MODE2.TAMPCTRL.reg;
|
||||||
|
|
||||||
switch (pin) {
|
if (pin == HAL_GPIO_BTN_ALARM_pin()) {
|
||||||
case A4:
|
btn_alarm_callback = NULL;
|
||||||
a4_callback = NULL;
|
config &= ~(3 << RTC_TAMPCTRL_IN2ACT_Pos);
|
||||||
config &= ~(3 << RTC_TAMPCTRL_IN0ACT_Pos);
|
} else if (pin == HAL_GPIO_A2_pin()) {
|
||||||
break;
|
a2_callback = NULL;
|
||||||
case A2:
|
config &= ~(3 << RTC_TAMPCTRL_IN1ACT_Pos);
|
||||||
a2_callback = NULL;
|
}
|
||||||
config &= ~(3 << RTC_TAMPCTRL_IN1ACT_Pos);
|
else if (pin == HAL_GPIO_A4_pin()) {
|
||||||
break;
|
a4_callback = NULL;
|
||||||
case BTN_ALARM:
|
config &= ~(3 << RTC_TAMPCTRL_IN0ACT_Pos);
|
||||||
btn_alarm_callback = NULL;
|
|
||||||
config &= ~(3 << RTC_TAMPCTRL_IN2ACT_Pos);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hri_rtcmode0_get_CTRLA_ENABLE_bit(RTC)) {
|
// disable the RTC
|
||||||
hri_rtcmode0_clear_CTRLA_ENABLE_bit(RTC);
|
RTC->MODE2.CTRLA.bit.ENABLE = 0;
|
||||||
hri_rtcmode0_wait_for_sync(RTC, RTC_MODE0_SYNCBUSY_ENABLE);
|
while (RTC->MODE2.SYNCBUSY.bit.ENABLE); // wait for RTC to be disabled
|
||||||
}
|
|
||||||
hri_rtc_write_TAMPCTRL_reg(RTC, config);
|
// update the configuration
|
||||||
hri_rtcmode0_set_CTRLA_ENABLE_bit(RTC);
|
RTC->MODE2.TAMPCTRL.reg = config;
|
||||||
|
|
||||||
|
// re-enable the RTC
|
||||||
|
RTC->MODE2.CTRLA.bit.ENABLE = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void watch_store_backup_data(uint32_t data, uint8_t reg) {
|
void watch_store_backup_data(uint32_t data, uint8_t reg) {
|
||||||
@ -135,20 +134,27 @@ static void _watch_disable_all_pins_except_rtc(void) {
|
|||||||
// same with RTC/IN[1] and PB02
|
// same with RTC/IN[1] and PB02
|
||||||
if (config & RTC_TAMPCTRL_IN1ACT_Msk) portb_pins_to_disable &= 0xFFFFFFFB;
|
if (config & RTC_TAMPCTRL_IN1ACT_Msk) portb_pins_to_disable &= 0xFFFFFFFB;
|
||||||
|
|
||||||
// port A: always keep PA02 configured as-is; that's our ALARM button.
|
// port A: that last B is to always keep PA02 configured as-is; that's our ALARM button.
|
||||||
gpio_set_port_direction(0, 0xFFFFFFFB, GPIO_DIRECTION_OFF);
|
PORT->Group[0].DIRCLR.reg = 0xFFFFFFFB;
|
||||||
|
// WRCONFIG can only set half the pins at a time, so we need two writes. This sets pins 0-15.
|
||||||
|
PORT->Group[0].WRCONFIG.reg = PORT_WRCONFIG_WRPINCFG | 0xFFFB;
|
||||||
|
// ...and adding the HWSEL flag configures 16-31.
|
||||||
|
PORT->Group[0].WRCONFIG.reg = PORT_WRCONFIG_HWSEL | PORT_WRCONFIG_WRPINCFG | 0xffff;
|
||||||
|
|
||||||
// port B: disable all pins we didn't save above.
|
// port B: disable all pins we didn't save above.
|
||||||
gpio_set_port_direction(1, portb_pins_to_disable, GPIO_DIRECTION_OFF);
|
PORT->Group[1].DIRCLR.reg = portb_pins_to_disable;
|
||||||
|
PORT->Group[1].WRCONFIG.reg = PORT_WRCONFIG_WRPINCFG | (portb_pins_to_disable & 0xFFFF);
|
||||||
|
PORT->Group[1].WRCONFIG.reg = PORT_WRCONFIG_HWSEL | PORT_WRCONFIG_WRPINCFG | (portb_pins_to_disable >> 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _watch_disable_all_peripherals_except_slcd(void) {
|
static void _watch_disable_all_peripherals_except_slcd(void) {
|
||||||
_watch_disable_tcc();
|
_watch_disable_tcc();
|
||||||
watch_disable_adc();
|
watch_disable_adc();
|
||||||
watch_disable_external_interrupts();
|
watch_disable_external_interrupts();
|
||||||
watch_disable_i2c();
|
/// TODO: Actually disable all these peripherals! #SecondMovement
|
||||||
// TODO: replace this with a proper function when we remove the debug UART
|
// watch_disable_i2c();
|
||||||
SERCOM3->USART.CTRLA.reg &= ~SERCOM_USART_CTRLA_ENABLE;
|
// SERCOM3->USART.CTRLA.reg &= ~SERCOM_USART_CTRLA_ENABLE;
|
||||||
MCLK->APBCMASK.reg &= ~MCLK_APBCMASK_SERCOM3;
|
// MCLK->APBCMASK.reg &= ~MCLK_APBCMASK_SERCOM3;
|
||||||
}
|
}
|
||||||
|
|
||||||
void watch_enter_sleep_mode(void) {
|
void watch_enter_sleep_mode(void) {
|
||||||
@ -161,41 +167,21 @@ void watch_enter_sleep_mode(void) {
|
|||||||
// disable brownout detector interrupt, which could inadvertently wake us up.
|
// disable brownout detector interrupt, which could inadvertently wake us up.
|
||||||
SUPC->INTENCLR.bit.BOD33DET = 1;
|
SUPC->INTENCLR.bit.BOD33DET = 1;
|
||||||
|
|
||||||
// per Microchip datasheet clarification DS80000782,
|
|
||||||
// work around silicon erratum 1.8.4 by disabling the SysTick interrupt, which is
|
|
||||||
// enabled as part of driver init, before going to sleep.
|
|
||||||
SysTick->CTRL = SysTick->CTRL & ~(CONF_SYSTICK_TICKINT << SysTick_CTRL_TICKINT_Pos);
|
|
||||||
|
|
||||||
// disable all pins
|
// disable all pins
|
||||||
_watch_disable_all_pins_except_rtc();
|
_watch_disable_all_pins_except_rtc();
|
||||||
|
|
||||||
// enter standby (4); we basically hang out here until an interrupt wakes us.
|
// enter standby (4); we basically hang out here until an interrupt wakes us.
|
||||||
sleep(4);
|
sleep(4);
|
||||||
|
|
||||||
// and we awake! re-enable the brownout detector and SysTick interrupt
|
// and we awake! re-enable the brownout detector
|
||||||
SUPC->INTENSET.bit.BOD33DET = 1;
|
SUPC->INTENSET.bit.BOD33DET = 1;
|
||||||
SysTick->CTRL = SysTick->CTRL | (CONF_SYSTICK_TICKINT << SysTick_CTRL_TICKINT_Pos);
|
|
||||||
|
|
||||||
// call app_setup so the app can re-enable everything we disabled.
|
// call app_setup so the app can re-enable everything we disabled.
|
||||||
app_setup();
|
app_setup();
|
||||||
|
|
||||||
// and call app_wake_from_standby (since main won't have a chance to do it)
|
|
||||||
app_wake_from_standby();
|
|
||||||
}
|
|
||||||
|
|
||||||
void watch_enter_deep_sleep_mode(void) {
|
|
||||||
// identical to sleep mode except we disable the LCD first.
|
|
||||||
slcd_sync_deinit(&SEGMENT_LCD_0);
|
|
||||||
hri_mclk_clear_APBCMASK_SLCD_bit(SLCD);
|
|
||||||
|
|
||||||
watch_enter_sleep_mode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void watch_enter_backup_mode(void) {
|
void watch_enter_backup_mode(void) {
|
||||||
watch_rtc_disable_all_periodic_callbacks();
|
watch_rtc_disable_all_periodic_callbacks();
|
||||||
_watch_disable_all_peripherals_except_slcd();
|
|
||||||
slcd_sync_deinit(&SEGMENT_LCD_0);
|
|
||||||
hri_mclk_clear_APBCMASK_SLCD_bit(SLCD);
|
|
||||||
_watch_disable_all_pins_except_rtc();
|
_watch_disable_all_pins_except_rtc();
|
||||||
|
|
||||||
// go into backup sleep mode (5). when we exit, the reset controller will take over.
|
// go into backup sleep mode (5). when we exit, the reset controller will take over.
|
||||||
|
|||||||
@ -71,7 +71,7 @@ typedef void (*watch_cb_t)(void);
|
|||||||
// #include "watch_spi.h"
|
// #include "watch_spi.h"
|
||||||
// #include "watch_uart.h"
|
// #include "watch_uart.h"
|
||||||
// #include "watch_storage.h"
|
// #include "watch_storage.h"
|
||||||
// #include "watch_deepsleep.h"
|
#include "watch_deepsleep.h"
|
||||||
|
|
||||||
/** @brief Interrupt handler for the SYSTEM interrupt, which handles MCLK,
|
/** @brief Interrupt handler for the SYSTEM interrupt, which handles MCLK,
|
||||||
* OSC32KCTRL, OSCCTRL, PAC, PM and SUPC.
|
* OSC32KCTRL, OSCCTRL, PAC, PM and SUPC.
|
||||||
|
|||||||
@ -21,17 +21,13 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef _WATCH_DEEPSLEEP_H_INCLUDED
|
|
||||||
#define _WATCH_DEEPSLEEP_H_INCLUDED
|
#pragma once
|
||||||
|
|
||||||
////< @file watch_deepsleep.h
|
////< @file watch_deepsleep.h
|
||||||
|
|
||||||
#include "watch.h"
|
#include "watch.h"
|
||||||
|
|
||||||
// These are declared in watch_rtc.c.
|
|
||||||
extern ext_irq_cb_t btn_alarm_callback;
|
|
||||||
extern ext_irq_cb_t a2_callback;
|
|
||||||
extern ext_irq_cb_t a4_callback;
|
|
||||||
|
|
||||||
/** @addtogroup deepsleep Sleep Control
|
/** @addtogroup deepsleep Sleep Control
|
||||||
* @brief This section covers functions related to the various sleep modes available to the watch,
|
* @brief This section covers functions related to the various sleep modes available to the watch,
|
||||||
* including Sleep, Deep Sleep, and BACKUP mode.
|
* including Sleep, Deep Sleep, and BACKUP mode.
|
||||||
@ -56,8 +52,6 @@ extern ext_irq_cb_t a4_callback;
|
|||||||
* but the display remains on and your app's state is retained. You can enter this
|
* but the display remains on and your app's state is retained. You can enter this
|
||||||
* mode by calling `watch_enter_sleep_mode`. It consumes an order of magnitude less
|
* mode by calling `watch_enter_sleep_mode`. It consumes an order of magnitude less
|
||||||
* power than STANDBY mode.
|
* power than STANDBY mode.
|
||||||
* - Deep Sleep Mode is identical to sleep mode, but it also turns off the LCD to save
|
|
||||||
* a bit more power. You can enter this mode by calling `watch_enter_deep_sleep_mode`.
|
|
||||||
* - BACKUP mode is the lowest possible power mode on the SAM L22. It turns off all pins
|
* - BACKUP mode is the lowest possible power mode on the SAM L22. It turns off all pins
|
||||||
* and peripherals except for the RTC. It also turns off the RAM, obliterating your
|
* and peripherals except for the RTC. It also turns off the RAM, obliterating your
|
||||||
* application's state. The only way to wake from this mode is by setting an external
|
* application's state. The only way to wake from this mode is by setting an external
|
||||||
@ -84,7 +78,7 @@ extern ext_irq_cb_t a4_callback;
|
|||||||
* device from BACKUP mode. You can still use this function to register a BTN_ALARM interrupt
|
* device from BACKUP mode. You can still use this function to register a BTN_ALARM interrupt
|
||||||
* in normal or deep sleep mode, but to wake from BACKUP, you will need to use pin A2 or A4.
|
* in normal or deep sleep mode, but to wake from BACKUP, you will need to use pin A2 or A4.
|
||||||
*/
|
*/
|
||||||
void watch_register_extwake_callback(uint8_t pin, ext_irq_cb_t callback, bool level);
|
void watch_register_extwake_callback(uint8_t pin, watch_cb_t callback, bool level);
|
||||||
|
|
||||||
/** @brief Unregisters the RTC interrupt on one of the EXTWAKE pins. This will prevent a value change on
|
/** @brief Unregisters the RTC interrupt on one of the EXTWAKE pins. This will prevent a value change on
|
||||||
* one of these pins from waking the device.
|
* one of these pins from waking the device.
|
||||||
@ -122,18 +116,6 @@ uint32_t watch_get_backup_data(uint8_t reg);
|
|||||||
*/
|
*/
|
||||||
void watch_enter_sleep_mode(void);
|
void watch_enter_sleep_mode(void);
|
||||||
|
|
||||||
/** @brief enters Deep Sleep Mode by disabling all pins and peripherals except the RTC.
|
|
||||||
* @details Short of BACKUP mode, this is the lowest power mode you can enter while retaining your
|
|
||||||
* application state (and the ability to wake with the alarm button). Just note that the display
|
|
||||||
* will be completely off, so you should document to the user of your application that they will
|
|
||||||
* need to press the alarm button to wake the device, or use a sensor board with support for
|
|
||||||
* an external wake pin.
|
|
||||||
*
|
|
||||||
* All notes from watch_enter_sleep_mode apply here, except for power consumption. You can estimate
|
|
||||||
* the power consumption of this mode to be on the order of 4µA at room temperature.
|
|
||||||
*/
|
|
||||||
void watch_enter_deep_sleep_mode(void);
|
|
||||||
|
|
||||||
/** @brief Enters the SAM L22's lowest-power mode, BACKUP.
|
/** @brief Enters the SAM L22's lowest-power mode, BACKUP.
|
||||||
* @details This function does some housekeeping before entering BACKUP mode. It first disables all pins
|
* @details This function does some housekeeping before entering BACKUP mode. It first disables all pins
|
||||||
* and peripherals except for the RTC, and disables the tick interrupt (since that would wake
|
* and peripherals except for the RTC, and disables the tick interrupt (since that would wake
|
||||||
@ -151,5 +133,14 @@ void watch_enter_deep_sleep_mode(void);
|
|||||||
*/
|
*/
|
||||||
void watch_enter_backup_mode(void);
|
void watch_enter_backup_mode(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Puts the device to sleep in the specified mode.
|
||||||
|
* @param mode The sleep mode to enter. This can be one of the following:
|
||||||
|
* * 2 - Idle: CPU, AHBx, and APBx clocks are off.
|
||||||
|
* * 4 - Standby: STANDBY ALL clocks are OFF, unless requested by sleepwalking peripheral.
|
||||||
|
* * 5 - Backup: Only Backup domain is powered on.
|
||||||
|
* * 6 - Off: All clocks and power domains are OFF until next system reset.
|
||||||
|
*/
|
||||||
|
void sleep(const uint8_t mode);
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
#endif
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user