The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
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
16
typedef
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
22
int32_t
max
;
23
}
hid_field_t
;
24
25
typedef
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
29
hid_field_t
x
;
30
hid_field_t
y
;
31
hid_field_t
wheel
;
32
uint16_t
buttons_offset
;
33
uint8_t
buttons
;
// how many (one bit each)
34
}
hid_pointer_t
;
35
36
/**
37
* find the pointer fields in a report descriptor.
38
* @return true if it has an x and a y.
39
*/
40
bool
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
*/
47
int32_t
hid_field_value
(
const
hid_field_t
*field,
const
uint8_t
*report,
uint32_t
length);
stdint.h
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).
Definition
hid.c:246
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.
Definition
hid.c:66
uint32_t
unsigned int uint32_t
Definition
fb.h:17
uint8_t
unsigned char uint8_t
Definition
fb.h:18
uint16_t
unsigned short uint16_t
Definition
stdint.h:13
int32_t
int int32_t
Definition
stdint.h:14
hid_field_t
Definition
hid.h:17
hid_field_t::size
uint8_t size
Definition
hid.h:20
hid_field_t::max
int32_t max
Definition
hid.h:22
hid_field_t::min
int32_t min
Definition
hid.h:21
hid_field_t::present
bool present
Definition
hid.h:18
hid_field_t::offset
uint16_t offset
Definition
hid.h:19
hid_pointer_t
Definition
hid.h:26
hid_pointer_t::wheel
hid_field_t wheel
Definition
hid.h:31
hid_pointer_t::y
hid_field_t y
Definition
hid.h:30
hid_pointer_t::absolute
bool absolute
Definition
hid.h:28
hid_pointer_t::buttons
uint8_t buttons
Definition
hid.h:33
hid_pointer_t::report_id
uint8_t report_id
Definition
hid.h:27
hid_pointer_t::x
hid_field_t x
Definition
hid.h:29
hid_pointer_t::buttons_offset
uint16_t buttons_offset
Definition
hid.h:32
src
drivers
usb
hid.h
Generated by
1.18.0