winston1777

Untitled

Oct 1st, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.27 KB | None | 0 0
  1. /**
  2. ******************************************************************************
  3. * @file usbd_hid_core.c
  4. * @author MCD Application Team
  5. * @version V1.1.0
  6. * @date 19-March-2012
  7. * @brief This file provides the HID core functions.
  8. *
  9. * @verbatim
  10. *
  11. * ===================================================================
  12. * HID Class Description
  13. * ===================================================================
  14. * This module manages the HID class V1.11 following the "Device Class Definition
  15. * for Human Interface Devices (HID) Version 1.11 Jun 27, 2001".
  16. * This driver implements the following aspects of the specification:
  17. * - The Boot Interface Subclass
  18. * - The Mouse protocol
  19. * - Usage Page : Generic Desktop
  20. * - Usage : Joystick)
  21. * - Collection : Application
  22. *
  23. * @note In HS mode and when the DMA is used, all variables and data structures
  24. * dealing with the DMA during the transaction process should be 32-bit aligned.
  25. *
  26. *
  27. * @endverbatim
  28. *
  29. ******************************************************************************
  30. * @attention
  31. *
  32. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  33. *
  34. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  35. * You may not use this file except in compliance with the License.
  36. * You may obtain a copy of the License at:
  37. *
  38. * http://www.st.com/software_license_agreement_liberty_v2
  39. *
  40. * Unless required by applicable law or agreed to in writing, software
  41. * distributed under the License is distributed on an "AS IS" BASIS,
  42. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  43. * See the License for the specific language governing permissions and
  44. * limitations under the License.
  45. *
  46. ******************************************************************************
  47. */
  48.  
  49. /* Includes ------------------------------------------------------------------*/
  50. #include "usbd_hid_core.h"
  51. #include "usbd_desc.h"
  52. #include "usbd_req.h"
  53.  
  54.  
  55. /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
  56. * @{
  57. */
  58.  
  59.  
  60. /** @defgroup USBD_HID
  61. * @brief usbd core module
  62. * @{
  63. */
  64.  
  65. /** @defgroup USBD_HID_Private_TypesDefinitions
  66. * @{
  67. */
  68. /**
  69. * @}
  70. */
  71.  
  72.  
  73. /** @defgroup USBD_HID_Private_Defines
  74. * @{
  75. */
  76.  
  77. /**
  78. * @}
  79. */
  80.  
  81.  
  82. /** @defgroup USBD_HID_Private_Macros
  83. * @{
  84. */
  85. /**
  86. * @}
  87. */
  88.  
  89.  
  90.  
  91.  
  92. /** @defgroup USBD_HID_Private_FunctionPrototypes
  93. * @{
  94. */
  95.  
  96.  
  97. static uint8_t USBD_HID_Init (void *pdev,
  98. uint8_t cfgidx);
  99.  
  100. static uint8_t USBD_HID_DeInit (void *pdev,
  101. uint8_t cfgidx);
  102.  
  103. static uint8_t USBD_HID_Setup (void *pdev,
  104. USB_SETUP_REQ *req);
  105.  
  106. static uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length);
  107.  
  108. static uint8_t USBD_HID_DataIn (void *pdev, uint8_t epnum);
  109. /**
  110. * @}
  111. */
  112.  
  113. /** @defgroup USBD_HID_Private_Variables
  114. * @{
  115. */
  116.  
  117. USBD_Class_cb_TypeDef USBD_HID_cb =
  118. {
  119. USBD_HID_Init,
  120. USBD_HID_DeInit,
  121. USBD_HID_Setup,
  122. NULL, /*EP0_TxSent*/
  123. NULL, /*EP0_RxReady*/
  124. USBD_HID_DataIn, /*DataIn*/
  125. NULL, /*DataOut*/
  126. NULL, /*SOF */
  127. NULL,
  128. NULL,
  129. USBD_HID_GetCfgDesc,
  130. #ifdef USB_OTG_HS_CORE
  131. USBD_HID_GetCfgDesc, /* use same config as per FS */
  132. #endif
  133. };
  134.  
  135. #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
  136. #if defined ( __ICCARM__ ) /*!< IAR Compiler */
  137. #pragma data_alignment=4
  138. #endif
  139. #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
  140. __ALIGN_BEGIN static uint32_t USBD_HID_AltSet __ALIGN_END = 0;
  141.  
  142. #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
  143. #if defined ( __ICCARM__ ) /*!< IAR Compiler */
  144. #pragma data_alignment=4
  145. #endif
  146. #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
  147. __ALIGN_BEGIN static uint32_t USBD_HID_Protocol __ALIGN_END = 0;
  148.  
  149. #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
  150. #if defined ( __ICCARM__ ) /*!< IAR Compiler */
  151. #pragma data_alignment=4
  152. #endif
  153. #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
  154. __ALIGN_BEGIN static uint32_t USBD_HID_IdleState __ALIGN_END = 0;
  155.  
  156. #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
  157. #if defined ( __ICCARM__ ) /*!< IAR Compiler */
  158. #pragma data_alignment=4
  159. #endif
  160. #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
  161. /* USB HID device Configuration Descriptor */
  162. __ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END =
  163. {
  164. 0x09, /* bLength: Configuration Descriptor size */
  165. USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
  166. USB_HID_CONFIG_DESC_SIZ,
  167. /* wTotalLength: Bytes returned */
  168. 0x00,
  169. 0x01, /*bNumInterfaces: 1 interface*/
  170. 0x01, /*bConfigurationValue: Configuration value*/
  171. 0x00, /*iConfiguration: Index of string descriptor describing
  172. the configuration*/
  173. 0xE0, /*bmAttributes: bus powered and Support Remote Wake-up */
  174. 0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
  175.  
  176. /************** Descriptor of Joystick Mouse interface ****************/
  177. /* 09 */
  178. 0x09, /*bLength: Interface Descriptor size*/
  179. USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptor type*/
  180. 0x00, /*bInterfaceNumber: Number of Interface*/
  181. 0x00, /*bAlternateSetting: Alternate setting*/
  182. 0x01, /*bNumEndpoints*/
  183. 0x03, /*bInterfaceClass: HID*/
  184. 0x00, /*0x01*/ /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
  185. 0x00, /*0x02*/ /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
  186. 0, /*iInterface: Index of string descriptor*/
  187. /******************** Descriptor of Joystick Mouse HID ********************/
  188. /* 18 */
  189. 0x09, /*bLength: HID Descriptor size*/
  190. HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
  191. 0x11, /*bcdHID: HID Class Spec release number*/
  192. 0x01,
  193. 0x00, /*bCountryCode: Hardware target country*/
  194. 0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/
  195. 0x22, /*bDescriptorType*/
  196. HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
  197. 0x00,
  198. /******************** Descriptor of Mouse endpoint ********************/
  199. /* 27 */
  200. 0x07, /*bLength: Endpoint Descriptor size*/
  201. USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/
  202.  
  203. HID_IN_EP, /*bEndpointAddress: Endpoint Address (IN)*/
  204. 0x03, /*bmAttributes: Interrupt endpoint*/
  205. HID_IN_PACKET, /*wMaxPacketSize: 4 Byte max */
  206. 0x00,
  207. 0x0A, /*bInterval: Polling Interval (10 ms)*/
  208. /* 34 */
  209. } ;
  210.  
  211. #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
  212. #if defined ( __ICCARM__ ) /*!< IAR Compiler */
  213. #pragma data_alignment=4
  214. #endif
  215. /* USB HID device Configuration Descriptor */
  216. __ALIGN_BEGIN static uint8_t USBD_HID_Desc[USB_HID_DESC_SIZ] __ALIGN_END=
  217. {
  218. /* 18 */
  219. 0x09, /*bLength: HID Descriptor size*/
  220. HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
  221. 0x11, /*bcdHID: HID Class Spec release number*/
  222. 0x01,
  223. 0x00, /*bCountryCode: Hardware target country*/
  224. 0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/
  225. 0x22, /*bDescriptorType*/
  226. HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
  227. 0x00,
  228. };
  229. #endif
  230.  
  231.  
  232. #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
  233. #if defined ( __ICCARM__ ) /*!< IAR Compiler */
  234. #pragma data_alignment=4
  235. #endif
  236. #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
  237. __ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END =
  238. {
  239. /* 47 */
  240. 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
  241. 0x09, 0x06, // USAGE (Keyboard)
  242. 0xa1, 0x01, // COLLECTION (Application)
  243. 0x85, 0x01, // REPORT_ID (1)
  244. 0x05, 0x07, // USAGE_PAGE (Keyboard)
  245. 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
  246. 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
  247. 0x15, 0x00, // LOGICAL_MINIMUM (0)
  248. 0x25, 0x01, // LOGICAL_MAXIMUM (1)
  249. 0x75, 0x01, // REPORT_SIZE (1)
  250. 0x95, 0x08, // REPORT_COUNT (8)
  251. 0x81, 0x02, // INPUT (Data,Var,Abs)
  252. 0x95, 0x01, // REPORT_COUNT (1)
  253. 0x75, 0x08, // REPORT_SIZE (8)
  254. 0x81, 0x03, // INPUT (Cnst,Var,Abs)
  255. 0x95, 0x06, // REPORT_COUNT (6)
  256. 0x75, 0x08, // REPORT_SIZE (8)
  257. 0x15, 0x00, // LOGICAL_MINIMUM (0)
  258. 0x25, 0x65, // LOGICAL_MAXIMUM (101)
  259. 0x05, 0x07, // USAGE_PAGE (Keyboard)
  260. 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
  261. 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
  262. 0x81, 0x00, // INPUT (Data,Ary,Abs)
  263. 0xc0, // END_COLLECTION
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276. /* 54 */
  277. 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
  278. 0x09, 0x02, // USAGE (Mouse)
  279. 0xa1, 0x01, // COLLECTION (Application)
  280. 0x09, 0x01, // USAGE (Pointer)
  281. 0xa1, 0x00, // COLLECTION (Physical)
  282. 0x85, 0x02, // REPORT_ID (2)
  283. 0x05, 0x09, // USAGE_PAGE (Button)
  284. 0x19, 0x01, // USAGE_MINIMUM (Button 1)
  285. 0x29, 0x03, // USAGE_MAXIMUM (Button 3)
  286. 0x15, 0x00, // LOGICAL_MINIMUM (0)
  287. 0x25, 0x01, // LOGICAL_MAXIMUM (1)
  288. 0x95, 0x03, // REPORT_COUNT (3)
  289. 0x75, 0x01, // REPORT_SIZE (1)
  290. 0x81, 0x02, // INPUT (Data,Var,Abs)
  291. 0x95, 0x01, // REPORT_COUNT (1)
  292. 0x75, 0x05, // REPORT_SIZE (5)
  293. 0x81, 0x03, // INPUT (Cnst,Var,Abs)
  294. 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
  295. 0x09, 0x30, // USAGE (X)
  296. 0x09, 0x31, // USAGE (Y)
  297. 0x09, 0x38, // USAGE (Wheel)
  298. 0x15, 0x81, // LOGICAL_MINIMUM (-127)
  299. 0x25, 0x7f, // LOGICAL_MAXIMUM (127)
  300. 0x75, 0x08, // REPORT_SIZE (8)
  301. 0x95, 0x03, // REPORT_COUNT (3)
  302. 0x81, 0x06, // INPUT (Data,Var,Rel)
  303. 0xc0, // END_COLLECTION
  304. 0xc0, // END_COLLECTION
  305.  
  306. /* 48 */
  307. 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
  308. 0x09, 0x05, // USAGE (Game Pad)
  309. 0xa1, 0x01, // COLLECTION (Application)
  310. 0xa1, 0x00, // COLLECTION (Physical)
  311. 0x85, 0x03, // REPORT_ID (3)
  312. 0x05, 0x09, // USAGE_PAGE (Button)
  313. 0x19, 0x01, // USAGE_MINIMUM (Button 1)
  314. 0x29, 0x10, // USAGE_MAXIMUM (Button 16)
  315. 0x15, 0x00, // LOGICAL_MINIMUM (0)
  316. 0x25, 0x01, // LOGICAL_MAXIMUM (1)
  317. 0x95, 0x10, // REPORT_COUNT (16)
  318. 0x75, 0x01, // REPORT_SIZE (1)
  319. 0x81, 0x02, // INPUT (Data,Var,Abs)
  320. 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
  321. 0x09, 0x30, // USAGE (X)
  322. 0x09, 0x31, // USAGE (Y)
  323. 0x09, 0x32, // USAGE (Z)
  324. 0x09, 0x33, // USAGE (Rx)
  325. 0x15, 0x81, // LOGICAL_MINIMUM (-127)
  326. 0x25, 0x7f, // LOGICAL_MAXIMUM (127)
  327. 0x75, 0x08, // REPORT_SIZE (8)
  328. 0x95, 0x04, // REPORT_COUNT (4)
  329. 0x81, 0x02, // INPUT (Data,Var,Abs)
  330. 0xc0, // END_COLLECTION
  331. 0xc0, // END_COLLECTION
  332.  
  333. /* 48 */
  334. 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
  335. 0x09, 0x05, // USAGE (Game Pad)
  336. 0xa1, 0x01, // COLLECTION (Application)
  337. 0xa1, 0x00, // COLLECTION (Physical)
  338. 0x85, 0x04, // REPORT_ID (4)
  339. 0x05, 0x09, // USAGE_PAGE (Button)
  340. 0x19, 0x01, // USAGE_MINIMUM (Button 1)
  341. 0x29, 0x10, // USAGE_MAXIMUM (Button 16)
  342. 0x15, 0x00, // LOGICAL_MINIMUM (0)
  343. 0x25, 0x01, // LOGICAL_MAXIMUM (1)
  344. 0x95, 0x10, // REPORT_COUNT (16)
  345. 0x75, 0x01, // REPORT_SIZE (1)
  346. 0x81, 0x02, // INPUT (Data,Var,Abs)
  347. 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
  348. 0x09, 0x30, // USAGE (X)
  349. 0x09, 0x31, // USAGE (Y)
  350. 0x09, 0x32, // USAGE (Z)
  351. 0x09, 0x33, // USAGE (Rx)
  352. 0x15, 0x81, // LOGICAL_MINIMUM (-127)
  353. 0x25, 0x7f, // LOGICAL_MAXIMUM (127)
  354. 0x75, 0x08, // REPORT_SIZE (8)
  355. 0x95, 0x04, // REPORT_COUNT (4)
  356. 0x81, 0x02, // INPUT (Data,Var,Abs)
  357. 0xc0, // END_COLLECTION
  358. 0xc0, // END_COLLECTION
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366. 0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
  367. 0x09, 0x01, // USAGE (Consumer Control)
  368. 0xa1, 0x01, // COLLECTION (Application)
  369. 0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
  370. 0x85, 0x05, // REPORT_ID (5)
  371. 0x09, 0xe2, // USAGE (Mute)
  372. 0x09, 0xe9, // USAGE (Volume Up)
  373. 0x09, 0xea, // USAGE (Volume Down)
  374. 0x09, 0xb0, // USAGE (Play)
  375. 0x09, 0xb1, // USAGE (Pause)
  376. 0x09, 0xb7, // USAGE (Stop)
  377. 0x15, 0x01, // LOGICAL_MINIMUM (1)
  378. 0x25, 0x06, // LOGICAL_MAXIMUM (6)
  379. 0x75, 0x08, // REPORT_SIZE (8)
  380. 0x95, 0x01, // REPORT_COUNT (1)
  381. 0x81, 0x00, // INPUT (Data,Ary,Abs)
  382. 0x95, 0x01, // REPORT_COUNT (1)
  383. 0x75, 0x10, // REPORT_SIZE (16)
  384. 0x81, 0x03, // INPUT (Cnst,Var,Abs)
  385. 0xc0 // END_COLLECTION
  386.  
  387. /* 0x05, 0x01,
  388. 0x09, 0x02,
  389. 0xA1, 0x01,
  390. 0x09, 0x01,
  391.  
  392. 0xA1, 0x00,
  393. 0x05, 0x09,
  394. 0x19, 0x01,
  395. 0x29, 0x03,
  396.  
  397. 0x15, 0x00,
  398. 0x25, 0x01,
  399. 0x95, 0x03,
  400. 0x75, 0x01,
  401.  
  402. 0x81, 0x02,
  403. 0x95, 0x01,
  404. 0x75, 0x05,
  405. 0x81, 0x01,
  406.  
  407. 0x05, 0x01,
  408. 0x09, 0x30,
  409. 0x09, 0x31,
  410. 0x09, 0x38,
  411.  
  412. 0x15, 0x81,
  413. 0x25, 0x7F,
  414. 0x75, 0x08,
  415. 0x95, 0x03,
  416.  
  417. 0x81, 0x06,
  418. 0xC0, 0x09,
  419. 0x3c, 0x05,
  420. 0xff, 0x09,
  421.  
  422. 0x01, 0x15,
  423. 0x00, 0x25,
  424. 0x01, 0x75,
  425. 0x01, 0x95,
  426.  
  427. 0x02, 0xb1,
  428. 0x22, 0x75,
  429. 0x06, 0x95,
  430. 0x01, 0xb1,
  431.  
  432. 0x01, 0xc0*/
  433. };
  434.  
  435. /**
  436. * @}
  437. */
  438.  
  439. /** @defgroup USBD_HID_Private_Functions
  440. * @{
  441. */
  442.  
  443. /**
  444. * @brief USBD_HID_Init
  445. * Initialize the HID interface
  446. * @param pdev: device instance
  447. * @param cfgidx: Configuration index
  448. * @retval status
  449. */
  450. static uint8_t USBD_HID_Init (void *pdev,
  451. uint8_t cfgidx)
  452. {
  453.  
  454. /* Open EP IN */
  455. DCD_EP_Open(pdev,
  456. HID_IN_EP,
  457. HID_IN_PACKET,
  458. USB_OTG_EP_INT);
  459.  
  460. /* Open EP OUT */
  461. DCD_EP_Open(pdev,
  462. HID_OUT_EP,
  463. HID_OUT_PACKET,
  464. USB_OTG_EP_INT);
  465.  
  466. return USBD_OK;
  467. }
  468.  
  469. /**
  470. * @brief USBD_HID_Init
  471. * DeInitialize the HID layer
  472. * @param pdev: device instance
  473. * @param cfgidx: Configuration index
  474. * @retval status
  475. */
  476. static uint8_t USBD_HID_DeInit (void *pdev,
  477. uint8_t cfgidx)
  478. {
  479. /* Close HID EPs */
  480. DCD_EP_Close (pdev , HID_IN_EP);
  481. DCD_EP_Close (pdev , HID_OUT_EP);
  482.  
  483.  
  484. return USBD_OK;
  485. }
  486.  
  487. /**
  488. * @brief USBD_HID_Setup
  489. * Handle the HID specific requests
  490. * @param pdev: instance
  491. * @param req: usb requests
  492. * @retval status
  493. */
  494. static uint8_t USBD_HID_Setup (void *pdev,
  495. USB_SETUP_REQ *req)
  496. {
  497. uint16_t len = 0;
  498. uint8_t *pbuf = NULL;
  499.  
  500. switch (req->bmRequest & USB_REQ_TYPE_MASK)
  501. {
  502. case USB_REQ_TYPE_CLASS :
  503. switch (req->bRequest)
  504. {
  505.  
  506.  
  507. case HID_REQ_SET_PROTOCOL:
  508. USBD_HID_Protocol = (uint8_t)(req->wValue);
  509. break;
  510.  
  511. case HID_REQ_GET_PROTOCOL:
  512. USBD_CtlSendData (pdev,
  513. (uint8_t *)&USBD_HID_Protocol,
  514. 1);
  515. break;
  516.  
  517. case HID_REQ_SET_IDLE:
  518. USBD_HID_IdleState = (uint8_t)(req->wValue >> 8);
  519. break;
  520.  
  521. case HID_REQ_GET_IDLE:
  522. USBD_CtlSendData (pdev,
  523. (uint8_t *)&USBD_HID_IdleState,
  524. 1);
  525. break;
  526.  
  527. default:
  528. USBD_CtlError (pdev, req);
  529. return USBD_FAIL;
  530. }
  531. break;
  532.  
  533. case USB_REQ_TYPE_STANDARD:
  534. switch (req->bRequest)
  535. {
  536. case USB_REQ_GET_DESCRIPTOR:
  537. if( req->wValue >> 8 == HID_REPORT_DESC)
  538. {
  539. len = MIN(HID_MOUSE_REPORT_DESC_SIZE , req->wLength);
  540. pbuf = HID_MOUSE_ReportDesc;
  541. }
  542. else if( req->wValue >> 8 == HID_DESCRIPTOR_TYPE)
  543. {
  544.  
  545. #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
  546. pbuf = USBD_HID_Desc;
  547. #else
  548. pbuf = USBD_HID_CfgDesc + 0x12;
  549. #endif
  550. len = MIN(USB_HID_DESC_SIZ , req->wLength);
  551. }
  552.  
  553. USBD_CtlSendData (pdev,
  554. pbuf,
  555. len);
  556.  
  557. break;
  558.  
  559. case USB_REQ_GET_INTERFACE :
  560. USBD_CtlSendData (pdev,
  561. (uint8_t *)&USBD_HID_AltSet,
  562. 1);
  563. break;
  564.  
  565. case USB_REQ_SET_INTERFACE :
  566. USBD_HID_AltSet = (uint8_t)(req->wValue);
  567. break;
  568. }
  569. }
  570. return USBD_OK;
  571. }
  572.  
  573. /**
  574. * @brief USBD_HID_SendReport
  575. * Send HID Report
  576. * @param pdev: device instance
  577. * @param buff: pointer to report
  578. * @retval status
  579. */
  580. uint8_t USBD_HID_SendReport (USB_OTG_CORE_HANDLE *pdev,
  581. uint8_t *report,
  582. uint16_t len)
  583. {
  584. if (pdev->dev.device_status == USB_OTG_CONFIGURED )
  585. {
  586. DCD_EP_Tx (pdev, HID_IN_EP, report, len);
  587. }
  588. return USBD_OK;
  589. }
  590.  
  591. /**
  592. * @brief USBD_HID_GetCfgDesc
  593. * return configuration descriptor
  594. * @param speed : current device speed
  595. * @param length : pointer data length
  596. * @retval pointer to descriptor buffer
  597. */
  598. static uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length)
  599. {
  600. *length = sizeof (USBD_HID_CfgDesc);
  601. return USBD_HID_CfgDesc;
  602. }
  603.  
  604. /**
  605. * @brief USBD_HID_DataIn
  606. * handle data IN Stage
  607. * @param pdev: device instance
  608. * @param epnum: endpoint index
  609. * @retval status
  610. */
  611. static uint8_t USBD_HID_DataIn (void *pdev,
  612. uint8_t epnum)
  613. {
  614.  
  615. /* Ensure that the FIFO is empty before a new transfer, this condition could
  616. be caused by a new transfer before the end of the previous transfer */
  617. DCD_EP_Flush(pdev, HID_IN_EP);
  618. return USBD_OK;
  619. }
  620.  
  621. /**
  622. * @}
  623. */
  624.  
  625.  
  626. /**
  627. * @}
  628. */
  629.  
  630.  
  631. /**
  632. * @}
  633. */
  634.  
  635. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Add Comment
Please, Sign In to add comment