usbd_desc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. #include "usbd_core.h"
  2. #include "usbd_desc.h"
  3. #include "usbd_conf.h"
  4. #include "usb_config.h"
  5. #include "app/nfm/nfm_base.h"
  6. #if USBD_GETDESCRIPTORS_ALTMETHOD == 1
  7. // THIS FILE CONTAINS DEFAULT DESCRIPTORS ACCESSORS
  8. // AND THE DEFAULT DESCRIPTORS CONTENT.
  9. // IF YOU NEED TO OVERRIDE SOME DESCRIPTOR VALUE IN THE CLASS
  10. // YOU NEED TO DEFINE CLASS-DEFINED GETDESCRIPTORS HANDLERS SET,
  11. // a.k.a. USBD_DescriptorsTypeDef, AND PUT
  12. // THE "USBD_GETDESCRIPTOR_DEFAULT_HANDLERS_SET" MACRO INSIDE
  13. // TO INITIALIZE THE STRUCTURE WITH THE DEFAULT ACCESSORS (HANDLERS).
  14. // THEN YOU NEED TO RE-DEFINE THE ONLY ACCESSOR(S) YOU NEED TO OVERRIDE
  15. // IN THE SAME INITIALIZER. SEE "USBD_GETDESCRIPTOR_DEFAULT_HANDLERS_SET"
  16. // FOR DETAILS.
  17. #else
  18. // THIS FILE CONTAINS DEFAULT DESCRIPTORS ACCESSORS
  19. // AND THE DEFAULT DESCRIPTORS CONTENT.
  20. // IF YOU NEED TO OVERRIDE SOME DESCRIPTOR VALUE IN THE CLASS
  21. // YOU NEED TO DEFINE CLASS-DEFINED GETDESCRIPTORS HANDLERS SET,
  22. // a.k.a. USBD_DescriptorsTypeDef, AND INITIALIZE THE STRUCTURE
  23. // WITH ACCESSOR(S) YOU NEED TO OVERRIDE IN THE SAME INITIALIZER.
  24. // ALL THE OTHER ACCESSORS VALUES MUST BE NULL.
  25. #endif
  26. #define USBD_VID USB_VID
  27. #define USBD_LANGID_STRING 1033
  28. #define USBD_PID USB_PID_VENDOR
  29. #if defined(CMT)
  30. //static const uint8_t USBD_MANUFACTURER_STRING[] = { 122, USB_DESC_TYPE_STRING,
  31. // 'C', 0, 'o', 0, 'p', 0, 'p', 0, 'e', 0, 'r', 0, ' ', 0, 'M', 0, 'o', 0, 'u', 0, 'n', 0, 't', 0, 'a', 0, 'i', 0, 'n', 0, ' ', 0, 'T', 0, 'e', 0, 'c', 0, 'h', 0, 'n', 0, 'o', 0, 'l', 0, 'o', 0, 'g', 0, 'i', 0, 'e', 0, 's', 0, ' ', 0, '(', 0, 'h', 0, 't', 0, 't', 0, 'p', 0, ':', 0, '/', 0, '/', 0, 'c', 0, 'o', 0, 'p', 0, 'p', 0, 'e', 0, 'r', 0, 'm', 0, 'o', 0, 'u', 0, 'n', 0, 't', 0, 'a', 0, 'i', 0, 'n', 0, 't', 0, 'e', 0, 'c', 0, 'h', 0, '.', 0, 'c', 0, 'o', 0, 'm', 0, ')', 0,
  32. //};
  33. static const uint8_t USBD_MANUFACTURER_STRING[] = { 8, USB_DESC_TYPE_STRING,
  34. 'C', 0, 'M', 0, 'T', 0,
  35. };
  36. #elif defined(PLANAR)
  37. static const uint8_t USBD_MANUFACTURER_STRING[] = { 68, USB_DESC_TYPE_STRING,
  38. 'P', 0,'l', 0,'a', 0,'n', 0,'a', 0,'r', 0,' ', 0,'(', 0,'h', 0,'t', 0, 't', 0,'p', 0,':', 0,'/', 0,'/', 0,'w', 0,'w', 0,'w', 0,'.', 0,'p', 0,'l', 0, 'a', 0, 'n', 0, 'a', 0, 'r', 0, 'c', 0, 'h', 0, 'e', 0, 'l', 0, '.', 0, 'r', 0, 'u', 0, ')', 0,
  39. };
  40. #else
  41. #error Specify PLANAR or CMT macro in project settings!
  42. #endif
  43. static const uint8_t USBD_PRODUCT_STRING_FS[] = { 38, USB_DESC_TYPE_STRING,
  44. 'M', 0,'K', 0,'2', 0,'0', 0,'7', 0,'-', 0,'0', 0, '4', 0, 'H', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0,' ', 0,' ', 0,' ', 0,' ', 0,' ', 0,
  45. };
  46. #if CONFIG_NFMBASECLASS
  47. #else
  48. static const uint8_t USBD_SERIALNUMBER_STRING_FS[] = { 26, USB_DESC_TYPE_STRING,
  49. '0',0,'0',0,'0',0,'0',0,'0',0,'0',0,'0',0,'0',0,'0',0,'0',0,'0',0,'0',0,
  50. };
  51. #endif
  52. static const uint8_t USBD_CONFIGURATION_STRING_FS[] = { 22, USB_DESC_TYPE_STRING,
  53. 'M',0,'a',0,'i',0,'n',0,'C',0,'o',0,'n',0,'f',0,'i',0,'g',0,
  54. };
  55. static const uint8_t USBD_INTERFACE_STRING_FS[] = { 24, USB_DESC_TYPE_STRING,
  56. 'V',0,'e',0,'n',0,'d',0,'o',0,'r',0,'I',0,'f',0,'a',0,'c',0,'e',0,
  57. };
  58. static const uint8_t USBD_MSOS_STRING_FS[] = { 24, USB_DESC_TYPE_STRING,
  59. 'V',0,'e',0,'n',0,'d',0,'o',0,'r',0,'I',0,'f',0,'a',0,'c',0,'e',0,
  60. };
  61. #if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  62. static const uint8_t * USBD_COMMON_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  63. static const uint8_t * USBD_COMMON_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  64. static const uint8_t * USBD_COMMON_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  65. static const uint8_t * USBD_COMMON_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  66. static const uint8_t * USBD_COMMON_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  67. static const uint8_t * USBD_COMMON_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  68. static const uint8_t * USBD_COMMON_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  69. static const uint8_t * USBD_COMMON_GetCfgDesc (USBD_SpeedTypeDef speed, uint16_t *length);
  70. //static const uint8_t * USBD_COMMON_GetMsOsStringDescriptor (USBD_SpeedTypeDef speed, uint16_t *length);
  71. //static const uint8_t * USBD_COMMON_GetExtCompatIdOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t * length);
  72. //static const uint8_t * USBD_COMMON_GetExtPropertiesOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t * length);
  73. #endif
  74. USBD_DescriptorsTypeDef USBD_COMMON_Desc =
  75. {
  76. .GetDeviceDescriptor = USBD_COMMON_DeviceDescriptor,
  77. .GetLangIDStrDescriptor = USBD_COMMON_LangIDStrDescriptor,
  78. .GetManufacturerStrDescriptor = USBD_COMMON_ManufacturerStrDescriptor,
  79. .GetProductStrDescriptor = USBD_COMMON_ProductStrDescriptor,
  80. .GetSerialStrDescriptor = USBD_COMMON_SerialStrDescriptor,
  81. .GetConfigurationStrDescriptor = USBD_COMMON_ConfigStrDescriptor,
  82. .GetInterfaceStrDescriptor = USBD_COMMON_InterfaceStrDescriptor,
  83. .GetConfigDescriptor = USBD_COMMON_GetCfgDesc,
  84. //.GetMsOsStringDescriptor = USBD_COMMON_GetMsOsStringDescriptor,
  85. //.GetExtCompatIdOsFeatureDescriptor = USBD_COMMON_GetExtCompatIdOsFeatureDescriptor,
  86. //.GetExtPropertiesOsFeatureDescriptor = USBD_COMMON_GetExtPropertiesOsFeatureDescriptor,
  87. #if (USBD_SUPPORT_USER_STRING)
  88. .GetUsrStrDescriptor = NULL,
  89. #endif
  90. };
  91. #if defined ( __ICCARM__ ) /* IAR Compiler */
  92. #pragma data_alignment=4
  93. #endif /* defined ( __ICCARM__ ) */
  94. /** USB standard device descriptor. */
  95. static __ALIGN_BEGIN const uint8_t USBD_COMMON_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
  96. {
  97. USB_LEN_DEV_DESC, /*bLength */
  98. USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
  99. LOBYTE(0x0200), /*bcdUSB */
  100. HIBYTE(0x0200), /*bcdUSB */
  101. 0x02, /*bDeviceClass*/
  102. 0x02, /*bDeviceSubClass*/
  103. 0x00, /*bDeviceProtocol*/
  104. USB_MAX_EP0_SIZE, /*bMaxPacketSize*/
  105. LOBYTE(USBD_VID), /*idVendor*/
  106. HIBYTE(USBD_VID), /*idVendor*/
  107. LOBYTE(USBD_PID), /*idProduct*/
  108. HIBYTE(USBD_PID), /*idProduct*/
  109. LOBYTE(0x0200), /*bcdDevice rel. 2.00*/
  110. HIBYTE(0x0200),
  111. USBD_IDX_MFC_STR, /*Index of manufacturer string*/
  112. USBD_IDX_PRODUCT_STR, /*Index of product string*/
  113. USBD_IDX_SERIAL_STR, /*Index of serial number string*/
  114. USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
  115. };
  116. #define USB_CONFIG_DESC_SIZ 18
  117. /* USB Vendor device Configuration Descriptor */
  118. static __ALIGN_BEGIN const uint8_t USBD_COMMON_CfgDesc[USB_CONFIG_DESC_SIZ] __ALIGN_END =
  119. {
  120. /*Configuration Descriptor*/
  121. 0x09, /* bLength: Configuration Descriptor size */
  122. USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
  123. USB_CONFIG_DESC_SIZ, /* wTotalLength: # of returned bytes */
  124. 0x00,
  125. 0x01, /* bNumInterfaces: 1 interface */
  126. 0x01, /* bConfigurationValue: Configuration value */
  127. 0x00, /* iConfiguration: Index of string descriptor describing the configuration */
  128. 0x80, /* bmAttributes: no options */
  129. 0xFF, /* MaxPower 0 mA */ //0x32
  130. /*---------------------------------------------------------------------------*/
  131. /*Data class interface descriptor*/
  132. 0x09, /* bLength: Endpoint Descriptor size */
  133. USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
  134. 0x00, /* bInterfaceNumber: Number of Interface */
  135. 0x00, /* bAlternateSetting: Alternate setting */
  136. 0x00, /* bNumEndpoints: No endpoints used */
  137. 0x00, /* bInterfaceClass: */
  138. 0x00, /* bInterfaceSubClass: */
  139. 0x00, /* bInterfaceProtocol: */
  140. 0x00, /* iInterface: */
  141. };
  142. //#define USB_MICROSOFT_OS_STRING_DECRIPTOR_SIZ 18
  143. //
  144. ///* USB Vendor device Configuration Descriptor */
  145. //static __ALIGN_BEGIN const uint8_t USBD_COMMON_MSOSDESCR[USB_MICROSOFT_OS_STRING_DECRIPTOR_SIZ] __ALIGN_END =
  146. //{
  147. // /*Configuration Descriptor*/
  148. // 0x12, /* bLength: Configuration Descriptor size */
  149. // USB_DESC_TYPE_STRING, /* bDescriptorType: Configuration */
  150. // 0x4D, 0x00, 0x53, /* Signature: 'MSFT100' UNICODE STRING (LE)*/
  151. // 0x00, 0x46, 0x00,
  152. // 0x54, 0x00, 0x31,
  153. // 0x00, 0x30, 0x00,
  154. // 0x30, 0x00,
  155. // USBD_MSOS_VENDOR, /* Vendor Code: */
  156. // 0x00, /* Padding: */
  157. //};
  158. //
  159. //#define USB_MICROSOFT_OS_COMP_DECRIPTOR_SIZ 40
  160. ///* USB Vendor device Configuration Descriptor */
  161. //static __ALIGN_BEGIN const uint8_t USBD_COMMON_MSCOMPATIBLEDESCR[USB_MICROSOFT_OS_COMP_DECRIPTOR_SIZ] __ALIGN_END =
  162. //{
  163. // /*Configuration Descriptor*/
  164. // 0x28, 0x00, 0x00, 0x00, /* bLength: Descriptor length (40 bytes) */
  165. // 0x00, 0x01, /* Version ('1.0') */
  166. // 0x04, 0x00, /* Compatible ID Descriptor index (0x0004)*/
  167. // 0x01, /* Number of sections (1) */
  168. // 0x00, 0x00, 0x00, 0x00, /* Reserved */
  169. // 0x00, 0x00, 0x00,
  170. // 0x00, /* Interface Number (Interface #0) */
  171. // 0x01, /* Reserved */
  172. // 'W', 'I', 'N', 'U', /* Compatible ID ("WINUSB\0\0") */
  173. // 'S', 'B', 0x00, 0x00,
  174. // 0x00, 0x00, 0x00, 0x00, /* Sub-Compatible Id (unused) */
  175. // 0x00, 0x00, 0x00, 0x00,
  176. // 0x00, 0x00, 0x00, 0x00, /* Reserved */
  177. // 0x00, 0x00,
  178. //};
  179. //
  180. //#define USB_MICROSOFT_EXT_PROP_SIZ 142
  181. ///* USB Vendor device Configuration Descriptor */
  182. //static __ALIGN_BEGIN const uint8_t USBD_COMMON_EXTPROPDESCR[USB_MICROSOFT_EXT_PROP_SIZ] __ALIGN_END =
  183. //{
  184. // /*Extended properties Descriptor Header*/
  185. // 0x8E, 0x00, 0x00, 0x00, /* bLength: Descriptor length (142 bytes) */
  186. // 0x00, 0x01, /* Version ('1.0') */
  187. // 0x05, 0x00, /* Extended property descriptor index*/
  188. // 0x01, 0x00, /* Number of sections (1) */
  189. // /* Custom Property section 1 */
  190. // 0x84, 0x00, 0x00, 0x00, /* Size of the property section (132 bytes) */
  191. // 0x01, 0x00, 0x00, 0x00, /* Property data type (1 - UNICODE) */
  192. // 0x28, 0x00, /* Property name length (40 bytes) */
  193. // 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, /* 'DeviceIntefaceGUID'*/
  194. // 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, 'r', 0x00, 'f', 0x00,
  195. // 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00,
  196. // 'D', 0x00, 0x00, 0x00,
  197. // 0x4E, 0x00, 0x00, 0x00, /* Property Name {78cdcb7a-6971-4210-997c-5b8ea05e1715} */
  198. // '{', 0x00, '7', 0x00, '8', 0x00, 'C', 0x00, 'D', 0x00, 'C', 0x00, 'B', 0x00, '7', 0x00, 'A', 0x00, '-', 0x00,
  199. // '6', 0x00, '9', 0x00, '7', 0x00, '1', 0x00, '-', 0x00,
  200. // '4', 0x00, '2', 0x00, '1', 0x00, '0', 0x00, '-', 0x00,
  201. // '9', 0x00, '9', 0x00, '7', 0x00, 'C', 0x00, '-', 0x00,
  202. // '5', 0x00, 'B', 0x00, '8', 0x00, 'E', 0x00, 'A', 0x00, '0', 0x00, '5', 0x00, 'E', 0x00, '1', 0x00, '7', 0x00, '1', 0x00, '5', 0x00, '}', 0x00, 0x00, 0x00,
  203. //};
  204. #if defined ( __ICCARM__ ) /* IAR Compiler */
  205. #pragma data_alignment=4
  206. #endif /* defined ( __ICCARM__ ) */
  207. /** USB lang indentifier descriptor. */
  208. static __ALIGN_BEGIN const uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
  209. {
  210. USB_LEN_LANGID_STR_DESC,
  211. USB_DESC_TYPE_STRING,
  212. LOBYTE(USBD_LANGID_STRING),
  213. HIBYTE(USBD_LANGID_STRING)
  214. };
  215. /**
  216. * @brief Return the device descriptor
  217. * @param speed : Current device speed
  218. * @param length : Pointer to data length variable
  219. * @retval Pointer to descriptor buffer
  220. */
  221. #if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  222. static const uint8_t * USBD_COMMON_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  223. #else
  224. const uint8_t * USBD_COMMON_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  225. #endif
  226. {
  227. *length = sizeof(USBD_COMMON_DeviceDesc);
  228. return USBD_COMMON_DeviceDesc;
  229. }
  230. /**
  231. * @brief USBD_VENDOR_GetCfgDesc
  232. * Return configuration descriptor
  233. * @param speed : current device speed
  234. * @param length : pointer data length
  235. * @retval pointer to descriptor buffer
  236. */
  237. #if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  238. static const uint8_t * USBD_COMMON_GetCfgDesc (USBD_SpeedTypeDef speed, uint16_t *length)
  239. #else
  240. const uint8_t * USBD_COMMON_GetCfgDesc (USBD_SpeedTypeDef speed, uint16_t *length)
  241. #endif
  242. {
  243. *length = sizeof (USBD_COMMON_CfgDesc);
  244. return USBD_COMMON_CfgDesc;
  245. }
  246. /**
  247. * @brief Return the LangID string descriptor
  248. * @param speed : Current device speed
  249. * @param length : Pointer to data length variable
  250. * @retval Pointer to descriptor buffer
  251. */
  252. #if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  253. static const uint8_t * USBD_COMMON_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  254. #else
  255. const uint8_t * USBD_COMMON_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  256. #endif
  257. {
  258. *length = sizeof(USBD_LangIDDesc);
  259. return USBD_LangIDDesc;
  260. }
  261. /**
  262. * @brief Return the product string descriptor
  263. * @param speed : Current device speed
  264. * @param length : Pointer to data length variable
  265. * @retval Pointer to descriptor buffer
  266. */
  267. #if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  268. static const uint8_t * USBD_COMMON_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  269. #else
  270. const uint8_t * USBD_COMMON_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  271. #endif
  272. {
  273. *length = sizeof(USBD_PRODUCT_STRING_FS);
  274. return USBD_PRODUCT_STRING_FS;
  275. }
  276. /**
  277. * @brief Return the manufacturer string descriptor
  278. * @param speed : Current device speed
  279. * @param length : Pointer to data length variable
  280. * @retval Pointer to descriptor buffer
  281. */
  282. #if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  283. static const uint8_t * USBD_COMMON_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  284. #else
  285. const uint8_t * USBD_COMMON_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  286. #endif
  287. {
  288. *length = sizeof(USBD_MANUFACTURER_STRING);
  289. return USBD_MANUFACTURER_STRING;
  290. }
  291. /**
  292. * @brief Return the configuration string descriptor
  293. * @param speed : Current device speed
  294. * @param length : Pointer to data length variable
  295. * @retval Pointer to descriptor buffer
  296. */
  297. #if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  298. static const uint8_t * USBD_COMMON_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  299. #else
  300. const uint8_t * USBD_COMMON_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  301. #endif
  302. {
  303. *length = sizeof(USBD_CONFIGURATION_STRING_FS);
  304. return USBD_CONFIGURATION_STRING_FS;
  305. }
  306. /**
  307. * @brief Return the interface string descriptor
  308. * @param speed : Current device speed
  309. * @param length : Pointer to data length variable
  310. * @retval Pointer to descriptor buffer
  311. */
  312. #if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  313. static const uint8_t * USBD_COMMON_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  314. #else
  315. const uint8_t * USBD_COMMON_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  316. #endif
  317. {
  318. *length = sizeof(USBD_INTERFACE_STRING_FS);
  319. return USBD_INTERFACE_STRING_FS;
  320. }
  321. //#if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  322. //static const uint8_t * USBD_COMMON_GetMsOsStringDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  323. //#else
  324. //const uint8_t * USBD_COMMON_GetMsOsStringDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  325. //#endif
  326. //{
  327. // eNFMUSBInterface_t usbDeviceInterface;
  328. // NFMClass->methods.usbInterface.getInterface(&usbDeviceInterface);
  329. // if(usbDeviceInterface == eNFM_IfaceUSBTMC)
  330. // {
  331. // *length = 0;
  332. // return 0;
  333. // }
  334. // *length = sizeof(USBD_COMMON_MSOSDESCR);
  335. // return USBD_COMMON_MSOSDESCR;
  336. //}
  337. //
  338. //#if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  339. //static const uint8_t * USBD_COMMON_GetExtCompatIdOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  340. //#else
  341. //const uint8_t * USBD_COMMON_GetExtCompatIdOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  342. //#endif
  343. //{
  344. // eNFMUSBInterface_t usbDeviceInterface;
  345. // NFMClass->methods.usbInterface.getInterface(&usbDeviceInterface);
  346. // if(usbDeviceInterface == eNFM_IfaceUSBTMC)
  347. // {
  348. // *length = 0;
  349. // return 0;
  350. // }
  351. // *length = sizeof(USBD_COMMON_MSCOMPATIBLEDESCR);
  352. // return USBD_COMMON_MSCOMPATIBLEDESCR;
  353. //}
  354. //
  355. //#if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  356. //static const uint8_t * USBD_COMMON_GetExtPropertiesOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  357. //#else
  358. //const uint8_t * USBD_COMMON_GetExtPropertiesOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  359. //#endif
  360. //{
  361. // eNFMUSBInterface_t usbDeviceInterface;
  362. // NFMClass->methods.usbInterface.getInterface(&usbDeviceInterface);
  363. // if(usbDeviceInterface == eNFM_IfaceUSBTMC)
  364. // {
  365. // *length = 0;
  366. // return 0;
  367. // }
  368. // *length = sizeof(USBD_COMMON_EXTPROPDESCR);
  369. // return USBD_COMMON_EXTPROPDESCR;
  370. //}
  371. // Dynamic Serial Number Descriptor is implemented.
  372. //
  373. #define MAX_USB_SERIAL_NUMBER_LEN 10
  374. #pragma pack( push, 1 )
  375. static union
  376. {
  377. struct
  378. {
  379. uint8_t bLength;
  380. uint8_t bType;
  381. uint8_t aSerial[ (MAX_USB_SERIAL_NUMBER_LEN) * 2 ];
  382. };
  383. uint8_t raw[1];
  384. }
  385. sUSBSerialNumberDescriptor;
  386. #pragma pack(pop)
  387. #if CONFIG_NFMBASECLASS
  388. /**
  389. * @brief Return the serial number string descriptor
  390. * @param speed : Current device speed
  391. * @param length : Pointer to data length variable
  392. * @retval Pointer to descriptor buffer
  393. */
  394. const uint8_t * USBD_COMMON_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  395. {
  396. uint8_t * pDest = sUSBSerialNumberDescriptor.aSerial;
  397. const char * pSrc = NFMClass->properties.serialNumber;
  398. size_t n = strlen( pSrc );
  399. if( n * 2 > sizeof( sUSBSerialNumberDescriptor.aSerial) )
  400. {
  401. n = sizeof( sUSBSerialNumberDescriptor.aSerial) / 2;
  402. }
  403. sUSBSerialNumberDescriptor.bType = USB_DESC_TYPE_STRING;
  404. sUSBSerialNumberDescriptor.bLength = *length = sizeof(sUSBSerialNumberDescriptor.bLength)
  405. + sizeof(sUSBSerialNumberDescriptor.bType)
  406. + 2 * n;
  407. while( n > 0 )
  408. {
  409. n--;
  410. *pDest = *pSrc;
  411. pSrc++; pDest++;
  412. *pDest = '\0';
  413. pDest++;
  414. }
  415. return sUSBSerialNumberDescriptor.raw;
  416. }
  417. #else
  418. #if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  419. static const uint8_t * USBD_COMMON_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  420. #else
  421. const uint8_t * USBD_COMMON_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  422. #endif
  423. {
  424. *length = sizeof(USBD_SERIALNUMBER_STRING_FS);
  425. return USBD_SERIALNUMBER_STRING_FS;
  426. }
  427. #endif