| M480 BSP V3.05.001 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

Copyright
  (C) 2017-2020 Nuvoton Technology Corp. All rights reserved.

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] | hdev | HID device pointer
  [in] | rtp_id | Report ID
  [out] | idle_rate | An one byte buffer holds the reported idle rate.

Returns
  Success or not.

Return values

  0 | Success
  Otherwise | Failed

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] | hdev | HID device pointer
  [out] | protocol | An one byte buffer holds the protocol code.

Returns
  Success or not.

Return values

  0 | Success
  Otherwise | Failed

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] | hdev | HID device pointer
  [in] | rtp_typ | Report type. Valid values are: RT_INPUT RT_OUTPUT RT_FEATURE
  [in] | rtp_id | Report ID
  [out] | data | Buffer to store data retrieved from this report ID.
  [in] | len | Report length.

Returns
  Report length or error code.

Return values

  >=0 | The actual length of data obtained from this report ID.
  Otherwise | Failed

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] | hdev | HID device pointer
  [out] | desc_buf | Data buffer for report descriptor read from HID device.
  [in] | buf_max_len | The maximum length of desc_buf.

Returns
  Report descriptor length or error code.

Return values

  <0 | Failed
  Otherwise | Length 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] | hdev | HID device
  [in] | rtp_id | Report ID
  [out] | idle_rate | The idle rate to be set.

Returns
  Success or not.

Return values

  0 | Success
  Otherwise | Failed

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] | hdev | HID device pointer.
  [in] | protocol | The protocol to be set.

Returns
  Success or not.

Return values

  0 | Success
  Otherwise | Failed

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] | hdev | HID device pointer
  [in] | rtp_typ | Report type. Valid values are: RT_INPUT RT_OUTPUT RT_FEATURE
  [in] | rtp_id | Report ID
  [out] | data | Buffer store data to be send.
  [in] | len | Report length.

Returns
  Written length or error code.

Return values

  >=0 | The actual length of data written to this report ID.
  Otherwise | Failed

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] | hdev | HID device pointer.
  [in] | ep_addr | Endpoint 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] | func | The interrupt in data receiver callback function.

Returns
  Success or not.

Return values

  0 | Success
  Otherwise | Failed

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] | hdev | HID device pointer.
  [in] | ep_addr | Endpoint 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] | func | The interrupt in data transfer callback function.

Returns
  Success or not.

Return values

  0 | Success
  Otherwise | Failed

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] | hdev | HID device pointer
  [in] | ep_addr | Endpoint 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

  0 | Success
  Otherwise | Failed

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] | hdev | HID device pointer
  [in] | ep_addr | Endpoint 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

  0 | Success
  Otherwise | Failed

Definition at line 691 of file hid_core.c.