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-11-03 16:21:20 +11:00
|
|
|
#include <dt-bindings/zmk/modifiers.h>
|
2020-10-26 15:30:24 +11:00
|
|
|
#include <dt-bindings/zmk/hid_usage_pages.h>
|
2020-06-30 14:31:09 +10: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
|
|
|
|
|
|
|
struct keycode_state_changed {
|
|
|
|
struct zmk_event_header header;
|
2020-12-03 03:41:57 +11:00
|
|
|
uint8_t usage_page;
|
|
|
|
uint32_t keycode;
|
|
|
|
uint8_t implicit_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
|
|
|
};
|
|
|
|
|
2020-07-01 00:43:09 +10:00
|
|
|
ZMK_EVENT_DECLARE(keycode_state_changed);
|
|
|
|
|
2020-11-12 08:06:25 +11:00
|
|
|
static inline struct keycode_state_changed *
|
2020-12-03 03:41:57 +11:00
|
|
|
keycode_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t timestamp) {
|
|
|
|
uint16_t page = HID_USAGE_PAGE(encoded) & 0xFF;
|
|
|
|
uint16_t id = HID_USAGE_ID(encoded);
|
2020-10-26 15:30:24 +11:00
|
|
|
zmk_mod_flags implicit_mods = SELECT_MODS(encoded);
|
|
|
|
|
|
|
|
if (!page) {
|
|
|
|
page = HID_USAGE_KEY;
|
|
|
|
}
|
|
|
|
|
2020-09-14 12:53:24 +10:00
|
|
|
struct keycode_state_changed *ev = new_keycode_state_changed();
|
2020-10-26 15:30:24 +11:00
|
|
|
ev->usage_page = page;
|
|
|
|
ev->keycode = id;
|
|
|
|
ev->implicit_modifiers = implicit_mods;
|
|
|
|
ev->state = pressed;
|
2020-11-12 08:06:25 +11:00
|
|
|
ev->timestamp = timestamp;
|
2020-07-01 00:43:09 +10:00
|
|
|
return ev;
|
2020-09-03 06:30:09 +10:00
|
|
|
}
|