diff options
| author | hathach <[email protected]> | 2022-02-23 18:42:32 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2022-02-25 18:35:21 +0700 |
| commit | 4a5a53b3b88fcd2f5ec7f1f94eb07c27cb1e9bec (patch) | |
| tree | 3f005e9cb4adcf39b8c67860890987f96b650212 /src/device/usbd.c | |
| parent | b797d1aa50310a46d430ff0efd66d7e88028de3b (diff) | |
improve rphort management for usbd
Diffstat (limited to 'src/device/usbd.c')
| -rw-r--r-- | src/device/usbd.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c index 448114303..37ca9822f 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -269,11 +269,12 @@ static inline usbd_class_driver_t const * get_driver(uint8_t drvid) // DCD Event //--------------------------------------------------------------------+ -static bool _usbd_initialized = false; +enum { RHPORT_INVALID = 0xFFu }; +static uint8_t _usbd_rhport = RHPORT_INVALID; // Event queue // OPT_MODE_DEVICE is used by OS NONE for mutex (disable usb isr) -OSAL_QUEUE_DEF(OPT_MODE_DEVICE, _usbd_qdef, CFG_TUD_TASK_QUEUE_SZ, dcd_event_t); +OSAL_QUEUE_DEF(usbd_int_set, _usbd_qdef, CFG_TUD_TASK_QUEUE_SZ, dcd_event_t); static osal_queue_t _usbd_q; // Mutex for claiming endpoint, only needed when using with preempted RTOS @@ -376,21 +377,21 @@ bool tud_remote_wakeup(void) { // only wake up host if this feature is supported and enabled and we are suspended TU_VERIFY (_usbd_dev.suspended && _usbd_dev.remote_wakeup_support && _usbd_dev.remote_wakeup_en ); - dcd_remote_wakeup(TUD_OPT_RHPORT); + dcd_remote_wakeup(_usbd_rhport); return true; } bool tud_disconnect(void) { TU_VERIFY(dcd_disconnect); - dcd_disconnect(TUD_OPT_RHPORT); + dcd_disconnect(_usbd_rhport); return true; } bool tud_connect(void) { TU_VERIFY(dcd_connect); - dcd_connect(TUD_OPT_RHPORT); + dcd_connect(_usbd_rhport); return true; } @@ -399,13 +400,13 @@ bool tud_connect(void) //--------------------------------------------------------------------+ bool tud_inited(void) { - return _usbd_initialized; + return _usbd_rhport != RHPORT_INVALID; } bool tud_init (uint8_t rhport) { // skip if already initialized - if (_usbd_initialized) return _usbd_initialized; + if ( tud_inited() ) return true; TU_LOG2("USBD init\r\n"); @@ -439,7 +440,7 @@ bool tud_init (uint8_t rhport) dcd_init(rhport); dcd_int_enable(rhport); - _usbd_initialized = true; + _usbd_rhport = rhport; return true; } @@ -1173,6 +1174,17 @@ void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_ // USBD API For Class Driver //--------------------------------------------------------------------+ +void usbd_int_set(bool enabled) +{ + if (enabled) + { + dcd_int_enable(_usbd_rhport); + }else + { + dcd_int_disable(_usbd_rhport); + } +} + // Parse consecutive endpoint descriptors (IN & OUT) bool usbd_open_edpt_pair(uint8_t rhport, uint8_t const* p_desc, uint8_t ep_count, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in) { |
