Subversion Repositories DashDisplay

Rev

Blame | Last modification | View Log | Download | RSS feed

  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.  
  35. /* Includes ------------------------------------------------------------------*/
  36. #include "usbd_core.h"
  37. #include "usbd_desc.h"
  38. #include "usbd_conf.h"
  39.  
  40. /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
  41.   * @{
  42.   */
  43.  
  44. /** @defgroup USBD_DESC
  45.   * @brief USBD descriptors module
  46.   * @{
  47.   */
  48.  
  49. /** @defgroup USBD_DESC_Private_TypesDefinitions
  50.   * @{
  51.   */
  52. /**
  53.   * @}
  54.   */
  55.  
  56. /** @defgroup USBD_DESC_Private_Defines
  57.   * @{
  58.   */
  59. #define USBD_VID     0x483
  60. #define USBD_LANGID_STRING     1033
  61. #define USBD_MANUFACTURER_STRING     "STMicroelectronics"
  62. #define USBD_PID_FS     0x5740
  63. #define USBD_PRODUCT_STRING_FS     "STM32 Virtual ComPort"
  64. #define USBD_SERIALNUMBER_STRING_FS     "00000000001A"
  65. #define USBD_CONFIGURATION_STRING_FS     "CDC Config"
  66. #define USBD_INTERFACE_STRING_FS     "CDC Interface"
  67.  
  68. /* USER CODE BEGIN 0 */
  69.  
  70. /* USER CODE END 0*/
  71. /**
  72.   * @}
  73.   */
  74.  
  75. /** @defgroup USBD_DESC_Private_Macros
  76.   * @{
  77.   */
  78. /**
  79.   * @}
  80.   */
  81.  
  82. /** @defgroup USBD_DESC_Private_Variables
  83.   * @{
  84.   */
  85. uint8_t *     USBD_FS_DeviceDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  86. uint8_t *     USBD_FS_LangIDStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  87. uint8_t *     USBD_FS_ManufacturerStrDescriptor ( USBD_SpeedTypeDef speed , uint16_t *length);
  88. uint8_t *     USBD_FS_ProductStrDescriptor ( USBD_SpeedTypeDef speed , uint16_t *length);
  89. uint8_t *     USBD_FS_SerialStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  90. uint8_t *     USBD_FS_ConfigStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  91. uint8_t *     USBD_FS_InterfaceStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  92.  
  93. #ifdef USB_SUPPORT_USER_STRING_DESC
  94. uint8_t *     USBD_FS_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx , uint16_t *length);  
  95. #endif /* USB_SUPPORT_USER_STRING_DESC */  
  96.  
  97. USBD_DescriptorsTypeDef FS_Desc =
  98. {
  99.   USBD_FS_DeviceDescriptor,
  100.   USBD_FS_LangIDStrDescriptor,
  101.   USBD_FS_ManufacturerStrDescriptor,
  102.   USBD_FS_ProductStrDescriptor,
  103.   USBD_FS_SerialStrDescriptor,
  104.   USBD_FS_ConfigStrDescriptor,
  105.   USBD_FS_InterfaceStrDescriptor,
  106. };
  107.  
  108. #if defined ( __ICCARM__ ) /*!< IAR Compiler */
  109.   #pragma data_alignment=4  
  110. #endif
  111. /* USB Standard Device Descriptor */
  112. __ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
  113.   {
  114.     0x12,                       /*bLength */
  115.     USB_DESC_TYPE_DEVICE,       /*bDescriptorType*/
  116.     0x00,                       /* bcdUSB */  
  117.     0x02,
  118.     0x02,                        /*bDeviceClass*/
  119.     0x02,                       /*bDeviceSubClass*/
  120.     0x00,                       /*bDeviceProtocol*/
  121.     USB_MAX_EP0_SIZE,          /*bMaxPacketSize*/
  122.     LOBYTE(USBD_VID),           /*idVendor*/
  123.     HIBYTE(USBD_VID),           /*idVendor*/
  124.     LOBYTE(USBD_PID_FS),           /*idVendor*/
  125.     HIBYTE(USBD_PID_FS),           /*idVendor*/
  126.     0x00,                       /*bcdDevice rel. 2.00*/
  127.     0x02,
  128.     USBD_IDX_MFC_STR,           /*Index of manufacturer  string*/
  129.     USBD_IDX_PRODUCT_STR,       /*Index of product string*/
  130.     USBD_IDX_SERIAL_STR,        /*Index of serial number string*/
  131.     USBD_MAX_NUM_CONFIGURATION  /*bNumConfigurations*/
  132.   } ;
  133. /* USB_DeviceDescriptor */
  134.  
  135. #if defined ( __ICCARM__ ) /*!< IAR Compiler */
  136.   #pragma data_alignment=4  
  137. #endif
  138.  
  139. /* USB Standard Device Descriptor */
  140. __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
  141. {
  142.      USB_LEN_LANGID_STR_DESC,        
  143.      USB_DESC_TYPE_STRING,      
  144.      LOBYTE(USBD_LANGID_STRING),
  145.      HIBYTE(USBD_LANGID_STRING),
  146. };
  147.  
  148. #if defined ( __ICCARM__ ) /*!< IAR Compiler */
  149.   #pragma data_alignment=4  
  150. #endif
  151. __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
  152. /**
  153.   * @}
  154.   */
  155.  
  156. /** @defgroup USBD_DESC_Private_FunctionPrototypes
  157.   * @{
  158.   */
  159. /**
  160.   * @}
  161.   */
  162.  
  163. /** @defgroup USBD_DESC_Private_Functions
  164.   * @{
  165.   */
  166.  
  167. /**
  168. * @brief  USBD_FS_DeviceDescriptor
  169. *         return the device descriptor
  170. * @param  speed : current device speed
  171. * @param  length : pointer to data length variable
  172. * @retval pointer to descriptor buffer
  173. */
  174. uint8_t *  USBD_FS_DeviceDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
  175. {
  176.   *length = sizeof(USBD_FS_DeviceDesc);
  177.   return USBD_FS_DeviceDesc;
  178. }
  179.  
  180. /**
  181. * @brief  USBD_FS_LangIDStrDescriptor
  182. *         return the LangID string descriptor
  183. * @param  speed : current device speed
  184. * @param  length : pointer to data length variable
  185. * @retval pointer to descriptor buffer
  186. */
  187. uint8_t *  USBD_FS_LangIDStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
  188. {
  189.   *length =  sizeof(USBD_LangIDDesc);  
  190.   return USBD_LangIDDesc;
  191. }
  192.  
  193. /**
  194. * @brief  USBD_FS_ProductStrDescriptor
  195. *         return the product string descriptor
  196. * @param  speed : current device speed
  197. * @param  length : pointer to data length variable
  198. * @retval pointer to descriptor buffer
  199. */
  200. uint8_t *  USBD_FS_ProductStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
  201. {
  202.   if(speed == 0)
  203.   {  
  204.     USBD_GetString (USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
  205.   }
  206.   else
  207.   {
  208.     USBD_GetString (USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);    
  209.   }
  210.   return USBD_StrDesc;
  211. }
  212.  
  213. /**
  214. * @brief  USBD_FS_ManufacturerStrDescriptor
  215. *         return the manufacturer string descriptor
  216. * @param  speed : current device speed
  217. * @param  length : pointer to data length variable
  218. * @retval pointer to descriptor buffer
  219. */
  220. uint8_t *  USBD_FS_ManufacturerStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
  221. {
  222.   USBD_GetString (USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
  223.   return USBD_StrDesc;
  224. }
  225.  
  226. /**
  227. * @brief  USBD_FS_SerialStrDescriptor
  228. *         return the serial number string descriptor
  229. * @param  speed : current device speed
  230. * @param  length : pointer to data length variable
  231. * @retval pointer to descriptor buffer
  232. */
  233. uint8_t *  USBD_FS_SerialStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
  234. {
  235.   if(speed  == USBD_SPEED_HIGH)
  236.   {    
  237.     USBD_GetString (USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);
  238.   }
  239.   else
  240.   {
  241.     USBD_GetString (USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);    
  242.   }
  243.   return USBD_StrDesc;
  244. }
  245.  
  246. /**
  247. * @brief  USBD_FS_ConfigStrDescriptor
  248. *         return the configuration string descriptor
  249. * @param  speed : current device speed
  250. * @param  length : pointer to data length variable
  251. * @retval pointer to descriptor buffer
  252. */
  253. uint8_t *  USBD_FS_ConfigStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
  254. {
  255.   if(speed  == USBD_SPEED_HIGH)
  256.   {  
  257.     USBD_GetString (USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
  258.   }
  259.   else
  260.   {
  261.     USBD_GetString (USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
  262.   }
  263.   return USBD_StrDesc;  
  264. }
  265.  
  266. /**
  267. * @brief  USBD_HS_InterfaceStrDescriptor
  268. *         return the interface string descriptor
  269. * @param  speed : current device speed
  270. * @param  length : pointer to data length variable
  271. * @retval pointer to descriptor buffer
  272. */
  273. uint8_t *  USBD_FS_InterfaceStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
  274. {
  275.   if(speed == 0)
  276.   {
  277.     USBD_GetString (USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
  278.   }
  279.   else
  280.   {
  281.     USBD_GetString (USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
  282.   }
  283.   return USBD_StrDesc;  
  284. }
  285. /**
  286.   * @}
  287.   */
  288.  
  289. /**
  290.   * @}
  291.   */
  292.  
  293. /**
  294.   * @}
  295.   */
  296.  
  297. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  298.