// SPDX-License-Identifier: GPL-2.0-or-later // // KeyOverlay: lets the host ask which layer is active. // // Request (host -> keyboard): [0xE0, 0x01, ...] // Response (keyboard -> host): [0xE0, 0x01, highest_layer, layer_state (u32 LE), default_layer_state (u32 LE), ...] // // 0xE0 is outside the ids used by VIA (0x01..0x1F), Vial (0xFE) and "unhandled" (0xFF). // Only reads state; it changes nothing on the keyboard and works while Vial is locked. #include QMK_KEYBOARD_H #include "raw_hid.h" #include #define KEYOVERLAY_CMD 0xE0 #define KEYOVERLAY_PROTOCOL 0x01 #define KEYOVERLAY_ID_UNHANDLED 0xFF #define KEYOVERLAY_MIN_LENGTH 11 void raw_hid_receive_kb(uint8_t *data, uint8_t length) { if (data[0] != KEYOVERLAY_CMD || length < KEYOVERLAY_MIN_LENGTH) { data[0] = KEYOVERLAY_ID_UNHANDLED; return; } const uint32_t active = (uint32_t)layer_state; const uint32_t default_ = (uint32_t)default_layer_state; data[1] = KEYOVERLAY_PROTOCOL; data[2] = get_highest_layer(layer_state | default_layer_state); memcpy(&data[3], &active, sizeof(active)); memcpy(&data[7], &default_, sizeof(default_)); }