mirror of
https://github.com/ArteryTek/AT32F415_Firmware_Library.git
synced 2026-05-21 09:22:11 +00:00
upload version v2.0.0
This commit is contained in:
451
middlewares/usbh_class/usbh_hid/usbh_hid_class.c
Normal file
451
middlewares/usbh_class/usbh_hid/usbh_hid_class.c
Normal file
@@ -0,0 +1,451 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_class.c
|
||||
* @version v2.0.0
|
||||
* @date 2021-11-26
|
||||
* @brief usb host hid class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
#include "usbh_hid_class.h"
|
||||
#include "usb_conf.h"
|
||||
#include "usbh_core.h"
|
||||
#include "usbh_ctrl.h"
|
||||
#include "usbh_hid_mouse.h"
|
||||
#include "usbh_hid_keyboard.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbh_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_hid_class
|
||||
* @brief usb host class hid demo
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_hid_class_private_functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
usb_sts_type uhost_init_handler(void *uhost);
|
||||
usb_sts_type uhost_reset_handler(void *uhost);
|
||||
usb_sts_type uhost_request_handler(void *uhost);
|
||||
usb_sts_type uhost_process_handler(void *uhost);
|
||||
|
||||
usbh_hid_type usbh_hid;
|
||||
usbh_class_handler_type uhost_class_handler =
|
||||
{
|
||||
uhost_init_handler,
|
||||
uhost_reset_handler,
|
||||
uhost_request_handler,
|
||||
uhost_process_handler,
|
||||
&usbh_hid
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief usb host class init handler
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type uhost_init_handler(void *uhost)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usb_sts_type status = USB_OK;
|
||||
uint8_t hidx, eptidx = 0;
|
||||
usbh_hid_type *phid = &usbh_hid;
|
||||
|
||||
puhost->class_handler->pdata = &usbh_hid;
|
||||
|
||||
/* get hid interface */
|
||||
hidx = usbh_find_interface(puhost, USB_CLASS_CODE_HID, 0x01, 0xFF);
|
||||
if(hidx == 0xFF)
|
||||
{
|
||||
USBH_DEBUG("Unsupport Device!");
|
||||
return USB_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
/* get hid protocol */
|
||||
phid->protocol = puhost->dev.cfg_desc.interface[hidx].interface.bInterfaceProtocol;
|
||||
|
||||
if(phid->protocol == USB_HID_MOUSE_PROTOCOL_CODE)
|
||||
{
|
||||
USBH_DEBUG("Mouse Device!");
|
||||
}
|
||||
else if(phid->protocol == USB_HID_KEYBOARD_PROTOCOL_CODE)
|
||||
{
|
||||
USBH_DEBUG("Keyboard Device!");
|
||||
}
|
||||
|
||||
for(eptidx = 0; eptidx < puhost->dev.cfg_desc.interface[hidx].interface.bNumEndpoints; eptidx ++)
|
||||
{
|
||||
if(puhost->dev.cfg_desc.interface[hidx].endpoint[eptidx].bEndpointAddress & 0x80)
|
||||
{
|
||||
/* find interface out endpoint information */
|
||||
phid->eptin = puhost->dev.cfg_desc.interface[hidx].endpoint[eptidx].bEndpointAddress;
|
||||
phid->in_maxpacket = puhost->dev.cfg_desc.interface[hidx].endpoint[eptidx].wMaxPacketSize;
|
||||
phid->in_poll = puhost->dev.cfg_desc.interface[hidx].endpoint[eptidx].bInterval;
|
||||
|
||||
phid->chin = usbh_alloc_channel(puhost, phid->eptin);
|
||||
/* enable channel */
|
||||
usbh_hc_open(puhost, phid->chin,phid->eptin,
|
||||
puhost->dev.address, EPT_INT_TYPE,
|
||||
phid->in_maxpacket,
|
||||
puhost->dev.speed);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* get interface out endpoint information */
|
||||
phid->eptout = puhost->dev.cfg_desc.interface[hidx].endpoint[eptidx].bEndpointAddress;
|
||||
phid->out_maxpacket = puhost->dev.cfg_desc.interface[hidx].endpoint[eptidx].wMaxPacketSize;
|
||||
phid->out_poll = puhost->dev.cfg_desc.interface[hidx].endpoint[eptidx].bInterval;
|
||||
|
||||
phid->chout = usbh_alloc_channel(puhost, usbh_hid.eptout);
|
||||
/* enable channel */
|
||||
usbh_hc_open(puhost, phid->chout, phid->eptout,
|
||||
puhost->dev.address, EPT_INT_TYPE,
|
||||
phid->out_maxpacket,
|
||||
puhost->dev.speed);
|
||||
}
|
||||
}
|
||||
phid->ctrl_state = USB_HID_STATE_IDLE;
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host class reset handler
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type uhost_reset_handler(void *uhost)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_hid_type *phid = (usbh_hid_type *)puhost->class_handler->pdata;
|
||||
usb_sts_type status = USB_OK;
|
||||
if(puhost->class_handler->pdata == NULL)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
if(phid->chin != 0)
|
||||
{
|
||||
/* free in channel */
|
||||
usbh_free_channel(puhost, phid->chin);
|
||||
usbh_ch_disable(puhost, phid->chin);
|
||||
phid->chin = 0;
|
||||
}
|
||||
|
||||
if(phid->chout != 0)
|
||||
{
|
||||
/* free out channel */
|
||||
usbh_free_channel(puhost, phid->chout);
|
||||
usbh_ch_disable(puhost, phid->chout);
|
||||
phid->chout = 0;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host hid class get descriptor
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @param length: descriptor length
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type usbh_hid_get_desc(void *uhost, uint16_t length)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_hid_type *phid = (usbh_hid_type *)puhost->class_handler->pdata;
|
||||
usb_sts_type status = USB_WAIT;
|
||||
uint8_t bm_req;
|
||||
uint16_t wvalue;
|
||||
if(puhost->ctrl.state == CONTROL_IDLE)
|
||||
{
|
||||
bm_req = USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD;
|
||||
wvalue = (0x21 << 8) & 0xFF00;
|
||||
|
||||
usbh_get_descriptor(puhost, length, bm_req,
|
||||
wvalue, puhost->rx_buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(usbh_ctrl_result_check(puhost, CONTROL_IDLE, ENUM_IDLE) == USB_OK)
|
||||
{
|
||||
phid->hid_desc.bLength = puhost->rx_buffer[0];
|
||||
phid->hid_desc.bDescriptorType = puhost->rx_buffer[1];
|
||||
phid->hid_desc.bcdHID = SWAPBYTE(puhost->rx_buffer+2);
|
||||
phid->hid_desc.bCountryCode = puhost->rx_buffer[4];
|
||||
phid->hid_desc.bNumDescriptors = puhost->rx_buffer[5];
|
||||
phid->hid_desc.bReportDescriptorType = puhost->rx_buffer[6];
|
||||
phid->hid_desc.wItemLength = SWAPBYTE(puhost->rx_buffer+7);
|
||||
status = USB_OK;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief usb host hid class get report
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @param length: reprot length
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type usbh_hid_get_report(void *uhost, uint16_t length)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usb_sts_type status = USB_WAIT;
|
||||
uint8_t bm_req;
|
||||
uint16_t wvalue;
|
||||
if(puhost->ctrl.state == CONTROL_IDLE)
|
||||
{
|
||||
bm_req = USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD;
|
||||
wvalue = (0x22 << 8) & 0xFF00;
|
||||
|
||||
usbh_get_descriptor(puhost, length, bm_req,
|
||||
wvalue, puhost->rx_buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(usbh_ctrl_result_check(puhost, CONTROL_IDLE, ENUM_IDLE) == USB_OK)
|
||||
{
|
||||
status = USB_OK;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host hid class set idle
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @param id: id
|
||||
* @param dr: dr
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type usbh_hid_set_idle(void *uhost, uint8_t id, uint8_t dr)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usb_sts_type status = USB_WAIT;
|
||||
if(puhost->ctrl.state == CONTROL_IDLE)
|
||||
{
|
||||
puhost->ctrl.setup.bmRequestType = USB_DIR_H2D | USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_CLASS;
|
||||
puhost->ctrl.setup.bRequest = USB_HID_SET_IDLE;
|
||||
puhost->ctrl.setup.wValue = (dr << 8) | id;
|
||||
puhost->ctrl.setup.wIndex = 0;
|
||||
puhost->ctrl.setup.wLength = 0;
|
||||
usbh_ctrl_request(puhost, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = usbh_ctrl_result_check(puhost, CONTROL_IDLE, ENUM_IDLE);
|
||||
if(status == USB_OK || status == USB_NOT_SUPPORT)
|
||||
{
|
||||
status = USB_OK;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host hid class set protocol
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @param protocol: portocol number
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type usbh_hid_set_protocol(void *uhost, uint8_t protocol)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usb_sts_type status = USB_WAIT;
|
||||
if(puhost->ctrl.state == CONTROL_IDLE)
|
||||
{
|
||||
puhost->ctrl.setup.bmRequestType = USB_DIR_H2D | USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_CLASS;
|
||||
puhost->ctrl.setup.bRequest = USB_HID_SET_PROTOCOL;
|
||||
puhost->ctrl.setup.wValue = protocol;
|
||||
puhost->ctrl.setup.wIndex = 0;
|
||||
puhost->ctrl.setup.wLength = 0;
|
||||
usbh_ctrl_request(puhost, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = usbh_ctrl_result_check(puhost, CONTROL_IDLE, ENUM_IDLE);
|
||||
if(status == USB_OK || status == USB_NOT_SUPPORT)
|
||||
{
|
||||
status = USB_OK;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host clear feature
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @param hc_num: channel number
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type usbh_clear_endpoint_feature(usbh_core_type *uhost, uint8_t ept_num, uint8_t hc_num)
|
||||
{
|
||||
usb_sts_type status = USB_WAIT;
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
uint8_t bm_req;
|
||||
bm_req = USB_REQ_RECIPIENT_ENDPOINT | USB_REQ_TYPE_STANDARD;
|
||||
if(puhost->ctrl.state == CONTROL_IDLE)
|
||||
{
|
||||
puhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req;
|
||||
puhost->ctrl.setup.bRequest = USB_STD_REQ_CLEAR_FEATURE;
|
||||
puhost->ctrl.setup.wValue = 0x00;
|
||||
puhost->ctrl.setup.wLength = 0;
|
||||
puhost->ctrl.setup.wIndex = ept_num;
|
||||
if((ept_num & 0x80) == USB_DIR_D2H)
|
||||
{
|
||||
puhost->hch[hc_num].toggle_in = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
puhost->hch[hc_num].toggle_out = 0;
|
||||
}
|
||||
status = usbh_ctrl_request(puhost, 0, 0);
|
||||
}
|
||||
if(usbh_ctrl_result_check(puhost, CONTROL_IDLE, ENUM_IDLE) == USB_OK)
|
||||
{
|
||||
status = USB_OK;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host hid class request handler
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type uhost_request_handler(void *uhost)
|
||||
{
|
||||
usb_sts_type status = USB_WAIT;
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_hid_type *phid = (usbh_hid_type *)puhost->class_handler->pdata;
|
||||
|
||||
switch(phid->ctrl_state)
|
||||
{
|
||||
case USB_HID_STATE_IDLE:
|
||||
phid->ctrl_state = USB_HID_STATE_GET_DESC;
|
||||
break;
|
||||
case USB_HID_STATE_GET_DESC:
|
||||
if(usbh_hid_get_desc(puhost, 9) == USB_OK)
|
||||
{
|
||||
phid->ctrl_state = USB_HID_STATE_GET_REPORT;
|
||||
}
|
||||
break;
|
||||
case USB_HID_STATE_GET_REPORT:
|
||||
if(usbh_hid_get_report(puhost, phid->hid_desc.wItemLength) == USB_OK)
|
||||
{
|
||||
phid->ctrl_state = USB_HID_STATE_SET_IDLE;
|
||||
}
|
||||
break;
|
||||
case USB_HID_STATE_SET_IDLE:
|
||||
if(usbh_hid_set_idle(puhost, 0, 0) == USB_OK)
|
||||
{
|
||||
phid->ctrl_state = USB_HID_STATE_SET_PROTOCOL;
|
||||
}
|
||||
break;
|
||||
case USB_HID_STATE_SET_PROTOCOL:
|
||||
if(usbh_hid_set_protocol(puhost, 0) == USB_OK)
|
||||
{
|
||||
phid->ctrl_state = USB_HID_STATE_COMPLETE;
|
||||
}
|
||||
break;
|
||||
case USB_HID_STATE_COMPLETE:
|
||||
phid->state = USB_HID_INIT;
|
||||
status = USB_OK;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host hid class process handler
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type uhost_process_handler(void *uhost)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_hid_type *phid = (usbh_hid_type *)puhost->class_handler->pdata;
|
||||
urb_sts_type urb_status;
|
||||
switch(phid->state)
|
||||
{
|
||||
case USB_HID_INIT:
|
||||
phid->state = USB_HID_GET;
|
||||
break;
|
||||
|
||||
case USB_HID_GET:
|
||||
usbh_interrupt_recv(puhost, phid->chin, phid->buffer, phid->in_maxpacket);
|
||||
phid->state = USB_HID_POLL;
|
||||
phid->poll_timer = usbh_get_frame(puhost->usb_reg);
|
||||
break;
|
||||
|
||||
case USB_HID_POLL:
|
||||
if((usbh_get_frame(puhost->usb_reg) - phid->poll_timer) >= phid->in_poll )
|
||||
{
|
||||
phid->state = USB_HID_GET;
|
||||
}
|
||||
else
|
||||
{
|
||||
urb_status = usbh_get_urb_status(puhost, phid->chin);
|
||||
if(urb_status == URB_DONE)
|
||||
{
|
||||
puhost->urb_state[phid->chin] = URB_IDLE;
|
||||
if(phid->protocol == USB_HID_MOUSE_PROTOCOL_CODE)
|
||||
{
|
||||
usbh_hid_mouse_decode(phid->buffer);
|
||||
}
|
||||
else if(phid->protocol == USB_HID_KEYBOARD_PROTOCOL_CODE)
|
||||
{
|
||||
usbh_hid_keyboard_decode(phid->buffer);
|
||||
}
|
||||
|
||||
}
|
||||
else if(urb_status == URB_STALL)
|
||||
{
|
||||
if(usbh_clear_endpoint_feature(puhost, phid->eptin, phid->chin) == USB_OK)
|
||||
{
|
||||
phid->state = USB_HID_GET;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return USB_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
148
middlewares/usbh_class/usbh_hid/usbh_hid_class.h
Normal file
148
middlewares/usbh_class/usbh_hid/usbh_hid_class.h
Normal file
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_class.h
|
||||
* @version v2.0.0
|
||||
* @date 2021-11-26
|
||||
* @brief usb host hid class header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBH_HID_CLASS_H
|
||||
#define __USBH_HID_CLASS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "usbh_core.h"
|
||||
#include "usb_conf.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbh_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_hid_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_hid_class_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief usb hid protocol code
|
||||
*/
|
||||
#define USB_HID_NONE_PROTOCOL_CODE 0x00
|
||||
#define USB_HID_KEYBOARD_PROTOCOL_CODE 0x01
|
||||
#define USB_HID_MOUSE_PROTOCOL_CODE 0x02
|
||||
|
||||
/**
|
||||
* @brief usb hid request code
|
||||
*/
|
||||
#define USB_HID_GET_REPORT 0x01
|
||||
#define USB_HID_GET_IDLE 0x02
|
||||
#define USB_HID_GET_PROTOCOL 0x03
|
||||
#define USB_HID_SET_REPORT 0x09
|
||||
#define USB_HID_SET_IDLE 0x0A
|
||||
#define USB_HID_SET_PROTOCOL 0x0B
|
||||
|
||||
/**
|
||||
* @brief usb hid request state
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
USB_HID_STATE_IDLE,
|
||||
USB_HID_STATE_GET_DESC,
|
||||
USB_HID_STATE_GET_REPORT,
|
||||
USB_HID_STATE_SET_IDLE,
|
||||
USB_HID_STATE_SET_PROTOCOL,
|
||||
USB_HID_STATE_COMPLETE,
|
||||
}usb_hid_ctrl_state_type;
|
||||
|
||||
/**
|
||||
* @brief usb hid process state
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
USB_HID_INIT,
|
||||
USB_HID_GET,
|
||||
USB_HID_SEND,
|
||||
USB_HID_POLL,
|
||||
USB_HID_BUSY,
|
||||
USB_HID_ERROR,
|
||||
}usb_hid_state_type;
|
||||
|
||||
/**
|
||||
* @brief usb hid descriptor type
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t bcdHID;
|
||||
uint8_t bCountryCode;
|
||||
uint8_t bNumDescriptors;
|
||||
uint8_t bReportDescriptorType;
|
||||
uint16_t wItemLength;
|
||||
}usb_hid_desc_type;
|
||||
|
||||
/**
|
||||
* @brief usb hid struct
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t chin;
|
||||
uint8_t eptin;
|
||||
uint16_t in_maxpacket;
|
||||
uint8_t in_poll;
|
||||
|
||||
uint8_t chout;
|
||||
uint8_t eptout;
|
||||
uint16_t out_maxpacket;
|
||||
uint8_t out_poll;
|
||||
uint8_t protocol;
|
||||
|
||||
|
||||
usb_hid_desc_type hid_desc;
|
||||
usb_hid_ctrl_state_type ctrl_state;
|
||||
usb_hid_state_type state;
|
||||
uint16_t poll_timer;
|
||||
uint8_t buffer[64];
|
||||
}usbh_hid_type;
|
||||
|
||||
extern usbh_class_handler_type uhost_class_handler;
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
255
middlewares/usbh_class/usbh_hid/usbh_hid_keyboard.c
Normal file
255
middlewares/usbh_class/usbh_hid/usbh_hid_keyboard.c
Normal file
@@ -0,0 +1,255 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_keyboard.c
|
||||
* @version v2.0.0
|
||||
* @date 2021-11-26
|
||||
* @brief usb host hid keyboard type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
#include "usbh_hid_keyboard.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbh_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_hid_class_keyboard
|
||||
* @brief usb host class hid keyboard
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_hid_class_keyboard_private_functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
static const uint8_t hid_keyboard_codes[] =
|
||||
{
|
||||
0, 0, 0, 0, 31, 50, 48, 33,
|
||||
19, 34, 35, 36, 24, 37, 38, 39,
|
||||
52, 51, 25, 26, 17, 20, 32, 21,
|
||||
23, 49, 18, 47, 22, 46, 2, 3,
|
||||
4, 5, 6, 7, 8, 9, 10, 11,
|
||||
43, 110, 15, 16, 61, 12, 13, 27,
|
||||
28, 29, 42, 40, 41, 1, 53, 54,
|
||||
55, 30, 112, 113, 114, 115, 116, 117,
|
||||
118, 119, 120, 121, 122, 123, 124, 125,
|
||||
126, 75, 80, 85, 76, 81, 86, 89,
|
||||
79, 84, 83, 90, 95, 100, 105, 106,
|
||||
108, 93, 98, 103, 92, 97, 102, 91,
|
||||
96, 101, 99, 104, 45, 129, 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, 107, 0, 56,
|
||||
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, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
58, 44, 60, 127, 64, 57, 62, 128,
|
||||
};
|
||||
|
||||
#ifdef QWERTY_KEYBOARD
|
||||
|
||||
static const int8_t hid_keyboard_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_keyboard_key_shift[] = {
|
||||
'\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_keyboard_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_keyboard_key_shift[] = {
|
||||
'\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
|
||||
|
||||
/**
|
||||
* @brief usb host hid keyboard decode
|
||||
* @param data: keyboard data
|
||||
* @retval none
|
||||
*/
|
||||
void usbh_hid_keyboard_decode(uint8_t *data)
|
||||
{
|
||||
static uint8_t shift;
|
||||
static uint8_t keys[KEYBOARD_MAX_NB_PRESSED];
|
||||
static uint8_t keys_n[KEYBOARD_MAX_NB_PRESSED];
|
||||
static uint8_t keys_l[KEYBOARD_MAX_NB_PRESSED];
|
||||
static uint8_t key_newest;
|
||||
static uint8_t nb_keys;
|
||||
static uint8_t nb_keys_n;
|
||||
static uint8_t nb_keys_l;
|
||||
|
||||
uint8_t idx;
|
||||
uint8_t idy;
|
||||
uint8_t err;
|
||||
uint8_t out;
|
||||
|
||||
nb_keys = 0;
|
||||
nb_keys_n = 0;
|
||||
nb_keys_l = 0;
|
||||
key_newest = 0;
|
||||
|
||||
if(data[0] == KEYBOARD_LEFT_SHIFT || data[0] == KEYBOARD_RIGHT_SHIFT)
|
||||
{
|
||||
shift = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
shift = FALSE;
|
||||
}
|
||||
err = FALSE;
|
||||
|
||||
for(idx = 2; idx < 2 + KEYBOARD_MAX_NB_PRESSED; idx ++)
|
||||
{
|
||||
if((data[idx] == 0x01) ||
|
||||
(data[idx] == 0x02) ||
|
||||
(data[idx] == 0x03))
|
||||
{
|
||||
err = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if(err == TRUE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
nb_keys = 0;
|
||||
nb_keys_n = 0;
|
||||
for(idx = 2; idx < 2 + KEYBOARD_MAX_NB_PRESSED; idx ++)
|
||||
{
|
||||
if(data[idx] != 0)
|
||||
{
|
||||
keys[nb_keys] = data[idx];
|
||||
nb_keys ++;
|
||||
for(idy = 0; idy < nb_keys_l; idy ++)
|
||||
{
|
||||
if(data[idx] == keys_l[idy])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(idy == nb_keys_l)
|
||||
{
|
||||
keys_n[nb_keys_n] = data[idx];
|
||||
nb_keys_n ++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(nb_keys_n == 1)
|
||||
{
|
||||
key_newest = keys_n[0];
|
||||
|
||||
if(shift == TRUE)
|
||||
{
|
||||
out = hid_keyboard_key_shift[hid_keyboard_codes[key_newest]];
|
||||
}
|
||||
else
|
||||
{
|
||||
out = hid_keyboard_key[hid_keyboard_codes[key_newest]];
|
||||
}
|
||||
/* callback user handler */
|
||||
USBH_DEBUG("%c", out);
|
||||
}
|
||||
else
|
||||
{
|
||||
key_newest = 0;
|
||||
}
|
||||
|
||||
nb_keys_l = nb_keys;
|
||||
for(idx = 0; idx < KEYBOARD_MAX_NB_PRESSED; idx ++)
|
||||
{
|
||||
keys_l[idx] = keys[idx];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
84
middlewares/usbh_class/usbh_hid/usbh_hid_keyboard.h
Normal file
84
middlewares/usbh_class/usbh_hid/usbh_hid_keyboard.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_keyboard.h
|
||||
* @version v2.0.0
|
||||
* @date 2021-11-26
|
||||
* @brief usb host hid keyboard header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBH_HID_KEYBOARD_H
|
||||
#define __USBH_HID_KEYBOARD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "usb_conf.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbh_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_hid_class_keyboard
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_hid_class_keyboard_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief usb keyboard option code
|
||||
*/
|
||||
#define KEYBOARD_LEFT_CTRL 0x01
|
||||
#define KEYBOARD_LEFT_SHIFT 0x02
|
||||
#define KEYBOARD_LEFT_ALT 0x04
|
||||
#define KEYBOARD_LEFT_GUI 0x08
|
||||
#define KEYBOARD_RIGHT_CTRL 0x10
|
||||
#define KEYBOARD_RIGHT_SHIFT 0x20
|
||||
#define KEYBOARD_RIGHT_ALT 0x40
|
||||
#define KEYBOARD_RIGHT_GUI 0x80
|
||||
|
||||
#define KEYBOARD_MAX_NB_PRESSED 6
|
||||
|
||||
#ifndef AZERTY_KEYBOARD
|
||||
#define QWERTY_KEYBOARD
|
||||
#endif
|
||||
|
||||
void usbh_hid_keyboard_decode(uint8_t *data);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
188
middlewares/usbh_class/usbh_hid/usbh_hid_mouse.c
Normal file
188
middlewares/usbh_class/usbh_hid/usbh_hid_mouse.c
Normal file
@@ -0,0 +1,188 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_mouse.c
|
||||
* @version v2.0.0
|
||||
* @date 2021-11-26
|
||||
* @brief usb host hid mouse type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
#include "usbh_hid_mouse.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbh_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_hid_class_mouse
|
||||
* @brief usb host class hid mouse
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_hid_class_mouse_private_functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
usb_hid_mouse_type hid_mouse;
|
||||
uint16_t x_pos = 0, y_pos = 0;
|
||||
|
||||
/**
|
||||
* @brief usb host hid position
|
||||
* @param x: x position
|
||||
* @param y: y position
|
||||
* @retval none
|
||||
*/
|
||||
void usbh_hid_mouse_position(uint8_t x, uint8_t y)
|
||||
{
|
||||
if((x != 0) || (y != 0))
|
||||
{
|
||||
x_pos += x / 2;
|
||||
y_pos += y / 2;
|
||||
|
||||
if(x_pos > MOUSE_WINDOW_WIDTH - 12)
|
||||
{
|
||||
x_pos = MOUSE_WINDOW_WIDTH - 12;
|
||||
}
|
||||
if(y_pos > MOUSE_WINDOW_HEIGHT - 12)
|
||||
{
|
||||
y_pos = MOUSE_WINDOW_HEIGHT - 12;
|
||||
}
|
||||
|
||||
if(x_pos < 2)
|
||||
{
|
||||
x_pos = 2;
|
||||
}
|
||||
if(y_pos < 2)
|
||||
{
|
||||
y_pos = 2;
|
||||
}
|
||||
USBH_DEBUG("Moving Mouse");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host hid button press
|
||||
* @param button: button id
|
||||
* @retval none
|
||||
*/
|
||||
void usbh_hid_mouse_button_press(uint8_t button)
|
||||
{
|
||||
switch(button)
|
||||
{
|
||||
case MOUSE_BUTTON_LEFT:
|
||||
/* left button */
|
||||
USBH_DEBUG("Left Button Pressed ");
|
||||
break;
|
||||
case MOUSE_BUTTON_RIGHT:
|
||||
USBH_DEBUG("Right Button Pressed ");
|
||||
/* left button */
|
||||
break;
|
||||
case MOUSE_BUTTON_MIDDLE:
|
||||
USBH_DEBUG("Middle Button Pressed ");
|
||||
/* middle button */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host hid button release
|
||||
* @param button: button id
|
||||
* @retval none
|
||||
*/
|
||||
void usbh_hid_mouse_button_release(uint8_t button)
|
||||
{
|
||||
switch(button)
|
||||
{
|
||||
case MOUSE_BUTTON_LEFT:
|
||||
/* left button */
|
||||
USBH_DEBUG("Left Button Released ");
|
||||
break;
|
||||
case MOUSE_BUTTON_RIGHT:
|
||||
/* left button */
|
||||
USBH_DEBUG("Right Button Released ");
|
||||
break;
|
||||
case MOUSE_BUTTON_MIDDLE:
|
||||
/* middle button */
|
||||
USBH_DEBUG("Middle Button Released ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host hid mouse process
|
||||
* @param mouse: mouse data type
|
||||
* @retval none
|
||||
*/
|
||||
void usbh_hid_mouse_process(usb_hid_mouse_type *mouse)
|
||||
{
|
||||
uint8_t idx = 1;
|
||||
static uint8_t b_state[3] = {0};
|
||||
if((mouse->x != 0) && (mouse->y != 0))
|
||||
{
|
||||
usbh_hid_mouse_position(mouse->x, mouse->y);
|
||||
}
|
||||
|
||||
for(idx = 0; idx < 3; idx ++)
|
||||
{
|
||||
if(mouse->button & 1 << idx)
|
||||
{
|
||||
if(b_state[idx] == 0)
|
||||
{
|
||||
usbh_hid_mouse_button_press(idx);
|
||||
b_state[idx] = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(b_state[idx] == 1)
|
||||
{
|
||||
usbh_hid_mouse_button_release(idx);
|
||||
b_state[idx] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host hid mouse decode
|
||||
* @param mouse_data: mouse data
|
||||
* @retval none
|
||||
*/
|
||||
void usbh_hid_mouse_decode(uint8_t *mouse_data)
|
||||
{
|
||||
hid_mouse.button = mouse_data[0];
|
||||
hid_mouse.x = mouse_data[1];
|
||||
hid_mouse.y = mouse_data[2];
|
||||
hid_mouse.z = mouse_data[3];
|
||||
|
||||
usbh_hid_mouse_process(&hid_mouse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
93
middlewares/usbh_class/usbh_hid/usbh_hid_mouse.h
Normal file
93
middlewares/usbh_class/usbh_hid/usbh_hid_mouse.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_mouse.h
|
||||
* @version v2.0.0
|
||||
* @date 2021-11-26
|
||||
* @brief usb host hid mouse header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBH_HID_MOUSE_H
|
||||
#define __USBH_HID_MOUSE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "usb_conf.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbh_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_hid_class_mouse
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_hid_class_mouse_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief usb hid mouse x y
|
||||
*/
|
||||
#define MOUSE_WINDOW_X 100
|
||||
#define MOUSE_WINDOW_Y 220
|
||||
#define MOUSE_WINDOW_HEIGHT 90
|
||||
#define MOUSE_WINDOW_WIDTH 128
|
||||
|
||||
/**
|
||||
* @brief usb hid mouse button
|
||||
*/
|
||||
#define MOUSE_BUTTON_LEFT 0x00
|
||||
#define MOUSE_BUTTON_RIGHT 0x01
|
||||
#define MOUSE_BUTTON_MIDDLE 0x02
|
||||
|
||||
/**
|
||||
* @brief usb hid mouse type
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t button;
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
uint8_t z;
|
||||
}usb_hid_mouse_type;
|
||||
|
||||
void usbh_hid_mouse_decode(uint8_t *mouse_data);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user