usbd_desc.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /**
  2. ******************************************************************************
  3. * @file : usbd_desc.c
  4. * @version : v1.0_Cube
  5. * @brief : This file implements the USB Device descriptors
  6. ******************************************************************************
  7. *
  8. * COPYRIGHT(c) 2016 STMicroelectronics
  9. *
  10. * Redistribution and use in source and binary forms, with or without modification,
  11. * are permitted provided that the following conditions are met:
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  18. * may be 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 "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. ******************************************************************************
  33. */
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "usbd_core.h"
  36. #include "usbd_desc.h"
  37. #include "usbd_conf.h"
  38. /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
  39. * @{
  40. */
  41. /** @defgroup USBD_DESC
  42. * @brief USBD descriptors module
  43. * @{
  44. */
  45. /** @defgroup USBD_DESC_Private_TypesDefinitions
  46. * @{
  47. */
  48. /**
  49. * @}
  50. */
  51. /** @defgroup USBD_DESC_Private_Defines
  52. * @{
  53. */
  54. #define USBD_VID 1155
  55. #define USBD_LANGID_STRING 1033
  56. #define USBD_MANUFACTURER_STRING "STMicroelectronics"
  57. #define USBD_PID_FS 22315
  58. #define USBD_PRODUCT_STRING_FS "STM32 Human interface"
  59. /* USER CODE BEGIN SERIALNUMBER_STRING_FS */
  60. #define USBD_SERIALNUMBER_STRING_FS "00000000001A"
  61. /* USER CODE END SERIALNUMBER_STRING_FS */
  62. #define USBD_CONFIGURATION_STRING_FS "HID Config"
  63. #define USBD_INTERFACE_STRING_FS "HID Interface"
  64. /**
  65. * @}
  66. */
  67. /** @defgroup USBD_DESC_Private_Macros
  68. * @{
  69. */
  70. /**
  71. * @}
  72. */
  73. /** @defgroup USBD_DESC_Private_Variables
  74. * @{
  75. */
  76. uint8_t * USBD_FS_DeviceDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  77. uint8_t * USBD_FS_LangIDStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  78. uint8_t * USBD_FS_ManufacturerStrDescriptor ( USBD_SpeedTypeDef speed , uint16_t *length);
  79. uint8_t * USBD_FS_ProductStrDescriptor ( USBD_SpeedTypeDef speed , uint16_t *length);
  80. uint8_t * USBD_FS_SerialStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  81. uint8_t * USBD_FS_ConfigStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  82. uint8_t * USBD_FS_InterfaceStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  83. #ifdef USB_SUPPORT_USER_STRING_DESC
  84. uint8_t * USBD_FS_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx , uint16_t *length);
  85. #endif /* USB_SUPPORT_USER_STRING_DESC */
  86. USBD_DescriptorsTypeDef FS_Desc =
  87. {
  88. USBD_FS_DeviceDescriptor,
  89. USBD_FS_LangIDStrDescriptor,
  90. USBD_FS_ManufacturerStrDescriptor,
  91. USBD_FS_ProductStrDescriptor,
  92. USBD_FS_SerialStrDescriptor,
  93. USBD_FS_ConfigStrDescriptor,
  94. USBD_FS_InterfaceStrDescriptor,
  95. };
  96. #if defined ( __ICCARM__ ) /*!< IAR Compiler */
  97. #pragma data_alignment=4
  98. #endif
  99. /* USB Standard Device Descriptor */
  100. __ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
  101. {
  102. 0x12, /*bLength */
  103. USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
  104. 0x00, /* bcdUSB */
  105. 0x02,
  106. 0x00, /*bDeviceClass*/
  107. 0x00, /*bDeviceSubClass*/
  108. 0x00, /*bDeviceProtocol*/
  109. USB_MAX_EP0_SIZE, /*bMaxPacketSize*/
  110. LOBYTE(USBD_VID), /*idVendor*/
  111. HIBYTE(USBD_VID), /*idVendor*/
  112. LOBYTE(USBD_PID_FS), /*idVendor*/
  113. HIBYTE(USBD_PID_FS), /*idVendor*/
  114. 0x00, /*bcdDevice rel. 2.00*/
  115. 0x02,
  116. USBD_IDX_MFC_STR, /*Index of manufacturer string*/
  117. USBD_IDX_PRODUCT_STR, /*Index of product string*/
  118. USBD_IDX_SERIAL_STR, /*Index of serial number string*/
  119. USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
  120. } ;
  121. /* USB_DeviceDescriptor */
  122. #if defined ( __ICCARM__ ) /*!< IAR Compiler */
  123. #pragma data_alignment=4
  124. #endif
  125. /* USB Standard Device Descriptor */
  126. __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
  127. {
  128. USB_LEN_LANGID_STR_DESC,
  129. USB_DESC_TYPE_STRING,
  130. LOBYTE(USBD_LANGID_STRING),
  131. HIBYTE(USBD_LANGID_STRING),
  132. };
  133. #if defined ( __ICCARM__ ) /*!< IAR Compiler */
  134. #pragma data_alignment=4
  135. #endif
  136. __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
  137. /**
  138. * @}
  139. */
  140. /** @defgroup USBD_DESC_Private_FunctionPrototypes
  141. * @{
  142. */
  143. /**
  144. * @}
  145. */
  146. /** @defgroup USBD_DESC_Private_Functions
  147. * @{
  148. */
  149. /**
  150. * @brief USBD_FS_DeviceDescriptor
  151. * return the device descriptor
  152. * @param speed : current device speed
  153. * @param length : pointer to data length variable
  154. * @retval pointer to descriptor buffer
  155. */
  156. uint8_t * USBD_FS_DeviceDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
  157. {
  158. *length = sizeof(USBD_FS_DeviceDesc);
  159. return USBD_FS_DeviceDesc;
  160. }
  161. /**
  162. * @brief USBD_FS_LangIDStrDescriptor
  163. * return the LangID string descriptor
  164. * @param speed : current device speed
  165. * @param length : pointer to data length variable
  166. * @retval pointer to descriptor buffer
  167. */
  168. uint8_t * USBD_FS_LangIDStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
  169. {
  170. *length = sizeof(USBD_LangIDDesc);
  171. return USBD_LangIDDesc;
  172. }
  173. /**
  174. * @brief USBD_FS_ProductStrDescriptor
  175. * return the product string descriptor
  176. * @param speed : current device speed
  177. * @param length : pointer to data length variable
  178. * @retval pointer to descriptor buffer
  179. */
  180. uint8_t * USBD_FS_ProductStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
  181. {
  182. if(speed == 0)
  183. {
  184. USBD_GetString (USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
  185. }
  186. else
  187. {
  188. USBD_GetString (USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
  189. }
  190. return USBD_StrDesc;
  191. }
  192. /**
  193. * @brief USBD_FS_ManufacturerStrDescriptor
  194. * return the manufacturer string descriptor
  195. * @param speed : current device speed
  196. * @param length : pointer to data length variable
  197. * @retval pointer to descriptor buffer
  198. */
  199. uint8_t * USBD_FS_ManufacturerStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
  200. {
  201. USBD_GetString (USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
  202. return USBD_StrDesc;
  203. }
  204. /**
  205. * @brief USBD_FS_SerialStrDescriptor
  206. * return the serial number string descriptor
  207. * @param speed : current device speed
  208. * @param length : pointer to data length variable
  209. * @retval pointer to descriptor buffer
  210. */
  211. uint8_t * USBD_FS_SerialStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
  212. {
  213. if(speed == USBD_SPEED_HIGH)
  214. {
  215. USBD_GetString (USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);
  216. }
  217. else
  218. {
  219. USBD_GetString (USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);
  220. }
  221. return USBD_StrDesc;
  222. }
  223. /**
  224. * @brief USBD_FS_ConfigStrDescriptor
  225. * return the configuration string descriptor
  226. * @param speed : current device speed
  227. * @param length : pointer to data length variable
  228. * @retval pointer to descriptor buffer
  229. */
  230. uint8_t * USBD_FS_ConfigStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
  231. {
  232. if(speed == USBD_SPEED_HIGH)
  233. {
  234. USBD_GetString (USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
  235. }
  236. else
  237. {
  238. USBD_GetString (USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
  239. }
  240. return USBD_StrDesc;
  241. }
  242. /**
  243. * @brief USBD_HS_InterfaceStrDescriptor
  244. * return the interface string descriptor
  245. * @param speed : current device speed
  246. * @param length : pointer to data length variable
  247. * @retval pointer to descriptor buffer
  248. */
  249. uint8_t * USBD_FS_InterfaceStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
  250. {
  251. if(speed == 0)
  252. {
  253. USBD_GetString (USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
  254. }
  255. else
  256. {
  257. USBD_GetString (USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
  258. }
  259. return USBD_StrDesc;
  260. }
  261. /**
  262. * @}
  263. */
  264. /**
  265. * @}
  266. */
  267. /**
  268. * @}
  269. */
  270. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/