winusb1.0_template.c 17 KB

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