drv_usbd.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. /*
  2. * File : drv_usbc.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009 RT-Thread Develop Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2017-12-04 ZYH first implementation
  13. */
  14. #include <usb/include/usb_device_config.h>
  15. #include <usb/include/usb.h>
  16. #include <rtthread.h>
  17. #include <usb/phy/usb_phy.h>
  18. #include <usb/device/usb_device.h>
  19. #include <usb/device/usb_device_dci.h>
  20. #include <rtdevice.h>
  21. #ifdef RT_USING_EHCI0_AS_DEVICE
  22. #ifdef RT_USING_EHCI1_AS_DEVICE
  23. #error Can not using 2 controller as usb device
  24. #endif
  25. #endif
  26. /* USB PHY condfiguration */
  27. #define BOARD_USB_PHY_D_CAL (0x0CU)
  28. #define BOARD_USB_PHY_TXCAL45DP (0x06U)
  29. #define BOARD_USB_PHY_TXCAL45DM (0x06U)
  30. #define BOARD_XTAL0_CLK_HZ 24000000U
  31. #ifdef RT_USING_EHCI0_AS_DEVICE
  32. static usb_device_handle ehci0_handle;
  33. static struct udcd _fsl_udc_0;
  34. #endif
  35. #ifdef RT_USING_EHCI1_AS_DEVICE
  36. static usb_device_handle ehci1_handle;
  37. static struct udcd _fsl_udc_1;
  38. #endif
  39. static usb_status_t usb_device_callback(usb_device_handle handle, uint32_t callbackEvent, void *eventParam);
  40. static usb_status_t usb_device_endpoint_callback(usb_device_handle handle, usb_device_endpoint_callback_message_struct_t *message, void *callbackParam);
  41. void USB_DeviceIsrEnable(uint8_t controllerId)
  42. {
  43. uint8_t irqNumber;
  44. #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0U)
  45. uint8_t usbDeviceEhciIrq[] = USBHS_IRQS;
  46. irqNumber = usbDeviceEhciIrq[controllerId - kUSB_ControllerEhci0];
  47. #endif
  48. /* Install isr, set priority, and enable IRQ. */
  49. #if defined(__GIC_PRIO_BITS)
  50. GIC_SetPriority((IRQn_Type)irqNumber, 3);
  51. #else
  52. NVIC_SetPriority((IRQn_Type)irqNumber, 3);
  53. #endif
  54. EnableIRQ((IRQn_Type)irqNumber);
  55. }
  56. void USB_DeviceClockInit(uint8_t controllerId)
  57. {
  58. #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0U)
  59. usb_phy_config_struct_t phyConfig = {
  60. BOARD_USB_PHY_D_CAL, BOARD_USB_PHY_TXCAL45DP, BOARD_USB_PHY_TXCAL45DM,
  61. };
  62. #endif
  63. #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0U)
  64. if (controllerId == kUSB_ControllerEhci0)
  65. {
  66. CLOCK_EnableUsbhs0PhyPllClock(kCLOCK_Usbphy480M, 480000000U);
  67. CLOCK_EnableUsbhs0Clock(kCLOCK_Usb480M, 480000000U);
  68. }
  69. else
  70. {
  71. CLOCK_EnableUsbhs1PhyPllClock(kCLOCK_Usbphy480M, 480000000U);
  72. CLOCK_EnableUsbhs1Clock(kCLOCK_Usb480M, 480000000U);
  73. }
  74. USB_EhciPhyInit(controllerId, BOARD_XTAL0_CLK_HZ, &phyConfig);
  75. #endif
  76. }
  77. #ifdef RT_USING_EHCI0_AS_DEVICE
  78. static struct ep_id _ehci0_ep_pool[] =
  79. {
  80. {0x0, USB_EP_ATTR_CONTROL, USB_DIR_INOUT, 64, ID_ASSIGNED },
  81. {0x1, USB_EP_ATTR_BULK, USB_DIR_IN, 64, ID_UNASSIGNED},
  82. {0x1, USB_EP_ATTR_BULK, USB_DIR_OUT, 64, ID_UNASSIGNED},
  83. {0x2, USB_EP_ATTR_INT, USB_DIR_IN, 64, ID_UNASSIGNED},
  84. {0x2, USB_EP_ATTR_INT, USB_DIR_OUT, 64, ID_UNASSIGNED},
  85. {0x3, USB_EP_ATTR_BULK, USB_DIR_IN, 64, ID_UNASSIGNED},
  86. {0x3, USB_EP_ATTR_BULK, USB_DIR_OUT, 64, ID_UNASSIGNED},
  87. {0x4, USB_EP_ATTR_INT, USB_DIR_IN, 64, ID_UNASSIGNED},
  88. {0x4, USB_EP_ATTR_INT, USB_DIR_OUT, 64, ID_UNASSIGNED},
  89. {0x5, USB_EP_ATTR_BULK, USB_DIR_IN, 64, ID_UNASSIGNED},
  90. {0x5, USB_EP_ATTR_BULK, USB_DIR_OUT, 64, ID_UNASSIGNED},
  91. {0x6, USB_EP_ATTR_INT, USB_DIR_IN, 64, ID_UNASSIGNED},
  92. {0x6, USB_EP_ATTR_INT, USB_DIR_OUT, 64, ID_UNASSIGNED},
  93. {0x7, USB_EP_ATTR_BULK, USB_DIR_IN, 64, ID_UNASSIGNED},
  94. {0x7, USB_EP_ATTR_BULK, USB_DIR_OUT, 64, ID_UNASSIGNED},
  95. {0xFF, USB_EP_ATTR_TYPE_MASK, USB_DIR_MASK, 0, ID_ASSIGNED },
  96. };
  97. void USB_OTG1_IRQHandler(void)
  98. {
  99. /* enter interrupt */
  100. rt_interrupt_enter();
  101. USB_DeviceEhciIsrFunction(ehci0_handle);
  102. /* leave interrupt */
  103. rt_interrupt_leave();
  104. }
  105. static rt_err_t _ehci0_ep_set_stall(rt_uint8_t address)
  106. {
  107. USB_DeviceStallEndpoint(ehci0_handle, address);
  108. return RT_EOK;
  109. }
  110. static rt_err_t _ehci0_ep_clear_stall(rt_uint8_t address)
  111. {
  112. USB_DeviceUnstallEndpoint(ehci0_handle, address);
  113. return RT_EOK;
  114. }
  115. static rt_err_t _ehci0_set_address(rt_uint8_t address)
  116. {
  117. USB_DeviceSetStatus(ehci0_handle, kUSB_DeviceStatusAddress, &address);
  118. return RT_EOK;
  119. }
  120. static rt_err_t _ehci0_set_config(rt_uint8_t address)
  121. {
  122. return RT_EOK;
  123. }
  124. static rt_err_t _ehci0_ep_enable(uep_t ep)
  125. {
  126. usb_device_endpoint_init_struct_t ep_init;
  127. usb_device_endpoint_callback_struct_t ep_callback;
  128. RT_ASSERT(ep != RT_NULL);
  129. RT_ASSERT(ep->ep_desc != RT_NULL);
  130. ep_init.maxPacketSize = ep->ep_desc->wMaxPacketSize;
  131. ep_init.endpointAddress = ep->ep_desc->bEndpointAddress;
  132. ep_init.transferType = ep->ep_desc->bmAttributes;
  133. ep_init.zlt = 0;
  134. ep_callback.callbackFn = usb_device_endpoint_callback;
  135. ep_callback.callbackParam = (void *)ep_init.endpointAddress;
  136. ep_callback.isBusy = 0;
  137. USB_DeviceInitEndpoint(ehci0_handle,&ep_init,&ep_callback);
  138. return RT_EOK;
  139. }
  140. static rt_err_t _ehci0_ep_disable(uep_t ep)
  141. {
  142. RT_ASSERT(ep != RT_NULL);
  143. RT_ASSERT(ep->ep_desc != RT_NULL);
  144. USB_DeviceDeinitEndpoint(ehci0_handle, ep->ep_desc->bEndpointAddress);
  145. return RT_EOK;
  146. }
  147. static rt_size_t _ehci0_ep_read(rt_uint8_t address, void *buffer)
  148. {
  149. rt_size_t size = 0;
  150. RT_ASSERT(buffer != RT_NULL);
  151. return size;
  152. }
  153. static rt_size_t _ehci0_ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size)
  154. {
  155. USB_DeviceRecvRequest(ehci0_handle, address, buffer, size);
  156. return size;
  157. }
  158. static rt_size_t _ehci0_ep_write(rt_uint8_t address, void *buffer, rt_size_t size)
  159. {
  160. USB_DeviceSendRequest(ehci0_handle, address, buffer, size);
  161. return size;
  162. }
  163. static rt_err_t _ehci0_ep0_send_status(void)
  164. {
  165. _ehci0_ep_write(0x00, NULL, 0);
  166. return RT_EOK;
  167. }
  168. static rt_err_t _ehci0_suspend(void)
  169. {
  170. return RT_EOK;
  171. }
  172. static rt_err_t _ehci0_wakeup(void)
  173. {
  174. return RT_EOK;
  175. }
  176. const static struct udcd_ops _ehci0_udc_ops =
  177. {
  178. _ehci0_set_address,
  179. _ehci0_set_config,
  180. _ehci0_ep_set_stall,
  181. _ehci0_ep_clear_stall,
  182. _ehci0_ep_enable,
  183. _ehci0_ep_disable,
  184. _ehci0_ep_read_prepare,
  185. _ehci0_ep_read,
  186. _ehci0_ep_write,
  187. _ehci0_ep0_send_status,
  188. _ehci0_suspend,
  189. _ehci0_wakeup,
  190. };
  191. static rt_err_t drv_ehci0_usbd_init(rt_device_t device)
  192. {
  193. usb_status_t result;
  194. USB_DeviceClockInit(kUSB_ControllerEhci0);
  195. result = USB_DeviceInit(kUSB_ControllerEhci0,usb_device_callback,&ehci0_handle);
  196. RT_ASSERT(ehci0_handle);
  197. if(result == kStatus_USB_Success)
  198. {
  199. USB_DeviceIsrEnable(kUSB_ControllerEhci0);
  200. USB_DeviceRun(ehci0_handle);
  201. }
  202. else
  203. {
  204. rt_kprintf("USB_DeviceInit ehci0 error\r\n");
  205. return RT_ERROR;
  206. }
  207. return RT_EOK;
  208. }
  209. #endif
  210. #ifdef RT_USING_EHCI1_AS_DEVICE
  211. static struct ep_id _ehci1_ep_pool[] =
  212. {
  213. {0x0, USB_EP_ATTR_CONTROL, USB_DIR_INOUT, 64, ID_ASSIGNED },
  214. {0x1, USB_EP_ATTR_BULK, USB_DIR_IN, 64, ID_UNASSIGNED},
  215. {0x1, USB_EP_ATTR_BULK, USB_DIR_OUT, 64, ID_UNASSIGNED},
  216. {0x2, USB_EP_ATTR_INT, USB_DIR_IN, 64, ID_UNASSIGNED},
  217. {0x2, USB_EP_ATTR_INT, USB_DIR_OUT, 64, ID_UNASSIGNED},
  218. {0x3, USB_EP_ATTR_BULK, USB_DIR_IN, 64, ID_UNASSIGNED},
  219. {0x3, USB_EP_ATTR_BULK, USB_DIR_OUT, 64, ID_UNASSIGNED},
  220. {0x4, USB_EP_ATTR_INT, USB_DIR_IN, 64, ID_UNASSIGNED},
  221. {0x4, USB_EP_ATTR_INT, USB_DIR_OUT, 64, ID_UNASSIGNED},
  222. {0x5, USB_EP_ATTR_BULK, USB_DIR_IN, 64, ID_UNASSIGNED},
  223. {0x5, USB_EP_ATTR_BULK, USB_DIR_OUT, 64, ID_UNASSIGNED},
  224. {0x6, USB_EP_ATTR_INT, USB_DIR_IN, 64, ID_UNASSIGNED},
  225. {0x6, USB_EP_ATTR_INT, USB_DIR_OUT, 64, ID_UNASSIGNED},
  226. {0x7, USB_EP_ATTR_BULK, USB_DIR_IN, 64, ID_UNASSIGNED},
  227. {0x7, USB_EP_ATTR_BULK, USB_DIR_OUT, 64, ID_UNASSIGNED},
  228. {0xFF, USB_EP_ATTR_TYPE_MASK, USB_DIR_MASK, 0, ID_ASSIGNED },
  229. };
  230. void USB_OTG2_IRQHandler(void)
  231. {
  232. /* enter interrupt */
  233. rt_interrupt_enter();
  234. USB_DeviceEhciIsrFunction(ehci1_handle);
  235. /* leave interrupt */
  236. rt_interrupt_leave();
  237. }
  238. static rt_err_t _ehci1_ep_set_stall(rt_uint8_t address)
  239. {
  240. USB_DeviceStallEndpoint(ehci1_handle, address);
  241. return RT_EOK;
  242. }
  243. static rt_err_t _ehci1_ep_clear_stall(rt_uint8_t address)
  244. {
  245. USB_DeviceUnstallEndpoint(ehci1_handle, address);
  246. return RT_EOK;
  247. }
  248. static rt_err_t _ehci1_set_address(rt_uint8_t address)
  249. {
  250. USB_DeviceSetStatus(ehci1_handle, kUSB_DeviceStatusAddress, &address);
  251. return RT_EOK;
  252. }
  253. static rt_err_t _ehci1_set_config(rt_uint8_t address)
  254. {
  255. return RT_EOK;
  256. }
  257. static rt_err_t _ehci1_ep_enable(uep_t ep)
  258. {
  259. usb_device_endpoint_init_struct_t ep_init;
  260. usb_device_endpoint_callback_struct_t ep_callback;
  261. RT_ASSERT(ep != RT_NULL);
  262. RT_ASSERT(ep->ep_desc != RT_NULL);
  263. ep_init.maxPacketSize = ep->ep_desc->wMaxPacketSize;
  264. ep_init.endpointAddress = ep->ep_desc->bEndpointAddress;
  265. ep_init.transferType = ep->ep_desc->bmAttributes;
  266. ep_init.zlt = 0;
  267. ep_callback.callbackFn = usb_device_endpoint_callback;
  268. ep_callback.callbackParam = (void *)ep_init.endpointAddress;
  269. ep_callback.isBusy = 0;
  270. USB_DeviceInitEndpoint(ehci1_handle,&ep_init,&ep_callback);
  271. return RT_EOK;
  272. }
  273. static rt_err_t _ehci1_ep_disable(uep_t ep)
  274. {
  275. RT_ASSERT(ep != RT_NULL);
  276. RT_ASSERT(ep->ep_desc != RT_NULL);
  277. USB_DeviceDeinitEndpoint(ehci1_handle, ep->ep_desc->bEndpointAddress);
  278. return RT_EOK;
  279. }
  280. static rt_size_t _ehci1_ep_read(rt_uint8_t address, void *buffer)
  281. {
  282. rt_size_t size = 0;
  283. RT_ASSERT(buffer != RT_NULL);
  284. return size;
  285. }
  286. static rt_size_t _ehci1_ep_read_prepare(rt_uint8_t address, void *buffer, rt_size_t size)
  287. {
  288. USB_DeviceRecvRequest(ehci1_handle, address, buffer, size);
  289. return size;
  290. }
  291. static rt_size_t _ehci1_ep_write(rt_uint8_t address, void *buffer, rt_size_t size)
  292. {
  293. USB_DeviceSendRequest(ehci1_handle, address, buffer, size);
  294. return size;
  295. }
  296. static rt_err_t _ehci1_ep0_send_status(void)
  297. {
  298. _ehci1_ep_write(0x00, NULL, 0);
  299. return RT_EOK;
  300. }
  301. static rt_err_t _ehci1_suspend(void)
  302. {
  303. return RT_EOK;
  304. }
  305. static rt_err_t _ehci1_wakeup(void)
  306. {
  307. return RT_EOK;
  308. }
  309. const static struct udcd_ops _ehci1_udc_ops =
  310. {
  311. _ehci1_set_address,
  312. _ehci1_set_config,
  313. _ehci1_ep_set_stall,
  314. _ehci1_ep_clear_stall,
  315. _ehci1_ep_enable,
  316. _ehci1_ep_disable,
  317. _ehci1_ep_read_prepare,
  318. _ehci1_ep_read,
  319. _ehci1_ep_write,
  320. _ehci1_ep0_send_status,
  321. _ehci1_suspend,
  322. _ehci1_wakeup,
  323. };
  324. static rt_err_t drv_ehci1_usbd_init(rt_device_t device)
  325. {
  326. usb_status_t result;
  327. USB_DeviceClockInit(kUSB_ControllerEhci1);
  328. result = USB_DeviceInit(kUSB_ControllerEhci1,usb_device_callback,&ehci1_handle);
  329. RT_ASSERT(ehci1_handle);
  330. if(result == kStatus_USB_Success)
  331. {
  332. USB_DeviceIsrEnable(kUSB_ControllerEhci1);
  333. USB_DeviceRun(ehci1_handle);
  334. }
  335. else
  336. {
  337. rt_kprintf("USB_DeviceInit ehci1 error\r\n");
  338. return RT_ERROR;
  339. }
  340. return RT_EOK;
  341. }
  342. #endif
  343. #if defined(RT_USING_EHCI0_AS_DEVICE) && defined(RT_USING_EHCI1_AS_DEVICE)
  344. #error Can not using both now
  345. #endif
  346. static int rt_usbd_init(void)
  347. {
  348. #ifdef RT_USING_EHCI0_AS_DEVICE
  349. rt_memset((void *)&_fsl_udc_0, 0, sizeof(struct udcd));
  350. _fsl_udc_0.parent.type = RT_Device_Class_USBDevice;
  351. _fsl_udc_0.parent.init = drv_ehci0_usbd_init;
  352. _fsl_udc_0.ops = &_ehci0_udc_ops;
  353. /* Register endpoint infomation */
  354. _fsl_udc_0.ep_pool = _ehci0_ep_pool;
  355. _fsl_udc_0.ep0.id = &_ehci0_ep_pool[0];
  356. rt_device_register((rt_device_t)&_fsl_udc_0, "usbd", 0);
  357. rt_usb_device_init();
  358. #endif
  359. #ifdef RT_USING_EHCI1_AS_DEVICE
  360. rt_memset((void *)&_fsl_udc_1, 0, sizeof(struct udcd));
  361. _fsl_udc_1.parent.type = RT_Device_Class_USBDevice;
  362. _fsl_udc_1.parent.init = drv_ehci1_usbd_init;
  363. _fsl_udc_1.ops = &_ehci1_udc_ops;
  364. /* Register endpoint infomation */
  365. _fsl_udc_1.ep_pool = _ehci1_ep_pool;
  366. _fsl_udc_1.ep0.id = &_ehci1_ep_pool[0];
  367. rt_device_register((rt_device_t)&_fsl_udc_1, "usbd", 0);
  368. rt_usb_device_init();
  369. #endif
  370. return 0;
  371. }
  372. INIT_DEVICE_EXPORT(rt_usbd_init);
  373. static usb_status_t usb_device_endpoint_callback(usb_device_handle handle, usb_device_endpoint_callback_message_struct_t *message, void *callbackParam)
  374. {
  375. rt_uint32_t ep_addr = (rt_uint32_t)callbackParam;
  376. usb_device_struct_t *deviceHandle = (usb_device_struct_t *)handle;
  377. udcd_t udcd = RT_NULL;
  378. uint8_t state;
  379. if(deviceHandle->controllerId == kUSB_ControllerEhci0)
  380. {
  381. #ifdef RT_USING_EHCI0_AS_DEVICE
  382. udcd = &_fsl_udc_0;
  383. #endif
  384. }
  385. else
  386. {
  387. #ifdef RT_USING_EHCI1_AS_DEVICE
  388. udcd = &_fsl_udc_1;
  389. #endif
  390. }
  391. if(message->isSetup)
  392. {
  393. rt_usbd_ep0_setup_handler(udcd, (struct urequest*)message->buffer);
  394. }
  395. else if(ep_addr == 0x00)
  396. {
  397. USB_DeviceGetStatus(handle, kUSB_DeviceStatusDeviceState, &state);
  398. if(state == kUSB_DeviceStateAddressing)
  399. {
  400. if (kStatus_USB_Success == USB_DeviceSetStatus(handle, kUSB_DeviceStatusAddress, NULL))
  401. {
  402. state = kUSB_DeviceStateAddress;
  403. USB_DeviceSetStatus(handle, kUSB_DeviceStatusDeviceState, &state);
  404. }
  405. }
  406. rt_usbd_ep0_out_handler(udcd,message->length);
  407. }
  408. else if(ep_addr == 0x80)
  409. {
  410. USB_DeviceGetStatus(handle, kUSB_DeviceStatusDeviceState, &state);
  411. if(state == kUSB_DeviceStateAddressing)
  412. {
  413. if (kStatus_USB_Success == USB_DeviceSetStatus(handle, kUSB_DeviceStatusAddress, NULL))
  414. {
  415. state = kUSB_DeviceStateAddress;
  416. USB_DeviceSetStatus(handle, kUSB_DeviceStatusDeviceState, &state);
  417. }
  418. }
  419. rt_usbd_ep0_in_handler(udcd);
  420. }
  421. else if(ep_addr&0x80)
  422. {
  423. rt_usbd_ep_in_handler(udcd, ep_addr, message->length);
  424. }
  425. else
  426. {
  427. rt_usbd_ep_out_handler(udcd, ep_addr, message->length);
  428. }
  429. return kStatus_USB_Success;
  430. }
  431. static usb_status_t usb_device_callback(usb_device_handle handle, uint32_t callbackEvent, void *eventParam)
  432. {
  433. usb_status_t error = kStatus_USB_Error;
  434. usb_device_struct_t *deviceHandle = (usb_device_struct_t *)handle;
  435. usb_device_endpoint_init_struct_t ep0_init =
  436. {
  437. 0x40,
  438. 0x00,
  439. USB_EP_ATTR_CONTROL,
  440. 0
  441. };
  442. usb_device_endpoint_callback_struct_t ep0_callback =
  443. {
  444. usb_device_endpoint_callback,
  445. 0,
  446. 0
  447. };
  448. udcd_t udcd = RT_NULL;
  449. if(deviceHandle->controllerId == kUSB_ControllerEhci0)
  450. {
  451. #ifdef RT_USING_EHCI0_AS_DEVICE
  452. udcd = &_fsl_udc_0;
  453. #endif
  454. }
  455. else
  456. {
  457. #ifdef RT_USING_EHCI1_AS_DEVICE
  458. udcd = &_fsl_udc_1;
  459. #endif
  460. }
  461. switch (callbackEvent)
  462. {
  463. case kUSB_DeviceEventBusReset:
  464. ep0_init.endpointAddress = 0x00;
  465. ep0_callback.callbackParam = (void *)0x00;
  466. USB_DeviceInitEndpoint(deviceHandle,&ep0_init,&ep0_callback);
  467. ep0_init.endpointAddress = 0x80;
  468. ep0_callback.callbackParam = (void *)0x80;
  469. USB_DeviceInitEndpoint(deviceHandle,&ep0_init,&ep0_callback);
  470. rt_usbd_reset_handler(udcd);
  471. break;
  472. case kUSB_DeviceEventAttach:
  473. rt_usbd_connect_handler(udcd);
  474. break;
  475. case kUSB_DeviceEventDetach:
  476. rt_usbd_disconnect_handler(udcd);
  477. break;
  478. }
  479. return error;
  480. }