composite.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /****************************************************************************
  2. * drivers/usbdev/composite.h
  3. *
  4. * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __DRIVERS_USBDEV_COMPOSITE_H
  36. #define __DRIVERS_USBDEV_COMPOSITE_H 1
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <sys/types.h>
  42. #include <stdint.h>
  43. #include <nuttx/usb/usb.h>
  44. #include <nuttx/usb/usbdev_trace.h>
  45. #ifdef CONFIG_USBDEV_COMPOSITE
  46. #ifdef CONFIG_CDCACM_COMPOSITE
  47. # include <nuttx/usb/cdcacm.h>
  48. # include "cdcacm.h"
  49. #endif
  50. #ifdef CONFIG_USBMSC_COMPOSITE
  51. # include "usbmsc.h"
  52. #endif
  53. /****************************************************************************
  54. * Pre-processor Definitions
  55. ****************************************************************************/
  56. /* Configuration ************************************************************/
  57. /* Packet sizes */
  58. #ifndef CONFIG_COMPOSITE_EP0MAXPACKET
  59. # define CONFIG_COMPOSITE_EP0MAXPACKET 64
  60. #endif
  61. /* Vendor and product IDs and strings */
  62. #ifndef CONFIG_COMPOSITE_COMPOSITE
  63. # ifndef CONFIG_COMPOSITE_VENDORID
  64. # warning "CONFIG_COMPOSITE_VENDORID not defined"
  65. # define CONFIG_COMPOSITE_VENDORID 0x03eb
  66. # endif
  67. # ifndef CONFIG_COMPOSITE_PRODUCTID
  68. # warning "CONFIG_COMPOSITE_PRODUCTID not defined"
  69. # define CONFIG_COMPOSITE_PRODUCTID 0x2022
  70. # endif
  71. # ifndef CONFIG_COMPOSITE_VERSIONNO
  72. # define CONFIG_COMPOSITE_VERSIONNO (0x0101)
  73. # endif
  74. # ifndef CONFIG_COMPOSITE_VENDORSTR
  75. # warning "No Vendor string specified"
  76. # define CONFIG_COMPOSITE_VENDORSTR "NuttX"
  77. # endif
  78. # ifndef CONFIG_COMPOSITE_PRODUCTSTR
  79. # warning "No Product string specified"
  80. # define CONFIG_COMPOSITE_PRODUCTSTR "Composite Device"
  81. # endif
  82. # undef CONFIG_COMPOSITE_SERIALSTR
  83. # define CONFIG_COMPOSITE_SERIALSTR "0101"
  84. #endif
  85. #undef CONFIG_COMPOSITE_CONFIGSTR
  86. #define CONFIG_COMPOSITE_CONFIGSTR "Composite"
  87. /* Constituent devices ******************************************************/
  88. #undef DEV1_IS_CDCACM
  89. #undef DEV1_IS_USBMSC
  90. #undef DEV2_IS_CDCACM
  91. #undef DEV2_IS_USBMSC
  92. /* Pick the first device in the composite. At present, this may only be
  93. * the CDC serial device or the mass storage device.
  94. */
  95. #if defined(CONFIG_CDCACM_COMPOSITE)
  96. # define DEV1_IS_CDCACM 1
  97. # define DEV1_MKCFGDESC cdcacm_mkcfgdesc
  98. # define DEV1_MKSTRDESC cdcacm_mkstrdesc
  99. # define DEV1_CLASSOBJECT board_cdcclassobject
  100. # define DEV1_UNINITIALIZE board_cdcuninitialize
  101. # define DEV1_NCONFIGS CDCACM_NCONFIGS
  102. # define DEV1_CONFIGID CDCACM_CONFIGID
  103. # define DEV1_FIRSTINTERFACE CONFIG_CDCACM_IFNOBASE
  104. # define DEV1_NINTERFACES CDCACM_NINTERFACES
  105. # define DEV1_STRIDBASE CONFIG_CDCACM_STRBASE
  106. # define DEV1_NSTRIDS CDCACM_NSTRIDS
  107. # define DEV1_CFGDESCSIZE SIZEOF_CDCACM_CFGDESC
  108. #elif defined(CONFIG_CDCACM_COMPOSITE)
  109. # define DEV1_IS_USBMSC 1
  110. # define DEV1_MKCFGDESC usbmsc_mkcfgdesc
  111. # define DEV1_MKSTRDESC usbmsc_mkstrdesc
  112. # define DEV1_CLASSOBJECT board_mscclassobject
  113. # define DEV1_UNINITIALIZE board_mscuninitialize
  114. # define DEV1_NCONFIGS USBMSC_NCONFIGS
  115. # define DEV1_CONFIGID USBMSC_CONFIGID
  116. # define DEV1_FIRSTINTERFACE CONFIG_USBMSC_IFNOBASE
  117. # define DEV1_NINTERFACES USBMSC_NINTERFACES
  118. # define DEV1_STRIDBASE CONFIG_USBMSC_IFNOBASE
  119. # define DEV1_NSTRIDS USBMSC_NSTRIDS
  120. # define DEV1_CFGDESCSIZE SIZEOF_USBMSC_CFGDESC
  121. #else
  122. # error "No members of the composite defined"
  123. #endif
  124. /* Pick the second device in the composite. At present, this may only be
  125. * the CDC serial device or the mass storage device.
  126. */
  127. #if defined(CONFIG_CDCACM_COMPOSITE) && !defined(DEV1_IS_CDCACM)
  128. # define DEV2_IS_CDCACM 1
  129. # define DEV2_MKCFGDESC cdcacm_mkcfgdesc
  130. # define DEV2_MKSTRDESC cdcacm_mkstrdesc
  131. # define DEV2_CLASSOBJECT board_cdcclassobject
  132. # define DEV2_UNINITIALIZE board_cdcuninitialize
  133. # define DEV2_NCONFIGS CDCACM_NCONFIGS
  134. # define DEV2_CONFIGID CDCACM_CONFIGID
  135. # define DEV2_FIRSTINTERFACE CONFIG_CDCACM_IFNOBASE
  136. # define DEV2_NINTERFACES CDCACM_NINTERFACES
  137. # define DEV2_STRIDBASE CONFIG_CDCACM_STRBASE
  138. # define DEV2_NSTRIDS CDCACM_NSTRIDS
  139. # define DEV2_CFGDESCSIZE SIZEOF_CDCACM_CFGDESC
  140. #elif defined(CONFIG_CDCACM_COMPOSITE) && !defined(DEV1_IS_USBMSC)
  141. # define DEV2_IS_USBMSC 1
  142. # define DEV2_MKCFGDESC usbmsc_mkcfgdesc
  143. # define DEV2_MKSTRDESC usbmsc_mkstrdesc
  144. # define DEV2_UNINITIALIZE board_mscuninitialize
  145. # define DEV2_CLASSOBJECT board_mscclassobject
  146. # define DEV2_NCONFIGS USBMSC_NCONFIGS
  147. # define DEV2_CONFIGID USBMSC_CONFIGID
  148. # define DEV2_FIRSTINTERFACE CONFIG_USBMSC_IFNOBASE
  149. # define DEV2_NINTERFACES USBMSC_NINTERFACES
  150. # define DEV2_STRIDBASE CONFIG_USBMSC_STRBASE
  151. # define DEV2_NSTRIDS USBMSC_NSTRIDS
  152. # define DEV2_CFGDESCSIZE SIZEOF_USBMSC_CFGDESC
  153. #else
  154. # error "Insufficient members of the composite defined"
  155. #endif
  156. /* Verify interface configuration */
  157. #if DEV1_FIRSTINTERFACE != 0
  158. # warning "The first interface number should be zero"
  159. #endif
  160. #if (DEV1_FIRSTINTERFACE + DEV1_NINTERFACES) != DEV2_FIRSTINTERFACE
  161. # warning "Interface numbers are not contiguous"
  162. #endif
  163. /* Check if an IAD is needed */
  164. #ifdef CONFIG_COMPOSITE_IAD
  165. # if DEV1_NINTERFACES == 1 && DEV2_NINTERFACES == 1
  166. # warning "CONFIG_COMPOSITE_IAD not needed"
  167. # endif
  168. #endif
  169. #if !defined(CONFIG_COMPOSITE_IAD) && DEV1_NINTERFACES > 1 && DEV2_NINTERFACES > 1
  170. # warning "CONFIG_COMPOSITE_IAD may be needed"
  171. #endif
  172. /* Total size of the configuration descriptor: */
  173. #define COMPOSITE_CFGDESCSIZE (USB_SIZEOF_CFGDESC + DEV1_CFGDESCSIZE + DEV2_CFGDESCSIZE)
  174. /* The total number of interfaces */
  175. #define COMPOSITE_NINTERFACES (DEV1_NINTERFACES + DEV2_NINTERFACES)
  176. /* Composite configuration ID value */
  177. #if DEV1_NCONFIGS != 1 || DEV1_CONFIGID != 1
  178. # error "DEV1: Only a single configuration is supported"
  179. #endif
  180. #if DEV2_NCONFIGS != 1 || DEV2_CONFIGID != 1
  181. # error "DEV2: Only a single configuration is supported"
  182. #endif
  183. /* Descriptors **************************************************************/
  184. /* These settings are not modifiable via the NuttX configuration */
  185. #define COMPOSITE_CONFIGIDNONE (0) /* Config ID = 0 means to return to address mode */
  186. #define COMPOSITE_NCONFIGS (1) /* The number of configurations supported */
  187. #define COMPOSITE_CONFIGID (1) /* The only supported configuration ID */
  188. /* String language */
  189. #define COMPOSITE_STR_LANGUAGE (0x0409) /* en-us */
  190. /* Descriptor strings */
  191. #define COMPOSITE_MANUFACTURERSTRID (1)
  192. #define COMPOSITE_PRODUCTSTRID (2)
  193. #define COMPOSITE_SERIALSTRID (3)
  194. #define COMPOSITE_CONFIGSTRID (4)
  195. #define COMPOSITE_NSTRIDS (4)
  196. /* Verify string configuration */
  197. #if COMPOSITE_NSTRIDS != DEV1_STRIDBASE
  198. # warning "The DEV1 string base should be COMPOSITE_NSTRIDS"
  199. #endif
  200. #if (DEV1_STRIDBASE + DEV1_NSTRIDS) != DEV2_STRIDBASE
  201. # warning "String IDs are not contiguous"
  202. #endif
  203. /* Everpresent MIN/MAX macros ***********************************************/
  204. #ifndef MIN
  205. # define MIN(a,b) ((a) < (b) ? (a) : (b))
  206. #endif
  207. #ifndef MAX
  208. # define MAX(a,b) ((a) > (b) ? (a) : (b))
  209. #endif
  210. /****************************************************************************
  211. * Public Types
  212. ****************************************************************************/
  213. /****************************************************************************
  214. * Public Data
  215. ****************************************************************************/
  216. extern const char g_compvendorstr[];
  217. extern const char g_compproductstr[];
  218. extern const char g_compserialstr[];
  219. /****************************************************************************
  220. * Public Function Prototypes
  221. ****************************************************************************/
  222. /****************************************************************************
  223. * Name: composite_mkstrdesc
  224. *
  225. * Description:
  226. * Construct a string descriptor
  227. *
  228. ****************************************************************************/
  229. int composite_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc);
  230. /****************************************************************************
  231. * Name: composite_getepdesc
  232. *
  233. * Description:
  234. * Return a pointer to the composite device descriptor
  235. *
  236. ****************************************************************************/
  237. #ifndef CONFIG_COMPOSITE_COMPOSITE
  238. FAR const struct usb_devdesc_s *composite_getdevdesc(void);
  239. #endif
  240. /****************************************************************************
  241. * Name: composite_mkcfgdesc
  242. *
  243. * Description:
  244. * Construct the composite configuration descriptor
  245. *
  246. ****************************************************************************/
  247. #ifdef CONFIG_USBDEV_DUALSPEED
  248. int16_t composite_mkcfgdesc(uint8_t *buf, uint8_t speed, uint8_t type);
  249. #else
  250. int16_t composite_mkcfgdesc(uint8_t *buf);
  251. #endif
  252. /****************************************************************************
  253. * Name: composite_getqualdesc
  254. *
  255. * Description:
  256. * Return a pointer to the composite qual descriptor
  257. *
  258. ****************************************************************************/
  259. #ifdef CONFIG_USBDEV_DUALSPEED
  260. FAR const struct usb_qualdesc_s *composite_getqualdesc(void);
  261. #endif
  262. #endif /* CONFIG_USBDEV_COMPOSITE */
  263. #endif /* __DRIVERS_USBDEV_COMPOSITE_H */