From b5fb2dbc1ed53d2e6756b5b03566a7cb3efbcc94 Mon Sep 17 00:00:00 2001 From: Ralf Schmitt Date: Tue, 8 Apr 2014 21:02:46 +0200 Subject: [PATCH] New macro: ACTION_BACKLIGHT_LEVEL(level) To have full control of the backlight level. --- common/action.c | 5 ++++- common/action_code.h | 18 +++++++++++------- common/backlight.c | 8 ++++++++ common/backlight.h | 7 +++---- doc/keymap.md | 4 ++++ 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/common/action.c b/common/action.c index e6938f5a..fddb97c5 100644 --- a/common/action.c +++ b/common/action.c @@ -294,7 +294,7 @@ void process_action(keyrecord_t *record) #ifdef BACKLIGHT_ENABLE case ACT_BACKLIGHT: if (!event.pressed) { - switch (action.backlight.id) { + switch (action.backlight.opt) { case BACKLIGHT_INCREASE: backlight_increase(); break; @@ -307,6 +307,9 @@ void process_action(keyrecord_t *record) case BACKLIGHT_STEP: backlight_step(); break; + case BACKLIGHT_LEVEL: + backlight_level(action.backlight.level); + break; } } break; diff --git a/common/action_code.h b/common/action_code.h index 8df86b11..50112d4d 100644 --- a/common/action_code.h +++ b/common/action_code.h @@ -87,7 +87,7 @@ along with this program. If not, see . * 1100|1111| id(8) Macro record? * * ACT_BACKLIGHT(1101): - * 1101|xxxx| id(8) Backlight commands + * 1101|opt |level(8) Backlight commands * * ACT_COMMAND(1110): * 1110|opt | id(8) Built-in Command exec @@ -163,7 +163,9 @@ typedef union { uint8_t kind :4; } usage; struct action_backlight { - uint8_t id :8; + uint8_t level :8; + uint8_t opt :4; + uint8_t kind :4; } backlight; struct action_command { uint8_t id :8; @@ -282,21 +284,23 @@ enum layer_pram_tap_op { /* * Extensions */ -enum backlight_id { +enum backlight_opt { BACKLIGHT_INCREASE = 0, BACKLIGHT_DECREASE = 1, BACKLIGHT_TOGGLE = 2, BACKLIGHT_STEP = 3, + BACKLIGHT_LEVEL = 4, }; /* 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) -#define ACTION_BACKLIGHT_DECREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_DECREASE) -#define ACTION_BACKLIGHT_TOGGLE() ACTION(ACT_BACKLIGHT, BACKLIGHT_TOGGLE) -#define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP) +#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_LEVEL(level) ACTION(ACT_BACKLIGHT, BACKLIGHT_LEVEL << 8 | level) /* Command */ #define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr)) /* Function */ diff --git a/common/backlight.c b/common/backlight.c index 00dc04a0..558ad9b0 100644 --- a/common/backlight.c +++ b/common/backlight.c @@ -75,3 +75,11 @@ void backlight_step(void) dprintf("backlight step: %u\n", backlight_config.level); backlight_set(backlight_config.level); } + +void backlight_level(uint8_t level) +{ + backlight_config.level ^= level; + backlight_config.enable = !!backlight_config.level; + eeconfig_write_backlight(backlight_config.raw); + backlight_set(backlight_config.level); +} diff --git a/common/backlight.h b/common/backlight.h index 685c422a..525ec8bb 100644 --- a/common/backlight.h +++ b/common/backlight.h @@ -24,18 +24,17 @@ along with this program. If not, see . typedef union { uint8_t raw; struct { - bool enable:1; - uint8_t level:7; + bool enable :1; + uint8_t level :7; }; } backlight_config_t; void backlight_init(void); - void backlight_increase(void); void backlight_decrease(void); void backlight_toggle(void); void backlight_step(void); - void backlight_set(uint8_t level); +void backlight_level(uint8_t level); #endif diff --git a/doc/keymap.md b/doc/keymap.md index 3d78fc9c..11feeac2 100644 --- a/doc/keymap.md +++ b/doc/keymap.md @@ -444,6 +444,10 @@ Step through backlight levels. ACTION_BACKLIGHT_STEP() +Turn a specific backlight level on or off. + + ACTION_BACKLIGHT_LEVEL(1) + #### 2.5.2 Turn on / off backlight Turn the backlight on and off without changing level.