summaryrefslogtreecommitdiff
path: root/nuttx/drivers/usbdev
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-01-27 16:25:57 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-01-27 16:25:57 +0000
commit7a0c66e591a0f4023fb44878f76f567448b8a3eb (patch)
treefe3cbb3a753d0755ceced271a369b0d92594e0fb /nuttx/drivers/usbdev
parent8f6700143c5b021a5a1bd3e21a8c20f177e8e9f2 (diff)
downloadpx4-nuttx-7a0c66e591a0f4023fb44878f76f567448b8a3eb.tar.gz
px4-nuttx-7a0c66e591a0f4023fb44878f76f567448b8a3eb.tar.bz2
px4-nuttx-7a0c66e591a0f4023fb44878f76f567448b8a3eb.zip
First round of changes from debug of USB composite device (still has problems)
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4342 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/drivers/usbdev')
-rw-r--r--nuttx/drivers/usbdev/cdcacm.h22
-rw-r--r--nuttx/drivers/usbdev/cdcacm_descriptors.c31
-rw-r--r--nuttx/drivers/usbdev/composite.h12
-rw-r--r--nuttx/drivers/usbdev/composite_descriptors.c36
-rw-r--r--nuttx/drivers/usbdev/usbmsc.c4
-rw-r--r--nuttx/drivers/usbdev/usbmsc.h7
-rw-r--r--nuttx/drivers/usbdev/usbmsc_descriptors.c30
7 files changed, 99 insertions, 43 deletions
diff --git a/nuttx/drivers/usbdev/cdcacm.h b/nuttx/drivers/usbdev/cdcacm.h
index 13007d18c..a107fd060 100644
--- a/nuttx/drivers/usbdev/cdcacm.h
+++ b/nuttx/drivers/usbdev/cdcacm.h
@@ -64,6 +64,10 @@
# define CONFIG_CDCACM_STRBASE (4)
#endif
+#if defined(CONFIG_CDCACM_COMPOSITE) && !defined(CONFIG_COMPOSITE_IAD)
+# warning "CONFIG_COMPOSITE_IAD may be needed"
+#endif
+
/* Packet and request buffer sizes */
#ifndef CONFIG_CDCACM_COMPOSITE
@@ -158,7 +162,7 @@
/* Configuration descriptor size */
-#ifndef CONFIG_CDCACM_COMPOSITE
+#if !defined(CONFIG_CDCACM_COMPOSITE)
/* Number of individual descriptors in the configuration descriptor:
* Configuration descriptor + (2) interface descriptors + (3) endpoint
@@ -172,6 +176,22 @@
# define SIZEOF_CDCACM_CFGDESC \
(USB_SIZEOF_CFGDESC + 2*USB_SIZEOF_IFDESC + 3*USB_SIZEOF_EPDESC + \
SIZEOF_ACM_FUNCDESC + SIZEOF_HDR_FUNCDESC + SIZEOF_UNION_FUNCDESC(1))
+
+#elif defined(CONFIG_COMPOSITE_IAD)
+
+/* Number of individual descriptors in the configuration descriptor:
+ * (1) interface association descriptor + (2) interface descriptors +
+ * (3) endpoint descriptors + (3) ACM descriptors.
+ */
+
+# define CDCACM_CFGGROUP_SIZE (9)
+
+/* The size of the config descriptor: (8 + 2*9 + 3*7 + 4 + 5 + 5) = 61 */
+
+# define SIZEOF_CDCACM_CFGDESC \
+ (USB_SIZEOF_IADDESC +2*USB_SIZEOF_IFDESC + 3*USB_SIZEOF_EPDESC + \
+ SIZEOF_ACM_FUNCDESC + SIZEOF_HDR_FUNCDESC + SIZEOF_UNION_FUNCDESC(1))
+
#else
/* Number of individual descriptors in the configuration descriptor:
diff --git a/nuttx/drivers/usbdev/cdcacm_descriptors.c b/nuttx/drivers/usbdev/cdcacm_descriptors.c
index 80bbfbfd1..11a83541e 100644
--- a/nuttx/drivers/usbdev/cdcacm_descriptors.c
+++ b/nuttx/drivers/usbdev/cdcacm_descriptors.c
@@ -139,6 +139,22 @@ static const struct usb_cfgdesc_s g_cfgdesc =
};
#endif
+/* Interface association descriptor */
+
+#if defined(CONFIG_CDCACM_COMPOSITE) && defined(CONFIG_COMPOSITE_IAD)
+static const struct usb_iaddesc_s g_iaddesc =
+{
+ USB_SIZEOF_IADDESC, /* len */
+ USB_DESC_TYPE_INTERFACEASSOCIATION, /* type */
+ CONFIG_CDCACM_IFNOBASE, /* firstif */
+ CDCACM_NINTERFACES, /* nifs */
+ USB_CLASS_CDC, /* class */
+ CDC_SUBCLASS_ACM, /* subclass */
+ CDC_PROTO_NONE, /* protocol */
+ 0 /* ifunction */
+};
+#endif
+
/* Notification interface */
static const struct usb_ifdesc_s g_notifdesc =
@@ -273,12 +289,25 @@ static const struct cfgdecsc_group_s g_cfggroup[CDCACM_CFGGROUP_SIZE] =
* provided by the composite device logic.
*/
-#ifndef CONFIG_CDCACM_COMPOSITE
+#if !defined(CONFIG_CDCACM_COMPOSITE)
{
USB_SIZEOF_CFGDESC, /* 1. Configuration descriptor */
0,
(FAR void *)&g_cfgdesc
},
+
+ /* If the serial device is part of a composite device, then it should
+ * begin with an interface association descriptor (IAD) because the
+ * CDC/ACM device consists of more than one interface. The IAD associates
+ * the two CDC/ACM interfaces with the same CDC/ACM device.
+ */
+
+#elif defined(CONFIG_COMPOSITE_IAD)
+ {
+ USB_SIZEOF_IADDESC, /* 1. Interface association descriptor */
+ 0,
+ (FAR void *)&g_iaddesc
+ },
#endif
{
USB_SIZEOF_IFDESC, /* 2. Notification interface */
diff --git a/nuttx/drivers/usbdev/composite.h b/nuttx/drivers/usbdev/composite.h
index f1f624c1c..aaddfad34 100644
--- a/nuttx/drivers/usbdev/composite.h
+++ b/nuttx/drivers/usbdev/composite.h
@@ -185,6 +185,18 @@
# warning "Interface numbers are not contiguous"
#endif
+/* Check if an IAD is needed */
+
+#ifdef CONFIG_COMPOSITE_IAD
+# if DEV1_NINTERFACES == 1 && DEV2_NINTERFACES == 1
+# warning "CONFIG_COMPOSITE_IAD not needed"
+# endif
+#endif
+
+#if !defined(CONFIG_COMPOSITE_IAD) && DEV1_NINTERFACES > 1 && DEV2_NINTERFACES > 1
+# warning "CONFIG_COMPOSITE_IAD may be needed"
+#endif
+
/* Total size of the configuration descriptor: */
#define COMPOSITE_CFGDESCSIZE (USB_SIZEOF_CFGDESC + DEV1_CFGDESCSIZE + DEV2_CFGDESCSIZE)
diff --git a/nuttx/drivers/usbdev/composite_descriptors.c b/nuttx/drivers/usbdev/composite_descriptors.c
index 349a54c6c..5c9e586d8 100644
--- a/nuttx/drivers/usbdev/composite_descriptors.c
+++ b/nuttx/drivers/usbdev/composite_descriptors.c
@@ -84,9 +84,15 @@ static const struct usb_devdesc_s g_devdesc =
LSBYTE(0x0200),
MSBYTE(0x0200)
},
+#ifdef CONFIG_COMPOSITE_IAD
+ USB_CLASS_MISC, /* class */
+ 2, /* subclass */
+ 1, /* protocol */
+#else
USB_CLASS_PER_INTERFACE, /* class */
0, /* subclass */
0, /* protocol */
+#endif
CONFIG_COMPOSITE_EP0MAXPACKET, /* maxpacketsize */
{
LSBYTE(CONFIG_COMPOSITE_VENDORID), /* vendor */
@@ -240,31 +246,31 @@ int16_t composite_mkcfgdesc(uint8_t *buf, uint8_t speed, uint8_t type)
int16_t composite_mkcfgdesc(uint8_t *buf)
#endif
{
- FAR struct usb_cfgdesc_s *cfgdesc = (struct usb_cfgdesc_s*)buf;
int16_t len;
+ int16_t total;
/* Configuration descriptor -- Copy the canned configuration descriptor. */
- memcpy(cfgdesc, &g_cfgdesc, USB_SIZEOF_CFGDESC);
- len = USB_SIZEOF_CFGDESC;
- buf += USB_SIZEOF_CFGDESC;
+ memcpy(buf, &g_cfgdesc, USB_SIZEOF_CFGDESC);
+ total = USB_SIZEOF_CFGDESC;
+ buf += USB_SIZEOF_CFGDESC;
- /* Copy DEV1/DEV2 configuration descriptors */
+ /* Copy DEV1/DEV2 interface descriptors */
#ifdef CONFIG_USBDEV_DUALSPEED
- len = DEV1_MKCFGDESC(buf, speed, type);
- buf += len;
- len = DEV2_MKCFGDESC(buf, speed, type);
- buf += len;
+ len = DEV1_MKCFGDESC(buf, speed, type);
+ total += len;
+ buf += len;
+ total += DEV2_MKCFGDESC(buf, speed, type);
#else
- len = DEV1_MKCFGDESC(buf);
- buf += len;
- len = DEV2_MKCFGDESC(buf);
- buf += len;
+ len = DEV1_MKCFGDESC(buf);
+ total += len;
+ buf += len;
+ total += DEV2_MKCFGDESC(buf);
#endif
- DEBUGASSERT(len == COMPOSITE_CFGDESCSIZE);
- return COMPOSITE_CFGDESCSIZE;
+ DEBUGASSERT(total == COMPOSITE_CFGDESCSIZE);
+ return total;
}
/****************************************************************************
diff --git a/nuttx/drivers/usbdev/usbmsc.c b/nuttx/drivers/usbdev/usbmsc.c
index 0c444c156..f521c0a2d 100644
--- a/nuttx/drivers/usbdev/usbmsc.c
+++ b/nuttx/drivers/usbdev/usbmsc.c
@@ -1660,6 +1660,7 @@ errout_with_mutex:
int usbmsc_classobject(FAR void *handle,
FAR struct usbdevclass_driver_s **classdev)
{
+ FAR struct usbmsc_alloc_s *alloc = (FAR struct usbmsc_alloc_s *)handle;
int ret;
DEBUGASSERT(handle && classdev);
@@ -1673,8 +1674,7 @@ int usbmsc_classobject(FAR void *handle,
{
/* On sucess, return an (typed) instance of the class instance */
- *classdev = (FAR struct usbdevclass_driver_s *)
- &((FAR struct usbmsc_alloc_s *)handle)->dev;
+ *classdev = &alloc->drvr.drvr;
}
return ret;
}
diff --git a/nuttx/drivers/usbdev/usbmsc.h b/nuttx/drivers/usbdev/usbmsc.h
index 910aef8bd..a656872a2 100644
--- a/nuttx/drivers/usbdev/usbmsc.h
+++ b/nuttx/drivers/usbdev/usbmsc.h
@@ -369,7 +369,8 @@
/* The size of the config descriptor: (9 + 9 + 2*7) = 32 */
# define SIZEOF_USBMSC_CFGDESC \
- (USB_SIZEOF_CFGDESC + USB_SIZEOF_IFDESC + 2*USB_SIZEOF_EPDESC)
+ (USB_SIZEOF_CFGDESC + USB_SIZEOF_IFDESC + USBMSC_NENDPOINTS * USB_SIZEOF_EPDESC)
+
#else
/* Number of individual descriptors in the configuration descriptor:
@@ -380,7 +381,9 @@
/* The size of the config descriptor: (9 + 2*7) = 23 */
-# define SIZEOF_USBMSC_CFGDESC (USB_SIZEOF_IFDESC + 2*USB_SIZEOF_EPDESC)
+# define SIZEOF_USBMSC_CFGDESC \
+ (USB_SIZEOF_IFDESC + USBMSC_NENDPOINTS * USB_SIZEOF_EPDESC)
+
#endif
/* Block driver helpers *****************************************************/
diff --git a/nuttx/drivers/usbdev/usbmsc_descriptors.c b/nuttx/drivers/usbdev/usbmsc_descriptors.c
index 30a48f1bf..5d8efd448 100644
--- a/nuttx/drivers/usbdev/usbmsc_descriptors.c
+++ b/nuttx/drivers/usbdev/usbmsc_descriptors.c
@@ -109,7 +109,10 @@ static const struct usb_cfgdesc_s g_cfgdesc =
{
USB_SIZEOF_CFGDESC, /* len */
USB_DESC_TYPE_CONFIG, /* type */
- {0, 0}, /* totallen -- to be provided */
+ { /* totallen */
+ LSBYTE(SIZEOF_USBMSC_CFGDESC),
+ MSBYTE(SIZEOF_USBMSC_CFGDESC)
+ },
USBMSC_NINTERFACES, /* ninterfaces */
USBMSC_CONFIGID, /* cfgvalue */
USBMSC_CONFIGSTRID, /* icfg */
@@ -353,30 +356,19 @@ int16_t usbmsc_mkcfgdesc(uint8_t *buf, uint8_t speed, uint8_t type)
int16_t usbmsc_mkcfgdesc(uint8_t *buf)
#endif
{
-#ifndef CONFIG_USBMSC_COMPOSITE
- FAR struct usb_cfgdesc_s *cfgdesc = (struct usb_cfgdesc_s*)buf;
-#endif
#ifdef CONFIG_USBDEV_DUALSPEED
FAR const struct usb_epdesc_s *epdesc;
bool hispeed = (speed == USB_SPEED_HIGH);
uint16_t bulkmxpacket;
#endif
- uint16_t totallen;
-
- /* This is the total length of the configuration (not necessarily the
- * size that we will be sending now.
- */
- totallen = USB_SIZEOF_CFGDESC + USB_SIZEOF_IFDESC + USBMSC_NENDPOINTS * USB_SIZEOF_EPDESC;
-
- /* Configuration descriptor -- Copy the canned descriptor and fill in the
- * type (we'll also need to update the size below). If the USB mass storage
- * device is configured as part of a composite device, then the configuration
+ /* Configuration descriptor. If the USB mass storage device is
+ * configured as part of a composite device, then the configuration
* descriptor will be provided by the composite device logic.
*/
#ifndef CONFIG_USBMSC_COMPOSITE
- memcpy(cfgdesc, &g_cfgdesc, USB_SIZEOF_CFGDESC);
+ memcpy(buf, &g_cfgdesc, USB_SIZEOF_CFGDESC);
buf += USB_SIZEOF_CFGDESC;
#endif
@@ -409,13 +401,7 @@ int16_t usbmsc_mkcfgdesc(uint8_t *buf)
memcpy(buf, &g_fsepbulkindesc, USB_SIZEOF_EPDESC);
#endif
- /* Finally, fill in the total size of the configuration descriptor */
-
-#ifndef CONFIG_USBMSC_COMPOSITE
- cfgdesc->totallen[0] = LSBYTE(totallen);
- cfgdesc->totallen[1] = MSBYTE(totallen);
-#endif
- return totallen;
+ return SIZEOF_USBMSC_CFGDESC;
}
/****************************************************************************