diff --git a/drivers/usbdev/Make.defs b/drivers/usbdev/Make.defs index 8b09b0fcb7e..427f66cadad 100644 --- a/drivers/usbdev/Make.defs +++ b/drivers/usbdev/Make.defs @@ -35,7 +35,7 @@ ifeq ($(CONFIG_USBMSC),y) endif ifeq ($(CONFIG_USBDEV_COMPOSITE),y) - CSRCS += composite.c composite_desc.c + CSRCS += composite_desc.c endif ifeq ($(CONFIG_USBDEV_TRACE_STRINGS),y) @@ -58,7 +58,8 @@ ifeq ($(CONFIG_NET_CDCECM),y) CSRCS += cdcecm.c endif -CSRCS += usbdev_req.c usbdev_trace.c usbdev_trprintf.c +CSRCS += composite.c usbdev_req.c +CSRCS += usbdev_trace.c usbdev_trprintf.c # Include USB device build support diff --git a/drivers/usbdev/composite.c b/drivers/usbdev/composite.c index 463282b419d..2cc1ba3955c 100644 --- a/drivers/usbdev/composite.c +++ b/drivers/usbdev/composite.c @@ -40,8 +40,6 @@ #include "composite.h" -#ifdef CONFIG_USBDEV_COMPOSITE - /**************************************************************************** * Private Types ****************************************************************************/ @@ -108,16 +106,6 @@ static const struct usbdevclass_driverops_s g_driverops = composite_resume, /* resume */ }; -/**************************************************************************** - * Public Data - ****************************************************************************/ - -const char g_compvendorstr[] = CONFIG_COMPOSITE_VENDORSTR; -const char g_compproductstr[] = CONFIG_COMPOSITE_PRODUCTSTR; -#ifndef CONFIG_COMPOSITE_BOARD_SERIALSTR -const char g_compserialstr[] = CONFIG_COMPOSITE_SERIALSTR; -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -512,7 +500,7 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver, { #ifdef CONFIG_USBDEV_DUALSPEED ret = composite_mkcfgdesc(priv, ctrlreq->buf, dev->speed, - ctrl->value[1]); + ctrl->value[1]); #else ret = composite_mkcfgdesc(priv, ctrlreq->buf); #endif @@ -527,6 +515,7 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver, FAR struct usb_strdesc_s *buf = (FAR struct usb_strdesc_s *)ctrlreq->buf; +#ifdef CONFIG_USBDEV_COMPOSITE if (strid < COMPOSITE_NSTRIDS) { ret = composite_mkstrdesc(strid, buf); @@ -571,6 +560,9 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver, } } } +#else + ret = composite_mkstrdesc(strid, buf); +#endif } break; @@ -587,7 +579,7 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver, case USB_REQ_SETCONFIGURATION: { - if (ctrl->type == 0) + if (ctrl->type == 0 && value != priv->config) { int i; @@ -622,7 +614,7 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver, case USB_REQ_SETINTERFACE: { if (ctrl->type == USB_REQ_RECIPIENT_INTERFACE && - priv->config == COMPOSITE_CONFIGID) + priv->config != COMPOSITE_CONFIGIDNONE) { ret = composite_classsetup(priv, dev, ctrl, dataout, outlen); dispatched = true; @@ -957,7 +949,7 @@ FAR void *composite_initialize(uint8_t ndevices, if (ret < 0) { usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_DEVREGISTER), - (uint16_t)-ret); + (uint16_t)-ret); goto errout_with_alloc; } @@ -1061,5 +1053,3 @@ int composite_ep0submit(FAR struct usbdevclass_driver_s *driver, return 0; } } - -#endif /* CONFIG_USBDEV_COMPOSITE */ diff --git a/drivers/usbdev/composite.h b/drivers/usbdev/composite.h index 60240005535..308501579cd 100644 --- a/drivers/usbdev/composite.h +++ b/drivers/usbdev/composite.h @@ -35,86 +35,21 @@ #include #include -#ifdef CONFIG_USBDEV_COMPOSITE - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -/* Configuration ************************************************************/ - -/* Packet sizes */ - -#ifndef CONFIG_COMPOSITE_EP0MAXPACKET -# define CONFIG_COMPOSITE_EP0MAXPACKET 64 -#endif - -/* Vendor and product IDs and strings */ - -#ifndef CONFIG_COMPOSITE_COMPOSITE -# ifndef CONFIG_COMPOSITE_VENDORID -# warning "CONFIG_COMPOSITE_VENDORID not defined" -# define CONFIG_COMPOSITE_VENDORID 0x03eb -# endif - -# ifndef CONFIG_COMPOSITE_PRODUCTID -# warning "CONFIG_COMPOSITE_PRODUCTID not defined" -# define CONFIG_COMPOSITE_PRODUCTID 0x2022 -# endif - -# ifndef CONFIG_COMPOSITE_VERSIONNO -# define CONFIG_COMPOSITE_VERSIONNO (0x0101) -# endif - -# ifndef CONFIG_COMPOSITE_VENDORSTR -# warning "No Vendor string specified" -# define CONFIG_COMPOSITE_VENDORSTR "NuttX" -# endif - -# ifndef CONFIG_COMPOSITE_PRODUCTSTR -# warning "No Product string specified" -# define CONFIG_COMPOSITE_PRODUCTSTR "Composite Device" -# endif - -# undef CONFIG_COMPOSITE_SERIALSTR -# define CONFIG_COMPOSITE_SERIALSTR "0101" -#endif - -#undef CONFIG_COMPOSITE_CONFIGSTR -#define CONFIG_COMPOSITE_CONFIGSTR "Composite" - -#ifdef CONFIG_USBDEV_SELFPOWERED -# define COMPOSITE_SELFPOWERED USB_CONFIG_ATTR_SELFPOWER +#ifdef CONFIG_USBDEV_COMPOSITE +# define NUM_DEVICES_TO_HANDLE (8) #else -# define COMPOSITE_SELFPOWERED (0) +# define NUM_DEVICES_TO_HANDLE (1) #endif -#ifdef CONFIG_USBDEV_REMOTEWAKEUP -# define COMPOSITE_REMOTEWAKEUP USB_CONFIG_ATTR_WAKEUP -#else -# define COMPOSITE_REMOTEWAKEUP (0) -#endif - -#define NUM_DEVICES_TO_HANDLE (8) - -/* Descriptors **************************************************************/ - /* These settings are not modifiable via the NuttX configuration */ #define COMPOSITE_CONFIGIDNONE (0) /* Config ID = 0 means to return to address mode */ #define COMPOSITE_CONFIGID (1) /* The only supported configuration ID */ -/* String language */ - -#define COMPOSITE_STR_LANGUAGE (0x0409) /* en-us */ - -/* Descriptor strings */ - -#define COMPOSITE_MANUFACTURERSTRID (1) -#define COMPOSITE_PRODUCTSTRID (2) -#define COMPOSITE_SERIALSTRID (3) -#define COMPOSITE_CONFIGSTRID (4) - /**************************************************************************** * Public Types ****************************************************************************/ @@ -136,23 +71,24 @@ struct composite_devobj_s struct composite_dev_s { - FAR struct usbdev_s *usbdev; /* usbdev driver pointer */ - uint8_t config; /* Configuration number */ - FAR struct usbdev_req_s *ctrlreq; /* Allocated control request */ - uint8_t ndevices; /* Num devices in this composite device */ - int cfgdescsize; /* Total size of the configuration descriptor: */ - int ninterfaces; /* The total number of interfaces in this composite device */ - - struct composite_devobj_s device[NUM_DEVICES_TO_HANDLE]; /* Device class object */ + FAR struct usbdev_s *usbdev; /* usbdev driver pointer */ + FAR struct usbdev_req_s *ctrlreq; /* Allocated control request */ + int cfgdescsize; /* Total size of the configuration descriptor: */ + int ninterfaces; /* The total number of interfaces in this composite device */ + uint8_t config; /* Configuration number */ + uint8_t ndevices; /* Num devices in this composite device */ + struct composite_devobj_s device[NUM_DEVICES_TO_HANDLE]; /* Device class object */ }; /**************************************************************************** * Public Data ****************************************************************************/ +#ifdef CONFIG_USBDEV_COMPOSITE extern const char g_compvendorstr[]; extern const char g_compproductstr[]; extern const char g_compserialstr[]; +#endif /**************************************************************************** * Public Function Prototypes @@ -176,9 +112,7 @@ int composite_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc); * ****************************************************************************/ -#ifndef CONFIG_COMPOSITE_COMPOSITE FAR const struct usb_devdesc_s *composite_getdevdesc(void); -#endif /**************************************************************************** * Name: composite_mkcfgdesc @@ -208,5 +142,4 @@ int16_t composite_mkcfgdesc(FAR struct composite_dev_s *priv, FAR const struct usb_qualdesc_s *composite_getqualdesc(void); #endif -#endif /* CONFIG_USBDEV_COMPOSITE */ #endif /* __DRIVERS_USBDEV_COMPOSITE_H */ diff --git a/drivers/usbdev/composite_desc.c b/drivers/usbdev/composite_desc.c index 1621f8a9919..fd4661b84e2 100644 --- a/drivers/usbdev/composite_desc.c +++ b/drivers/usbdev/composite_desc.c @@ -42,6 +42,75 @@ #ifdef CONFIG_USBDEV_COMPOSITE +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/* Packet sizes */ + +#ifndef CONFIG_COMPOSITE_EP0MAXPACKET +# define CONFIG_COMPOSITE_EP0MAXPACKET 64 +#endif + +/* Vendor and product IDs and strings */ + +#ifndef CONFIG_COMPOSITE_VENDORID +# warning "CONFIG_COMPOSITE_VENDORID not defined" +# define CONFIG_COMPOSITE_VENDORID 0x03eb +#endif + +#ifndef CONFIG_COMPOSITE_PRODUCTID +# warning "CONFIG_COMPOSITE_PRODUCTID not defined" +# define CONFIG_COMPOSITE_PRODUCTID 0x2022 +#endif + +#ifndef CONFIG_COMPOSITE_VERSIONNO +# define CONFIG_COMPOSITE_VERSIONNO (0x0101) +#endif + +#ifndef CONFIG_COMPOSITE_VENDORSTR +# warning "No Vendor string specified" +# define CONFIG_COMPOSITE_VENDORSTR "NuttX" +#endif + +#ifndef CONFIG_COMPOSITE_PRODUCTSTR +# warning "No Product string specified" +# define CONFIG_COMPOSITE_PRODUCTSTR "Composite Device" +#endif + +#undef CONFIG_COMPOSITE_SERIALSTR +#define CONFIG_COMPOSITE_SERIALSTR "0101" + +#undef CONFIG_COMPOSITE_CONFIGSTR +#define CONFIG_COMPOSITE_CONFIGSTR "Composite" + +#ifdef CONFIG_USBDEV_SELFPOWERED +# define COMPOSITE_SELFPOWERED USB_CONFIG_ATTR_SELFPOWER +#else +# define COMPOSITE_SELFPOWERED (0) +#endif + +#ifdef CONFIG_USBDEV_REMOTEWAKEUP +# define COMPOSITE_REMOTEWAKEUP USB_CONFIG_ATTR_WAKEUP +#else +# define COMPOSITE_REMOTEWAKEUP (0) +#endif + +/* Descriptors **************************************************************/ + +/* String language */ + +#define COMPOSITE_STR_LANGUAGE (0x0409) /* en-us */ + +/* Descriptor strings */ + +#define COMPOSITE_MANUFACTURERSTRID (1) +#define COMPOSITE_PRODUCTSTRID (2) +#define COMPOSITE_SERIALSTRID (3) +#define COMPOSITE_CONFIGSTRID (4) + /**************************************************************************** * Private Data ****************************************************************************/ @@ -102,6 +171,16 @@ static const struct usb_qualdesc_s g_qualdesc = }; #endif +/**************************************************************************** + * Public Data + ****************************************************************************/ + +const char g_compvendorstr[] = CONFIG_COMPOSITE_VENDORSTR; +const char g_compproductstr[] = CONFIG_COMPOSITE_PRODUCTSTR; +#ifndef CONFIG_COMPOSITE_BOARD_SERIALSTR +const char g_compserialstr[] = CONFIG_COMPOSITE_SERIALSTR; +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/include/nuttx/usb/composite.h b/include/nuttx/usb/composite.h index dcf2552ebb9..22a665dcd21 100644 --- a/include/nuttx/usb/composite.h +++ b/include/nuttx/usb/composite.h @@ -28,8 +28,6 @@ #include #include -#ifdef CONFIG_USBDEV_COMPOSITE - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -142,5 +140,4 @@ int composite_ep0submit(FAR struct usbdevclass_driver_s *driver, } #endif -#endif /* CONFIG_USBDEV_COMPOSITE */ #endif /* __INCLUDE_NUTTX_USB_COMPOSITE_H */ diff --git a/include/nuttx/usb/usbdev.h b/include/nuttx/usb/usbdev.h index d5d493aa7f4..9c2dc3f9b62 100644 --- a/include/nuttx/usb/usbdev.h +++ b/include/nuttx/usb/usbdev.h @@ -182,7 +182,7 @@ struct usbdev_devinfo_s int epno[5]; /* Array holding the endpoint configuration for this device */ }; -#ifdef CONFIG_USBDEV_COMPOSITE +struct usbdevclass_driver_s; struct composite_devdesc_s { #ifdef CONFIG_USBDEV_DUALSPEED @@ -213,7 +213,6 @@ struct composite_devdesc_s struct usbdev_devinfo_s devinfo; }; -#endif /* struct usbdev_req_s - describes one i/o request */ @@ -315,7 +314,6 @@ struct usbdev_s /* USB Device Class Implementations *****************************************/ -struct usbdevclass_driver_s; struct usbdevclass_driverops_s { CODE int (*bind)(FAR struct usbdevclass_driver_s *driver,