master
Ondřej Hruška 8 years ago
parent f1abfedd1c
commit 10791c1d80
  1. 19
      Middlewares/ST/STM32_USB_Device_Library/Class/HID/Inc/usbd_hid.h
  2. 53
      Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c

@ -30,7 +30,7 @@
#define __USB_HID_H #define __USB_HID_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
@ -55,6 +55,7 @@
#define USB_HID_CONFIG_DESC_SIZ 34 #define USB_HID_CONFIG_DESC_SIZ 34
#define USB_HID_DESC_SIZ 9 #define USB_HID_DESC_SIZ 9
#define HID_MOUSE_REPORT_DESC_SIZE 74 #define HID_MOUSE_REPORT_DESC_SIZE 74
#define HID_KEYBD_REPORT_DESC_SIZE 63
#define HID_DESCRIPTOR_TYPE 0x21 #define HID_DESCRIPTOR_TYPE 0x21
#define HID_REPORT_DESC 0x22 #define HID_REPORT_DESC 0x22
@ -79,22 +80,18 @@
/** @defgroup USBD_CORE_Exported_TypesDefinitions /** @defgroup USBD_CORE_Exported_TypesDefinitions
* @{ * @{
*/ */
typedef enum typedef enum {
{
HID_IDLE = 0, HID_IDLE = 0,
HID_BUSY, HID_BUSY,
} } HID_StateTypeDef;
HID_StateTypeDef;
typedef struct typedef struct {
{
uint32_t Protocol; uint32_t Protocol;
uint32_t IdleState; uint32_t IdleState;
uint32_t AltSetting; uint32_t AltSetting;
HID_StateTypeDef state; HID_StateTypeDef state;
} } USBD_HID_HandleTypeDef;
USBD_HID_HandleTypeDef;
/** /**
* @} * @}
*/ */
@ -132,7 +129,7 @@ extern USBD_ClassTypeDef USBD_HID;
* @param buff: pointer to report * @param buff: pointer to report
* @retval status * @retval status
*/ */
uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev, uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev,
uint8_t *report, uint8_t *report,
uint16_t len); uint16_t len);
@ -145,7 +142,7 @@ uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev,
* @param pdev: device instance * @param pdev: device instance
* @retval polling interval * @retval polling interval
*/ */
uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev); uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev);
/** /**
* @} * @}

@ -118,20 +118,26 @@ static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
USBD_ClassTypeDef USBD_HID = USBD_ClassTypeDef USBD_HID =
{ {
USBD_HID_Init, .Init = USBD_HID_Init,
USBD_HID_DeInit, .DeInit = USBD_HID_DeInit,
USBD_HID_Setup,
NULL, /*EP0_TxSent*/ /* Control Endpoints*/
NULL, /*EP0_RxReady*/ .Setup = USBD_HID_Setup,
USBD_HID_DataIn, /*DataIn*/ .EP0_TxSent = NULL,
NULL, /*DataOut*/ .EP0_RxReady = NULL,
NULL, /*SOF */
NULL, /* Class Specific Endpoints*/
NULL, .DataIn = USBD_HID_DataIn,
USBD_HID_GetCfgDesc, .DataOut = NULL,
USBD_HID_GetCfgDesc, .SOF = NULL,
USBD_HID_GetCfgDesc, .IsoINIncomplete = NULL, // unused
USBD_HID_GetDeviceQualifierDesc, .IsoOUTIncomplete = NULL, // unused
/* Descriptor getters */
.GetHSConfigDescriptor = USBD_HID_GetCfgDesc,
.GetFSConfigDescriptor = USBD_HID_GetCfgDesc,
.GetOtherSpeedConfigDescriptor = USBD_HID_GetCfgDesc,
.GetDeviceQualifierDescriptor = USBD_HID_GetDeviceQualifierDesc,
}; };
/* USB HID device Configuration Descriptor */ /* USB HID device Configuration Descriptor */
@ -139,8 +145,7 @@ __ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_
{ {
0x09, /* bLength: Configuration Descriptor size */ 0x09, /* bLength: Configuration Descriptor size */
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
USB_HID_CONFIG_DESC_SIZ, USB_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */
/* wTotalLength: Bytes returned */
0x00, 0x00,
0x01, /*bNumInterfaces: 1 interface*/ 0x01, /*bNumInterfaces: 1 interface*/
0x01, /*bConfigurationValue: Configuration value*/ 0x01, /*bConfigurationValue: Configuration value*/
@ -279,8 +284,7 @@ __ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] _
* @param cfgidx: Configuration index * @param cfgidx: Configuration index
* @retval status * @retval status
*/ */
static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
uint8_t cfgidx)
{ {
uint8_t ret = 0; uint8_t ret = 0;
@ -308,8 +312,7 @@ static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev,
* @param cfgidx: Configuration index * @param cfgidx: Configuration index
* @retval status * @retval status
*/ */
static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
uint8_t cfgidx)
{ {
/* Close HID EPs */ /* Close HID EPs */
USBD_LL_CloseEP(pdev, USBD_LL_CloseEP(pdev,
@ -331,8 +334,7 @@ static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev,
* @param req: usb requests * @param req: usb requests
* @retval status * @retval status
*/ */
static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
USBD_SetupReqTypedef *req)
{ {
uint16_t len = 0; uint16_t len = 0;
uint8_t *pbuf = NULL; uint8_t *pbuf = NULL;
@ -408,9 +410,7 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev,
* @param buff: pointer to report * @param buff: pointer to report
* @retval status * @retval status
*/ */
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len)
uint8_t *report,
uint16_t len)
{ {
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *) pdev->pClassData; USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *) pdev->pClassData;
@ -474,8 +474,7 @@ static uint8_t *USBD_HID_GetCfgDesc(uint16_t *length)
* @param epnum: endpoint index * @param epnum: endpoint index
* @retval status * @retval status
*/ */
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
uint8_t epnum)
{ {
/* Ensure that the FIFO is empty before a new transfer, this condition could /* Ensure that the FIFO is empty before a new transfer, this condition could

Loading…
Cancel
Save