mirror of
https://github.com/apache/nuttx.git
synced 2026-06-08 18:37:46 +08:00
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
This commit is contained in:
+21
-1
@@ -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:
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 *****************************************************/
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user