diff options
| author | hathach <[email protected]> | 2021-03-02 23:24:36 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2021-03-02 23:24:36 +0700 |
| commit | 9d5e3691706f3f17edd701310b967c729240a507 (patch) | |
| tree | fe8491897c08e74a991776973aa6e7bc14b834b6 /src/device | |
| parent | d91979cfef477e43a19e43b7f56847f207feb385 (diff) | |
rp2040 add disconnection detection
- also use dcd_event_bus_reset()
- Add TODO for suspend, resume later on (need to test with/without vbus
detection).
Diffstat (limited to 'src/device')
| -rw-r--r-- | src/device/usbd.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c index 4fc221888..911977eb0 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -992,11 +992,15 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr) switch (event->event_id) { case DCD_EVENT_UNPLUGGED: - _usbd_dev.connected = 0; - _usbd_dev.addressed = 0; - _usbd_dev.cfg_num = 0; - _usbd_dev.suspended = 0; - osal_queue_send(_usbd_q, event, in_isr); + // UNPLUGGED event can be bouncing, only processing if we are currently connected + if ( _usbd_dev.connected ) + { + _usbd_dev.connected = 0; + _usbd_dev.addressed = 0; + _usbd_dev.cfg_num = 0; + _usbd_dev.suspended = 0; + osal_queue_send(_usbd_q, event, in_isr); + } break; case DCD_EVENT_SOF: @@ -1004,9 +1008,10 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr) break; case DCD_EVENT_SUSPEND: - // NOTE: When plugging/unplugging device, the D+/D- state are unstable and can accidentally meet the - // SUSPEND condition ( Idle for 3ms ). Some MCUs such as SAMD doesn't distinguish suspend vs disconnect as well. - // We will skip handling SUSPEND/RESUME event if not currently connected + // NOTE: When plugging/unplugging device, the D+/D- state are unstable and + // can accidentally meet the SUSPEND condition ( Bus Idle for 3ms ). + // In addition, some MCUs such as SAMD or boards that haven no VBUS detection cannot distinguish + // suspended vs disconnected. We will skip handling SUSPEND/RESUME event if not currently connected if ( _usbd_dev.connected ) { _usbd_dev.suspended = 1; |
