From b4f0923a7c7321bf06584f83099b0f417981fc6d Mon Sep 17 00:00:00 2001 From: fauxpark Date: Fri, 10 Jan 2020 12:22:14 +1100 Subject: [PATCH] [Core] Move backlight keycode handling to process_keycode/ (#7008) * Move backlight keycode handling to process_keycode/ * Switch keycode only when pressed * Remove default case * Add ChangeLog entry * New breaking changes target date --- common_features.mk | 1 + docs/ChangeLog/20200229/PR7008.md | 4 ++ quantum/keymap_common.c | 20 -------- quantum/process_keycode/process_backlight.c | 51 +++++++++++++++++++++ quantum/process_keycode/process_backlight.h | 21 +++++++++ quantum/quantum.c | 3 ++ quantum/quantum.h | 4 ++ tmk_core/common/action.c | 26 ----------- tmk_core/common/action_code.h | 27 +---------- 9 files changed, 85 insertions(+), 72 deletions(-) create mode 100644 docs/ChangeLog/20200229/PR7008.md create mode 100644 quantum/process_keycode/process_backlight.c create mode 100644 quantum/process_keycode/process_backlight.h diff --git a/common_features.mk b/common_features.mk index 67c64b425f68..43c8a1f577a4 100644 --- a/common_features.mk +++ b/common_features.mk @@ -245,6 +245,7 @@ VALID_BACKLIGHT_TYPES := pwm software custom BACKLIGHT_ENABLE ?= no BACKLIGHT_DRIVER ?= pwm ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) + SRC += $(QUANTUM_DIR)/process_keycode/process_backlight.c ifeq ($(filter $(BACKLIGHT_DRIVER),$(VALID_BACKLIGHT_TYPES)),) $(error BACKLIGHT_DRIVER="$(BACKLIGHT_DRIVER)" is not a valid backlight type) endif diff --git a/docs/ChangeLog/20200229/PR7008.md b/docs/ChangeLog/20200229/PR7008.md new file mode 100644 index 000000000000..40693f6a619f --- /dev/null +++ b/docs/ChangeLog/20200229/PR7008.md @@ -0,0 +1,4 @@ +* Moving backlight keycode handling to `process_keycode/` + * This refactors the backlight keycode logic to be clearer and more modular. + * All backlight-related keycodes are now actioned in a single file. + * The `ACTION_BACKLIGHT_*` macros have also been deleted. If you are still using these in a `fn_actions[]` block, please switch to using the backlight keycodes or functions directly. diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index c82c44639937..f34ba26e5acc 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -139,26 +139,6 @@ action_t action_for_key(uint8_t layer, keypos_t key) { mod = mod_config((keycode >> 0x8) & 0x1F); action.code = ACTION_MODS_TAP_KEY(mod, keycode & 0xFF); break; -#ifdef BACKLIGHT_ENABLE - case BL_ON: - action.code = ACTION_BACKLIGHT_ON(); - break; - case BL_OFF: - action.code = ACTION_BACKLIGHT_OFF(); - break; - case BL_DEC: - action.code = ACTION_BACKLIGHT_DECREASE(); - break; - case BL_INC: - action.code = ACTION_BACKLIGHT_INCREASE(); - break; - case BL_TOGG: - action.code = ACTION_BACKLIGHT_TOGGLE(); - break; - case BL_STEP: - action.code = ACTION_BACKLIGHT_STEP(); - break; -#endif #ifdef SWAP_HANDS_ENABLE case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX: action.code = ACTION(ACT_SWAP_HANDS, keycode & 0xff); diff --git a/quantum/process_keycode/process_backlight.c b/quantum/process_keycode/process_backlight.c new file mode 100644 index 000000000000..4d12f6813a92 --- /dev/null +++ b/quantum/process_keycode/process_backlight.c @@ -0,0 +1,51 @@ +/* Copyright 2019 + * + * 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 + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "process_backlight.h" + +#include "backlight.h" + +bool process_backlight(uint16_t keycode, keyrecord_t *record) { + if (record->event.pressed) { + switch (keycode) { + case BL_ON: + backlight_level(BACKLIGHT_LEVELS); + return false; + case BL_OFF: + backlight_level(0); + return false; + case BL_DEC: + backlight_decrease(); + return false; + case BL_INC: + backlight_increase(); + return false; + case BL_TOGG: + backlight_toggle(); + return false; + case BL_STEP: + backlight_step(); + return false; +#ifdef BACKLIGHT_BREATHING + case BL_BRTG: + backlight_toggle_breathing(); + return false; +#endif + } + } + + return true; +} diff --git a/quantum/process_keycode/process_backlight.h b/quantum/process_keycode/process_backlight.h new file mode 100644 index 000000000000..7fe887ae6752 --- /dev/null +++ b/quantum/process_keycode/process_backlight.h @@ -0,0 +1,21 @@ +/* Copyright 2019 + * + * 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 + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "quantum.h" + +bool process_backlight(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/quantum.c b/quantum/quantum.c index bf159644ab6d..0ba4a6799abd 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -223,6 +223,9 @@ bool process_record_quantum(keyrecord_t *record) { #ifdef AUDIO_ENABLE process_audio(keycode, record) && #endif +#ifdef BACKLIGHT_ENABLE + process_backlight(keycode, record) && +#endif #ifdef STENO_ENABLE process_steno(keycode, record) && #endif diff --git a/quantum/quantum.h b/quantum/quantum.h index 9758374f64ca..7807a44dcdc7 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -88,6 +88,10 @@ extern layer_state_t layer_state; # include "process_music.h" #endif +#ifdef BACKLIGHT_ENABLE +# include "process_backlight.h" +#endif + #ifdef LEADER_ENABLE # include "process_leader.h" #endif diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index d6062703ee68..2090f68efc93 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -559,32 +559,6 @@ void process_action(keyrecord_t *record, action_t action) { case ACT_MACRO: action_macro_play(action_get_macro(record, action.func.id, action.func.opt)); break; -#endif -#if defined(BACKLIGHT_ENABLE) || defined(LED_MATRIX_ENABLE) - case ACT_BACKLIGHT: - if (!event.pressed) { - switch (action.backlight.opt) { - case BACKLIGHT_INCREASE: - backlight_increase(); - break; - case BACKLIGHT_DECREASE: - backlight_decrease(); - break; - case BACKLIGHT_TOGGLE: - backlight_toggle(); - break; - case BACKLIGHT_STEP: - backlight_step(); - break; - case BACKLIGHT_ON: - backlight_level(BACKLIGHT_LEVELS); - break; - case BACKLIGHT_OFF: - backlight_level(0); - break; - } - } - break; #endif case ACT_COMMAND: break; diff --git a/tmk_core/common/action_code.h b/tmk_core/common/action_code.h index 03fcb3382bbb..1e95c8514c54 100644 --- a/tmk_core/common/action_code.h +++ b/tmk_core/common/action_code.h @@ -86,8 +86,7 @@ along with this program. If not, see . * 1100|opt | id(8) Macro play? * 1100|1111| id(8) Macro record? * - * ACT_BACKLIGHT(1101): - * 1101|opt |level(8) Backlight commands + * 1101|xxxx xxxx xxxx (reserved) * * ACT_COMMAND(1110): * 1110|opt | id(8) Built-in Command exec @@ -116,7 +115,6 @@ enum action_kind_id { ACT_LAYER_TAP_EXT = 0b1011, /* Layer 16-31 */ /* Extensions */ ACT_MACRO = 0b1100, - ACT_BACKLIGHT = 0b1101, ACT_COMMAND = 0b1110, ACT_FUNCTION = 0b1111 }; @@ -169,11 +167,6 @@ typedef union { uint8_t page : 2; uint8_t kind : 4; } usage; - struct action_backlight { - uint8_t level : 8; - uint8_t opt : 4; - uint8_t kind : 4; - } backlight; struct action_command { uint8_t id : 8; uint8_t opt : 4; @@ -290,28 +283,10 @@ enum layer_param_tap_op { #define ACTION_DEFAULT_LAYER_BIT_XOR(part, bits) ACTION_LAYER_BITOP(OP_BIT_XOR, (part), (bits), 0) #define ACTION_DEFAULT_LAYER_BIT_SET(part, bits) ACTION_LAYER_BITOP(OP_BIT_SET, (part), (bits), 0) -/** \brief Extensions - */ -enum backlight_opt { - BACKLIGHT_INCREASE = 0, - BACKLIGHT_DECREASE = 1, - BACKLIGHT_TOGGLE = 2, - BACKLIGHT_STEP = 3, - BACKLIGHT_ON = 4, - BACKLIGHT_OFF = 5, -}; - /* Macro */ #define ACTION_MACRO(id) ACTION(ACT_MACRO, (id)) #define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP << 8 | (id)) #define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt) << 8 | (id)) -/* Backlight */ -#define ACTION_BACKLIGHT_INCREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_INCREASE << 8) -#define ACTION_BACKLIGHT_DECREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_DECREASE << 8) -#define ACTION_BACKLIGHT_TOGGLE() ACTION(ACT_BACKLIGHT, BACKLIGHT_TOGGLE << 8) -#define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP << 8) -#define ACTION_BACKLIGHT_ON() ACTION(ACT_BACKLIGHT, BACKLIGHT_ON << 8) -#define ACTION_BACKLIGHT_OFF() ACTION(ACT_BACKLIGHT, BACKLIGHT_OFF << 8) /* Command */ #define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt) << 8 | (id)) /* Function */