Initial basic modifiers support.
This commit is contained in:
parent
5e34e7fec9
commit
585e062e87
5 changed files with 47 additions and 5 deletions
|
@ -60,13 +60,25 @@
|
||||||
|
|
||||||
#define KC_APP 0x65
|
#define KC_APP 0x65
|
||||||
|
|
||||||
|
#define KC_LCTL 0xE0
|
||||||
|
#define KC_LSFT 0xE1
|
||||||
|
#define KC_LALT 0xE2
|
||||||
|
#define KC_LGUI 0xE3
|
||||||
|
#define KC_RCTL 0xE4
|
||||||
|
#define KC_RSFT 0xE5
|
||||||
|
#define KC_RALT 0xE6
|
||||||
#define KC_RGUI 0xE7
|
#define KC_RGUI 0xE7
|
||||||
|
|
||||||
#define MD_SHFT 0x01
|
|
||||||
#define KC_ALT 0x02
|
|
||||||
#define KC_CTRL 0x03
|
|
||||||
|
|
||||||
#define ZC_TRNS 0xF0
|
#define ZC_TRNS 0xF0
|
||||||
#define ZC_NOOP 0xF1
|
#define ZC_NOOP 0xF1
|
||||||
|
|
||||||
#define ZC_CSTM(n) (0xFF + n)
|
#define ZC_CSTM(n) (0xFF + n)
|
||||||
|
|
||||||
|
#define MOD_LCTL 0x00
|
||||||
|
#define MOD_LSFT 0x01
|
||||||
|
#define MOD_LALT 0x02
|
||||||
|
#define MOD_LGUI 0x03
|
||||||
|
#define MOD_RCTL 0x04
|
||||||
|
#define MOD_RSFT 0x05
|
||||||
|
#define MOD_RALT 0x06
|
||||||
|
#define MOD_RGUI 0x07
|
|
@ -101,6 +101,8 @@ struct zmk_hid_report
|
||||||
u8_t keys[13];
|
u8_t keys[13];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
|
int zmk_hid_register_mod(zmk_mod modifier);
|
||||||
|
int zmk_hid_unregister_mod(zmk_mod modifier);
|
||||||
int zmk_hid_press_key(zmk_key key);
|
int zmk_hid_press_key(zmk_key key);
|
||||||
int zmk_hid_release_key(zmk_key key);
|
int zmk_hid_release_key(zmk_key key);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <dt-bindings/zmk/keys.h>
|
#include <dt-bindings/zmk/keys.h>
|
||||||
|
|
||||||
typedef u64_t zmk_key;
|
typedef u64_t zmk_key;
|
||||||
|
typedef u8_t zmk_mod;
|
||||||
|
|
||||||
struct zmk_key_event
|
struct zmk_key_event
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,6 +33,7 @@ int zmk_endpoints_send_key_event(struct zmk_key_event key_event)
|
||||||
struct zmk_hid_report *report;
|
struct zmk_hid_report *report;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
|
||||||
if (key_event.pressed)
|
if (key_event.pressed)
|
||||||
{
|
{
|
||||||
zmk_hid_press_key(key_event.key);
|
zmk_hid_press_key(key_event.key);
|
||||||
|
|
26
src/hid.c
26
src/hid.c
|
@ -4,6 +4,22 @@ static struct zmk_hid_report report = {
|
||||||
.modifiers = 0,
|
.modifiers = 0,
|
||||||
.keys = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
|
.keys = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
|
||||||
|
|
||||||
|
#define _TOGGLE_MOD(mod, state) \
|
||||||
|
if (modifier > MOD_RGUI) \
|
||||||
|
{ \
|
||||||
|
return -EINVAL; \
|
||||||
|
} \
|
||||||
|
WRITE_BIT(report.modifiers, mod, state);
|
||||||
|
|
||||||
|
int zmk_hid_register_mod(zmk_mod modifier)
|
||||||
|
{
|
||||||
|
_TOGGLE_MOD(modifier, true);
|
||||||
|
}
|
||||||
|
int zmk_hid_unregister_mod(zmk_mod modifier)
|
||||||
|
{
|
||||||
|
_TOGGLE_MOD(modifier, false);
|
||||||
|
}
|
||||||
|
|
||||||
#define KEY_OFFSET 0x02
|
#define KEY_OFFSET 0x02
|
||||||
#define MAX_KEYS 6
|
#define MAX_KEYS 6
|
||||||
|
|
||||||
|
@ -24,6 +40,11 @@ static struct zmk_hid_report report = {
|
||||||
|
|
||||||
int zmk_hid_press_key(zmk_key code)
|
int zmk_hid_press_key(zmk_key code)
|
||||||
{
|
{
|
||||||
|
if (code >= KC_LCTL && code <= KC_RGUI)
|
||||||
|
{
|
||||||
|
return zmk_hid_register_mod(code - KC_LCTL);
|
||||||
|
}
|
||||||
|
|
||||||
if (code > ZMK_HID_MAX_KEYCODE)
|
if (code > ZMK_HID_MAX_KEYCODE)
|
||||||
{
|
{
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -38,6 +59,11 @@ int zmk_hid_press_key(zmk_key code)
|
||||||
|
|
||||||
int zmk_hid_release_key(zmk_key code)
|
int zmk_hid_release_key(zmk_key code)
|
||||||
{
|
{
|
||||||
|
if (code >= KC_LCTL && code <= KC_RGUI)
|
||||||
|
{
|
||||||
|
return zmk_hid_unregister_mod(code - KC_LCTL);
|
||||||
|
}
|
||||||
|
|
||||||
if (code > ZMK_HID_MAX_KEYCODE)
|
if (code > ZMK_HID_MAX_KEYCODE)
|
||||||
{
|
{
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
Loading…
Reference in a new issue