From 1ade8e02a7379732683e34b5cd71acfb2f1685ce Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Fri, 29 May 2015 14:48:06 -0700 Subject: Cr50: Use USB structs instead of byte arrays for readability The USB spec mandates that all structs are little-endian over the wire. Since we're a little-endian architecture (and the code we're changing is intentionally chip-specific), we can just cast the hardware buffer into the correct struct. This makes the code easier to read and understand. BUG=none BRANCH=none TEST=make buildall Change-Id: Ib2d3b04f4db1a531cb3f5ada1a2e6ee82e8a23aa Signed-off-by: Bill Richardson Reviewed-on: https://chromium-review.googlesource.com/274130 Reviewed-by: Randall Spangler --- chip/g/usb_hid.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'chip/g/usb_hid.c') diff --git a/chip/g/usb_hid.c b/chip/g/usb_hid.c index 477bbfe683..bca7c03a15 100644 --- a/chip/g/usb_hid.c +++ b/chip/g/usb_hid.c @@ -124,15 +124,16 @@ extern struct g_usb_desc ep0_out_desc; static int hid_iface_request(uint8_t *ep0_buf_rx, uint8_t *ep0_buf_tx) { - int len, req_len; + /* This chip and buffer data are all little-endian, so this works */ + struct usb_setup_packet *req = (struct usb_setup_packet *)ep0_buf_rx; + int len; - if (ep0_buf_rx[0] == (USB_DIR_IN | USB_RECIP_INTERFACE) && - ep0_buf_rx[1] == USB_REQ_GET_DESCRIPTOR && - ep0_buf_rx[3] == USB_HID_DT_REPORT) { + if (req->bmRequestType == (USB_DIR_IN | USB_RECIP_INTERFACE) && + req->bRequest == USB_REQ_GET_DESCRIPTOR && + req->wValue == (USB_HID_DT_REPORT << 8)) { /* Setup : HID specific : Get Report descriptor */ memcpy(ep0_buf_tx, report_desc, sizeof(report_desc)); - req_len = (((unsigned int)ep0_buf_rx[7]) << 8) + ep0_buf_rx[6]; - len = MIN(req_len, sizeof(report_desc)); + len = MIN(req->wLength, sizeof(report_desc)); ep0_in_desc.flags = DIEPDMA_LAST | DIEPDMA_BS_HOST_RDY | DIEPDMA_IOC | DIEPDMA_TXBYTES(len); GR_USB_DIEPCTL(0) |= DXEPCTL_CNAK | DXEPCTL_EPENA; -- cgit v1.2.1