From ef0ed276a54fa304cf865b52d3665fa1f2f83b47 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Sat, 28 Aug 2021 19:49:49 -0400 Subject: handle tinyusb device tasks on a timer, allows delays in app --- watch-library/main.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'watch-library/main.c') diff --git a/watch-library/main.c b/watch-library/main.c index 886ab851..3133c2d2 100755 --- a/watch-library/main.c +++ b/watch-library/main.c @@ -58,11 +58,8 @@ int main(void) { // 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. + // if so, enable USB functionality. _watch_enable_usb(); } watch_disable_digital_input(VBUS_DET); @@ -71,11 +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 (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) { + + if (can_sleep && !usb_enabled) { app_prepare_for_sleep(); sleep(4); app_wake_from_sleep(); -- cgit v1.2.3