usb: device_next: broadcast SOF to classes

Start of Frame is not relevant for most classes, but it is crucial for
isochronous operation. The most prominent example where SOF is necessary
is USB Audio class.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
This commit is contained in:
Tomasz Moń 2023-12-08 13:04:44 +01:00 committed by Carles Cufí
parent ee13631362
commit 31de122ec0
3 changed files with 22 additions and 0 deletions

View file

@ -226,6 +226,9 @@ struct usbd_class_api {
/** USB power management handler resumed */
void (*resumed)(struct usbd_class_node *const node);
/** Start of Frame */
void (*sof)(struct usbd_class_node *const node);
/** Class associated configuration is selected */
void (*enable)(struct usbd_class_node *const node);

View file

@ -189,6 +189,22 @@ static inline void usbd_class_resumed(struct usbd_class_node *const node)
}
}
/**
* @brief USB Start of Frame handler
*
* @note The execution of the handler must not block.
*
* @param[in] node Pointer to USB device class node
*/
static inline void usbd_class_sof(struct usbd_class_node *const node)
{
const struct usbd_class_api *api = node->api;
if (api->sof != NULL) {
api->sof(node);
}
}
/**
* @brief Class associated configuration active handler
*

View file

@ -84,6 +84,9 @@ static void usbd_class_bcast_event(struct usbd_contex *const uds_ctx,
case UDC_EVT_RESUME:
usbd_class_resumed(c_nd);
break;
case UDC_EVT_SOF:
usbd_class_sof(c_nd);
break;
default:
break;
}