usb_cdc: Add usb_read_ep0_setup() interface function

Use new usb_read_ep0_setup() function when reading a setup packet -
this allows the low-level usb hardware code to better handle errors.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-09-30 15:14:30 -04:00
parent 731236cf20
commit 93e4897044
4 changed files with 14 additions and 2 deletions

View File

@ -412,9 +412,8 @@ static void
usb_state_ready(void) usb_state_ready(void)
{ {
struct usb_ctrlrequest req; struct usb_ctrlrequest req;
int_fast8_t ret = usb_read_ep0(&req, sizeof(req)); int_fast8_t ret = usb_read_ep0_setup(&req, sizeof(req));
if (ret != sizeof(req)) if (ret != sizeof(req))
// XXX - should verify that packet was sent with a setup token
return; return;
switch (req.bRequest) { switch (req.bRequest) {
case USB_REQ_GET_DESCRIPTOR: usb_req_get_descriptor(&req); break; case USB_REQ_GET_DESCRIPTOR: usb_req_get_descriptor(&req); break;

View File

@ -15,6 +15,7 @@ enum {
int_fast8_t usb_read_bulk_out(void *data, uint_fast8_t max_len); int_fast8_t usb_read_bulk_out(void *data, uint_fast8_t max_len);
int_fast8_t usb_send_bulk_in(void *data, uint_fast8_t len); int_fast8_t usb_send_bulk_in(void *data, uint_fast8_t len);
int_fast8_t usb_read_ep0(void *data, uint_fast8_t max_len); int_fast8_t usb_read_ep0(void *data, uint_fast8_t max_len);
int_fast8_t usb_read_ep0_setup(void *data, uint_fast8_t max_len);
int_fast8_t usb_send_ep0(const void *data, uint_fast8_t len); int_fast8_t usb_send_ep0(const void *data, uint_fast8_t len);
int_fast8_t usb_send_ep0_progmem(const void *data, uint_fast8_t len); int_fast8_t usb_send_ep0_progmem(const void *data, uint_fast8_t len);
void usb_stall_ep0(void); void usb_stall_ep0(void);

View File

@ -189,6 +189,12 @@ usb_read_ep0(void *data, uint_fast8_t max_len)
return usb_read_packet(EP0OUT, data, max_len); return usb_read_packet(EP0OUT, data, max_len);
} }
int_fast8_t
usb_read_ep0_setup(void *data, uint_fast8_t max_len)
{
return usb_read_ep0(data, max_len);
}
int_fast8_t int_fast8_t
usb_send_ep0(const void *data, uint_fast8_t len) usb_send_ep0(const void *data, uint_fast8_t len)
{ {

View File

@ -127,6 +127,12 @@ usb_read_ep0(void *data, uint_fast8_t max_len)
return usb_read_packet(0, 0, data, max_len); return usb_read_packet(0, 0, data, max_len);
} }
int_fast8_t
usb_read_ep0_setup(void *data, uint_fast8_t max_len)
{
return usb_read_ep0(data, max_len);
}
int_fast8_t int_fast8_t
usb_send_ep0(const void *data, uint_fast8_t len) usb_send_ep0(const void *data, uint_fast8_t len)
{ {