summaryrefslogtreecommitdiffstats
path: root/watch-library/main.c
diff options
context:
space:
mode:
authorJoey Castillo <jose.castillo@gmail.com>2021-08-02 16:14:47 -0400
committerJoey Castillo <jose.castillo@gmail.com>2021-08-02 16:14:47 -0400
commit8b92a1b44a489ad08fc1749e105ac4565d726803 (patch)
tree4790e2f8d9bf65071099ae2e93627af95e559d43 /watch-library/main.c
parent34945d78e933fc62bedcc975e88be02a0b7fcc2e (diff)
downloadSensor-Watch-8b92a1b44a489ad08fc1749e105ac4565d726803.tar.gz
Sensor-Watch-8b92a1b44a489ad08fc1749e105ac4565d726803.tar.bz2
Sensor-Watch-8b92a1b44a489ad08fc1749e105ac4565d726803.zip
thinking through deep sleep stuff
Diffstat (limited to 'watch-library/main.c')
-rwxr-xr-xwatch-library/main.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/watch-library/main.c b/watch-library/main.c
index 0d457b5f..67e47896 100755
--- a/watch-library/main.c
+++ b/watch-library/main.c
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, Joey Castillo
- * SAML22 starter project is Copyright (c) 2014-2017, Alex Taradov <alex@taradov.com>
+ * UART methods are Copyright (c) 2014-2017, Alex Taradov <alex@taradov.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -82,26 +82,35 @@ void uart_puts(char *s) {
while (*s) uart_putc(*s++);
}
-//-----------------------------------------------------------------------------
-static void sys_init(void) {
- uart_puts("init_mcu\n");
+int main(void) {
+ // Temporary, for debugging.
+ uart_init(115200);
+
+ // ASF code. Initialize the MCU with configuration options from Atmel Studio.
init_mcu();
- uart_puts("watch_init\n");
- watch_init();
- uart_puts("app_init\n");
+
+ // User code. Give the app a chance to initialize its data structures and state.
app_init();
-}
-//-----------------------------------------------------------------------------
-int main(void) {
- uart_init(115200);
- sys_init();
+ // At this point, if the RTC peripheral is enabled, we are waking from BACKUP.
+ if (watch_rtc_is_enabled()) {
+ // User code. Give the application a chance to restore state from backup registers.
+ app_wake_from_deep_sleep();
+ }
+
+ // Watch library code. Set initial parameters for the device and enable the RTC.
+ watch_init();
+
+ // User code. Give the app a chance to enable and set up peripherals.
+ app_setup();
while (1) {
- app_loop();
- app_prepare_for_sleep();
- sleep(4);
- app_wake_from_sleep();
+ bool can_sleep = app_loop();
+ if (can_sleep) {
+ app_prepare_for_sleep();
+ sleep(4);
+ app_wake_from_sleep();
+ }
}
return 0;