From 782a98407637ecdf9afa27d99cd178d1c75db4d3 Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 23 Apr 2012 16:49:15 +0000 Subject: Rename some USB device files git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4645 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/drivers/usbdev/Make.defs | 6 +- nuttx/drivers/usbdev/cdcacm_desc.c | 613 +++++++++++++++++++++++++++ nuttx/drivers/usbdev/cdcacm_descriptors.c | 613 --------------------------- nuttx/drivers/usbdev/composite_desc.c | 291 +++++++++++++ nuttx/drivers/usbdev/composite_descriptors.c | 291 ------------- nuttx/drivers/usbdev/usbmsc_desc.c | 421 ++++++++++++++++++ nuttx/drivers/usbdev/usbmsc_descriptors.c | 421 ------------------ 7 files changed, 1328 insertions(+), 1328 deletions(-) create mode 100644 nuttx/drivers/usbdev/cdcacm_desc.c delete mode 100644 nuttx/drivers/usbdev/cdcacm_descriptors.c create mode 100644 nuttx/drivers/usbdev/composite_desc.c delete mode 100644 nuttx/drivers/usbdev/composite_descriptors.c create mode 100644 nuttx/drivers/usbdev/usbmsc_desc.c delete mode 100644 nuttx/drivers/usbdev/usbmsc_descriptors.c (limited to 'nuttx/drivers/usbdev') diff --git a/nuttx/drivers/usbdev/Make.defs b/nuttx/drivers/usbdev/Make.defs index 445cf7817..f1b3c405a 100644 --- a/nuttx/drivers/usbdev/Make.defs +++ b/nuttx/drivers/usbdev/Make.defs @@ -42,15 +42,15 @@ ifeq ($(CONFIG_PL2303),y) endif ifeq ($(CONFIG_CDCACM),y) - CSRCS += cdcacm.c cdcacm_descriptors.c + CSRCS += cdcacm.c cdcacm_desc.c endif ifeq ($(CONFIG_USBMSC),y) - CSRCS += usbmsc.c usbmsc_descriptors.c usbmsc_scsi.c + CSRCS += usbmsc.c usbmsc_desc.c usbmsc_scsi.c endif ifeq ($(CONFIG_USBDEV_COMPOSITE),y) - CSRCS += composite.c composite_descriptors.c + CSRCS += composite.c composite_desc.c endif CSRCS += usbdev_trace.c usbdev_trprintf.c diff --git a/nuttx/drivers/usbdev/cdcacm_desc.c b/nuttx/drivers/usbdev/cdcacm_desc.c new file mode 100644 index 000000000..fde13bfd3 --- /dev/null +++ b/nuttx/drivers/usbdev/cdcacm_desc.c @@ -0,0 +1,613 @@ +/**************************************************************************** + * drivers/usbdev/cdcacm_desc.c + * + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "cdcacm.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* Describes one description in the group of descriptors forming the + * total configuration descriptor. + */ + +struct cfgdecsc_group_s +{ + uint16_t descsize; /* Size of the descriptor in bytes */ + uint16_t hsepsize; /* High speed max packet size */ + FAR void *desc; /* A pointer to the descriptor */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* USB descriptor templates these will be copied and modified **************/ +/* Device Descriptor. If the USB serial device is configured as part of + * composite device, then the device descriptor will be provided by the + * composite device logic. + */ + +#ifndef CONFIG_CDCACM_COMPOSITE +static const struct usb_devdesc_s g_devdesc = +{ + USB_SIZEOF_DEVDESC, /* len */ + USB_DESC_TYPE_DEVICE, /* type */ + { /* usb */ + LSBYTE(0x0200), + MSBYTE(0x0200) + }, + USB_CLASS_CDC, /* class */ + CDC_SUBCLASS_NONE, /* subclass */ + CDC_PROTO_NONE, /* protocol */ + CONFIG_CDCACM_EP0MAXPACKET, /* maxpacketsize */ + { + LSBYTE(CONFIG_CDCACM_VENDORID), /* vendor */ + MSBYTE(CONFIG_CDCACM_VENDORID) + }, + { + LSBYTE(CONFIG_CDCACM_PRODUCTID), /* product */ + MSBYTE(CONFIG_CDCACM_PRODUCTID) + }, + { + LSBYTE(CDCACM_VERSIONNO), /* device */ + MSBYTE(CDCACM_VERSIONNO) + }, + CDCACM_MANUFACTURERSTRID, /* imfgr */ + CDCACM_PRODUCTSTRID, /* iproduct */ + CDCACM_SERIALSTRID, /* serno */ + CDCACM_NCONFIGS /* nconfigs */ +}; +#endif + +/* Configuration descriptor. If the USB serial device is configured as part of + * composite device, then the configuration descriptor will be provided by the + * composite device logic. + */ + +#ifndef CONFIG_CDCACM_COMPOSITE +static const struct usb_cfgdesc_s g_cfgdesc = +{ + USB_SIZEOF_CFGDESC, /* len */ + USB_DESC_TYPE_CONFIG, /* type */ + { + LSBYTE(SIZEOF_CDCACM_CFGDESC), /* LS totallen */ + MSBYTE(SIZEOF_CDCACM_CFGDESC) /* MS totallen */ + }, + CDCACM_NINTERFACES, /* ninterfaces */ + CDCACM_CONFIGID, /* cfgvalue */ + CDCACM_CONFIGSTRID, /* icfg */ + USB_CONFIG_ATTR_ONE|SELFPOWERED|REMOTEWAKEUP, /* attr */ + (CONFIG_USBDEV_MAXPOWER + 1) / 2 /* mxpower */ +}; +#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 = +{ + USB_SIZEOF_IFDESC, /* len */ + USB_DESC_TYPE_INTERFACE, /* type */ + CDCACM_NOTIFID, /* ifno */ + CDCACM_NOTALTIFID, /* alt */ + 1, /* neps */ + USB_CLASS_CDC, /* class */ + CDC_SUBCLASS_ACM, /* subclass */ + CDC_PROTO_ATM, /* proto */ +#ifdef CONFIG_CDCACM_NOTIFSTR + CDCACM_NOTIFSTRID /* iif */ +#else + 0 /* iif */ +#endif +}; + +/* Header functional descriptor */ + +static const struct cdc_hdr_funcdesc_s g_funchdr = +{ + SIZEOF_HDR_FUNCDESC, /* size */ + USB_DESC_TYPE_CSINTERFACE, /* type */ + CDC_DSUBTYPE_HDR, /* subtype */ + { + LSBYTE(CDC_VERSIONNO), /* LS cdc */ + MSBYTE(CDC_VERSIONNO) /* MS cdc */ + } +}; + +/* ACM functional descriptor */ + +static const struct cdc_acm_funcdesc_s g_acmfunc = +{ + SIZEOF_ACM_FUNCDESC, /* size */ + USB_DESC_TYPE_CSINTERFACE, /* type */ + CDC_DSUBTYPE_ACM, /* subtype */ + 0x06 /* caps */ +}; + +/* Union functional descriptor */ + +static const struct cdc_union_funcdesc_s g_unionfunc = +{ + SIZEOF_UNION_FUNCDESC(1), /* size */ + USB_DESC_TYPE_CSINTERFACE, /* type */ + CDC_DSUBTYPE_UNION, /* subtype */ + 0, /* master */ + {1} /* slave[0] */ +}; + +/* Interrupt IN endpoint descriptor */ + +static const struct usb_epdesc_s g_epintindesc = +{ + USB_SIZEOF_EPDESC, /* len */ + USB_DESC_TYPE_ENDPOINT, /* type */ + CDCACM_EPINTIN_ADDR, /* addr */ + CDCACM_EPINTIN_ATTR, /* attr */ + { + LSBYTE(CONFIG_CDCACM_EPINTIN_FSSIZE), /* maxpacket (full speed) */ + MSBYTE(CONFIG_CDCACM_EPINTIN_FSSIZE) + }, + 0xff /* interval */ +}; + +/* Data interface descriptor */ + +static const struct usb_ifdesc_s g_dataifdesc = +{ + USB_SIZEOF_IFDESC, /* len */ + USB_DESC_TYPE_INTERFACE, /* type */ + CDCACM_DATAIFID, /* ifno */ + CDCACM_DATAALTIFID, /* alt */ + 2, /* neps */ + USB_CLASS_CDC_DATA, /* class */ + CDC_DATA_SUBCLASS_NONE, /* subclass */ + CDC_DATA_PROTO_NONE, /* proto */ +#ifdef CONFIG_CDCACM_DATAIFSTR + CDCACM_DATAIFSTRID /* iif */ +#else + 0 /* iif */ +#endif +}; + +/* Bulk OUT endpoint descriptor */ + +static const struct usb_epdesc_s g_epbulkoutdesc = +{ + USB_SIZEOF_EPDESC, /* len */ + USB_DESC_TYPE_ENDPOINT, /* type */ + CDCACM_EPOUTBULK_ADDR, /* addr */ + CDCACM_EPOUTBULK_ATTR, /* attr */ + { + LSBYTE(CONFIG_CDCACM_EPBULKOUT_FSSIZE), /* maxpacket (full speed) */ + MSBYTE(CONFIG_CDCACM_EPBULKOUT_FSSIZE) + }, + 1 /* interval */ +}; + +/* Bulk IN endpoint descriptor */ + +static const struct usb_epdesc_s g_epbulkindesc = +{ + USB_SIZEOF_EPDESC, /* len */ + USB_DESC_TYPE_ENDPOINT, /* type */ + CDCACM_EPINBULK_ADDR, /* addr */ + CDCACM_EPINBULK_ATTR, /* attr */ + { + LSBYTE(CONFIG_CDCACM_EPBULKIN_FSSIZE), /* maxpacket (full speed) */ + MSBYTE(CONFIG_CDCACM_EPBULKIN_FSSIZE) + }, + 1 /* interval */ +}; + +/* The components of the the configuration descriptor are maintained as + * a collection of separate descriptor structure coordinated by the + * following array. These descriptors could have been combined into + * one larger "super" configuration descriptor structure. However, I + * have concerns about compiler-dependent alignment and packing. Since + * the individual structures consist only of byte types, alignment and + * packing is not an issue. And since the are concatentated at run time + * instead of compile time, there should no issues there either. + */ + +static const struct cfgdecsc_group_s g_cfggroup[CDCACM_CFGGROUP_SIZE] = +{ + /* Configuration Descriptor. If the serial device is used in as part + * or a composite device, then the configuration descriptor is + * provided by the composite device logic. + */ + +#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 */ + 0, + (FAR void *)&g_notifdesc + }, + { + SIZEOF_HDR_FUNCDESC, /* 3. Header functional descriptor */ + 0, + (FAR void *)&g_funchdr + }, + { + SIZEOF_ACM_FUNCDESC, /* 4. ACM functional descriptor */ + 0, + (FAR void *)&g_acmfunc + }, + { + SIZEOF_UNION_FUNCDESC(1), /* 5. Union functional descriptor */ + 0, + (FAR void *)&g_unionfunc + }, + { + USB_SIZEOF_EPDESC, /* 6. Interrupt IN endpoint descriptor */ + CONFIG_CDCACM_EPINTIN_HSSIZE, + (FAR void *)&g_epintindesc + }, + { + USB_SIZEOF_IFDESC, /* 7. Data interface descriptor */ + 0, + (FAR void *)&g_dataifdesc + }, + { + USB_SIZEOF_EPDESC, /* 8. Bulk OUT endpoint descriptor */ + CONFIG_CDCACM_EPBULKOUT_HSSIZE, + (FAR void *)&g_epbulkoutdesc + }, + { + USB_SIZEOF_EPDESC, /* 9. Bulk OUT endpoint descriptor */ + CONFIG_CDCACM_EPBULKIN_HSSIZE, + (FAR void *)&g_epbulkindesc + } +}; + +#if !defined(CONFIG_CDCACM_COMPOSITE) && defined(CONFIG_USBDEV_DUALSPEED) +static const struct usb_qualdesc_s g_qualdesc = +{ + USB_SIZEOF_QUALDESC, /* len */ + USB_DESC_TYPE_DEVICEQUALIFIER, /* type */ + { /* usb */ + LSBYTE(0x0200), + MSBYTE(0x0200) + }, + USB_CLASS_VENDOR_SPEC, /* class */ + 0, /* subclass */ + 0, /* protocol */ + CONFIG_CDCACM_EP0MAXPACKET, /* mxpacketsize */ + CDCACM_NCONFIGS, /* nconfigs */ + 0, /* reserved */ +}; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: cdcacm_mkstrdesc + * + * Description: + * Construct a string descriptor + * + ****************************************************************************/ + +int cdcacm_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc) +{ +#if !defined(CONFIG_CDCACM_COMPOSITE) || defined(CONFIG_CDCACM_NOTIFSTR) || \ + defined(CONFIG_CDCACM_DATAIFSTR) + + const char *str; + int len; + int ndata; + int i; + + switch (id) + { +#ifndef CONFIG_CDCACM_COMPOSITE + case 0: + { + /* Descriptor 0 is the language id */ + + strdesc->len = 4; + strdesc->type = USB_DESC_TYPE_STRING; + strdesc->data[0] = LSBYTE(CDCACM_STR_LANGUAGE); + strdesc->data[1] = MSBYTE(CDCACM_STR_LANGUAGE); + return 4; + } + + case CDCACM_MANUFACTURERSTRID: + str = CONFIG_CDCACM_VENDORSTR; + break; + + case CDCACM_PRODUCTSTRID: + str = CONFIG_CDCACM_PRODUCTSTR; + break; + + case CDCACM_SERIALSTRID: + str = CONFIG_CDCACM_SERIALSTR; + break; + + case CDCACM_CONFIGSTRID: + str = CONFIG_CDCACM_CONFIGSTR; + break; +#endif + +#ifdef CONFIG_CDCACM_NOTIFSTR + case CDCACM_NOTIFSTRID: + str = CONFIG_CDCACM_NOTIFSTR; + break; +#endif + +#ifdef CONFIG_CDCACM_DATAIFSTR + case CDCACM_DATAIFSTRID: + str = CONFIG_CDCACM_DATAIFSTR; + break; +#endif + + default: + return -EINVAL; + } + + /* The string is utf16-le. The poor man's utf-8 to utf16-le + * conversion below will only handle 7-bit en-us ascii + */ + + len = strlen(str); + for (i = 0, ndata = 0; i < len; i++, ndata += 2) + { + strdesc->data[ndata] = str[i]; + strdesc->data[ndata+1] = 0; + } + + strdesc->len = ndata+2; + strdesc->type = USB_DESC_TYPE_STRING; + return strdesc->len; +#else + return -EINVAL; +#endif +} + +/**************************************************************************** + * Name: cdcacm_getepdesc + * + * Description: + * Return a pointer to the raw device descriptor + * + ****************************************************************************/ + +#ifndef CONFIG_CDCACM_COMPOSITE +FAR const struct usb_devdesc_s *cdcacm_getdevdesc(void) +{ + return &g_devdesc; +} +#endif + +/**************************************************************************** + * Name: cdcacm_getepdesc + * + * Description: + * Return a pointer to the raw endpoint struct (used for configuring + * endpoints) + * + ****************************************************************************/ + +FAR const struct usb_epdesc_s *cdcacm_getepdesc(enum cdcacm_epdesc_e epid) +{ + switch (epid) + { + case CDCACM_EPINTIN: /* Interrupt IN endpoint */ + return &g_epintindesc; + + case CDCACM_EPBULKOUT: /* Bulk OUT endpoint */ + return &g_epbulkoutdesc; + + case CDCACM_EPBULKIN: /* Bulk IN endpoint */ + return &g_epbulkindesc; + + default: + return NULL; + } +} + +/**************************************************************************** + * Name: cdcacm_mkepdesc + * + * Description: + * Construct the endpoint descriptor using the correct max packet size. + * + ****************************************************************************/ + +#ifdef CONFIG_USBDEV_DUALSPEED +void cdcacm_mkepdesc(num cdcacm_epdesc_e epid, uint16_t mxpacket, + FAR struct usb_epdesc_s *outdesc) +{ + FAR const struct usb_epdesc_s *indesc; + + /* Copy the "canned" descriptor */ + + indesc = cdcacm_getepdesc(epid) + memcpy(outdesc, indesc, USB_SIZEOF_EPDESC); + + /* Then add the correct max packet size */ + + outdesc->mxpacketsize[0] = LSBYTE(mxpacket); + outdesc->mxpacketsize[1] = MSBYTE(mxpacket); +} +#endif + +/**************************************************************************** + * Name: cdcacm_mkcfgdesc + * + * Description: + * Construct the configuration descriptor + * + ****************************************************************************/ + +#ifdef CONFIG_USBDEV_DUALSPEED +int16_t cdcacm_mkcfgdesc(FAR uint8_t *buf, uint8_t speed, uint8_t type) +#else +int16_t cdcacm_mkcfgdesc(FAR uint8_t *buf) +#endif +{ + FAR const struct cfgdecsc_group_s *group; + FAR uint8_t *dest = buf; + int i; + +#ifdef CONFIG_USBDEV_DUALSPEED + bool hispeed = (speed == USB_SPEED_HIGH); + + /* Check for switches between high and full speed */ + + if (type == USB_DESC_TYPE_OTHERSPEEDCONFIG) + { + hispeed = !hispeed; + } +#endif + + /* Copy all of the descriptors in the group */ + + for (i = 0, dest = buf; i < CDCACM_CFGGROUP_SIZE; i++) + { + group = &g_cfggroup[i]; + + /* The "canned" descriptors all have full speed endpoint maxpacket + * sizes. If high speed is selected, we will have to change the + * endpoint maxpacket size. + * + * Is there a alternative high speed maxpacket size in the table? + * If so, that is sufficient proof that the descriptor that we + * just copied is an endpoint descriptor and needs the fixup + */ + +#ifdef CONFIG_USBDEV_DUALSPEED + if (highspeed && group->hsepsize != 0) + { + cdcacm_mkepdesc(group->desc, group->hsepsize, + (FAR struct usb_epdesc_s*)dest); + } + else +#endif + /* Copy the "canned" descriptor with the full speed max packet + * size + */ + + { + memcpy(dest, group->desc, group->descsize); + } + + /* Advance to the destination location for the next descriptor */ + + dest += group->descsize; + } + + return SIZEOF_CDCACM_CFGDESC; +} + +/**************************************************************************** + * Name: cdcacm_getqualdesc + * + * Description: + * Return a pointer to the raw qual descriptor + * + ****************************************************************************/ + +#if !defined(CONFIG_CDCACM_COMPOSITE) && defined(CONFIG_USBDEV_DUALSPEED) +FAR const struct usb_qualdesc_s *cdcacm_getqualdesc(void) +{ + return &g_qualdesc; +} +#endif diff --git a/nuttx/drivers/usbdev/cdcacm_descriptors.c b/nuttx/drivers/usbdev/cdcacm_descriptors.c deleted file mode 100644 index 11a83541e..000000000 --- a/nuttx/drivers/usbdev/cdcacm_descriptors.c +++ /dev/null @@ -1,613 +0,0 @@ -/**************************************************************************** - * drivers/usbdev/cdcacm_descriptors.c - * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "cdcacm.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* Describes one description in the group of descriptors forming the - * total configuration descriptor. - */ - -struct cfgdecsc_group_s -{ - uint16_t descsize; /* Size of the descriptor in bytes */ - uint16_t hsepsize; /* High speed max packet size */ - FAR void *desc; /* A pointer to the descriptor */ -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* USB descriptor templates these will be copied and modified **************/ -/* Device Descriptor. If the USB serial device is configured as part of - * composite device, then the device descriptor will be provided by the - * composite device logic. - */ - -#ifndef CONFIG_CDCACM_COMPOSITE -static const struct usb_devdesc_s g_devdesc = -{ - USB_SIZEOF_DEVDESC, /* len */ - USB_DESC_TYPE_DEVICE, /* type */ - { /* usb */ - LSBYTE(0x0200), - MSBYTE(0x0200) - }, - USB_CLASS_CDC, /* class */ - CDC_SUBCLASS_NONE, /* subclass */ - CDC_PROTO_NONE, /* protocol */ - CONFIG_CDCACM_EP0MAXPACKET, /* maxpacketsize */ - { - LSBYTE(CONFIG_CDCACM_VENDORID), /* vendor */ - MSBYTE(CONFIG_CDCACM_VENDORID) - }, - { - LSBYTE(CONFIG_CDCACM_PRODUCTID), /* product */ - MSBYTE(CONFIG_CDCACM_PRODUCTID) - }, - { - LSBYTE(CDCACM_VERSIONNO), /* device */ - MSBYTE(CDCACM_VERSIONNO) - }, - CDCACM_MANUFACTURERSTRID, /* imfgr */ - CDCACM_PRODUCTSTRID, /* iproduct */ - CDCACM_SERIALSTRID, /* serno */ - CDCACM_NCONFIGS /* nconfigs */ -}; -#endif - -/* Configuration descriptor. If the USB serial device is configured as part of - * composite device, then the configuration descriptor will be provided by the - * composite device logic. - */ - -#ifndef CONFIG_CDCACM_COMPOSITE -static const struct usb_cfgdesc_s g_cfgdesc = -{ - USB_SIZEOF_CFGDESC, /* len */ - USB_DESC_TYPE_CONFIG, /* type */ - { - LSBYTE(SIZEOF_CDCACM_CFGDESC), /* LS totallen */ - MSBYTE(SIZEOF_CDCACM_CFGDESC) /* MS totallen */ - }, - CDCACM_NINTERFACES, /* ninterfaces */ - CDCACM_CONFIGID, /* cfgvalue */ - CDCACM_CONFIGSTRID, /* icfg */ - USB_CONFIG_ATTR_ONE|SELFPOWERED|REMOTEWAKEUP, /* attr */ - (CONFIG_USBDEV_MAXPOWER + 1) / 2 /* mxpower */ -}; -#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 = -{ - USB_SIZEOF_IFDESC, /* len */ - USB_DESC_TYPE_INTERFACE, /* type */ - CDCACM_NOTIFID, /* ifno */ - CDCACM_NOTALTIFID, /* alt */ - 1, /* neps */ - USB_CLASS_CDC, /* class */ - CDC_SUBCLASS_ACM, /* subclass */ - CDC_PROTO_ATM, /* proto */ -#ifdef CONFIG_CDCACM_NOTIFSTR - CDCACM_NOTIFSTRID /* iif */ -#else - 0 /* iif */ -#endif -}; - -/* Header functional descriptor */ - -static const struct cdc_hdr_funcdesc_s g_funchdr = -{ - SIZEOF_HDR_FUNCDESC, /* size */ - USB_DESC_TYPE_CSINTERFACE, /* type */ - CDC_DSUBTYPE_HDR, /* subtype */ - { - LSBYTE(CDC_VERSIONNO), /* LS cdc */ - MSBYTE(CDC_VERSIONNO) /* MS cdc */ - } -}; - -/* ACM functional descriptor */ - -static const struct cdc_acm_funcdesc_s g_acmfunc = -{ - SIZEOF_ACM_FUNCDESC, /* size */ - USB_DESC_TYPE_CSINTERFACE, /* type */ - CDC_DSUBTYPE_ACM, /* subtype */ - 0x06 /* caps */ -}; - -/* Union functional descriptor */ - -static const struct cdc_union_funcdesc_s g_unionfunc = -{ - SIZEOF_UNION_FUNCDESC(1), /* size */ - USB_DESC_TYPE_CSINTERFACE, /* type */ - CDC_DSUBTYPE_UNION, /* subtype */ - 0, /* master */ - {1} /* slave[0] */ -}; - -/* Interrupt IN endpoint descriptor */ - -static const struct usb_epdesc_s g_epintindesc = -{ - USB_SIZEOF_EPDESC, /* len */ - USB_DESC_TYPE_ENDPOINT, /* type */ - CDCACM_EPINTIN_ADDR, /* addr */ - CDCACM_EPINTIN_ATTR, /* attr */ - { - LSBYTE(CONFIG_CDCACM_EPINTIN_FSSIZE), /* maxpacket (full speed) */ - MSBYTE(CONFIG_CDCACM_EPINTIN_FSSIZE) - }, - 0xff /* interval */ -}; - -/* Data interface descriptor */ - -static const struct usb_ifdesc_s g_dataifdesc = -{ - USB_SIZEOF_IFDESC, /* len */ - USB_DESC_TYPE_INTERFACE, /* type */ - CDCACM_DATAIFID, /* ifno */ - CDCACM_DATAALTIFID, /* alt */ - 2, /* neps */ - USB_CLASS_CDC_DATA, /* class */ - CDC_DATA_SUBCLASS_NONE, /* subclass */ - CDC_DATA_PROTO_NONE, /* proto */ -#ifdef CONFIG_CDCACM_DATAIFSTR - CDCACM_DATAIFSTRID /* iif */ -#else - 0 /* iif */ -#endif -}; - -/* Bulk OUT endpoint descriptor */ - -static const struct usb_epdesc_s g_epbulkoutdesc = -{ - USB_SIZEOF_EPDESC, /* len */ - USB_DESC_TYPE_ENDPOINT, /* type */ - CDCACM_EPOUTBULK_ADDR, /* addr */ - CDCACM_EPOUTBULK_ATTR, /* attr */ - { - LSBYTE(CONFIG_CDCACM_EPBULKOUT_FSSIZE), /* maxpacket (full speed) */ - MSBYTE(CONFIG_CDCACM_EPBULKOUT_FSSIZE) - }, - 1 /* interval */ -}; - -/* Bulk IN endpoint descriptor */ - -static const struct usb_epdesc_s g_epbulkindesc = -{ - USB_SIZEOF_EPDESC, /* len */ - USB_DESC_TYPE_ENDPOINT, /* type */ - CDCACM_EPINBULK_ADDR, /* addr */ - CDCACM_EPINBULK_ATTR, /* attr */ - { - LSBYTE(CONFIG_CDCACM_EPBULKIN_FSSIZE), /* maxpacket (full speed) */ - MSBYTE(CONFIG_CDCACM_EPBULKIN_FSSIZE) - }, - 1 /* interval */ -}; - -/* The components of the the configuration descriptor are maintained as - * a collection of separate descriptor structure coordinated by the - * following array. These descriptors could have been combined into - * one larger "super" configuration descriptor structure. However, I - * have concerns about compiler-dependent alignment and packing. Since - * the individual structures consist only of byte types, alignment and - * packing is not an issue. And since the are concatentated at run time - * instead of compile time, there should no issues there either. - */ - -static const struct cfgdecsc_group_s g_cfggroup[CDCACM_CFGGROUP_SIZE] = -{ - /* Configuration Descriptor. If the serial device is used in as part - * or a composite device, then the configuration descriptor is - * provided by the composite device logic. - */ - -#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 */ - 0, - (FAR void *)&g_notifdesc - }, - { - SIZEOF_HDR_FUNCDESC, /* 3. Header functional descriptor */ - 0, - (FAR void *)&g_funchdr - }, - { - SIZEOF_ACM_FUNCDESC, /* 4. ACM functional descriptor */ - 0, - (FAR void *)&g_acmfunc - }, - { - SIZEOF_UNION_FUNCDESC(1), /* 5. Union functional descriptor */ - 0, - (FAR void *)&g_unionfunc - }, - { - USB_SIZEOF_EPDESC, /* 6. Interrupt IN endpoint descriptor */ - CONFIG_CDCACM_EPINTIN_HSSIZE, - (FAR void *)&g_epintindesc - }, - { - USB_SIZEOF_IFDESC, /* 7. Data interface descriptor */ - 0, - (FAR void *)&g_dataifdesc - }, - { - USB_SIZEOF_EPDESC, /* 8. Bulk OUT endpoint descriptor */ - CONFIG_CDCACM_EPBULKOUT_HSSIZE, - (FAR void *)&g_epbulkoutdesc - }, - { - USB_SIZEOF_EPDESC, /* 9. Bulk OUT endpoint descriptor */ - CONFIG_CDCACM_EPBULKIN_HSSIZE, - (FAR void *)&g_epbulkindesc - } -}; - -#if !defined(CONFIG_CDCACM_COMPOSITE) && defined(CONFIG_USBDEV_DUALSPEED) -static const struct usb_qualdesc_s g_qualdesc = -{ - USB_SIZEOF_QUALDESC, /* len */ - USB_DESC_TYPE_DEVICEQUALIFIER, /* type */ - { /* usb */ - LSBYTE(0x0200), - MSBYTE(0x0200) - }, - USB_CLASS_VENDOR_SPEC, /* class */ - 0, /* subclass */ - 0, /* protocol */ - CONFIG_CDCACM_EP0MAXPACKET, /* mxpacketsize */ - CDCACM_NCONFIGS, /* nconfigs */ - 0, /* reserved */ -}; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cdcacm_mkstrdesc - * - * Description: - * Construct a string descriptor - * - ****************************************************************************/ - -int cdcacm_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc) -{ -#if !defined(CONFIG_CDCACM_COMPOSITE) || defined(CONFIG_CDCACM_NOTIFSTR) || \ - defined(CONFIG_CDCACM_DATAIFSTR) - - const char *str; - int len; - int ndata; - int i; - - switch (id) - { -#ifndef CONFIG_CDCACM_COMPOSITE - case 0: - { - /* Descriptor 0 is the language id */ - - strdesc->len = 4; - strdesc->type = USB_DESC_TYPE_STRING; - strdesc->data[0] = LSBYTE(CDCACM_STR_LANGUAGE); - strdesc->data[1] = MSBYTE(CDCACM_STR_LANGUAGE); - return 4; - } - - case CDCACM_MANUFACTURERSTRID: - str = CONFIG_CDCACM_VENDORSTR; - break; - - case CDCACM_PRODUCTSTRID: - str = CONFIG_CDCACM_PRODUCTSTR; - break; - - case CDCACM_SERIALSTRID: - str = CONFIG_CDCACM_SERIALSTR; - break; - - case CDCACM_CONFIGSTRID: - str = CONFIG_CDCACM_CONFIGSTR; - break; -#endif - -#ifdef CONFIG_CDCACM_NOTIFSTR - case CDCACM_NOTIFSTRID: - str = CONFIG_CDCACM_NOTIFSTR; - break; -#endif - -#ifdef CONFIG_CDCACM_DATAIFSTR - case CDCACM_DATAIFSTRID: - str = CONFIG_CDCACM_DATAIFSTR; - break; -#endif - - default: - return -EINVAL; - } - - /* The string is utf16-le. The poor man's utf-8 to utf16-le - * conversion below will only handle 7-bit en-us ascii - */ - - len = strlen(str); - for (i = 0, ndata = 0; i < len; i++, ndata += 2) - { - strdesc->data[ndata] = str[i]; - strdesc->data[ndata+1] = 0; - } - - strdesc->len = ndata+2; - strdesc->type = USB_DESC_TYPE_STRING; - return strdesc->len; -#else - return -EINVAL; -#endif -} - -/**************************************************************************** - * Name: cdcacm_getepdesc - * - * Description: - * Return a pointer to the raw device descriptor - * - ****************************************************************************/ - -#ifndef CONFIG_CDCACM_COMPOSITE -FAR const struct usb_devdesc_s *cdcacm_getdevdesc(void) -{ - return &g_devdesc; -} -#endif - -/**************************************************************************** - * Name: cdcacm_getepdesc - * - * Description: - * Return a pointer to the raw endpoint struct (used for configuring - * endpoints) - * - ****************************************************************************/ - -FAR const struct usb_epdesc_s *cdcacm_getepdesc(enum cdcacm_epdesc_e epid) -{ - switch (epid) - { - case CDCACM_EPINTIN: /* Interrupt IN endpoint */ - return &g_epintindesc; - - case CDCACM_EPBULKOUT: /* Bulk OUT endpoint */ - return &g_epbulkoutdesc; - - case CDCACM_EPBULKIN: /* Bulk IN endpoint */ - return &g_epbulkindesc; - - default: - return NULL; - } -} - -/**************************************************************************** - * Name: cdcacm_mkepdesc - * - * Description: - * Construct the endpoint descriptor using the correct max packet size. - * - ****************************************************************************/ - -#ifdef CONFIG_USBDEV_DUALSPEED -void cdcacm_mkepdesc(num cdcacm_epdesc_e epid, uint16_t mxpacket, - FAR struct usb_epdesc_s *outdesc) -{ - FAR const struct usb_epdesc_s *indesc; - - /* Copy the "canned" descriptor */ - - indesc = cdcacm_getepdesc(epid) - memcpy(outdesc, indesc, USB_SIZEOF_EPDESC); - - /* Then add the correct max packet size */ - - outdesc->mxpacketsize[0] = LSBYTE(mxpacket); - outdesc->mxpacketsize[1] = MSBYTE(mxpacket); -} -#endif - -/**************************************************************************** - * Name: cdcacm_mkcfgdesc - * - * Description: - * Construct the configuration descriptor - * - ****************************************************************************/ - -#ifdef CONFIG_USBDEV_DUALSPEED -int16_t cdcacm_mkcfgdesc(FAR uint8_t *buf, uint8_t speed, uint8_t type) -#else -int16_t cdcacm_mkcfgdesc(FAR uint8_t *buf) -#endif -{ - FAR const struct cfgdecsc_group_s *group; - FAR uint8_t *dest = buf; - int i; - -#ifdef CONFIG_USBDEV_DUALSPEED - bool hispeed = (speed == USB_SPEED_HIGH); - - /* Check for switches between high and full speed */ - - if (type == USB_DESC_TYPE_OTHERSPEEDCONFIG) - { - hispeed = !hispeed; - } -#endif - - /* Copy all of the descriptors in the group */ - - for (i = 0, dest = buf; i < CDCACM_CFGGROUP_SIZE; i++) - { - group = &g_cfggroup[i]; - - /* The "canned" descriptors all have full speed endpoint maxpacket - * sizes. If high speed is selected, we will have to change the - * endpoint maxpacket size. - * - * Is there a alternative high speed maxpacket size in the table? - * If so, that is sufficient proof that the descriptor that we - * just copied is an endpoint descriptor and needs the fixup - */ - -#ifdef CONFIG_USBDEV_DUALSPEED - if (highspeed && group->hsepsize != 0) - { - cdcacm_mkepdesc(group->desc, group->hsepsize, - (FAR struct usb_epdesc_s*)dest); - } - else -#endif - /* Copy the "canned" descriptor with the full speed max packet - * size - */ - - { - memcpy(dest, group->desc, group->descsize); - } - - /* Advance to the destination location for the next descriptor */ - - dest += group->descsize; - } - - return SIZEOF_CDCACM_CFGDESC; -} - -/**************************************************************************** - * Name: cdcacm_getqualdesc - * - * Description: - * Return a pointer to the raw qual descriptor - * - ****************************************************************************/ - -#if !defined(CONFIG_CDCACM_COMPOSITE) && defined(CONFIG_USBDEV_DUALSPEED) -FAR const struct usb_qualdesc_s *cdcacm_getqualdesc(void) -{ - return &g_qualdesc; -} -#endif diff --git a/nuttx/drivers/usbdev/composite_desc.c b/nuttx/drivers/usbdev/composite_desc.c new file mode 100644 index 000000000..0a0cd4a6a --- /dev/null +++ b/nuttx/drivers/usbdev/composite_desc.c @@ -0,0 +1,291 @@ +/**************************************************************************** + * drivers/usbdev/composite_desc.c + * + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include +#include +#include + +#include + +#include "composite.h" + +#ifdef CONFIG_USBDEV_COMPOSITE + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +#ifdef CONFIG_USBDEV_DUALSPEED +typedef int16_t (*mkcfgdesc)(FAR uint8_t *buf, uint8_t speed, uint8_t type); +#else +typedef int16_t (*mkcfgdesc)(FAR uint8_t *buf); +#endif + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ +/* Device Descriptor */ + +static const struct usb_devdesc_s g_devdesc = +{ + USB_SIZEOF_DEVDESC, /* len */ + USB_DESC_TYPE_DEVICE, /* type */ + { /* usb */ + LSBYTE(0x0200), + MSBYTE(0x0200) + }, +#ifdef CONFIG_COMPOSITE_IAD + USB_CLASS_MISC, /* classid */ + 2, /* subclass */ + 1, /* protocol */ +#else + USB_CLASS_PER_INTERFACE, /* classid */ + 0, /* subclass */ + 0, /* protocol */ +#endif + CONFIG_COMPOSITE_EP0MAXPACKET, /* maxpacketsize */ + { + LSBYTE(CONFIG_COMPOSITE_VENDORID), /* vendor */ + MSBYTE(CONFIG_COMPOSITE_VENDORID) + }, + { + LSBYTE(CONFIG_COMPOSITE_PRODUCTID), /* product */ + MSBYTE(CONFIG_COMPOSITE_PRODUCTID) + }, + { + LSBYTE(CONFIG_COMPOSITE_VERSIONNO), /* device */ + MSBYTE(CONFIG_COMPOSITE_VERSIONNO) + }, + COMPOSITE_MANUFACTURERSTRID, /* imfgr */ + COMPOSITE_PRODUCTSTRID, /* iproduct */ + COMPOSITE_SERIALSTRID, /* serno */ + COMPOSITE_NCONFIGS /* nconfigs */ +}; + +/* Configuration descriptor for the composite device */ + +static const struct usb_cfgdesc_s g_cfgdesc = +{ + USB_SIZEOF_CFGDESC, /* len */ + USB_DESC_TYPE_CONFIG, /* type */ + { + LSBYTE(COMPOSITE_CFGDESCSIZE), /* LS totallen */ + MSBYTE(COMPOSITE_CFGDESCSIZE) /* MS totallen */ + }, + COMPOSITE_NINTERFACES, /* ninterfaces */ + COMPOSITE_CONFIGID, /* cfgvalue */ + COMPOSITE_CONFIGSTRID, /* icfg */ + USB_CONFIG_ATTR_ONE|SELFPOWERED|REMOTEWAKEUP, /* attr */ + (CONFIG_USBDEV_MAXPOWER + 1) / 2 /* mxpower */ +}; + +#ifdef CONFIG_USBDEV_DUALSPEED +static const struct usb_qualdesc_s g_qualdesc = +{ + USB_SIZEOF_QUALDESC, /* len */ + USB_DESC_TYPE_DEVICEQUALIFIER, /* type */ + { /* usb */ + LSBYTE(0x0200), + MSBYTE(0x0200) + }, + USB_CLASS_VENDOR_SPEC, /* classid */ + 0, /* subclass */ + 0, /* protocol */ + CONFIG_COMPOSITE_EP0MAXPACKET, /* mxpacketsize */ + COMPOSITE_NCONFIGS, /* nconfigs */ + 0, /* reserved */ +}; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: composite_mkstrdesc + * + * Description: + * Construct a string descriptor + * + ****************************************************************************/ + +int composite_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc) +{ + const char *str; + int len; + int ndata; + int i; + + switch (id) + { + case 0: + { + /* Descriptor 0 is the language id */ + + strdesc->len = 4; + strdesc->type = USB_DESC_TYPE_STRING; + strdesc->data[0] = LSBYTE(COMPOSITE_STR_LANGUAGE); + strdesc->data[1] = MSBYTE(COMPOSITE_STR_LANGUAGE); + return 4; + } + + case COMPOSITE_MANUFACTURERSTRID: + str = g_compvendorstr; + break; + + case COMPOSITE_PRODUCTSTRID: + str = g_compproductstr; + break; + + case COMPOSITE_SERIALSTRID: + str = g_compserialstr; + break; + + case COMPOSITE_CONFIGSTRID: + str = CONFIG_COMPOSITE_CONFIGSTR; + break; + + default: + return -EINVAL; + } + + /* The string is utf16-le. The poor man's utf-8 to utf16-le + * conversion below will only handle 7-bit en-us ascii + */ + + len = strlen(str); + for (i = 0, ndata = 0; i < len; i++, ndata += 2) + { + strdesc->data[ndata] = str[i]; + strdesc->data[ndata+1] = 0; + } + + strdesc->len = ndata+2; + strdesc->type = USB_DESC_TYPE_STRING; + return strdesc->len; +} + +/**************************************************************************** + * Name: composite_getepdesc + * + * Description: + * Return a pointer to the raw device descriptor + * + ****************************************************************************/ + +FAR const struct usb_devdesc_s *composite_getdevdesc(void) +{ + return &g_devdesc; +} + +/**************************************************************************** + * Name: composite_mkcfgdesc + * + * Description: + * Construct the configuration descriptor + * + ****************************************************************************/ + +#ifdef CONFIG_USBDEV_DUALSPEED +int16_t composite_mkcfgdesc(uint8_t *buf, uint8_t speed, uint8_t type) +#else +int16_t composite_mkcfgdesc(uint8_t *buf) +#endif +{ + int16_t len; + int16_t total; + + /* Configuration descriptor -- Copy the canned configuration descriptor. */ + + memcpy(buf, &g_cfgdesc, USB_SIZEOF_CFGDESC); + total = USB_SIZEOF_CFGDESC; + buf += USB_SIZEOF_CFGDESC; + + /* Copy DEV1/DEV2 interface descriptors */ + +#ifdef CONFIG_USBDEV_DUALSPEED + len = DEV1_MKCFGDESC(buf, speed, type); + total += len; + buf += len; + total += DEV2_MKCFGDESC(buf, speed, type); +#else + len = DEV1_MKCFGDESC(buf); + total += len; + buf += len; + total += DEV2_MKCFGDESC(buf); +#endif + + DEBUGASSERT(total == COMPOSITE_CFGDESCSIZE); + return total; +} + +/**************************************************************************** + * Name: composite_getqualdesc + * + * Description: + * Return a pointer to the raw qual descriptor + * + ****************************************************************************/ + +#ifdef CONFIG_USBDEV_DUALSPEED +FAR const struct usb_qualdesc_s *composite_getqualdesc(void) +{ + return &g_qualdesc; +} +#endif + +#endif /* CONFIG_USBDEV_COMPOSITE */ diff --git a/nuttx/drivers/usbdev/composite_descriptors.c b/nuttx/drivers/usbdev/composite_descriptors.c deleted file mode 100644 index 9ea6ef2d7..000000000 --- a/nuttx/drivers/usbdev/composite_descriptors.c +++ /dev/null @@ -1,291 +0,0 @@ -/**************************************************************************** - * drivers/usbdev/composite_descriptors.c - * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include -#include -#include -#include -#include - -#include - -#include "composite.h" - -#ifdef CONFIG_USBDEV_COMPOSITE - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -#ifdef CONFIG_USBDEV_DUALSPEED -typedef int16_t (*mkcfgdesc)(FAR uint8_t *buf, uint8_t speed, uint8_t type); -#else -typedef int16_t (*mkcfgdesc)(FAR uint8_t *buf); -#endif - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ -/* Device Descriptor */ - -static const struct usb_devdesc_s g_devdesc = -{ - USB_SIZEOF_DEVDESC, /* len */ - USB_DESC_TYPE_DEVICE, /* type */ - { /* usb */ - LSBYTE(0x0200), - MSBYTE(0x0200) - }, -#ifdef CONFIG_COMPOSITE_IAD - USB_CLASS_MISC, /* classid */ - 2, /* subclass */ - 1, /* protocol */ -#else - USB_CLASS_PER_INTERFACE, /* classid */ - 0, /* subclass */ - 0, /* protocol */ -#endif - CONFIG_COMPOSITE_EP0MAXPACKET, /* maxpacketsize */ - { - LSBYTE(CONFIG_COMPOSITE_VENDORID), /* vendor */ - MSBYTE(CONFIG_COMPOSITE_VENDORID) - }, - { - LSBYTE(CONFIG_COMPOSITE_PRODUCTID), /* product */ - MSBYTE(CONFIG_COMPOSITE_PRODUCTID) - }, - { - LSBYTE(CONFIG_COMPOSITE_VERSIONNO), /* device */ - MSBYTE(CONFIG_COMPOSITE_VERSIONNO) - }, - COMPOSITE_MANUFACTURERSTRID, /* imfgr */ - COMPOSITE_PRODUCTSTRID, /* iproduct */ - COMPOSITE_SERIALSTRID, /* serno */ - COMPOSITE_NCONFIGS /* nconfigs */ -}; - -/* Configuration descriptor for the composite device */ - -static const struct usb_cfgdesc_s g_cfgdesc = -{ - USB_SIZEOF_CFGDESC, /* len */ - USB_DESC_TYPE_CONFIG, /* type */ - { - LSBYTE(COMPOSITE_CFGDESCSIZE), /* LS totallen */ - MSBYTE(COMPOSITE_CFGDESCSIZE) /* MS totallen */ - }, - COMPOSITE_NINTERFACES, /* ninterfaces */ - COMPOSITE_CONFIGID, /* cfgvalue */ - COMPOSITE_CONFIGSTRID, /* icfg */ - USB_CONFIG_ATTR_ONE|SELFPOWERED|REMOTEWAKEUP, /* attr */ - (CONFIG_USBDEV_MAXPOWER + 1) / 2 /* mxpower */ -}; - -#ifdef CONFIG_USBDEV_DUALSPEED -static const struct usb_qualdesc_s g_qualdesc = -{ - USB_SIZEOF_QUALDESC, /* len */ - USB_DESC_TYPE_DEVICEQUALIFIER, /* type */ - { /* usb */ - LSBYTE(0x0200), - MSBYTE(0x0200) - }, - USB_CLASS_VENDOR_SPEC, /* classid */ - 0, /* subclass */ - 0, /* protocol */ - CONFIG_COMPOSITE_EP0MAXPACKET, /* mxpacketsize */ - COMPOSITE_NCONFIGS, /* nconfigs */ - 0, /* reserved */ -}; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: composite_mkstrdesc - * - * Description: - * Construct a string descriptor - * - ****************************************************************************/ - -int composite_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc) -{ - const char *str; - int len; - int ndata; - int i; - - switch (id) - { - case 0: - { - /* Descriptor 0 is the language id */ - - strdesc->len = 4; - strdesc->type = USB_DESC_TYPE_STRING; - strdesc->data[0] = LSBYTE(COMPOSITE_STR_LANGUAGE); - strdesc->data[1] = MSBYTE(COMPOSITE_STR_LANGUAGE); - return 4; - } - - case COMPOSITE_MANUFACTURERSTRID: - str = g_compvendorstr; - break; - - case COMPOSITE_PRODUCTSTRID: - str = g_compproductstr; - break; - - case COMPOSITE_SERIALSTRID: - str = g_compserialstr; - break; - - case COMPOSITE_CONFIGSTRID: - str = CONFIG_COMPOSITE_CONFIGSTR; - break; - - default: - return -EINVAL; - } - - /* The string is utf16-le. The poor man's utf-8 to utf16-le - * conversion below will only handle 7-bit en-us ascii - */ - - len = strlen(str); - for (i = 0, ndata = 0; i < len; i++, ndata += 2) - { - strdesc->data[ndata] = str[i]; - strdesc->data[ndata+1] = 0; - } - - strdesc->len = ndata+2; - strdesc->type = USB_DESC_TYPE_STRING; - return strdesc->len; -} - -/**************************************************************************** - * Name: composite_getepdesc - * - * Description: - * Return a pointer to the raw device descriptor - * - ****************************************************************************/ - -FAR const struct usb_devdesc_s *composite_getdevdesc(void) -{ - return &g_devdesc; -} - -/**************************************************************************** - * Name: composite_mkcfgdesc - * - * Description: - * Construct the configuration descriptor - * - ****************************************************************************/ - -#ifdef CONFIG_USBDEV_DUALSPEED -int16_t composite_mkcfgdesc(uint8_t *buf, uint8_t speed, uint8_t type) -#else -int16_t composite_mkcfgdesc(uint8_t *buf) -#endif -{ - int16_t len; - int16_t total; - - /* Configuration descriptor -- Copy the canned configuration descriptor. */ - - memcpy(buf, &g_cfgdesc, USB_SIZEOF_CFGDESC); - total = USB_SIZEOF_CFGDESC; - buf += USB_SIZEOF_CFGDESC; - - /* Copy DEV1/DEV2 interface descriptors */ - -#ifdef CONFIG_USBDEV_DUALSPEED - len = DEV1_MKCFGDESC(buf, speed, type); - total += len; - buf += len; - total += DEV2_MKCFGDESC(buf, speed, type); -#else - len = DEV1_MKCFGDESC(buf); - total += len; - buf += len; - total += DEV2_MKCFGDESC(buf); -#endif - - DEBUGASSERT(total == COMPOSITE_CFGDESCSIZE); - return total; -} - -/**************************************************************************** - * Name: composite_getqualdesc - * - * Description: - * Return a pointer to the raw qual descriptor - * - ****************************************************************************/ - -#ifdef CONFIG_USBDEV_DUALSPEED -FAR const struct usb_qualdesc_s *composite_getqualdesc(void) -{ - return &g_qualdesc; -} -#endif - -#endif /* CONFIG_USBDEV_COMPOSITE */ diff --git a/nuttx/drivers/usbdev/usbmsc_desc.c b/nuttx/drivers/usbdev/usbmsc_desc.c new file mode 100644 index 000000000..6d7561b3f --- /dev/null +++ b/nuttx/drivers/usbdev/usbmsc_desc.c @@ -0,0 +1,421 @@ +/**************************************************************************** + * drivers/usbdev/usbmsc_desc.c + * + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include "usbmsc.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ +/* Descriptors **************************************************************/ +/* Device descriptor. If the USB mass storage device is configured as part + * of a composite device, then the device descriptor will be provided by the + * composite device logic. + */ + +#ifndef CONFIG_USBMSC_COMPOSITE +static const struct usb_devdesc_s g_devdesc = +{ + USB_SIZEOF_DEVDESC, /* len */ + USB_DESC_TYPE_DEVICE, /* type */ + {LSBYTE(0x0200), MSBYTE(0x0200)}, /* usb */ + USB_CLASS_PER_INTERFACE, /* classid */ + 0, /* subclass */ + 0, /* protocol */ + CONFIG_USBMSC_EP0MAXPACKET, /* maxpacketsize */ + { /* vendor */ + LSBYTE(CONFIG_USBMSC_VENDORID), + MSBYTE(CONFIG_USBMSC_VENDORID) + }, + { /* product */ + LSBYTE(CONFIG_USBMSC_PRODUCTID), + MSBYTE(CONFIG_USBMSC_PRODUCTID) }, + { /* device */ + LSBYTE(CONFIG_USBMSC_VERSIONNO), + MSBYTE(CONFIG_USBMSC_VERSIONNO) + }, + USBMSC_MANUFACTURERSTRID, /* imfgr */ + USBMSC_PRODUCTSTRID, /* iproduct */ + USBMSC_SERIALSTRID, /* serno */ + USBMSC_NCONFIGS /* nconfigs */ +}; +#endif + +/* 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 +static const struct usb_cfgdesc_s g_cfgdesc = +{ + USB_SIZEOF_CFGDESC, /* len */ + USB_DESC_TYPE_CONFIG, /* type */ + { /* totallen */ + LSBYTE(SIZEOF_USBMSC_CFGDESC), + MSBYTE(SIZEOF_USBMSC_CFGDESC) + }, + USBMSC_NINTERFACES, /* ninterfaces */ + USBMSC_CONFIGID, /* cfgvalue */ + USBMSC_CONFIGSTRID, /* icfg */ + USB_CONFIG_ATTR_ONE|SELFPOWERED|REMOTEWAKEUP, /* attr */ + (CONFIG_USBDEV_MAXPOWER + 1) / 2 /* mxpower */ +}; +#endif + +/* Single interface descriptor */ + +static const struct usb_ifdesc_s g_ifdesc = +{ + USB_SIZEOF_IFDESC, /* len */ + USB_DESC_TYPE_INTERFACE, /* type */ + USBMSC_INTERFACEID, /* ifno */ + USBMSC_ALTINTERFACEID, /* alt */ + USBMSC_NENDPOINTS, /* neps */ + USB_CLASS_MASS_STORAGE, /* classid */ + USBMSC_SUBCLASS_SCSI, /* subclass */ + USBMSC_PROTO_BULKONLY, /* protocol */ + USBMSC_INTERFACESTRID /* iif */ +}; + +/* Endpoint descriptors */ + +static const struct usb_epdesc_s g_fsepbulkoutdesc = +{ + USB_SIZEOF_EPDESC, /* len */ + USB_DESC_TYPE_ENDPOINT, /* type */ + USBMSC_EPOUTBULK_ADDR, /* addr */ + USBMSC_EPOUTBULK_ATTR, /* attr */ + { /* maxpacket */ + LSBYTE(USBMSC_FSBULKMAXPACKET), + MSBYTE(USBMSC_FSBULKMAXPACKET) + }, + 0 /* interval */ +}; + +static const struct usb_epdesc_s g_fsepbulkindesc = +{ + USB_SIZEOF_EPDESC, /* len */ + USB_DESC_TYPE_ENDPOINT, /* type */ + USBMSC_EPINBULK_ADDR, /* addr */ + USBMSC_EPINBULK_ATTR, /* attr */ + { /* maxpacket */ + LSBYTE(USBMSC_FSBULKMAXPACKET), + MSBYTE(USBMSC_FSBULKMAXPACKET) + }, + 0 /* interval */ +}; + +#ifdef CONFIG_USBDEV_DUALSPEED +#ifndef CONFIG_USBMSC_COMPOSITE +static const struct usb_qualdesc_s g_qualdesc = +{ + USB_SIZEOF_QUALDESC, /* len */ + USB_DESC_TYPE_DEVICEQUALIFIER, /* type */ + { /* usb */ + LSBYTE(0x0200), + MSBYTE(0x0200) + }, + USB_CLASS_PER_INTERFACE, /* classid */ + 0, /* subclass */ + 0, /* protocol */ + CONFIG_USBMSC_EP0MAXPACKET, /* mxpacketsize */ + USBMSC_NCONFIGS, /* nconfigs */ + 0, /* reserved */ +}; +#endif + +static const struct usb_epdesc_s g_hsepbulkoutdesc = +{ + USB_SIZEOF_EPDESC, /* len */ + USB_DESC_TYPE_ENDPOINT, /* type */ + USBMSC_EPOUTBULK_ADDR, /* addr */ + USBMSC_EPOUTBULK_ATTR, /* attr */ + { /* maxpacket */ + LSBYTE(USBMSC_HSBULKMAXPACKET), + MSBYTE(USBMSC_HSBULKMAXPACKET) + }, + 0 /* interval */ +}; + +static const struct usb_epdesc_s g_hsepbulkindesc = +{ + USB_SIZEOF_EPDESC, /* len */ + USB_DESC_TYPE_ENDPOINT, /* type */ + USBMSC_EPINBULK_ADDR, /* addr */ + USBMSC_EPINBULK_ATTR, /* attr */ + { /* maxpacket */ + LSBYTE(USBMSC_HSBULKMAXPACKET), + MSBYTE(USBMSC_HSBULKMAXPACKET) + }, + 0 /* interval */ +}; +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ +/* Strings ******************************************************************/ + +#ifndef CONFIG_USBMSC_COMPOSITE +const char g_mscvendorstr[] = CONFIG_USBMSC_VENDORSTR; +const char g_mscproductstr[] = CONFIG_USBMSC_PRODUCTSTR; +const char g_mscserialstr[] = CONFIG_USBMSC_SERIALSTR; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: usbmsc_mkstrdesc + * + * Description: + * Construct a string descriptor + * + ****************************************************************************/ + +int usbmsc_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc) +{ + const char *str; + int len; + int ndata; + int i; + + switch (id) + { +#ifndef CONFIG_USBMSC_COMPOSITE + case 0: + { + /* Descriptor 0 is the language id */ + + strdesc->len = 4; + strdesc->type = USB_DESC_TYPE_STRING; + strdesc->data[0] = LSBYTE(USBMSC_STR_LANGUAGE); + strdesc->data[1] = MSBYTE(USBMSC_STR_LANGUAGE); + return 4; + } + + case USBMSC_MANUFACTURERSTRID: + str = g_mscvendorstr; + break; + + case USBMSC_PRODUCTSTRID: + str = g_mscproductstr; + break; + + case USBMSC_SERIALSTRID: + str = g_mscserialstr; + break; +#endif + + /* case USBMSC_CONFIGSTRID: */ + case USBMSC_INTERFACESTRID: + str = CONFIG_USBMSC_CONFIGSTR; + break; + + default: + return -EINVAL; + } + + /* The string is utf16-le. The poor man's utf-8 to utf16-le + * conversion below will only handle 7-bit en-us ascii + */ + + len = strlen(str); + for (i = 0, ndata = 0; i < len; i++, ndata += 2) + { + strdesc->data[ndata] = str[i]; + strdesc->data[ndata+1] = 0; + } + + strdesc->len = ndata+2; + strdesc->type = USB_DESC_TYPE_STRING; + return strdesc->len; +} + +/**************************************************************************** + * Name: usbmsc_getepdesc + * + * Description: + * Return a pointer to the raw device descriptor + * + ****************************************************************************/ + +#ifndef CONFIG_USBMSC_COMPOSITE +FAR const struct usb_devdesc_s *usbmsc_getdevdesc(void) +{ + return &g_devdesc; +} +#endif + +/**************************************************************************** + * Name: usbmsc_getepdesc + * + * Description: + * Return a pointer to the raw endpoint descriptor (used for configuring + * endpoints) + * + ****************************************************************************/ + +FAR const struct usb_epdesc_s *usbmsc_getepdesc(enum usbmsc_epdesc_e epid) +{ + switch (epid) + { + case USBMSC_EPFSBULKOUT: /* Full speed bulk OUT endpoint descriptor */ + return &g_fsepbulkoutdesc; + + case USBMSC_EPFSBULKIN: /* Full speed bulk IN endpoint descriptor */ + return &g_fsepbulkindesc; + +#ifdef CONFIG_USBDEV_DUALSPEED + case USBMSC_EPHSBULKOUT: /* High speed bulk OUT endpoint descriptor */ + return &g_hsepbulkoutdesc; + + case USBMSC_EPHSBULKIN: /* High speed bulk IN endpoint descriptor */ + return &g_hsepbulkindesc; +#endif + default: + return NULL; + } +}; + +/**************************************************************************** + * Name: usbmsc_mkcfgdesc + * + * Description: + * Construct the configuration descriptor + * + ****************************************************************************/ + +#ifdef CONFIG_USBDEV_DUALSPEED +int16_t usbmsc_mkcfgdesc(uint8_t *buf, uint8_t speed, uint8_t type) +#else +int16_t usbmsc_mkcfgdesc(uint8_t *buf) +#endif +{ +#ifdef CONFIG_USBDEV_DUALSPEED + FAR const struct usb_epdesc_s *epdesc; + bool hispeed = (speed == USB_SPEED_HIGH); + uint16_t bulkmxpacket; +#endif + + /* 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(buf, &g_cfgdesc, USB_SIZEOF_CFGDESC); + buf += USB_SIZEOF_CFGDESC; +#endif + + /* Copy the canned interface descriptor */ + + memcpy(buf, &g_ifdesc, USB_SIZEOF_IFDESC); + buf += USB_SIZEOF_IFDESC; + + /* Make the two endpoint configurations */ + +#ifdef CONFIG_USBDEV_DUALSPEED + /* Check for switches between high and full speed */ + + hispeed = (speed == USB_SPEED_HIGH); + if (type == USB_DESC_TYPE_OTHERSPEEDCONFIG) + { + hispeed = !hispeed; + } + + bulkmxpacket = USBMSC_BULKMAXPACKET(hispeed); + epdesc = USBMSC_EPBULKINDESC(hispeed); + memcpy(buf, epdesc, USB_SIZEOF_EPDESC); + buf += USB_SIZEOF_EPDESC; + + epdesc = USBMSC_EPBULKOUTDESC(hispeed); + memcpy(buf, epdesc, USB_SIZEOF_EPDESC); +#else + memcpy(buf, &g_fsepbulkoutdesc, USB_SIZEOF_EPDESC); + buf += USB_SIZEOF_EPDESC; + memcpy(buf, &g_fsepbulkindesc, USB_SIZEOF_EPDESC); +#endif + + return SIZEOF_USBMSC_CFGDESC; +} + +/**************************************************************************** + * Name: usbmsc_getqualdesc + * + * Description: + * Return a pointer to the raw qual descriptor + * + ****************************************************************************/ + +#if !defined(CONFIG_USBMSC_COMPOSITE) && defined(CONFIG_USBDEV_DUALSPEED) +FAR const struct usb_qualdesc_s *usbmsc_getqualdesc(void) +{ + return &g_qualdesc; +} +#endif + diff --git a/nuttx/drivers/usbdev/usbmsc_descriptors.c b/nuttx/drivers/usbdev/usbmsc_descriptors.c deleted file mode 100644 index 8305a660a..000000000 --- a/nuttx/drivers/usbdev/usbmsc_descriptors.c +++ /dev/null @@ -1,421 +0,0 @@ -/**************************************************************************** - * drivers/usbdev/usbmsc_descriptors.c - * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include -#include - -#include "usbmsc.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ -/* Descriptors **************************************************************/ -/* Device descriptor. If the USB mass storage device is configured as part - * of a composite device, then the device descriptor will be provided by the - * composite device logic. - */ - -#ifndef CONFIG_USBMSC_COMPOSITE -static const struct usb_devdesc_s g_devdesc = -{ - USB_SIZEOF_DEVDESC, /* len */ - USB_DESC_TYPE_DEVICE, /* type */ - {LSBYTE(0x0200), MSBYTE(0x0200)}, /* usb */ - USB_CLASS_PER_INTERFACE, /* classid */ - 0, /* subclass */ - 0, /* protocol */ - CONFIG_USBMSC_EP0MAXPACKET, /* maxpacketsize */ - { /* vendor */ - LSBYTE(CONFIG_USBMSC_VENDORID), - MSBYTE(CONFIG_USBMSC_VENDORID) - }, - { /* product */ - LSBYTE(CONFIG_USBMSC_PRODUCTID), - MSBYTE(CONFIG_USBMSC_PRODUCTID) }, - { /* device */ - LSBYTE(CONFIG_USBMSC_VERSIONNO), - MSBYTE(CONFIG_USBMSC_VERSIONNO) - }, - USBMSC_MANUFACTURERSTRID, /* imfgr */ - USBMSC_PRODUCTSTRID, /* iproduct */ - USBMSC_SERIALSTRID, /* serno */ - USBMSC_NCONFIGS /* nconfigs */ -}; -#endif - -/* 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 -static const struct usb_cfgdesc_s g_cfgdesc = -{ - USB_SIZEOF_CFGDESC, /* len */ - USB_DESC_TYPE_CONFIG, /* type */ - { /* totallen */ - LSBYTE(SIZEOF_USBMSC_CFGDESC), - MSBYTE(SIZEOF_USBMSC_CFGDESC) - }, - USBMSC_NINTERFACES, /* ninterfaces */ - USBMSC_CONFIGID, /* cfgvalue */ - USBMSC_CONFIGSTRID, /* icfg */ - USB_CONFIG_ATTR_ONE|SELFPOWERED|REMOTEWAKEUP, /* attr */ - (CONFIG_USBDEV_MAXPOWER + 1) / 2 /* mxpower */ -}; -#endif - -/* Single interface descriptor */ - -static const struct usb_ifdesc_s g_ifdesc = -{ - USB_SIZEOF_IFDESC, /* len */ - USB_DESC_TYPE_INTERFACE, /* type */ - USBMSC_INTERFACEID, /* ifno */ - USBMSC_ALTINTERFACEID, /* alt */ - USBMSC_NENDPOINTS, /* neps */ - USB_CLASS_MASS_STORAGE, /* classid */ - USBMSC_SUBCLASS_SCSI, /* subclass */ - USBMSC_PROTO_BULKONLY, /* protocol */ - USBMSC_INTERFACESTRID /* iif */ -}; - -/* Endpoint descriptors */ - -static const struct usb_epdesc_s g_fsepbulkoutdesc = -{ - USB_SIZEOF_EPDESC, /* len */ - USB_DESC_TYPE_ENDPOINT, /* type */ - USBMSC_EPOUTBULK_ADDR, /* addr */ - USBMSC_EPOUTBULK_ATTR, /* attr */ - { /* maxpacket */ - LSBYTE(USBMSC_FSBULKMAXPACKET), - MSBYTE(USBMSC_FSBULKMAXPACKET) - }, - 0 /* interval */ -}; - -static const struct usb_epdesc_s g_fsepbulkindesc = -{ - USB_SIZEOF_EPDESC, /* len */ - USB_DESC_TYPE_ENDPOINT, /* type */ - USBMSC_EPINBULK_ADDR, /* addr */ - USBMSC_EPINBULK_ATTR, /* attr */ - { /* maxpacket */ - LSBYTE(USBMSC_FSBULKMAXPACKET), - MSBYTE(USBMSC_FSBULKMAXPACKET) - }, - 0 /* interval */ -}; - -#ifdef CONFIG_USBDEV_DUALSPEED -#ifndef CONFIG_USBMSC_COMPOSITE -static const struct usb_qualdesc_s g_qualdesc = -{ - USB_SIZEOF_QUALDESC, /* len */ - USB_DESC_TYPE_DEVICEQUALIFIER, /* type */ - { /* usb */ - LSBYTE(0x0200), - MSBYTE(0x0200) - }, - USB_CLASS_PER_INTERFACE, /* classid */ - 0, /* subclass */ - 0, /* protocol */ - CONFIG_USBMSC_EP0MAXPACKET, /* mxpacketsize */ - USBMSC_NCONFIGS, /* nconfigs */ - 0, /* reserved */ -}; -#endif - -static const struct usb_epdesc_s g_hsepbulkoutdesc = -{ - USB_SIZEOF_EPDESC, /* len */ - USB_DESC_TYPE_ENDPOINT, /* type */ - USBMSC_EPOUTBULK_ADDR, /* addr */ - USBMSC_EPOUTBULK_ATTR, /* attr */ - { /* maxpacket */ - LSBYTE(USBMSC_HSBULKMAXPACKET), - MSBYTE(USBMSC_HSBULKMAXPACKET) - }, - 0 /* interval */ -}; - -static const struct usb_epdesc_s g_hsepbulkindesc = -{ - USB_SIZEOF_EPDESC, /* len */ - USB_DESC_TYPE_ENDPOINT, /* type */ - USBMSC_EPINBULK_ADDR, /* addr */ - USBMSC_EPINBULK_ATTR, /* attr */ - { /* maxpacket */ - LSBYTE(USBMSC_HSBULKMAXPACKET), - MSBYTE(USBMSC_HSBULKMAXPACKET) - }, - 0 /* interval */ -}; -#endif - -/**************************************************************************** - * Public Data - ****************************************************************************/ -/* Strings ******************************************************************/ - -#ifndef CONFIG_USBMSC_COMPOSITE -const char g_mscvendorstr[] = CONFIG_USBMSC_VENDORSTR; -const char g_mscproductstr[] = CONFIG_USBMSC_PRODUCTSTR; -const char g_mscserialstr[] = CONFIG_USBMSC_SERIALSTR; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: usbmsc_mkstrdesc - * - * Description: - * Construct a string descriptor - * - ****************************************************************************/ - -int usbmsc_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc) -{ - const char *str; - int len; - int ndata; - int i; - - switch (id) - { -#ifndef CONFIG_USBMSC_COMPOSITE - case 0: - { - /* Descriptor 0 is the language id */ - - strdesc->len = 4; - strdesc->type = USB_DESC_TYPE_STRING; - strdesc->data[0] = LSBYTE(USBMSC_STR_LANGUAGE); - strdesc->data[1] = MSBYTE(USBMSC_STR_LANGUAGE); - return 4; - } - - case USBMSC_MANUFACTURERSTRID: - str = g_mscvendorstr; - break; - - case USBMSC_PRODUCTSTRID: - str = g_mscproductstr; - break; - - case USBMSC_SERIALSTRID: - str = g_mscserialstr; - break; -#endif - - /* case USBMSC_CONFIGSTRID: */ - case USBMSC_INTERFACESTRID: - str = CONFIG_USBMSC_CONFIGSTR; - break; - - default: - return -EINVAL; - } - - /* The string is utf16-le. The poor man's utf-8 to utf16-le - * conversion below will only handle 7-bit en-us ascii - */ - - len = strlen(str); - for (i = 0, ndata = 0; i < len; i++, ndata += 2) - { - strdesc->data[ndata] = str[i]; - strdesc->data[ndata+1] = 0; - } - - strdesc->len = ndata+2; - strdesc->type = USB_DESC_TYPE_STRING; - return strdesc->len; -} - -/**************************************************************************** - * Name: usbmsc_getepdesc - * - * Description: - * Return a pointer to the raw device descriptor - * - ****************************************************************************/ - -#ifndef CONFIG_USBMSC_COMPOSITE -FAR const struct usb_devdesc_s *usbmsc_getdevdesc(void) -{ - return &g_devdesc; -} -#endif - -/**************************************************************************** - * Name: usbmsc_getepdesc - * - * Description: - * Return a pointer to the raw endpoint descriptor (used for configuring - * endpoints) - * - ****************************************************************************/ - -FAR const struct usb_epdesc_s *usbmsc_getepdesc(enum usbmsc_epdesc_e epid) -{ - switch (epid) - { - case USBMSC_EPFSBULKOUT: /* Full speed bulk OUT endpoint descriptor */ - return &g_fsepbulkoutdesc; - - case USBMSC_EPFSBULKIN: /* Full speed bulk IN endpoint descriptor */ - return &g_fsepbulkindesc; - -#ifdef CONFIG_USBDEV_DUALSPEED - case USBMSC_EPHSBULKOUT: /* High speed bulk OUT endpoint descriptor */ - return &g_hsepbulkoutdesc; - - case USBMSC_EPHSBULKIN: /* High speed bulk IN endpoint descriptor */ - return &g_hsepbulkindesc; -#endif - default: - return NULL; - } -}; - -/**************************************************************************** - * Name: usbmsc_mkcfgdesc - * - * Description: - * Construct the configuration descriptor - * - ****************************************************************************/ - -#ifdef CONFIG_USBDEV_DUALSPEED -int16_t usbmsc_mkcfgdesc(uint8_t *buf, uint8_t speed, uint8_t type) -#else -int16_t usbmsc_mkcfgdesc(uint8_t *buf) -#endif -{ -#ifdef CONFIG_USBDEV_DUALSPEED - FAR const struct usb_epdesc_s *epdesc; - bool hispeed = (speed == USB_SPEED_HIGH); - uint16_t bulkmxpacket; -#endif - - /* 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(buf, &g_cfgdesc, USB_SIZEOF_CFGDESC); - buf += USB_SIZEOF_CFGDESC; -#endif - - /* Copy the canned interface descriptor */ - - memcpy(buf, &g_ifdesc, USB_SIZEOF_IFDESC); - buf += USB_SIZEOF_IFDESC; - - /* Make the two endpoint configurations */ - -#ifdef CONFIG_USBDEV_DUALSPEED - /* Check for switches between high and full speed */ - - hispeed = (speed == USB_SPEED_HIGH); - if (type == USB_DESC_TYPE_OTHERSPEEDCONFIG) - { - hispeed = !hispeed; - } - - bulkmxpacket = USBMSC_BULKMAXPACKET(hispeed); - epdesc = USBMSC_EPBULKINDESC(hispeed); - memcpy(buf, epdesc, USB_SIZEOF_EPDESC); - buf += USB_SIZEOF_EPDESC; - - epdesc = USBMSC_EPBULKOUTDESC(hispeed); - memcpy(buf, epdesc, USB_SIZEOF_EPDESC); -#else - memcpy(buf, &g_fsepbulkoutdesc, USB_SIZEOF_EPDESC); - buf += USB_SIZEOF_EPDESC; - memcpy(buf, &g_fsepbulkindesc, USB_SIZEOF_EPDESC); -#endif - - return SIZEOF_USBMSC_CFGDESC; -} - -/**************************************************************************** - * Name: usbmsc_getqualdesc - * - * Description: - * Return a pointer to the raw qual descriptor - * - ****************************************************************************/ - -#if !defined(CONFIG_USBMSC_COMPOSITE) && defined(CONFIG_USBDEV_DUALSPEED) -FAR const struct usb_qualdesc_s *usbmsc_getqualdesc(void) -{ - return &g_qualdesc; -} -#endif - -- cgit v1.2.3