diff options
| author | Damien George | 2017-09-06 13:40:51 +1000 |
|---|---|---|
| committer | Damien George | 2017-09-06 13:40:51 +1000 |
| commit | 01dd7804b87d60b2deab16712eccb3b97351a9b7 (patch) | |
| tree | 1aa21f38a872b8e62a3d4e4f74f68033c6f827e4 /stmhal/usbhost/Class/HID/Src | |
| parent | a9862b30068fc9df1022f08019fb35aaa5085f64 (diff) | |
ports: Make new ports/ sub-directory and move all ports there.
This is to keep the top-level directory clean, to make it clear what is
core and what is a port, and to allow the repository to grow with new ports
in a sustainable way.
Diffstat (limited to 'stmhal/usbhost/Class/HID/Src')
| -rw-r--r-- | stmhal/usbhost/Class/HID/Src/usbh_hid.c | 800 | ||||
| -rw-r--r-- | stmhal/usbhost/Class/HID/Src/usbh_hid_keybd.c | 418 | ||||
| -rw-r--r-- | stmhal/usbhost/Class/HID/Src/usbh_hid_mouse.c | 267 | ||||
| -rw-r--r-- | stmhal/usbhost/Class/HID/Src/usbh_hid_parser.c | 235 |
4 files changed, 0 insertions, 1720 deletions
diff --git a/stmhal/usbhost/Class/HID/Src/usbh_hid.c b/stmhal/usbhost/Class/HID/Src/usbh_hid.c deleted file mode 100644 index a56f45c5c..000000000 --- a/stmhal/usbhost/Class/HID/Src/usbh_hid.c +++ /dev/null @@ -1,800 +0,0 @@ -/**
- ******************************************************************************
- * @file usbh_hid.c
- * @author MCD Application Team
- * @version V3.0.0
- * @date 18-February-2014
- * @brief This file is the HID Layer Handlers for USB Host HID class.
- *
- * @verbatim
- *
- * ===================================================================
- * HID Class Description
- * ===================================================================
- * This module manages the MSC class V1.11 following the "Device Class Definition
- * for Human Interface Devices (HID) Version 1.11 Jun 27, 2001".
- * This driver implements the following aspects of the specification:
- * - The Boot Interface Subclass
- * - The Mouse and Keyboard protocols
- *
- * @endverbatim
- *
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
- *
- * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.st.com/software_license_agreement_liberty_v2
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- */
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_hid.h"
-#include "usbh_hid_parser.h"
-
-
-/** @addtogroup USBH_LIB
-* @{
-*/
-
-/** @addtogroup USBH_CLASS
-* @{
-*/
-
-/** @addtogroup USBH_HID_CLASS
-* @{
-*/
-
-/** @defgroup USBH_HID_CORE
-* @brief This file includes HID Layer Handlers for USB Host HID class.
-* @{
-*/
-
-/** @defgroup USBH_HID_CORE_Private_TypesDefinitions
-* @{
-*/
-/**
-* @}
-*/
-
-
-/** @defgroup USBH_HID_CORE_Private_Defines
-* @{
-*/
-/**
-* @}
-*/
-
-
-/** @defgroup USBH_HID_CORE_Private_Macros
-* @{
-*/
-/**
-* @}
-*/
-
-
-/** @defgroup USBH_HID_CORE_Private_Variables
-* @{
-*/
-
-/**
-* @}
-*/
-
-
-/** @defgroup USBH_HID_CORE_Private_FunctionPrototypes
-* @{
-*/
-
-static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_HID_InterfaceDeInit (USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_HID_ClassRequest(USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost);
-static USBH_StatusTypeDef USBH_HID_SOFProcess(USBH_HandleTypeDef *phost);
-static void USBH_HID_ParseHIDDesc (HID_DescTypeDef *desc, uint8_t *buf);
-
-extern USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost);
-extern USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost);
-
-USBH_ClassTypeDef HID_Class =
-{
- "HID",
- USB_HID_CLASS,
- USBH_HID_InterfaceInit,
- USBH_HID_InterfaceDeInit,
- USBH_HID_ClassRequest,
- USBH_HID_Process,
- USBH_HID_SOFProcess,
- NULL,
-};
-/**
-* @}
-*/
-
-
-/** @defgroup USBH_HID_CORE_Private_Functions
-* @{
-*/
-
-
-/**
- * @brief USBH_HID_InterfaceInit
- * The function init the HID class.
- * @param phost: Host handle
- * @retval USBH Status
- */
-static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost)
-{
- uint8_t max_ep;
- uint8_t num = 0;
- uint8_t interface;
-
- USBH_StatusTypeDef status = USBH_FAIL ;
- HID_HandleTypeDef *HID_Handle;
-
- interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, 0xFF);
-
- if(interface == 0xFF) /* No Valid Interface */
- {
- status = USBH_FAIL;
- USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name);
- }
- else
- {
- USBH_SelectInterface (phost, interface);
- phost->pActiveClass->pData = (HID_HandleTypeDef *)USBH_malloc (sizeof(HID_HandleTypeDef));
- HID_Handle = phost->pActiveClass->pData;
- HID_Handle->state = HID_ERROR;
-
- /*Decode Bootclass Protocl: Mouse or Keyboard*/
- if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_KEYBRD_BOOT_CODE)
- {
- USBH_UsrLog ("KeyBoard device found!");
- HID_Handle->Init = USBH_HID_KeybdInit;
- }
- else if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_MOUSE_BOOT_CODE)
- {
- USBH_UsrLog ("Mouse device found!");
- HID_Handle->Init = USBH_HID_MouseInit;
- }
- else
- {
- USBH_UsrLog ("Protocol not supported.");
- return USBH_FAIL;
- }
-
- HID_Handle->state = HID_INIT;
- HID_Handle->ctl_state = HID_REQ_INIT;
- HID_Handle->ep_addr = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress;
- HID_Handle->length = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].wMaxPacketSize;
- HID_Handle->poll = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bInterval ;
-
- if (HID_Handle->poll < HID_MIN_POLL)
- {
- HID_Handle->poll = HID_MIN_POLL;
- }
-
- /* Check fo available number of endpoints */
- /* Find the number of EPs in the Interface Descriptor */
- /* Choose the lower number in order not to overrun the buffer allocated */
- max_ep = ( (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bNumEndpoints <= USBH_MAX_NUM_ENDPOINTS) ?
- phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bNumEndpoints :
- USBH_MAX_NUM_ENDPOINTS);
-
-
- /* Decode endpoint IN and OUT address from interface descriptor */
- for ( ;num < max_ep; num++)
- {
- if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress & 0x80)
- {
- HID_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress);
- HID_Handle->InPipe =\
- USBH_AllocPipe(phost, HID_Handle->InEp);
-
- /* Open pipe for IN endpoint */
- USBH_OpenPipe (phost,
- HID_Handle->InPipe,
- HID_Handle->InEp,
- phost->device.address,
- phost->device.speed,
- USB_EP_TYPE_INTR,
- HID_Handle->length);
-
- USBH_LL_SetToggle (phost, HID_Handle->InPipe, 0);
-
- }
- else
- {
- HID_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress);
- HID_Handle->OutPipe =\
- USBH_AllocPipe(phost, HID_Handle->OutEp);
-
- /* Open pipe for OUT endpoint */
- USBH_OpenPipe (phost,
- HID_Handle->OutPipe,
- HID_Handle->OutEp,
- phost->device.address,
- phost->device.speed,
- USB_EP_TYPE_INTR,
- HID_Handle->length);
-
- USBH_LL_SetToggle (phost, HID_Handle->OutPipe, 0);
- }
-
- }
- status = USBH_OK;
- }
- return status;
-}
-
-/**
- * @brief USBH_HID_InterfaceDeInit
- * The function DeInit the Pipes used for the HID class.
- * @param phost: Host handle
- * @retval USBH Status
- */
-USBH_StatusTypeDef USBH_HID_InterfaceDeInit (USBH_HandleTypeDef *phost )
-{
- HID_HandleTypeDef *HID_Handle = phost->pActiveClass->pData;
-
- if(HID_Handle->InPipe != 0x00)
- {
- USBH_ClosePipe (phost, HID_Handle->InPipe);
- USBH_FreePipe (phost, HID_Handle->InPipe);
- HID_Handle->InPipe = 0; /* Reset the pipe as Free */
- }
-
- if(HID_Handle->OutPipe != 0x00)
- {
- USBH_ClosePipe(phost, HID_Handle->OutPipe);
- USBH_FreePipe (phost, HID_Handle->OutPipe);
- HID_Handle->OutPipe = 0; /* Reset the pipe as Free */
- }
-
- if(phost->pActiveClass->pData)
- {
- USBH_free (phost->pActiveClass->pData);
- }
-
- return USBH_OK;
-}
-
-/**
- * @brief USBH_HID_ClassRequest
- * The function is responsible for handling Standard requests
- * for HID class.
- * @param phost: Host handle
- * @retval USBH Status
- */
-static USBH_StatusTypeDef USBH_HID_ClassRequest(USBH_HandleTypeDef *phost)
-{
-
- USBH_StatusTypeDef status = USBH_BUSY;
- USBH_StatusTypeDef classReqStatus = USBH_BUSY;
- HID_HandleTypeDef *HID_Handle = phost->pActiveClass->pData;
-
- /* Switch HID state machine */
- switch (HID_Handle->ctl_state)
- {
- case HID_REQ_INIT:
- case HID_REQ_GET_HID_DESC:
-
- /* Get HID Desc */
- if (USBH_HID_GetHIDDescriptor (phost, USB_HID_DESC_SIZE)== USBH_OK)
- {
-
- USBH_HID_ParseHIDDesc(&HID_Handle->HID_Desc, phost->device.Data);
- HID_Handle->ctl_state = HID_REQ_GET_REPORT_DESC;
- }
-
- break;
- case HID_REQ_GET_REPORT_DESC:
-
-
- /* Get Report Desc */
- if (USBH_HID_GetHIDReportDescriptor(phost, HID_Handle->HID_Desc.wItemLength) == USBH_OK)
- {
- /* The decriptor is available in phost->device.Data */
-
- HID_Handle->ctl_state = HID_REQ_SET_IDLE;
- }
-
- break;
-
- case HID_REQ_SET_IDLE:
-
- classReqStatus = USBH_HID_SetIdle (phost, 0, 0);
-
- /* set Idle */
- if (classReqStatus == USBH_OK)
- {
- HID_Handle->ctl_state = HID_REQ_SET_PROTOCOL;
- }
- else if(classReqStatus == USBH_NOT_SUPPORTED)
- {
- HID_Handle->ctl_state = HID_REQ_SET_PROTOCOL;
- }
- break;
-
- case HID_REQ_SET_PROTOCOL:
- /* set protocol */
- if (USBH_HID_SetProtocol (phost, 0) == USBH_OK)
- {
- HID_Handle->ctl_state = HID_REQ_IDLE;
-
- /* all requests performed*/
- phost->pUser(phost, HOST_USER_CLASS_ACTIVE);
- status = USBH_OK;
- }
- break;
-
- case HID_REQ_IDLE:
- default:
- break;
- }
-
- return status;
-}
-
-/**
- * @brief USBH_HID_Process
- * The function is for managing state machine for HID data transfers
- * @param phost: Host handle
- * @retval USBH Status
- */
-static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost)
-{
- USBH_StatusTypeDef status = USBH_OK;
- HID_HandleTypeDef *HID_Handle = phost->pActiveClass->pData;
-
- switch (HID_Handle->state)
- {
- case HID_INIT:
- HID_Handle->Init(phost);
- case HID_IDLE:
- if(USBH_HID_GetReport (phost,
- 0x01,
- 0,
- HID_Handle->pData,
- HID_Handle->length) == USBH_OK)
- {
-
- fifo_write(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length);
- HID_Handle->state = HID_SYNC;
- }
-
- break;
-
- case HID_SYNC:
-
- /* Sync with start of Even Frame */
- if(phost->Timer & 1)
- {
- HID_Handle->state = HID_GET_DATA;
- }
-#if (USBH_USE_OS == 1)
- osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif
- break;
-
- case HID_GET_DATA:
-
- USBH_InterruptReceiveData(phost,
- HID_Handle->pData,
- HID_Handle->length,
- HID_Handle->InPipe);
-
- HID_Handle->state = HID_POLL;
- HID_Handle->timer = phost->Timer;
- HID_Handle->DataReady = 0;
- break;
-
- case HID_POLL:
-
- if(USBH_LL_GetURBState(phost , HID_Handle->InPipe) == USBH_URB_DONE)
- {
- if(HID_Handle->DataReady == 0)
- {
- fifo_write(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length);
- HID_Handle->DataReady = 1;
- USBH_HID_EventCallback(phost);
-#if (USBH_USE_OS == 1)
- osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif
- }
- }
- else if(USBH_LL_GetURBState(phost , HID_Handle->InPipe) == USBH_URB_STALL) /* IN Endpoint Stalled */
- {
-
- /* Issue Clear Feature on interrupt IN endpoint */
- if(USBH_ClrFeature(phost,
- HID_Handle->ep_addr) == USBH_OK)
- {
- /* Change state to issue next IN token */
- HID_Handle->state = HID_GET_DATA;
- }
- }
-
-
- break;
-
- default:
- break;
- }
- return status;
-}
-
-/**
- * @brief USBH_HID_SOFProcess
- * The function is for managing the SOF Process
- * @param phost: Host handle
- * @retval USBH Status
- */
-static USBH_StatusTypeDef USBH_HID_SOFProcess(USBH_HandleTypeDef *phost)
-{
- HID_HandleTypeDef *HID_Handle = phost->pActiveClass->pData;
-
- if(HID_Handle->state == HID_POLL)
- {
- if(( phost->Timer - HID_Handle->timer) >= HID_Handle->poll)
- {
- HID_Handle->state = HID_GET_DATA;
-#if (USBH_USE_OS == 1)
- osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif
- }
- }
- return USBH_OK;
-}
-
-/**
-* @brief USBH_Get_HID_ReportDescriptor
- * Issue report Descriptor command to the device. Once the response
- * received, parse the report descriptor and update the status.
- * @param phost: Host handle
- * @param Length : HID Report Descriptor Length
- * @retval USBH Status
- */
-USBH_StatusTypeDef USBH_HID_GetHIDReportDescriptor (USBH_HandleTypeDef *phost,
- uint16_t length)
-{
-
- USBH_StatusTypeDef status;
-
- status = USBH_GetDescriptor(phost,
- USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD,
- USB_DESC_HID_REPORT,
- phost->device.Data,
- length);
-
- /* HID report descriptor is available in phost->device.Data.
- In case of USB Boot Mode devices for In report handling ,
- HID report descriptor parsing is not required.
- In case, for supporting Non-Boot Protocol devices and output reports,
- user may parse the report descriptor*/
-
-
- return status;
-}
-
-/**
- * @brief USBH_Get_HID_Descriptor
- * Issue HID Descriptor command to the device. Once the response
- * received, parse the report descriptor and update the status.
- * @param phost: Host handle
- * @param Length : HID Descriptor Length
- * @retval USBH Status
- */
-USBH_StatusTypeDef USBH_HID_GetHIDDescriptor (USBH_HandleTypeDef *phost,
- uint16_t length)
-{
-
- USBH_StatusTypeDef status;
-
- status = USBH_GetDescriptor( phost,
- USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD,
- USB_DESC_HID,
- phost->device.Data,
- length);
-
- return status;
-}
-
-/**
- * @brief USBH_Set_Idle
- * Set Idle State.
- * @param phost: Host handle
- * @param duration: Duration for HID Idle request
- * @param reportId : Targetted report ID for Set Idle request
- * @retval USBH Status
- */
-USBH_StatusTypeDef USBH_HID_SetIdle (USBH_HandleTypeDef *phost,
- uint8_t duration,
- uint8_t reportId)
-{
-
- phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\
- USB_REQ_TYPE_CLASS;
-
-
- phost->Control.setup.b.bRequest = USB_HID_SET_IDLE;
- phost->Control.setup.b.wValue.w = (duration << 8 ) | reportId;
-
- phost->Control.setup.b.wIndex.w = 0;
- phost->Control.setup.b.wLength.w = 0;
-
- return USBH_CtlReq(phost, 0 , 0 );
-}
-
-
-/**
- * @brief USBH_HID_Set_Report
- * Issues Set Report
- * @param phost: Host handle
- * @param reportType : Report type to be sent
- * @param reportId : Targetted report ID for Set Report request
- * @param reportBuff : Report Buffer
- * @param reportLen : Length of data report to be send
- * @retval USBH Status
- */
-USBH_StatusTypeDef USBH_HID_SetReport (USBH_HandleTypeDef *phost,
- uint8_t reportType,
- uint8_t reportId,
- uint8_t* reportBuff,
- uint8_t reportLen)
-{
-
- phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\
- USB_REQ_TYPE_CLASS;
-
-
- phost->Control.setup.b.bRequest = USB_HID_SET_REPORT;
- phost->Control.setup.b.wValue.w = (reportType << 8 ) | reportId;
-
- phost->Control.setup.b.wIndex.w = 0;
- phost->Control.setup.b.wLength.w = reportLen;
-
- return USBH_CtlReq(phost, reportBuff , reportLen );
-}
-
-
-/**
- * @brief USBH_HID_GetReport
- * retreive Set Report
- * @param phost: Host handle
- * @param reportType : Report type to be sent
- * @param reportId : Targetted report ID for Set Report request
- * @param reportBuff : Report Buffer
- * @param reportLen : Length of data report to be send
- * @retval USBH Status
- */
-USBH_StatusTypeDef USBH_HID_GetReport (USBH_HandleTypeDef *phost,
- uint8_t reportType,
- uint8_t reportId,
- uint8_t* reportBuff,
- uint8_t reportLen)
-{
-
- phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE |\
- USB_REQ_TYPE_CLASS;
-
-
- phost->Control.setup.b.bRequest = USB_HID_GET_REPORT;
- phost->Control.setup.b.wValue.w = (reportType << 8 ) | reportId;
-
- phost->Control.setup.b.wIndex.w = 0;
- phost->Control.setup.b.wLength.w = reportLen;
-
- return USBH_CtlReq(phost, reportBuff , reportLen );
-}
-
-/**
- * @brief USBH_Set_Protocol
- * Set protocol State.
- * @param phost: Host handle
- * @param protocol : Set Protocol for HID : boot/report protocol
- * @retval USBH Status
- */
-USBH_StatusTypeDef USBH_HID_SetProtocol(USBH_HandleTypeDef *phost,
- uint8_t protocol)
-{
-
-
- phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\
- USB_REQ_TYPE_CLASS;
-
-
- phost->Control.setup.b.bRequest = USB_HID_SET_PROTOCOL;
- phost->Control.setup.b.wValue.w = protocol != 0 ? 0 : 1;
- phost->Control.setup.b.wIndex.w = 0;
- phost->Control.setup.b.wLength.w = 0;
-
- return USBH_CtlReq(phost, 0 , 0 );
-
-}
-
-/**
- * @brief USBH_ParseHIDDesc
- * This function Parse the HID descriptor
- * @param desc: HID Descriptor
- * @param buf: Buffer where the source descriptor is available
- * @retval None
- */
-static void USBH_HID_ParseHIDDesc (HID_DescTypeDef *desc, uint8_t *buf)
-{
-
- desc->bLength = *(uint8_t *) (buf + 0);
- desc->bDescriptorType = *(uint8_t *) (buf + 1);
- desc->bcdHID = LE16 (buf + 2);
- desc->bCountryCode = *(uint8_t *) (buf + 4);
- desc->bNumDescriptors = *(uint8_t *) (buf + 5);
- desc->bReportDescriptorType = *(uint8_t *) (buf + 6);
- desc->wItemLength = LE16 (buf + 7);
-}
-
-/**
- * @brief USBH_HID_GetDeviceType
- * Return Device function.
- * @param phost: Host handle
- * @retval HID function: HID_MOUSE / HID_KEYBOARD
- */
-HID_TypeTypeDef USBH_HID_GetDeviceType(USBH_HandleTypeDef *phost)
-{
- HID_TypeTypeDef type = HID_UNKNOWN;
-
- if(phost->gState == HOST_CLASS)
- {
-
- if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol \
- == HID_KEYBRD_BOOT_CODE)
- {
- type = HID_KEYBOARD;
- }
- else if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol \
- == HID_MOUSE_BOOT_CODE)
- {
- type= HID_MOUSE;
- }
- }
- return type;
-}
-
-/**
- * @brief fifo_init
- * Initialize FIFO.
- * @param f: Fifo address
- * @param buf: Fifo buffer
- * @param size: Fifo Size
- * @retval none
- */
-void fifo_init(FIFO_TypeDef * f, uint8_t * buf, uint16_t size)
-{
- f->head = 0;
- f->tail = 0;
- f->lock = 0;
- f->size = size;
- f->buf = buf;
-}
-
-/**
- * @brief fifo_read
- * Read from FIFO.
- * @param f: Fifo address
- * @param buf: read buffer
- * @param nbytes: number of item to read
- * @retval number of read items
- */
-uint16_t fifo_read(FIFO_TypeDef * f, void * buf, uint16_t nbytes)
-{
- uint16_t i;
- uint8_t * p;
- p = buf;
-
- if(f->lock == 0)
- {
- f->lock = 1;
- for(i=0; i < nbytes; i++)
- {
- if( f->tail != f->head )
- {
- *p++ = f->buf[f->tail];
- f->tail++;
- if( f->tail == f->size )
- {
- f->tail = 0;
- }
- } else
- {
- f->lock = 0;
- return i;
- }
- }
- }
- f->lock = 0;
- return nbytes;
-}
-
-/**
- * @brief fifo_write
- * Read from FIFO.
- * @param f: Fifo address
- * @param buf: read buffer
- * @param nbytes: number of item to write
- * @retval number of written items
- */
-uint16_t fifo_write(FIFO_TypeDef * f, const void * buf, uint16_t nbytes)
-{
- uint16_t i;
- const uint8_t * p;
- p = buf;
- if(f->lock == 0)
- {
- f->lock = 1;
- for(i=0; i < nbytes; i++)
- {
- if( (f->head + 1 == f->tail) ||
- ( (f->head + 1 == f->size) && (f->tail == 0)) )
- {
- f->lock = 0;
- return i;
- }
- else
- {
- f->buf[f->head] = *p++;
- f->head++;
- if( f->head == f->size )
- {
- f->head = 0;
- }
- }
- }
- }
- f->lock = 0;
- return nbytes;
-}
-
-
-/**
-* @brief The function is a callback about HID Data events
-* @param phost: Selected device
-* @retval None
-*/
-__weak void USBH_HID_EventCallback(USBH_HandleTypeDef *phost)
-{
-
-}
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-
-/**
-* @}
-*/
-
-
-/**
-* @}
-*/
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/stmhal/usbhost/Class/HID/Src/usbh_hid_keybd.c b/stmhal/usbhost/Class/HID/Src/usbh_hid_keybd.c deleted file mode 100644 index 79104767b..000000000 --- a/stmhal/usbhost/Class/HID/Src/usbh_hid_keybd.c +++ /dev/null @@ -1,418 +0,0 @@ -/**
- ******************************************************************************
- * @file usbh_hid_keybd.c
- * @author MCD Application Team
- * @version V3.0.0
- * @date 18-February-2014
- * @brief This file is the application layer for USB Host HID Keyboard handling
- * QWERTY and AZERTY Keyboard are supported as per the selection in
- * usbh_hid_keybd.h
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
- *
- * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.st.com/software_license_agreement_liberty_v2
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- */
-
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_hid_keybd.h"
-#include "usbh_hid_parser.h"
-
-/** @addtogroup USBH_LIB
-* @{
-*/
-
-/** @addtogroup USBH_CLASS
-* @{
-*/
-
-/** @addtogroup USBH_HID_CLASS
-* @{
-*/
-
-/** @defgroup USBH_HID_KEYBD
-* @brief This file includes HID Layer Handlers for USB Host HID class.
-* @{
-*/
-
-/** @defgroup USBH_HID_KEYBD_Private_TypesDefinitions
-* @{
-*/
-/**
-* @}
-*/
-
-
-/** @defgroup USBH_HID_KEYBD_Private_Defines
-* @{
-*/
-/**
-* @}
-*/
-#ifndef AZERTY_KEYBOARD
- #define QWERTY_KEYBOARD
-#endif
-#define KBD_LEFT_CTRL 0x01
-#define KBD_LEFT_SHIFT 0x02
-#define KBD_LEFT_ALT 0x04
-#define KBD_LEFT_GUI 0x08
-#define KBD_RIGHT_CTRL 0x10
-#define KBD_RIGHT_SHIFT 0x20
-#define KBD_RIGHT_ALT 0x40
-#define KBD_RIGHT_GUI 0x80
-#define KBR_MAX_NBR_PRESSED 6
-
-/** @defgroup USBH_HID_KEYBD_Private_Macros
-* @{
-*/
-/**
-* @}
-*/
-
-/** @defgroup USBH_HID_KEYBD_Private_FunctionPrototypes
-* @{
-*/
-static USBH_StatusTypeDef USBH_HID_KeybdDecode(USBH_HandleTypeDef *phost);
-/**
-* @}
-*/
-
-/** @defgroup USBH_HID_KEYBD_Private_Variables
-* @{
-*/
-
-HID_KEYBD_Info_TypeDef keybd_info;
-uint32_t keybd_report_data[2];
-
-static const HID_Report_ItemTypedef imp_0_lctrl={
- (uint8_t*)keybd_report_data+0, /*data*/
- 1, /*size*/
- 0, /*shift*/
- 0, /*count (only for array items)*/
- 0, /*signed?*/
- 0, /*min value read can return*/
- 1, /*max value read can return*/
- 0, /*min vale device can report*/
- 1, /*max value device can report*/
- 1 /*resolution*/
-};
-static const HID_Report_ItemTypedef imp_0_lshift={
- (uint8_t*)keybd_report_data+0, /*data*/
- 1, /*size*/
- 1, /*shift*/
- 0, /*count (only for array items)*/
- 0, /*signed?*/
- 0, /*min value read can return*/
- 1, /*max value read can return*/
- 0, /*min vale device can report*/
- 1, /*max value device can report*/
- 1 /*resolution*/
-};
-static const HID_Report_ItemTypedef imp_0_lalt={
- (uint8_t*)keybd_report_data+0, /*data*/
- 1, /*size*/
- 2, /*shift*/
- 0, /*count (only for array items)*/
- 0, /*signed?*/
- 0, /*min value read can return*/
- 1, /*max value read can return*/
- 0, /*min vale device can report*/
- 1, /*max value device can report*/
- 1 /*resolution*/
-};
-static const HID_Report_ItemTypedef imp_0_lgui={
- (uint8_t*)keybd_report_data+0, /*data*/
- 1, /*size*/
- 3, /*shift*/
- 0, /*count (only for array items)*/
- 0, /*signed?*/
- 0, /*min value read can return*/
- 1, /*max value read can return*/
- 0, /*min vale device can report*/
- 1, /*max value device can report*/
- 1 /*resolution*/
-};
-static const HID_Report_ItemTypedef imp_0_rctrl={
- (uint8_t*)keybd_report_data+0, /*data*/
- 1, /*size*/
- 4, /*shift*/
- 0, /*count (only for array items)*/
- 0, /*signed?*/
- 0, /*min value read can return*/
- 1, /*max value read can return*/
- 0, /*min vale device can report*/
- 1, /*max value device can report*/
- 1 /*resolution*/
-};
-static const HID_Report_ItemTypedef imp_0_rshift={
- (uint8_t*)keybd_report_data+0, /*data*/
- 1, /*size*/
- 5, /*shift*/
- 0, /*count (only for array items)*/
- 0, /*signed?*/
- 0, /*min value read can return*/
- 1, /*max value read can return*/
- 0, /*min vale device can report*/
- 1, /*max value device can report*/
- 1 /*resolution*/
-};
-static const HID_Report_ItemTypedef imp_0_ralt={
- (uint8_t*)keybd_report_data+0, /*data*/
- 1, /*size*/
- 6, /*shift*/
- 0, /*count (only for array items)*/
- 0, /*signed?*/
- 0, /*min value read can return*/
- 1, /*max value read can return*/
- 0, /*min vale device can report*/
- 1, /*max value device can report*/
- 1 /*resolution*/
-};
-static const HID_Report_ItemTypedef imp_0_rgui={
- (uint8_t*)keybd_report_data+0, /*data*/
- 1, /*size*/
- 7, /*shift*/
- 0, /*count (only for array items)*/
- 0, /*signed?*/
- 0, /*min value read can return*/
- 1, /*max value read can return*/
- 0, /*min vale device can report*/
- 1, /*max value device can report*/
- 1 /*resolution*/
-};
-
-static const HID_Report_ItemTypedef imp_0_key_array={
- (uint8_t*)keybd_report_data+2, /*data*/
- 8, /*size*/
- 0, /*shift*/
- 6, /*count (only for array items)*/
- 0, /*signed?*/
- 0, /*min value read can return*/
- 101, /*max value read can return*/
- 0, /*min vale device can report*/
- 101, /*max value device can report*/
- 1 /*resolution*/
-};
-
-#ifdef QWERTY_KEYBOARD
-static const int8_t HID_KEYBRD_Key[] = {
- '\0', '`', '1', '2', '3', '4', '5', '6',
- '7', '8', '9', '0', '-', '=', '\0', '\r',
- '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u',
- 'i', 'o', 'p', '[', ']', '\\',
- '\0', 'a', 's', 'd', 'f', 'g', 'h', 'j',
- 'k', 'l', ';', '\'', '\0', '\n',
- '\0', '\0', 'z', 'x', 'c', 'v', 'b', 'n',
- 'm', ',', '.', '/', '\0', '\0',
- '\0', '\0', '\0', ' ', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\r', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0',
- '\0', '\0', '7', '4', '1',
- '\0', '/', '8', '5', '2',
- '0', '*', '9', '6', '3',
- '.', '-', '+', '\0', '\n', '\0', '\0', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0'
-};
-
-static const int8_t HID_KEYBRD_ShiftKey[] = {
- '\0', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')',
- '_', '+', '\0', '\0', '\0', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U',
- 'I', 'O', 'P', '{', '}', '|', '\0', 'A', 'S', 'D', 'F', 'G',
- 'H', 'J', 'K', 'L', ':', '"', '\0', '\n', '\0', '\0', 'Z', 'X',
- 'C', 'V', 'B', 'N', 'M', '<', '>', '?', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
-};
-
-#else
-
-static const int8_t HID_KEYBRD_Key[] = {
- '\0', '`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
- '-', '=', '\0', '\r', '\t', 'a', 'z', 'e', 'r', 't', 'y', 'u',
- 'i', 'o', 'p', '[', ']', '\\', '\0', 'q', 's', 'd', 'f', 'g',
- 'h', 'j', 'k', 'l', 'm', '\0', '\0', '\n', '\0', '\0', 'w', 'x',
- 'c', 'v', 'b', 'n', ',', ';', ':', '!', '\0', '\0', '\0', '\0',
- '\0', ' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\r', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0', '\0', '7', '4', '1','\0', '/',
- '8', '5', '2', '0', '*', '9', '6', '3', '.', '-', '+', '\0',
- '\n', '\0', '\0', '\0', '\0', '\0', '\0','\0', '\0', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
-};
-
-static const int8_t HID_KEYBRD_ShiftKey[] = {
- '\0', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_',
- '+', '\0', '\0', '\0', 'A', 'Z', 'E', 'R', 'T', 'Y', 'U', 'I', 'O',
- 'P', '{', '}', '*', '\0', 'Q', 'S', 'D', 'F', 'G', 'H', 'J', 'K',
- 'L', 'M', '%', '\0', '\n', '\0', '\0', 'W', 'X', 'C', 'V', 'B', 'N',
- '?', '.', '/', '\0', '\0', '\0','\0', '\0', '\0', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
- '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
-};
-#endif
-
-static const uint8_t HID_KEYBRD_Codes[] = {
- 0, 0, 0, 0, 31, 50, 48, 33,
- 19, 34, 35, 36, 24, 37, 38, 39, /* 0x00 - 0x0F */
- 52, 51, 25, 26, 17, 20, 32, 21,
- 23, 49, 18, 47, 22, 46, 2, 3, /* 0x10 - 0x1F */
- 4, 5, 6, 7, 8, 9, 10, 11,
- 43, 110, 15, 16, 61, 12, 13, 27, /* 0x20 - 0x2F */
- 28, 29, 42, 40, 41, 1, 53, 54,
- 55, 30, 112, 113, 114, 115, 116, 117, /* 0x30 - 0x3F */
- 118, 119, 120, 121, 122, 123, 124, 125,
- 126, 75, 80, 85, 76, 81, 86, 89, /* 0x40 - 0x4F */
- 79, 84, 83, 90, 95, 100, 105, 106,
- 108, 93, 98, 103, 92, 97, 102, 91, /* 0x50 - 0x5F */
- 96, 101, 99, 104, 45, 129, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x6F */
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 - 0x7F */
- 0, 0, 0, 0, 0, 107, 0, 56,
- 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 - 0x8F */
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 - 0x9F */
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, /* 0xA0 - 0xAF */
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, /* 0xB0 - 0xBF */
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, /* 0xC0 - 0xCF */
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, /* 0xD0 - 0xDF */
- 58, 44, 60, 127, 64, 57, 62, 128 /* 0xE0 - 0xE7 */
-};
-
-/**
- * @brief USBH_HID_KeybdInit
- * The function init the HID keyboard.
- * @param phost: Host handle
- * @retval USBH Status
- */
-USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost)
-{
- uint32_t x;
- HID_HandleTypeDef *HID_Handle = phost->pActiveClass->pData;
-
- keybd_info.lctrl=keybd_info.lshift= 0;
- keybd_info.lalt=keybd_info.lgui= 0;
- keybd_info.rctrl=keybd_info.rshift= 0;
- keybd_info.ralt=keybd_info.rgui=0;
-
-
- for(x=0; x< (sizeof(keybd_report_data)/sizeof(uint32_t)); x++)
- {
- keybd_report_data[x]=0;
- }
-
- if(HID_Handle->length > (sizeof(keybd_report_data)/sizeof(uint32_t)))
- {
- HID_Handle->length = (sizeof(keybd_report_data)/sizeof(uint32_t));
- }
- HID_Handle->pData = (uint8_t*)keybd_report_data;
- fifo_init(&HID_Handle->fifo, phost->device.Data, HID_QUEUE_SIZE * sizeof(keybd_report_data));
-
- return USBH_OK;
-}
-
-/**
- * @brief USBH_HID_GetKeybdInfo
- * The function return keyboard information.
- * @param phost: Host handle
- * @retval keyboard information
- */
-HID_KEYBD_Info_TypeDef *USBH_HID_GetKeybdInfo(USBH_HandleTypeDef *phost)
-{
- if(USBH_HID_KeybdDecode(phost) == USBH_OK)
- {
- return &keybd_info;
- }
- else
- {
- return NULL;
- }
-}
-
-/**
- * @brief USBH_HID_KeybdDecode
- * The function decode keyboard data.
- * @param phost: Host handle
- * @retval USBH Status
- */
-static USBH_StatusTypeDef USBH_HID_KeybdDecode(USBH_HandleTypeDef *phost)
-{
- uint8_t x;
-
- HID_HandleTypeDef *HID_Handle = phost->pActiveClass->pData;
- if(HID_Handle->length == 0)
- {
- return USBH_FAIL;
- }
- /*Fill report */
- if(fifo_read(&HID_Handle->fifo, &keybd_report_data, HID_Handle->length) == HID_Handle->length)
- {
-
- keybd_info.lctrl=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lctrl, 0);
- keybd_info.lshift=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lshift, 0);
- keybd_info.lalt=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lalt, 0);
- keybd_info.lgui=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lgui, 0);
- keybd_info.rctrl=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rctrl, 0);
- keybd_info.rshift=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rshift, 0);
- keybd_info.ralt=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_ralt, 0);
- keybd_info.rgui=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rgui, 0);
-
- for(x=0; x < sizeof(keybd_info.keys); x++)
- {
- keybd_info.keys[x]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_key_array, x);
- }
-
- return USBH_OK;
- }
- return USBH_FAIL;
-}
-
-/**
- * @brief USBH_HID_GetASCIICode
- * The function decode keyboard data into ASCII characters.
- * @param phost: Host handle
- * @param info: Keyboard information
- * @retval ASCII code
- */
-uint8_t USBH_HID_GetASCIICode(HID_KEYBD_Info_TypeDef *info)
-{
- uint8_t output;
- if((info->lshift == 1) || (info->rshift))
- {
- output = HID_KEYBRD_ShiftKey[HID_KEYBRD_Codes[info->keys[0]]];
- }
- else
- {
- output = HID_KEYBRD_Key[HID_KEYBRD_Codes[info->keys[0]]];
- }
- return output;
-}
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
diff --git a/stmhal/usbhost/Class/HID/Src/usbh_hid_mouse.c b/stmhal/usbhost/Class/HID/Src/usbh_hid_mouse.c deleted file mode 100644 index 0851714af..000000000 --- a/stmhal/usbhost/Class/HID/Src/usbh_hid_mouse.c +++ /dev/null @@ -1,267 +0,0 @@ -/**
- ******************************************************************************
- * @file usbh_hid_mouse.c
- * @author MCD Application Team
- * @version V3.0.0
- * @date 18-February-2014
- * @brief This file is the application layer for USB Host HID Mouse Handling.
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
- *
- * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.st.com/software_license_agreement_liberty_v2
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- */
-
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_hid_mouse.h"
-#include "usbh_hid_parser.h"
-
-
-/** @addtogroup USBH_LIB
- * @{
- */
-
-/** @addtogroup USBH_CLASS
- * @{
- */
-
-/** @addtogroup USBH_HID_CLASS
- * @{
- */
-
-/** @defgroup USBH_HID_MOUSE
- * @brief This file includes HID Layer Handlers for USB Host HID class.
- * @{
- */
-
-/** @defgroup USBH_HID_MOUSE_Private_TypesDefinitions
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USBH_HID_MOUSE_Private_Defines
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USBH_HID_MOUSE_Private_Macros
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USBH_HID_MOUSE_Private_FunctionPrototypes
- * @{
- */
-static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost);
-
-/**
- * @}
- */
-
-
-/** @defgroup USBH_HID_MOUSE_Private_Variables
- * @{
- */
-HID_MOUSE_Info_TypeDef mouse_info;
-uint32_t mouse_report_data[1];
-
-/* Structures defining how to access items in a HID mouse report */
-/* Access button 1 state. */
-static const HID_Report_ItemTypedef prop_b1={
- (uint8_t *)mouse_report_data+0, /*data*/
- 1, /*size*/
- 0, /*shift*/
- 0, /*count (only for array items)*/
- 0, /*signed?*/
- 0, /*min value read can return*/
- 1, /*max value read can return*/
- 0, /*min value device can report*/
- 1, /*max value device can report*/
- 1 /*resolution*/
-};
-
-/* Access button 2 state. */
-static const HID_Report_ItemTypedef prop_b2={
- (uint8_t *)mouse_report_data+0, /*data*/
- 1, /*size*/
- 1, /*shift*/
- 0, /*count (only for array items)*/
- 0, /*signed?*/
- 0, /*min value read can return*/
- 1, /*max value read can return*/
- 0, /*min value device can report*/
- 1, /*max value device can report*/
- 1 /*resolution*/
-};
-
-/* Access button 3 state. */
-static const HID_Report_ItemTypedef prop_b3={
- (uint8_t *)mouse_report_data+0, /*data*/
- 1, /*size*/
- 2, /*shift*/
- 0, /*count (only for array items)*/
- 0, /*signed?*/
- 0, /*min value read can return*/
- 1, /*max value read can return*/
- 0, /*min vale device can report*/
- 1, /*max value device can report*/
- 1 /*resolution*/
-};
-
-/* Access x coordinate change. */
-static const HID_Report_ItemTypedef prop_x={
- (uint8_t *)mouse_report_data+1, /*data*/
- 8, /*size*/
- 0, /*shift*/
- 0, /*count (only for array items)*/
- 1, /*signed?*/
- 0, /*min value read can return*/
- 0xFFFF,/*max value read can return*/
- 0, /*min vale device can report*/
- 0xFFFF,/*max value device can report*/
- 1 /*resolution*/
-};
-
-/* Access y coordinate change. */
-static const HID_Report_ItemTypedef prop_y={
- (uint8_t *)mouse_report_data+2, /*data*/
- 8, /*size*/
- 0, /*shift*/
- 0, /*count (only for array items)*/
- 1, /*signed?*/
- 0, /*min value read can return*/
- 0xFFFF,/*max value read can return*/
- 0, /*min vale device can report*/
- 0xFFFF,/*max value device can report*/
- 1 /*resolution*/
-};
-
-
-/**
- * @}
- */
-
-
-/** @defgroup USBH_HID_MOUSE_Private_Functions
- * @{
- */
-
-/**
- * @brief USBH_HID_MouseInit
- * The function init the HID mouse.
- * @param phost: Host handle
- * @retval USBH Status
- */
-USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost)
-{
- HID_HandleTypeDef *HID_Handle = phost->pActiveClass->pData;
-
- mouse_info.x=0;
- mouse_info.y=0;
- mouse_info.buttons[0]=0;
- mouse_info.buttons[1]=0;
- mouse_info.buttons[2]=0;
-
- mouse_report_data[0]=0;
-
- if(HID_Handle->length > sizeof(mouse_report_data))
- {
- HID_Handle->length = sizeof(mouse_report_data);
- }
- HID_Handle->pData = (uint8_t *)mouse_report_data;
- fifo_init(&HID_Handle->fifo, phost->device.Data, HID_QUEUE_SIZE * sizeof(mouse_report_data));
-
- return USBH_OK;
-}
-
-/**
- * @brief USBH_HID_GetMouseInfo
- * The function return mouse information.
- * @param phost: Host handle
- * @retval mouse information
- */
-HID_MOUSE_Info_TypeDef *USBH_HID_GetMouseInfo(USBH_HandleTypeDef *phost)
-{
- if(USBH_HID_MouseDecode(phost)== USBH_OK)
- {
- return &mouse_info;
- }
- else
- {
- return NULL;
- }
-}
-
-/**
- * @brief USBH_HID_MouseDecode
- * The function decode mouse data.
- * @param phost: Host handle
- * @retval USBH Status
- */
-static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost)
-{
- HID_HandleTypeDef *HID_Handle = phost->pActiveClass->pData;
-
- if(HID_Handle->length == 0)
- {
- return USBH_FAIL;
- }
- /*Fill report */
- if(fifo_read(&HID_Handle->fifo, &mouse_report_data, HID_Handle->length) == HID_Handle->length)
- {
-
- /*Decode report */
- mouse_info.x = (int16_t )HID_ReadItem((HID_Report_ItemTypedef *) &prop_x, 0);
- mouse_info.y = (int16_t )HID_ReadItem((HID_Report_ItemTypedef *) &prop_y, 0);
-
- mouse_info.buttons[0]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b1, 0);
- mouse_info.buttons[1]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b2, 0);
- mouse_info.buttons[2]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b3, 0);
-
- return USBH_OK;
- }
- return USBH_FAIL;
-}
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-
-/**
- * @}
- */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/stmhal/usbhost/Class/HID/Src/usbh_hid_parser.c b/stmhal/usbhost/Class/HID/Src/usbh_hid_parser.c deleted file mode 100644 index a050f95e9..000000000 --- a/stmhal/usbhost/Class/HID/Src/usbh_hid_parser.c +++ /dev/null @@ -1,235 +0,0 @@ -/**
- ******************************************************************************
- * @file usbh_hid_parser.c
- * @author MCD Application Team
- * @version V3.0.0
- * @date 18-February-2014
- * @brief This file is the HID Layer Handlers for USB Host HID class.
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
- *
- * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.st.com/software_license_agreement_liberty_v2
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- */
-/* Includes ------------------------------------------------------------------*/
-#include "usbh_hid_parser.h"
-
-
-/** @addtogroup USBH_LIB
- * @{
- */
-
-/** @addtogroup USBH_CLASS
- * @{
- */
-
-/** @addtogroup USBH_HID_CLASS
- * @{
- */
-
-/** @defgroup USBH_HID_PARSER
- * @brief This file includes HID parsers for USB Host HID class.
- * @{
- */
-
-/** @defgroup USBH_HID_PARSER_Private_TypesDefinitions
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USBH_HID_PARSER_Private_Defines
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USBH_HID_PARSER_Private_Macros
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USBH_HID_PARSER_Private_FunctionPrototypes
- * @{
- */
-
-/**
- * @}
- */
-
-
-/** @defgroup USBH_HID_PARSER_Private_Variables
- * @{
- */
-
-/**
- * @}
- */
-
-
-/** @defgroup USBH_HID_PARSER_Private_Functions
- * @{
- */
-
-/**
- * @brief HID_ReadItem
- * The function read a report item.
- * @param ri: report item
- * @param ndx: report index
-* @retval status (0 : fail / otherwise: item value)
- */
-uint32_t HID_ReadItem(HID_Report_ItemTypedef *ri, uint8_t ndx)
-{
- uint32_t val=0;
- uint32_t x=0;
- uint32_t bofs;
- uint8_t *data=ri->data;
- uint8_t shift=ri->shift;
-
- /* get the logical value of the item */
-
- /* if this is an array, wee may need to offset ri->data.*/
- if (ri->count > 0)
- {
- /* If app tries to read outside of the array. */
- if (ri->count <= ndx)
- {
- return(0);
- }
-
- /* calculate bit offset */
- bofs = ndx*ri->size;
- bofs += shift;
- /* calculate byte offset + shift pair from bit offset. */
- data+=bofs/8;
- shift=(uint8_t)(bofs%8);
- }
- /* read data bytes in little endian order */
- for(x=0; x < ((ri->size & 0x7) ? (ri->size/8)+1 : (ri->size/8)); x++)
- {
- val=(uint32_t)(*data << (x*8));
- }
- val=(val >> shift) & ((1<<ri->size)-1);
-
- if (val < ri->logical_min || val > ri->logical_max)
- {
- return(0);
- }
-
- /* convert logical value to physical value */
- /* See if the number is negative or not. */
- if ((ri->sign) && (val & (1<<(ri->size-1))))
- {
- /* yes, so sign extend value to 32 bits. */
- int vs=(int)((-1 & ~((1<<(ri->size))-1)) | val);
-
- if(ri->resolution == 1)
- {
- return((uint32_t)vs);
- }
- return((uint32_t)(vs*ri->resolution));
- }
- else
- {
- if(ri->resolution == 1)
- {
- return(val);
- }
- return(val*ri->resolution);
- }
-}
-
-/**
- * @brief HID_WriteItem
- * The function write a report item.
- * @param ri: report item
- * @param ndx: report index
- * @retval status (1: fail/ 0 : Ok)
- */
-uint32_t HID_WriteItem(HID_Report_ItemTypedef *ri, uint32_t value, uint8_t ndx)
-{
- uint32_t x;
- uint32_t mask;
- uint32_t bofs;
- uint8_t *data=ri->data;
- uint8_t shift=ri->shift;
-
- if (value < ri->physical_min || value > ri->physical_max)
- {
- return(1);
- }
-
- /* if this is an array, wee may need to offset ri->data.*/
- if (ri->count > 0)
- {
- /* If app tries to read outside of the array. */
- if (ri->count >= ndx)
- {
- return(0);
- }
- /* calculate bit offset */
- bofs = ndx*ri->size;
- bofs += shift;
- /* calculate byte offset + shift pair from bit offset. */
- data+=bofs/8;
- shift=(uint8_t)(bofs%8);
-
- }
-
- /* Convert physical value to logical value. */
- if (ri->resolution != 1)
- {
- value=value/ri->resolution;
- }
-
- /* Write logical value to report in little endian order. */
- mask=(uint32_t)((1<<ri->size)-1);
- value = (value & mask) << shift;
-
- for(x=0; x < ((ri->size & 0x7) ? (ri->size/8)+1 : (ri->size/8)); x++)
- {
- *(ri->data+x)=(uint8_t)((*(ri->data+x) & ~(mask>>(x*8))) | ((value>>(x*8)) & (mask>>(x*8))));
- }
- return(0);
-}
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-
-/**
- * @}
- */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
