-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
342 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
/* Led Num Lock */ | ||
#define LED_NUMLOCK (0) | ||
#define LED_NUM (LED_NUMLOCK) | ||
#define LED_NLCK (LED_NUMLOCK) | ||
|
||
/* Led Caps Lock */ | ||
#define LED_CAPSLOCK (1) | ||
#define LED_CAPS (LED_CAPSLOCK) | ||
#define LED_CLCK (LED_CAPSLOCK) | ||
|
||
/* Led Scroll Lock */ | ||
#define LED_SCROLLLOCK (2) | ||
#define LED_SLCK (LED_SCROLLLOCK) | ||
|
||
/* Led Compose */ | ||
#define LED_COMPOSE (3) | ||
|
||
/* Led Kana */ | ||
#define LED_KANA (4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <zmk/led_indicators_types.h> | ||
#include <zmk/event_manager.h> | ||
|
||
struct zmk_led_changed { | ||
zmk_leds_flags_t leds; | ||
}; | ||
|
||
ZMK_EVENT_DECLARE(zmk_led_changed); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <zmk/endpoints_types.h> | ||
#include <zmk/hid.h> | ||
#include <zmk/led_indicators_types.h> | ||
|
||
zmk_leds_flags_t zmk_leds_get_current_flags(); | ||
zmk_leds_flags_t zmk_leds_get_flags(enum zmk_endpoint endpoint, uint8_t profile); | ||
void zmk_leds_update_flags(zmk_leds_flags_t leds, enum zmk_endpoint endpoint, uint8_t profile); | ||
|
||
void zmk_leds_process_report(struct zmk_hid_led_report_body *report, enum zmk_endpoint endpoint, | ||
uint8_t profile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
typedef uint8_t zmk_leds_flags_t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include <kernel.h> | ||
#include <zmk/events/led_indicator_changed.h> | ||
|
||
ZMK_EVENT_IMPL(zmk_led_changed); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include <kernel.h> | ||
#include <device.h> | ||
#include <init.h> | ||
|
||
#include <logging/log.h> | ||
#include <drivers/led.h> | ||
|
||
#include <zmk/ble.h> | ||
#include <zmk/endpoints.h> | ||
#include <zmk/hid.h> | ||
#include <zmk/led_indicators.h> | ||
#include <zmk/events/led_indicator_changed.h> | ||
#include <dt-bindings/zmk/led_indicators.h> | ||
|
||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); | ||
|
||
#define NUM_USB_PROFILES (COND_CODE_1(IS_ENABLED(CONFIG_ZMK_USB), (1), (0))) | ||
#define NUM_BLE_PROFILES (COND_CODE_1(IS_ENABLED(CONFIG_ZMK_BLE), (CONFIG_BT_MAX_CONN), (0))) | ||
#define NUM_PROFILES (NUM_USB_PROFILES + NUM_BLE_PROFILES) | ||
|
||
static zmk_leds_flags_t led_flags[NUM_PROFILES]; | ||
|
||
static size_t profile_index(enum zmk_endpoint endpoint, uint8_t profile) { | ||
switch (endpoint) { | ||
case ZMK_ENDPOINT_USB: | ||
return 0; | ||
case ZMK_ENDPOINT_BLE: | ||
return NUM_USB_PROFILES + profile; | ||
} | ||
|
||
CODE_UNREACHABLE; | ||
} | ||
|
||
zmk_leds_flags_t zmk_leds_get_current_flags() { | ||
enum zmk_endpoint endpoint = zmk_endpoints_selected(); | ||
|
||
uint8_t profile; | ||
|
||
switch (endpoint) { | ||
#if IS_ENABLED(CONFIG_ZMK_BLE) | ||
case ZMK_ENDPOINT_USB: | ||
profile = zmk_ble_active_profile_index(); | ||
break; | ||
#endif | ||
default: | ||
profile = 0; | ||
} | ||
|
||
return zmk_leds_get_flags(endpoint, profile); | ||
} | ||
|
||
zmk_leds_flags_t zmk_leds_get_flags(enum zmk_endpoint endpoint, uint8_t profile) { | ||
size_t index = profile_index(endpoint, profile); | ||
return led_flags[index]; | ||
} | ||
|
||
static void raise_led_changed_event(struct k_work *_work) { | ||
ZMK_EVENT_RAISE( | ||
new_zmk_led_changed((struct zmk_led_changed){.leds = zmk_leds_get_current_flags()})); | ||
} | ||
|
||
static K_WORK_DEFINE(led_changed_work, raise_led_changed_event); | ||
|
||
void zmk_leds_update_flags(zmk_leds_flags_t leds, enum zmk_endpoint endpoint, uint8_t profile) { | ||
size_t index = profile_index(endpoint, profile); | ||
led_flags[index] = leds; | ||
|
||
k_work_submit(&led_changed_work); | ||
} | ||
|
||
void zmk_leds_process_report(struct zmk_hid_led_report_body *report, enum zmk_endpoint endpoint, | ||
uint8_t profile) { | ||
zmk_leds_flags_t leds = report->leds; | ||
zmk_leds_update_flags(leds, endpoint, profile); | ||
|
||
LOG_DBG("Update LED indicators: endpoint=%d, profile=%d, flags=%x", endpoint, profile, leds); | ||
} |
Oops, something went wrong.