The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
hid.c File Reference
#include "hid.h"
#include "common/memory.h"

Macros

#define TYPE_MAIN   0
 the HID report descriptor parser (USB Device Class Definition for HID 1.11, section 6.2.2).
#define TYPE_GLOBAL   1
#define TYPE_LOCAL   2
#define MAIN_INPUT   0x8
#define GLOBAL_PAGE   0x0
#define GLOBAL_LOG_MIN   0x1
#define GLOBAL_LOG_MAX   0x2
#define GLOBAL_SIZE   0x7
#define GLOBAL_ID   0x8
#define GLOBAL_COUNT   0x9
#define LOCAL_USAGE   0x0
#define LOCAL_USAGE_MIN   0x1
#define LOCAL_USAGE_MAX   0x2
#define INPUT_CONSTANT   0x01
#define INPUT_RELATIVE   0x04
#define PAGE_DESKTOP   0x01
#define PAGE_BUTTON   0x09
#define USAGE_X   0x30
#define USAGE_Y   0x31
#define USAGE_WHEEL   0x38
#define MAX_USAGES   16

Functions

bool hid_parse_pointer (const uint8_t *descriptor, uint32_t length, hid_pointer_t *out)
 find the pointer fields in a report descriptor.
int32_t hid_field_value (const hid_field_t *field, const uint8_t *report, uint32_t length)
 read a field from a report (the report id byte already skipped).

Macro Definition Documentation

◆ TYPE_MAIN

#define TYPE_MAIN   0

the HID report descriptor parser (USB Device Class Definition for HID 1.11, section 6.2.2).

a descriptor is a list of items: a prefix byte (the size in bits 0 to 1, the type in bits 2 to 3, the tag in bits 4 to 7) and 0, 1, 2 or 4 data bytes. global items (the usage page, the logical range, the report size, count and id) stay set until changed; local items (the usages) belong to the next main item. an Input main item adds report count fields of report size bits each to the report.

not supported: push and pop of the global state, and long items (they are skipped). the pointer fields must all be in one report.

◆ TYPE_GLOBAL

#define TYPE_GLOBAL   1

◆ TYPE_LOCAL

#define TYPE_LOCAL   2

◆ MAIN_INPUT

#define MAIN_INPUT   0x8

◆ GLOBAL_PAGE

#define GLOBAL_PAGE   0x0

◆ GLOBAL_LOG_MIN

#define GLOBAL_LOG_MIN   0x1

◆ GLOBAL_LOG_MAX

#define GLOBAL_LOG_MAX   0x2

◆ GLOBAL_SIZE

#define GLOBAL_SIZE   0x7

◆ GLOBAL_ID

#define GLOBAL_ID   0x8

◆ GLOBAL_COUNT

#define GLOBAL_COUNT   0x9

◆ LOCAL_USAGE

#define LOCAL_USAGE   0x0

◆ LOCAL_USAGE_MIN

#define LOCAL_USAGE_MIN   0x1

◆ LOCAL_USAGE_MAX

#define LOCAL_USAGE_MAX   0x2

◆ INPUT_CONSTANT

#define INPUT_CONSTANT   0x01

◆ INPUT_RELATIVE

#define INPUT_RELATIVE   0x04

◆ PAGE_DESKTOP

#define PAGE_DESKTOP   0x01

◆ PAGE_BUTTON

#define PAGE_BUTTON   0x09

◆ USAGE_X

#define USAGE_X   0x30

◆ USAGE_Y

#define USAGE_Y   0x31

◆ USAGE_WHEEL

#define USAGE_WHEEL   0x38

◆ MAX_USAGES

#define MAX_USAGES   16

Function Documentation

◆ hid_parse_pointer()

bool hid_parse_pointer ( const uint8_t * descriptor,
uint32_t length,
hid_pointer_t * out )

find the pointer fields in a report descriptor.

Returns
true if it has an x and a y.

◆ hid_field_value()

int32_t hid_field_value ( const hid_field_t * field,
const uint8_t * report,
uint32_t length )

read a field from a report (the report id byte already skipped).

Parameters
lengththe bytes in the report.
Returns
the value, sign-extended when the field's range is signed.