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
|
#include "hid.h"
static struct zmk_hid_report report = {
.modifiers = 0,
.keys = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
#define KEY_OFFSET 0x02
#define MAX_KEYS 6
/*
#define TOGGLE_BOOT_KEY(match, val) \
for (int idx = 0; idx < MAX_KEYS; idx++) \
{ \
if (report.boot.keys[idx + KEY_OFFSET] != match) \
{ \
continue; \
} \
report.boot.keys[idx + KEY_OFFSET] = val; \
break; \
}
*/
#define TOGGLE_KEY(code, val) WRITE_BIT(report.keys[code / 8], code % 8, val)
int zmk_hid_press_key(zmk_key code)
{
if (code > ZMK_HID_MAX_KEYCODE)
{
return -EINVAL;
}
// TOGGLE_BOOT_KEY(0U, code);
TOGGLE_KEY(code, true);
return 0;
};
int zmk_hid_release_key(zmk_key code)
{
if (code > ZMK_HID_MAX_KEYCODE)
{
return -EINVAL;
}
// TOGGLE_BOOT_KEY(code, 0U);
TOGGLE_KEY(code, false);
return 0;
};
struct zmk_hid_report *zmk_hid_get_report()
{
return &report;
}
|