HidKeyboard
[Drivers]

Implements a USB HID class keyboard. More...

Collaboration diagram for HidKeyboard:

Data Structures

struct  HIDKBD_KeyReport_t
 HID keyboard input report definition. More...
struct  HIDKBD_Init_t
 HidKeyboard driver initialization structure. More...

Typedefs

typedef void(* HIDKBD_SetReportFunc_t )(uint8_t report)
 Callback function pointer for HID output reports.

Functions

void HIDKBD_Init (HIDKBD_Init_t *init)
 Initialize HID Keyboard driver.
int HIDKBD_SetupCmd (const USB_Setup_TypeDef *setup)
 Handle USB setup commands.
void HIDKBD_StateChangeEvent (USBD_State_TypeDef oldState, USBD_State_TypeDef newState)
 Handle USB state change events, this function must be called each time the USB device state is changed.
void HIDKBD_KeyboardEvent (HIDKBD_KeyReport_t *report)
 Report a keyboard press/release event.

Variables

const char HIDKBD_ReportDescriptor [69]
 HID report descriptor created with usb.org's "HID Descriptor Tool(DT)" version 2.4.

Detailed Description

Implements a USB HID class keyboard.

HIDKBD implementation.

The source code of the HIDKBD implementation resides in kits/common/drivers/hidkbd.c and hidkbd.h. This driver implements a basic USB keyboard. Refer to hidkbd examples for STK3700 and DK3750 for examples using this driver.

HIDKBD device configuration options.

This section contains a description of the configuration options for the driver. The options are #define's which are expected to be found in the application "usbconfig.h" header file. The values shown below are from the Giant Gecko STK3700 hidbkd example.

// USB interface number. Interfaces are numbered from zero to one less than
// the number of concurrent interfaces supported by the configuration.
// The interfac numbers must be 0 standalone HID device, for a
// composite device which includes a HID interface it must not be in conflict
// with other device interfaces.
#define HIDKBD_INTERFACE_NO     0

// Endpoint address for HID input reports.
#define HIDKBD_INTR_IN_EP_ADDR  0x81

// The bInterval reported with the interrupt IN endpoint descriptor.
#define HIDKBD_POLL_RATE        24

// Timer id, see USBTIMER in the USB device stack documentation.
// The HID driver use a timer to implement the idle-rate defined in the HID class spec.
#define HIDKBD_IDLE_TIMER       0
  

Typedef Documentation

typedef void(* HIDKBD_SetReportFunc_t)(uint8_t report)

Callback function pointer for HID output reports.

This function will be called by the driver each time an output report is received by the device.

Parameters:
[in] report Output report byte.
Bit 0 : State of keyboard NumLock LED.
Bit 1 : State of keyboard CapsLock LED.
Bit 2 : State of keyboard ScrollLock LED.

Definition at line 58 of file hidkbd.h.


Function Documentation

void HIDKBD_Init ( HIDKBD_Init_t init  ) 

Initialize HID Keyboard driver.

Parameters:
[in] init Pointer to a HIDKBD_Init_t struct with configuration options.

Definition at line 187 of file hidkbd.c.

References HIDKBD_Init_t::hidDescriptor, and HIDKBD_Init_t::setReportFunc.

void HIDKBD_KeyboardEvent ( HIDKBD_KeyReport_t report  ) 

Report a keyboard press/release event.

Parameters:
[in] report Pointer to a HIDKBD_KeyReport_t struct with new key pressed information.

Definition at line 202 of file hidkbd.c.

int HIDKBD_SetupCmd ( const USB_Setup_TypeDef *  setup  ) 

Handle USB setup commands.

Implements HID class specific commands. This function must be called each time the device receive a setup command.

Parameters:
[in] setup Pointer to the setup packet received.
Returns:
USB_STATUS_OK if command accepted, USB_STATUS_REQ_UNHANDLED when command is unknown. In the latter case the USB device stack will handle the request.

Definition at line 232 of file hidkbd.c.

References HIDKBD_ReportDescriptor.

void HIDKBD_StateChangeEvent ( USBD_State_TypeDef  oldState,
USBD_State_TypeDef  newState 
)

Handle USB state change events, this function must be called each time the USB device state is changed.

Parameters:
[in] oldState The device state the device has just left.
[in] newState The new device state.

Definition at line 344 of file hidkbd.c.

References DEFAULT_IDLE_RATE.


Variable Documentation

const char HIDKBD_ReportDescriptor[69]

HID report descriptor created with usb.org's "HID Descriptor Tool(DT)" version 2.4.

The descriptor defines an input report which matches the HIDKBD_KeyReport_t typedef, and an output report with 3 bits for controlling NumLock, CapsLock and ScrollLock keyboard LED's

Definition at line 67 of file hidkbd.c.

Referenced by HIDKBD_SetupCmd().