From c09d754654eb7846f3b53cbe58da517076c97494 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 27 Mar 2019 23:47:59 +0700 Subject: remove tud_msc_ready() --- src/class/msc/msc_device.c | 5 ----- src/class/msc/msc_device.h | 3 --- 2 files changed, 8 deletions(-) (limited to 'src/class') diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 04a3178a3..ace91b40a 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -102,11 +102,6 @@ static inline uint16_t rdwr10_get_blockcount(uint8_t const command[]) //--------------------------------------------------------------------+ // APPLICATION API //--------------------------------------------------------------------+ -bool tud_msc_ready(void) -{ - return ( _mscd_itf.ep_in != 0 ) && ( _mscd_itf.ep_out != 0 ) ; -} - bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, uint8_t add_sense_qualifier) { (void) lun; diff --git a/src/class/msc/msc_device.h b/src/class/msc/msc_device.h index e030951be..74be7e06d 100644 --- a/src/class/msc/msc_device.h +++ b/src/class/msc/msc_device.h @@ -68,9 +68,6 @@ TU_VERIFY_STATIC(CFG_TUD_MSC_BUFSIZE < UINT16_MAX, "Size is not correct"); * \defgroup MSC_Device Device * @{ */ - -// Check if MSC interface is ready to use -bool tud_msc_ready(void); bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, uint8_t add_sense_qualifier); //--------------------------------------------------------------------+ -- cgit v1.3.1 From 8fb9fbb0b19de3422645e65fbd422c86cb548c62 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 27 Mar 2019 23:58:24 +0700 Subject: add tud_mounted() check in tud_cdc_connected() mark device as disconnected immed with DCD_EVENT_UNPLUGGED --- src/class/cdc/cdc_device.c | 2 +- src/class/cdc/cdc_device.h | 1 - src/device/usbd.c | 8 ++++++-- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src/class') diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index 2ac8d471c..7b8f1bf72 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 TU_BIT_TEST(_cdcd_itf[itf].line_state, 0); + return tud_mounted() && TU_BIT_TEST(_cdcd_itf[itf].line_state, 0); } uint8_t tud_cdc_n_get_line_state (uint8_t itf) diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h index 468edef45..d9a200dd4 100644 --- a/src/class/cdc/cdc_device.h +++ b/src/class/cdc/cdc_device.h @@ -97,7 +97,6 @@ ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_li //--------------------------------------------------------------------+ // INTERNAL USBD-CLASS DRIVER API - //--------------------------------------------------------------------+ void cdcd_init (void); bool cdcd_open (uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); diff --git a/src/device/usbd.c b/src/device/usbd.c index 604f35bc5..58c0d3c4d 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -40,7 +40,7 @@ // Device Data //--------------------------------------------------------------------+ typedef struct { - uint8_t config_num; + volatile uint8_t config_num; uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid) uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid ) @@ -332,7 +332,7 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const break; case TUSB_REQ_GET_CONFIGURATION: - data_buf = &_usbd_dev.config_num; + data_buf = (uint8_t*) &_usbd_dev.config_num; data_len = 1; break; @@ -543,7 +543,11 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr) switch (event->event_id) { case DCD_EVENT_BUS_RESET: + osal_queue_send(_usbd_q, event, in_isr); + break; + case DCD_EVENT_UNPLUGGED: + _usbd_dev.config_num = 0; // mark disconnected osal_queue_send(_usbd_q, event, in_isr); break; -- cgit v1.3.1 From 0bdd4bd55002c4563154214a4d57581433cae668 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 29 Mar 2019 01:34:53 +0700 Subject: added Suspend and Resume event for nrf5x port also rename DCD_EVENT_SUSPENDED to DCD_EVENT_SUSPEND --- src/class/hid/hid_device.c | 7 +++++ src/device/dcd.h | 2 +- src/device/usbd.c | 4 +-- src/portable/nordic/nrf5x/dcd_nrf5x.c | 36 +++++++++++++++++++++----- src/portable/nordic/nrf5x/hal_nrf5x.c | 4 +-- src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c | 2 +- src/portable/nxp/lpc17_40/dcd_lpc17_40.c | 2 +- src/portable/nxp/lpc18_43/dcd_lpc18_43.c | 2 +- 8 files changed, 44 insertions(+), 15 deletions(-) (limited to 'src/class') diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 3a20a9cc8..765ee042e 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -265,6 +265,7 @@ void hidd_init(void) void hidd_reset(uint8_t rhport) { + (void) rhport; tu_memclr(_hidd_itf, sizeof(_hidd_itf)); #if CFG_TUD_HID_KEYBOARD @@ -447,6 +448,7 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque // return false to stall control endpoint (e.g Host send non-sense DATA) bool hidd_control_request_complete(uint8_t rhport, tusb_control_request_t const * p_request) { + (void) rhport; hidd_interface_t* p_hid = get_interface_by_itfnum( (uint8_t) p_request->wIndex ); TU_ASSERT(p_hid); @@ -469,6 +471,11 @@ bool hidd_control_request_complete(uint8_t rhport, tusb_control_request_t const bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { // nothing to do + (void) rhport; + (void) ep_addr; + (void) event; + (void) xferred_bytes; + return true; } diff --git a/src/device/dcd.h b/src/device/dcd.h index 186c4af0c..9abebc2af 100644 --- a/src/device/dcd.h +++ b/src/device/dcd.h @@ -42,7 +42,7 @@ typedef enum DCD_EVENT_BUS_RESET = 1, DCD_EVENT_UNPLUGGED, DCD_EVENT_SOF, - DCD_EVENT_SUSPENDED, + DCD_EVENT_SUSPEND, DCD_EVENT_RESUME, DCD_EVENT_SETUP_RECEIVED, diff --git a/src/device/usbd.c b/src/device/usbd.c index 58c0d3c4d..933e0f846 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -40,7 +40,7 @@ // Device Data //--------------------------------------------------------------------+ typedef struct { - volatile uint8_t config_num; + volatile uint8_t config_num; // 0 is non-configure ~ disconnect uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid) uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid ) @@ -555,7 +555,7 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr) // nothing to do now break; - case DCD_EVENT_SUSPENDED: + case DCD_EVENT_SUSPEND: // TODO support suspended break; diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index 3c2b6d45b..928ef6713 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -207,6 +207,13 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num) (void) rhport; (void) config_num; // Nothing to do + + // Clear current pending + NRF_USBD->EVENTCAUSE |= NRF_USBD->EVENTCAUSE; + NRF_USBD->EVENTS_USBEVENT = 0; + + // Enable usb event for suspend and resume + NRF_USBD->INTENSET = USBD_INTEN_USBEVENT_Msk; } //--------------------------------------------------------------------+ @@ -358,13 +365,34 @@ void USBD_IRQHandler(void) } } - /*------------- Interrupt Processing -------------*/ if ( int_status & USBD_INTEN_USBRESET_Msk ) { bus_reset(); dcd_event_bus_signal(0, DCD_EVENT_BUS_RESET, true); } + if ( int_status & USBD_INTEN_SOF_Msk ) + { + dcd_event_bus_signal(0, DCD_EVENT_SOF, true); + } + + if ( int_status & USBD_INTEN_USBEVENT_Msk ) + { + uint32_t const evt_cause = NRF_USBD->EVENTCAUSE; + + if ( evt_cause & USBD_EVENTCAUSE_SUSPEND_Msk ) + { + dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true); + } + + if ( evt_cause & USBD_EVENTCAUSE_RESUME_Msk ) + { + dcd_event_bus_signal(0, DCD_EVENT_RESUME , true); + } + + NRF_USBD->EVENTCAUSE = evt_cause; // clear interrupt + } + if ( int_status & EDPT_END_ALL_MASK ) { // DMA complete move data from SRAM -> Endpoint @@ -502,12 +530,6 @@ void USBD_IRQHandler(void) } } } - - // SOF interrupt - if ( int_status & USBD_INTEN_SOF_Msk ) - { - dcd_event_bus_signal(0, DCD_EVENT_SOF, true); - } } #endif diff --git a/src/portable/nordic/nrf5x/hal_nrf5x.c b/src/portable/nordic/nrf5x/hal_nrf5x.c index 8477a56cd..730b580b4 100644 --- a/src/portable/nordic/nrf5x/hal_nrf5x.c +++ b/src/portable/nordic/nrf5x/hal_nrf5x.c @@ -212,8 +212,8 @@ void tusb_hal_nrf_power_event (uint32_t event) nrf_usbd_isosplit_set(USBD_ISOSPLIT_SPLIT_HalfIN); - // Enable interrupt. SOF is used as CDC auto flush - NRF_USBD->INTENSET = USBD_INTEN_USBRESET_Msk | USBD_INTEN_USBEVENT_Msk | USBD_INTEN_EPDATA_Msk | + // Enable interrupt + NRF_USBD->INTENSET = USBD_INTEN_USBRESET_Msk | USBD_INTEN_EPDATA_Msk | USBD_INTEN_EP0SETUP_Msk | USBD_INTEN_EP0DATADONE_Msk | USBD_INTEN_ENDEPIN0_Msk | USBD_INTEN_ENDEPOUT0_Msk; // Enable interrupt, priorities should be set by application diff --git a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c b/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c index 65b345957..0b0c10bc3 100644 --- a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c +++ b/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c @@ -339,7 +339,7 @@ void USB_IRQHandler(void) // Note: Host may delay more than 3 ms before and/or after bus reset before doing enumeration. if (dev_cmd_stat & CMDSTAT_DEVICE_ADDR_MASK) { - dcd_event_bus_signal(0, DCD_EVENT_SUSPENDED, true); + dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true); } } } diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c index f18a91b1c..ea95918ae 100644 --- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c +++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c @@ -481,7 +481,7 @@ static void bus_event_isr(uint8_t rhport) { if (dev_status & SIE_DEV_STATUS_SUSPEND_MASK) { - dcd_event_bus_signal(rhport, DCD_EVENT_SUSPENDED, true); + dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true); } else { diff --git a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c index a92a1c7b1..9be1af679 100644 --- a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c +++ b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c @@ -303,7 +303,7 @@ void hal_dcd_isr(uint8_t rhport) // Note: Host may delay more than 3 ms before and/or after bus reset before doing enumeration. if ((lpc_usb->DEVICEADDR >> 25) & 0x0f) { - dcd_event_bus_signal(rhport, DCD_EVENT_SUSPENDED, true); + dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true); } } } -- cgit v1.3.1 From 1c2beba85c223bcf401f877b0c29025490fcdaa4 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 29 Mar 2019 16:23:00 +0700 Subject: working on suspend and resume change dcd_init signature --- examples/device/cdc_msc_hid/src/main.c | 12 ++++++++ src/class/cdc/cdc_device.h | 1 - src/common/tusb_types.h | 7 +++++ src/device/dcd.h | 9 ++++-- src/device/usbd.c | 42 ++++++++++++++++++-------- src/device/usbd.h | 11 +++++-- src/portable/microchip/samd21/dcd_samd21.c | 4 +-- src/portable/microchip/samd51/dcd_samd51.c | 4 +-- src/portable/nordic/nrf5x/dcd_nrf5x.c | 3 +- src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c | 4 +-- src/portable/nxp/lpc17_40/dcd_lpc17_40.c | 4 +-- src/portable/nxp/lpc18_43/dcd_lpc18_43.c | 4 +-- src/portable/st/stm32f3/dcd_stm32f3.c | 4 +-- src/portable/st/stm32f4/dcd_stm32f4.c | 4 +-- 14 files changed, 71 insertions(+), 42 deletions(-) (limited to 'src/class') diff --git a/examples/device/cdc_msc_hid/src/main.c b/examples/device/cdc_msc_hid/src/main.c index 75d9a31dc..1416852f7 100644 --- a/examples/device/cdc_msc_hid/src/main.c +++ b/examples/device/cdc_msc_hid/src/main.c @@ -127,6 +127,7 @@ 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(); /*------------- Keyboard -------------*/ @@ -160,18 +161,29 @@ void usb_hid_task(void) if ( btn & 0x04 ) tud_hid_mouse_move( 0 , -DELTA); // up if ( btn & 0x08 ) tud_hid_mouse_move( 0 , DELTA); // down } +#endif } uint16_t tud_hid_generic_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) { // TODO not Implemented + (void) report_id; + (void) report_type; + (void) buffer; + (void) reqlen; + return 0; } void tud_hid_generic_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) { // TODO not Implemented + (void) report_id; + (void) report_type; + (void) buffer; + (void) bufsize; } + #endif //--------------------------------------------------------------------+ diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h index d9a200dd4..25c721e13 100644 --- a/src/class/cdc/cdc_device.h +++ b/src/class/cdc/cdc_device.h @@ -38,7 +38,6 @@ #define CFG_TUD_CDC_EPSIZE 64 #endif - #ifdef __cplusplus extern "C" { #endif diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index d4a623aaa..5e4da8985 100644 --- a/src/common/tusb_types.h +++ b/src/common/tusb_types.h @@ -103,6 +103,13 @@ typedef enum TUSB_REQ_SYNCH_FRAME ///< 12 }tusb_request_code_t; +typedef enum +{ + TUSB_REQ_FEATURE_EDPT_HALT = 0, + TUSB_REQ_FEATURE_REMOTE_WAKEUP = 1, + TUSB_REQ_FEATURE_TEST_MODE = 2 +}tusb_request_feature_selector_t; + typedef enum { TUSB_REQ_TYPE_STANDARD = 0, diff --git a/src/device/dcd.h b/src/device/dcd.h index 9abebc2af..f47c3714a 100644 --- a/src/device/dcd.h +++ b/src/device/dcd.h @@ -80,7 +80,9 @@ TU_VERIFY_STATIC(sizeof(dcd_event_t) <= 12, "size is not correct"); /*------------------------------------------------------------------*/ /* Device API *------------------------------------------------------------------*/ -bool dcd_init (uint8_t rhport); + +// Initialize controller to device mode +void dcd_init (uint8_t rhport); // Enable device interrupt void dcd_int_enable (uint8_t rhport); @@ -91,9 +93,12 @@ void dcd_int_disable(uint8_t rhport); // Receive Set Address request, mcu port must also include status IN response void dcd_set_address(uint8_t rhport, uint8_t dev_addr); -// Receive Set Config request +// Receive Set Configure request void dcd_set_config (uint8_t rhport, uint8_t config_num); +// Wake up host +void dcd_remote_wakeup(uint8_t rhport); + /*------------------------------------------------------------------*/ /* Endpoint API * - open : Configure endpoint's registers diff --git a/src/device/usbd.c b/src/device/usbd.c index 933e0f846..5127cfaab 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -40,12 +40,13 @@ // Device Data //--------------------------------------------------------------------+ typedef struct { - volatile uint8_t config_num; // 0 is non-configure ~ disconnect + volatile uint8_t config_num; // 0 is non-configured ~ disconnect + bool remote_wakeup_en; uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid) uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid ) - uint8_t ep_busy_mask[2]; // bit mask for busy endpoint +// uint8_t ep_busy_mask[2]; // bit mask for busy endpoint uint8_t ep_stall_mask[2]; // bit mask for stalled endpoint }usbd_device_t; @@ -186,7 +187,7 @@ bool usbd_init (void) for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++) usbd_class_drivers[i].init(); // Init device controller driver - TU_ASSERT(dcd_init(TUD_OPT_RHPORT)); + dcd_init(TUD_OPT_RHPORT); dcd_int_enable(TUD_OPT_RHPORT); return true; @@ -352,6 +353,20 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const if ( data_buf == NULL || data_len == 0 ) return false; break; + case TUSB_REQ_SET_FEATURE: + if ( TUSB_REQ_FEATURE_REMOTE_WAKEUP == p_request->wValue ) + { + // Host enable remote wake up before suspending especially HID device + } + break; + + case TUSB_REQ_CLEAR_FEATURE: + if ( TUSB_REQ_FEATURE_REMOTE_WAKEUP == p_request->wValue ) + { + // Host disable remote wake up after resuming + } + break; + default: TU_BREAKPOINT(); return false; @@ -386,15 +401,19 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const break; case TUSB_REQ_CLEAR_FEATURE: - // only endpoint feature is halted/stalled - dcd_edpt_clear_stall(rhport, tu_u16_low(p_request->wIndex)); - usbd_control_status(rhport, p_request); + if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue ) + { + dcd_edpt_clear_stall(rhport, tu_u16_low(p_request->wIndex)); + usbd_control_status(rhport, p_request); + } break; case TUSB_REQ_SET_FEATURE: - // only endpoint feature is halted/stalled - usbd_edpt_stall(rhport, tu_u16_low(p_request->wIndex)); - usbd_control_status(rhport, p_request); + if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue ) + { + usbd_edpt_stall(rhport, tu_u16_low(p_request->wIndex)); + usbd_control_status(rhport, p_request); + } break; default: @@ -556,11 +575,8 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr) break; case DCD_EVENT_SUSPEND: - // TODO support suspended - break; - case DCD_EVENT_RESUME: - // TODO support resume + osal_queue_send(_usbd_q, event, in_isr); break; case DCD_EVENT_SETUP_RECEIVED: diff --git a/src/device/usbd.h b/src/device/usbd.h index 614b4f311..6bf7eca02 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -60,7 +60,6 @@ typedef struct { }tud_desc_set_t; - // Must be defined by application extern tud_desc_set_t tud_desc_set; @@ -70,6 +69,8 @@ extern tud_desc_set_t tud_desc_set; bool tud_mounted(void); void tud_task (void); +bool tud_remote_wakeup(void); + //--------------------------------------------------------------------+ // APPLICATION CALLBACK (WEAK is optional) //--------------------------------------------------------------------+ @@ -77,10 +78,14 @@ void tud_task (void); // Callback invoked when device is mounted (configured) ATTR_WEAK void tud_mount_cb(void); -// Callback invoked when device is unmounted (bus reset/unplugged) +// Callback invoked when device is unmounted ATTR_WEAK void tud_umount_cb(void); -//void tud_device_suspended_cb(void); +// Callback invoked when device is suspended +ATTR_WEAK void tud_suspend_cb(bool remote_wakeup_en); + +// Callback invoked when device is resumed +ATTR_WEAK void tud_resume_cb(void); #ifdef __cplusplus } diff --git a/src/portable/microchip/samd21/dcd_samd21.c b/src/portable/microchip/samd21/dcd_samd21.c index 723bd6c3a..a340c888d 100644 --- a/src/portable/microchip/samd21/dcd_samd21.c +++ b/src/portable/microchip/samd21/dcd_samd21.c @@ -57,7 +57,7 @@ static void bus_reset(void) { /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -bool dcd_init (uint8_t rhport) +void dcd_init (uint8_t rhport) { (void) rhport; @@ -80,8 +80,6 @@ bool dcd_init (uint8_t rhport) while (USB->DEVICE.SYNCBUSY.bit.ENABLE == 1) {} USB->DEVICE.INTENSET.reg = USB_DEVICE_INTENSET_SOF | USB_DEVICE_INTENSET_EORST; - - return true; } void dcd_int_enable(uint8_t rhport) diff --git a/src/portable/microchip/samd51/dcd_samd51.c b/src/portable/microchip/samd51/dcd_samd51.c index 9869956c7..13250c38c 100644 --- a/src/portable/microchip/samd51/dcd_samd51.c +++ b/src/portable/microchip/samd51/dcd_samd51.c @@ -57,7 +57,7 @@ static void bus_reset(void) { /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -bool dcd_init (uint8_t rhport) +void dcd_init (uint8_t rhport) { (void) rhport; @@ -79,8 +79,6 @@ bool dcd_init (uint8_t rhport) USB->DEVICE.CTRLA.reg = USB_CTRLA_MODE_DEVICE | USB_CTRLA_ENABLE | USB_CTRLA_RUNSTDBY; while (USB->DEVICE.SYNCBUSY.bit.ENABLE == 1) {} USB->DEVICE.INTENSET.reg = USB_DEVICE_INTENSET_SOF | USB_DEVICE_INTENSET_EORST; - - return true; } void dcd_int_enable(uint8_t rhport) diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index 928ef6713..edaef7cca 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -177,10 +177,9 @@ static void xact_in_prepare(uint8_t epnum) //--------------------------------------------------------------------+ // Controller API //--------------------------------------------------------------------+ -bool dcd_init (uint8_t rhport) +void dcd_init (uint8_t rhport) { (void) rhport; - return true; } void dcd_int_enable(uint8_t rhport) diff --git a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c b/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c index 0b0c10bc3..f01bed1c9 100644 --- a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c +++ b/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c @@ -153,7 +153,7 @@ void dcd_set_address(uint8_t rhport, uint8_t dev_addr) LPC_USB->DEVCMDSTAT |= dev_addr; } -bool dcd_init(uint8_t rhport) +void dcd_init(uint8_t rhport) { (void) rhport; @@ -166,8 +166,6 @@ bool dcd_init(uint8_t rhport) CMDSTAT_RESET_CHANGE_MASK | CMDSTAT_CONNECT_CHANGE_MASK | CMDSTAT_SUSPEND_CHANGE_MASK; NVIC_EnableIRQ(USB0_IRQn); - - return true; } //--------------------------------------------------------------------+ diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c index ea95918ae..5da18d52b 100644 --- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c +++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c @@ -166,7 +166,7 @@ static void bus_reset(void) tu_memclr(&_dcd, sizeof(dcd_data_t)); } -bool dcd_init(uint8_t rhport) +void dcd_init(uint8_t rhport) { (void) rhport; @@ -186,8 +186,6 @@ bool dcd_init(uint8_t rhport) // USB IRQ priority should be set by application previously NVIC_ClearPendingIRQ(USB_IRQn); NVIC_EnableIRQ(USB_IRQn); - - return true; } void dcd_int_enable(uint8_t rhport) diff --git a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c index 9be1af679..b272a143e 100644 --- a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c +++ b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c @@ -121,7 +121,7 @@ static void bus_reset(uint8_t rhport) p_dcd->qhd[0].int_on_setup = 1; // OUT only } -bool dcd_init(uint8_t rhport) +void dcd_init(uint8_t rhport) { LPC_USBHS_T* const lpc_usb = LPC_USB[rhport]; dcd_data_t* p_dcd = dcd_data_ptr[rhport]; @@ -134,8 +134,6 @@ bool dcd_init(uint8_t rhport) lpc_usb->USBCMD_D &= ~0x00FF0000; // Interrupt Threshold Interval = 0 lpc_usb->USBCMD_D |= TU_BIT(0); // connect - - return true; } void dcd_int_enable(uint8_t rhport) diff --git a/src/portable/st/stm32f3/dcd_stm32f3.c b/src/portable/st/stm32f3/dcd_stm32f3.c index 138c454a7..41f82891b 100644 --- a/src/portable/st/stm32f3/dcd_stm32f3.c +++ b/src/portable/st/stm32f3/dcd_stm32f3.c @@ -35,10 +35,8 @@ // MACRO TYPEDEF CONSTANT ENUM DECLARATION //--------------------------------------------------------------------+ - -bool dcd_init (uint8_t rhport) +void dcd_init (uint8_t rhport) { - return true; } // Enable device interrupt diff --git a/src/portable/st/stm32f4/dcd_stm32f4.c b/src/portable/st/stm32f4/dcd_stm32f4.c index db72f92d3..f0d6e7d58 100644 --- a/src/portable/st/stm32f4/dcd_stm32f4.c +++ b/src/portable/st/stm32f4/dcd_stm32f4.c @@ -128,7 +128,7 @@ static void end_of_reset(void) { /*------------------------------------------------------------------*/ /* Controller API *------------------------------------------------------------------*/ -bool dcd_init (uint8_t rhport) +void dcd_init (uint8_t rhport) { (void) rhport; @@ -161,8 +161,6 @@ bool dcd_init (uint8_t rhport) // Enable pullup, enable peripheral. USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN | USB_OTG_GCCFG_PWRDWN; - - return true; } void dcd_int_enable (uint8_t rhport) -- cgit v1.3.1 From eabfc53f38dc538b44615aed32db66484a3acca4 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 30 Mar 2019 23:01:23 +0700 Subject: 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(-) (limited to 'src/class') 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 ) -- cgit v1.3.1 From 4af16efea706655a814d55e02f8d0463f4d29cf3 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 2 Apr 2019 02:14:39 +0700 Subject: add tud_ready() to hid_ready() --- src/class/hid/hid_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/class') diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 765ee042e..5c81a1268 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -107,7 +107,7 @@ static inline hidd_interface_t* get_interface_by_itfnum(uint8_t itf_num) //--------------------------------------------------------------------+ bool tud_hid_generic_ready(void) { - return (_hidd_itf[ITF_IDX_GENERIC].ep_in != 0) && !dcd_edpt_busy(TUD_OPT_RHPORT, _hidd_itf[ITF_IDX_GENERIC].ep_in); + return tud_ready() && (_hidd_itf[ITF_IDX_GENERIC].ep_in != 0) && !dcd_edpt_busy(TUD_OPT_RHPORT, _hidd_itf[ITF_IDX_GENERIC].ep_in); } bool tud_hid_generic_report(uint8_t report_id, void const* report, uint8_t len) -- cgit v1.3.1