Dwayne Dilbeck / USBDevice

Dependents:   HW4_AudioControl

Fork of USBDevice by mbed official

Embed: (wiki syntax)

« Back to documentation index

USBKeyboard Class Reference

USBKeyboard Class Reference

USBKeyboard example. More...

#include <USBKeyboard.h>

Inherits USBHID.

Public Member Functions

 USBKeyboard (uint16_t vendor_id=0x1235, uint16_t product_id=0x0050, uint16_t product_release=0x0001)
 Constructor.
bool keyCode (uint8_t key, uint8_t modifier=0)
 To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key.
virtual int _putc (int c)
 Send a character.
bool mediaControl (MEDIA_KEY key)
 Control media keys.
uint8_t lockStatus ()
 Read status of lock keys.
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

USBKeyboard example.

 #include "mbed.h"
 #include "USBKeyboard.h"

 USBKeyboard key;

 int main(void)
 {
   while (1)
   {
       key.printf("Hello World\r\n");
       wait(1);
   }
 }

Definition at line 92 of file USBKeyboard.h.


Constructor & Destructor Documentation

USBKeyboard ( uint16_t  vendor_id = 0x1235,
uint16_t  product_id = 0x0050,
uint16_t  product_release = 0x0001 
)

Constructor.

Parameters:
ledsLeds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK
vendor_idYour vendor_id (default: 0x1235)
product_idYour product_id (default: 0x0050)
product_releaseYour preoduct_release (default: 0x0001)

Definition at line 105 of file USBKeyboard.h.


Member Function Documentation

int _putc ( int  c ) [virtual]

Send a character.

Parameters:
ccharacter to be sent
Returns:
true if there is no error, false otherwise

Definition at line 441 of file USBKeyboard.cpp.

bool FillFeatureReport ( HID_REPORT *  report ) [inherited]

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 ) [inherited]

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 keyCode ( uint8_t  key,
uint8_t  modifier = 0 
)

To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key.

 //To send CTRL + s (save)
  keyboard.keyCode('s', KEY_CTRL);
Parameters:
modifierbit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0)
keycharacter to send
Returns:
true if there is no error, false otherwise

Definition at line 445 of file USBKeyboard.cpp.

uint8_t lockStatus (  )

Read status of lock keys.

Useful to switch-on/off leds according to key pressed. Only the first three bits of the result is important:

  • First bit: NUM_LOCK
  • Second bit: CAPS_LOCK
  • Third bit: SCROLL_LOCK
Returns:
status of lock keys

Definition at line 437 of file USBKeyboard.cpp.

bool mediaControl ( MEDIA_KEY  key )

Control media keys.

Parameters:
keymedia key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN)
Returns:
true if there is no error, false otherwise

Definition at line 477 of file USBKeyboard.cpp.

bool read ( HID_REPORT *  report ) [inherited]

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 ) [inherited]

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 ) [inherited]

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 ) [inherited]

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, inherited]

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) [inherited]

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) [inherited]

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) [inherited]

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) [inherited]

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) [inherited]

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) [inherited]

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.