Skip to content

Commit

Permalink
New unplugged callback & event filtering
Browse files Browse the repository at this point in the history
- A USB event is only added when it's new and different from the last unhandled one
- New event to inform when the device is unplugged on USB (like when the PHY is reset)
  • Loading branch information
RockyZeroFour committed Mar 7, 2024
1 parent abe6f58 commit c1a3d42
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/device/usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,11 @@ void tud_task_ext(uint32_t timeout_ms, bool in_isr)
else if (DCD_EVENT_UNPLUGGED == event.event_id)
{
_usbd_dev.speed = DCD_EVENT_INVALID;

if (tud_unplugged_cb)
{
tud_unplugged_cb();
}
}
break;

Expand Down
3 changes: 3 additions & 0 deletions src/device/usbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ TU_ATTR_WEAK void tud_mount_cb(void);
// Invoked when device is unmounted
TU_ATTR_WEAK void tud_umount_cb(void);

// Invoked when device is unplugged
TU_ATTR_WEAK void tud_unplugged_cb(void);

// Invoked when usb bus is suspended
// Within 7ms, device must draw an average of current less than 2.5 mA from bus
TU_ATTR_WEAK void tud_suspend_cb(bool remote_wakeup_en);
Expand Down

0 comments on commit c1a3d42

Please sign in to comment.