User API reference of the Human Interface Device Class. More...
Functions | |
void | USBH_HID_Initialize (uint8_t instance) |
Callback function called when Human Interface Device was enumerated and is ready. | |
void | USBH_HID_Uninitialize (uint8_t instance) |
Callback function called when Human Interface Device was disconnected. | |
uint8_t | USBH_HID_GetDevice (uint8_t instance) |
Get Device instance of Human Interface Device. | |
usbStatus | USBH_HID_GetStatus (uint8_t instance) |
Get status of Human Interface Device. | |
int32_t | USBH_HID_Read (uint8_t instance, uint8_t *buf, int32_t len) |
Read data received from Human Interface Device. | |
int32_t | USBH_HID_Write (uint8_t instance, const uint8_t *buf, int32_t len) |
Write data to Human Interface Device. | |
int | USBH_HID_GetKeyboardKey (uint8_t instance) |
Retrieve first pending pressed keyboard key on HID Keyboard. | |
usbStatus | USBH_HID_GetMouseState (uint8_t instance, usbHID_MouseState *state) |
Retrieve state change since last call of this function. | |
void | USBH_HID_ParseReportDescriptor (uint8_t instance, const uint8_t *ptr_hid_report_desc, uint32_t len) |
Callback function called for parsing of the Human Interface Device report descriptor. | |
void | USBH_HID_DataReceived (uint8_t instance, uint32_t len) |
Callback function called when data is received from the Human Interface Device. | |
User API reference of the Human Interface Device Class.
void USBH_HID_DataReceived | ( | uint8_t | instance, |
uint32_t | len | ||
) |
Callback function called when data is received from the Human Interface Device.
[in] | instance | instance index. |
[in] | len | length of received data. |
The USBH_HID_DataReceived function enables programmers to analyze received data coming from an USB HID device. Implementing this function in user code overrides the USB Component function that handles boot protocol device data reception. This is useful if the default HID functionality needs to be changed to support special HID devices.
uint8_t USBH_HID_GetDevice | ( | uint8_t | instance | ) |
Get Device instance of Human Interface Device.
[in] | instance | instance of HID Device. |
The function USBH_HID_GetDevice is used to retrieve device instance that is used to handle human interface device instance.
The argument instance specifies the HID device instance.
int32_t USBH_HID_GetKeyboardKey | ( | uint8_t | instance | ) |
Retrieve first pending pressed keyboard key on HID Keyboard.
[in] | instance | instance of HID Device. |
The function USBH_HID_GetKeyboardKey enables programmers to handle signals from a USB keyboard.
The argument instance specifies the HID device instance.
The function returns an integer value of the first pending keystroke. Characters that are directly mapped into ASCII are the HID codes starting from 4 (representing 'a') up to to 57 (representing '/'). All other HID codes are passed by this function using bit 16. set to '1' to notify the application about extended non-ASCII mapped HID codes. Modifier keys are encoded in bits 8..15 with following encoding:
Bit | Modifier Key |
---|---|
8 | Left Control |
9 | Left Shift |
10 | Left Alt |
11 | Left GUI |
12 | Right Control |
13 | Right Shift |
14 | Right Alt |
15 | Right GUI |
Consult the USB-IF's online documentation for information on HID Usage Tables relevant usage page for this function is Keyboard/Keypad Page 0x07.
Code Example
bool USBH_HID_GetMouseState | ( | uint8_t | instance, |
usbHID_MouseState * | state | ||
) |
Retrieve state change since last call of this function.
[in] | instance | instance of HID Device. |
[out] | state | pointer to mouse state usbHID_MouseState structure. |
The function USBH_HID_GetMouseState enables programmers to handle signals from an USB mouse.
The argument instance specifies the HID device instance.
The argument state is a pointer to the mouse state structure (usbHID_MouseState).
Code Example
usbStatus USBH_HID_GetStatus | ( | uint8_t | instance | ) |
Get status of Human Interface Device.
[in] | instance | instance of HID Device. |
The function USBH_HID_GetStatus checks whether the human interface device is connected and initialized.
The argument instance specifies the HID device instance.
Code Example
void USBH_HID_Initialize | ( | uint8_t | instance | ) |
Callback function called when Human Interface Device was enumerated and is ready.
[in] | instance | instance of HID Device. |
The function USBH_HID_Initialize is called when a human interface device was connected and successfully enumerated and is ready for communication.
The argument instance specifies the HID device instance.
void USBH_HID_ParseReportDescriptor | ( | uint8_t | instance, |
const uint8_t * | ptr_hid_report_desc, | ||
uint32_t | len | ||
) |
Callback function called for parsing of the Human Interface Device report descriptor.
[in] | instance | instance index. |
[in] | ptr_hid_report_desc | pointer to HID report descriptor. |
[in] | len | length of HID report descriptor. |
The USBH_HID_ParseReportDescriptor function enables programmers to parse report descriptors of an USB HID device. This is useful if the default HID functionality needs to be changed to support special HID devices.
int32_t USBH_HID_Read | ( | uint8_t | instance, |
uint8_t * | buf, | ||
int32_t | len | ||
) |
Read data received from Human Interface Device.
[in] | instance | instance of HID Device. |
[out] | buf | buffer that receives data. |
[in] | len | maximum number of bytes to read. |
The function USBH_HID_Read retrieves the data sent by an USB HID device and stores it in a buffer.
The argument instance specifies the HID device instance.
The argument buf is pointing to the location where the data will be returned (stored). It is recommended that buffer is 4-byte aligned as some drivers might not support 1-byte alignment if DMA is used.
The argument len specifies the number of bytes to be read (must be multiple of HID device Interrupt In endpoint maximum packet size).
Code Example
void USBH_HID_Uninitialize | ( | uint8_t | instance | ) |
Callback function called when Human Interface Device was disconnected.
[in] | instance | instance of HID Device. |
The function USBH_HID_Unitialize is called when a human interface device was disconnected form the USB Bus.
The argument instance specifies the HID device instance.
int32_t USBH_HID_Write | ( | uint8_t | instance, |
const uint8_t * | buf, | ||
int32_t | len | ||
) |
Write data to Human Interface Device.
[in] | instance | instance of HID Device. |
[in] | buf | data buffer containing data to write. |
[in] | len | number of data bytes to write. |
The function USBH_HID_Write writes data from a buffer to an USB HID device.
The argument instance specifies the HID device instance.
The argument buf is pointing to the location where the data will be written. It is recommended that buffer is 4-byte aligned as some drivers might not support 1-byte alignment if DMA is used.
The argument len specifies the number of data bytes to be written.
Code Example