diff options
author | joeycastillo <joeycastillo@utexas.edu> | 2021-08-30 14:42:11 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-30 14:42:11 -0400 |
commit | eb3d9b26cbda2d2612f11eb39843b221224f1fa7 (patch) | |
tree | 7a514b4d21dd0d2a324a5e1313a144f26bf20799 /watch-library/main.c | |
parent | ee9cc322d301631c9ff0751d9bed717c6492b6a5 (diff) | |
parent | b0845cc3f1a8234a30c980eccf10e44765e4e105 (diff) | |
download | Sensor-Watch-eb3d9b26cbda2d2612f11eb39843b221224f1fa7.tar.gz Sensor-Watch-eb3d9b26cbda2d2612f11eb39843b221224f1fa7.tar.bz2 Sensor-Watch-eb3d9b26cbda2d2612f11eb39843b221224f1fa7.zip |
Merge pull request #9 from joeycastillo/usb-refactor
USB refactor / Makefile simplification
Diffstat (limited to 'watch-library/main.c')
-rwxr-xr-x | watch-library/main.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/watch-library/main.c b/watch-library/main.c index c23ceac6..af34d850 100755 --- a/watch-library/main.c +++ b/watch-library/main.c @@ -32,11 +32,21 @@ #include "hal_init.h" #include "atmel_start_pins.h" #include "watch.h" +#include "tusb.h" int main(void) { // ASF code. Initialize the MCU with configuration options from Atmel Studio. init_mcu(); + // check if we are plugged into USB power. + watch_enable_digital_input(VBUS_DET); + watch_enable_pull_down(VBUS_DET); + if (watch_get_pin_level(VBUS_DET)) { + // if so, enable USB functionality. + _watch_enable_usb(); + } + watch_disable_digital_input(VBUS_DET); + // User code. Give the app a chance to initialize its data structures and state. app_init(); @@ -58,8 +68,10 @@ int main(void) { app_setup(); while (1) { + bool usb_enabled = hri_usbdevice_get_CTRLA_ENABLE_bit(USB); bool can_sleep = app_loop(); - if (can_sleep) { + + if (can_sleep && !usb_enabled) { app_prepare_for_sleep(); sleep(4); app_wake_from_sleep(); |