Dwayne Dilbeck / USBDevice

Dependents:   HW4_AudioControl

Fork of USBDevice by mbed official

Embed: (wiki syntax)

« Back to documentation index

USBHID Class Reference

USBHID Class Reference

USBHID example. More...

#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_lengthMaximum length of a sent report (up to 64 bytes) (default: 64 bytes)
input_report_lengthMaximum length of a received report (up to 64 bytes) (default: 64 bytes)
report_report_lengthMaximum length of a received report (up to 64 bytes) (default: 64 bytes)
vendor_idYour vendor_id
product_idYour product_id
product_releaseYour preoduct_release
connectConnect 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_lengthMaximum length of a sent report (up to 64 bytes) (default: 64 bytes)
input_report_lengthMaximum length of a received report (up to 64 bytes) (default: 64 bytes)
report_report_lengthMaximum length of a received report (up to 64 bytes) (default: 64 bytes)
vendor_idYour vendor_id
product_idYour product_id
product_releaseYour preoduct_release
connectConnect 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:
reportpointer 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:
reportpointer 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:
reportReport 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:
reportReport 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)

Callback pointers to functions.

Parameters:
reportpointer to the report to fill These allow a user program to hook on get_report/set_report actions for each type.

Definition at line 194 of file USBHID.h.

bool(* callbackGetInputReport)(HID_REPORT *report)

Callback pointers to functions.

Parameters:
reportpointer to the report to fill These allow a user program to hook on get_report/set_report actions for each type.

Definition at line 166 of file USBHID.h.

bool(* callbackGetOutputReport)(HID_REPORT *report)

Callback pointers to functions.

Parameters:
reportpointer to the report to fill These allow a user program to hook on get_report/set_report actions for each type.

Definition at line 180 of file USBHID.h.

void(* callbackSetFeatureReport)(HID_REPORT *report)

Callback pointers to functions.

Parameters:
reportpointer to the report to fill These allow a user program to hook on get_report/set_report actions for each type.

Definition at line 187 of file USBHID.h.

void(* callbackSetInputReport)(HID_REPORT *report)

Callback pointers to functions.

Parameters:
reportpointer to the report to fill These allow a user program to hook on get_report/set_report actions for each type.

Definition at line 159 of file USBHID.h.

void(* callbackSetOutputReport)(HID_REPORT *report)

Callback pointers to functions.

Parameters:
reportpointer to the report to fill These allow a user program to hook on get_report/set_report actions for each type.

Definition at line 173 of file USBHID.h.