-
Notifications
You must be signed in to change notification settings - Fork 9
/
ibp_lib.h
74 lines (63 loc) · 1.87 KB
/
ibp_lib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef IBP_LIB_H_
#define IBP_LIB_H_
#ifdef IBP_KERNEL_MODULE
#include <linux/types.h>
#else
#include <stdbool.h>
#include <stdint.h>
#endif
#define IBP_MAX_PACKET_LEN 128
#define IBP_MAX_KEYCODES 8
#define IBP_MAX_ACTIVELAYERS 8
#define IBP_INVALID_PACKET_DELAY_MS 1
typedef enum {
IBP_KEYCODE = 0,
IBP_CONSUMER,
IBP_MOUSE,
IBP_ACTIVE_LAYERS,
IBP_TOTAL,
} FieldType;
typedef struct {
uint8_t modifier_bitmask; // Same as the USB HID.
uint8_t num_keycodes : 3;
uint8_t keycodes[IBP_MAX_KEYCODES];
} IBPKeyCodes;
typedef struct {
uint16_t consumer_keycode;
} IBPConsumer;
typedef struct {
// For buttons.
// 7 0
// +------+------+------+------+------+------+------+------+
// | Reserved |FRWARD| BACK |MSE_M |MSE_R |MSE_L |
// +------+------+------+------+------+------+------+------+
uint8_t button_bitmask;
int8_t x;
int8_t y;
int8_t vertical;
int8_t horizontal;
} IBPMouse;
typedef struct {
uint8_t num_activated_layers : 3;
uint8_t active_layers[IBP_MAX_ACTIVELAYERS];
} IBPLayers;
typedef union {
IBPKeyCodes keycodes;
IBPConsumer consumer_keycode;
IBPMouse mouse;
IBPLayers layers;
} FieldData;
typedef struct {
// 7 0
// +------+------+------+------+------+------+------+------+
// | number of data bytes | field type |parity|
// +------+------+------+------+------+------+------+------+
FieldType field_type : 3;
FieldData field_data;
} IBPSegment;
int8_t SerializeSegments(const IBPSegment* segments, uint8_t num_segments,
uint8_t* output, uint8_t buffer_size);
int8_t DeSerializeSegment(const uint8_t* input, uint8_t input_buffer_size,
IBPSegment* segment);
int8_t GetTransactionTotalSize(uint8_t transaction_first_byte);
#endif /* IBP_LIB_H_ */