hpw421初始版本
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,270 @@
|
||||
/*!
|
||||
* \file usbd_hid.h
|
||||
*
|
||||
* \brief This file provides the HID core functions.
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author MCD Application Team
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_HID_H
|
||||
#define __USB_HID_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------------------------
|
||||
INCLUDE HEADE FILES
|
||||
------------------------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Macros
|
||||
-------------------------------------------------------------------------------------*/
|
||||
/** @defgroup USBD_HID_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#if (HID_CLASS_MODE == HID_MOUSE) /* HID_MOUSE */
|
||||
#define HID_EPIN_ADDR 0x81U
|
||||
#define HID_EPIN_SIZE 0x04U
|
||||
|
||||
#define USB_HID_CONFIG_DESC_SIZ 34U
|
||||
#elif (HID_CLASS_MODE == HID_KEYBOARD) /* HID_KEYBOARD */
|
||||
#define HID_EP1_OUTPUT 0U
|
||||
|
||||
#define HID_EPIN_ADDR 0x81U
|
||||
#define HID_EPIN_SIZE 0x08U
|
||||
|
||||
#define HID_EPOUT_ADDR 0x01U
|
||||
#define HID_EPOUT_SIZE 0x01U
|
||||
|
||||
#if HID_EP1_OUTPUT
|
||||
#define USB_HID_CONFIG_DESC_SIZ 41U
|
||||
#else
|
||||
#define USB_HID_CONFIG_DESC_SIZ 34U
|
||||
#endif
|
||||
|
||||
#define USBD_HID_OUTREPORT_BUF_SIZE 1U
|
||||
#elif (HID_CLASS_MODE == HID_CUSTOM) /* HID_CUSTOM */
|
||||
#define HID_EPIN_ADDR 0x81U
|
||||
#define HID_EPIN_SIZE 0x40U
|
||||
|
||||
#define HID_EPOUT_ADDR 0x01U
|
||||
#define HID_EPOUT_SIZE 0x40U
|
||||
|
||||
#define USB_HID_CONFIG_DESC_SIZ 41U
|
||||
|
||||
#define USBD_HID_OUTREPORT_BUF_SIZE 0x40U
|
||||
|
||||
#elif ((HID_CLASS_MODE == (HID_MOUSE | HID_CUSTOM)) || \
|
||||
(HID_CLASS_MODE == (HID_KEYBOARD | HID_CUSTOM)))/* (HID_MOUSE | HID_CUSTOM) */
|
||||
|
||||
#if ((HID_CLASS_MODE & HID_MOUSE) == HID_MOUSE)
|
||||
#define HID_EPIN_ADDR 0x81U
|
||||
#define HID_EPIN_SIZE 0x04U
|
||||
#endif
|
||||
|
||||
#if ((HID_CLASS_MODE & HID_KEYBOARD) == HID_KEYBOARD)
|
||||
#define HID_EPIN_ADDR 0x81U
|
||||
#define HID_EPIN_SIZE 0x08U
|
||||
|
||||
#define HID_EPOUT_ADDR 0x01U
|
||||
#define HID_EPOUT_SIZE 0x01U
|
||||
|
||||
#define USBD_HID_OUTREPORT_BUF_SIZE 1U
|
||||
#endif
|
||||
|
||||
#define CUSTOM_HID_EPIN_ADDR 0x82U
|
||||
#define CUSTOM_HID_EPIN_SIZE 0x40U
|
||||
|
||||
#define CUSTOM_HID_EPOUT_ADDR 0x02U
|
||||
#define CUSTOM_HID_EPOUT_SIZE 0x40U
|
||||
|
||||
#define CUSTOM_HID_FS_BINTERVAL 0x5U
|
||||
|
||||
#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 0x40U
|
||||
|
||||
#if ((HID_CLASS_MODE & HID_MOUSE) == HID_MOUSE)
|
||||
#define USB_HID_CONFIG_DESC_SIZ 66U
|
||||
#endif
|
||||
#if ((HID_CLASS_MODE & HID_KEYBOARD) == HID_KEYBOARD)
|
||||
#define USB_HID_CONFIG_DESC_SIZ 73U
|
||||
#endif
|
||||
|
||||
|
||||
#define HID_DATAIN_EPNUM (HID_EPIN_ADDR & 0x0FU)
|
||||
#define CUSTOM_HID_DATAIN_EPNUM (CUSTOM_HID_EPIN_ADDR & 0x0FU)
|
||||
|
||||
#elif (HID_CLASS_MODE == (HID_KEYBOARD | HID_MOUSE))
|
||||
|
||||
#define HID_EP1IN_ADDR 0x81U
|
||||
#define HID_EP1IN_SIZE 0x08U
|
||||
|
||||
#define HID_EP1OUT_ADDR 0x01U
|
||||
#define HID_EP1OUT_SIZE 0x01U
|
||||
|
||||
#define USBD_HID_OUTREPORT_BUF_SIZE 1U
|
||||
|
||||
#define HID_EP2IN_ADDR 0x82U
|
||||
#define HID_EP2IN_SIZE 0x04U
|
||||
|
||||
#define USB_HID_CONFIG_DESC_SIZ 66U
|
||||
|
||||
#define HID_DATAIN_EPNUM_1 (HID_EP1IN_ADDR & 0x0FU)
|
||||
#define HID_DATAIN_EPNUM_2 (HID_EP2IN_ADDR & 0x0FU)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define USB_HID_DESC_SIZ 9U
|
||||
#define HID_MOUSE_REPORT_DESC_SIZE 74U
|
||||
#define HID_KEYBOARD_REPORT_DESC_SIZE 63U
|
||||
#define USBD_CUSTOM_REPORT_DESC_SIZE 34U//43U //39U//34U
|
||||
|
||||
#define HID_DESCRIPTOR_TYPE 0x21U
|
||||
#define HID_REPORT_DESC 0x22U
|
||||
|
||||
#ifndef HID_HS_BINTERVAL
|
||||
#define HID_HS_BINTERVAL 0x07U
|
||||
#endif /* HID_HS_BINTERVAL */
|
||||
|
||||
#ifndef HID_FS_BINTERVAL
|
||||
#if ((HID_CLASS_MODE== HID_MOUSE) || \
|
||||
(HID_CLASS_MODE == HID_KEYBOARD))
|
||||
#define HID_FS_BINTERVAL 0x01U
|
||||
#else
|
||||
#define HID_FS_BINTERVAL 0x01U
|
||||
#endif
|
||||
#endif /* HID_FS_BINTERVAL */
|
||||
|
||||
#define HID_REQ_SET_PROTOCOL 0x0BU
|
||||
#define HID_REQ_GET_PROTOCOL 0x03U
|
||||
|
||||
#define HID_REQ_SET_IDLE 0x0AU
|
||||
#define HID_REQ_GET_IDLE 0x02U
|
||||
|
||||
#define HID_REQ_SET_REPORT 0x09U
|
||||
#define HID_REQ_GET_REPORT 0x01U
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Typedef
|
||||
-------------------------------------------------------------------------------------*/
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
HID_IDLE = 0,
|
||||
HID_BUSY,
|
||||
} HID_StateTypeDef;
|
||||
|
||||
#if (HID_CLASS_MODE == HID_MOUSE)
|
||||
typedef struct
|
||||
{
|
||||
uint32_t Protocol;
|
||||
uint32_t IdleState;
|
||||
uint32_t AltSetting;
|
||||
HID_StateTypeDef state;
|
||||
} USBD_HID_HandleTypeDef;
|
||||
#else
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Report_buf[USBD_HID_OUTREPORT_BUF_SIZE];
|
||||
uint32_t Protocol;
|
||||
uint32_t IdleState;
|
||||
uint32_t AltSetting;
|
||||
uint32_t IsReportAvailable;
|
||||
HID_StateTypeDef state;
|
||||
} USBD_HID_HandleTypeDef;
|
||||
#endif
|
||||
|
||||
|
||||
//#if ((HID_CLASS_MODE & HID_CUSTOM) == HID_CUSTOM)
|
||||
///** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
// * @{
|
||||
// */
|
||||
//typedef enum
|
||||
//{
|
||||
// CUSTOM_HID_IDLE = 0U,
|
||||
// CUSTOM_HID_BUSY,
|
||||
//} CUSTOM_HID_StateTypeDef;
|
||||
|
||||
//typedef struct
|
||||
//{
|
||||
// uint8_t Report_buf[USBD_CUSTOMHID_OUTREPORT_BUF_SIZE];
|
||||
// uint32_t Protocol;
|
||||
// uint32_t IdleState;
|
||||
// uint32_t AltSetting;
|
||||
// uint32_t IsReportAvailable;
|
||||
// CUSTOM_HID_StateTypeDef state;
|
||||
//} USBD_CUSTOM_HID_HandleTypeDef;
|
||||
//#endif
|
||||
|
||||
/*
|
||||
* HID Class specification version 1.1
|
||||
* 6.2.1 HID Descriptor
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t bcdHID;
|
||||
uint8_t bCountryCode;
|
||||
uint8_t bNumDescriptors;
|
||||
uint8_t bHIDDescriptorType;
|
||||
uint16_t wItemLength;
|
||||
} __PACKED USBD_HIDDescTypeDef;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Global Variables
|
||||
-------------------------------------------------------------------------------------*/
|
||||
extern USBD_ClassTypeDef USBD_HID;
|
||||
#if (HID_CLASS_MODE == HID_KEYBOARD)
|
||||
extern uint8_t Report_buff[1];
|
||||
#endif
|
||||
|
||||
extern uint8_t DataOut_Finished;
|
||||
/*------------------------------------------------------------------------------------
|
||||
Global Functions
|
||||
-------------------------------------------------------------------------------------*/
|
||||
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *report, uint16_t len);
|
||||
uint8_t USBD_HID_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||
uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_HID_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user