2020-09-10 13:57:44 +10:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 The ZMK Contributors
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*/
|
|
|
|
|
2020-05-15 23:41:06 +10:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <usb/usb_device.h>
|
|
|
|
#include <usb/class/usb_hid.h>
|
|
|
|
|
2020-05-18 23:11:46 +10:00
|
|
|
#include <zmk/keys.h>
|
2020-11-04 03:55:34 +11:00
|
|
|
#include <dt-bindings/zmk/hid_usage.h>
|
|
|
|
#include <dt-bindings/zmk/hid_usage_pages.h>
|
2020-05-15 23:41:06 +10:00
|
|
|
|
2021-03-15 15:40:09 +11:00
|
|
|
#define ZMK_HID_KEYBOARD_NKRO_MAX_USAGE HID_USAGE_KEY_KEYPAD_EQUAL
|
2020-05-15 23:41:06 +10:00
|
|
|
|
2021-03-15 15:40:09 +11:00
|
|
|
#define COLLECTION_REPORT 0x03
|
2020-10-28 05:42:41 +11:00
|
|
|
|
2020-12-03 03:41:57 +11:00
|
|
|
static const uint8_t zmk_hid_report_desc[] = {
|
2021-11-05 15:14:44 +11:00
|
|
|
HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP),
|
|
|
|
HID_USAGE(HID_USAGE_GD_KEYBOARD),
|
|
|
|
HID_COLLECTION(HID_COLLECTION_APPLICATION),
|
|
|
|
HID_REPORT_ID(0x01),
|
|
|
|
HID_USAGE_PAGE(HID_USAGE_KEY),
|
|
|
|
HID_USAGE_MIN8(HID_USAGE_KEY_KEYBOARD_LEFTCONTROL),
|
|
|
|
HID_USAGE_MAX8(HID_USAGE_KEY_KEYBOARD_RIGHT_GUI),
|
|
|
|
HID_LOGICAL_MIN8(0x00),
|
|
|
|
HID_LOGICAL_MAX8(0x01),
|
|
|
|
|
|
|
|
HID_REPORT_SIZE(0x01),
|
|
|
|
HID_REPORT_COUNT(0x08),
|
2020-05-15 23:41:06 +10:00
|
|
|
/* INPUT (Data,Var,Abs) */
|
2021-11-05 15:14:44 +11:00
|
|
|
HID_INPUT(0x02),
|
|
|
|
|
|
|
|
HID_USAGE_PAGE(HID_USAGE_KEY),
|
|
|
|
HID_REPORT_SIZE(0x08),
|
|
|
|
HID_REPORT_COUNT(0x01),
|
2020-10-28 04:42:00 +11:00
|
|
|
/* INPUT (Cnst,Var,Abs) */
|
2021-11-05 15:14:44 +11:00
|
|
|
HID_INPUT(0x03),
|
2020-10-28 04:42:00 +11:00
|
|
|
|
2021-11-05 15:14:44 +11:00
|
|
|
HID_USAGE_PAGE(HID_USAGE_KEY),
|
2021-03-15 15:40:09 +11:00
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_NKRO)
|
2021-11-05 15:14:44 +11:00
|
|
|
HID_LOGICAL_MIN8(0x00),
|
|
|
|
HID_LOGICAL_MAX8(0x01),
|
|
|
|
HID_USAGE_MIN8(0x00),
|
|
|
|
HID_USAGE_MAX8(ZMK_HID_KEYBOARD_NKRO_MAX_USAGE),
|
|
|
|
HID_REPORT_SIZE(0x01),
|
|
|
|
HID_REPORT_COUNT(ZMK_HID_KEYBOARD_NKRO_MAX_USAGE + 1),
|
2021-03-15 15:40:09 +11:00
|
|
|
/* INPUT (Data,Ary,Abs) */
|
2021-11-05 15:14:44 +11:00
|
|
|
HID_INPUT(0x02),
|
2021-03-15 15:40:09 +11:00
|
|
|
#elif IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_HKRO)
|
2021-11-05 15:14:44 +11:00
|
|
|
HID_LOGICAL_MIN8(0x00),
|
2022-11-05 07:47:16 +11:00
|
|
|
HID_LOGICAL_MAX16(0xFF, 0x00),
|
2021-11-05 15:14:44 +11:00
|
|
|
HID_USAGE_MIN8(0x00),
|
|
|
|
HID_USAGE_MAX8(0xFF),
|
|
|
|
HID_REPORT_SIZE(0x08),
|
|
|
|
HID_REPORT_COUNT(CONFIG_ZMK_HID_KEYBOARD_REPORT_SIZE),
|
2020-05-15 23:41:06 +10:00
|
|
|
/* INPUT (Data,Ary,Abs) */
|
2021-11-05 15:14:44 +11:00
|
|
|
HID_INPUT(0x00),
|
2021-03-15 15:40:09 +11:00
|
|
|
#else
|
|
|
|
#error "A proper HID report type must be selected"
|
|
|
|
#endif
|
2020-10-28 09:35:44 +11:00
|
|
|
|
2021-11-05 15:14:44 +11:00
|
|
|
HID_END_COLLECTION,
|
|
|
|
HID_USAGE_PAGE(HID_USAGE_CONSUMER),
|
|
|
|
HID_USAGE(HID_USAGE_CONSUMER_CONSUMER_CONTROL),
|
|
|
|
HID_COLLECTION(HID_COLLECTION_APPLICATION),
|
|
|
|
HID_REPORT_ID(0x02),
|
|
|
|
HID_USAGE_PAGE(HID_USAGE_CONSUMER),
|
2021-10-05 13:41:56 +11:00
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_BASIC)
|
2021-11-05 15:14:44 +11:00
|
|
|
HID_LOGICAL_MIN8(0x00),
|
|
|
|
HID_LOGICAL_MAX16(0xFF, 0x00),
|
|
|
|
HID_USAGE_MIN8(0x00),
|
|
|
|
HID_USAGE_MAX8(0xFF),
|
|
|
|
HID_REPORT_SIZE(0x08),
|
2021-10-05 13:41:56 +11:00
|
|
|
#elif IS_ENABLED(CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_FULL)
|
2021-11-05 15:14:44 +11:00
|
|
|
HID_LOGICAL_MIN8(0x00),
|
2022-04-08 02:24:25 +10:00
|
|
|
HID_LOGICAL_MAX16(0xFF, 0x0F),
|
2021-11-05 15:14:44 +11:00
|
|
|
HID_USAGE_MIN8(0x00),
|
2022-04-08 02:24:25 +10:00
|
|
|
HID_USAGE_MAX16(0xFF, 0x0F),
|
2021-11-05 15:14:44 +11:00
|
|
|
HID_REPORT_SIZE(0x10),
|
2021-10-05 13:41:56 +11:00
|
|
|
#else
|
|
|
|
#error "A proper consumer HID report usage range must be selected"
|
|
|
|
#endif
|
2021-11-05 15:14:44 +11:00
|
|
|
HID_REPORT_COUNT(CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE),
|
|
|
|
/* INPUT (Data,Ary,Abs) */
|
|
|
|
HID_INPUT(0x00),
|
|
|
|
HID_END_COLLECTION,
|
2020-05-15 23:41:06 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
// struct zmk_hid_boot_report
|
|
|
|
// {
|
2020-12-03 03:41:57 +11:00
|
|
|
// uint8_t modifiers;
|
|
|
|
// uint8_t _unused;
|
|
|
|
// uint8_t keys[6];
|
2020-05-15 23:41:06 +10:00
|
|
|
// } __packed;
|
|
|
|
|
2020-11-22 07:09:21 +11:00
|
|
|
struct zmk_hid_keyboard_report_body {
|
2020-12-20 04:33:15 +11:00
|
|
|
zmk_mod_flags_t modifiers;
|
2020-12-03 03:41:57 +11:00
|
|
|
uint8_t _reserved;
|
2021-03-15 15:40:09 +11:00
|
|
|
#if IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_NKRO)
|
|
|
|
uint8_t keys[(ZMK_HID_KEYBOARD_NKRO_MAX_USAGE + 1) / 8];
|
|
|
|
#elif IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_HKRO)
|
|
|
|
uint8_t keys[CONFIG_ZMK_HID_KEYBOARD_REPORT_SIZE];
|
|
|
|
#endif
|
2020-05-15 23:41:06 +10:00
|
|
|
} __packed;
|
|
|
|
|
2020-11-22 07:09:21 +11:00
|
|
|
struct zmk_hid_keyboard_report {
|
2020-12-03 03:41:57 +11:00
|
|
|
uint8_t report_id;
|
2020-11-22 07:09:21 +11:00
|
|
|
struct zmk_hid_keyboard_report_body body;
|
2020-06-03 01:23:22 +10:00
|
|
|
} __packed;
|
|
|
|
|
2020-09-14 12:53:24 +10:00
|
|
|
struct zmk_hid_consumer_report_body {
|
2021-10-05 13:41:56 +11:00
|
|
|
#if IS_ENABLED(CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_BASIC)
|
|
|
|
uint8_t keys[CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE];
|
|
|
|
#elif IS_ENABLED(CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_FULL)
|
2021-03-15 15:40:09 +11:00
|
|
|
uint16_t keys[CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE];
|
2021-10-05 13:41:56 +11:00
|
|
|
#endif
|
2020-06-03 01:23:22 +10:00
|
|
|
} __packed;
|
|
|
|
|
2020-09-14 12:53:24 +10:00
|
|
|
struct zmk_hid_consumer_report {
|
2020-12-03 03:41:57 +11:00
|
|
|
uint8_t report_id;
|
2020-06-03 01:23:22 +10:00
|
|
|
struct zmk_hid_consumer_report_body body;
|
|
|
|
} __packed;
|
|
|
|
|
2020-12-27 00:46:56 +11:00
|
|
|
zmk_mod_flags_t zmk_hid_get_explicit_mods();
|
2020-12-20 04:32:40 +11:00
|
|
|
int zmk_hid_register_mod(zmk_mod_t modifier);
|
|
|
|
int zmk_hid_unregister_mod(zmk_mod_t modifier);
|
2022-04-30 04:31:21 +10:00
|
|
|
bool zmk_hid_mod_is_pressed(zmk_mod_t modifier);
|
|
|
|
|
2021-01-23 03:00:19 +11:00
|
|
|
int zmk_hid_register_mods(zmk_mod_flags_t explicit_modifiers);
|
|
|
|
int zmk_hid_unregister_mods(zmk_mod_flags_t explicit_modifiers);
|
2020-12-20 04:33:15 +11:00
|
|
|
int zmk_hid_implicit_modifiers_press(zmk_mod_flags_t implicit_modifiers);
|
2020-09-03 06:30:09 +10:00
|
|
|
int zmk_hid_implicit_modifiers_release();
|
2022-10-15 12:40:28 +11:00
|
|
|
int zmk_hid_masked_modifiers_set(zmk_mod_flags_t masked_modifiers);
|
|
|
|
int zmk_hid_masked_modifiers_clear();
|
2021-03-15 07:39:31 +11:00
|
|
|
|
2020-12-20 04:32:02 +11:00
|
|
|
int zmk_hid_keyboard_press(zmk_key_t key);
|
|
|
|
int zmk_hid_keyboard_release(zmk_key_t key);
|
2020-11-22 07:09:21 +11:00
|
|
|
void zmk_hid_keyboard_clear();
|
2022-04-30 04:31:21 +10:00
|
|
|
bool zmk_hid_keyboard_is_pressed(zmk_key_t key);
|
2020-06-23 01:06:01 +10:00
|
|
|
|
2020-12-20 04:32:02 +11:00
|
|
|
int zmk_hid_consumer_press(zmk_key_t key);
|
|
|
|
int zmk_hid_consumer_release(zmk_key_t key);
|
2020-10-12 10:38:39 +11:00
|
|
|
void zmk_hid_consumer_clear();
|
2022-04-30 04:31:21 +10:00
|
|
|
bool zmk_hid_consumer_is_pressed(zmk_key_t key);
|
2020-05-15 23:41:06 +10:00
|
|
|
|
2021-03-15 07:39:31 +11:00
|
|
|
int zmk_hid_press(uint32_t usage);
|
|
|
|
int zmk_hid_release(uint32_t usage);
|
2022-04-30 04:31:21 +10:00
|
|
|
bool zmk_hid_is_pressed(uint32_t usage);
|
2021-03-15 07:39:31 +11:00
|
|
|
|
2020-11-22 07:09:21 +11:00
|
|
|
struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report();
|
2020-06-03 01:23:22 +10:00
|
|
|
struct zmk_hid_consumer_report *zmk_hid_get_consumer_report();
|