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

@ -30,7 +30,7 @@
#define __USB_HID_H
#ifdef __cplusplus
extern "C" {
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
@ -39,22 +39,23 @@
/** @addtogroup STM32_USB_DEVICE_LIBRARY
* @{
*/
/** @defgroup USBD_HID
* @brief This file is the Header file for usbd_hid.c
* @{
*/
*/
/** @defgroup USBD_HID_Exported_Defines
* @{
*/
*/
#define HID_EPIN_ADDR 0x81
#define HID_EPIN_SIZE 0x04
#define USB_HID_CONFIG_DESC_SIZ 34
#define USB_HID_DESC_SIZ 9
#define HID_MOUSE_REPORT_DESC_SIZE 74
#define HID_KEYBD_REPORT_DESC_SIZE 63
#define HID_DESCRIPTOR_TYPE 0x21
#define HID_REPORT_DESC 0x22
@ -73,55 +74,51 @@
#define HID_REQ_GET_REPORT 0x01
/**
* @}
*/
*/
/** @defgroup USBD_CORE_Exported_TypesDefinitions
* @{
*/
typedef enum
{
HID_IDLE = 0,
HID_BUSY,
}
HID_StateTypeDef;
typedef struct
{
uint32_t Protocol;
uint32_t IdleState;
uint32_t AltSetting;
HID_StateTypeDef state;
}
USBD_HID_HandleTypeDef;
typedef enum {
HID_IDLE = 0,
HID_BUSY,
} HID_StateTypeDef;
typedef struct {
uint32_t Protocol;
uint32_t IdleState;
uint32_t AltSetting;
HID_StateTypeDef state;
} USBD_HID_HandleTypeDef;
/**
* @}
*/
*/
/** @defgroup USBD_CORE_Exported_Macros
* @{
*/
*/
/**
* @}
*/
*/
/** @defgroup USBD_CORE_Exported_Variables
* @{
*/
*/
extern USBD_ClassTypeDef USBD_HID;
#define USBD_HID_CLASS &USBD_HID
extern USBD_ClassTypeDef USBD_HID;
#define USBD_HID_CLASS &USBD_HID
/**
* @}
*/
*/
/** @defgroup USB_CORE_Exported_Functions
* @{
*/
*/
/*- injected dox -*/
@ -132,9 +129,9 @@ extern USBD_ClassTypeDef USBD_HID;
* @param buff: pointer to report
* @retval status
*/
uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev,
uint8_t *report,
uint16_t len);
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev,
uint8_t *report,
uint16_t len);
@ -145,11 +142,11 @@ uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev,
* @param pdev: device instance
* @retval polling interval
*/
uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev);
uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev);
/**
* @}
*/
*/
#ifdef __cplusplus
}
@ -158,10 +155,10 @@ uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev);
#endif /* __USB_HID_H */
/**
* @}
*/
*/
/**
* @}
*/
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

@ -118,29 +118,34 @@ static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
USBD_ClassTypeDef USBD_HID =
{
USBD_HID_Init,
USBD_HID_DeInit,
USBD_HID_Setup,
NULL, /*EP0_TxSent*/
NULL, /*EP0_RxReady*/
USBD_HID_DataIn, /*DataIn*/
NULL, /*DataOut*/
NULL, /*SOF */
NULL,
NULL,
USBD_HID_GetCfgDesc,
USBD_HID_GetCfgDesc,
USBD_HID_GetCfgDesc,
USBD_HID_GetDeviceQualifierDesc,
.Init = USBD_HID_Init,
.DeInit = USBD_HID_DeInit,
/* Control Endpoints*/
.Setup = USBD_HID_Setup,
.EP0_TxSent = NULL,
.EP0_RxReady = NULL,
/* Class Specific Endpoints*/
.DataIn = USBD_HID_DataIn,
.DataOut = NULL,
.SOF = NULL,
.IsoINIncomplete = NULL, // unused
.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 */
__ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END =
{
0x09, /* bLength: Configuration Descriptor size */
0x09, /* bLength: Configuration Descriptor size */
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
USB_HID_CONFIG_DESC_SIZ,
/* wTotalLength: Bytes returned */
USB_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */
0x00,
0x01, /*bNumInterfaces: 1 interface*/
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
* @retval status
*/
static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev,
uint8_t cfgidx)
static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
{
uint8_t ret = 0;
@ -308,8 +312,7 @@ static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev,
* @param cfgidx: Configuration index
* @retval status
*/
static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev,
uint8_t cfgidx)
static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
{
/* Close HID EPs */
USBD_LL_CloseEP(pdev,
@ -331,8 +334,7 @@ static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev,
* @param req: usb requests
* @retval status
*/
static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev,
USBD_SetupReqTypedef *req)
static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
{
uint16_t len = 0;
uint8_t *pbuf = NULL;
@ -408,9 +410,7 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev,
* @param buff: pointer to report
* @retval status
*/
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev,
uint8_t *report,
uint16_t len)
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len)
{
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
* @retval status
*/
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev,
uint8_t epnum)
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
{
/* Ensure that the FIFO is empty before a new transfer, this condition could

@ -161,7 +161,7 @@ typedef struct _Device_cb
{
uint8_t (*Init) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx);
uint8_t (*DeInit) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx);
/* Control Endpoints*/
/* Control Endpoints*/
uint8_t (*Setup) (struct _USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req);
uint8_t (*EP0_TxSent) (struct _USBD_HandleTypeDef *pdev );
uint8_t (*EP0_RxReady) (struct _USBD_HandleTypeDef *pdev );

Loading…
Cancel
Save