Skip to content

Commit 3003362

Browse files
committed
refactor(usb_host): Cancel hub porpagation to the user, rename non-critical func
1 parent 3fd17b8 commit 3003362

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

components/usb/usb_host.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static bool _unblock_lib(bool in_isr)
223223
return yield;
224224
}
225225

226-
static inline bool _is_internal_client(void *client)
226+
static inline bool is_internal_client(void *client)
227227
{
228228
if (p_host_lib_obj->constant.enum_client && (client == p_host_lib_obj->constant.enum_client)) {
229229
return true;
@@ -297,7 +297,7 @@ static void usbh_event_callback(usbh_event_data_t *event_data, void *arg)
297297
assert(event_data->ctrl_xfer_data.urb != NULL);
298298
assert(event_data->ctrl_xfer_data.urb->usb_host_client != NULL);
299299
// Redistribute completed control transfers to the clients that submitted them
300-
if (_is_internal_client(event_data->ctrl_xfer_data.urb->usb_host_client)) {
300+
if (is_internal_client(event_data->ctrl_xfer_data.urb->usb_host_client)) {
301301
// Simply call the transfer callback
302302
event_data->ctrl_xfer_data.urb->transfer.callback(&event_data->ctrl_xfer_data.urb->transfer);
303303
} else {
@@ -311,10 +311,11 @@ static void usbh_event_callback(usbh_event_data_t *event_data, void *arg)
311311
break;
312312
}
313313
case USBH_EVENT_NEW_DEV: {
314-
// Internal client
315-
hub_notify_new_dev(event_data->new_dev_data.dev_addr);
316-
// External clients
317-
// Prepare a NEW_DEV client event message, the send it to all clients
314+
if (hub_dev_new(event_data->new_dev_data.dev_addr) == ESP_OK) {
315+
// Device is a hub, we do not need to propagate the event to the clients
316+
break;
317+
}
318+
// Prepare a NEW_DEV client event message, and send it to all clients
318319
usb_host_client_event_msg_t event_msg = {
319320
.event = USB_HOST_CLIENT_EVENT_NEW_DEV,
320321
.new_dev.address = event_data->new_dev_data.dev_addr,
@@ -323,10 +324,11 @@ static void usbh_event_callback(usbh_event_data_t *event_data, void *arg)
323324
break;
324325
}
325326
case USBH_EVENT_DEV_GONE: {
326-
// Internal client
327-
hub_notify_dev_gone(event_data->new_dev_data.dev_addr);
328-
// External clients
329-
// Prepare event msg, send only to clients that have opened the device
327+
if (hub_dev_gone(event_data->new_dev_data.dev_addr) == ESP_OK) {
328+
// Device is a hub, we do not need to propagate the event to the clients
329+
break;
330+
}
331+
// Prepare a DEV GONE event, send only to clients that have opened the device
330332
usb_host_client_event_msg_t event_msg = {
331333
.event = USB_HOST_CLIENT_EVENT_DEV_GONE,
332334
.dev_gone.dev_hdl = event_data->dev_gone_data.dev_hdl,

0 commit comments

Comments
 (0)