usbd_usbtmc_desc.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. #include "usbd_usbtmc_desc.h"
  2. #include "usbd_usbtmc.h"
  3. #include "usbd_desc.h"
  4. #include "usbd_ctlreq.h"
  5. static const uint8_t * USBD_USBTMC_GetDeviceDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  6. //static const uint8_t * USBD_USBTMC_GetLangIDStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  7. static const uint8_t * USBD_USBTMC_GetManufacturerStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  8. static const uint8_t * USBD_USBTMC_GetProductStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  9. static const uint8_t * USBD_USBTMC_GetSerialStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  10. static const uint8_t * USBD_USBTMC_GetConfigurationStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  11. static const uint8_t * USBD_USBTMC_GetInterfaceStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  12. static const uint8_t * USBD_USBTMC_GetCfgDesc( USBD_SpeedTypeDef speed ,uint16_t *length );
  13. static const uint8_t * USBD_USBTMC_GetMsOsStringDescriptor (USBD_SpeedTypeDef speed, uint16_t *length);
  14. static const uint8_t * USBD_USBTMC_GetExtCompatIdOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t * length);
  15. static const uint8_t * USBD_USBTMC_GetExtPropertiesOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t * length);
  16. #define USBD_USBTMC_LANGID_STRING 1033
  17. const USBD_DescriptorsTypeDef USBD_USBTMC_DescriptorHandlers = {
  18. #if USBD_GETDESCRIPTORS_ALTMETHOD == 1
  19. // default handlers
  20. USBD_GETDESCRIPTOR_DEFAULT_HANDLERS_SET,
  21. #endif
  22. // overrided handlers:
  23. .GetDeviceDescriptor = USBD_USBTMC_GetDeviceDescriptor,
  24. //.GetLangIDStrDescriptor = USBD_USBTMC_GetLangIDStrDescriptor,
  25. .GetManufacturerStrDescriptor = USBD_USBTMC_GetManufacturerStrDescriptor,
  26. .GetProductStrDescriptor = USBD_USBTMC_GetProductStrDescriptor,
  27. // .GetSerialStrDescriptor = USBD_USBTMC_GetSerialStrDescriptor,
  28. .GetConfigurationStrDescriptor = USBD_USBTMC_GetConfigurationStrDescriptor,
  29. .GetInterfaceStrDescriptor = USBD_USBTMC_GetInterfaceStrDescriptor,
  30. .GetConfigDescriptor = USBD_USBTMC_GetCfgDesc,
  31. .GetMsOsStringDescriptor = USBD_USBTMC_GetMsOsStringDescriptor,
  32. .GetExtCompatIdOsFeatureDescriptor = USBD_USBTMC_GetExtCompatIdOsFeatureDescriptor,
  33. .GetExtPropertiesOsFeatureDescriptor = USBD_USBTMC_GetExtPropertiesOsFeatureDescriptor,
  34. };
  35. #if defined ( __ICCARM__ ) /* IAR Compiler */
  36. #pragma data_alignment=4
  37. #endif /* defined ( __ICCARM__ ) */
  38. /** USB standard device descriptor. */
  39. static __ALIGN_BEGIN const uint8_t USBD_USBTMC_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
  40. {
  41. USB_LEN_DEV_DESC, /*bLength */
  42. USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
  43. LOBYTE(0x0200), /*bcdUSB */
  44. HIBYTE(0x0200), /*bcdUSB */
  45. 0x00, /*bDeviceClass*/ // 0x02,
  46. 0x00, /*bDeviceSubClass*/ // 0x02,
  47. 0x00, /*bDeviceProtocol*/ // 0x00,
  48. USB_MAX_EP0_SIZE, /*bMaxPacketSize*/
  49. LOBYTE(USB_VID), /*idVendor*/
  50. HIBYTE(USB_VID), /*idVendor*/
  51. LOBYTE(USB_PID_USBTMC), /*idProduct*/
  52. HIBYTE(USB_PID_USBTMC), /*idProduct*/
  53. LOBYTE(0x0200), /*bcdDevice rel. 2.00*/
  54. HIBYTE(0x0200),
  55. USBD_IDX_MFC_STR, /*Index of manufacturer string*/
  56. USBD_IDX_PRODUCT_STR, /*Index of product string*/
  57. USBD_IDX_SERIAL_STR, /*Index of serial number string*/
  58. USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
  59. };
  60. /**
  61. * @brief Return the device descriptor
  62. * @param speed : Current device speed
  63. * @param length : Pointer to data length variable
  64. * @retval Pointer to descriptor buffer
  65. */
  66. static const uint8_t * USBD_USBTMC_GetDeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  67. {
  68. *length = sizeof(USBD_USBTMC_DeviceDesc);
  69. return USBD_USBTMC_DeviceDesc;
  70. }
  71. #define USB_USBTMC_CONFIG_DESC_SIZ 39
  72. /* USBTMC device Configuration Descriptor */
  73. static __ALIGN_BEGIN const uint8_t USBD_USBTMC_CfgDesc[USB_USBTMC_CONFIG_DESC_SIZ] __ALIGN_END =
  74. {
  75. /* CONFIGURATION */
  76. /*Configuration Descriptor*/
  77. 0x09, /* bLength: Configuration Descriptor size */
  78. USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
  79. USB_USBTMC_CONFIG_DESC_SIZ, /* wTotalLength: # of returned bytes */
  80. 0x00,
  81. 0x01, /* bNumInterfaces: 1 interface */
  82. 0x01, /* bConfigurationValue: Configuration value */
  83. USBD_IDX_CONFIG_STR, /* iConfiguration: Index of string descriptor describing the configuration */
  84. 0x80, /* bmAttributes: no options */
  85. 0x32, /* MaxPower 0 mA */
  86. /*---------------------------------------------------------------------------*/
  87. /* INTERFACE */
  88. /*Data class interface descriptor*/
  89. 0x09, /* bLength: Interface Descriptor size */
  90. USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
  91. 0x00, /* bInterfaceNumber: Number of Interface */
  92. 0x00, /* bAlternateSetting: Alternate setting */
  93. 0x03, /* bNumEndpoints: BulkIn+BulkOut+IntIn */
  94. 0xFE, /* bInterfaceClass: 0xFE; USBTMC spec. rev 1.0, 2003, p. 33, 5.5 Interface Descriptor */
  95. 0x03, /* bInterfaceSubClass: 0x03; USBTMC spec. rev 1.0, 2003, p. 33, 5.5 Interface Descriptor */
  96. 0x01, /* bInterfaceProtocol: 0x01; USBTMC spec. rev 1.0, 2003, p. 33, 5.5 Interface Descriptor */
  97. USBD_IDX_INTERFACE_STR, /* iInterface: */
  98. /*---------------------------------------------------------------------------*/
  99. /* BULKOUT Endpoint */
  100. 0x07, /* bLength: Endpoint Descriptor size */
  101. USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
  102. USBTMC_BULKOUT_EP, /* bEndpointAddress */
  103. 0x02, /* bmAttributes: Bulk */
  104. LOBYTE( USBTMC_DATAOUT_MAX_PACKET_SIZE), /* wMaxPacketSize, Low byte */
  105. HIBYTE( USBTMC_DATAOUT_MAX_PACKET_SIZE), /* wMaxPacketSize, High byte */
  106. 0x00, /* bInterval */
  107. /*---------------------------------------------------------------------------*/
  108. /* BULKIN Endpoint */
  109. 0x07, /* bLength: Endpoint Descriptor size */
  110. USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
  111. USBTMC_BULKIN_EP, /* bEndpointAddress */
  112. 0x02, /* bmAttributes: Bulk */
  113. LOBYTE( USBTMC_DATAIN_MAX_PACKET_SIZE), /* wMaxPacketSize, Low byte */
  114. HIBYTE( USBTMC_DATAIN_MAX_PACKET_SIZE), /* wMaxPacketSize, High byte */
  115. 0x00, /* bInterval */
  116. /*---------------------------------------------------------------------------*/
  117. /* INTERRUPTIN Endpoint */
  118. 0x07, /* bLength: Endpoint Descriptor size */
  119. USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
  120. USBTMC_INTERRUPTIN_EP, /* bEndpointAddress */
  121. 0x03, /* bmAttributes: Interrupt */
  122. LOBYTE( USBTMC_INTIN_MAX_PACKET_SIZE), /* wMaxPacketSize, Low byte */
  123. HIBYTE( USBTMC_INTIN_MAX_PACKET_SIZE), /* wMaxPacketSize, High byte */
  124. 0x08, /* bInterval: VALUE = 2 ^ (bInterval-1); 1<=bInterval<=16, see USB 2.0 Spec, Table 9-13. Standard Endpoint Descriptor (Continued) */
  125. };
  126. /**
  127. * @brief USBD_USBTMC_GetCfgDesc
  128. * Return configuration descriptor
  129. * @param speed : current device speed
  130. * @param length : pointer data length
  131. * @retval pointer to descriptor buffer
  132. */
  133. static const uint8_t * USBD_USBTMC_GetCfgDesc(USBD_SpeedTypeDef speed, uint16_t *length)
  134. {
  135. *length = sizeof (USBD_USBTMC_CfgDesc);
  136. return USBD_USBTMC_CfgDesc;
  137. }
  138. /* USB Standard Device Qualifier Descriptor */
  139. static __ALIGN_BEGIN const uint8_t USBD_USBTMC_DevQual[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
  140. {
  141. USB_LEN_DEV_QUALIFIER_DESC,
  142. USB_DESC_TYPE_DEVICE_QUALIFIER,
  143. 0x00, // bcdUSB
  144. 0x02, // bcdUSB
  145. 0x00, // bDeviceClass
  146. 0x00, // bDeviceSubClass
  147. 0x00, // bDeviceProtocol
  148. USB_MAX_EP0_SIZE, // bMaxPacketSize0
  149. 0x01, // bNumConfigurations
  150. 0x00, // bReserved
  151. };
  152. #if defined ( __ICCARM__ ) /* IAR Compiler */
  153. #pragma data_alignment=4
  154. #endif /* defined ( __ICCARM__ ) */
  155. /** USB lang indentifier descriptor. */
  156. /*
  157. static __ALIGN_BEGIN const uint8_t USBD_USBTMC_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
  158. {
  159. USB_LEN_LANGID_STR_DESC,
  160. USB_DESC_TYPE_STRING,
  161. LOBYTE(USBD_USBTMC_LANGID_STRING),
  162. HIBYTE(USBD_USBTMC_LANGID_STRING)
  163. };
  164. */
  165. /**
  166. * @brief Return the LangID string descriptor
  167. * @param speed : Current device speed
  168. * @param length : Pointer to data length variable
  169. * @retval Pointer to descriptor buffer
  170. */
  171. /*
  172. static const uint8_t * USBD_USBTMC_GetLangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  173. {
  174. *length = sizeof(USBD_USBTMC_LangIDDesc);
  175. return USBD_USBTMC_LangIDDesc;
  176. }
  177. */
  178. #if defined(CMT)
  179. //static const uint8_t USBD_USBTMC_MANUFACTURER_STRING[] = { 122, USB_DESC_TYPE_STRING,
  180. // '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,
  181. //};
  182. static const uint8_t USBD_USBTMC_MANUFACTURER_STRING[] = { 8, USB_DESC_TYPE_STRING,
  183. 'C', 0, 'M', 0, 'T', 0,
  184. };
  185. #elif defined(PLANAR)
  186. static const uint8_t USBD_USBTMC_MANUFACTURER_STRING[] = { 68, USB_DESC_TYPE_STRING,
  187. '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,
  188. };
  189. #else
  190. #error Specify PLANAR or CMT macro in project settings!
  191. #endif
  192. /**
  193. * @brief Return the manufacturer string descriptor
  194. * @param speed : Current device speed
  195. * @param length : Pointer to data length variable
  196. * @retval Pointer to descriptor buffer
  197. */
  198. static const uint8_t * USBD_USBTMC_GetManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  199. {
  200. *length = sizeof(USBD_USBTMC_MANUFACTURER_STRING);
  201. return USBD_USBTMC_MANUFACTURER_STRING;
  202. }
  203. static const uint8_t USBD_USBTMC_PRODUCT_STRING[] = { 38, USB_DESC_TYPE_STRING,
  204. '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,
  205. };
  206. /**
  207. * @brief Return the product string descriptor
  208. * @param speed : Current device speed
  209. * @param length : Pointer to data length variable
  210. * @retval Pointer to descriptor buffer
  211. */
  212. static const uint8_t * USBD_USBTMC_GetProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  213. {
  214. *length = sizeof(USBD_USBTMC_PRODUCT_STRING);
  215. return USBD_USBTMC_PRODUCT_STRING;
  216. }
  217. #if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  218. static const uint8_t * USBD_USBTMC_GetMsOsStringDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  219. #else
  220. const uint8_t * USBD_USBTMC_GetMsOsStringDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  221. #endif
  222. {
  223. *length = 0;
  224. return 0;
  225. }
  226. #if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  227. static const uint8_t * USBD_USBTMC_GetExtCompatIdOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  228. #else
  229. const uint8_t * USBD_USBTMC_GetExtCompatIdOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  230. #endif
  231. {
  232. *length = 0;
  233. return 0;
  234. }
  235. #if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  236. static const uint8_t * USBD_USBTMC_GetExtPropertiesOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  237. #else
  238. const uint8_t * USBD_USBTMC_GetExtPropertiesOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  239. #endif
  240. {
  241. *length = 0;
  242. return 0;
  243. }
  244. // // Dynamic Serial Number Descriptor is implemented.
  245. // //
  246. // #define MAX_USB_SERIAL_NUMBER_LEN 8
  247. // #pragma pack( push, 1 )
  248. // static union
  249. // {
  250. // uint8_t raw[0];
  251. // struct
  252. // {
  253. // uint8_t bLength;
  254. // uint8_t bType;
  255. // uint8_t aSerial[ (MAX_USB_SERIAL_NUMBER_LEN) * 2 ];
  256. // };
  257. // }
  258. // sUSBSerialNumberDescriptor;
  259. // #pragma pack(pop)
  260. // /**
  261. // * @brief Return the serial number string descriptor
  262. // * @param speed : Current device speed
  263. // * @param length : Pointer to data length variable
  264. // * @retval Pointer to descriptor buffer
  265. // */
  266. // static const uint8_t * USBD_USBTMC_GetSerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  267. // {
  268. // uint8_t * pDest = sUSBSerialNumberDescriptor.aSerial;
  269. // const uint8_t * pSrc = ACMClass->properties.serialNumber;
  270. //
  271. // size_t n = strlen( pSrc );
  272. //
  273. // if( n * 2 > sizeof( sUSBSerialNumberDescriptor.aSerial) )
  274. // {
  275. // n = sizeof( sUSBSerialNumberDescriptor.aSerial) / 2;
  276. // }
  277. //
  278. // sUSBSerialNumberDescriptor.bType = USB_DESC_TYPE_STRING;
  279. // sUSBSerialNumberDescriptor.bLength = *length = sizeof(sUSBSerialNumberDescriptor.bLength)
  280. // + sizeof(sUSBSerialNumberDescriptor.bType)
  281. // + 2 * n;
  282. // while( n > 0 )
  283. // {
  284. // n--;
  285. // *pDest = *pSrc;
  286. // pSrc++; pDest++;
  287. // *pDest = '\0';
  288. // pDest++;
  289. // }
  290. //
  291. // return sUSBSerialNumberDescriptor.raw;
  292. // }
  293. static const uint8_t USBD_USBTMC_CONFIGURATION_STRING[] = { 94, USB_DESC_TYPE_STRING,
  294. 'U',0,'S',0,'B',0,'T',0,'M',0,'C',0,'-',0,'U',0,'S',0,'B',0,'4',0,'8',0,'8',0,' ',0,
  295. '(',0,'T',0,'e',0,'s',0,'t',0,' ',0,'a',0,'n',0,'d',0,' ',0,
  296. 'M',0,'e',0,'a',0,'s',0,'u',0,'r',0,'e',0,'m',0,'e',0,'n',0,'t',0,' ',0,
  297. 'I',0,'n',0,'t',0,'e',0,'r',0,'f',0,'a',0,'c',0,'e',0,')',0
  298. };
  299. /**
  300. * @brief Return the configuration string descriptor
  301. * @param speed : Current device speed
  302. * @param length : Pointer to data length variable
  303. * @retval Pointer to descriptor buffer
  304. */
  305. const uint8_t * USBD_USBTMC_GetConfigurationStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  306. {
  307. *length = sizeof(USBD_USBTMC_CONFIGURATION_STRING);
  308. return USBD_USBTMC_CONFIGURATION_STRING;
  309. }
  310. static const uint8_t USBD_USBTMC_INTERFACE_STRING[] = { 94, USB_DESC_TYPE_STRING,
  311. 'U',0,'S',0,'B',0,'T',0,'M',0,'C',0,'-',0,'U',0,'S',0,'B',0,'4',0,'8',0,'8',0,' ',0,
  312. '(',0,'T',0,'e',0,'s',0,'t',0,' ',0,'a',0,'n',0,'d',0,' ',0,
  313. 'M',0,'e',0,'a',0,'s',0,'u',0,'r',0,'e',0,'m',0,'e',0,'n',0,'t',0,' ',0,
  314. 'I',0,'n',0,'t',0,'e',0,'r',0,'f',0,'a',0,'c',0,'e',0,')',0
  315. };
  316. /**
  317. * @brief Return the interface string descriptor
  318. * @param speed : Current device speed
  319. * @param length : Pointer to data length variable
  320. * @retval Pointer to descriptor buffer
  321. */
  322. static const uint8_t * USBD_USBTMC_GetInterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  323. {
  324. *length = sizeof(USBD_USBTMC_INTERFACE_STRING);
  325. return USBD_USBTMC_INTERFACE_STRING;
  326. }