diff options
author | Joey Castillo <jose.castillo@gmail.com> | 2021-08-28 13:35:52 -0400 |
---|---|---|
committer | Joey Castillo <jose.castillo@gmail.com> | 2021-08-28 13:55:17 -0400 |
commit | 3e45de7deade177b5caa921ee72a0e36300474c7 (patch) | |
tree | a93006c058d0efeb50353227a06eedb240005060 /watch-library/main.c | |
parent | 39a5c822a2a2e798e2e39ff8a98b7af84253026c (diff) | |
download | Sensor-Watch-3e45de7deade177b5caa921ee72a0e36300474c7.tar.gz Sensor-Watch-3e45de7deade177b5caa921ee72a0e36300474c7.tar.bz2 Sensor-Watch-3e45de7deade177b5caa921ee72a0e36300474c7.zip |
implement USB console
Diffstat (limited to 'watch-library/main.c')
-rwxr-xr-x | watch-library/main.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/watch-library/main.c b/watch-library/main.c index c23ceac6..886ab851 100755 --- a/watch-library/main.c +++ b/watch-library/main.c @@ -32,6 +32,7 @@ #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. @@ -54,12 +55,27 @@ int main(void) { // Watch library code. Set initial parameters for the device and enable the RTC. _watch_init(); + // check if we are plugged into USB power. + watch_enable_digital_input(VBUS_DET); + watch_enable_pull_down(VBUS_DET); + // IF WE ARE: + if (watch_get_pin_level(VBUS_DET)) { + // Ramp up to 16 MHz (seems necessary for USB to work)... + hri_oscctrl_write_OSC16MCTRL_reg(OSCCTRL, OSCCTRL_OSC16MCTRL_ONDEMAND | OSCCTRL_OSC16MCTRL_FSEL_16 | OSCCTRL_OSC16MCTRL_ENABLE); + // ...and enable USB functionality. + _watch_enable_usb(); + } + watch_disable_digital_input(VBUS_DET); + // User code. Give the app a chance to enable and set up peripherals. app_setup(); while (1) { bool can_sleep = app_loop(); - if (can_sleep) { + if (hri_usbdevice_get_CTRLA_ENABLE_bit(USB)) { + // if USB is enabled, do not sleep, and handle any pending TinyUSB tasks. + tud_task(); + } else if (can_sleep) { app_prepare_for_sleep(); sleep(4); app_wake_from_sleep(); |