IOTON boards API using mbed SDK - http://ioton.cc/plataforma-ton

Dependents:   ton-bot_teste ton-bot_seguidor_linha ton-bot_seguidor_parede

Fork of IOTON-API by Kleber Silva

Committer:
krebyy
Date:
Thu Jun 29 20:11:00 2017 +0000
Revision:
1:3a73d77c2cef
Update to TON Board V1.2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
krebyy 1:3a73d77c2cef 1 /**
krebyy 1:3a73d77c2cef 2 ******************************************************************************
krebyy 1:3a73d77c2cef 3 * @file umart_lite_plus_teste/src/usbd_desc.c
krebyy 1:3a73d77c2cef 4 * @author MCD Application Team
krebyy 1:3a73d77c2cef 5 * @version V1.2.0
krebyy 1:3a73d77c2cef 6 * @date 26-December-2014
krebyy 1:3a73d77c2cef 7 * @brief This file provides the USBD descriptors and string formating method.
krebyy 1:3a73d77c2cef 8 ******************************************************************************
krebyy 1:3a73d77c2cef 9 * @attention
krebyy 1:3a73d77c2cef 10 *
krebyy 1:3a73d77c2cef 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
krebyy 1:3a73d77c2cef 12 *
krebyy 1:3a73d77c2cef 13 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
krebyy 1:3a73d77c2cef 14 * You may not use this file except in compliance with the License.
krebyy 1:3a73d77c2cef 15 * You may obtain a copy of the License at:
krebyy 1:3a73d77c2cef 16 *
krebyy 1:3a73d77c2cef 17 * http://www.st.com/software_license_agreement_liberty_v2
krebyy 1:3a73d77c2cef 18 *
krebyy 1:3a73d77c2cef 19 * Unless required by applicable law or agreed to in writing, software
krebyy 1:3a73d77c2cef 20 * distributed under the License is distributed on an "AS IS" BASIS,
krebyy 1:3a73d77c2cef 21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
krebyy 1:3a73d77c2cef 22 * See the License for the specific language governing permissions and
krebyy 1:3a73d77c2cef 23 * limitations under the License.
krebyy 1:3a73d77c2cef 24 *
krebyy 1:3a73d77c2cef 25 ******************************************************************************
krebyy 1:3a73d77c2cef 26 */
krebyy 1:3a73d77c2cef 27
krebyy 1:3a73d77c2cef 28 /* Includes ------------------------------------------------------------------*/
krebyy 1:3a73d77c2cef 29 #include "usbd_core.h"
krebyy 1:3a73d77c2cef 30 #include "usbd_desc.h"
krebyy 1:3a73d77c2cef 31 #include "usbd_conf.h"
krebyy 1:3a73d77c2cef 32
krebyy 1:3a73d77c2cef 33 /* Private typedef -----------------------------------------------------------*/
krebyy 1:3a73d77c2cef 34 /* Private define ------------------------------------------------------------*/
krebyy 1:3a73d77c2cef 35 #define USBD_VID 0x0483
krebyy 1:3a73d77c2cef 36 #define USBD_PID 0x5740
krebyy 1:3a73d77c2cef 37 #define USBD_LANGID_STRING 0x409
krebyy 1:3a73d77c2cef 38 #define USBD_MANUFACTURER_STRING "STMicroelectronics"
krebyy 1:3a73d77c2cef 39 #define USBD_PRODUCT_HS_STRING "STM32 Virtual ComPort in HS Mode"
krebyy 1:3a73d77c2cef 40 #define USBD_PRODUCT_FS_STRING "STM32 Virtual ComPort in FS Mode"
krebyy 1:3a73d77c2cef 41 #define USBD_CONFIGURATION_HS_STRING "VCP Config"
krebyy 1:3a73d77c2cef 42 #define USBD_INTERFACE_HS_STRING "VCP Interface"
krebyy 1:3a73d77c2cef 43 #define USBD_CONFIGURATION_FS_STRING "VCP Config"
krebyy 1:3a73d77c2cef 44 #define USBD_INTERFACE_FS_STRING "VCP Interface"
krebyy 1:3a73d77c2cef 45
krebyy 1:3a73d77c2cef 46 /* Private macro -------------------------------------------------------------*/
krebyy 1:3a73d77c2cef 47 /* Private function prototypes -----------------------------------------------*/
krebyy 1:3a73d77c2cef 48 uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
krebyy 1:3a73d77c2cef 49 uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
krebyy 1:3a73d77c2cef 50 uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
krebyy 1:3a73d77c2cef 51 uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
krebyy 1:3a73d77c2cef 52 uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
krebyy 1:3a73d77c2cef 53 uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
krebyy 1:3a73d77c2cef 54 uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
krebyy 1:3a73d77c2cef 55 #ifdef USB_SUPPORT_USER_STRING_DESC
krebyy 1:3a73d77c2cef 56 uint8_t *USBD_VCP_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
krebyy 1:3a73d77c2cef 57 #endif /* USB_SUPPORT_USER_STRING_DESC */
krebyy 1:3a73d77c2cef 58
krebyy 1:3a73d77c2cef 59 /* Private variables ---------------------------------------------------------*/
krebyy 1:3a73d77c2cef 60 USBD_DescriptorsTypeDef VCP_Desc = {
krebyy 1:3a73d77c2cef 61 USBD_VCP_DeviceDescriptor,
krebyy 1:3a73d77c2cef 62 USBD_VCP_LangIDStrDescriptor,
krebyy 1:3a73d77c2cef 63 USBD_VCP_ManufacturerStrDescriptor,
krebyy 1:3a73d77c2cef 64 USBD_VCP_ProductStrDescriptor,
krebyy 1:3a73d77c2cef 65 USBD_VCP_SerialStrDescriptor,
krebyy 1:3a73d77c2cef 66 USBD_VCP_ConfigStrDescriptor,
krebyy 1:3a73d77c2cef 67 USBD_VCP_InterfaceStrDescriptor,
krebyy 1:3a73d77c2cef 68 };
krebyy 1:3a73d77c2cef 69
krebyy 1:3a73d77c2cef 70 /* USB Standard Device Descriptor */
krebyy 1:3a73d77c2cef 71 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
krebyy 1:3a73d77c2cef 72 #pragma data_alignment=4
krebyy 1:3a73d77c2cef 73 #endif
krebyy 1:3a73d77c2cef 74 __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
krebyy 1:3a73d77c2cef 75 0x12, /* bLength */
krebyy 1:3a73d77c2cef 76 USB_DESC_TYPE_DEVICE, /* bDescriptorType */
krebyy 1:3a73d77c2cef 77 0x00, /* bcdUSB */
krebyy 1:3a73d77c2cef 78 0x02,
krebyy 1:3a73d77c2cef 79 0x00, /* bDeviceClass */
krebyy 1:3a73d77c2cef 80 0x00, /* bDeviceSubClass */
krebyy 1:3a73d77c2cef 81 0x00, /* bDeviceProtocol */
krebyy 1:3a73d77c2cef 82 USB_MAX_EP0_SIZE, /* bMaxPacketSize */
krebyy 1:3a73d77c2cef 83 LOBYTE(USBD_VID), /* idVendor */
krebyy 1:3a73d77c2cef 84 HIBYTE(USBD_VID), /* idVendor */
krebyy 1:3a73d77c2cef 85 LOBYTE(USBD_PID), /* idVendor */
krebyy 1:3a73d77c2cef 86 HIBYTE(USBD_PID), /* idVendor */
krebyy 1:3a73d77c2cef 87 0x00, /* bcdDevice rel. 2.00 */
krebyy 1:3a73d77c2cef 88 0x02,
krebyy 1:3a73d77c2cef 89 USBD_IDX_MFC_STR, /* Index of manufacturer string */
krebyy 1:3a73d77c2cef 90 USBD_IDX_PRODUCT_STR, /* Index of product string */
krebyy 1:3a73d77c2cef 91 USBD_IDX_SERIAL_STR, /* Index of serial number string */
krebyy 1:3a73d77c2cef 92 USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
krebyy 1:3a73d77c2cef 93 }; /* USB_DeviceDescriptor */
krebyy 1:3a73d77c2cef 94
krebyy 1:3a73d77c2cef 95 /* USB Standard Device Descriptor */
krebyy 1:3a73d77c2cef 96 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
krebyy 1:3a73d77c2cef 97 #pragma data_alignment=4
krebyy 1:3a73d77c2cef 98 #endif
krebyy 1:3a73d77c2cef 99 __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
krebyy 1:3a73d77c2cef 100 USB_LEN_LANGID_STR_DESC,
krebyy 1:3a73d77c2cef 101 USB_DESC_TYPE_STRING,
krebyy 1:3a73d77c2cef 102 LOBYTE(USBD_LANGID_STRING),
krebyy 1:3a73d77c2cef 103 HIBYTE(USBD_LANGID_STRING),
krebyy 1:3a73d77c2cef 104 };
krebyy 1:3a73d77c2cef 105
krebyy 1:3a73d77c2cef 106 uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] =
krebyy 1:3a73d77c2cef 107 {
krebyy 1:3a73d77c2cef 108 USB_SIZ_STRING_SERIAL,
krebyy 1:3a73d77c2cef 109 USB_DESC_TYPE_STRING,
krebyy 1:3a73d77c2cef 110 };
krebyy 1:3a73d77c2cef 111
krebyy 1:3a73d77c2cef 112 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
krebyy 1:3a73d77c2cef 113 #pragma data_alignment=4
krebyy 1:3a73d77c2cef 114 #endif
krebyy 1:3a73d77c2cef 115 __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
krebyy 1:3a73d77c2cef 116
krebyy 1:3a73d77c2cef 117 /* Private functions ---------------------------------------------------------*/
krebyy 1:3a73d77c2cef 118 static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len);
krebyy 1:3a73d77c2cef 119 static void Get_SerialNum(void);
krebyy 1:3a73d77c2cef 120
krebyy 1:3a73d77c2cef 121 /**
krebyy 1:3a73d77c2cef 122 * @brief Returns the device descriptor.
krebyy 1:3a73d77c2cef 123 * @param speed: Current device speed
krebyy 1:3a73d77c2cef 124 * @param length: Pointer to data length variable
krebyy 1:3a73d77c2cef 125 * @retval Pointer to descriptor buffer
krebyy 1:3a73d77c2cef 126 */
krebyy 1:3a73d77c2cef 127 uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
krebyy 1:3a73d77c2cef 128 {
krebyy 1:3a73d77c2cef 129 *length = sizeof(USBD_DeviceDesc);
krebyy 1:3a73d77c2cef 130 return (uint8_t*)USBD_DeviceDesc;
krebyy 1:3a73d77c2cef 131 }
krebyy 1:3a73d77c2cef 132
krebyy 1:3a73d77c2cef 133 /**
krebyy 1:3a73d77c2cef 134 * @brief Returns the LangID string descriptor.
krebyy 1:3a73d77c2cef 135 * @param speed: Current device speed
krebyy 1:3a73d77c2cef 136 * @param length: Pointer to data length variable
krebyy 1:3a73d77c2cef 137 * @retval Pointer to descriptor buffer
krebyy 1:3a73d77c2cef 138 */
krebyy 1:3a73d77c2cef 139 uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
krebyy 1:3a73d77c2cef 140 {
krebyy 1:3a73d77c2cef 141 *length = sizeof(USBD_LangIDDesc);
krebyy 1:3a73d77c2cef 142 return (uint8_t*)USBD_LangIDDesc;
krebyy 1:3a73d77c2cef 143 }
krebyy 1:3a73d77c2cef 144
krebyy 1:3a73d77c2cef 145 /**
krebyy 1:3a73d77c2cef 146 * @brief Returns the product string descriptor.
krebyy 1:3a73d77c2cef 147 * @param speed: Current device speed
krebyy 1:3a73d77c2cef 148 * @param length: Pointer to data length variable
krebyy 1:3a73d77c2cef 149 * @retval Pointer to descriptor buffer
krebyy 1:3a73d77c2cef 150 */
krebyy 1:3a73d77c2cef 151 uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
krebyy 1:3a73d77c2cef 152 {
krebyy 1:3a73d77c2cef 153 if(speed == 0)
krebyy 1:3a73d77c2cef 154 {
krebyy 1:3a73d77c2cef 155 USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
krebyy 1:3a73d77c2cef 156 }
krebyy 1:3a73d77c2cef 157 else
krebyy 1:3a73d77c2cef 158 {
krebyy 1:3a73d77c2cef 159 USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
krebyy 1:3a73d77c2cef 160 }
krebyy 1:3a73d77c2cef 161 return USBD_StrDesc;
krebyy 1:3a73d77c2cef 162 }
krebyy 1:3a73d77c2cef 163
krebyy 1:3a73d77c2cef 164 /**
krebyy 1:3a73d77c2cef 165 * @brief Returns the manufacturer string descriptor.
krebyy 1:3a73d77c2cef 166 * @param speed: Current device speed
krebyy 1:3a73d77c2cef 167 * @param length: Pointer to data length variable
krebyy 1:3a73d77c2cef 168 * @retval Pointer to descriptor buffer
krebyy 1:3a73d77c2cef 169 */
krebyy 1:3a73d77c2cef 170 uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
krebyy 1:3a73d77c2cef 171 {
krebyy 1:3a73d77c2cef 172 USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
krebyy 1:3a73d77c2cef 173 return USBD_StrDesc;
krebyy 1:3a73d77c2cef 174 }
krebyy 1:3a73d77c2cef 175
krebyy 1:3a73d77c2cef 176 /**
krebyy 1:3a73d77c2cef 177 * @brief Returns the serial number string descriptor.
krebyy 1:3a73d77c2cef 178 * @param speed: Current device speed
krebyy 1:3a73d77c2cef 179 * @param length: Pointer to data length variable
krebyy 1:3a73d77c2cef 180 * @retval Pointer to descriptor buffer
krebyy 1:3a73d77c2cef 181 */
krebyy 1:3a73d77c2cef 182 uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
krebyy 1:3a73d77c2cef 183 {
krebyy 1:3a73d77c2cef 184 *length = USB_SIZ_STRING_SERIAL;
krebyy 1:3a73d77c2cef 185
krebyy 1:3a73d77c2cef 186 /* Update the serial number string descriptor with the data from the unique ID*/
krebyy 1:3a73d77c2cef 187 Get_SerialNum();
krebyy 1:3a73d77c2cef 188
krebyy 1:3a73d77c2cef 189 return (uint8_t*)USBD_StringSerial;
krebyy 1:3a73d77c2cef 190 }
krebyy 1:3a73d77c2cef 191
krebyy 1:3a73d77c2cef 192 /**
krebyy 1:3a73d77c2cef 193 * @brief Returns the configuration string descriptor.
krebyy 1:3a73d77c2cef 194 * @param speed: Current device speed
krebyy 1:3a73d77c2cef 195 * @param length: Pointer to data length variable
krebyy 1:3a73d77c2cef 196 * @retval Pointer to descriptor buffer
krebyy 1:3a73d77c2cef 197 */
krebyy 1:3a73d77c2cef 198 uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
krebyy 1:3a73d77c2cef 199 {
krebyy 1:3a73d77c2cef 200 if(speed == USBD_SPEED_HIGH)
krebyy 1:3a73d77c2cef 201 {
krebyy 1:3a73d77c2cef 202 USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
krebyy 1:3a73d77c2cef 203 }
krebyy 1:3a73d77c2cef 204 else
krebyy 1:3a73d77c2cef 205 {
krebyy 1:3a73d77c2cef 206 USBD_GetString((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
krebyy 1:3a73d77c2cef 207 }
krebyy 1:3a73d77c2cef 208 return USBD_StrDesc;
krebyy 1:3a73d77c2cef 209 }
krebyy 1:3a73d77c2cef 210
krebyy 1:3a73d77c2cef 211 /**
krebyy 1:3a73d77c2cef 212 * @brief Returns the interface string descriptor.
krebyy 1:3a73d77c2cef 213 * @param speed: Current device speed
krebyy 1:3a73d77c2cef 214 * @param length: Pointer to data length variable
krebyy 1:3a73d77c2cef 215 * @retval Pointer to descriptor buffer
krebyy 1:3a73d77c2cef 216 */
krebyy 1:3a73d77c2cef 217 uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
krebyy 1:3a73d77c2cef 218 {
krebyy 1:3a73d77c2cef 219 if(speed == 0)
krebyy 1:3a73d77c2cef 220 {
krebyy 1:3a73d77c2cef 221 USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
krebyy 1:3a73d77c2cef 222 }
krebyy 1:3a73d77c2cef 223 else
krebyy 1:3a73d77c2cef 224 {
krebyy 1:3a73d77c2cef 225 USBD_GetString((uint8_t *)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
krebyy 1:3a73d77c2cef 226 }
krebyy 1:3a73d77c2cef 227 return USBD_StrDesc;
krebyy 1:3a73d77c2cef 228 }
krebyy 1:3a73d77c2cef 229
krebyy 1:3a73d77c2cef 230 /**
krebyy 1:3a73d77c2cef 231 * @brief Create the serial number string descriptor
krebyy 1:3a73d77c2cef 232 * @param None
krebyy 1:3a73d77c2cef 233 * @retval None
krebyy 1:3a73d77c2cef 234 */
krebyy 1:3a73d77c2cef 235 static void Get_SerialNum(void)
krebyy 1:3a73d77c2cef 236 {
krebyy 1:3a73d77c2cef 237 uint32_t deviceserial0, deviceserial1, deviceserial2;
krebyy 1:3a73d77c2cef 238
krebyy 1:3a73d77c2cef 239 deviceserial0 = *(uint32_t*)DEVICE_ID1;
krebyy 1:3a73d77c2cef 240 deviceserial1 = *(uint32_t*)DEVICE_ID2;
krebyy 1:3a73d77c2cef 241 deviceserial2 = *(uint32_t*)DEVICE_ID3;
krebyy 1:3a73d77c2cef 242
krebyy 1:3a73d77c2cef 243 deviceserial0 += deviceserial2;
krebyy 1:3a73d77c2cef 244
krebyy 1:3a73d77c2cef 245 if (deviceserial0 != 0)
krebyy 1:3a73d77c2cef 246 {
krebyy 1:3a73d77c2cef 247 IntToUnicode (deviceserial0, &USBD_StringSerial[2] ,8);
krebyy 1:3a73d77c2cef 248 IntToUnicode (deviceserial1, &USBD_StringSerial[18] ,4);
krebyy 1:3a73d77c2cef 249 }
krebyy 1:3a73d77c2cef 250 }
krebyy 1:3a73d77c2cef 251
krebyy 1:3a73d77c2cef 252 /**
krebyy 1:3a73d77c2cef 253 * @brief Convert Hex 32Bits value into char
krebyy 1:3a73d77c2cef 254 * @param value: value to convert
krebyy 1:3a73d77c2cef 255 * @param pbuf: pointer to the buffer
krebyy 1:3a73d77c2cef 256 * @param len: buffer length
krebyy 1:3a73d77c2cef 257 * @retval None
krebyy 1:3a73d77c2cef 258 */
krebyy 1:3a73d77c2cef 259 static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len)
krebyy 1:3a73d77c2cef 260 {
krebyy 1:3a73d77c2cef 261 uint8_t idx = 0;
krebyy 1:3a73d77c2cef 262
krebyy 1:3a73d77c2cef 263 for( idx = 0; idx < len; idx ++)
krebyy 1:3a73d77c2cef 264 {
krebyy 1:3a73d77c2cef 265 if( ((value >> 28)) < 0xA )
krebyy 1:3a73d77c2cef 266 {
krebyy 1:3a73d77c2cef 267 pbuf[ 2* idx] = (value >> 28) + '0';
krebyy 1:3a73d77c2cef 268 }
krebyy 1:3a73d77c2cef 269 else
krebyy 1:3a73d77c2cef 270 {
krebyy 1:3a73d77c2cef 271 pbuf[2* idx] = (value >> 28) + 'A' - 10;
krebyy 1:3a73d77c2cef 272 }
krebyy 1:3a73d77c2cef 273
krebyy 1:3a73d77c2cef 274 value = value << 4;
krebyy 1:3a73d77c2cef 275
krebyy 1:3a73d77c2cef 276 pbuf[ 2* idx + 1] = 0;
krebyy 1:3a73d77c2cef 277 }
krebyy 1:3a73d77c2cef 278 }
krebyy 1:3a73d77c2cef 279 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/