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
|
|
|
|
2020-06-03 01:23:22 +10:00
|
|
|
#define COLLECTION_REPORT 0x03
|
|
|
|
|
2020-10-28 09:35:44 +11:00
|
|
|
#define ZMK_HID_KEYPAD_NKRO_SIZE 6
|
2020-05-15 23:41:06 +10:00
|
|
|
|
2020-10-28 05:42:41 +11:00
|
|
|
#define ZMK_HID_CONSUMER_NKRO_SIZE 6
|
|
|
|
|
2020-05-15 23:41:06 +10:00
|
|
|
static const u8_t zmk_hid_report_desc[] = {
|
|
|
|
/* USAGE_PAGE (Generic Desktop) */
|
|
|
|
HID_GI_USAGE_PAGE,
|
2020-11-04 03:55:34 +11:00
|
|
|
HID_USAGE_GD,
|
2020-05-15 23:41:06 +10:00
|
|
|
/* USAGE (Keyboard) */
|
|
|
|
HID_LI_USAGE,
|
2020-11-04 03:55:34 +11:00
|
|
|
HID_USAGE_GD_KEYBOARD,
|
2020-05-15 23:41:06 +10:00
|
|
|
/* COLLECTION (Application) */
|
|
|
|
HID_MI_COLLECTION,
|
|
|
|
COLLECTION_APPLICATION,
|
|
|
|
/* REPORT ID (1) */
|
|
|
|
HID_GI_REPORT_ID,
|
|
|
|
0x01,
|
2020-11-04 03:55:34 +11:00
|
|
|
/* USAGE_PAGE (Keyboard/Keypad) */
|
2020-05-15 23:41:06 +10:00
|
|
|
HID_GI_USAGE_PAGE,
|
2020-11-04 03:55:34 +11:00
|
|
|
HID_USAGE_KEY,
|
2020-05-15 23:41:06 +10:00
|
|
|
/* USAGE_MINIMUM (Keyboard LeftControl) */
|
|
|
|
HID_LI_USAGE_MIN(1),
|
2020-11-10 21:28:06 +11:00
|
|
|
HID_USAGE_KEY_KEYBOARD_LEFTCONTROL,
|
2020-05-15 23:41:06 +10:00
|
|
|
/* USAGE_MAXIMUM (Keyboard Right GUI) */
|
|
|
|
HID_LI_USAGE_MAX(1),
|
2020-11-10 21:28:06 +11:00
|
|
|
HID_USAGE_KEY_KEYBOARD_RIGHT_GUI,
|
2020-05-15 23:41:06 +10:00
|
|
|
/* LOGICAL_MINIMUM (0) */
|
|
|
|
HID_GI_LOGICAL_MIN(1),
|
|
|
|
0x00,
|
|
|
|
/* LOGICAL_MAXIMUM (1) */
|
|
|
|
HID_GI_LOGICAL_MAX(1),
|
|
|
|
0x01,
|
|
|
|
|
|
|
|
/* REPORT_SIZE (1) */
|
|
|
|
HID_GI_REPORT_SIZE,
|
|
|
|
0x01,
|
|
|
|
/* REPORT_COUNT (8) */
|
|
|
|
HID_GI_REPORT_COUNT,
|
|
|
|
0x08,
|
|
|
|
/* INPUT (Data,Var,Abs) */
|
|
|
|
HID_MI_INPUT,
|
|
|
|
0x02,
|
|
|
|
|
2020-11-04 03:55:34 +11:00
|
|
|
/* USAGE_PAGE (Keyboard/Keypad) */
|
2020-10-28 04:42:00 +11:00
|
|
|
HID_GI_USAGE_PAGE,
|
2020-11-04 03:55:34 +11:00
|
|
|
HID_USAGE_KEY,
|
2020-10-28 04:42:00 +11:00
|
|
|
/* REPORT_SIZE (8) */
|
|
|
|
HID_GI_REPORT_SIZE,
|
|
|
|
0x08,
|
|
|
|
/* REPORT_COUNT (1) */
|
|
|
|
HID_GI_REPORT_COUNT,
|
|
|
|
0x01,
|
|
|
|
/* INPUT (Cnst,Var,Abs) */
|
|
|
|
HID_MI_INPUT,
|
|
|
|
0x03,
|
|
|
|
|
2020-11-04 03:55:34 +11:00
|
|
|
/* USAGE_PAGE (Keyboard/Keypad) */
|
2020-05-15 23:41:06 +10:00
|
|
|
HID_GI_USAGE_PAGE,
|
2020-11-04 03:55:34 +11:00
|
|
|
HID_USAGE_KEY,
|
2020-05-15 23:41:06 +10:00
|
|
|
/* LOGICAL_MINIMUM (0) */
|
|
|
|
HID_GI_LOGICAL_MIN(1),
|
|
|
|
0x00,
|
2020-10-28 09:35:44 +11:00
|
|
|
/* LOGICAL_MAXIMUM (0xFF) */
|
2020-05-15 23:41:06 +10:00
|
|
|
HID_GI_LOGICAL_MAX(1),
|
2020-10-28 09:35:44 +11:00
|
|
|
0xFF,
|
2020-05-15 23:41:06 +10:00
|
|
|
/* USAGE_MINIMUM (Reserved) */
|
|
|
|
HID_LI_USAGE_MIN(1),
|
|
|
|
0x00,
|
|
|
|
/* USAGE_MAXIMUM (Keyboard Application) */
|
|
|
|
HID_LI_USAGE_MAX(1),
|
2020-10-28 09:35:44 +11:00
|
|
|
0xFF,
|
|
|
|
/* REPORT_SIZE (1) */
|
2020-05-15 23:41:06 +10:00
|
|
|
HID_GI_REPORT_SIZE,
|
2020-10-28 09:35:44 +11:00
|
|
|
0x08,
|
|
|
|
/* REPORT_COUNT (ZMK_HID_KEYPAD_NKRO_SIZE) */
|
2020-05-15 23:41:06 +10:00
|
|
|
HID_GI_REPORT_COUNT,
|
2020-10-28 09:35:44 +11:00
|
|
|
ZMK_HID_KEYPAD_NKRO_SIZE,
|
2020-05-15 23:41:06 +10:00
|
|
|
/* INPUT (Data,Ary,Abs) */
|
|
|
|
HID_MI_INPUT,
|
2020-10-28 09:35:44 +11:00
|
|
|
0x00,
|
|
|
|
|
2020-05-15 23:41:06 +10:00
|
|
|
/* END_COLLECTION */
|
|
|
|
HID_MI_COLLECTION_END,
|
2020-06-03 01:23:22 +10:00
|
|
|
/* USAGE_PAGE (Consumer) */
|
|
|
|
HID_GI_USAGE_PAGE,
|
2020-11-04 03:55:34 +11:00
|
|
|
HID_USAGE_CONSUMER,
|
2020-06-03 01:23:22 +10:00
|
|
|
/* USAGE (Consumer Control) */
|
|
|
|
HID_LI_USAGE,
|
2020-11-07 00:32:42 +11:00
|
|
|
HID_USAGE_CONSUMER_CONSUMER_CONTROL,
|
2020-06-03 01:23:22 +10:00
|
|
|
/* Consumer Page */
|
|
|
|
HID_MI_COLLECTION,
|
|
|
|
COLLECTION_APPLICATION,
|
|
|
|
/* REPORT ID (1) */
|
|
|
|
HID_GI_REPORT_ID,
|
|
|
|
0x02,
|
|
|
|
/* USAGE_PAGE (Consumer) */
|
|
|
|
HID_GI_USAGE_PAGE,
|
2020-11-04 03:55:34 +11:00
|
|
|
HID_USAGE_CONSUMER,
|
2020-06-03 01:23:22 +10:00
|
|
|
/* LOGICAL_MINIMUM (0) */
|
|
|
|
HID_GI_LOGICAL_MIN(1),
|
|
|
|
0x00,
|
2020-10-28 04:38:49 +11:00
|
|
|
/* LOGICAL_MAXIMUM (0xFFFF) */
|
|
|
|
HID_GI_LOGICAL_MAX(2),
|
|
|
|
0xFF,
|
2020-06-23 01:06:01 +10:00
|
|
|
0xFF,
|
|
|
|
HID_LI_USAGE_MIN(1),
|
|
|
|
0x00,
|
2020-10-28 04:38:49 +11:00
|
|
|
/* USAGE_MAXIMUM (0xFFFF) */
|
|
|
|
HID_LI_USAGE_MAX(2),
|
|
|
|
0xFF,
|
2020-06-23 01:06:01 +10:00
|
|
|
0xFF,
|
2020-06-03 01:23:22 +10:00
|
|
|
/* INPUT (Data,Ary,Abs) */
|
2020-10-28 04:38:49 +11:00
|
|
|
/* REPORT_SIZE (16) */
|
2020-06-03 01:23:22 +10:00
|
|
|
HID_GI_REPORT_SIZE,
|
2020-10-28 04:38:49 +11:00
|
|
|
0x10,
|
2020-10-28 05:42:41 +11:00
|
|
|
/* REPORT_COUNT (ZMK_HID_CONSUMER_NKRO_SIZE) */
|
2020-06-03 01:23:22 +10:00
|
|
|
HID_GI_REPORT_COUNT,
|
2020-10-28 05:42:41 +11:00
|
|
|
ZMK_HID_CONSUMER_NKRO_SIZE,
|
2020-06-03 01:23:22 +10:00
|
|
|
HID_MI_INPUT,
|
2020-06-23 01:06:01 +10:00
|
|
|
0x00,
|
2020-06-03 01:23:22 +10:00
|
|
|
/* END COLLECTION */
|
|
|
|
HID_MI_COLLECTION_END,
|
2020-05-15 23:41:06 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
// struct zmk_hid_boot_report
|
|
|
|
// {
|
|
|
|
// u8_t modifiers;
|
|
|
|
// u8_t _unused;
|
|
|
|
// u8_t keys[6];
|
|
|
|
// } __packed;
|
|
|
|
|
2020-09-14 12:53:24 +10:00
|
|
|
struct zmk_hid_keypad_report_body {
|
2020-05-23 12:47:03 +10:00
|
|
|
zmk_mod_flags modifiers;
|
2020-10-28 04:42:00 +11:00
|
|
|
u8_t _reserved;
|
2020-10-28 09:35:44 +11:00
|
|
|
u8_t keys[ZMK_HID_KEYPAD_NKRO_SIZE];
|
2020-05-15 23:41:06 +10:00
|
|
|
} __packed;
|
|
|
|
|
2020-09-14 12:53:24 +10:00
|
|
|
struct zmk_hid_keypad_report {
|
2020-06-03 01:23:22 +10:00
|
|
|
u8_t report_id;
|
|
|
|
struct zmk_hid_keypad_report_body body;
|
|
|
|
} __packed;
|
|
|
|
|
2020-09-14 12:53:24 +10:00
|
|
|
struct zmk_hid_consumer_report_body {
|
2020-10-28 04:38:49 +11:00
|
|
|
u16_t keys[ZMK_HID_CONSUMER_NKRO_SIZE];
|
2020-06-03 01:23:22 +10:00
|
|
|
} __packed;
|
|
|
|
|
2020-09-14 12:53:24 +10:00
|
|
|
struct zmk_hid_consumer_report {
|
2020-06-03 01:23:22 +10:00
|
|
|
u8_t report_id;
|
|
|
|
struct zmk_hid_consumer_report_body body;
|
|
|
|
} __packed;
|
|
|
|
|
2020-05-19 13:34:36 +10:00
|
|
|
int zmk_hid_register_mod(zmk_mod modifier);
|
|
|
|
int zmk_hid_unregister_mod(zmk_mod modifier);
|
2020-09-03 06:30:09 +10:00
|
|
|
int zmk_hid_implicit_modifiers_press(zmk_mod_flags implicit_modifiers);
|
|
|
|
int zmk_hid_implicit_modifiers_release();
|
2020-06-23 01:06:01 +10:00
|
|
|
int zmk_hid_keypad_press(zmk_key key);
|
|
|
|
int zmk_hid_keypad_release(zmk_key key);
|
2020-10-12 10:38:39 +11:00
|
|
|
void zmk_hid_keypad_clear();
|
2020-06-23 01:06:01 +10:00
|
|
|
|
|
|
|
int zmk_hid_consumer_press(zmk_key key);
|
|
|
|
int zmk_hid_consumer_release(zmk_key key);
|
2020-10-12 10:38:39 +11:00
|
|
|
void zmk_hid_consumer_clear();
|
2020-05-15 23:41:06 +10:00
|
|
|
|
2020-06-03 01:23:22 +10:00
|
|
|
struct zmk_hid_keypad_report *zmk_hid_get_keypad_report();
|
|
|
|
struct zmk_hid_consumer_report *zmk_hid_get_consumer_report();
|