Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of USBDevice by
USBHID Class Reference
#include <USBHID.h>
Inherits USBDevice.
Inherited by USBKeyboard, USBMouse, and USBMouseKeyboard.
Public Member Functions | |
| USBHID (uint8_t output_report_length, uint8_t input_report_length, uint8_t feature_report_length, uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect) | |
| Constructor. | |
| USBHID (uint8_t output_report_length=64, uint8_t input_report_length=64, uint16_t vendor_id=0x1234, uint16_t product_id=0x0006, uint16_t product_release=0x0001, bool connect=true) | |
| Constructor default constructor to maintain backwards compatibility. | |
| bool | send (HID_REPORT *report) |
| Send a Report. | |
| bool | sendNB (HID_REPORT *report) |
| Send a Report. | |
| bool | read (HID_REPORT *report) |
| Read a report: blocking legacy method retained for backward compatability. | |
| bool | readNB (HID_REPORT *report) |
| Read a report: non blocking legacy method retained for backward compatability. | |
| bool | FillInputReport (HID_REPORT *report) |
| Provide the ability to Fill the inputReport. | |
| bool | FillFeatureReport (HID_REPORT *report) |
| Provide the ability to Fill the featureReport. | |
| virtual void | SetReportIdle (uint16_t wValue) |
| This function should be private, but is exposed to allow a developer to reenable IDLE values > zero after windows sets the value to zero. | |
Data Fields | |
| void(* | callbackSetInputReport )(HID_REPORT *report) |
| Callback pointers to functions. | |
| bool(* | callbackGetInputReport )(HID_REPORT *report) |
| Callback pointers to functions. | |
| void(* | callbackSetOutputReport )(HID_REPORT *report) |
| Callback pointers to functions. | |
| bool(* | callbackGetOutputReport )(HID_REPORT *report) |
| Callback pointers to functions. | |
| void(* | callbackSetFeatureReport )(HID_REPORT *report) |
| Callback pointers to functions. | |
| bool(* | callbackGetFeatureReport )(HID_REPORT *report) |
| Callback pointers to functions. | |
Detailed Description
USBHID example.
//We declare a USBHID device. Input, Output, and Feature reports have a length of 8 bytes USBHID hid(8, 8, 8,0x1234,0x0006, 0x0001,true); HID_REPORT tempReport; void MycallbackSetReport(HID_REPORT *report){ printf("Report: "); for(int i = 0; i < report->length; i++) { printf("%x ", report->data[i]); } printf("\r\n"); }; bool SetTempReport(HID_REPORT *report){ for (int i = 0; i < report->length; i++) { report->data[i] = rand() & 0xff; } return true; }; int main(void) { printf("Starting==>\r\n"); hid.callbackSetOutputReport=&MycallbackSetReport; tempReport.length=8; while (1) { SetTempReport(&tempReport); hid.FillInputReport(&tempReport); wait(2.2); } }
Definition at line 68 of file USBHID.h.
Constructor & Destructor Documentation
| USBHID | ( | uint8_t | output_report_length, |
| uint8_t | input_report_length, | ||
| uint8_t | feature_report_length, | ||
| uint16_t | vendor_id, | ||
| uint16_t | product_id, | ||
| uint16_t | product_release, | ||
| bool | connect | ||
| ) |
Constructor.
- Parameters:
-
output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes) input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes) report_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes) vendor_id Your vendor_id product_id Your product_id product_release Your preoduct_release connect Connect the device
Definition at line 26 of file USBHID.cpp.
| USBHID | ( | uint8_t | output_report_length = 64, |
| uint8_t | input_report_length = 64, |
||
| uint16_t | vendor_id = 0x1234, |
||
| uint16_t | product_id = 0x0006, |
||
| uint16_t | product_release = 0x0001, |
||
| bool | connect = true |
||
| ) |
Constructor default constructor to maintain backwards compatibility.
- Parameters:
-
output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes) input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes) report_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes) vendor_id Your vendor_id product_id Your product_id product_release Your preoduct_release connect Connect the device
Definition at line 57 of file USBHID.cpp.
Member Function Documentation
| bool FillFeatureReport | ( | HID_REPORT * | report ) |
Provide the ability to Fill the featureReport.
- Parameters:
-
HID_REPORT
- Returns:
- true if succsful
Definition at line 180 of file USBHID.cpp.
| bool FillInputReport | ( | HID_REPORT * | report ) |
Provide the ability to Fill the inputReport.
Report transfer is automatic if the data changes
- Parameters:
-
HID_REPORT
- Returns:
- true if succsful The devloper should always use FillReport, The IDLE logic will send a report if the value has changed, or if the idle period expires.
Definition at line 163 of file USBHID.cpp.
| bool read | ( | HID_REPORT * | report ) |
Read a report: blocking legacy method retained for backward compatability.
- Parameters:
-
report pointer to the report to fill
- Returns:
- true if successful
Definition at line 132 of file USBHID.cpp.
| bool readNB | ( | HID_REPORT * | report ) |
Read a report: non blocking legacy method retained for backward compatability.
- Parameters:
-
report pointer to the report to fill
- Returns:
- true if successful
Definition at line 145 of file USBHID.cpp.
| bool send | ( | HID_REPORT * | report ) |
Send a Report.
warning: blocking legacy method retained for backward compatability
- Parameters:
-
report Report which will be sent (a report is defined by all data and the length)
- Returns:
- true if successful
Definition at line 120 of file USBHID.cpp.
| bool sendNB | ( | HID_REPORT * | report ) |
Send a Report.
warning: non blocking legacy method retained for backward compatability
- Parameters:
-
report Report which will be sent (a report is defined by all data and the length)
- Returns:
- true if successful
Definition at line 126 of file USBHID.cpp.
| void SetReportIdle | ( | uint16_t | wValue ) | [virtual] |
This function should be private, but is exposed to allow a developer to reenable IDLE values > zero after windows sets the value to zero.
This is due to microsoft windows HID driver not implementing IOCTL_HID_SET_POLL_FREQUENCY_MSEC/IOCTL_HID_GET_POLL_FREQUENCY_MSEC
Definition at line 108 of file USBHID.cpp.
Field Documentation
| bool(* callbackGetFeatureReport)(HID_REPORT *report) |
| bool(* callbackGetInputReport)(HID_REPORT *report) |
| bool(* callbackGetOutputReport)(HID_REPORT *report) |
| void(* callbackSetFeatureReport)(HID_REPORT *report) |
| void(* callbackSetInputReport)(HID_REPORT *report) |
| void(* callbackSetOutputReport)(HID_REPORT *report) |
Generated on Tue Jul 12 2022 20:53:39 by
1.7.2
