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 #define __USB_HID_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
@ -39,22 +39,23 @@
/** @addtogroup STM32_USB_DEVICE_LIBRARY /** @addtogroup STM32_USB_DEVICE_LIBRARY
* @{ * @{
*/ */
/** @defgroup USBD_HID /** @defgroup USBD_HID
* @brief This file is the Header file for usbd_hid.c * @brief This file is the Header file for usbd_hid.c
* @{ * @{
*/ */
/** @defgroup USBD_HID_Exported_Defines /** @defgroup USBD_HID_Exported_Defines
* @{ * @{
*/ */
#define HID_EPIN_ADDR 0x81 #define HID_EPIN_ADDR 0x81
#define HID_EPIN_SIZE 0x04 #define HID_EPIN_SIZE 0x04
#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
@ -73,55 +74,51 @@
#define HID_REQ_GET_REPORT 0x01 #define HID_REQ_GET_REPORT 0x01
/** /**
* @} * @}
*/ */
/** @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 {
uint32_t Protocol;
typedef struct uint32_t IdleState;
{ uint32_t AltSetting;
uint32_t Protocol; HID_StateTypeDef state;
uint32_t IdleState; } USBD_HID_HandleTypeDef;
uint32_t AltSetting;
HID_StateTypeDef state;
}
USBD_HID_HandleTypeDef;
/** /**
* @} * @}
*/ */
/** @defgroup USBD_CORE_Exported_Macros /** @defgroup USBD_CORE_Exported_Macros
* @{ * @{
*/ */
/** /**
* @} * @}
*/ */
/** @defgroup USBD_CORE_Exported_Variables /** @defgroup USBD_CORE_Exported_Variables
* @{ * @{
*/ */
extern USBD_ClassTypeDef USBD_HID; extern USBD_ClassTypeDef USBD_HID;
#define USBD_HID_CLASS &USBD_HID #define USBD_HID_CLASS &USBD_HID
/** /**
* @} * @}
*/ */
/** @defgroup USB_CORE_Exported_Functions /** @defgroup USB_CORE_Exported_Functions
* @{ * @{
*/ */
/*- injected dox -*/ /*- injected dox -*/
@ -132,9 +129,9 @@ 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,11 +142,11 @@ 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);
/** /**
* @} * @}
*/ */
#ifdef __cplusplus #ifdef __cplusplus
} }
@ -158,10 +155,10 @@ uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev);
#endif /* __USB_HID_H */ #endif /* __USB_HID_H */
/** /**
* @} * @}
*/ */
/** /**
* @} * @}
*/ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ /************************ (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_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 */
__ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END = __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_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

@ -161,7 +161,7 @@ typedef struct _Device_cb
{ {
uint8_t (*Init) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx); uint8_t (*Init) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx);
uint8_t (*DeInit) (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 (*Setup) (struct _USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req);
uint8_t (*EP0_TxSent) (struct _USBD_HandleTypeDef *pdev ); uint8_t (*EP0_TxSent) (struct _USBD_HandleTypeDef *pdev );
uint8_t (*EP0_RxReady) (struct _USBD_HandleTypeDef *pdev ); uint8_t (*EP0_RxReady) (struct _USBD_HandleTypeDef *pdev );

Loading…
Cancel
Save