1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

USBUS/hid: Adapt to xmit API

This commit is contained in:
Koen Zandberg 2021-10-26 19:47:31 +02:00
parent 5455c40c7a
commit 587d25a38e
No known key found for this signature in database
GPG Key ID: BA1718B37D79F51C
5 changed files with 18 additions and 6 deletions

View File

@ -113,7 +113,7 @@ typedef struct usbus_cdcecm_device {
unsigned active_iface; /**< Current active data interface */ unsigned active_iface; /**< Current active data interface */
/** /**
* @brief Buffer for received frames * @brief Buffer for received frames from the host
*/ */
usbdev_ep_buf_t data_out[ETHERNET_FRAME_LEN]; usbdev_ep_buf_t data_out[ETHERNET_FRAME_LEN];

View File

@ -77,6 +77,16 @@ struct usbus_hid_device {
usbus_hid_cb_t cb; /**< Callback for data handlers */ usbus_hid_cb_t cb; /**< Callback for data handlers */
event_t tx_ready; /**< Transmit ready event */ event_t tx_ready; /**< Transmit ready event */
mutex_t in_lock; /**< mutex used for locking hid send */ mutex_t in_lock; /**< mutex used for locking hid send */
/**
* @brief Host to device data buffer
*/
usbdev_ep_buf_t out_buf[CONFIG_USBUS_HID_INTERRUPT_EP_SIZE];
/**
* @brief Device to host data buffer
*/
usbdev_ep_buf_t in_buf[CONFIG_USBUS_HID_INTERRUPT_EP_SIZE];
}; };
/** /**

View File

@ -142,6 +142,7 @@ static int _recv(netdev_t *netdev, void *buf, size_t max_len, void *info)
return pktlen; return pktlen;
} }
if (pktlen <= max_len) { if (pktlen <= max_len) {
/* Copy the received data from the host to the netif buffer */
memcpy(buf, cdcecm->data_out, pktlen); memcpy(buf, cdcecm->data_out, pktlen);
} }
_signal_rx_flush(cdcecm); _signal_rx_flush(cdcecm);

View File

@ -77,7 +77,7 @@ static void _handle_tx_ready(event_t *ev)
{ {
usbus_hid_device_t *hid = container_of(ev, usbus_hid_device_t, tx_ready); usbus_hid_device_t *hid = container_of(ev, usbus_hid_device_t, tx_ready);
usbdev_ep_ready(hid->ep_in->ep, hid->occupied); usbdev_ep_xmit(hid->ep_in->ep, hid->in_buf, hid->occupied);
} }
void usbus_hid_init(usbus_t *usbus, usbus_hid_device_t *hid, usbus_hid_cb_t cb, void usbus_hid_init(usbus_t *usbus, usbus_hid_device_t *hid, usbus_hid_cb_t cb,
@ -138,7 +138,8 @@ static void _init(usbus_t *usbus, usbus_handler_t *handler)
usbus_enable_endpoint(hid->ep_out); usbus_enable_endpoint(hid->ep_out);
/* signal that INTERRUPT OUT is ready to receive data */ /* signal that INTERRUPT OUT is ready to receive data */
usbdev_ep_ready(hid->ep_out->ep, 0); usbdev_ep_xmit(hid->ep_out->ep, hid->out_buf,
CONFIG_USBUS_HID_INTERRUPT_EP_SIZE);
usbus_add_interface(usbus, &hid->iface); usbus_add_interface(usbus, &hid->iface);
} }
@ -222,8 +223,8 @@ static void _transfer_handler(usbus_t *usbus, usbus_handler_t *handler,
size_t len; size_t len;
usbdev_ep_get(ep, USBOPT_EP_AVAILABLE, &len, sizeof(size_t)); usbdev_ep_get(ep, USBOPT_EP_AVAILABLE, &len, sizeof(size_t));
if (len > 0) { if (len > 0) {
hid->cb(hid, ep->buf, len); hid->cb(hid, hid->out_buf, len);
} }
usbdev_ep_ready(ep, 0); usbdev_ep_xmit(ep, hid->out_buf, CONFIG_USBUS_HID_INTERRUPT_EP_SIZE);
} }
} }

View File

@ -50,7 +50,7 @@ int usb_hid_io_read_timeout(void *buffer, size_t len, uint32_t timeout)
void usb_hid_io_write(const void *buffer, size_t len) void usb_hid_io_write(const void *buffer, size_t len)
{ {
assert(buffer); assert(buffer);
uint8_t *buffer_ep = hid.ep_in->ep->buf; uint8_t *buffer_ep = hid.in_buf;
uint16_t max_size = hid.ep_in->maxpacketsize; uint16_t max_size = hid.ep_in->maxpacketsize;
size_t offset = 0; size_t offset = 0;