diff options
| author | hathach <[email protected]> | 2019-03-30 23:01:23 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2019-03-30 23:01:23 +0700 |
| commit | eabfc53f38dc538b44615aed32db66484a3acca4 (patch) | |
| tree | e1ad77937c1ed4b2f3d81636d4f94fe2d25647e3 | |
| parent | f3a954e7deaa33db5fed8e807cd146e65aaeb104 (diff) | |
added tud_suspended() and tud_ready()
| -rw-r--r-- | examples/device/cdc_msc_hid/src/main.c | 15 | ||||
| -rw-r--r-- | hw/bsp/pca10056/board_pca10056.c | 8 | ||||
| -rw-r--r-- | src/class/cdc/cdc_device.c | 2 | ||||
| -rw-r--r-- | src/device/usbd.c | 6 | ||||
| -rw-r--r-- | src/device/usbd.h | 12 | ||||
| -rw-r--r-- | 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; i<BOARD_BUTTON_COUNT; i++) nrf_gpio_cfg_input(_button_pins[i], NRF_GPIO_PIN_PULLUP); + for(uint8_t i=0; i<BUTTON_COUNT; i++) nrf_gpio_cfg_input(_button_pins[i], NRF_GPIO_PIN_PULLUP); #if CFG_TUSB_OS == OPT_OS_NONE // 1ms tick timer @@ -138,10 +138,10 @@ uint32_t board_buttons(void) { uint32_t ret = 0; - for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) + for(uint8_t i=0; i<BUTTON_COUNT; i++) { // button is active LOW - ret |= ( nrf_gpio_pin_read(_button_pins[i]) ? 0 : (1 << i)); + ret |= (nrf_gpio_pin_read(_button_pins[i]) ? 0 : (1 << i)); } return ret; diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index 7b8f1bf72..c194aacd8 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -99,7 +99,7 @@ static void _prep_out_transaction (uint8_t itf) bool tud_cdc_n_connected(uint8_t itf)
{
// DTR (bit 0) active is considered as connected
- return tud_mounted() && TU_BIT_TEST(_cdcd_itf[itf].line_state, 0);
+ return tud_ready() && TU_BIT_TEST(_cdcd_itf[itf].line_state, 0);
}
uint8_t tud_cdc_n_get_line_state (uint8_t itf)
diff --git a/src/device/usbd.c b/src/device/usbd.c index fb6249528..7b87d1944 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -182,6 +182,11 @@ bool tud_mounted(void) return _usbd_dev.configured;
}
+bool tud_suspended(void)
+{
+ return _usbd_dev.suspended;
+}
+
bool tud_remote_wakeup(void)
{
// only wake up host if this feature is supported and enabled and we are suspended
@@ -627,6 +632,7 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr) case DCD_EVENT_UNPLUGGED:
_usbd_dev.connected = 0;
_usbd_dev.configured = 0;
+ _usbd_dev.suspended = 0;
osal_queue_send(_usbd_q, event, in_isr);
break;
diff --git a/src/device/usbd.h b/src/device/usbd.h index d9b9cb8a7..13c282e91 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -66,6 +66,15 @@ void tud_task (void); // Check if device is connected and configured
bool tud_mounted(void);
+// Check if device is suspended
+bool tud_suspended(void);
+
+// Check if device is ready to transfer
+static inline bool tud_ready(void)
+{
+ return tud_mounted() && !tud_suspended();
+}
+
// Remote wake up host, only if suspended and enabled by host
bool tud_remote_wakeup(void);
@@ -79,7 +88,8 @@ ATTR_WEAK void tud_mount_cb(void); // Invoked when device is unmounted
ATTR_WEAK void tud_umount_cb(void);
-// Invoked when usb bus is suspended, max bus current draw is 2.5 mA
+// Invoked when usb bus is suspended
+// Within 7ms, device must draw an average of current less than 2.5 mA from bus
ATTR_WEAK void tud_suspend_cb(bool remote_wakeup_en);
// Invoked when usb bus is resumed
diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index 452f25292..15a1963b9 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -219,6 +219,9 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num) void dcd_remote_wakeup(uint8_t rhport) { (void) rhport; + + NRF_USBD->DPDMVALUE = 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 ) |
