forked from mirrors/qmk_userspace
Added Lemokey P1 Pro
This commit is contained in:
parent
b71b83f882
commit
62030ee6bb
72 changed files with 2876 additions and 507 deletions
|
@ -1,4 +1,4 @@
|
|||
/* Copyright 2023 @ lokher (https://www.keychron.com)
|
||||
/* Copyright 2022~2024 @ lokher (https://www.keychron.com)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -28,7 +28,6 @@
|
|||
# include "factory_test.h"
|
||||
#endif
|
||||
#include "lpm.h"
|
||||
|
||||
#include "lemokey_task.h"
|
||||
#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)
|
||||
# ifdef LED_MATRIX_ENABLE
|
||||
|
@ -37,15 +36,16 @@
|
|||
# ifdef RGB_MATRIX_ENABLE
|
||||
# include "rgb_matrix.h"
|
||||
# endif
|
||||
# include "bat_level_animation.h"
|
||||
# include "eeprom.h"
|
||||
#endif
|
||||
#include "bat_level_animation.h"
|
||||
|
||||
#define HOST_INDEX_MASK 0x0F
|
||||
#define HOST_P2P4G 0x10
|
||||
#define INDEX_MASK 0x0F
|
||||
#define P24G_IND_MASK 0x10
|
||||
#define USB_IND_MASK 0x20
|
||||
#define LED_ON 0x80
|
||||
|
||||
// #define RGB_MATRIX_TIMEOUT_INFINITE 0xFFFFFFFF
|
||||
#define IND_VAL_MASK (USB_IND_MASK | P24G_IND_MASK | INDEX_MASK)
|
||||
|
||||
#ifdef LED_MATRIX_ENABLE
|
||||
# define DECIDE_TIME(t, duration) (duration == 0 ? LED_MATRIX_TIMEOUT_INFINITE : ((t > duration) ? t : duration))
|
||||
#endif
|
||||
|
@ -71,12 +71,7 @@ static uint16_t next_period;
|
|||
static indicator_type_t type;
|
||||
static uint32_t indicator_timer_buffer = 0;
|
||||
|
||||
#if defined(BAT_LOW_LED_PIN)
|
||||
static uint32_t bat_low_pin_indicator = 0;
|
||||
static uint32_t bat_low_blink_duration = 0;
|
||||
#endif
|
||||
|
||||
#if defined(LOW_BAT_IND_INDEX)
|
||||
#if defined(BAT_LOW_LED_PIN) || defined(SPACE_KEY_LOW_BAT_IND)
|
||||
static uint32_t bat_low_backlit_indicator = 0;
|
||||
static uint8_t bat_low_ind_state = 0;
|
||||
static uint32_t rtc_time = 0;
|
||||
|
@ -85,22 +80,13 @@ static uint32_t rtc_time = 0;
|
|||
#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)
|
||||
backlight_state_t original_backlight_state;
|
||||
|
||||
# ifdef BT_HOST_LED_MATRIX_LIST
|
||||
static uint8_t bt_host_led_matrix_list[BT_HOST_DEVICES_COUNT] = BT_HOST_LED_MATRIX_LIST;
|
||||
# ifdef BT_INDICATION_LED_LIST
|
||||
static uint8_t bt_host_led_matrix_list[BT_HOST_DEVICES_COUNT] = BT_INDICATION_LED_LIST;
|
||||
# endif
|
||||
|
||||
# ifdef P2P4G_HOST_LED_MATRIX_LIST
|
||||
static uint8_t p2p4g_host_led_matrix_list[P2P4G_HOST_DEVICES_COUNT] = P2P4G_HOST_LED_MATRIX_LIST;
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef BT_HOST_LED_PIN_LIST
|
||||
static pin_t bt_led_pin_list[BT_HOST_DEVICES_COUNT] = BT_HOST_LED_PIN_LIST;
|
||||
#endif
|
||||
|
||||
#ifdef P24G_HOST_LED_PIN_LIST
|
||||
static pin_t p24g_led_pin_list[P24G_HOST_DEVICES_COUNT] = P24G_HOST_LED_PIN_LIST;
|
||||
#ifdef BT_INDICATION_LED_PIN_LIST
|
||||
static pin_t bt_led_pin_list[BT_HOST_DEVICES_COUNT] = BT_INDICATION_LED_PIN_LIST;
|
||||
#endif
|
||||
|
||||
#ifdef LED_MATRIX_ENABLE
|
||||
|
@ -111,9 +97,9 @@ static pin_t p24g_led_pin_list[P24G_HOST_DEVICES_COUNT] = P24G_HOST_LED_PIN_LIST
|
|||
# define SET_ALL_LED_OFF() led_matrix_set_value_all(0)
|
||||
# define SET_LED_OFF(idx) led_matrix_set_value(idx, 0)
|
||||
# define SET_LED_ON(idx) led_matrix_set_value(idx, 255)
|
||||
# define SET_LED_BT(idx) led_matrix_set_value(idx, 255)
|
||||
# define SET_LED_P24G(idx) led_matrix_set_value(idx, 255)
|
||||
# define SET_LED_LOW_BAT(idx) led_matrix_set_value(idx, 255)
|
||||
# define SET_LED_BT SET_LED_ON
|
||||
# define SET_LED_P24G SET_LED_ON
|
||||
# define SET_LED_LOW_BAT SET_LED_ON
|
||||
# define LED_DRIVER_IS_ENABLED led_matrix_is_enabled
|
||||
# define LED_DRIVER_EECONFIG_RELOAD() \
|
||||
eeprom_read_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); \
|
||||
|
@ -157,29 +143,41 @@ static pin_t p24g_led_pin_list[P24G_HOST_DEVICES_COUNT] = P24G_HOST_LED_PIN_LIST
|
|||
# define LED_DRIVER_TIMEOUTED rgb_matrix_timeouted
|
||||
#endif
|
||||
|
||||
#ifdef WINLOCK_LED_LIST
|
||||
# define SET_LED_WINLOCK(idx) rgb_matrix_set_color(idx, 255, 0, 0)
|
||||
#endif
|
||||
|
||||
bool LED_INDICATORS_KB(void);
|
||||
|
||||
void indicator_init(void) {
|
||||
memset(&indicator_config, 0, sizeof(indicator_config));
|
||||
|
||||
#ifdef BT_HOST_LED_PIN_LIST
|
||||
#ifdef BT_INDICATION_LED_PIN_LIST
|
||||
for (uint8_t i = 0; i < BT_HOST_DEVICES_COUNT; i++) {
|
||||
setPinOutput(bt_led_pin_list[i]);
|
||||
writePin(bt_led_pin_list[i], !HOST_LED_PIN_ON_STATE);
|
||||
writePin(bt_led_pin_list[i], !BT_INDICATION_LED_ON_STATE);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef P24G_HOST_LED_PIN_LIST
|
||||
for (uint8_t i = 0; i < P24G_HOST_DEVICES_COUNT; i++) {
|
||||
setPinOutput(p24g_led_pin_list[i]);
|
||||
writePin(p24g_led_pin_list[i], !HOST_LED_PIN_ON_STATE);
|
||||
}
|
||||
#ifdef COMMON_BT_LED_PIN
|
||||
setPinOutput(COMMON_BT_LED_PIN);
|
||||
writePin(COMMON_BT_LED_PIN, !COMMON_BT_LED_PIN_ON_STATE);
|
||||
#endif
|
||||
|
||||
#ifdef P24G_INDICATION_LED_PIN
|
||||
setPinOutput(P24G_INDICATION_LED_PIN);
|
||||
writePin(P24G_INDICATION_LED_PIN, !BT_INDICATION_LED_ON_STATE);
|
||||
#endif
|
||||
|
||||
#ifdef BAT_LOW_LED_PIN
|
||||
setPinOutput(BAT_LOW_LED_PIN);
|
||||
writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE);
|
||||
#endif
|
||||
|
||||
#ifdef WIN_LOCK_LED_PIN
|
||||
setPinOutput(WIN_LOCK_LED_PIN);
|
||||
writePin(WIN_LOCK_LED_PIN, keymap_config.no_gui);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)
|
||||
|
@ -213,10 +211,7 @@ void indicator_eeconfig_reload(void) {
|
|||
|
||||
bool indicator_is_running(void) {
|
||||
return
|
||||
#if defined(BAT_LOW_LED_PIN)
|
||||
bat_low_blink_duration ||
|
||||
#endif
|
||||
#if defined(LOW_BAT_IND_INDEX)
|
||||
#if defined(BAT_LOW_LED_PIN) || defined(SPACE_KEY_LOW_BAT_IND)
|
||||
bat_low_ind_state ||
|
||||
#endif
|
||||
!!indicator_config.value;
|
||||
|
@ -253,7 +248,7 @@ static void indicator_timer_cb(void *arg) {
|
|||
indicator_config.value |= LED_ON;
|
||||
next_period = indicator_config.on_time;
|
||||
} else {
|
||||
indicator_config.value = indicator_config.value & 0x1F;
|
||||
indicator_config.value = indicator_config.value & IND_VAL_MASK;
|
||||
next_period = indicator_config.duration - indicator_config.on_time;
|
||||
}
|
||||
|
||||
|
@ -268,7 +263,7 @@ static void indicator_timer_cb(void *arg) {
|
|||
case INDICATOR_BLINK:
|
||||
if (indicator_config.value) {
|
||||
if (indicator_config.value & LED_ON) {
|
||||
indicator_config.value = indicator_config.value & 0x1F;
|
||||
indicator_config.value = indicator_config.value & IND_VAL_MASK;
|
||||
next_period = indicator_config.off_time;
|
||||
} else {
|
||||
indicator_config.value |= LED_ON;
|
||||
|
@ -289,32 +284,38 @@ static void indicator_timer_cb(void *arg) {
|
|||
break;
|
||||
}
|
||||
|
||||
#if defined(BT_HOST_LED_PIN_LIST) || defined(P24G_HOST_LED_PIN_LIST)
|
||||
#if defined(BT_INDICATION_LED_PIN_LIST) || defined(P24G_INDICATION_LED_PIN) || defined(COMMON_BT_LED_PIN)
|
||||
if (indicator_config.value) {
|
||||
uint8_t idx = (indicator_config.value & HOST_INDEX_MASK) - 1;
|
||||
|
||||
pin_t *led_lin_list = NULL;
|
||||
uint8_t led_count;
|
||||
# if defined(P24G_HOST_LED_PIN_LIST)
|
||||
if (indicator_config.value & HOST_P2P4G) {
|
||||
if (idx < P24G_HOST_DEVICES_COUNT) led_lin_list = p24g_led_pin_list;
|
||||
led_count = P24G_HOST_DEVICES_COUNT;
|
||||
# if defined(P24G_INDICATION_LED_PIN)
|
||||
if (indicator_config.value & P24G_IND_MASK) {
|
||||
if ((indicator_config.value & LED_ON) && !time_up) {
|
||||
writePin(P24G_INDICATION_LED_PIN, BT_INDICATION_LED_ON_STATE);
|
||||
} else {
|
||||
writePin(P24G_INDICATION_LED_PIN, !BT_INDICATION_LED_ON_STATE);
|
||||
}
|
||||
} else
|
||||
# endif
|
||||
{
|
||||
if (idx < BT_HOST_DEVICES_COUNT) led_lin_list = bt_led_pin_list;
|
||||
led_count = BT_HOST_DEVICES_COUNT;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < led_count; i++) {
|
||||
if (i != idx) writePin(led_lin_list[idx], !HOST_LED_PIN_ON_STATE);
|
||||
}
|
||||
|
||||
if (led_lin_list) {
|
||||
uint8_t idx = (indicator_config.value & INDEX_MASK) - 1;
|
||||
#ifdef BT_INDICATION_LED_PIN_LIST
|
||||
for (uint8_t i = 0; i < BT_HOST_DEVICES_COUNT; i++) {
|
||||
if (i != idx) writePin(bt_led_pin_list[idx], !BT_INDICATION_LED_ON_STATE);
|
||||
}
|
||||
#endif
|
||||
if ((indicator_config.value & LED_ON) && !time_up) {
|
||||
writePin(led_lin_list[idx], HOST_LED_PIN_ON_STATE);
|
||||
#ifdef BT_INDICATION_LED_PIN_LIST
|
||||
writePin(bt_led_pin_list[idx], BT_INDICATION_LED_ON_STATE);
|
||||
#endif
|
||||
#ifdef COMMON_BT_LED_PIN
|
||||
writePin(COMMON_BT_LED_PIN, COMMON_BT_LED_PIN_ON_STATE);
|
||||
#endif
|
||||
} else {
|
||||
writePin(led_lin_list[idx], !HOST_LED_PIN_ON_STATE);
|
||||
#ifdef BT_INDICATION_LED_PIN_LIST
|
||||
writePin(bt_led_pin_list[idx], !BT_INDICATION_LED_ON_STATE);
|
||||
#endif
|
||||
#ifdef COMMON_BT_LED_PIN
|
||||
writePin(COMMON_BT_LED_PIN, !COMMON_BT_LED_PIN_ON_STATE);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -322,7 +323,7 @@ static void indicator_timer_cb(void *arg) {
|
|||
|
||||
if (time_up) {
|
||||
/* Set indicator to off on timeup, avoid keeping light up until next update in raindrop effect */
|
||||
indicator_config.value = indicator_config.value & 0x1F;
|
||||
indicator_config.value = indicator_config.value & IND_VAL_MASK;
|
||||
#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)
|
||||
LED_INDICATORS_KB();
|
||||
#endif
|
||||
|
@ -342,11 +343,18 @@ static void indicator_timer_cb(void *arg) {
|
|||
void indicator_set(wt_state_t state, uint8_t host_index) {
|
||||
if (get_transport() == TRANSPORT_USB) return;
|
||||
|
||||
#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)
|
||||
static uint8_t pre_state = 0;
|
||||
#endif
|
||||
static uint8_t current_state = 0;
|
||||
static uint8_t current_host = 0;
|
||||
bool host_index_changed = false;
|
||||
|
||||
if (host_index == 24) host_index = HOST_P2P4G | 0x01;
|
||||
if (host_index == P24G_HOST_INDEX)
|
||||
host_index = P24G_IND_MASK | 0x01;
|
||||
|
||||
else if (host_index == USB_HOST_INDEX)
|
||||
host_index = USB_IND_MASK | 0x01;
|
||||
|
||||
if (current_host != host_index && state != WT_DISCONNECTED) {
|
||||
host_index_changed = true;
|
||||
|
@ -354,6 +362,11 @@ void indicator_set(wt_state_t state, uint8_t host_index) {
|
|||
}
|
||||
|
||||
if (current_state != state || host_index_changed || state == WT_RECONNECTING) {
|
||||
// Some BT chips need to reset to enter sleep mode, ignore it.
|
||||
if (current_state == WT_SUSPEND && state == WT_DISCONNECTED) return;
|
||||
#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)
|
||||
pre_state = current_state;
|
||||
#endif
|
||||
current_state = state;
|
||||
} else {
|
||||
return;
|
||||
|
@ -366,15 +379,25 @@ void indicator_set(wt_state_t state, uint8_t host_index) {
|
|||
indicator_enable();
|
||||
indicator_reset_backlit_time();
|
||||
#endif
|
||||
#if defined(BT_INDICATION_LED_PIN_LIST)
|
||||
for (uint8_t i = 0; i < BT_HOST_DEVICES_COUNT; i++)
|
||||
writePin(bt_led_pin_list[i], !BT_INDICATION_LED_ON_STATE);
|
||||
#endif
|
||||
|
||||
#if defined(P24G_INDICATION_LED_PIN)
|
||||
writePin(P24G_INDICATION_LED_PIN, !BT_INDICATION_LED_ON_STATE);
|
||||
#endif
|
||||
#ifdef COMMON_BT_LED_PIN
|
||||
writePin(COMMON_BT_LED_PIN, !COMMON_BT_LED_PIN_ON_STATE);
|
||||
#endif
|
||||
switch (state) {
|
||||
case WT_DISCONNECTED:
|
||||
|
||||
#if defined(BT_HOST_LED_PIN_LIST)
|
||||
if ((host_index & HOST_P2P4G) != HOST_P2P4G) writePin(bt_led_pin_list[(host_index & HOST_INDEX_MASK) - 1], !HOST_LED_PIN_ON_STATE);
|
||||
#if defined(BT_INDICATION_LED_PIN_LIST)
|
||||
if ((host_index & P24G_IND_MASK) != P24G_IND_MASK) writePin(bt_led_pin_list[(host_index & INDEX_MASK) - 1], !BT_INDICATION_LED_ON_STATE);
|
||||
#endif
|
||||
#if defined(P24G_HOST_LED_PIN_LIST)
|
||||
if (host_index & HOST_P2P4G) writePin(p24g_led_pin_list[(host_index & HOST_INDEX_MASK) - 1], !HOST_LED_PIN_ON_STATE);
|
||||
#if defined(P24G_INDICATION_LED_PIN)
|
||||
writePin(P24G_INDICATION_LED_PIN, !BT_INDICATION_LED_ON_STATE);
|
||||
#endif
|
||||
|
||||
INDICATOR_SET(disconnected);
|
||||
|
@ -385,6 +408,11 @@ void indicator_set(wt_state_t state, uint8_t host_index) {
|
|||
indicator_set_backlit_timeout(1000);
|
||||
|
||||
} else {
|
||||
#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)
|
||||
if (pre_state == WT_CONNECTED)
|
||||
indicator_set_backlit_timeout(1000);
|
||||
else
|
||||
#endif
|
||||
/* Set timer so that user has chance to turn on the backlight when is off */
|
||||
indicator_set_backlit_timeout(DECIDE_TIME(DISCONNECTED_BACKLIGHT_DISABLE_TIMEOUT * 1000, indicator_config.duration));
|
||||
}
|
||||
|
@ -435,14 +463,19 @@ void indicator_set(wt_state_t state, uint8_t host_index) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(BT_HOST_LED_PIN_LIST)
|
||||
#if defined(BT_INDICATION_LED_PIN_LIST)
|
||||
for (uint8_t i = 0; i < BT_HOST_DEVICES_COUNT; i++)
|
||||
writePin(bt_led_pin_list[i], !HOST_LED_PIN_ON_STATE);
|
||||
writePin(bt_led_pin_list[i], !BT_INDICATION_LED_ON_STATE);
|
||||
#endif
|
||||
#if defined(P24G_HOST_LED_PIN_LIST)
|
||||
for (uint8_t i = 0; i < P24G_HOST_DEVICES_COUNT; i++)
|
||||
writePin(p24g_led_pin_list[i], !HOST_LED_PIN_ON_STATE);
|
||||
#if defined(P24G_INDICATION_LED_PIN)
|
||||
writePin(P24G_INDICATION_LED_PIN, !BT_INDICATION_LED_ON_STATE);
|
||||
#endif
|
||||
#ifdef COMMON_BT_LED_PIN
|
||||
writePin(COMMON_BT_LED_PIN, !COMMON_BT_LED_PIN_ON_STATE);
|
||||
#endif
|
||||
# if defined(BAT_LOW_LED_PIN)
|
||||
writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE);
|
||||
# endif
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -465,22 +498,11 @@ void indicator_stop(void) {
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef BAT_LOW_LED_PIN
|
||||
void indicator_battery_low_enable(bool enable) {
|
||||
if (enable) {
|
||||
if (bat_low_blink_duration == 0) {
|
||||
bat_low_blink_duration = bat_low_pin_indicator = timer_read32();
|
||||
} else
|
||||
bat_low_blink_duration = timer_read32();
|
||||
} else
|
||||
writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LOW_BAT_IND_INDEX)
|
||||
void indicator_battery_low_backlit_enable(bool enable) {
|
||||
#if defined(BAT_LOW_LED_PIN) || defined(SPACE_KEY_LOW_BAT_IND)
|
||||
if (enable) {
|
||||
uint32_t t = rtc_timer_read_ms();
|
||||
|
||||
/* Check overflow */
|
||||
if (rtc_time > t) {
|
||||
if (bat_low_ind_state == 0)
|
||||
|
@ -489,55 +511,62 @@ void indicator_battery_low_backlit_enable(bool enable) {
|
|||
rtc_time += t;
|
||||
}
|
||||
}
|
||||
|
||||
/* Indicating at first time or after the interval */
|
||||
if ((rtc_time == 0 || t - rtc_time > LOW_BAT_LED_TRIG_INTERVAL) && bat_low_ind_state == 0) {
|
||||
bat_low_backlit_indicator = enable ? timer_read32() : 0;
|
||||
rtc_time = rtc_timer_read_ms();
|
||||
bat_low_ind_state = 1;
|
||||
|
||||
# if defined(SPACE_KEY_LOW_BAT_IND)
|
||||
indicator_enable();
|
||||
# endif
|
||||
}
|
||||
} else {
|
||||
rtc_time = 0;
|
||||
bat_low_ind_state = 0;
|
||||
|
||||
# if defined(SPACE_KEY_LOW_BAT_IND)
|
||||
indicator_eeconfig_reload();
|
||||
if (!LED_DRIVER_IS_ENABLED()) indicator_disable();
|
||||
# endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void indicator_battery_low(void) {
|
||||
#ifdef BAT_LOW_LED_PIN
|
||||
if (bat_low_pin_indicator && timer_elapsed32(bat_low_pin_indicator) > (LOW_BAT_LED_BLINK_PERIOD)) {
|
||||
togglePin(BAT_LOW_LED_PIN);
|
||||
bat_low_pin_indicator = timer_read32();
|
||||
// Turn off low battery indication if we reach the duration
|
||||
if (timer_elapsed32(bat_low_blink_duration) > LOW_BAT_LED_BLINK_DURATION && palReadLine(BAT_LOW_LED_PIN) != BAT_LOW_LED_PIN_ON_STATE) {
|
||||
bat_low_blink_duration = bat_low_pin_indicator = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(LOW_BAT_IND_INDEX)
|
||||
#if defined(BAT_LOW_LED_PIN) || defined(SPACE_KEY_LOW_BAT_IND)
|
||||
if (bat_low_ind_state) {
|
||||
if ((bat_low_ind_state & 0x0F) <= (LOW_BAT_LED_BLINK_TIMES) && timer_elapsed32(bat_low_backlit_indicator) > (LOW_BAT_LED_BLINK_PERIOD)) {
|
||||
if (bat_low_ind_state & 0x80) {
|
||||
bat_low_ind_state &= 0x7F;
|
||||
bat_low_ind_state++;
|
||||
# if defined(BAT_LOW_LED_PIN)
|
||||
writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE);
|
||||
# endif
|
||||
} else {
|
||||
bat_low_ind_state |= 0x80;
|
||||
# if defined(BAT_LOW_LED_PIN)
|
||||
writePin(BAT_LOW_LED_PIN, BAT_LOW_LED_PIN_ON_STATE);
|
||||
# endif
|
||||
}
|
||||
|
||||
bat_low_backlit_indicator = timer_read32();
|
||||
|
||||
/* Restore backligth state */
|
||||
if ((bat_low_ind_state & 0x0F) > (LOW_BAT_LED_BLINK_TIMES)) {
|
||||
# if defined(NUM_LOCK_INDEX) || defined(CAPS_LOCK_INDEX) || defined(SCROLL_LOCK_INDEX) || defined(COMPOSE_LOCK_INDEX) || defined(KANA_LOCK_INDEX)
|
||||
if (LED_DRIVER_ALLOW_SHUTDOWN())
|
||||
# if defined(BAT_LOW_LED_PIN)
|
||||
writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE);
|
||||
# endif
|
||||
# if defined(SPACE_KEY_LOW_BAT_IND)
|
||||
# if defined(NUM_LOCK_INDEX) || defined(CAPS_LOCK_INDEX) || defined(SCROLL_LOCK_INDEX) || defined(COMPOSE_LOCK_INDEX) || defined(KANA_LOCK_INDEX)
|
||||
if (LED_DRIVER_ALLOW_SHUTDOWN())
|
||||
# endif
|
||||
indicator_disable();
|
||||
# endif
|
||||
}
|
||||
} else if ((bat_low_ind_state & 0x0F) > (LOW_BAT_LED_BLINK_TIMES)) {
|
||||
# if defined(BAT_LOW_LED_PIN)
|
||||
writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE);
|
||||
# endif
|
||||
bat_low_ind_state = 0;
|
||||
lpm_timer_reset();
|
||||
}
|
||||
|
@ -546,9 +575,7 @@ void indicator_battery_low(void) {
|
|||
}
|
||||
|
||||
void indicator_task(void) {
|
||||
#if (defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)) && defined(BAT_LEVEL_LED_LIST)
|
||||
bat_level_animiation_task();
|
||||
#endif
|
||||
if (indicator_config.value && timer_elapsed32(indicator_timer_buffer) >= next_period) {
|
||||
indicator_timer_cb((void *)&type);
|
||||
indicator_timer_buffer = timer_read32();
|
||||
|
@ -592,6 +619,32 @@ __attribute__((weak)) void os_state_indicate(void) {
|
|||
SET_LED_ON(KANA_LOCK_INDEX);
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(WIN_LOCK_LED_PIN) || defined(WINLOCK_LED_LIST)
|
||||
/* TODO: move to common.c */
|
||||
if (keymap_config.no_gui && (((get_transport() & TRANSPORT_WIRELESS) && wireless_get_state() == WT_CONNECTED) || (get_transport() == TRANSPORT_USB && USBD1.state == USB_ACTIVE))) {
|
||||
# ifdef WINLOCK_LED_LIST
|
||||
if (keymap_config.no_gui) {
|
||||
uint8_t led_list[] = WINLOCK_LED_LIST;
|
||||
uint8_t led_cnt = ARRAY_SIZE(led_list);
|
||||
for (uint8_t i = 0; i < led_cnt; i++) {
|
||||
# if defined(DIM_WIN_LOCK)
|
||||
SET_LED_OFF(led_list[i]);
|
||||
# else
|
||||
SET_LED_WINLOCK(led_list[i]);
|
||||
# endif
|
||||
}
|
||||
}
|
||||
# endif
|
||||
# ifdef WIN_LOCK_LED_PIN
|
||||
writePin(WIN_LOCK_LED_PIN, WIN_LOCK_LED_ON_LEVEL);
|
||||
# endif
|
||||
} else {
|
||||
# ifdef WIN_LOCK_LED_PIN
|
||||
writePin(WIN_LOCK_LED_PIN, !WIN_LOCK_LED_ON_LEVEL);
|
||||
# endif
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
bool LED_INDICATORS_KB(void) {
|
||||
|
@ -602,9 +655,8 @@ bool LED_INDICATORS_KB(void) {
|
|||
return true;
|
||||
}
|
||||
|
||||
# if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)
|
||||
if (battery_is_empty()) SET_ALL_LED_OFF();
|
||||
# if defined(LOW_BAT_IND_INDEX)
|
||||
# if defined(LOW_BAT_IND_INDEX)
|
||||
if (bat_low_ind_state && (bat_low_ind_state & 0x0F) <= LOW_BAT_LED_BLINK_TIMES) {
|
||||
uint8_t idx_list[] = LOW_BAT_IND_INDEX;
|
||||
for (uint8_t i = 0; i < sizeof(idx_list); i++) {
|
||||
|
@ -615,8 +667,8 @@ bool LED_INDICATORS_KB(void) {
|
|||
}
|
||||
}
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if (defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)) && defined(BAT_LEVEL_LED_LIST)
|
||||
if (bat_level_animiation_actived()) {
|
||||
bat_level_animiation_indicate();
|
||||
|
@ -625,39 +677,40 @@ bool LED_INDICATORS_KB(void) {
|
|||
static uint8_t last_host_index = 0xFF;
|
||||
|
||||
if (indicator_config.value) {
|
||||
uint8_t host_index = indicator_config.value & HOST_INDEX_MASK;
|
||||
uint8_t host_index = indicator_config.value & INDEX_MASK;
|
||||
|
||||
if (indicator_config.highlight) {
|
||||
SET_ALL_LED_OFF();
|
||||
} else if (last_host_index != host_index) {
|
||||
if (indicator_config.value & HOST_P2P4G)
|
||||
SET_LED_OFF(p2p4g_host_led_matrix_list[host_index - 1]);
|
||||
# ifdef P24G_INDICATION_LED_INDEX
|
||||
if (indicator_config.value & P24G_IND_MASK)
|
||||
SET_LED_OFF(P24G_INDICATION_LED_INDEX);
|
||||
else
|
||||
# endif
|
||||
SET_LED_OFF(bt_host_led_matrix_list[host_index - 1]);
|
||||
last_host_index = host_index;
|
||||
}
|
||||
|
||||
if (indicator_config.value & LED_ON) {
|
||||
# ifdef P2P4G_HOST_LED_MATRIX_LIST
|
||||
if (indicator_config.value & HOST_P2P4G)
|
||||
SET_LED_P24G(p2p4g_host_led_matrix_list[host_index - 1]);
|
||||
# ifdef P24G_INDICATION_LED_INDEX
|
||||
if (indicator_config.value & P24G_IND_MASK)
|
||||
SET_LED_P24G(P24G_INDICATION_LED_INDEX);
|
||||
else
|
||||
# endif
|
||||
SET_LED_BT(bt_host_led_matrix_list[host_index - 1]);
|
||||
|
||||
} else {
|
||||
# ifdef P2P4G_HOST_LED_MATRIX_LIST
|
||||
if (indicator_config.value & HOST_P2P4G)
|
||||
SET_LED_OFF(p2p4g_host_led_matrix_list[host_index - 1]);
|
||||
# ifdef P24G_INDICATION_LED_INDEX
|
||||
if (indicator_config.value & P24G_IND_MASK)
|
||||
SET_LED_OFF(P24G_INDICATION_LED_INDEX);
|
||||
else
|
||||
# endif
|
||||
SET_LED_OFF(bt_host_led_matrix_list[host_index - 1]);
|
||||
}
|
||||
} else
|
||||
os_state_indicate();
|
||||
|
||||
} else
|
||||
os_state_indicate();
|
||||
}
|
||||
if (get_transport() == TRANSPORT_USB) os_state_indicate();
|
||||
|
||||
if (!LED_INDICATORS_USER()) return true;
|
||||
|
||||
|
@ -686,10 +739,7 @@ bool led_update_kb(led_t led_state) {
|
|||
}
|
||||
|
||||
void LED_NONE_INDICATORS_KB(void) {
|
||||
# if defined(RGB_DISABLE_WHEN_USB_SUSPENDED)
|
||||
if (get_transport() == TRANSPORT_USB && USB_DRIVER.state == USB_SUSPENDED) return;
|
||||
# endif
|
||||
# if defined(LED_DISABLE_WHEN_USB_SUSPENDED)
|
||||
# if defined(RGB_DISABLE_WHEN_USB_SUSPENDED) || defined(LED_DISABLE_WHEN_USB_SUSPENDED)
|
||||
if (get_transport() == TRANSPORT_USB && USB_DRIVER.state == USB_SUSPENDED) return;
|
||||
# endif
|
||||
|
||||
|
@ -713,8 +763,11 @@ bool LED_DRIVER_ALLOW_SHUTDOWN(void) {
|
|||
# if defined(KANA_LOCK_INDEX)
|
||||
if (host_keyboard_led_state().kana) return false;
|
||||
# endif
|
||||
# if defined(WINLOCK_LED_LIST) && !defined(WIN_LOCK_LED_PIN)
|
||||
if (keymap_config.no_gui && (wireless_get_state() == WT_CONNECTED || get_transport()==TRANSPORT_USB)) return false;
|
||||
# endif
|
||||
|
||||
return true;
|
||||
}
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue