EFM32 Happy Gecko Software Documentation  efm32hg-doc-5.1.2
HidKeyboard

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

Data Structures

struct  HIDKBD_Init_t
 
struct  HIDKBD_KeyReport_t
 

Typedefs

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. More...
 

Functions

void HIDKBD_Init (HIDKBD_Init_t *init)
 Initialize HID Keyboard driver. More...
 
void HIDKBD_KeyboardEvent (HIDKBD_KeyReport_t *report)
 Report a keyboard press/release event. More...
 
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. More...
 
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. More...
 

Variables

const char HIDKBD_ReportDescriptor [69]
 

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]reportOutput 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]initPointer 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]reportPointer to a HIDKBD_KeyReport_t struct with new key pressed information.

Definition at line 202 of file hidkbd.c.

References USBD_Write().

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]setupPointer 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 USB_Setup_TypeDef::bRequest, USB_Setup_TypeDef::Direction, GET_DESCRIPTOR, USB_Setup_TypeDef::Recipient, SL_MIN, STATIC_UBUF, USB_Setup_TypeDef::Type, USB_HID_DESCRIPTOR, USB_HID_DESCSIZE, USB_HID_GET_IDLE, USB_HID_GET_REPORT, USB_HID_REPORT_DESCRIPTOR, USB_HID_SET_IDLE, USB_HID_SET_REPORT, USB_SETUP_DIR_IN, USB_SETUP_RECIPIENT_INTERFACE, USB_SETUP_TYPE_CLASS, USB_SETUP_TYPE_STANDARD, USB_STATUS_OK, USB_STATUS_REQ_UNHANDLED, USBD_Read(), USBD_Write(), USBTIMER_Stop(), USB_Setup_TypeDef::wIndex, USB_Setup_TypeDef::wLength, and USB_Setup_TypeDef::wValue.

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]oldStateThe device state the device has just left.
[in]newStateThe new device state.

Definition at line 344 of file hidkbd.c.

References DEFAULT_IDLE_RATE, USBD_STATE_CONFIGURED, USBD_STATE_SUSPENDED, USBTIMER_Start(), and USBTIMER_Stop().