M480 BSP V3.05.005
The Board Support Package for M480 Series
Functions
hid_core.c File Reference

M480 USB Host HID driver. More...

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "NuMicro.h"
#include "usb.h"
#include "usbh_lib.h"
#include "usbh_hid.h"

Go to the source code of this file.

Functions

int32_t usbh_hid_get_report_descriptor (HID_DEV_T *hdev, uint8_t *desc_buf, int buf_max_len)
 Read report descriptor from HID device. More...
 
int32_t usbh_hid_get_report (HID_DEV_T *hdev, int rtp_typ, int rtp_id, uint8_t *data, int len)
 Issue a HID class GET_REPORT request. More...
 
int32_t usbh_hid_set_report (HID_DEV_T *hdev, int rtp_typ, int rtp_id, uint8_t *data, int len)
 Issue a HID class SET_REPORT request. The Set_Report request allows the host to send a report to the device, possibly setting the state of input, output, or feature controls. More...
 
HIDDEN_SYMBOLS int32_t usbh_hid_get_idle (HID_DEV_T *hdev, int rtp_id, uint8_t *idle_rate)
 Issue a HID class GET_IDLE request. The GET_IDLE request reads the current idle rate for a particular Input report. More...
 
int32_t usbh_hid_set_idle (HID_DEV_T *hdev, int rtp_id, uint8_t idle_rate)
 Issue a HID class SET_IDLE request. The SET_IDLE request silences a particular report on the Interrupt In pipe until a new event occurs or the specified amount of time passes. More...
 
int32_t usbh_hid_get_protocol (HID_DEV_T *hdev, uint8_t *protocol)
 Issue a HID class GET_PROTOCOL request. The GET_PROTOCOL request reads which protocol is currently active (either the boot protocol or the report protocol.) More...
 
int32_t usbh_hid_set_protocol (HID_DEV_T *hdev, uint8_t protocol)
 Issue a HID class SET_PROTOCOL request. The SET_PROTOCOL switches between the boot protocol and the report protocol (or vice versa). More...
 
HIDDEN_SYMBOLS int32_t usbh_hid_start_int_read (HID_DEV_T *hdev, uint8_t ep_addr, HID_IR_FUNC *func)
 Start purge the USB interrupt in transfer. More...
 
int32_t usbh_hid_stop_int_read (HID_DEV_T *hdev, uint8_t ep_addr)
 Stop purge the USB interrupt in transfer. More...
 
int32_t usbh_hid_start_int_write (HID_DEV_T *hdev, uint8_t ep_addr, HID_IW_FUNC *func)
 Start purge the USB interrupt out transfer. More...
 
int32_t usbh_hid_stop_int_write (HID_DEV_T *hdev, uint8_t ep_addr)
 stop purge the USB interrupt out transfer. More...
 
void usbh_hid_regitser_mouse_callback (HID_MOUSE_FUNC *func)
 Register the mouse event callback function to HID class driver. Any mouse reports will be sent to user application via this callback. More...
 
void usbh_hid_regitser_keyboard_callback (HID_KEYBOARD_FUNC *func)
 Register the keyboard event callback function to HID class driver. Any keyboard reports will be sent to user application via this callback. More...
 

Detailed Description

M480 USB Host HID driver.

Version
V1.00

SPDX-License-Identifier: Apache-2.0

Definition in file hid_core.c.

Function Documentation

◆ usbh_hid_get_idle()

HIDDEN_SYMBOLS int32_t usbh_hid_get_idle ( HID_DEV_T hdev,
int  rtp_id,
uint8_t *  idle_rate 
)

Issue a HID class GET_IDLE request. The GET_IDLE request reads the current idle rate for a particular Input report.

Parameters
[in]hdevHID device pointer
[in]rtp_idReport ID
[out]idle_rateAn one byte buffer holds the reported idle rate.
Returns
Success or not.
Return values
0Success
OtherwiseFailed

Definition at line 243 of file hid_core.c.

◆ usbh_hid_get_protocol()

int32_t usbh_hid_get_protocol ( HID_DEV_T hdev,
uint8_t *  protocol 
)

Issue a HID class GET_PROTOCOL request. The GET_PROTOCOL request reads which protocol is currently active (either the boot protocol or the report protocol.)

Parameters
[in]hdevHID device pointer
[out]protocolAn one byte buffer holds the protocol code.
Returns
Success or not.
Return values
0Success
OtherwiseFailed

Definition at line 323 of file hid_core.c.

◆ usbh_hid_get_report()

int32_t usbh_hid_get_report ( HID_DEV_T hdev,
int  rtp_typ,
int  rtp_id,
uint8_t *  data,
int  len 
)

Issue a HID class GET_REPORT request.

