From eabfc53f38dc538b44615aed32db66484a3acca4 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 30 Mar 2019 23:01:23 +0700 Subject: [PATCH] added tud_suspended() and tud_ready() --- examples/device/cdc_msc_hid/src/main.c | 15 ++++++++++++--- hw/bsp/pca10056/board_pca10056.c | 8 ++++---- src/class/cdc/cdc_device.c | 2 +- src/device/usbd.c | 6 ++++++ src/device/usbd.h | 12 +++++++++++- src/portable/nordic/nrf5x/dcd_nrf5x.c | 5 +++++ 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/examples/device/cdc_msc_hid/src/main.c b/examples/device/cdc_msc_hid/src/main.c index a8ef0575c..a203e567e 100644 --- a/examples/device/cdc_msc_hid/src/main.c +++ b/examples/device/cdc_msc_hid/src/main.c @@ -135,9 +135,16 @@ void usb_hid_task(void) if ( board_millis() < start_ms + interval_ms) return; // not enough time start_ms += interval_ms; -#if 1 uint32_t const btn = board_buttons(); + if ( tud_suspended() && btn ) + { + // Wake up host if we are in suspend mode + // and REMOTE_WAKEUP feature is enabled by host + tud_remote_wakeup(); + } + +#if 0 /*------------- Keyboard -------------*/ if ( tud_hid_keyboard_ready() ) { @@ -157,8 +164,9 @@ void usb_hid_task(void) tud_hid_keyboard_keycode(0, NULL); } } +#endif - +#if 0 /*------------- Mouse -------------*/ if ( tud_hid_mouse_ready() ) { @@ -211,7 +219,8 @@ void tud_umount_cb(void) } // Invoked when usb bus is suspended -// USB specs: device can only draw up to 2.5 mA from bus +// remote_wakeup_en : if host allow us to perform remote wakeup +// Within 7ms, device must draw an average of current less than 2.5 mA from bus void tud_suspend_cb(bool remote_wakeup_en) { (void) remote_wakeup_en; diff --git a/hw/bsp/pca10056/board_pca10056.c b/hw/bsp/pca10056/board_pca10056.c index 90f466356..493508841 100644 --- a/hw/bsp/pca10056/board_pca10056.c +++ b/hw/bsp/pca10056/board_pca10056.c @@ -44,7 +44,7 @@ uint8_t _button_pins[] = { 11, 12, 24, 25 }; -#define BOARD_BUTTON_COUNT sizeof(_button_pins) +#define BUTTON_COUNT sizeof(_button_pins) /*------------------------------------------------------------------*/ @@ -84,7 +84,7 @@ void board_init(void) board_led_control(false); // Button - for(uint8_t i=0; iDPDMVALUE = USBD_DPDMVALUE_STATE_Resume; + NRF_USBD->TASKS_DPDMDRIVE = 1; } //--------------------------------------------------------------------+ @@ -389,6 +392,8 @@ void USBD_IRQHandler(void) if ( evt_cause & USBD_EVENTCAUSE_SUSPEND_Msk ) { dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true); + + } if ( evt_cause & USBD_EVENTCAUSE_RESUME_Msk )