2020-07-01 06:13:03 +10:00
|
|
|
/*
|
2020-09-10 13:57:44 +10:00
|
|
|
* Copyright (c) 2020 The ZMK Contributors
|
2020-07-01 06:13:03 +10:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*/
|
2020-07-26 13:17:33 +10:00
|
|
|
|
2020-06-30 14:31:09 +10:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <zephyr.h>
|
2020-12-23 02:56:00 +11:00
|
|
|
#include <zmk/event_manager.h>
|
2020-10-26 15:30:24 +11:00
|
|
|
#include <zmk/keys.h>
|
2020-06-30 14:31:09 +10:00
|
|
|
|
2021-01-18 16:35:56 +11:00
|
|
|
struct zmk_keycode_state_changed {
|
2020-12-18 06:36:19 +11:00
|
|
|
uint16_t usage_page;
|
2020-12-03 03:41:57 +11:00
|
|
|
uint32_t keycode;
|
|
|
|
uint8_t implicit_modifiers;
|
2021-01-23 03:00:19 +11:00
|
|
|
uint8_t explicit_modifiers;
|
2020-06-30 14:31:09 +10:00
|
|
|
bool state;
|
2020-12-03 03:41:57 +11:00
|
|
|
int64_t timestamp;
|
2020-06-30 14:31:09 +10:00
|
|
|
};
|
|
|
|
|
2021-01-18 16:35:56 +11:00
|
|
|
ZMK_EVENT_DECLARE(zmk_keycode_state_changed);
|
2020-07-01 00:43:09 +10:00
|
|
|
|
2021-01-18 16:35:56 +11:00
|
|
|
static inline struct zmk_keycode_state_changed_event *
|
|
|
|
zmk_keycode_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t timestamp) {
|
2020-12-03 03:41:57 +11:00
|
|
|
uint16_t page = HID_USAGE_PAGE(encoded) & 0xFF;
|
|
|
|
uint16_t id = HID_USAGE_ID(encoded);
|
2021-01-23 03:00:19 +11:00
|
|
|
uint8_t implicit_modifiers = 0x00;
|
|
|
|
uint8_t explicit_modifiers = 0x00;
|
2020-10-26 15:30:24 +11:00
|
|
|
|
|
|
|
if (!page) {
|
|
|
|
page = HID_USAGE_KEY;
|
|
|
|
}
|
|
|
|
|
2021-01-23 03:00:19 +11:00
|
|
|
if (is_mod(page, id)) {
|
|
|
|
explicit_modifiers = SELECT_MODS(encoded);
|
|
|
|
} else {
|
|
|
|
implicit_modifiers = SELECT_MODS(encoded);
|
|
|
|
}
|
|
|
|
|
2021-01-18 16:35:56 +11:00
|
|
|
return new_zmk_keycode_state_changed(
|
|
|
|
(struct zmk_keycode_state_changed){.usage_page = page,
|
|
|
|
.keycode = id,
|
2021-01-23 03:00:19 +11:00
|
|
|
.implicit_modifiers = implicit_modifiers,
|
|
|
|
.explicit_modifiers = explicit_modifiers,
|
2021-01-18 16:35:56 +11:00
|
|
|
.state = pressed,
|
|
|
|
.timestamp = timestamp});
|
2020-09-03 06:30:09 +10:00
|
|
|
}
|