aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common/backlight.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common/backlight.c')
-rw-r--r--tmk_core/common/backlight.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/tmk_core/common/backlight.c b/tmk_core/common/backlight.c
new file mode 100644
index 000000000..558ad9b01
--- /dev/null
+++ b/tmk_core/common/backlight.c
@@ -0,0 +1,85 @@
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}
78
79void 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}