diff options
author | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-01-27 16:25:57 +0000 |
---|---|---|
committer | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-01-27 16:25:57 +0000 |
commit | b8e32a94f3aad58ed203410fa5f11959a0a63f70 (patch) | |
tree | fe3cbb3a753d0755ceced271a369b0d92594e0fb /nuttx/drivers/usbdev | |
parent | cd24ef4a3026c7201e5332d4f905bdddad76051e (diff) | |
download | px4-firmware-b8e32a94f3aad58ed203410fa5f11959a0a63f70.tar.gz px4-firmware-b8e32a94f3aad58ed203410fa5f11959a0a63f70.tar.bz2 px4-firmware-b8e32a94f3aad58ed203410fa5f11959a0a63f70.zip |
First round of changes from debug of USB composite device (still has problems)
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4342 7fd9a85b-ad96-42d3-883c-3090e2eb8679
Diffstat (limited to 'nuttx/drivers/usbdev')
-rw-r--r-- | nuttx/drivers/usbdev/cdcacm.h | 22 | ||||
-rw-r--r-- | nuttx/drivers/usbdev/cdcacm_descriptors.c | 31 | ||||
-rw-r--r-- | nuttx/drivers/usbdev/composite.h | 12 | ||||
-rw-r--r-- | nuttx/drivers/usbdev/composite_descriptors.c | 36 | ||||
-rw-r--r-- | nuttx/drivers/usbdev/usbmsc.c | 4 | ||||
-rw-r--r-- | nuttx/drivers/usbdev/usbmsc.h | 7 | ||||
-rw-r--r-- | nuttx/drivers/usbdev/usbmsc_descriptors.c | 30 |
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; } /**************************************************************************** |