From 38fe9bcdf8f2c4334bec983f6f04f19e9cff6339 Mon Sep 17 00:00:00 2001 From: Gerardo Rodriguez Date: Wed, 7 Oct 2020 17:53:03 -0500 Subject: [PATCH] #64 Assume "PC connected" at the start of USB communication instead of waiting for the whole enumeration process to be finished. --- source/board/microbitv2/microbitv2.c | 10 +++++++--- source/usb/usb_lib.c | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/source/board/microbitv2/microbitv2.c b/source/board/microbitv2/microbitv2.c index a55b049d6..7b5e9c108 100644 --- a/source/board/microbitv2/microbitv2.c +++ b/source/board/microbitv2/microbitv2.c @@ -336,9 +336,6 @@ void board_30ms_hook() static uint8_t blink_in_progress = 0; if (usb_state == USB_CONNECTED) { - /* Set usb_pc_connected to true to prevent entering sleep mode when host does re-enumeration. - * Will be set to false when the USB cable is detached. */ - usb_pc_connected = true; // configure pin as GPIO PIN_HID_LED_PORT->PCR[PIN_HID_LED_BIT] = PORT_PCR_MUX(1); power_led_max_duty_cycle = PWR_LED_ON_MAX_BRIGHTNESS; @@ -508,6 +505,13 @@ void board_handle_powerdown() } } +void board_usb_sof_event(void) +{ + /* Set usb_pc_connected to true to prevent entering sleep mode when host does re-enumeration. + * Will be set to false when the USB cable is detached. */ + usb_pc_connected = true; +} + void vfs_user_build_filesystem_hook() { uint32_t file_size; error_t status; diff --git a/source/usb/usb_lib.c b/source/usb/usb_lib.c index ca177d9f2..dfd9e4b10 100644 --- a/source/usb/usb_lib.c +++ b/source/usb/usb_lib.c @@ -1065,6 +1065,8 @@ void USBD_Reset_Event(void) #endif #endif /* ((USBD_CDC_ACM_ENABLE)) */ +__weak void board_usb_sof_event(void) {} + #if ((USBD_HID_ENABLE) || (USBD_ADC_ENABLE) || (USBD_CDC_ACM_ENABLE) || (USBD_CLS_ENABLE)) #ifndef __RTX void USBD_SOF_Event(void) @@ -1081,6 +1083,7 @@ void USBD_SOF_Event(void) #if (USBD_CLS_ENABLE) USBD_CLS_SOF_Event(); #endif + board_usb_sof_event(); } #endif #endif /* ((USBD_HID_ENABLE) || (USBD_ADC_ENABLE) || (USBD_CDC_ACM_ENABLE) || (USBD_CLS_ENABLE)) */