USB: Add setup packet struct and parsing routine

This can be used by interface specific EP0 setup
packet callbacks.  The USB-SPI bridge will use
this to handle enabling and disabling the bridge.

Signed-off-by: Anton Staaf <robotboy@chromium.org>

BRANCH=None
BUG=None
TEST=make buildall -j

Change-Id: I3f3db65934707243f54bed9e093f376b6978d271
Reviewed-on: https://chromium-review.googlesource.com/232367
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
Trybot-Ready: Anton Staaf <robotboy@chromium.org>
This commit is contained in:
Anton Staaf
2014-12-01 13:33:16 -08:00
committed by chrome-internal-fetch
parent 8bb26a29b0
commit 0967049df6
2 changed files with 21 additions and 0 deletions

View File

@@ -83,6 +83,15 @@ static int desc_left;
/* pointer to descriptor data if any */
static const uint8_t *desc_ptr;
void usb_read_setup_packet(usb_uint *buffer, struct usb_setup_packet *packet)
{
packet->bmRequestType = buffer[0] & 0xff;
packet->bRequest = buffer[0] >> 8;
packet->wValue = buffer[1];
packet->wIndex = buffer[2];
packet->wLength = buffer[3];
}
/* Requests on the control endpoint (aka EP0) */
static void ep0_rx(void)
{

View File

@@ -194,6 +194,15 @@ struct usb_endpoint_descriptor {
#define USB_BC12_CHARGE_VOLTAGE 5000 /* mV */
/* Setup Packet */
struct usb_setup_packet {
uint8_t bmRequestType;
uint8_t bRequest;
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
};
/* Helpers for descriptors */
#define WIDESTR(quote) WIDESTR2(quote)
@@ -242,6 +251,9 @@ struct stm32_endpoint {
extern struct stm32_endpoint btable_ep[];
/* Read from USB RAM into a usb_setup_packet struct */
void usb_read_setup_packet(usb_uint *buffer, struct usb_setup_packet *packet);
/* Copy data to the USB dedicated RAM and take care of the weird addressing */
static inline void memcpy_usbram(usb_uint *ebuf, const uint8_t *src, int size)
{