Skip to content

Commit

Permalink
[Core] Move backlight keycode handling to process_keycode/ (qmk#7008)
Browse files Browse the repository at this point in the history
* Move backlight keycode handling to process_keycode/

* Switch keycode only when pressed

* Remove default case

* Add ChangeLog entry

* New breaking changes target date
  • Loading branch information
fauxpark authored and noroadsleft committed Feb 8, 2020
1 parent 1882fb0 commit 8e6b707
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 72 deletions.
1 change: 1 addition & 0 deletions common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,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
Expand Down
4 changes: 4 additions & 0 deletions docs/ChangeLog/20200229/PR7008.md
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 0 additions & 20 deletions quantum/keymap_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
51 changes: 51 additions & 0 deletions quantum/process_keycode/process_backlight.c
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#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;
}
21 changes: 21 additions & 0 deletions quantum/process_keycode/process_backlight.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "quantum.h"

bool process_backlight(uint16_t keycode, keyrecord_t *record);
3 changes: 3 additions & 0 deletions quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions quantum/quantum.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 0 additions & 26 deletions tmk_core/common/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 1 addition & 26 deletions tmk_core/common/action_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* 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
Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 8e6b707

Please sign in to comment.