summaryrefslogtreecommitdiff
path: root/app/include/zmk/hid.h
blob: e14a51a0bdae2ba393fe14eee2253a99b945662a (plain)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#pragma once

#include <usb/usb_device.h>
#include <usb/class/usb_hid.h>

#include <dt-bindings/zmk/keys.h>

#include <zmk/keys.h>

#define COLLECTION_REPORT 0x03

#define ZMK_HID_MAX_KEYCODE GUI

static const u8_t zmk_hid_report_desc[] = {
    /* USAGE_PAGE (Generic Desktop) */
    HID_GI_USAGE_PAGE,
    USAGE_GEN_DESKTOP,
    /* USAGE (Keyboard) */
    HID_LI_USAGE,
    USAGE_GEN_DESKTOP_KEYBOARD,
    /* COLLECTION (Application) */
    HID_MI_COLLECTION,
    COLLECTION_APPLICATION,
    /* REPORT ID (1) */
    HID_GI_REPORT_ID,
    0x01,
    /* USAGE_PAGE (Keypad) */
    HID_GI_USAGE_PAGE,
    USAGE_GEN_DESKTOP_KEYPAD,
    /* USAGE_MINIMUM (Keyboard LeftControl) */
    HID_LI_USAGE_MIN(1),
    0xE0,
    /* USAGE_MAXIMUM (Keyboard Right GUI) */
    HID_LI_USAGE_MAX(1),
    0xE7,
    /* LOGICAL_MINIMUM (0) */
    HID_GI_LOGICAL_MIN(1),
    0x00,
    /* LOGICAL_MAXIMUM (1) */
    HID_GI_LOGICAL_MAX(1),
    0x01,

    /* REPORT_SIZE (1) */
    HID_GI_REPORT_SIZE,
    0x01,
    /* REPORT_COUNT (8) */
    HID_GI_REPORT_COUNT,
    0x08,
    /* INPUT (Data,Var,Abs) */
    HID_MI_INPUT,
    0x02,

    /* USAGE_PAGE (Keypad) */
    HID_GI_USAGE_PAGE,
    USAGE_GEN_DESKTOP_KEYPAD,
    /* LOGICAL_MINIMUM (0) */
    HID_GI_LOGICAL_MIN(1),
    0x00,
    /* LOGICAL_MAXIMUM (1) */
    HID_GI_LOGICAL_MAX(1),
    0x01,
    /* USAGE_MINIMUM (Reserved) */
    HID_LI_USAGE_MIN(1),
    0x00,
    /* USAGE_MAXIMUM (Keyboard Application) */
    HID_LI_USAGE_MAX(1),
    ZMK_HID_MAX_KEYCODE,
    /* REPORT_SIZE (8) */
    HID_GI_REPORT_SIZE,
    0x01,
    /* REPORT_COUNT (6) */
    HID_GI_REPORT_COUNT,
    ZMK_HID_MAX_KEYCODE + 1,
    /* INPUT (Data,Ary,Abs) */
    HID_MI_INPUT,
    0x02,
    /* USAGE_PAGE (Keypad) */
    HID_GI_USAGE_PAGE,
    USAGE_GEN_DESKTOP_KEYPAD,
    /* REPORT_SIZE (8) */
    HID_GI_REPORT_SIZE,
    0x02,
    /* REPORT_COUNT (6) */
    HID_GI_REPORT_COUNT,
    0x01,
    /* INPUT (Cnst,Var,Abs) */
    HID_MI_INPUT,
    0x03,
    /* END_COLLECTION */
    HID_MI_COLLECTION_END,
    /* USAGE_PAGE (Consumer) */
    HID_GI_USAGE_PAGE,
    0x0C,
    /* USAGE (Consumer Control) */
    HID_LI_USAGE,
    0x01,
    /* Consumer Page */
    HID_MI_COLLECTION,
    COLLECTION_APPLICATION,
    /* REPORT ID (1) */
    HID_GI_REPORT_ID,
    0x02,
    /* USAGE_PAGE (Consumer) */
    HID_GI_USAGE_PAGE,
    0x0C,
    /* LOGICAL_MINIMUM (0) */
    HID_GI_LOGICAL_MIN(1),
    0x00,
    /* LOGICAL_MAXIMUM (1) */
    HID_GI_LOGICAL_MAX(1),
    0x01,
    /* USAGE (Scan Next Track) */
    HID_LI_USAGE,
    0xB5,
    /* USAGE (Scan Previous Track) */
    HID_LI_USAGE,
    0xB6,
    /* USAGE (Stop) */
    HID_LI_USAGE,
    0xB7,
    /* USAGE (Eject) */
    HID_LI_USAGE,
    0xB8,
    /* USAGE (Media Play/Pause) */
    HID_LI_USAGE,
    0xCD,
    /* USAGE (Mute) */
    HID_LI_USAGE,
    0xE2,
    /* USAGE (Volume Increment) */
    HID_LI_USAGE,
    0xE9,
    /* USAGE (Volume Decrement) */
    HID_LI_USAGE,
    0xEA,
    /* INPUT (Data,Ary,Abs) */
    /* REPORT_SIZE (1) */
    HID_GI_REPORT_SIZE,
    0x01,
    /* REPORT_COUNT (8) */
    HID_GI_REPORT_COUNT,
    0x08,
    HID_MI_INPUT,
    0x02,
    /* END COLLECTION */
    HID_MI_COLLECTION_END,
};

// struct zmk_hid_boot_report
// {
//     u8_t modifiers;
//     u8_t _unused;
//     u8_t keys[6];
// } __packed;

struct zmk_hid_keypad_report_body
{
    zmk_mod_flags modifiers;
    u8_t keys[13];
} __packed;

struct zmk_hid_keypad_report
{
    u8_t report_id;
    struct zmk_hid_keypad_report_body body;
} __packed;

struct zmk_hid_consumer_report_body
{
    u8_t keys;
} __packed;

struct zmk_hid_consumer_report
{
    u8_t report_id;
    struct zmk_hid_consumer_report_body body;
} __packed;

enum zmk_hid_report_changes
{
    None = 0x00,
    Keypad = (0x01 << 0x00),
    Consumer = (0x01 << 0x01)
};

int zmk_hid_register_mod(zmk_mod modifier);
int zmk_hid_unregister_mod(zmk_mod modifier);
int zmk_hid_register_mods(zmk_mod_flags modifiers);
int zmk_hid_unregister_mods(zmk_mod_flags modifiers);
enum zmk_hid_report_changes zmk_hid_press_key(zmk_key key);
enum zmk_hid_report_changes zmk_hid_release_key(zmk_key key);

struct zmk_hid_keypad_report *zmk_hid_get_keypad_report();
struct zmk_hid_consumer_report *zmk_hid_get_consumer_report();