winusb1.0_template.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /*
  2. * Copyright (c) 2024, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "usbd_core.h"
  7. #define WINUSB_VENDOR_CODE 0x17
  8. #define WINUSB_NUM 1
  9. const uint8_t WCID_StringDescriptor_MSOS[18] = {
  10. USB_MSOSV1_STRING_DESCRIPTOR_INIT(WINUSB_VENDOR_CODE)
  11. };
  12. const uint8_t WINUSB_WCIDDescriptor[] = {
  13. USB_MSOSV1_COMP_ID_HEADER_DESCRIPTOR_INIT(WINUSB_NUM),
  14. USB_MSOSV1_COMP_ID_FUNCTION_WINUSB_DESCRIPTOR_INIT(0),
  15. #if WINUSB_NUM == 2
  16. USB_MSOSV1_COMP_ID_FUNCTION_WINUSB_DESCRIPTOR_INIT(1),
  17. #endif
  18. };
  19. const uint8_t WINUSB_IF0_WCIDProperties[142] = {
  20. ///////////////////////////////////////
  21. /// WCID property descriptor
  22. ///////////////////////////////////////
  23. 0x8e, 0x00, 0x00, 0x00, /* dwLength */
  24. 0x00, 0x01, /* bcdVersion */
  25. 0x05, 0x00, /* wIndex */
  26. 0x01, 0x00, /* wCount */
  27. ///////////////////////////////////////
  28. /// registry propter descriptor
  29. ///////////////////////////////////////
  30. 0x84, 0x00, 0x00, 0x00, /* dwSize */
  31. 0x01, 0x00, 0x00, 0x00, /* dwPropertyDataType */
  32. 0x28, 0x00, /* wPropertyNameLength */
  33. /* DeviceInterfaceGUID */
  34. 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, /* wcName_20 */
  35. 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, /* wcName_20 */
  36. 't', 0x00, 'e', 0x00, 'r', 0x00, 'f', 0x00, /* wcName_20 */
  37. 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, /* wcName_20 */
  38. 'U', 0x00, 'I', 0x00, 'D', 0x00, 0x00, 0x00, /* wcName_20 */
  39. 0x4e, 0x00, 0x00, 0x00, /* dwPropertyDataLength */
  40. /* {1D4B2365-4749-48EA-B38A-7C6FDDDD7E26} */
  41. '{', 0x00, '1', 0x00, 'D', 0x00, '4', 0x00, /* wcData_39 */
  42. 'B', 0x00, '2', 0x00, '3', 0x00, '6', 0x00, /* wcData_39 */
  43. '5', 0x00, '-', 0x00, '4', 0x00, '7', 0x00, /* wcData_39 */
  44. '4', 0x00, '9', 0x00, '-', 0x00, '4', 0x00, /* wcData_39 */
  45. '8', 0x00, 'E', 0x00, 'A', 0x00, '-', 0x00, /* wcData_39 */
  46. 'B', 0x00, '3', 0x00, '8', 0x00, 'A', 0x00, /* wcData_39 */
  47. '-', 0x00, '7', 0x00, 'C', 0x00, '6', 0x00, /* wcData_39 */
  48. 'F', 0x00, 'D', 0x00, 'D', 0x00, 'D', 0x00, /* wcData_39 */
  49. 'D', 0x00, '7', 0x00, 'E', 0x00, '2', 0x00, /* wcData_39 */
  50. '6', 0x00, '}', 0x00, 0x00, 0x00, /* wcData_39 */
  51. };
  52. #if WINUSB_NUM == 2
  53. #define WINUSB_IF1_WCID_PROPERTIES_SIZE (142)
  54. const uint8_t WINUSB_IF1_WCIDProperties[142] = {
  55. ///////////////////////////////////////
  56. /// WCID property descriptor
  57. ///////////////////////////////////////
  58. 0x8e, 0x00, 0x00, 0x00, /* dwLength */
  59. 0x00, 0x01, /* bcdVersion */
  60. 0x05, 0x00, /* wIndex */
  61. 0x01, 0x00, /* wCount */
  62. ///////////////////////////////////////
  63. /// registry propter descriptor
  64. ///////////////////////////////////////
  65. 0x84, 0x00, 0x00, 0x00, /* dwSize */
  66. 0x01, 0x00, 0x00, 0x00, /* dwPropertyDataType */
  67. 0x28, 0x00, /* wPropertyNameLength */
  68. /* DeviceInterfaceGUID */
  69. 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, /* wcName_20 */
  70. 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, /* wcName_20 */
  71. 't', 0x00, 'e', 0x00, 'r', 0x00, 'f', 0x00, /* wcName_20 */
  72. 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, /* wcName_20 */
  73. 'U', 0x00, 'I', 0x00, 'D', 0x00, 0x00, 0x00, /* wcName_20 */
  74. 0x4e, 0x00, 0x00, 0x00, /* dwPropertyDataLength */
  75. /* {1D4B2365-4749-48EA-B38A-7C6FDDDD7E26} */
  76. '{', 0x00, '1', 0x00, 'D', 0x00, '4', 0x00, /* wcData_39 */
  77. 'B', 0x00, '2', 0x00, '3', 0x00, '6', 0x00, /* wcData_39 */
  78. '5', 0x00, '-', 0x00, '4', 0x00, '7', 0x00, /* wcData_39 */
  79. '4', 0x00, '9', 0x00, '-', 0x00, '4', 0x00, /* wcData_39 */
  80. '8', 0x00, 'E', 0x00, 'A', 0x00, '-', 0x00, /* wcData_39 */
  81. 'B', 0x00, '3', 0x00, '8', 0x00, 'A', 0x00, /* wcData_39 */
  82. '-', 0x00, '7', 0x00, 'C', 0x00, '6', 0x00, /* wcData_39 */
  83. 'F', 0x00, 'D', 0x00, 'D', 0x00, 'D', 0x00, /* wcData_39 */
  84. 'D', 0x00, '7', 0x00, 'E', 0x00, '2', 0x00, /* wcData_39 */
  85. '6', 0x00, '}', 0x00, 0x00, 0x00, /* wcData_39 */
  86. };
  87. #endif
  88. const uint8_t *WINUSB_IFx_WCIDProperties[] = {
  89. WINUSB_IF0_WCIDProperties,
  90. #if WINUSB_NUM == 2
  91. WINUSB_IF1_WCIDProperties,
  92. #endif
  93. };
  94. struct usb_msosv1_descriptor msosv1_desc = {
  95. .string = WCID_StringDescriptor_MSOS,
  96. .vendor_code = WINUSB_VENDOR_CODE,
  97. .compat_id = WINUSB_WCIDDescriptor,
  98. .comp_id_property = WINUSB_IFx_WCIDProperties,
  99. };
  100. #define WINUSB_IN_EP 0x81
  101. #define WINUSB_OUT_EP 0x02
  102. #define USBD_VID 0xFFFE
  103. #define USBD_PID 0xffff
  104. #define USBD_MAX_POWER 100
  105. #define USBD_LANGID_STRING 1033
  106. #if WINUSB_NUM == 1
  107. #define USB_CONFIG_SIZE (9 + 9 + 7 + 7)
  108. #define INTF_NUM 1
  109. #else
  110. #define WINUSB_IN_EP2 0x83
  111. #define WINUSB_OUT_EP2 0x04
  112. #define USB_CONFIG_SIZE (9 + 9 + 7 + 7 + 9 + 7 + 7)
  113. #define INTF_NUM 2
  114. #endif
  115. #ifdef CONFIG_USB_HS
  116. #define WINUSB_EP_MPS 512
  117. #else
  118. #define WINUSB_EP_MPS 64
  119. #endif
  120. #ifdef CONFIG_USBDEV_ADVANCE_DESC
  121. static const uint8_t device_descriptor[] = {
  122. USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0001, 0x01)
  123. };
  124. static const uint8_t config_descriptor[] = {
  125. USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, INTF_NUM, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
  126. USB_INTERFACE_DESCRIPTOR_INIT(0x00, 0x00, 0x02, 0xff, 0xff, 0x00, 0x04),
  127. USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP, 0x02, WINUSB_EP_MPS, 0x00),
  128. USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP, 0x02, WINUSB_EP_MPS, 0x00),
  129. #if WINUSB_NUM == 2
  130. USB_INTERFACE_DESCRIPTOR_INIT(0x01, 0x00, 0x02, 0xff, 0xff, 0x00, 0x05),
  131. USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP2, 0x02, WINUSB_EP_MPS, 0x00),
  132. USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP2, 0x02, WINUSB_EP_MPS, 0x00),
  133. #endif
  134. };
  135. static const uint8_t device_quality_descriptor[] = {
  136. ///////////////////////////////////////
  137. /// device qualifier descriptor
  138. ///////////////////////////////////////
  139. 0x0a,
  140. USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
  141. 0x00,
  142. 0x02,
  143. 0x00,
  144. 0x00,
  145. 0x00,
  146. 0x40,
  147. 0x00,
  148. 0x00,
  149. };
  150. static const char *string_descriptors[] = {
  151. (const char[]){ 0x09, 0x04 }, /* Langid */
  152. "CherryUSB", /* Manufacturer */
  153. "CherryUSB WINUSB DEMO", /* Product */
  154. "2022123456", /* Serial Number */
  155. "CherryUSB WINUSB DEMO 1", /* STRING4 */
  156. "CherryUSB WINUSB DEMO 2", /* STRING5 */
  157. };
  158. static const uint8_t *device_descriptor_callback(uint8_t speed)
  159. {
  160. return device_descriptor;
  161. }
  162. static const uint8_t *config_descriptor_callback(uint8_t speed)
  163. {
  164. return config_descriptor;
  165. }
  166. static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
  167. {
  168. return device_quality_descriptor;
  169. }
  170. static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
  171. {
  172. if (index > 5) {
  173. return NULL;
  174. }
  175. return string_descriptors[index];
  176. }
  177. const struct usb_descriptor winusbv1_descriptor = {
  178. .device_descriptor_callback = device_descriptor_callback,
  179. .config_descriptor_callback = config_descriptor_callback,
  180. .device_quality_descriptor_callback = device_quality_descriptor_callback,
  181. .string_descriptor_callback = string_descriptor_callback,
  182. .msosv1_descriptor = &msosv1_desc
  183. };
  184. #else
  185. const uint8_t winusbv1_descriptor[] = {
  186. USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0001, 0x01),
  187. USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, INTF_NUM, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
  188. USB_INTERFACE_DESCRIPTOR_INIT(0x00, 0x00, 0x02, 0xff, 0xff, 0x00, 0x04),
  189. USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP, 0x02, WINUSB_EP_MPS, 0x00),
  190. USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP, 0x02, WINUSB_EP_MPS, 0x00),
  191. #if WINUSB_NUM == 2
  192. USB_INTERFACE_DESCRIPTOR_INIT(0x01, 0x00, 0x02, 0xff, 0xff, 0x00, 0x05),
  193. USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP2, 0x02, WINUSB_EP_MPS, 0x00),
  194. USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP2, 0x02, WINUSB_EP_MPS, 0x00),
  195. #endif
  196. ///////////////////////////////////////
  197. /// string0 descriptor
  198. ///////////////////////////////////////
  199. USB_LANGID_INIT(USBD_LANGID_STRING),
  200. ///////////////////////////////////////
  201. /// string1 descriptor
  202. ///////////////////////////////////////
  203. 0x14, /* bLength */
  204. USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
  205. 'C', 0x00, /* wcChar0 */
  206. 'h', 0x00, /* wcChar1 */
  207. 'e', 0x00, /* wcChar2 */
  208. 'r', 0x00, /* wcChar3 */
  209. 'r', 0x00, /* wcChar4 */
  210. 'y', 0x00, /* wcChar5 */
  211. 'U', 0x00, /* wcChar6 */
  212. 'S', 0x00, /* wcChar7 */
  213. 'B', 0x00, /* wcChar8 */
  214. ///////////////////////////////////////
  215. /// string2 descriptor
  216. ///////////////////////////////////////
  217. 0x2C, /* bLength */
  218. USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
  219. 'C', 0x00, /* wcChar0 */
  220. 'h', 0x00, /* wcChar1 */
  221. 'e', 0x00, /* wcChar2 */
  222. 'r', 0x00, /* wcChar3 */
  223. 'r', 0x00, /* wcChar4 */
  224. 'y', 0x00, /* wcChar5 */
  225. 'U', 0x00, /* wcChar6 */
  226. 'S', 0x00, /* wcChar7 */
  227. 'B', 0x00, /* wcChar8 */
  228. ' ', 0x00, /* wcChar9 */
  229. 'W', 0x00, /* wcChar10 */
  230. 'I', 0x00, /* wcChar11 */
  231. 'N', 0x00, /* wcChar12 */
  232. 'U', 0x00, /* wcChar13 */
  233. 'S', 0x00, /* wcChar14 */
  234. 'B', 0x00, /* wcChar15 */
  235. ' ', 0x00, /* wcChar16 */
  236. 'D', 0x00, /* wcChar17 */
  237. 'E', 0x00, /* wcChar18 */
  238. 'M', 0x00, /* wcChar19 */
  239. 'O', 0x00, /* wcChar20 */
  240. ///////////////////////////////////////
  241. /// string3 descriptor
  242. ///////////////////////////////////////
  243. 0x16, /* bLength */
  244. USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
  245. '2', 0x00, /* wcChar0 */
  246. '0', 0x00, /* wcChar1 */
  247. '2', 0x00, /* wcChar2 */
  248. '1', 0x00, /* wcChar3 */
  249. '1', 0x00, /* wcChar4 */
  250. '2', 0x00, /* wcChar5 */
  251. '3', 0x00, /* wcChar6 */
  252. '4', 0x00, /* wcChar7 */
  253. '5', 0x00, /* wcChar8 */
  254. '6', 0x00, /* wcChar9 */
  255. ///////////////////////////////////////
  256. /// string4 descriptor
  257. ///////////////////////////////////////
  258. 0x30, /* bLength */
  259. USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
  260. 'C', 0x00, /* wcChar0 */
  261. 'h', 0x00, /* wcChar1 */
  262. 'e', 0x00, /* wcChar2 */
  263. 'r', 0x00, /* wcChar3 */
  264. 'r', 0x00, /* wcChar4 */
  265. 'y', 0x00, /* wcChar5 */
  266. 'U', 0x00, /* wcChar6 */
  267. 'S', 0x00, /* wcChar7 */
  268. 'B', 0x00, /* wcChar8 */
  269. ' ', 0x00, /* wcChar9 */
  270. 'W', 0x00, /* wcChar10 */
  271. 'I', 0x00, /* wcChar11 */
  272. 'N', 0x00, /* wcChar12 */
  273. 'U', 0x00, /* wcChar13 */
  274. 'S', 0x00, /* wcChar14 */
  275. 'B', 0x00, /* wcChar15 */
  276. ' ', 0x00, /* wcChar16 */
  277. 'D', 0x00, /* wcChar17 */
  278. 'E', 0x00, /* wcChar18 */
  279. 'M', 0x00, /* wcChar19 */
  280. 'O', 0x00, /* wcChar20 */
  281. ' ', 0x00, /* wcChar16 */
  282. '1', 0x00, /* wcChar21 */
  283. ///////////////////////////////////////
  284. /// string5 descriptor
  285. ///////////////////////////////////////
  286. 0x30, /* bLength */
  287. USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
  288. 'C', 0x00, /* wcChar0 */
  289. 'h', 0x00, /* wcChar1 */
  290. 'e', 0x00, /* wcChar2 */
  291. 'r', 0x00, /* wcChar3 */
  292. 'r', 0x00, /* wcChar4 */
  293. 'y', 0x00, /* wcChar5 */
  294. 'U', 0x00, /* wcChar6 */
  295. 'S', 0x00, /* wcChar7 */
  296. 'B', 0x00, /* wcChar8 */
  297. ' ', 0x00, /* wcChar9 */
  298. 'W', 0x00, /* wcChar10 */
  299. 'I', 0x00, /* wcChar11 */
  300. 'N', 0x00, /* wcChar12 */
  301. 'U', 0x00, /* wcChar13 */
  302. 'S', 0x00, /* wcChar14 */
  303. 'B', 0x00, /* wcChar15 */
  304. ' ', 0x00, /* wcChar16 */
  305. 'D', 0x00, /* wcChar17 */
  306. 'E', 0x00, /* wcChar18 */
  307. 'M', 0x00, /* wcChar19 */
  308. 'O', 0x00, /* wcChar20 */
  309. ' ', 0x00, /* wcChar16 */
  310. '2', 0x00, /* wcChar21 */
  311. #ifdef CONFIG_USB_HS
  312. ///////////////////////////////////////
  313. /// device qualifier descriptor
  314. ///////////////////////////////////////
  315. 0x0a,
  316. USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
  317. 0x00,
  318. 0x02,
  319. 0x00,
  320. 0x00,
  321. 0x00,
  322. 0x40,
  323. 0x00,
  324. 0x00,
  325. #endif
  326. 0x00
  327. };
  328. #endif
  329. USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[2048];
  330. USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[2048];
  331. volatile bool ep_tx_busy_flag = false;
  332. static void usbd_event_handler(uint8_t busid, uint8_t event)
  333. {
  334. switch (event) {
  335. case USBD_EVENT_RESET:
  336. break;
  337. case USBD_EVENT_CONNECTED:
  338. break;
  339. case USBD_EVENT_DISCONNECTED:
  340. break;
  341. case USBD_EVENT_RESUME:
  342. break;
  343. case USBD_EVENT_SUSPEND:
  344. break;
  345. case USBD_EVENT_CONFIGURED:
  346. ep_tx_busy_flag = false;
  347. /* setup first out ep read transfer */
  348. usbd_ep_start_read(busid, WINUSB_OUT_EP, read_buffer, 2048);
  349. #if WINUSB_NUM == 2
  350. usbd_ep_start_read(busid, WINUSB_OUT_EP2, read_buffer, 2048);
  351. #endif
  352. break;
  353. case USBD_EVENT_SET_REMOTE_WAKEUP:
  354. break;
  355. case USBD_EVENT_CLR_REMOTE_WAKEUP:
  356. break;
  357. default:
  358. break;
  359. }
  360. }
  361. void usbd_winusb_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
  362. {
  363. USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes);
  364. // for (int i = 0; i < 100; i++) {
  365. // printf("%02x ", read_buffer[i]);
  366. // }
  367. // printf("\r\n");
  368. usbd_ep_start_write(busid, WINUSB_IN_EP, read_buffer, nbytes);
  369. /* setup next out ep read transfer */
  370. usbd_ep_start_read(busid, WINUSB_OUT_EP, read_buffer, 2048);
  371. }
  372. void usbd_winusb_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
  373. {
  374. USB_LOG_RAW("actual in len:%d\r\n", (unsigned int)nbytes);
  375. if ((nbytes % WINUSB_EP_MPS) == 0 && nbytes) {
  376. /* send zlp */
  377. usbd_ep_start_write(busid, WINUSB_IN_EP, NULL, 0);
  378. } else {
  379. ep_tx_busy_flag = false;
  380. }
  381. }
  382. struct usbd_endpoint winusb_out_ep1 = {
  383. .ep_addr = WINUSB_OUT_EP,
  384. .ep_cb = usbd_winusb_out
  385. };
  386. struct usbd_endpoint winusb_in_ep1 = {
  387. .ep_addr = WINUSB_IN_EP,
  388. .ep_cb = usbd_winusb_in
  389. };
  390. struct usbd_interface intf0;
  391. #if WINUSB_NUM == 2
  392. void usbd_winusb_out2(uint8_t busid, uint8_t ep, uint32_t nbytes)
  393. {
  394. USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes);
  395. // for (int i = 0; i < 100; i++) {
  396. // printf("%02x ", read_buffer[i]);
  397. // }
  398. // printf("\r\n");
  399. usbd_ep_start_write(busid, WINUSB_IN_EP2, read_buffer, nbytes);
  400. /* setup next out ep read transfer */
  401. usbd_ep_start_read(busid, WINUSB_OUT_EP2, read_buffer, 2048);
  402. }
  403. void usbd_winusb_in2(uint8_t busid, uint8_t ep, uint32_t nbytes)
  404. {
  405. USB_LOG_RAW("actual in len:%d\r\n", (unsigned int)nbytes);
  406. if ((nbytes % usbd_get_ep_mps(busid, ep)) == 0 && nbytes) {
  407. /* send zlp */
  408. usbd_ep_start_write(busid, WINUSB_IN_EP2, NULL, 0);
  409. } else {
  410. ep_tx_busy_flag = false;
  411. }
  412. }
  413. struct usbd_endpoint winusb_out_ep2 = {
  414. .ep_addr = WINUSB_OUT_EP2,
  415. .ep_cb = usbd_winusb_out2
  416. };
  417. struct usbd_endpoint winusb_in_ep2 = {
  418. .ep_addr = WINUSB_IN_EP2,
  419. .ep_cb = usbd_winusb_in2
  420. };
  421. struct usbd_interface intf1;
  422. #endif
  423. void winusbv1_init(uint8_t busid, uintptr_t reg_base)
  424. {
  425. #ifdef CONFIG_USBDEV_ADVANCE_DESC
  426. usbd_desc_register(busid, &winusbv1_descriptor);
  427. #else
  428. usbd_desc_register(busid, winusbv1_descriptor);
  429. #endif
  430. #ifndef CONFIG_USBDEV_ADVANCE_DESC
  431. usbd_msosv1_desc_register(busid, &msosv1_desc);
  432. #endif
  433. usbd_add_interface(busid, &intf0);
  434. usbd_add_endpoint(busid, &winusb_out_ep1);
  435. usbd_add_endpoint(busid, &winusb_in_ep1);
  436. #if WINUSB_NUM == 2
  437. usbd_add_interface(busid, &intf1);
  438. usbd_add_endpoint(busid, &winusb_out_ep2);
  439. usbd_add_endpoint(busid, &winusb_in_ep2);
  440. #endif
  441. usbd_initialize(busid, reg_base, usbd_event_handler);
  442. }