]> git.gir.st - tmk_keyboard.git/blob - tmk_core/common/backlight.c
core: Fix sleep_led
[tmk_keyboard.git] / tmk_core / common / backlight.c
1 /*
2 Copyright 2013 Mathias Andersson <wraul@dbox.se>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along 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
22 backlight_config_t backlight_config;
23
24 void 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
34 void 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
46 void 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
58 void 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
66 void 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 }
78
79 void backlight_level(uint8_t level)
80 {
81 backlight_config.level ^= level;
82 backlight_config.enable = !!backlight_config.level;
83 eeconfig_write_backlight(backlight_config.raw);
84 backlight_set(backlight_config.level);
85 }
Imprint / Impressum