mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
USBUS: Adapt to xmit API
Converts the control endpoint to xmit API
This commit is contained in:
parent
a6b6f43ce2
commit
7d9a177f25
@ -69,14 +69,24 @@ typedef struct {
|
||||
size_t received_len;
|
||||
|
||||
/**
|
||||
* @brief EP0 OUT endpoint
|
||||
* @brief EP0 OUT endpoint reference
|
||||
*/
|
||||
usbdev_ep_t *out;
|
||||
|
||||
/**
|
||||
* @brief EP0 IN endpoint
|
||||
* @brief EP0 IN endpoint reference
|
||||
*/
|
||||
usbdev_ep_t *in;
|
||||
|
||||
/**
|
||||
* @brief Host to device control request buffer
|
||||
*/
|
||||
usbdev_ep_buf_t out_buf[CONFIG_USBUS_EP0_SIZE];
|
||||
|
||||
/**
|
||||
* @brief Device to host control request buffer
|
||||
*/
|
||||
usbdev_ep_buf_t in_buf[CONFIG_USBUS_EP0_SIZE];
|
||||
} usbus_control_handler_t;
|
||||
|
||||
/**
|
||||
|
@ -166,7 +166,7 @@ usbus_endpoint_t *usbus_add_endpoint(usbus_t *usbus, usbus_interface_t *iface,
|
||||
if (usbdev_ep) {
|
||||
ep = dir == USB_EP_DIR_IN ? &usbus->ep_in[usbdev_ep->num]
|
||||
: &usbus->ep_out[usbdev_ep->num];
|
||||
ep->maxpacketsize = usbdev_ep->len;
|
||||
ep->maxpacketsize = len;
|
||||
ep->ep = usbdev_ep;
|
||||
if (iface) {
|
||||
ep->next = iface->ep;
|
||||
@ -325,6 +325,7 @@ static void _event_cb(usbdev_t *usbdev, usbdev_event_t event)
|
||||
sizeof(uint8_t));
|
||||
flag = USBUS_HANDLER_FLAG_RESET;
|
||||
msg = USBUS_EVENT_USB_RESET;
|
||||
DEBUG("usbus: USB reset detected\n");
|
||||
break;
|
||||
case USBDEV_EVENT_SUSPEND:
|
||||
DEBUG("usbus: USB suspend detected\n");
|
||||
|
@ -286,11 +286,11 @@ static void _recv_setup(usbus_t *usbus, usbus_control_handler_t *handler)
|
||||
/* Signal ready for new data in case there is more */
|
||||
if (handler->received_len < pkt->length) {
|
||||
handler->control_request_state = USBUS_CONTROL_REQUEST_STATE_OUTDATA;
|
||||
usbdev_ep_ready(handler->out, 1);
|
||||
usbdev_ep_xmit(handler->out, handler->out_buf, CONFIG_USBUS_EP0_SIZE);
|
||||
}
|
||||
else {
|
||||
handler->control_request_state = USBUS_CONTROL_REQUEST_STATE_INACK;
|
||||
usbdev_ep_ready(handler->in, 0);
|
||||
usbdev_ep_xmit(handler->in, handler->in_buf, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -307,7 +307,7 @@ static void _usbus_config_ep0(usbus_control_handler_t *ep0_handler)
|
||||
sizeof(usbopt_enable_t));
|
||||
usbdev_ep_set(ep0_handler->out, USBOPT_EP_ENABLE, &enable,
|
||||
sizeof(usbopt_enable_t));
|
||||
usbdev_ep_ready(ep0_handler->out, 0);
|
||||
usbdev_ep_xmit(ep0_handler->out, ep0_handler->out_buf, CONFIG_USBUS_EP0_SIZE);
|
||||
}
|
||||
|
||||
uint8_t *usbus_control_get_out_data(usbus_t *usbus, size_t *len)
|
||||
@ -317,10 +317,9 @@ uint8_t *usbus_control_get_out_data(usbus_t *usbus, size_t *len)
|
||||
assert(len);
|
||||
assert(handler->control_request_state == USBUS_CONTROL_REQUEST_STATE_OUTDATA);
|
||||
|
||||
usbdev_ep_t *ep_out = handler->out;
|
||||
usbdev_ep_get(ep_out, USBOPT_EP_AVAILABLE,
|
||||
usbdev_ep_get(handler->out, USBOPT_EP_AVAILABLE,
|
||||
len, sizeof(size_t));
|
||||
return ep_out->buf;
|
||||
return handler->out_buf;
|
||||
}
|
||||
|
||||
static void _init(usbus_t *usbus, usbus_handler_t *handler)
|
||||
@ -351,14 +350,14 @@ static int _handle_tr_complete(usbus_t *usbus,
|
||||
}
|
||||
ep0_handler->control_request_state = USBUS_CONTROL_REQUEST_STATE_READY;
|
||||
/* Ready for new control request */
|
||||
usbdev_ep_ready(ep0_handler->out, 0);
|
||||
usbdev_ep_xmit(ep0_handler->out, ep0_handler->out_buf, CONFIG_USBUS_EP0_SIZE);
|
||||
}
|
||||
break;
|
||||
case USBUS_CONTROL_REQUEST_STATE_OUTACK:
|
||||
if (ep->dir == USB_EP_DIR_OUT) {
|
||||
ep0_handler->control_request_state = USBUS_CONTROL_REQUEST_STATE_READY;
|
||||
/* Ready for new control request */
|
||||
usbdev_ep_ready(ep0_handler->out, 0);
|
||||
usbdev_ep_xmit(ep0_handler->out, ep0_handler->out_buf, CONFIG_USBUS_EP0_SIZE);
|
||||
}
|
||||
break;
|
||||
case USBUS_CONTROL_REQUEST_STATE_INDATA:
|
||||
@ -369,7 +368,7 @@ static int _handle_tr_complete(usbus_t *usbus,
|
||||
}
|
||||
else {
|
||||
/* Ready out ZLP */
|
||||
usbdev_ep_ready(ep0_handler->out, 0);
|
||||
usbdev_ep_xmit(ep0_handler->out, ep0_handler->out_buf, CONFIG_USBUS_EP0_SIZE);
|
||||
ep0_handler->control_request_state = USBUS_CONTROL_REQUEST_STATE_OUTACK;
|
||||
}
|
||||
}
|
||||
@ -389,7 +388,7 @@ static int _handle_tr_complete(usbus_t *usbus,
|
||||
case USBUS_CONTROL_REQUEST_STATE_READY:
|
||||
if (ep->dir == USB_EP_DIR_OUT) {
|
||||
memset(&ep0_handler->slicer, 0, sizeof(usbus_control_slicer_t));
|
||||
memcpy(&ep0_handler->setup, ep0_handler->out->buf,
|
||||
memcpy(&ep0_handler->setup, ep0_handler->out_buf,
|
||||
sizeof(usb_setup_t));
|
||||
ep0_handler->received_len = 0;
|
||||
ep0_handler->slicer.reqlen = ep0_handler->setup.length;
|
||||
|
@ -69,7 +69,7 @@ size_t usbus_control_slicer_put_bytes(usbus_t *usbus, const uint8_t *buf,
|
||||
size_t start_offset = bldr->cur - bldr->start + byte_offset;
|
||||
bldr->cur += len;
|
||||
bldr->len += byte_len;
|
||||
memcpy(ep0->in->buf + start_offset, buf + byte_offset, byte_len);
|
||||
memcpy(ep0->in_buf + start_offset, buf + byte_offset, byte_len);
|
||||
return byte_len;
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ size_t usbus_control_slicer_put_char(usbus_t *usbus, char c)
|
||||
|
||||
/* Only copy the char if it is within the window */
|
||||
if ((bldr->start <= bldr->cur) && (bldr->cur < end)) {
|
||||
uint8_t *pos = ep0->in->buf + bldr->cur - bldr->start;
|
||||
uint8_t *pos = ep0->in_buf + bldr->cur - bldr->start;
|
||||
*pos = c;
|
||||
bldr->cur++;
|
||||
bldr->len++;
|
||||
@ -99,5 +99,5 @@ void usbus_control_slicer_ready(usbus_t *usbus)
|
||||
|
||||
len = len < bldr->reqlen - bldr->start ? len : bldr->reqlen - bldr->start;
|
||||
bldr->transferred += len;
|
||||
usbdev_ep_ready(ep0->in, len);
|
||||
usbdev_ep_xmit(ep0->in, ep0->in_buf, len);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user