feat: handle LED indicators report

This commit is contained in:
Alessandro Bortolin
2022-09-06 12:29:07 +00:00
committed by Pete Johanson
parent 6276e973d5
commit 4e55c5f6e9
13 changed files with 269 additions and 15 deletions

View File

@@ -27,6 +27,7 @@ int zmk_ble_prof_select(uint8_t index);
int zmk_ble_prof_disconnect(uint8_t index);
int zmk_ble_active_profile_index();
int zmk_ble_profile_index(const bt_addr_le_t *addr);
bt_addr_le_t *zmk_ble_active_profile_addr();
bool zmk_ble_active_profile_is_open();
bool zmk_ble_active_profile_is_connected();

View File

@@ -0,0 +1,16 @@
/*
* Copyright (c) 2022 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#pragma once
#include <zmk/hid_indicators_types.h>
#include <zmk/event_manager.h>
struct zmk_hid_indicators_changed {
zmk_hid_indicators indicators;
};
ZMK_EVENT_DECLARE(zmk_hid_indicators_changed);

View File

@@ -50,6 +50,7 @@
#define ZMK_HID_MAIN_VAL_BUFFERED_BYTES (0x01 << 8)
#define ZMK_HID_REPORT_ID_KEYBOARD 0x01
#define ZMK_HID_REPORT_ID_LEDS 0x01
#define ZMK_HID_REPORT_ID_CONSUMER 0x02
#define ZMK_HID_REPORT_ID_MOUSE 0x03
@@ -73,6 +74,22 @@ static const uint8_t zmk_hid_report_desc[] = {
HID_REPORT_COUNT(0x01),
HID_INPUT(ZMK_HID_MAIN_VAL_CONST | ZMK_HID_MAIN_VAL_VAR | ZMK_HID_MAIN_VAL_ABS),
#if IS_ENABLED(CONFIG_ZMK_HID_INDICATORS)
HID_USAGE_PAGE(HID_USAGE_LED),
HID_USAGE_MIN8(HID_USAGE_LED_NUM_LOCK),
HID_USAGE_MAX8(HID_USAGE_LED_KANA),
HID_REPORT_SIZE(0x01),
HID_REPORT_COUNT(0x05),
HID_OUTPUT(ZMK_HID_MAIN_VAL_DATA | ZMK_HID_MAIN_VAL_VAR | ZMK_HID_MAIN_VAL_ABS),
HID_USAGE_PAGE(HID_USAGE_LED),
HID_REPORT_SIZE(0x03),
HID_REPORT_COUNT(0x01),
HID_OUTPUT(ZMK_HID_MAIN_VAL_CONST | ZMK_HID_MAIN_VAL_VAR | ZMK_HID_MAIN_VAL_ABS),
#endif // IS_ENABLED(CONFIG_ZMK_HID_INDICATORS)
HID_USAGE_PAGE(HID_USAGE_KEY),
#if IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_NKRO)
@@ -189,6 +206,19 @@ struct zmk_hid_keyboard_report {
struct zmk_hid_keyboard_report_body body;
} __packed;
#if IS_ENABLED(CONFIG_ZMK_HID_INDICATORS)
struct zmk_hid_led_report_body {
uint8_t leds;
} __packed;
struct zmk_hid_led_report {
uint8_t report_id;
struct zmk_hid_led_report_body body;
} __packed;
#endif // IS_ENABLED(CONFIG_ZMK_HID_INDICATORS)
struct zmk_hid_consumer_report_body {
#if IS_ENABLED(CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_BASIC)
uint8_t keys[CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE];

View File

@@ -0,0 +1,19 @@
/*
* Copyright (c) 2022 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#pragma once
#include <zmk/endpoints_types.h>
#include <zmk/hid.h>
#include <zmk/hid_indicators_types.h>
zmk_hid_indicators zmk_hid_indicators_get_current_profile(void);
zmk_hid_indicators zmk_hid_indicators_get_profile(struct zmk_endpoint_instance endpoint);
void zmk_hid_indicators_set_profile(zmk_hid_indicators indicators,
struct zmk_endpoint_instance endpoint);
void zmk_hid_indicators_process_report(struct zmk_hid_led_report_body *report,
struct zmk_endpoint_instance endpoint);

View File

@@ -0,0 +1,9 @@
/*
* Copyright (c) 2022 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#pragma once
typedef uint8_t zmk_hid_indicators;