aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--common.mk5
-rw-r--r--common/action.c21
-rw-r--r--common/action_code.h18
-rw-r--r--common/backlight.c77
-rw-r--r--common/backlight.h41
-rw-r--r--common/command.c7
-rw-r--r--common/eeconfig.c4
-rw-r--r--common/eeconfig.h5
-rw-r--r--common/keyboard.c5
-rw-r--r--common/suspend.c7
-rw-r--r--doc/build.md1
-rw-r--r--doc/keymap.md21
13 files changed, 213 insertions, 0 deletions
diff --git a/README.md b/README.md
index d4793e9bf..5065f2788 100644
--- a/README.md
+++ b/README.md
@@ -23,6 +23,7 @@ These features can be used in your keyboard.
23* Virtual DIP Switch - Configurations stored EEPROM(Boot Magic) 23* Virtual DIP Switch - Configurations stored EEPROM(Boot Magic)
24* Locking CapsLock - Mechanical switch support for CapsLock 24* Locking CapsLock - Mechanical switch support for CapsLock
25* Breathing Sleep LED - Sleep indicator with charm during USB suspend 25* Breathing Sleep LED - Sleep indicator with charm during USB suspend
26* Backlight - Control backlight levels
26 27
27 28
28Projects 29Projects
diff --git a/common.mk b/common.mk
index 5f47e5c1b..47d5c852f 100644
--- a/common.mk
+++ b/common.mk
@@ -63,6 +63,11 @@ ifdef SLEEP_LED_ENABLE
63 OPT_DEFS += -DNO_SUSPEND_POWER_DOWN 63 OPT_DEFS += -DNO_SUSPEND_POWER_DOWN
64endif 64endif
65 65
66ifdef BACKLIGHT_ENABLE
67 SRC += $(COMMON_DIR)/backlight.c
68 OPT_DEFS += -DBACKLIGHT_ENABLE
69endif
70
66 71
67# Search Path 72# Search Path
68VPATH += $(TOP_DIR)/common 73VPATH += $(TOP_DIR)/common
diff --git a/common/action.c b/common/action.c
index c7c8f71f2..b1fa0e31c 100644
--- a/common/action.c
+++ b/common/action.c
@@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20#include "mousekey.h" 20#include "mousekey.h"
21#include "command.h" 21#include "command.h"
22#include "led.h" 22#include "led.h"
23#include "backlight.h"
23#include "action_layer.h" 24#include "action_layer.h"
24#include "action_tapping.h" 25#include "action_tapping.h"
25#include "action_oneshot.h" 26#include "action_oneshot.h"
@@ -292,6 +293,26 @@ void process_action(keyrecord_t *record)
292 action_macro_play(action_get_macro(record, action.func.id, action.func.opt)); 293 action_macro_play(action_get_macro(record, action.func.id, action.func.opt));
293 break; 294 break;
294#endif 295#endif
296#ifdef BACKLIGHT_ENABLE
297 case ACT_BACKLIGHT:
298 if (!event.pressed) {
299 switch (action.backlight.id) {
300 case BACKLIGHT_INCREASE:
301 backlight_increase();
302 break;
303 case BACKLIGHT_DECREASE:
304 backlight_decrease();
305 break;
306 case BACKLIGHT_TOGGLE:
307 backlight_toggle();
308 break;
309 case BACKLIGHT_STEP:
310 backlight_step();
311 break;
312 }
313 }
314 break;
315#endif
295 case ACT_COMMAND: 316 case ACT_COMMAND:
296 break; 317 break;
297#ifndef NO_ACTION_FUNCTION 318#ifndef NO_ACTION_FUNCTION
diff --git a/common/action_code.h b/common/action_code.h
index 0933dce13..d28b74f84 100644
--- a/common/action_code.h
+++ b/common/action_code.h
@@ -85,6 +85,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
85 * 1100|opt | id(8) Macro play? 85 * 1100|opt | id(8) Macro play?
86 * 1100|1111| id(8) Macro record? 86 * 1100|1111| id(8) Macro record?
87 * 87 *
88 * ACT_BACKLIGHT(1101):
89 * 1110|xxxx| id(8) Backlight commands
90 *
88 * ACT_COMMAND(1110): 91 * ACT_COMMAND(1110):
89 * 1110|opt | id(8) Built-in Command exec 92 * 1110|opt | id(8) Built-in Command exec
90 * 93 *
@@ -109,6 +112,7 @@ enum action_kind_id {
109 ACT_LAYER_TAP1 = 0b1011, 112 ACT_LAYER_TAP1 = 0b1011,
110 /* Extensions */ 113 /* Extensions */
111 ACT_MACRO = 0b1100, 114 ACT_MACRO = 0b1100,
115 ACT_BACKLIGHT = 0b1101,
112 ACT_COMMAND = 0b1110, 116 ACT_COMMAND = 0b1110,
113 ACT_FUNCTION = 0b1111 117 ACT_FUNCTION = 0b1111
114}; 118};
@@ -157,6 +161,9 @@ typedef union {
157 uint8_t page :2; 161 uint8_t page :2;
158 uint8_t kind :4; 162 uint8_t kind :4;
159 } usage; 163 } usage;
164 struct action_backlight {
165 uint8_t id :8;
166 } backlight;
160 struct action_command { 167 struct action_command {
161 uint8_t id :8; 168 uint8_t id :8;
162 uint8_t opt :4; 169 uint8_t opt :4;
@@ -272,10 +279,21 @@ enum layer_pram_tap_op {
272/* 279/*
273 * Extensions 280 * Extensions
274 */ 281 */
282enum backlight_id {
283 BACKLIGHT_INCREASE = 0,
284 BACKLIGHT_DECREASE = 1,
285 BACKLIGHT_TOGGLE = 2,
286 BACKLIGHT_STEP = 3,
287};
275/* Macro */ 288/* Macro */
276#define ACTION_MACRO(id) ACTION(ACT_MACRO, (id)) 289#define ACTION_MACRO(id) ACTION(ACT_MACRO, (id))
277#define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id)) 290#define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id))
278#define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt)<<8 | (id)) 291#define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt)<<8 | (id))
292/* Backlight */
293#define ACTION_BACKLIGHT_INCREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_INCREASE)
294#define ACTION_BACKLIGHT_DECREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_DECREASE)
295#define ACTION_BACKLIGHT_TOGGLE() ACTION(ACT_BACKLIGHT, BACKLIGHT_TOGGLE)
296#define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP)
279/* Command */ 297/* Command */
280#define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr)) 298#define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr))
281/* Function */ 299/* Function */
diff --git a/common/backlight.c b/common/backlight.c
new file mode 100644
index 000000000..00dc04a07
--- /dev/null
+++ b/common/backlight.c
@@ -0,0 +1,77 @@
1/*
2Copyright 2013 Mathias Andersson <wraul@dbox.se>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "backlight.h"
19#include "eeconfig.h"
20#include "debug.h"
21
22backlight_config_t backlight_config;
23
24void backlight_init(void)
25{
26 /* check signature */
27 if (!eeconfig_is_enabled()) {
28 eeconfig_init();
29 }
30 backlight_config.raw = eeconfig_read_backlight();
31 backlight_set(backlight_config.enable ? backlight_config.level : 0);
32}
33
34void backlight_increase(void)
35{
36 if(backlight_config.level < BACKLIGHT_LEVELS)
37 {
38 backlight_config.level++;
39 backlight_config.enable = 1;
40 eeconfig_write_backlight(backlight_config.raw);
41 }
42 dprintf("backlight increase: %u\n", backlight_config.level);
43 backlight_set(backlight_config.level);
44}
45
46void backlight_decrease(void)
47{
48 if(backlight_config.level > 0)
49 {
50 backlight_config.level--;
51 backlight_config.enable = !!backlight_config.level;
52 eeconfig_write_backlight(backlight_config.raw);
53 }
54 dprintf("backlight decrease: %u\n", backlight_config.level);
55 backlight_set(backlight_config.level);
56}
57
58void backlight_toggle(void)
59{
60 backlight_config.enable ^= 1;
61 eeconfig_write_backlight(backlight_config.raw);
62 dprintf("backlight toggle: %u\n", backlight_config.enable);
63 backlight_set(backlight_config.enable ? backlight_config.level : 0);
64}
65
66void backlight_step(void)
67{
68 backlight_config.level++;
69 if(backlight_config.level > BACKLIGHT_LEVELS)
70 {
71 backlight_config.level = 0;
72 }
73 backlight_config.enable = !!backlight_config.level;
74 eeconfig_write_backlight(backlight_config.raw);
75 dprintf("backlight step: %u\n", backlight_config.level);
76 backlight_set(backlight_config.level);
77}
diff --git a/common/backlight.h b/common/backlight.h
new file mode 100644
index 000000000..685c422ae
--- /dev/null
+++ b/common/backlight.h
@@ -0,0 +1,41 @@
1/*
2Copyright 2013 Mathias Andersson <wraul@dbox.se>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef BACKLIGHT_H
19#define BACKLIGHT_H
20
21#include <stdint.h>
22#include <stdbool.h>
23
24typedef union {
25 uint8_t raw;
26 struct {
27 bool enable:1;
28 uint8_t level:7;
29 };
30} backlight_config_t;
31
32void backlight_init(void);
33
34void backlight_increase(void);
35void backlight_decrease(void);
36void backlight_toggle(void);
37void backlight_step(void);
38
39void backlight_set(uint8_t level);
40
41#endif
diff --git a/common/command.c b/common/command.c
index 73a72b4a1..bcf1b4937 100644
--- a/common/command.c
+++ b/common/command.c
@@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
31#include "sleep_led.h" 31#include "sleep_led.h"
32#include "led.h" 32#include "led.h"
33#include "command.h" 33#include "command.h"
34#include "backlight.h"
34 35
35#ifdef MOUSEKEY_ENABLE 36#ifdef MOUSEKEY_ENABLE
36#include "mousekey.h" 37#include "mousekey.h"
@@ -149,6 +150,12 @@ static void print_eeconfig(void)
149 print(".no_gui: "); print_dec(kc.no_gui); print("\n"); 150 print(".no_gui: "); print_dec(kc.no_gui); print("\n");
150 print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n"); 151 print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n");
151 print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n"); 152 print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n");
153
154 backlight_config_t bc;
155 bc.raw = eeconfig_read_backlight();
156 print("backlight_config.raw: "); print_hex8(bc.raw); print("\n");
157 print(".enable: "); print_dec(bc.enable); print("\n");
158 print(".level: "); print_dec(bc.level); print("\n");
152} 159}
153#endif 160#endif
154 161
diff --git a/common/eeconfig.c b/common/eeconfig.c
index a833f4db9..7af29ec10 100644
--- a/common/eeconfig.c
+++ b/common/eeconfig.c
@@ -10,6 +10,7 @@ void eeconfig_init(void)
10 eeprom_write_byte(EECONFIG_DEFAULT_LAYER, 0); 10 eeprom_write_byte(EECONFIG_DEFAULT_LAYER, 0);
11 eeprom_write_byte(EECONFIG_KEYMAP, 0); 11 eeprom_write_byte(EECONFIG_KEYMAP, 0);
12 eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0); 12 eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0);
13 eeprom_write_byte(EECONFIG_BACKLIGHT, 0);
13} 14}
14 15
15void eeconfig_enable(void) 16void eeconfig_enable(void)
@@ -35,3 +36,6 @@ void eeconfig_write_default_layer(uint8_t val) { eeprom_write_byte(EECONFIG_DEFA
35 36
36uint8_t eeconfig_read_keymap(void) { return eeprom_read_byte(EECONFIG_KEYMAP); } 37uint8_t eeconfig_read_keymap(void) { return eeprom_read_byte(EECONFIG_KEYMAP); }
37void eeconfig_write_keymap(uint8_t val) { eeprom_write_byte(EECONFIG_KEYMAP, val); } 38void eeconfig_write_keymap(uint8_t val) { eeprom_write_byte(EECONFIG_KEYMAP, val); }
39
40uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); }
41void eeconfig_write_backlight(uint8_t val) { eeprom_write_byte(EECONFIG_BACKLIGHT, val); }
diff --git a/common/eeconfig.h b/common/eeconfig.h
index 0b605fc7b..f0acce01c 100644
--- a/common/eeconfig.h
+++ b/common/eeconfig.h
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19#define EECONFIG_H 19#define EECONFIG_H
20 20
21#include <stdint.h> 21#include <stdint.h>
22#include <stdbool.h>
22 23
23 24
24#define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED 25#define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED
@@ -29,6 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
29#define EECONFIG_DEFAULT_LAYER (uint8_t *)3 30#define EECONFIG_DEFAULT_LAYER (uint8_t *)3
30#define EECONFIG_KEYMAP (uint8_t *)4 31#define EECONFIG_KEYMAP (uint8_t *)4
31#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 32#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5
33#define EECONFIG_BACKLIGHT (uint8_t *)6
32 34
33 35
34/* debug bit */ 36/* debug bit */
@@ -64,4 +66,7 @@ void eeconfig_write_default_layer(uint8_t val);
64uint8_t eeconfig_read_keymap(void); 66uint8_t eeconfig_read_keymap(void);
65void eeconfig_write_keymap(uint8_t val); 67void eeconfig_write_keymap(uint8_t val);
66 68
69uint8_t eeconfig_read_backlight(void);
70void eeconfig_write_backlight(uint8_t val);
71
67#endif 72#endif
diff --git a/common/keyboard.c b/common/keyboard.c
index 6bc6fae6e..d1821a099 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
31#include "bootmagic.h" 31#include "bootmagic.h"
32#include "eeconfig.h" 32#include "eeconfig.h"
33#include "mousekey.h" 33#include "mousekey.h"
34#include "backlight.h"
34 35
35 36
36#ifdef MATRIX_HAS_GHOST 37#ifdef MATRIX_HAS_GHOST
@@ -65,6 +66,10 @@ void keyboard_init(void)
65#ifdef BOOTMAGIC_ENABLE 66#ifdef BOOTMAGIC_ENABLE
66 bootmagic(); 67 bootmagic();
67#endif 68#endif
69
70#ifdef BACKLIGHT_ENABLE
71 backlight_init();
72#endif
68} 73}
69 74
70/* 75/*
diff --git a/common/suspend.c b/common/suspend.c
index 6029fe7ff..146b96d5c 100644
--- a/common/suspend.c
+++ b/common/suspend.c
@@ -1,10 +1,14 @@
1#include "suspend.h" 1#include "suspend.h"
2#include "matrix.h" 2#include "matrix.h"
3#include "action.h" 3#include "action.h"
4#include "backlight.h"
4 5
5 6
6void suspend_power_down(void) 7void suspend_power_down(void)
7{ 8{
9#ifdef BACKLIGHT_ENABLE
10 backlight_set(0);
11#endif
8#ifndef NO_SUSPEND_POWER_DOWN 12#ifndef NO_SUSPEND_POWER_DOWN
9 // Enable watchdog to wake from MCU sleep 13 // Enable watchdog to wake from MCU sleep
10 cli(); 14 cli();
@@ -50,6 +54,9 @@ void suspend_wakeup_init(void)
50 // clear matrix and keyboard state 54 // clear matrix and keyboard state
51 matrix_init(); 55 matrix_init();
52 clear_keyboard(); 56 clear_keyboard();
57#ifdef BACKLIGHT_ENABLE
58 backlight_init();
59#endif
53} 60}
54 61
55#ifndef NO_SUSPEND_POWER_DOWN 62#ifndef NO_SUSPEND_POWER_DOWN
diff --git a/doc/build.md b/doc/build.md
index 88504f096..ae8565010 100644
--- a/doc/build.md
+++ b/doc/build.md
@@ -132,6 +132,7 @@ Optional. Note that ***comment out*** to disable them.
132 COMMAND_ENABLE = yes # Commands for debug and configuration 132 COMMAND_ENABLE = yes # Commands for debug and configuration
133 SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend 133 SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
134 #NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA 134 #NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA
135 #BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
135 136
136### 3. Programmer 137### 3. Programmer
137Optional. Set proper command for your controller, bootloader and programmer. This command can be used with `make program`. Not needed if you use `FLIP`, `dfu-programmer` or `Teesy Loader`. 138Optional. Set proper command for your controller, bootloader and programmer. This command can be used with `make program`. Not needed if you use `FLIP`, `dfu-programmer` or `Teesy Loader`.
diff --git a/doc/keymap.md b/doc/keymap.md
index 474a706e0..7d979eb7c 100644
--- a/doc/keymap.md
+++ b/doc/keymap.md
@@ -430,6 +430,27 @@ See `keyboard/hhkb/keymap.c` for sample.
430 430
431 431
432 432
433### 2.5 Backlight Action
434These actions control the backlight.
435
436#### 2.5.1 Change backlight level
437Increase backlight level.
438
439 ACTION_BACKLIGHT_INCREASE()
440
441Decrease backlight level.
442
443 ACTION_BACKLIGHT_DECREASE()
444
445Step through backlight levels.
446
447 ACTION_BACKLIGHT_STEP()
448
449#### 2.5.2 Turn on / off backlight
450Turn the backlight on and off without changing level.
451
452 ACTION_BACKLIGHT_TOGGLE()
453
433 454
434 455
435## 3. Layer switching Example 456## 3. Layer switching Example