diff options
author | Bill Richardson <wfrichar@chromium.org> | 2015-05-29 14:48:06 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-05-29 23:58:10 +0000 |
commit | 1ade8e02a7379732683e34b5cd71acfb2f1685ce (patch) | |
tree | 024ef38e75d3602c00c156828d7dc6fea0cffe4b /chip/g/usb_hid.c | |
parent | 3c2be1a44089e4ecffd8a6462583fc276ad76790 (diff) | |
download | chrome-ec-1ade8e02a7379732683e34b5cd71acfb2f1685ce.tar.gz |
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 <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/274130
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'chip/g/usb_hid.c')
-rw-r--r-- | chip/g/usb_hid.c | 13 |
1 files changed, 7 insertions, 6 deletions
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; |