summaryrefslogtreecommitdiff
path: root/nuttx/drivers/usbhost/usbhost_enumerate.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-02-11 02:36:01 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-02-11 02:36:01 +0000
commitfb469693dc16682c912f157cfc4ccc8870d226f4 (patch)
tree33cb0515625eeac844fd800af5ae78640c56b124 /nuttx/drivers/usbhost/usbhost_enumerate.c
parenta2edaab1b166b17bdaa06a95a1bcbecd5df5828a (diff)
downloadnuttx-fb469693dc16682c912f157cfc4ccc8870d226f4.tar.gz
nuttx-fb469693dc16682c912f157cfc4ccc8870d226f4.tar.bz2
nuttx-fb469693dc16682c912f157cfc4ccc8870d226f4.zip
Add logic to get the VID and PID
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3282 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/drivers/usbhost/usbhost_enumerate.c')
-rwxr-xr-xnuttx/drivers/usbhost/usbhost_enumerate.c79
1 files changed, 36 insertions, 43 deletions
diff --git a/nuttx/drivers/usbhost/usbhost_enumerate.c b/nuttx/drivers/usbhost/usbhost_enumerate.c
index 6c56ffc5a..82c65c8bf 100755
--- a/nuttx/drivers/usbhost/usbhost_enumerate.c
+++ b/nuttx/drivers/usbhost/usbhost_enumerate.c
@@ -1,7 +1,7 @@
/*******************************************************************************
* drivers/usbhost/usbhost_enumerate.c
*
- * Copyright (C) 2010 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -65,7 +65,7 @@
static inline uint16_t usbhost_getle16(const uint8_t *val);
static void usbhost_putle16(uint8_t *dest, uint16_t val);
-static inline int usbhost_devdesc(const struct usb_devdesc_s *devdesc, int desclen,
+static inline int usbhost_devdesc(const struct usb_devdesc_s *devdesc,
struct usbhost_id_s *id);
static inline int usbhost_configdesc(const uint8_t *configdesc, int desclen,
struct usbhost_id_s *id);
@@ -123,36 +123,24 @@ static void usbhost_putle16(uint8_t *dest, uint16_t val)
*******************************************************************************/
static inline int usbhost_devdesc(const struct usb_devdesc_s *devdesc,
- int desclen, struct usbhost_id_s *id)
+ struct usbhost_id_s *id)
{
/* Clear the ID info */
memset(id, 0, sizeof(struct usbhost_id_s));
- /* Check we have enough of the structure to see the ID info. */
-
- if (desclen >= 7)
- {
- /* Pick off the ID info */
-
- id->base = devdesc->class;
- id->subclass = devdesc->subclass;
- id->proto = devdesc->protocol;
- uvdbg("class:%d subclass:%d protocol:%d\n",
- id->base, id->subclass, id->proto);
-
- /* Check if we have enough of the structure to see the VID/PID */
+ /* Pick off the ID info */
- if (desclen >= 12)
- {
- /* Yes, then pick off the VID and PID as well */
+ id->base = devdesc->class;
+ id->subclass = devdesc->subclass;
+ id->proto = devdesc->protocol;
+ uvdbg("class:%d subclass:%d protocol:%d\n", id->base, id->subclass, id->proto);
- id->vid = usbhost_getle16(devdesc->vendor);
- id->pid = usbhost_getle16(devdesc->product);
- uvdbg("vid:%d pid:%d\n", id->vid, id->pid);
- }
- }
+ /* Yes, then pick off the VID and PID as well */
+ id->vid = usbhost_getle16(devdesc->vendor);
+ id->pid = usbhost_getle16(devdesc->product);
+ uvdbg("vid:%d pid:%d\n", id->vid, id->pid);
return OK;
}
@@ -367,32 +355,37 @@ int usbhost_enumerate(FAR struct usbhost_driver_s *drvr, uint8_t funcaddr,
goto errout;
}
- /* Extract info from the device descriptor */
+ /* Extract the correct max packetsize from the device descriptor */
- {
- struct usb_devdesc_s *devdesc = (struct usb_devdesc_s *)buffer;
+ maxpacketsize = ((struct usb_devdesc_s *)buffer)->mxpacketsize;
+ uvdbg("maxpacksetsize: %d\n", maxpacketsize);
- /* Extract the max packetsize for endpoint 0 */
+ /* And reconfigure EP0 */
- maxpacketsize = devdesc->mxpacketsize;
- uvdbg("maxpacksetsize: %d\n", maxpacketsize);
+ DRVR_EP0CONFIGURE(drvr, 0, maxpacketsize);
- DRVR_EP0CONFIGURE(drvr, 0, maxpacketsize);
+ /* Now read the full device descriptor */
+
+ ctrlreq->type = USB_REQ_DIR_IN|USB_REQ_RECIPIENT_DEVICE;
+ ctrlreq->req = USB_REQ_GETDESCRIPTOR;
+ usbhost_putle16(ctrlreq->value, (USB_DESC_TYPE_DEVICE << 8));
+ usbhost_putle16(ctrlreq->index, 0);
+ usbhost_putle16(ctrlreq->len, USB_SIZEOF_DEVDESC);
- /* Get class identification information from the device descriptor. Most
- * devices set this to USB_CLASS_PER_INTERFACE (zero) and provide the
- * identification informatino in the interface descriptor(s). That allows
- * a device to support multiple, different classes.
- */
+ ret = DRVR_CTRLIN(drvr, ctrlreq, buffer);
+ if (ret != OK)
+ {
+ udbg("ERROR: GETDESCRIPTOR/DEVICE, DRVR_CTRLIN returned %d\n", ret);
+ goto errout;
+ }
- (void)usbhost_devdesc(devdesc, 8, &id);
+ /* Get class identification information from the device descriptor. Most
+ * devices set this to USB_CLASS_PER_INTERFACE (zero) and provide the
+ * identification informatino in the interface descriptor(s). That allows
+ * a device to support multiple, different classes.
+ */
- /* NOTE: Additional logic is needed here. We will need additional logic
- * to (1) get the full device descriptor, (1) extract the vendor/product IDs
- * and (2) extract the number of configurations from the (full) device
- * descriptor.
- */
- }
+ (void)usbhost_devdesc((struct usb_devdesc_s *)buffer, &id);
/* Set the USB device address to the value in the 'funcaddr' input */