Parameters
[in]hdevHID device pointer
[in]rtp_typReport type. Valid values are:
[in]rtp_idReport ID
[out]dataBuffer to store data retrieved from this report ID.
[in]lenReport length.
Returns
Report length or error code.
Return values
>=0The actual length of data obtained from this report ID.
OtherwiseFailed

Definition at line 102 of file hid_core.c.

◆ usbh_hid_get_report_descriptor()

int32_t usbh_hid_get_report_descriptor ( HID_DEV_T hdev,
uint8_t *  desc_buf,
int  buf_max_len 
)

Read report descriptor from HID device.

Parameters
[in]hdevHID device pointer
[out]desc_bufData buffer for report descriptor read from HID device.
[in]buf_max_lenThe maximum length of desc_buf.
Returns
Report descriptor length or error code.
Return values
<0Failed
OtherwiseLength of report descriptor read.

Definition at line 56 of file hid_core.c.

◆ usbh_hid_set_idle()

int32_t usbh_hid_set_idle ( HID_DEV_T hdev,
int  rtp_id,
uint8_t  idle_rate 
)

Issue a HID class SET_IDLE request. The SET_IDLE request silences a particular report on the Interrupt In pipe until a new event occurs or the specified amount of time passes.

Parameters
[in]hdevHID device
[in]rtp_idReport ID
[out]idle_rateThe idle rate to be set.
Returns
Success or not.
Return values
0Success
OtherwiseFailed

Definition at line 283 of file hid_core.c.

◆ usbh_hid_set_protocol()

int32_t usbh_hid_set_protocol ( HID_DEV_T hdev,
uint8_t  protocol 
)

Issue a HID class SET_PROTOCOL request. The SET_PROTOCOL switches between the boot protocol and the report protocol (or vice versa).

Parameters
[in]hdevHID device pointer.
[in]protocolThe protocol to be set.
Returns
Success or not.
Return values
0Success
OtherwiseFailed

Definition at line 362 of file hid_core.c.

◆ usbh_hid_set_report()

int32_t usbh_hid_set_report ( HID_DEV_T hdev,
int  rtp_typ,
int  rtp_id,
uint8_t *  data,
int  len 
)

Issue a HID class SET_REPORT request. The Set_Report request allows the host to send a report to the device, possibly setting the state of input, output, or feature controls.

Parameters
[in]hdevHID device pointer
[in]rtp_typReport type. Valid values are:
[in]rtp_idReport ID
[out]dataBuffer store data to be send.
[in]lenReport length.
Returns
Written length or error code.
Return values
>=0The actual length of data written to this report ID.
OtherwiseFailed

Definition at line 147 of file hid_core.c.

◆ usbh_hid_start_int_read()

HIDDEN_SYMBOLS int32_t usbh_hid_start_int_read ( HID_DEV_T hdev,
uint8_t  ep_addr,
HID_IR_FUNC func 
)

Start purge the USB interrupt in transfer.

Parameters
[in]hdevHID device pointer.
[in]ep_addrEndpoint address. If ep_addr is 0, it will use the first found interrupt-in endpoint. If ep_addr is not 0, it will use the specified endpoint if found.
[in]funcThe interrupt in data receiver callback function.
Returns
Success or not.
Return values
0Success
OtherwiseFailed

Definition at line 485 of file hid_core.c.

◆ usbh_hid_start_int_write()

int32_t usbh_hid_start_int_write ( HID_DEV_T hdev,
uint8_t  ep_addr,
HID_IW_FUNC func 
)

Start purge the USB interrupt out transfer.

Parameters
[in]hdevHID device pointer.
[in]ep_addrEndpoint address. If ep_addr is 0, it will use the first found interrupt-out endpoint. If ep_addr is not 0, it will use the specified endpoint if found.
[in]funcThe interrupt in data transfer callback function.
Returns
Success or not.
Return values
0Success
OtherwiseFailed

Definition at line 614 of file hid_core.c.

◆ usbh_hid_stop_int_read()

int32_t usbh_hid_stop_int_read ( HID_DEV_T hdev,
uint8_t  ep_addr 
)

Stop purge the USB interrupt in transfer.

Parameters
[in]hdevHID device pointer
[in]ep_addrEndpoint address. If ep_addr is 0, it will use the first found interrupt-in endpoint. If ep_addr is not 0, it will use the specified endpoint if found.
Returns
Success or not.
Return values
0Success
OtherwiseFailed

Definition at line 559 of file hid_core.c.

◆ usbh_hid_stop_int_write()

int32_t usbh_hid_stop_int_write ( HID_DEV_T hdev,
uint8_t  ep_addr 
)

stop purge the USB interrupt out transfer.

Parameters
[in]hdevHID device pointer
[in]ep_addrEndpoint address. If ep_addr is 0, it will use the first found interrupt-out endpoint. If ep_addr is not 0, it will use the specified endpoint if found.
Returns
Success or not.
Return values
0Success
OtherwiseFailed

Definition at line 691 of file hid_core.c.