New macro: ACTION_BACKLIGHT_LEVEL(level)

To have full control of the backlight level.
daktil_thumb_popravljen
Ralf Schmitt 2014-04-08 21:02:46 +02:00
parent 5c63751790
commit 589d99b448
8 changed files with 89 additions and 24 deletions

View File

@ -294,7 +294,7 @@ void process_action(keyrecord_t *record)
#ifdef BACKLIGHT_ENABLE #ifdef BACKLIGHT_ENABLE
case ACT_BACKLIGHT: case ACT_BACKLIGHT:
if (!event.pressed) { if (!event.pressed) {
switch (action.backlight.id) { switch (action.backlight.opt) {
case BACKLIGHT_INCREASE: case BACKLIGHT_INCREASE:
backlight_increase(); backlight_increase();
break; break;
@ -307,6 +307,9 @@ void process_action(keyrecord_t *record)
case BACKLIGHT_STEP: case BACKLIGHT_STEP:
backlight_step(); backlight_step();
break; break;
case BACKLIGHT_LEVEL:
backlight_level(action.backlight.level);
break;
} }
} }
break; break;

View File

@ -87,7 +87,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* 1100|1111| id(8) Macro record? * 1100|1111| id(8) Macro record?
* *
* ACT_BACKLIGHT(1101): * ACT_BACKLIGHT(1101):
* 1101|xxxx| id(8) Backlight commands * 1101|opt |level(8) Backlight commands
* *
* ACT_COMMAND(1110): * ACT_COMMAND(1110):
* 1110|opt | id(8) Built-in Command exec * 1110|opt | id(8) Built-in Command exec
@ -163,7 +163,9 @@ typedef union {
uint8_t kind :4; uint8_t kind :4;
} usage; } usage;
struct action_backlight { struct action_backlight {
uint8_t id :8; uint8_t level :8;
uint8_t opt :4;
uint8_t kind :4;
} backlight; } backlight;
struct action_command { struct action_command {
uint8_t id :8; uint8_t id :8;
@ -282,21 +284,23 @@ enum layer_pram_tap_op {
/* /*
* Extensions * Extensions
*/ */
enum backlight_id { enum backlight_opt {
BACKLIGHT_INCREASE = 0, BACKLIGHT_INCREASE = 0,
BACKLIGHT_DECREASE = 1, BACKLIGHT_DECREASE = 1,
BACKLIGHT_TOGGLE = 2, BACKLIGHT_TOGGLE = 2,
BACKLIGHT_STEP = 3, BACKLIGHT_STEP = 3,
BACKLIGHT_LEVEL = 4,
}; };
/* Macro */ /* Macro */
#define ACTION_MACRO(id) ACTION(ACT_MACRO, (id)) #define ACTION_MACRO(id) ACTION(ACT_MACRO, (id))
#define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (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)) #define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt)<<8 | (id))
/* Backlight */ /* Backlight */
#define ACTION_BACKLIGHT_INCREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_INCREASE) #define ACTION_BACKLIGHT_INCREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_INCREASE << 8)
#define ACTION_BACKLIGHT_DECREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_DECREASE) #define ACTION_BACKLIGHT_DECREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_DECREASE << 8)
#define ACTION_BACKLIGHT_TOGGLE() ACTION(ACT_BACKLIGHT, BACKLIGHT_TOGGLE) #define ACTION_BACKLIGHT_TOGGLE() ACTION(ACT_BACKLIGHT, BACKLIGHT_TOGGLE << 8)
#define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP) #define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP << 8)
#define ACTION_BACKLIGHT_LEVEL(level) ACTION(ACT_BACKLIGHT, BACKLIGHT_LEVEL << 8 | level)
/* Command */ /* Command */
#define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr)) #define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr))
/* Function */ /* Function */

View File

@ -75,3 +75,11 @@ void backlight_step(void)
dprintf("backlight step: %u\n", backlight_config.level); dprintf("backlight step: %u\n", backlight_config.level);
backlight_set(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);
}

View File

@ -24,18 +24,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
typedef union { typedef union {
uint8_t raw; uint8_t raw;
struct { struct {
bool enable:1; bool enable :1;
uint8_t level:7; uint8_t level :7;
}; };
} backlight_config_t; } backlight_config_t;
void backlight_init(void); void backlight_init(void);
void backlight_increase(void); void backlight_increase(void);
void backlight_decrease(void); void backlight_decrease(void);
void backlight_toggle(void); void backlight_toggle(void);
void backlight_step(void); void backlight_step(void);
void backlight_set(uint8_t level); void backlight_set(uint8_t level);
void backlight_level(uint8_t level);
#endif #endif

View File

@ -444,6 +444,10 @@ Step through backlight levels.
ACTION_BACKLIGHT_STEP() ACTION_BACKLIGHT_STEP()
Turn a specific backlight level on or off.
ACTION_BACKLIGHT_LEVEL(1)
#### 2.5.2 Turn on / off backlight #### 2.5.2 Turn on / off backlight
Turn the backlight on and off without changing level. Turn the backlight on and off without changing level.

View File

@ -26,8 +26,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* Backside PD6 (high) * Backside PD6 (high)
* TopRight PD7 (low) * TopRight PD7 (low)
* F-Row PE6 (high) * F-Row PE6 (high)
*
*/ */
void backlight_set(uint8_t level) void backlight_set(uint8_t level)
{ {
// Set as output. // Set as output.
@ -35,22 +35,52 @@ void backlight_set(uint8_t level)
DDRD |= (1<<6) | (1<<7); DDRD |= (1<<6) | (1<<7);
DDRE |= (1<<6); DDRE |= (1<<6);
if(level & (1<<0)) if (level & BACKLIGHT_ALPHA)
{ {
PORTB &= ~(1<<1); PORTB |= (1<<1);
PORTB &= ~(1<<2);
PORTB &= ~(1<<3);
PORTD &= ~(1<<6);
PORTD |= (1<<7);
PORTE &= ~(1<<6);
} }
else else
{ {
PORTB |= (1<<1); PORTB &= ~(1<<1);
}
if (level & BACKLIGHT_NUMERIC)
{
PORTB |= (1<<2); PORTB |= (1<<2);
}
else
{
PORTB &= ~(1<<2);
}
if (level & BACKLIGHT_MODNUM)
{
PORTB |= (1<<3); PORTB |= (1<<3);
}
else
{
PORTB &= ~(1<<3);
}
if (level & BACKLIGHT_BACKSIDE)
{
PORTD |= (1<<6); PORTD |= (1<<6);
}
else
{
PORTD &= ~(1<<6);
}
if (level & BACKLIGHT_TOPRIGHT)
{
PORTD &= ~(1<<7); PORTD &= ~(1<<7);
}
else
{
PORTD |= (1<<7);
}
if (level & BACKLIGHT_FROW)
{
PORTE |= (1<<6); PORTE |= (1<<6);
} }
else
{
PORTE &= ~(1<<6);
}
} }

View File

@ -0,0 +1,9 @@
enum backlight_level {
BACKLIGHT_ALPHA = 0b0000001,
BACKLIGHT_NUMERIC = 0b0000010,
BACKLIGHT_MODNUM = 0b0000100,
BACKLIGHT_BACKSIDE = 0b0001000,
BACKLIGHT_TOPRIGHT = 0b0010000,
BACKLIGHT_FROW = 0b0100000,
};

View File

@ -1,3 +1,5 @@
#include "backlight.h"
static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KEYMAP(\ KEYMAP(\
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, INS, PSCR, SLCK, BRK, \ ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, INS, PSCR, SLCK, BRK, \
@ -8,14 +10,20 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
LCTL,LGUI,LALT, SPC, NO, RALT,RGUI,RCTL, KP_0, NO, KP_DOT, NO), \ LCTL,LGUI,LALT, SPC, NO, RALT,RGUI,RCTL, KP_0, NO, KP_DOT, NO), \
KEYMAP(\ KEYMAP(\
CALC,MYCM,WSCH,WHOM,MAIL,MUTE,VOLD,VOLU,MSEL,MSTP,MPLY,MPRV,MNXT,TRNS, TRNS, WAKE, PWR, SLEP, \ CALC,MYCM,WSCH,WHOM,MAIL,MUTE,VOLD,VOLU,MSEL,MSTP,MPLY,MPRV,MNXT,TRNS, TRNS, WAKE, PWR, SLEP, \
TRNS,TRNS,TRNS,TRNS,END ,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \ FN1, FN2, FN3, FN4, FN5, FN6, FN7, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \ TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \
TRNS,TRNS,TRNS,TRNS,PGDN,TRNS,LEFT,DOWN,UP ,RGHT,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \ TRNS,TRNS,TRNS,TRNS,PGDN,TRNS,LEFT,DOWN,UP ,RGHT,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \
TRNS, TRNS,TRNS,TRNS,TRNS,PGUP,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \ TRNS, TRNS,TRNS,TRNS,TRNS,PGUP,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \
TRNS,TRNS,TRNS, FN1, TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS) TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS)
}; };
static const uint16_t PROGMEM fn_actions[] = { static const uint16_t PROGMEM fn_actions[] = {
[0] = ACTION_LAYER_MOMENTARY(1), [0] = ACTION_LAYER_MOMENTARY(1),
[1] = ACTION_BACKLIGHT_STEP() [1] = ACTION_BACKLIGHT_TOGGLE(),
[2] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_ALPHA),
[3] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_MODNUM),
[4] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_NUMERIC),
[5] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_FROW),
[6] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_BACKSIDE),
[7] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_TOPRIGHT)
}; };