usbd_enum.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. /*!
  2. \file usbd_enum.c
  3. \brief USB enumeration function
  4. \version 2019-6-5, V1.0.0, firmware for GD32 USBFS&USBHS
  5. */
  6. /*
  7. Copyright (c) 2019, GigaDevice Semiconductor Inc.
  8. Redistribution and use in source and binary forms, with or without modification,
  9. are permitted provided that the following conditions are met:
  10. 1. Redistributions of source code must retain the above copyright notice, this
  11. list of conditions and the following disclaimer.
  12. 2. Redistributions in binary form must reproduce the above copyright notice,
  13. this list of conditions and the following disclaimer in the documentation
  14. and/or other materials provided with the distribution.
  15. 3. Neither the name of the copyright holder nor the names of its contributors
  16. may be used to endorse or promote products derived from this software without
  17. specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  22. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  27. OF SUCH DAMAGE.
  28. */
  29. #include "usbd_enum.h"
  30. #include "usb_ch9_std.h"
  31. static usb_reqsta _usb_std_getstatus(usb_core_driver* udev, usb_req* req);
  32. static usb_reqsta _usb_std_setaddress(usb_core_driver* udev, usb_req* req);
  33. static usb_reqsta _usb_std_setconfiguration(usb_core_driver* udev, usb_req* req);
  34. static usb_reqsta _usb_std_getconfiguration(usb_core_driver* udev, usb_req* req);
  35. static usb_reqsta _usb_std_getdescriptor(usb_core_driver* udev, usb_req* req);
  36. static usb_reqsta _usb_std_setfeature(usb_core_driver* udev, usb_req* req);
  37. static usb_reqsta _usb_std_clearfeature(usb_core_driver* udev, usb_req* req);
  38. static usb_reqsta _usb_std_reserved(usb_core_driver* udev, usb_req* req);
  39. static usb_reqsta _usb_std_setdescriptor(usb_core_driver* udev, usb_req* req);
  40. static usb_reqsta _usb_std_getinterface(usb_core_driver* udev, usb_req* req);
  41. static usb_reqsta _usb_std_setinterface(usb_core_driver* udev, usb_req* req);
  42. static usb_reqsta _usb_std_synchframe(usb_core_driver* udev, usb_req* req);
  43. static uint8_t* _usb_dev_desc_get(usb_core_driver* udev, uint8_t index, uint16_t* len);
  44. static uint8_t* _usb_config_desc_get(usb_core_driver* udev, uint8_t index, uint16_t* len);
  45. static uint8_t* _usb_str_desc_get(usb_core_driver* udev, uint8_t index, uint16_t* len);
  46. static uint8_t* _usb_bos_desc_get(usb_core_driver* udev, uint8_t index, uint16_t* len);
  47. static usb_reqsta(*_std_dev_req[])(usb_core_driver* udev, usb_req* req) = {
  48. [USB_GET_STATUS] = _usb_std_getstatus,
  49. [USB_CLEAR_FEATURE] = _usb_std_clearfeature,
  50. [USB_RESERVED2] = _usb_std_reserved,
  51. [USB_SET_FEATURE] = _usb_std_setfeature,
  52. [USB_RESERVED4] = _usb_std_reserved,
  53. [USB_SET_ADDRESS] = _usb_std_setaddress,
  54. [USB_GET_DESCRIPTOR] = _usb_std_getdescriptor,
  55. [USB_SET_DESCRIPTOR] = _usb_std_setdescriptor,
  56. [USB_GET_CONFIGURATION] = _usb_std_getconfiguration,
  57. [USB_SET_CONFIGURATION] = _usb_std_setconfiguration,
  58. [USB_GET_INTERFACE] = _usb_std_getinterface,
  59. [USB_SET_INTERFACE] = _usb_std_setinterface,
  60. [USB_SYNCH_FRAME] = _usb_std_synchframe,
  61. };
  62. /* get standard descriptor handler */
  63. static uint8_t* (*std_desc_get[])(usb_core_driver* udev, uint8_t index, uint16_t* len) = {
  64. [USB_DESCTYPE_DEV - 1] = _usb_dev_desc_get,
  65. [USB_DESCTYPE_CONFIG - 1] = _usb_config_desc_get,
  66. [USB_DESCTYPE_STR - 1] = _usb_str_desc_get
  67. };
  68. /*!
  69. \brief handle USB standard device request
  70. \param[in] udev: pointer to USB device instance
  71. \param[in] req: pointer to USB device request
  72. \param[out] none
  73. \retval USB device request status
  74. */
  75. usb_reqsta usbd_standard_request(usb_core_driver* udev, usb_req* req)
  76. {
  77. return (*_std_dev_req[req->bRequest])(udev, req);
  78. }
  79. /*!
  80. \brief handle USB device class request
  81. \param[in] udev: pointer to USB device instance
  82. \param[in] req: pointer to USB device class request
  83. \param[out] none
  84. \retval USB device request status
  85. */
  86. usb_reqsta usbd_class_request(usb_core_driver* udev, usb_req* req)
  87. {
  88. if (USBD_CONFIGURED == udev->dev.cur_status) {
  89. if (BYTE_LOW(req->wIndex) <= USBD_ITF_MAX_NUM) {
  90. /* call device class handle function */
  91. return (usb_reqsta)udev->dev.class_core->req_proc(udev, req);
  92. }
  93. }
  94. return REQ_NOTSUPP;
  95. }
  96. /*!
  97. \brief handle USB vendor request
  98. \param[in] udev: pointer to USB device instance
  99. \param[in] req: pointer to USB vendor request
  100. \param[out] none
  101. \retval USB device request status
  102. */
  103. usb_reqsta usbd_vendor_request(usb_core_driver* udev, usb_req* req)
  104. {
  105. /* added by user... */
  106. return REQ_SUPP;
  107. }
  108. /*!
  109. \brief no operation, just for reserved
  110. \param[in] udev: pointer to USB device instance
  111. \param[in] req: pointer to USB vendor request
  112. \param[out] none
  113. \retval USB device request status
  114. */
  115. static usb_reqsta _usb_std_reserved(usb_core_driver* udev, usb_req* req)
  116. {
  117. /* no operation... */
  118. return REQ_NOTSUPP;
  119. }
  120. /*!
  121. \brief get the device descriptor
  122. \param[in] udev: pointer to USB device instance
  123. \param[in] index: no use
  124. \param[out] len: data length pointer
  125. \retval descriptor buffer pointer
  126. */
  127. static uint8_t* _usb_dev_desc_get(usb_core_driver* udev, uint8_t index, uint16_t* len)
  128. {
  129. *len = udev->dev.desc.dev_desc[0];
  130. return udev->dev.desc.dev_desc;
  131. }
  132. /*!
  133. \brief get the configuration descriptor
  134. \brief[in] udev: pointer to USB device instance
  135. \brief[in] index: no use
  136. \param[out] len: data length pointer
  137. \retval descriptor buffer pointer
  138. */
  139. static uint8_t* _usb_config_desc_get(usb_core_driver* udev, uint8_t index, uint16_t* len)
  140. {
  141. *len = udev->dev.desc.config_desc[2];
  142. return udev->dev.desc.config_desc;
  143. }
  144. /*!
  145. \brief get the BOS descriptor
  146. \brief[in] udev: pointer to USB device instance
  147. \brief[in] index: no use
  148. \param[out] len: data length pointer
  149. \retval descriptor buffer pointer
  150. */
  151. static uint8_t* _usb_bos_desc_get(usb_core_driver* udev, uint8_t index, uint16_t* len)
  152. {
  153. *len = udev->dev.desc.bos_desc[2];
  154. return udev->dev.desc.bos_desc;
  155. }
  156. /*!
  157. \brief get string descriptor
  158. \param[in] udev: pointer to USB device instance
  159. \param[in] index: string descriptor index
  160. \param[out] len: pointer to string length
  161. \retval descriptor buffer pointer
  162. */
  163. static uint8_t* _usb_str_desc_get(usb_core_driver* udev, uint8_t index, uint16_t* len)
  164. {
  165. uint8_t* desc = udev->dev.desc.strings[index];
  166. *len = desc[0];
  167. return desc;
  168. }
  169. /*!
  170. \brief handle Get_Status request
  171. \param[in] udev: pointer to USB device instance
  172. \param[in] req: pointer to USB device request
  173. \param[out] none
  174. \retval USB device request status
  175. */
  176. static usb_reqsta _usb_std_getstatus(usb_core_driver* udev, usb_req* req)
  177. {
  178. uint8_t recp = BYTE_LOW(req->wIndex);
  179. usb_transc* transc = &udev->dev.transc_in[0];
  180. static uint8_t status[2] = {0};
  181. switch (req->bmRequestType & USB_RECPTYPE_MASK) {
  182. case USB_RECPTYPE_DEV:
  183. if ((USBD_ADDRESSED == udev->dev.cur_status) || \
  184. (USBD_CONFIGURED == udev->dev.cur_status)) {
  185. if (udev->dev.pm.power_mode) {
  186. status[0] = USB_STATUS_SELF_POWERED;
  187. } else {
  188. status[0] = 0U;
  189. }
  190. if (udev->dev.pm.dev_remote_wakeup) {
  191. status[0] |= USB_STATUS_REMOTE_WAKEUP;
  192. } else {
  193. status[0] = 0U;
  194. }
  195. transc->xfer_buf = status;
  196. transc->remain_len = 2U;
  197. return REQ_SUPP;
  198. }
  199. break;
  200. case USB_RECPTYPE_ITF:
  201. if ((USBD_CONFIGURED == udev->dev.cur_status) && (recp <= USBD_ITF_MAX_NUM)) {
  202. transc->xfer_buf = status;
  203. transc->remain_len = 2U;
  204. return REQ_SUPP;
  205. }
  206. break;
  207. case USB_RECPTYPE_EP:
  208. if (USBD_CONFIGURED == udev->dev.cur_status) {
  209. if (0x80U == (recp & 0x80U)) {
  210. status[0] = udev->dev.transc_in[EP_ID(recp)].ep_stall;
  211. } else {
  212. status[0] = udev->dev.transc_out[recp].ep_stall;
  213. }
  214. transc->xfer_buf = status;
  215. transc->remain_len = 2U;
  216. return REQ_SUPP;
  217. }
  218. break;
  219. default:
  220. break;
  221. }
  222. return REQ_NOTSUPP;
  223. }
  224. /*!
  225. \brief handle USB Clear_Feature request
  226. \param[in] udev: pointer to USB device instance
  227. \param[in] req: USB device request
  228. \param[out] none
  229. \retval USB device request status
  230. */
  231. static usb_reqsta _usb_std_clearfeature(usb_core_driver* udev, usb_req* req)
  232. {
  233. uint8_t ep = 0;
  234. switch (req->bmRequestType & USB_RECPTYPE_MASK) {
  235. case USB_RECPTYPE_DEV:
  236. if ((USBD_ADDRESSED == udev->dev.cur_status) || \
  237. (USBD_CONFIGURED == udev->dev.cur_status)) {
  238. /* clear device remote wakeup feature */
  239. if (USB_FEATURE_REMOTE_WAKEUP == req->wValue) {
  240. udev->dev.pm.dev_remote_wakeup = 0U;
  241. return REQ_SUPP;
  242. }
  243. }
  244. break;
  245. case USB_RECPTYPE_ITF:
  246. break;
  247. case USB_RECPTYPE_EP:
  248. /* get endpoint address */
  249. ep = BYTE_LOW(req->wIndex);
  250. if (USBD_CONFIGURED == udev->dev.cur_status) {
  251. /* clear endpoint halt feature */
  252. if ((USB_FEATURE_EP_HALT == req->wValue) && (!CTL_EP(ep))) {
  253. usbd_ep_stall_clear(udev, ep);
  254. udev->dev.class_core->req_proc(udev, req);
  255. }
  256. return REQ_SUPP;
  257. }
  258. break;
  259. default:
  260. break;
  261. }
  262. return REQ_NOTSUPP;
  263. }
  264. /*!
  265. \brief handle USB Set_Feature request
  266. \param[in] udev: pointer to USB device instance
  267. \param[in] req: pointer to USB device request
  268. \param[out] none
  269. \retval USB device request status
  270. */
  271. static usb_reqsta _usb_std_setfeature(usb_core_driver* udev, usb_req* req)
  272. {
  273. uint8_t ep = 0;
  274. switch (req->bmRequestType & USB_RECPTYPE_MASK) {
  275. case USB_RECPTYPE_DEV:
  276. if ((USBD_ADDRESSED == udev->dev.cur_status) || \
  277. (USBD_CONFIGURED == udev->dev.cur_status)) {
  278. /* set device remote wakeup feature */
  279. if (USB_FEATURE_REMOTE_WAKEUP == req->wValue) {
  280. udev->dev.pm.dev_remote_wakeup = 1U;
  281. }
  282. return REQ_SUPP;
  283. }
  284. break;
  285. case USB_RECPTYPE_ITF:
  286. break;
  287. case USB_RECPTYPE_EP:
  288. /* get endpoint address */
  289. ep = BYTE_LOW(req->wIndex);
  290. if (USBD_CONFIGURED == udev->dev.cur_status) {
  291. /* set endpoint halt feature */
  292. if ((USB_FEATURE_EP_HALT == req->wValue) && (!CTL_EP(ep))) {
  293. usbd_ep_stall(udev, ep);
  294. }
  295. return REQ_SUPP;
  296. }
  297. break;
  298. default:
  299. break;
  300. }
  301. return REQ_NOTSUPP;
  302. }
  303. /*!
  304. \brief handle USB Set_Address request
  305. \param[in] udev: pointer to USB device instance
  306. \param[in] req: pointer to USB device request
  307. \param[out] none
  308. \retval USB device request status
  309. */
  310. static usb_reqsta _usb_std_setaddress(usb_core_driver* udev, usb_req* req)
  311. {
  312. if ((0U == req->wIndex) && (0U == req->wLength)) {
  313. udev->dev.dev_addr = (uint8_t)(req->wValue) & 0x7FU;
  314. if (udev->dev.cur_status != USBD_CONFIGURED) {
  315. usbd_addr_set(udev, udev->dev.dev_addr);
  316. if (udev->dev.dev_addr) {
  317. udev->dev.cur_status = USBD_ADDRESSED;
  318. } else {
  319. udev->dev.cur_status = USBD_DEFAULT;
  320. }
  321. return REQ_SUPP;
  322. }
  323. }
  324. return REQ_NOTSUPP;
  325. }
  326. /*!
  327. \brief handle USB Get_Descriptor request
  328. \param[in] udev: pointer to USB device instance
  329. \param[in] req: pointer to USB device request
  330. \param[out] none
  331. \retval USB device request status
  332. */
  333. static usb_reqsta _usb_std_getdescriptor(usb_core_driver* udev, usb_req* req)
  334. {
  335. uint8_t desc_type = 0;
  336. uint8_t desc_index = 0;
  337. usb_transc* transc = &udev->dev.transc_in[0];
  338. /* get device standard descriptor */
  339. switch (req->bmRequestType & USB_RECPTYPE_MASK) {
  340. case USB_RECPTYPE_DEV:
  341. desc_type = BYTE_HIGH(req->wValue);
  342. desc_index = BYTE_LOW(req->wValue);
  343. switch (desc_type) {
  344. case USB_DESCTYPE_DEV:
  345. transc->xfer_buf = std_desc_get[desc_type - 1U](udev, desc_index, (uint16_t*) & (transc->remain_len));
  346. if (64U == req->wLength) {
  347. transc->remain_len = 8U;
  348. }
  349. break;
  350. case USB_DESCTYPE_CONFIG:
  351. transc->xfer_buf = std_desc_get[desc_type - 1U](udev, desc_index, (uint16_t*) & (transc->remain_len));
  352. break;
  353. case USB_DESCTYPE_STR:
  354. if (desc_index < STR_IDX_MAX) {
  355. transc->xfer_buf = std_desc_get[desc_type - 1U](udev, desc_index, (uint16_t*) & (transc->remain_len));
  356. }
  357. break;
  358. case USB_DESCTYPE_ITF:
  359. case USB_DESCTYPE_EP:
  360. case USB_DESCTYPE_DEV_QUALIFIER:
  361. case USB_DESCTYPE_OTHER_SPD_CONFIG:
  362. case USB_DESCTYPE_ITF_POWER:
  363. break;
  364. case USB_DESCTYPE_BOS:
  365. transc->xfer_buf = _usb_bos_desc_get(udev, desc_index, (uint16_t*) & (transc->remain_len));
  366. break;
  367. default:
  368. break;
  369. }
  370. break;
  371. case USB_RECPTYPE_ITF:
  372. /* get device class special descriptor */
  373. return (usb_reqsta)(udev->dev.class_core->req_proc(udev, req));
  374. case USB_RECPTYPE_EP:
  375. break;
  376. default:
  377. break;
  378. }
  379. if ((0U != transc->remain_len) && (0U != req->wLength)) {
  380. if (transc->remain_len < req->wLength) {
  381. if ((transc->remain_len >= transc->max_len) && (0U == (transc->remain_len % transc->max_len))) {
  382. udev->dev.control.ctl_zlp = 1;
  383. }
  384. } else {
  385. transc->remain_len = req->wLength;
  386. }
  387. return REQ_SUPP;
  388. }
  389. return REQ_NOTSUPP;
  390. }
  391. /*!
  392. \brief handle USB Set_Descriptor request
  393. \param[in] udev: pointer to USB device instance
  394. \param[in] req: pointer to USB device request
  395. \param[out] none
  396. \retval USB device request status
  397. */
  398. static usb_reqsta _usb_std_setdescriptor(usb_core_driver* udev, usb_req* req)
  399. {
  400. /* no handle... */
  401. return REQ_SUPP;
  402. }
  403. /*!
  404. \brief handle USB Get_Configuration request
  405. \param[in] udev: pointer to USB device instance
  406. \param[in] req: pointer to USB device request
  407. \param[out] none
  408. \retval USB device request status
  409. */
  410. static usb_reqsta _usb_std_getconfiguration(usb_core_driver* udev, usb_req* req)
  411. {
  412. usb_transc* transc = &udev->dev.transc_in[0];
  413. switch (udev->dev.cur_status) {
  414. case USBD_ADDRESSED:
  415. if (USB_DEFAULT_CONFIG == udev->dev.config) {
  416. transc->xfer_buf = &(udev->dev.config);
  417. transc->remain_len = 1U;
  418. return REQ_SUPP;
  419. }
  420. break;
  421. case USBD_CONFIGURED:
  422. if (udev->dev.config != USB_DEFAULT_CONFIG) {
  423. transc->xfer_buf = &(udev->dev.config);
  424. transc->remain_len = 1U;
  425. return REQ_SUPP;
  426. }
  427. break;
  428. default:
  429. break;
  430. }
  431. return REQ_NOTSUPP;
  432. }
  433. /*!
  434. \brief handle USB Set_Configuration request
  435. \param[in] udev: pointer to USB device instance
  436. \param[in] req: pointer to USB device request
  437. \param[out] none
  438. \retval USB device request status
  439. */
  440. static usb_reqsta _usb_std_setconfiguration(usb_core_driver* udev, usb_req* req)
  441. {
  442. static uint8_t config;
  443. config = (uint8_t)(req->wValue);
  444. if (config <= USBD_CFG_MAX_NUM) {
  445. switch (udev->dev.cur_status) {
  446. case USBD_ADDRESSED:
  447. if (config) {
  448. udev->dev.class_core->init(udev, config);
  449. udev->dev.config = config;
  450. udev->dev.cur_status = USBD_CONFIGURED;
  451. }
  452. return REQ_SUPP;
  453. case USBD_CONFIGURED:
  454. if (USB_DEFAULT_CONFIG == config) {
  455. udev->dev.class_core->deinit(udev, config);
  456. udev->dev.config = config;
  457. udev->dev.cur_status = USBD_ADDRESSED;
  458. } else if (config != udev->dev.config) {
  459. /* clear old configuration */
  460. udev->dev.class_core->deinit(udev, config);
  461. /* set new configuration */
  462. udev->dev.config = config;
  463. udev->dev.class_core->init(udev, config);
  464. }
  465. return REQ_SUPP;
  466. case USBD_DEFAULT:
  467. break;
  468. default:
  469. break;
  470. }
  471. }
  472. return REQ_NOTSUPP;
  473. }
  474. /*!
  475. \brief handle USB Get_Interface request
  476. \param[in] udev: pointer to USB device instance
  477. \param[in] req: pointer to USB device request
  478. \param[out] none
  479. \retval USB device request status
  480. */
  481. static usb_reqsta _usb_std_getinterface(usb_core_driver* udev, usb_req* req)
  482. {
  483. switch (udev->dev.cur_status) {
  484. case USBD_DEFAULT:
  485. break;
  486. case USBD_ADDRESSED:
  487. break;
  488. case USBD_CONFIGURED:
  489. if (BYTE_LOW(req->wIndex) <= USBD_ITF_MAX_NUM) {
  490. usb_transc* transc = &udev->dev.transc_in[0];
  491. transc->xfer_buf = &(udev->dev.class_core->alter_set);
  492. transc->remain_len = 1U;
  493. return REQ_SUPP;
  494. }
  495. break;
  496. default:
  497. break;
  498. }
  499. return REQ_NOTSUPP;
  500. }
  501. /*!
  502. \brief handle USB Set_Interface request
  503. \param[in] udev: pointer to USB device instance
  504. \param[in] req: pointer to USB device request
  505. \param[out] none
  506. \retval USB device request status
  507. */
  508. static usb_reqsta _usb_std_setinterface(usb_core_driver* udev, usb_req* req)
  509. {
  510. switch (udev->dev.cur_status) {
  511. case USBD_DEFAULT:
  512. break;
  513. case USBD_ADDRESSED:
  514. break;
  515. case USBD_CONFIGURED:
  516. if (BYTE_LOW(req->wIndex) <= USBD_ITF_MAX_NUM) {
  517. udev->dev.class_core->alter_set = req->wValue;
  518. return REQ_SUPP;
  519. }
  520. break;
  521. default:
  522. break;
  523. }
  524. return REQ_NOTSUPP;
  525. }
  526. /*!
  527. \brief handle USB SynchFrame request
  528. \param[in] udev: pointer to USB device instance
  529. \param[in] req: pointer to USB device request
  530. \param[out] none
  531. \retval USB device request status
  532. */
  533. static usb_reqsta _usb_std_synchframe(usb_core_driver* udev, usb_req* req)
  534. {
  535. /* no handle... */
  536. return REQ_SUPP;
  537. }
  538. /*!
  539. \brief handle USB enumeration error
  540. \param[in] udev: pointer to USB device instance
  541. \param[in] req: pointer to USB device request
  542. \param[out] none
  543. \retval none
  544. */
  545. void usbd_enum_error(usb_core_driver* udev, usb_req* req)
  546. {
  547. usbd_ep_stall(udev, 0x80);
  548. usbd_ep_stall(udev, 0x00);
  549. usb_ctlep_startout(udev);
  550. }
  551. /*!
  552. \brief convert hex 32bits value into unicode char
  553. \param[in] value: hex 32bits value
  554. \param[in] pbuf: buffer pointer to store unicode char
  555. \param[in] len: value length
  556. \param[out] none
  557. \retval none
  558. */
  559. void int_to_unicode(uint32_t value, uint8_t* pbuf, uint8_t len)
  560. {
  561. uint8_t index = 0;
  562. for (index = 0; index < len; index++) {
  563. if ((value >> 28) < 0x0A) {
  564. pbuf[2 * index] = (value >> 28) + '0';
  565. } else {
  566. pbuf[2 * index] = (value >> 28) + 'A' - 10;
  567. }
  568. value = value << 4;
  569. pbuf[2 * index + 1] = 0;
  570. }
  571. }