1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-24 14:03:55 +01:00

Merge pull request #12536 from bergzand/pr/usbus/cdcacm_activate_on_dte_present

cdcacm: Activate data out endpoint on DTE present signal
This commit is contained in:
benpicco 2019-10-29 13:03:39 +01:00 committed by GitHub
commit acaaee910e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 1 deletions

View File

@ -427,6 +427,24 @@ uint16_t usbus_add_string_descriptor(usbus_t *usbus, usbus_string_t *desc,
*/
uint16_t usbus_add_interface(usbus_t *usbus, usbus_interface_t *iface);
/**
* @brief Find an endpoint from an interface based on the endpoint properties
*
* This iterates over the endpoints in an interface and will return the first
* endpoint from the interface matching the @p type and @p dir. It will return
* NULL when no matching endpoint is found.
*
* @param[in] interface interface to look in
* @param[in] type endpoint type to match
* @param[in] dir endpoint direction to match
*
* @return ptr to the first matching endpoint
* @return NULL when no endpoint is found
*/
usbus_endpoint_t *usbus_interface_find_endpoint(usbus_interface_t *interface,
usb_ep_type_t type,
usb_ep_dir_t dir);
/**
* @brief Add an endpoint to the specified interface
*

View File

@ -213,12 +213,13 @@ static void _init(usbus_t *usbus, usbus_handler_t *handler)
USBUS_CDC_ACM_BULK_EP_SIZE);
ep->interval = 0; /* Interval is not used with bulk endpoints */
usbus_enable_endpoint(ep);
/* Store the endpoint reference to activate it
* when DTE present is signalled by the host */
ep = usbus_add_endpoint(usbus, &cdcacm->iface_data,
USB_EP_TYPE_BULK, USB_EP_DIR_OUT,
USBUS_CDC_ACM_BULK_EP_SIZE);
ep->interval = 0; /* Interval is not used with bulk endpoints */
usbus_enable_endpoint(ep);
usbdev_ep_ready(ep->ep, 0);
/* Add interfaces to the stack */
usbus_add_interface(usbus, &cdcacm->iface_ctrl);
@ -271,6 +272,10 @@ static int _control_handler(usbus_t *usbus, usbus_handler_t *handler,
if (setup->value & USB_CDC_ACM_CONTROL_LINE_DTE) {
DEBUG("CDC ACM: DTE enabled on interface %u\n", setup->index);
cdcacm->state = USBUS_CDC_ACM_LINE_STATE_DTE;
usbus_endpoint_t *data_out = usbus_interface_find_endpoint(
&cdcacm->iface_data, USB_EP_TYPE_BULK, USB_EP_DIR_OUT);
assert(data_out);
usbdev_ep_ready(data_out->ep, 0);
usbus_cdc_acm_flush(cdcacm);
}
else {

View File

@ -127,6 +127,18 @@ void usbus_register_event_handler(usbus_t *usbus, usbus_handler_t *handler)
*last = handler;
}
usbus_endpoint_t *usbus_interface_find_endpoint(usbus_interface_t *interface,
usb_ep_type_t type,
usb_ep_dir_t dir)
{
for (usbus_endpoint_t *uep = interface->ep; uep; uep = uep->next) {
if (uep->ep->type == type && uep->ep->dir == dir) {
return uep;
}
}
return NULL;
}
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)