新增4轮4转-补丁代码
This commit is contained in:
@@ -0,0 +1,679 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* uC/USB-Device
|
||||
* The Embedded USB Device Stack
|
||||
*
|
||||
* Copyright (c) 2021 Semidrive Semiconductor
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* USB HID CLASS OPERATING SYSTEM LAYER
|
||||
* For CMSIS OS2
|
||||
*
|
||||
* Filename : usbd_hid_os.c
|
||||
* Version : V1.00.00
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* INCLUDE FILES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#include "../../../../Source/usbd_core.h"
|
||||
#include "../../usbd_hid_report.h"
|
||||
#include "../../usbd_hid_os.h"
|
||||
#include <cmsis_os2.h>
|
||||
#include <driver/irq.h>
|
||||
#include <debug.h>
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* CONFIGURATION ERRORS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL DEFINES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
#define HID_DATA_EVENT_POST (1u<<0)
|
||||
#define HID_DATA_EVENT_ABORT (1u<<1)
|
||||
#define HID_DATA_EVENT_ALL (HID_DATA_EVENT_POST | HID_DATA_EVENT_ABORT)
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL CONSTANTS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL DATA TYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL TABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL GLOBAL VARIABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/* ---------------- USB HID SEM OBJECTS --------------- */
|
||||
static osEventFlagsId_t USBD_HID_OS_InputDataSem_Tbl[USBD_HID_CFG_MAX_NBR_DEV];
|
||||
static volatile CPU_INT32U USBD_HID_OS_InDataSemCnt_Tbl[USBD_HID_CFG_MAX_NBR_DEV];
|
||||
|
||||
static osSemaphoreId_t USBD_HID_OS_InputLockSem_Tbl[USBD_HID_CFG_MAX_NBR_DEV];
|
||||
|
||||
static osSemaphoreId_t USBD_HID_OS_TxSem_Tbl[USBD_HID_CFG_MAX_NBR_DEV];
|
||||
|
||||
static osSemaphoreId_t USBD_HID_OS_OutputLockSem_Tbl[USBD_HID_CFG_MAX_NBR_DEV];
|
||||
|
||||
static osEventFlagsId_t USBD_HID_OS_OutputDataSem_Tbl[USBD_HID_CFG_MAX_NBR_DEV];
|
||||
static volatile CPU_INT32U USBD_HID_OS_OutDataSemCnt_Tbl[USBD_HID_CFG_MAX_NBR_DEV];
|
||||
|
||||
static osThreadId_t USBD_HID_OS_TmrTaskID;
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL MACRO'S
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#define hidd_os_err(...) ssdk_printf(SSDK_CRIT, __VA_ARGS__)
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL FUNCTION PROTOTYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
static void USBD_HID_OS_TmrTask(void *p_arg);
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_HID_OS_Init()
|
||||
*
|
||||
* Description : Initialize HID OS interface.
|
||||
*
|
||||
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function :
|
||||
*
|
||||
* USBD_ERR_NONE HID OS initialization successful.
|
||||
* USBD_ERR_OS_SIGNAL_CREATE HID OS objects NOT successfully initialized.
|
||||
* USBD_ERR_OS_INIT_FAIL HID OS task NOT successfully initialized.
|
||||
*
|
||||
* Return(s) : none.
|
||||
*
|
||||
* Note(s) : none.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_HID_OS_Init (USBD_ERR *p_err)
|
||||
{
|
||||
CPU_INT08U class_nbr;
|
||||
osThreadId_t thread;
|
||||
osThreadAttr_t attr = {
|
||||
.name = "USBD HID Tmr Tsk",
|
||||
.stack_size = 4096,
|
||||
.priority = osPriorityAboveNormal3,
|
||||
};
|
||||
|
||||
for (class_nbr = 0; class_nbr < USBD_HID_CFG_MAX_NBR_DEV; class_nbr++) {
|
||||
USBD_HID_OS_TxSem_Tbl[class_nbr] = osSemaphoreNew(1, 1, NULL);
|
||||
if (!USBD_HID_OS_TxSem_Tbl[class_nbr]) {
|
||||
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
|
||||
return;
|
||||
}
|
||||
|
||||
USBD_HID_OS_OutputLockSem_Tbl[class_nbr] = osSemaphoreNew(1, 1, NULL);
|
||||
if (!USBD_HID_OS_OutputLockSem_Tbl[class_nbr]) {
|
||||
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
|
||||
return;
|
||||
}
|
||||
|
||||
USBD_HID_OS_OutputDataSem_Tbl[class_nbr] = osEventFlagsNew(NULL);
|
||||
if (!USBD_HID_OS_OutputDataSem_Tbl[class_nbr]) {
|
||||
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
|
||||
return;
|
||||
}
|
||||
USBD_HID_OS_OutDataSemCnt_Tbl[class_nbr] = 0;
|
||||
|
||||
USBD_HID_OS_InputLockSem_Tbl[class_nbr] = osSemaphoreNew(1, 1, NULL);
|
||||
if (!USBD_HID_OS_InputLockSem_Tbl[class_nbr]) {
|
||||
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
|
||||
return;
|
||||
}
|
||||
|
||||
USBD_HID_OS_InputDataSem_Tbl[class_nbr] = osEventFlagsNew(NULL);
|
||||
if (!USBD_HID_OS_InputDataSem_Tbl[class_nbr]) {
|
||||
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
|
||||
return;
|
||||
}
|
||||
USBD_HID_OS_InDataSemCnt_Tbl[class_nbr] = 0;
|
||||
}
|
||||
|
||||
thread = osThreadNew(USBD_HID_OS_TmrTask, NULL, &attr);
|
||||
if (!thread) {
|
||||
*p_err = USBD_ERR_OS_INIT_FAIL;
|
||||
return;
|
||||
}
|
||||
USBD_HID_OS_TmrTaskID = thread;
|
||||
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_HID_OS_TmrTask()
|
||||
*
|
||||
* Description : OS-dependent shell task to process periodic HID input reports.
|
||||
*
|
||||
* Argument(s) : p_arg Pointer to task initialization argument (required by CMSIS OS2).
|
||||
*
|
||||
* Return(s) : none.
|
||||
*
|
||||
* Note(s) : (1) Assumes OSCfg_TickRate_Hz frequency is greater than or equal to 250 Hz. Otherwise,
|
||||
* timer task scheduling rate will NOT be correct.
|
||||
*
|
||||
* (2) Timer task MUST delay without failure.
|
||||
*
|
||||
* (a) Failure to delay timer task will prevent some HID report task(s)/operation(s) from
|
||||
* functioning correctly. Thus, timer task is assumed to be successfully delayed
|
||||
* since NO error handling could be performed to counteract failure.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
static void USBD_HID_OS_TmrTask (void *p_arg)
|
||||
{
|
||||
while (DEF_ON) {
|
||||
|
||||
osDelay(4);
|
||||
|
||||
USBD_HID_Report_TmrTaskHandler();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_HID_OS_InputLock()
|
||||
*
|
||||
* Description : Lock class input report.
|
||||
*
|
||||
* Argument(s) : class_nbr Class instance number.
|
||||
* --------- Argument validated by the caller(s).
|
||||
*
|
||||
* p_err Pointer to variable that will receive the return error code from this function :
|
||||
*
|
||||
* USBD_ERR_NONE Class input report successfully locked.
|
||||
* USBD_ERR_OS_ABORT Class input report aborted.
|
||||
* USBD_ERR_OS_FAIL OS signal not acquired because another error.
|
||||
*
|
||||
* Return(s) : none.
|
||||
*
|
||||
* Note(s) : none.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_HID_OS_InputLock (CPU_INT08U class_nbr,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
osStatus_t ret;
|
||||
|
||||
ret = osSemaphoreAcquire(USBD_HID_OS_InputLockSem_Tbl[class_nbr], osWaitForever);
|
||||
switch (ret) {
|
||||
case osOK:
|
||||
*p_err = USBD_ERR_NONE;
|
||||
break;
|
||||
|
||||
default:
|
||||
*p_err = USBD_ERR_OS_FAIL;
|
||||
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_HID_OS_InputUnlock()
|
||||
*
|
||||
* Description : Unlock class input report.
|
||||
*
|
||||
* Argument(s) : class_nbr Class instance number.
|
||||
* --------- Argument validated by the caller(s).
|
||||
*
|
||||
* Return(s) : none.
|
||||
*
|
||||
* Note(s) : none.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_HID_OS_InputUnlock (CPU_INT08U class_nbr)
|
||||
{
|
||||
osStatus_t ret;
|
||||
|
||||
ret = osSemaphoreRelease(USBD_HID_OS_InputLockSem_Tbl[class_nbr]);
|
||||
if (ret < 0)
|
||||
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_HID_OS_OutputDataPendAbort()
|
||||
*
|
||||
* Description : Abort class output report.
|
||||
*
|
||||
* Argument(s) : class_nbr Class instance number.
|
||||
* --------- Argument validated by the caller(s).
|
||||
*
|
||||
* Return(s) : none.
|
||||
*
|
||||
* Note(s) : none.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_HID_OS_OutputDataPendAbort (CPU_INT08U class_nbr)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
ret = osEventFlagsSet(USBD_HID_OS_OutputDataSem_Tbl[class_nbr], HID_DATA_EVENT_ABORT);
|
||||
if (ret < 0)
|
||||
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_HID_OS_OutputDataPend()
|
||||
*
|
||||
* Description : Wait for output report data transfer to complete.
|
||||
*
|
||||
* Argument(s) : class_nbr Class instance number.
|
||||
* --------- Argument validated by the caller(s).
|
||||
*
|
||||
* timeout_ms Signal wait timeout, in milliseconds.
|
||||
*
|
||||
* p_err Pointer to variable that will receive the return error code from this function :
|
||||
*
|
||||
* USBD_ERR_NONE Class output successfully locked.
|
||||
* USBD_ERR_OS_ABORT Class output aborted.
|
||||
* USBD_ERR_OS_FAIL OS signal not acquired because another error.
|
||||
*
|
||||
* Return(s) : none.
|
||||
*
|
||||
* Note(s) : none.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_HID_OS_OutputDataPend (CPU_INT08U class_nbr,
|
||||
CPU_INT16U timeout_ms,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
int32_t ret;
|
||||
uint32_t tmo;
|
||||
uint32_t tk_start, tk_current;
|
||||
CPU_INT32U cnt;
|
||||
CPU_SR_ALLOC();
|
||||
|
||||
tk_start = osKernelGetTickCount();
|
||||
tk_current = tk_start;
|
||||
do {
|
||||
tmo = timeout_ms ? (tk_start + timeout_ms - tk_current): osWaitForever;
|
||||
ret = osEventFlagsWait(USBD_HID_OS_OutputDataSem_Tbl[class_nbr], HID_DATA_EVENT_ALL, 0, tmo);
|
||||
if (ret < 0) {
|
||||
switch (ret) {
|
||||
case osErrorTimeout:
|
||||
*p_err = USBD_ERR_OS_TIMEOUT;
|
||||
return;
|
||||
|
||||
default:
|
||||
*p_err = USBD_ERR_OS_FAIL;
|
||||
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
return;
|
||||
}
|
||||
} else if (ret & HID_DATA_EVENT_ABORT) {
|
||||
*p_err = USBD_ERR_OS_ABORT;
|
||||
return;
|
||||
}
|
||||
|
||||
CPU_CRITICAL_ENTER();
|
||||
cnt = USBD_HID_OS_OutDataSemCnt_Tbl[class_nbr];
|
||||
if (cnt)
|
||||
USBD_HID_OS_OutDataSemCnt_Tbl[class_nbr] = cnt - 1;
|
||||
CPU_CRITICAL_EXIT();
|
||||
|
||||
if (cnt > 1) {
|
||||
osEventFlagsSet(USBD_HID_OS_OutputDataSem_Tbl[class_nbr], HID_DATA_EVENT_POST);
|
||||
}
|
||||
|
||||
if (cnt) {
|
||||
*p_err = USBD_ERR_NONE;
|
||||
return;
|
||||
}
|
||||
|
||||
tk_current = osKernelGetTickCount();
|
||||
} while (!timeout_ms || (tk_current - tk_start <= timeout_ms));
|
||||
|
||||
*p_err = USBD_ERR_OS_TIMEOUT;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_HID_OS_OutputDataPost()
|
||||
*
|
||||
* Description : Signal that output report data is available.
|
||||
*
|
||||
* Argument(s) : class_nbr Class instance number.
|
||||
* --------- Argument validated by the caller(s).
|
||||
*
|
||||
* Return(s) : none.
|
||||
*
|
||||
* Note(s) : none.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_HID_OS_OutputDataPost (CPU_INT08U class_nbr)
|
||||
{
|
||||
int32_t ret;
|
||||
CPU_SR_ALLOC();
|
||||
|
||||
CPU_CRITICAL_ENTER();
|
||||
USBD_HID_OS_OutDataSemCnt_Tbl[class_nbr]++;
|
||||
CPU_CRITICAL_EXIT();
|
||||
|
||||
ret = osEventFlagsSet(USBD_HID_OS_OutputDataSem_Tbl[class_nbr], HID_DATA_EVENT_POST);
|
||||
if (ret < 0)
|
||||
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_HID_OS_OutputLock()
|
||||
*
|
||||
* Description : Lock class output report.
|
||||
*
|
||||
* Argument(s) : class_nbr Class instance number.
|
||||
* --------- Argument validated by the caller(s).
|
||||
*
|
||||
* p_err Pointer to variable that will receive the return error code from this function :
|
||||
*
|
||||
* USBD_ERR_NONE Class output successfully locked.
|
||||
* USBD_ERR_OS_ABORT Class output aborted.
|
||||
* USBD_ERR_OS_FAIL OS signal not acquired because another error.
|
||||
*
|
||||
* Return(s) : none.
|
||||
*
|
||||
* Note(s) : none.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_HID_OS_OutputLock (CPU_INT08U class_nbr,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
osStatus_t ret;
|
||||
|
||||
ret = osSemaphoreAcquire(USBD_HID_OS_OutputLockSem_Tbl[class_nbr], osWaitForever);
|
||||
switch (ret) {
|
||||
case osOK:
|
||||
*p_err = USBD_ERR_NONE;
|
||||
break;
|
||||
|
||||
default:
|
||||
*p_err = USBD_ERR_OS_FAIL;
|
||||
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_HID_OS_OutputUnlock()
|
||||
*
|
||||
* Description : Unlock class output report.
|
||||
*
|
||||
* Argument(s) : class_nbr Class instance number.
|
||||
* --------- Argument validated by the caller(s).
|
||||
*
|
||||
* Return(s) : none.
|
||||
*
|
||||
* Note(s) : none.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_HID_OS_OutputUnlock (CPU_INT08U class_nbr)
|
||||
{
|
||||
osStatus_t ret;
|
||||
|
||||
ret = osSemaphoreRelease(USBD_HID_OS_OutputLockSem_Tbl[class_nbr]);
|
||||
if (ret < 0)
|
||||
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_HID_OS_TxLock()
|
||||
*
|
||||
* Description : Lock class transmit.
|
||||
*
|
||||
* Argument(s) : class_nbr Class instance number.
|
||||
* --------- Argument validated by the caller(s).
|
||||
*
|
||||
* p_err Pointer to variable that will receive the return error code from this function :
|
||||
*
|
||||
* USBD_ERR_NONE Class feature report successfully locked.
|
||||
* USBD_ERR_OS_ABORT Class feature report aborted.
|
||||
* USBD_ERR_OS_FAIL OS signal not acquired because another error.
|
||||
*
|
||||
* Return(s) : none.
|
||||
*
|
||||
* Note(s) : none.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_HID_OS_TxLock (CPU_INT08U class_nbr,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
osStatus_t ret;
|
||||
|
||||
ret = osSemaphoreAcquire(USBD_HID_OS_TxSem_Tbl[class_nbr], osWaitForever);
|
||||
switch (ret) {
|
||||
case osOK:
|
||||
*p_err = USBD_ERR_NONE;
|
||||
break;
|
||||
|
||||
default:
|
||||
*p_err = USBD_ERR_OS_FAIL;
|
||||
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_HID_OS_TxUnlock()
|
||||
*
|
||||
* Description : Unlock class transmit.
|
||||
*
|
||||
* Argument(s) : class_nbr Class instance number.
|
||||
* --------- Argument validated by the caller(s).
|
||||
*
|
||||
* Return(s) : none.
|
||||
*
|
||||
* Note(s) : none.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_HID_OS_TxUnlock (CPU_INT08U class_nbr)
|
||||
{
|
||||
osStatus_t ret;
|
||||
|
||||
ret = osSemaphoreRelease(USBD_HID_OS_TxSem_Tbl[class_nbr]);
|
||||
if (ret < 0)
|
||||
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_HID_OS_InputDataPend()
|
||||
*
|
||||
* Description : Wait for input report data transfer to complete.
|
||||
*
|
||||
* Argument(s) : class_nbr Class instance number.
|
||||
* --------- Argument validated by the caller(s).
|
||||
*
|
||||
* timeout_ms Signal wait timeout in milliseconds.
|
||||
*
|
||||
* p_err Pointer to variable that will receive the return error code from this function :
|
||||
*
|
||||
* USBD_ERR_NONE OS signal successfully acquired.
|
||||
* USBD_ERR_OS_TIMEOUT OS signal NOT successfully acquired in the time
|
||||
* specified by 'timeout_ms'.
|
||||
* USBD_ERR_OS_ABORT OS signal aborted.
|
||||
* USBD_ERR_OS_FAIL OS signal not acquired because another error.
|
||||
*
|
||||
* Return(s) : none.
|
||||
*
|
||||
* Note(s) : none.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_HID_OS_InputDataPend (CPU_INT08U class_nbr,
|
||||
CPU_INT16U timeout_ms,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
int32_t ret;
|
||||
uint32_t tmo;
|
||||
uint32_t tk_start, tk_current;
|
||||
CPU_INT32U cnt;
|
||||
CPU_SR_ALLOC();
|
||||
|
||||
tk_start = osKernelGetTickCount();
|
||||
tk_current = tk_start;
|
||||
do {
|
||||
tmo = timeout_ms ? (tk_start + timeout_ms - tk_current): osWaitForever;
|
||||
ret = osEventFlagsWait(USBD_HID_OS_InputDataSem_Tbl[class_nbr], HID_DATA_EVENT_ALL, 0, tmo);
|
||||
if (ret < 0) {
|
||||
switch (ret) {
|
||||
case osErrorTimeout:
|
||||
*p_err = USBD_ERR_OS_TIMEOUT;
|
||||
return;
|
||||
|
||||
default:
|
||||
*p_err = USBD_ERR_OS_FAIL;
|
||||
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
return;
|
||||
}
|
||||
} else if (ret & HID_DATA_EVENT_ABORT) {
|
||||
*p_err = USBD_ERR_OS_ABORT;
|
||||
return;
|
||||
}
|
||||
|
||||
CPU_CRITICAL_ENTER();
|
||||
cnt = USBD_HID_OS_InDataSemCnt_Tbl[class_nbr];
|
||||
if (cnt)
|
||||
USBD_HID_OS_InDataSemCnt_Tbl[class_nbr] = cnt - 1;
|
||||
CPU_CRITICAL_EXIT();
|
||||
|
||||
if (cnt > 1) {
|
||||
osEventFlagsSet(USBD_HID_OS_InputDataSem_Tbl[class_nbr], HID_DATA_EVENT_POST);
|
||||
}
|
||||
|
||||
if (cnt) {
|
||||
*p_err = USBD_ERR_NONE;
|
||||
return;
|
||||
}
|
||||
|
||||
tk_current = osKernelGetTickCount();
|
||||
} while (!timeout_ms || (tk_current - tk_start <= timeout_ms));
|
||||
|
||||
*p_err = USBD_ERR_OS_TIMEOUT;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_HID_OS_InputDataPendAbort()
|
||||
*
|
||||
* Description : Abort any operation on input report.
|
||||
*
|
||||
* Argument(s) : class_nbr Class instance number.
|
||||
* --------- Argument validated by the caller(s).
|
||||
*
|
||||
* Return(s) : none.
|
||||
*
|
||||
* Note(s) : none.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_HID_OS_InputDataPendAbort (CPU_INT08U class_nbr)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
ret = osEventFlagsSet(USBD_HID_OS_InputDataSem_Tbl[class_nbr], HID_DATA_EVENT_ABORT);
|
||||
if (ret < 0)
|
||||
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_HID_OS_InputDataPost()
|
||||
*
|
||||
* Description : Signal that input report data transfer has completed.
|
||||
*
|
||||
* Argument(s) : class_nbr Class instance number.
|
||||
* --------- Argument validated by the caller(s).
|
||||
*
|
||||
* Return(s) : none.
|
||||
*
|
||||
* Note(s) : none.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_HID_OS_InputDataPost (CPU_INT08U class_nbr)
|
||||
{
|
||||
int32_t ret;
|
||||
CPU_SR_ALLOC();
|
||||
|
||||
CPU_CRITICAL_ENTER();
|
||||
USBD_HID_OS_InDataSemCnt_Tbl[class_nbr]++;
|
||||
CPU_CRITICAL_EXIT();
|
||||
|
||||
ret = osEventFlagsSet(USBD_HID_OS_InputDataSem_Tbl[class_nbr], HID_DATA_EVENT_POST);
|
||||
if (ret < 0)
|
||||
hidd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
}
|
||||
|
||||
|
||||
2486
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/HID/usbd_hid.c
Normal file
2486
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/HID/usbd_hid.c
Normal file
File diff suppressed because it is too large
Load Diff
265
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/HID/usbd_hid.h
Normal file
265
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/HID/usbd_hid.h
Normal file
@@ -0,0 +1,265 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* uC/USB-Device
|
||||
* The Embedded USB Device Stack
|
||||
*
|
||||
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
|
||||
*
|
||||
* SPDX-License-Identifier: APACHE-2.0
|
||||
*
|
||||
* This software is subject to an open source license and is distributed by
|
||||
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
|
||||
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* USB DEVICE HID CLASS
|
||||
*
|
||||
* Filename : usbd_hid.h
|
||||
* Version : V4.06.01
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MODULE
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef USBD_HID_MODULE_PRESENT
|
||||
#define USBD_HID_MODULE_PRESENT
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* INCLUDE FILES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#include "../../Source/usbd_core.h"
|
||||
#include "usbd_hid_report.h"
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* EXTERNS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef USBD_HID_MODULE
|
||||
#define USBD_HID_EXT
|
||||
#else
|
||||
#define USBD_HID_EXT extern
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DEFINES
|
||||
*
|
||||
* Note(s) : (1) See 'Device Class Definition for Human Interface Devices (HID), 6/27/01, Version 1.11',
|
||||
* section 6.2.1 for more details about HID descriptor country code.
|
||||
*
|
||||
* (a) The country code identifies which country the hardware is localized for. Most
|
||||
* hardware is not localized and thus this value would be zero (0). However, keyboards
|
||||
* may use the field to indicate the language of the key caps.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/* ------------ COUNTRY CODES (see Note #1) ----------- */
|
||||
typedef enum usbd_hid_country_code {
|
||||
USBD_HID_COUNTRY_CODE_NOT_SUPPORTED = 0u, /* See Note #1a. */
|
||||
USBD_HID_COUNTRY_CODE_ARABIC = 1u,
|
||||
USBD_HID_COUNTRY_CODE_BELGIAN = 2u,
|
||||
USBD_HID_COUNTRY_CODE_CANADIAN_BILINGUAL = 3u,
|
||||
USBD_HID_COUNTRY_CODE_CANADIAN_FRENCH = 4u,
|
||||
USBD_HID_COUNTRY_CODE_CZECH_REPUBLIC = 5u,
|
||||
USBD_HID_COUNTRY_CODE_DANISH = 6u,
|
||||
USBD_HID_COUNTRY_CODE_FINNISH = 7u,
|
||||
USBD_HID_COUNTRY_CODE_FRENCH = 8u,
|
||||
USBD_HID_COUNTRY_CODE_GERMAN = 9u,
|
||||
USBD_HID_COUNTRY_CODE_GREEK = 10u,
|
||||
USBD_HID_COUNTRY_CODE_HEBREW = 11u,
|
||||
USBD_HID_COUNTRY_CODE_HUNGARY = 12u,
|
||||
USBD_HID_COUNTRY_CODE_INTERNATIONAL = 13u,
|
||||
USBD_HID_COUNTRY_CODE_ITALIAN = 14u,
|
||||
USBD_HID_COUNTRY_CODE_JAPAN_KATAKANA = 15u,
|
||||
USBD_HID_COUNTRY_CODE_KOREAN = 16u,
|
||||
USBD_HID_COUNTRY_CODE_LATIN_AMERICAN = 17u,
|
||||
USBD_HID_COUNTRY_CODE_NETHERLANDS_DUTCH = 18u,
|
||||
USBD_HID_COUNTRY_CODE_NORWEGIAN = 19u,
|
||||
USBD_HID_COUNTRY_CODE_PERSIAN_FARSI = 20u,
|
||||
USBD_HID_COUNTRY_CODE_POLAND = 21u,
|
||||
USBD_HID_COUNTRY_CODE_PORTUGUESE = 22u,
|
||||
USBD_HID_COUNTRY_CODE_RUSSIA = 23u,
|
||||
USBD_HID_COUNTRY_CODE_SLOVAKIA = 24u,
|
||||
USBD_HID_COUNTRY_CODE_SPANISH = 25u,
|
||||
USBD_HID_COUNTRY_CODE_SWEDISH = 26u,
|
||||
USBD_HID_COUNTRY_CODE_SWISS_FRENCH = 27u,
|
||||
USBD_HID_COUNTRY_CODE_SWISS_GERMAN = 28u,
|
||||
USBD_HID_COUNTRY_CODE_SWITZERLAND = 29u,
|
||||
USBD_HID_COUNTRY_CODE_TAIWAN = 30u,
|
||||
USBD_HID_COUNTRY_CODE_TURKISH_Q = 31u,
|
||||
USBD_HID_COUNTRY_CODE_UK = 32u,
|
||||
USBD_HID_COUNTRY_CODE_US = 33u,
|
||||
USBD_HID_COUNTRY_CODE_YUGOSLAVIA = 34u,
|
||||
USBD_HID_COUNTRY_CODE_TURKISH_F = 35u
|
||||
} USBD_HID_COUNTRY_CODE;
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* HUMAN INTERFACE DEVICE CLASS SUBCLASS CODES DEFINES
|
||||
*
|
||||
* Note(s) : (1) Human interface device class subclass codes are defined in section 4.2 of HID
|
||||
* specification revision 1.11.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#define USBD_HID_SUBCLASS_NONE 0x00u /* No subclass. */
|
||||
#define USBD_HID_SUBCLASS_BOOT 0x01u /* Boot interface. */
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* HUMAN INTERFACE DEVICE CLASS PROTOCOL CODES DEFINES
|
||||
*
|
||||
* Note(s) : (1) Human interface device class protocol codes are defined in section 4.3 of HID
|
||||
* specification revision 1.11.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#define USBD_HID_PROTOCOL_NONE 0x00u /* No class specific protocol. */
|
||||
#define USBD_HID_PROTOCOL_KBD 0x01u /* Keyboard protocol. */
|
||||
#define USBD_HID_PROTOCOL_MOUSE 0x02u /* Mouse protocol. */
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DATA TYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/* Async comm callback. */
|
||||
typedef void (*USBD_HID_ASYNC_FNCT)(CPU_INT08U class_nbr,
|
||||
void *p_buf,
|
||||
CPU_INT32U buf_len,
|
||||
CPU_INT32U xfer_len,
|
||||
void *p_callback_arg,
|
||||
USBD_ERR err);
|
||||
|
||||
/* HID desc and req callbacks. */
|
||||
typedef const struct usbd_hid_callback {
|
||||
CPU_BOOLEAN (*FeatureReportGet)(CPU_INT08U class_nbr,
|
||||
CPU_INT08U report_id,
|
||||
CPU_INT08U *p_report_buf,
|
||||
CPU_INT16U report_len);
|
||||
|
||||
CPU_BOOLEAN (*FeatureReportSet)(CPU_INT08U class_nbr,
|
||||
CPU_INT08U report_id,
|
||||
CPU_INT08U *p_report_buf,
|
||||
CPU_INT16U report_len);
|
||||
|
||||
CPU_INT08U (*ProtocolGet) (CPU_INT08U class_nbr,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void (*ProtocolSet) (CPU_INT08U class_nbr,
|
||||
CPU_INT08U protocol,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void (*ReportSet) (CPU_INT08U class_nbr,
|
||||
CPU_INT08U report_id,
|
||||
CPU_INT08U *p_report_buf,
|
||||
CPU_INT16U report_len);
|
||||
} USBD_HID_CALLBACK;
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MACRO'S
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* FUNCTION PROTOTYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/* HID class initialization. */
|
||||
void USBD_HID_Init (USBD_ERR *p_err);
|
||||
|
||||
/* Add new instance of the HID class. */
|
||||
CPU_INT08U USBD_HID_Add (CPU_INT08U subclass,
|
||||
CPU_INT08U protocol,
|
||||
USBD_HID_COUNTRY_CODE country_code,
|
||||
CPU_INT08U *p_report_desc,
|
||||
CPU_INT16U report_desc_len,
|
||||
CPU_INT08U *p_phy_desc,
|
||||
CPU_INT16U phy_desc_len,
|
||||
CPU_INT16U interval_in,
|
||||
CPU_INT16U interval_out,
|
||||
CPU_BOOLEAN ctrl_rd_en,
|
||||
USBD_HID_CALLBACK *p_hid_callback,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
CPU_BOOLEAN USBD_HID_CfgAdd (CPU_INT08U class_nbr,
|
||||
CPU_INT08U dev_nbr,
|
||||
CPU_INT08U cfg_nbr,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
CPU_BOOLEAN USBD_HID_IsConn (CPU_INT08U class_nbr);
|
||||
|
||||
CPU_INT32U USBD_HID_Wr (CPU_INT08U class_nbr,
|
||||
void *p_buf,
|
||||
CPU_INT32U buf_len,
|
||||
CPU_INT16U timeout,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_HID_WrAsync(CPU_INT08U class_nbr,
|
||||
void *p_buf,
|
||||
CPU_INT32U buf_len,
|
||||
USBD_HID_ASYNC_FNCT async_fnct,
|
||||
void *p_async_arg,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
CPU_INT32U USBD_HID_Rd (CPU_INT08U class_nbr,
|
||||
void *p_buf,
|
||||
CPU_INT32U buf_len,
|
||||
CPU_INT16U timeout,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_HID_RdAsync(CPU_INT08U class_nbr,
|
||||
void *p_buf,
|
||||
CPU_INT32U buf_len,
|
||||
USBD_HID_ASYNC_FNCT async_fnct,
|
||||
void *p_async_arg,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* CONFIGURATION ERRORS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MODULE END
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#endif
|
||||
137
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/HID/usbd_hid_os.h
Normal file
137
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/HID/usbd_hid_os.h
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* uC/USB-Device
|
||||
* The Embedded USB Device Stack
|
||||
*
|
||||
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
|
||||
*
|
||||
* SPDX-License-Identifier: APACHE-2.0
|
||||
*
|
||||
* This software is subject to an open source license and is distributed by
|
||||
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
|
||||
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* USB HID CLASS OPERATING SYSTEM LAYER
|
||||
*
|
||||
* Filename : usbd_hid_os.h
|
||||
* Version : V4.06.01
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MODULE
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef USBD_HID_OS_MODULE_PRESENT
|
||||
#define USBD_HID_OS_MODULE_PRESENT
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* INCLUDE FILES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#include "../../Source/usbd_core.h"
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* EXTERNS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DEFINES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DATA TYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MACRO'S
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* FUNCTION PROTOTYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_HID_OS_Init (USBD_ERR *p_err);
|
||||
|
||||
|
||||
void USBD_HID_OS_InputLock (CPU_INT08U class_nbr,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_HID_OS_InputUnlock (CPU_INT08U class_nbr);
|
||||
|
||||
void USBD_HID_OS_InputDataPend (CPU_INT08U class_nbr,
|
||||
CPU_INT16U timeout_ms,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_HID_OS_InputDataPendAbort (CPU_INT08U class_nbr);
|
||||
|
||||
void USBD_HID_OS_InputDataPost (CPU_INT08U class_nbr);
|
||||
|
||||
|
||||
void USBD_HID_OS_OutputLock (CPU_INT08U class_nbr,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_HID_OS_OutputUnlock (CPU_INT08U class_nbr);
|
||||
|
||||
void USBD_HID_OS_OutputDataPendAbort(CPU_INT08U class_nbr);
|
||||
|
||||
void USBD_HID_OS_OutputDataPend (CPU_INT08U class_nbr,
|
||||
CPU_INT16U timeout_ms,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_HID_OS_OutputDataPost (CPU_INT08U class_nbr);
|
||||
|
||||
|
||||
void USBD_HID_OS_TxLock (CPU_INT08U class_nbr,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_HID_OS_TxUnlock (CPU_INT08U class_nbr);
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* CONFIGURATION ERRORS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MODULE END
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#endif
|
||||
1002
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/HID/usbd_hid_report.c
Normal file
1002
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/HID/usbd_hid_report.c
Normal file
File diff suppressed because it is too large
Load Diff
391
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/HID/usbd_hid_report.h
Normal file
391
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/HID/usbd_hid_report.h
Normal file
@@ -0,0 +1,391 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* uC/USB-Device
|
||||
* The Embedded USB Device Stack
|
||||
*
|
||||
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
|
||||
*
|
||||
* SPDX-License-Identifier: APACHE-2.0
|
||||
*
|
||||
* This software is subject to an open source license and is distributed by
|
||||
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
|
||||
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* USB DEVICE HID REPORT
|
||||
*
|
||||
* Filename : usbd_hid_report.h
|
||||
* Version : V4.06.01
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MODULE
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef USBD_HID_REPORT_MODULE_PRESENT
|
||||
#define USBD_HID_REPORT_MODULE_PRESENT
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* INCLUDE FILES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* EXTERNS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef USBD_HID_REPORT_MODULE
|
||||
#define USBD_HID_REPORT_EXT
|
||||
#else
|
||||
#define USBD_HID_REPORT_EXT extern
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DEFINES
|
||||
*
|
||||
* Note(s) : (1) See 'Device Class Definition for Human Interface Devices (HID), 6/27/01, Version 1.11'
|
||||
* for more details about :
|
||||
*
|
||||
* (a) SHORT ITEM TYPES (Section 6.2.2.2)
|
||||
*
|
||||
* (e) MAIN ITEMS (Section 6.2.2.4)
|
||||
*
|
||||
* (f) INPUT/OUTPUT/FEATURE ITEMS (Section 6.2.2.5)
|
||||
*
|
||||
* (g) COLLECTION ITEMS (Section 6.2.2.6)
|
||||
*
|
||||
* (h) GLOBAL ITEMS (Section 6.2.2.7)
|
||||
*
|
||||
* (i) LOCAL ITEMS (Section 6.2.2.7)
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/* ------------------ HID REPORT DESC ----------------- */
|
||||
#define USBD_HID_ITEM_LONG 0xFE
|
||||
/* Short item types (see Note #1a). */
|
||||
#define USBD_HID_ITEM_TYPE_MAIN 0x00
|
||||
#define USBD_HID_ITEM_TYPE_GLOBAL 0x04
|
||||
#define USBD_HID_ITEM_TYPE_LOCAL 0x08
|
||||
#define USBD_HID_ITEM_TYPE_RESERVED 0x0C
|
||||
/* Main item (see Note #1e). */
|
||||
#define USBD_HID_MAIN_INPUT 0x80
|
||||
#define USBD_HID_MAIN_OUTPUT 0x90
|
||||
#define USBD_HID_MAIN_COLLECTION 0xA0
|
||||
#define USBD_HID_MAIN_FEATURE 0xB0
|
||||
#define USBD_HID_MAIN_ENDCOLLECTION 0xC0
|
||||
/* Input/output/feature item (see Note #1f). */
|
||||
#define USBD_HID_MAIN_CONSTANT 0x01
|
||||
#define USBD_HID_MAIN_DATA 0x00
|
||||
#define USBD_HID_MAIN_VARIABLE 0x02
|
||||
#define USBD_HID_MAIN_ARRAY 0x00
|
||||
#define USBD_HID_MAIN_RELATIVE 0x04
|
||||
#define USBD_HID_MAIN_ABSOLUTE 0x00
|
||||
#define USBD_HID_MAIN_WRAP 0x08
|
||||
#define USBD_HID_MAIN_NOWRAP 0x00
|
||||
#define USBD_HID_MAIN_NONLINEAR 0x10
|
||||
#define USBD_HID_MAIN_LINEAR 0x00
|
||||
#define USBD_HID_MAIN_NOPREFERRED 0x20
|
||||
#define USBD_HID_MAIN_PREFERREDSTATE 0x00
|
||||
#define USBD_HID_MAIN_NULLSTATE 0x40
|
||||
#define USBD_HID_MAIN_NONULLPOSITION 0x00
|
||||
#define USBD_HID_MAIN_VOLATILE 0x80
|
||||
#define USBD_HID_MAIN_NONVOLATILE 0x00
|
||||
#define USBD_HID_MAIN_BUFFEREDBYTES 0x0100
|
||||
#define USBD_HID_MAIN_BITFIELD 0x0000
|
||||
/* Collection item (see Note #1g). */
|
||||
#define USBD_HID_COLLECTION_PHYSICAL 0x00
|
||||
#define USBD_HID_COLLECTION_APPLICATION 0x01
|
||||
#define USBD_HID_COLLECTION_LOGICAL 0x02
|
||||
#define USBD_HID_COLLECTION_REPORT 0x03
|
||||
#define USBD_HID_COLLECTION_NAMEDARRAY 0x04
|
||||
#define USBD_HID_COLLECTION_USAGESWITCH 0x05
|
||||
#define USBD_HID_COLLECTION_USAGEMODIFIER 0x06
|
||||
/* Global item (see Note #1h). */
|
||||
#define USBD_HID_GLOBAL_USAGE_PAGE 0x04
|
||||
#define USBD_HID_GLOBAL_LOG_MIN 0x14
|
||||
#define USBD_HID_GLOBAL_LOG_MAX 0x24
|
||||
#define USBD_HID_GLOBAL_PHY_MIN 0x34
|
||||
#define USBD_HID_GLOBAL_PHY_MAX 0x44
|
||||
#define USBD_HID_GLOBAL_UNIT_EXPONENT 0x54
|
||||
#define USBD_HID_GLOBAL_UNIT 0x64
|
||||
#define USBD_HID_GLOBAL_REPORT_SIZE 0x74
|
||||
#define USBD_HID_GLOBAL_REPORT_ID 0x84
|
||||
#define USBD_HID_GLOBAL_REPORT_COUNT 0x94
|
||||
#define USBD_HID_GLOBAL_PUSH 0xA4
|
||||
#define USBD_HID_GLOBAL_POP 0xB4
|
||||
/* Local item (see Note #1i). */
|
||||
#define USBD_HID_LOCAL_USAGE 0x08
|
||||
#define USBD_HID_LOCAL_USAGE_MIN 0x18
|
||||
#define USBD_HID_LOCAL_USAGE_MAX 0x28
|
||||
#define USBD_HID_LOCAL_DESIGNATOR_INDEX 0x38
|
||||
#define USBD_HID_LOCAL_DESIGNATOR_MIN 0x48
|
||||
#define USBD_HID_LOCAL_DESIGNATOR_MAX 0x58
|
||||
#define USBD_HID_LOCAL_STRING_INDEX 0x78
|
||||
#define USBD_HID_LOCAL_STRING_MIN 0x88
|
||||
#define USBD_HID_LOCAL_STRING_MAX 0x98
|
||||
#define USBD_HID_LOCAL_DELIMITER 0xA8
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* HID PHYSICAL DESCRIPTOR DEFINES
|
||||
*
|
||||
* Note(s) : (1) See 'Device Class Definition for Human Interface Devices Version 1.11', Section 6.2.3.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/* ---------- HID PHYSICAL DESC (see Note #1) --------- */
|
||||
/* Bias values. */
|
||||
#define USBD_HID_BIAS_NOT_APPLICABLE 0
|
||||
#define USBD_HID_BIAS_RIGHT_HAND 1
|
||||
#define USBD_HID_BIAS_LEFT_HAND 2
|
||||
#define USBD_HID_BIAS_BOTH_HANDS 3
|
||||
#define USBD_HID_BIAS_EITHER_HAND 4
|
||||
/* Designator values. */
|
||||
#define USBD_HID_DESIGNATOR_NONE 0x00
|
||||
#define USBD_HID_DESIGNATOR_HAND 0x01
|
||||
#define USBD_HID_DESIGNATOR_EYEBALL 0x02
|
||||
#define USBD_HID_DESIGNATOR_EYEBROW 0x03
|
||||
#define USBD_HID_DESIGNATOR_EYELID 0x04
|
||||
#define USBD_HID_DESIGNATOR_EAR 0x05
|
||||
#define USBD_HID_DESIGNATOR_NOSE 0x06
|
||||
#define USBD_HID_DESIGNATOR_MOUTH 0x07
|
||||
#define USBD_HID_DESIGNATOR_UPPER_LIP 0x08
|
||||
#define USBD_HID_DESIGNATOR_LOWER_LIP 0x09
|
||||
#define USBD_HID_DESIGNATOR_JAW 0x0A
|
||||
#define USBD_HID_DESIGNATOR_NECK 0x0B
|
||||
#define USBD_HID_DESIGNATOR_UPPER_ARM 0x0C
|
||||
#define USBD_HID_DESIGNATOR_ELBOW 0x0D
|
||||
#define USBD_HID_DESIGNATOR_FOREARM 0x0E
|
||||
#define USBD_HID_DESIGNATOR_WRIST 0x0F
|
||||
#define USBD_HID_DESIGNATOR_PALM 0x10
|
||||
#define USBD_HID_DESIGNATOR_THUMB 0x11
|
||||
#define USBD_HID_DESIGNATOR_INDEX_FINGER 0x12
|
||||
#define USBD_HID_DESIGNATOR_MIDDLE_FINGER 0x13
|
||||
#define USBD_HID_DESIGNATOR_RING_FINGER 0x14
|
||||
#define USBD_HID_DESIGNATOR_LITTLE_FINGER 0x15
|
||||
#define USBD_HID_DESIGNATOR_HEAD 0x16
|
||||
#define USBD_HID_DESIGNATOR_SHOULDER 0x17
|
||||
#define USBD_HID_DESIGNATOR_HIP 0x18
|
||||
#define USBD_HID_DESIGNATOR_WAIST 0x19
|
||||
#define USBD_HID_DESIGNATOR_THIGH 0x1A
|
||||
#define USBD_HID_DESIGNATOR_KNEE 0x1B
|
||||
#define USBD_HID_DESIGNATOR_CALF 0x1C
|
||||
#define USBD_HID_DESIGNATOR_ANKLE 0x1D
|
||||
#define USBD_HID_DESIGNATOR_FOOT 0x1E
|
||||
#define USBD_HID_DESIGNATOR_HEEL 0x1F
|
||||
#define USBD_HID_DESIGNATOR_BALL_OF_FOOT 0x20
|
||||
#define USBD_HID_DESIGNATOR_BIG_TOE 0x21
|
||||
#define USBD_HID_DESIGNATOR_SECOND_TOE 0x22
|
||||
#define USBD_HID_DESIGNATOR_THIRD_TOE 0x23
|
||||
#define USBD_HID_DESIGNATOR_FOURTH_TOE 0x24
|
||||
#define USBD_HID_DESIGNATOR_LITTLE_TOE 0x25
|
||||
#define USBD_HID_DESIGNATOR_BROW 0x26
|
||||
#define USBD_HID_DESIGNATOR_CHEEK 0x27
|
||||
/* Qualifier values. */
|
||||
#define USBD_HID_QUALIFIER_NOT_APPLICABLE 0
|
||||
#define USBD_HID_QUALIFIER_RIGHT 1
|
||||
#define USBD_HID_QUALIFIER_LEFT 2
|
||||
#define USBD_HID_QUALIFIER_BOTH 3
|
||||
#define USBD_HID_QUALIFIER_EITHER 4
|
||||
#define USBD_HID_QUALIFIER_CENTER 5
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* HID USAGE PAGES
|
||||
*
|
||||
* Note(s) : (1) See 'Universal Serial Bus HID Usage Tables', Version 1.12, Section 3 for more details
|
||||
* about Usage Pages.
|
||||
*
|
||||
* (2) See 'Universal Serial Bus HID Usage Tables', Version 1.12, Section 4 for more details
|
||||
* about Generic Desktop Page usages and controls.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
/* ------------- USAGE PAGES (see Note #1) ------------ */
|
||||
#define USBD_HID_USAGE_PAGE_UNDEFINED 0x00
|
||||
#define USBD_HID_USAGE_PAGE_GENERIC_DESKTOP_CONTROLS 0x01
|
||||
#define USBD_HID_USAGE_PAGE_SIMULATION_CONTROLS 0x02
|
||||
#define USBD_HID_USAGE_PAGE_VR_CONTROLS 0x03
|
||||
#define USBD_HID_USAGE_PAGE_SPORT_CONTROLS 0x04
|
||||
#define USBD_HID_USAGE_PAGE_GAME_CONTROLS 0x05
|
||||
#define USBD_HID_USAGE_PAGE_GENERIC_DEVICE_CONTROLS 0x06
|
||||
#define USBD_HID_USAGE_PAGE_KEYBOARD 0x07
|
||||
#define USBD_HID_USAGE_PAGE_LEDS 0x08
|
||||
#define USBD_HID_USAGE_PAGE_BUTTON 0x09
|
||||
#define USBD_HID_USAGE_PAGE_ORDINAL 0x0A
|
||||
#define USBD_HID_USAGE_PAGE_TELEPHONY 0x0B
|
||||
#define USBD_HID_USAGE_PAGE_CONSUMER 0x0C
|
||||
#define USBD_HID_USAGE_PAGE_DIGITIZER 0x0D
|
||||
#define USBD_HID_USAGE_PAGE_PID_PAGE 0x0F
|
||||
#define USBD_HID_USAGE_PAGE_UNICODE 0x10
|
||||
#define USBD_HID_USAGE_PAGE_ALPHANUMERIC_DISPLAY 0x14
|
||||
#define USBD_HID_USAGE_PAGE_MEDICAL_INSTRUMENTS 0x40
|
||||
#define USBD_HID_USAGE_PAGE_MONITOR_0 0x80
|
||||
#define USBD_HID_USAGE_PAGE_MONITOR_1 0x81
|
||||
#define USBD_HID_USAGE_PAGE_MONITOR_2 0x82
|
||||
#define USBD_HID_USAGE_PAGE_MONITOR_3 0x83
|
||||
#define USBD_HID_USAGE_PAGE_POWER_0 0x84
|
||||
#define USBD_HID_USAGE_PAGE_POWER_1 0x85
|
||||
#define USBD_HID_USAGE_PAGE_POWER_2 0x86
|
||||
#define USBD_HID_USAGE_PAGE_POWER_3 0x87
|
||||
#define USBD_HID_USAGE_PAGE_BAR_CODE_SCANNER_PAGE 0x8C
|
||||
#define USBD_HID_USAGE_PAGE_SCALE_PAGE 0x8D
|
||||
#define USBD_HID_USAGE_PAGE_MSR_DEVICES 0x8E
|
||||
#define USBD_HID_USAGE_PAGE_POINT_OF_SALE_PAGES 0x8F
|
||||
#define USBD_HID_USAGE_PAGE_CAMERA_CONTROL_PAGE 0x90
|
||||
#define USBD_HID_USAGE_PAGE_ARCADE_PAGE 0x91
|
||||
|
||||
/* -------- GENERIC DESKTOP PAGE USAGES & CTRL -------- */
|
||||
/* See Note #2. */
|
||||
#define USBD_HID_CP_POINTER 0x01
|
||||
#define USBD_HID_CA_MOUSE 0x02
|
||||
#define USBD_HID_CA_JOYSTICK 0x04
|
||||
#define USBD_HID_CA_GAME_PAD 0x05
|
||||
#define USBD_HID_CA_KEYBOARD 0x06
|
||||
#define USBD_HID_CA_KEYPAD 0x07
|
||||
#define USBD_HID_CA_MULTI_AXIS_CONTROLLER 0x08
|
||||
#define USBD_HID_DV_X 0x30
|
||||
#define USBD_HID_DV_Y 0x31
|
||||
#define USBD_HID_DV_Z 0x32
|
||||
#define USBD_HID_DV_WHEEL 0x38
|
||||
#define USBD_HID_CA_SYSTEM_CONTROL 0x80
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DATA TYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
typedef enum usbd_hid_report_type {
|
||||
USBD_HID_REPORT_TYPE_NONE = 0,
|
||||
USBD_HID_REPORT_TYPE_INPUT,
|
||||
USBD_HID_REPORT_TYPE_OUTPUT,
|
||||
USBD_HID_REPORT_TYPE_FEATURE
|
||||
} USBD_HID_REPORT_TYPE;
|
||||
|
||||
|
||||
typedef struct usbd_hid_report_id USBD_HID_REPORT_ID;
|
||||
|
||||
|
||||
struct usbd_hid_report_id {
|
||||
CPU_INT08U ID;
|
||||
CPU_INT16U Size;
|
||||
CPU_INT08U *DataPtr;
|
||||
USBD_HID_REPORT_ID *NextPtr;
|
||||
|
||||
CPU_INT08U ClassNbr;
|
||||
CPU_INT08U IdleCnt;
|
||||
CPU_INT08U IdleRate;
|
||||
CPU_BOOLEAN Update;
|
||||
USBD_HID_REPORT_ID *TmrNextPtr;
|
||||
};
|
||||
|
||||
|
||||
typedef struct usbd_hid_report {
|
||||
CPU_BOOLEAN HasReports;
|
||||
CPU_INT16U MaxInputReportSize;
|
||||
CPU_INT16U MaxFeatureReportSize;
|
||||
CPU_INT08U *MaxFeatureReportPtr;
|
||||
CPU_INT16U MaxOutputReportSize;
|
||||
CPU_INT08U *MaxOutputReportPtr;
|
||||
USBD_HID_REPORT_ID *Reports[3]; /* Index 0: Input Reports; 1: Output; 2: Feature. */
|
||||
} USBD_HID_REPORT;
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MACRO'S
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* FUNCTION PROTOTYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_HID_Report_Init ( USBD_ERR *p_err);
|
||||
|
||||
void USBD_HID_Report_Parse ( CPU_INT08U class_nbr,
|
||||
const CPU_INT08U *p_report_data,
|
||||
CPU_INT16U report_data_len,
|
||||
USBD_HID_REPORT *p_report,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
CPU_INT16U USBD_HID_ReportID_InfoGet (const USBD_HID_REPORT *p_report,
|
||||
USBD_HID_REPORT_TYPE report_type,
|
||||
CPU_INT08U report_id,
|
||||
CPU_INT08U **p_buf,
|
||||
CPU_BOOLEAN *p_is_largest,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
CPU_INT08U USBD_HID_ReportID_IdleGet (const USBD_HID_REPORT *p_report,
|
||||
CPU_INT08U report_id,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_HID_ReportID_IdleSet (const USBD_HID_REPORT *p_report,
|
||||
CPU_INT08U report_id,
|
||||
CPU_INT08U idle_rate,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
CPU_BOOLEAN USBD_HID_ReportID_IsLargestIn (const USBD_HID_REPORT *p_report,
|
||||
CPU_INT08U report_id,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_HID_Report_RemoveAllIdle (const USBD_HID_REPORT *p_report);
|
||||
|
||||
void USBD_HID_Report_TmrTaskHandler(void);
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* CONFIGURATION ERRORS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef USBD_HID_CFG_MAX_NBR_REPORT_ID
|
||||
#error "USBD_HID_CFG_MAX_NBR_REPORT_ID not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
|
||||
#endif
|
||||
|
||||
#if (USBD_HID_CFG_MAX_NBR_REPORT_ID < 1u)
|
||||
#error "USBD_HID_CFG_MAX_NBR_REPORT_ID illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
|
||||
#endif
|
||||
|
||||
#ifndef USBD_HID_CFG_MAX_NBR_REPORT_PUSHPOP
|
||||
#error "USBD_HID_CFG_MAX_NBR_REPORT_PUSHPOP not #define'd in 'usbd_cfg.h' [MUST be >= 0]"
|
||||
#endif
|
||||
|
||||
#if (USBD_HID_CFG_MAX_NBR_REPORT_PUSHPOP < 0)
|
||||
#error "USBD_HID_CFG_MAX_NBR_REPORT_PUSHPOP illegally #define'd in 'usbd_cfg.h' [MUST be >= 0]"
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MODULE END
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user