diff options
author | Joey Castillo <jose.castillo@gmail.com> | 2021-08-02 16:14:47 -0400 |
---|---|---|
committer | Joey Castillo <jose.castillo@gmail.com> | 2021-08-02 16:14:47 -0400 |
commit | 8b92a1b44a489ad08fc1749e105ac4565d726803 (patch) | |
tree | 4790e2f8d9bf65071099ae2e93627af95e559d43 /watch-library/watch/watch.c | |
parent | 34945d78e933fc62bedcc975e88be02a0b7fcc2e (diff) | |
download | Sensor-Watch-8b92a1b44a489ad08fc1749e105ac4565d726803.tar.gz Sensor-Watch-8b92a1b44a489ad08fc1749e105ac4565d726803.tar.bz2 Sensor-Watch-8b92a1b44a489ad08fc1749e105ac4565d726803.zip |
thinking through deep sleep stuff
Diffstat (limited to 'watch-library/watch/watch.c')
-rw-r--r-- | watch-library/watch/watch.c | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/watch-library/watch/watch.c b/watch-library/watch/watch.c index 6ab093bd..82b7467c 100644 --- a/watch-library/watch/watch.c +++ b/watch-library/watch/watch.c @@ -1,15 +1,8 @@ -/* - * watch.c - * - * Created: 4/25/2021 10:22:10 AM - * Author: joeycastillo - */ - #include "watch.h" #include <stdlib.h> void watch_init() { - // use switching regulator + // Use switching regulator for lower power consumption. SUPC->VREG.bit.SEL = 1; while(!SUPC->STATUS.bit.VREGRDY); @@ -17,9 +10,8 @@ void watch_init() { CALENDAR_0_init(); calendar_enable(&CALENDAR_0); - // TODO: use performance level 0? -// _set_performance_level(0); -// hri_pm_write_PLCFG_PLDIS_bit(PM, true); + // Not sure if this belongs in every app -- is there a power impact? + delay_driver_init(); } static const uint8_t Character_Set[] = @@ -258,6 +250,10 @@ void watch_set_led_off() { } } +bool watch_rtc_is_enabled() { + return RTC->MODE0.CTRLA.bit.ENABLE; +} + void watch_set_date_time(struct calendar_date_time date_time) { calendar_set_date(&CALENDAR_0, &date_time.date); calendar_set_time(&CALENDAR_0, &date_time.time); @@ -314,7 +310,7 @@ void watch_enable_pull_down(const uint8_t pin) { gpio_set_pin_pull_mode(pin, GPIO_PULL_DOWN); } -bool watch_get_pin_level(const uint8_t pin, const bool level) { +bool watch_get_pin_level(const uint8_t pin) { return gpio_get_pin_level(pin); } @@ -348,3 +344,23 @@ void watch_i2c_receive(int16_t addr, uint8_t *buf, uint16_t length) { i2c_m_sync_set_slaveaddr(&I2C_0, addr, I2C_M_SEVEN); io_read(I2C_0_io, buf, length); } + +void watch_store_backup_data(uint32_t data, uint8_t reg) { + if (reg < 8) { + RTC->MODE0.BKUP[reg].reg = data; + } +} + +uint32_t watch_get_backup_data(uint8_t reg) { + if (reg < 8) { + return RTC->MODE0.BKUP[reg].reg; + } + + return 0; +} + +void watch_enter_deep_sleep(){ + // Not yet implemented. + // TODO: enable tamper interrupt on ALARM pin. + // sleep(5); +} |