The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
hid.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file hid.h
5 * @brief a small HID report descriptor parser for pointing devices.
6 *
7 * a USB mouse in the boot protocol sends a fixed report (buttons, x, y);
8 * other pointing devices (QEMU's tablet, graphics tablets, touch screens
9 * in mouse mode) describe their report in a report descriptor. this
10 * parser finds the buttons, x, y and the wheel in it: their bit offset,
11 * size and range, and whether x and y are absolute.
12 */
13
14#include "common/stdint.h"
15
16typedef struct
17{
18 bool present;
19 uint16_t offset; // bit offset in the report (after the report id byte)
20 uint8_t size; // bits
21 int32_t min; // the logical range
24
25typedef struct
26{
27 uint8_t report_id; // the report these fields are in (0: no ids)
28 bool absolute; // x and y are positions, not changes
33 uint8_t buttons; // how many (one bit each)
35
36/**
37 * find the pointer fields in a report descriptor.
38 * @return true if it has an x and a y.
39 */
40bool hid_parse_pointer(const uint8_t *descriptor, uint32_t length, hid_pointer_t *out);
41
42/**
43 * read a field from a report (the report id byte already skipped).
44 * @param length the bytes in the report.
45 * @return the value, sign-extended when the field's range is signed.
46 */
47int32_t hid_field_value(const hid_field_t *field, const uint8_t *report, uint32_t length);
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).
Definition hid.c:246
bool hid_parse_pointer(const uint8_t *descriptor, uint32_t length, hid_pointer_t *out)
find the pointer fields in a report descriptor.
Definition hid.c:66
unsigned int uint32_t
Definition fb.h:17
unsigned char uint8_t
Definition fb.h:18
unsigned short uint16_t
Definition stdint.h:13
int int32_t
Definition stdint.h:14
Definition hid.h:17
uint8_t size
Definition hid.h:20
int32_t max
Definition hid.h:22
int32_t min
Definition hid.h:21
bool present
Definition hid.h:18
uint16_t offset
Definition hid.h:19
Definition hid.h:26
hid_field_t wheel
Definition hid.h:31
hid_field_t y
Definition hid.h:30
bool absolute
Definition hid.h:28
uint8_t buttons
Definition hid.h:33
uint8_t report_id
Definition hid.h:27
hid_field_t x
Definition hid.h:29
uint16_t buttons_offset
Definition hid.h:32