mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
usbus: Add functions to query max packet sizes
This commit is contained in:
parent
aa67c98a4a
commit
8b41443913
@ -239,6 +239,26 @@ typedef enum {
|
||||
USB_EP_DIR_IN, /**< Host in, device out */
|
||||
} usb_ep_dir_t;
|
||||
|
||||
/**
|
||||
* @brief Maximum transfer size for interrupt endpoints at full speed
|
||||
*/
|
||||
#define USB_ENDPOINT_INTERRUPT_FS_MAX_SIZE (64)
|
||||
|
||||
/**
|
||||
* @brief Maximum transfer size for interrupt endpoints at high speed
|
||||
*/
|
||||
#define USB_ENDPOINT_INTERRUPT_HS_MAX_SIZE (1024)
|
||||
|
||||
/**
|
||||
* @brief Maximum transfer size for bulk endpoints at full speed
|
||||
*/
|
||||
#define USB_ENDPOINT_BULK_FS_MAX_SIZE (64)
|
||||
|
||||
/**
|
||||
* @brief Maximum transfer size for bulk endpoints at high speed
|
||||
*/
|
||||
#define USB_ENDPOINT_BULK_HS_MAX_SIZE (512)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -589,6 +589,22 @@ void usbus_register_event_handler(usbus_t *usbus, usbus_handler_t *handler);
|
||||
*/
|
||||
void usbus_init(usbus_t *usbus, usbdev_t *usbdev);
|
||||
|
||||
/**
|
||||
* @brief Get the maximum supported bulk endpoint transfer size based on the enumeration speed
|
||||
*
|
||||
* Should only be called after enumeration has finished by the peripheral. Calling this in response
|
||||
* to the @ref USBUS_EVENT_USB_RESET is valid
|
||||
*/
|
||||
size_t usbus_max_bulk_endpoint_size(usbus_t *usbus);
|
||||
|
||||
/**
|
||||
* @brief Get the maximum supported interrupt endpoint transfer size based on the enumeration speed
|
||||
*
|
||||
* Should only be called after enumeration has finished by the peripheral. Calling this in response
|
||||
* to the @ref USBUS_EVENT_USB_RESET is valid
|
||||
*/
|
||||
size_t usbus_max_interrupt_endpoint_size(usbus_t *usbus);
|
||||
|
||||
/**
|
||||
* @brief Create and start the USBUS thread
|
||||
*
|
||||
|
@ -162,6 +162,50 @@ usbus_endpoint_t *usbus_interface_find_endpoint(usbus_interface_t *interface,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t usbus_max_bulk_endpoint_size(usbus_t *usbus)
|
||||
{
|
||||
usb_speed_t speed;
|
||||
int res = usbdev_get(usbus->dev, USBOPT_ENUMERATED_SPEED, &speed,
|
||||
sizeof(speed));
|
||||
if (res == -ENOTSUP) {
|
||||
res = usbdev_get(usbus->dev, USBOPT_MAX_SPEED, &speed,
|
||||
sizeof(speed));
|
||||
}
|
||||
|
||||
if (res < 0) {
|
||||
return 0; /* Misbehaving usbdev device not implementing any speed indication */
|
||||
}
|
||||
|
||||
switch (speed) {
|
||||
case USB_SPEED_HIGH:
|
||||
return USB_ENDPOINT_BULK_HS_MAX_SIZE;
|
||||
default:
|
||||
return USB_ENDPOINT_BULK_FS_MAX_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
size_t usbus_max_interrupt_endpoint_size(usbus_t *usbus)
|
||||
{
|
||||
usb_speed_t speed;
|
||||
int res = usbdev_get(usbus->dev, USBOPT_ENUMERATED_SPEED, &speed,
|
||||
sizeof(speed));
|
||||
if (res == -ENOTSUP) {
|
||||
res = usbdev_get(usbus->dev, USBOPT_MAX_SPEED, &speed,
|
||||
sizeof(speed));
|
||||
}
|
||||
|
||||
if (res < 0) {
|
||||
assert(false); /* Misbehaving usbdev device not implementing mandatory USBOPTS */
|
||||
}
|
||||
|
||||
switch (speed) {
|
||||
case USB_SPEED_HIGH:
|
||||
return USB_ENDPOINT_INTERRUPT_HS_MAX_SIZE;
|
||||
default:
|
||||
return USB_ENDPOINT_INTERRUPT_FS_MAX_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
usbus_endpoint_t *usbus_add_endpoint(usbus_t *usbus, usbus_interface_t *iface,
|
||||
usb_ep_type_t type, usb_ep_dir_t dir,
|
||||
size_t len)
|
||||
|
Loading…
Reference in New Issue
Block a user