]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/common/backlight.c
Generate API docs from source code comments (#2491)
[qmk_firmware.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 /** \brief Backlight initialization
25  *
26  * FIXME: needs doc
27  */
28 void backlight_init(void)
29 {
30     /* check signature */
31     if (!eeconfig_is_enabled()) {
32         eeconfig_init();
33     }
34     backlight_config.raw = eeconfig_read_backlight();
35     if (backlight_config.level > BACKLIGHT_LEVELS) {
36        backlight_config.level = BACKLIGHT_LEVELS;
37     }
38     backlight_set(backlight_config.enable ? backlight_config.level : 0);
39 }
40
41 /** \brief Backlight increase
42  *
43  * FIXME: needs doc
44  */
45 void backlight_increase(void)
46 {
47     if(backlight_config.level < BACKLIGHT_LEVELS)
48     {
49         backlight_config.level++;
50     }
51     backlight_config.enable = 1;
52     eeconfig_update_backlight(backlight_config.raw);
53     dprintf("backlight increase: %u\n", backlight_config.level);
54     backlight_set(backlight_config.level);
55 }
56
57 /** \brief Backlight decrease
58  *
59  * FIXME: needs doc
60  */
61 void backlight_decrease(void)
62 {
63     if(backlight_config.level > 0)
64     {
65         backlight_config.level--;
66         backlight_config.enable = !!backlight_config.level;
67         eeconfig_update_backlight(backlight_config.raw);
68     }
69     dprintf("backlight decrease: %u\n", backlight_config.level);
70     backlight_set(backlight_config.level);
71 }
72
73 /** \brief Backlight toggle
74  *
75  * FIXME: needs doc
76  */
77 void backlight_toggle(void)
78 {
79     backlight_config.enable ^= 1;
80     if (backlight_config.raw == 1) // enabled but level = 0
81         backlight_config.level = 1;
82     eeconfig_update_backlight(backlight_config.raw);
83     dprintf("backlight toggle: %u\n", backlight_config.enable);
84     backlight_set(backlight_config.enable ? backlight_config.level : 0);
85 }
86
87 /** \brief Backlight step through levels
88  *
89  * FIXME: needs doc
90  */
91 void backlight_step(void)
92 {
93     backlight_config.level++;
94     if(backlight_config.level > BACKLIGHT_LEVELS)
95     {
96         backlight_config.level = 0;
97     }
98     backlight_config.enable = !!backlight_config.level;
99     eeconfig_update_backlight(backlight_config.raw);
100     dprintf("backlight step: %u\n", backlight_config.level);
101     backlight_set(backlight_config.level);
102 }
103
104 /** \brief Backlight set level
105  *
106  * FIXME: needs doc
107  */
108 void backlight_level(uint8_t level)
109 {
110     if (level > BACKLIGHT_LEVELS)
111         level = BACKLIGHT_LEVELS;
112     backlight_config.level = level;
113     backlight_config.enable = !!backlight_config.level;
114     eeconfig_update_backlight(backlight_config.raw);
115     backlight_set(backlight_config.level);
116 }
117
118 /** \brief Get backlight level
119  *
120  * FIXME: needs doc
121  */
122 uint8_t get_backlight_level(void)
123 {
124     return backlight_config.level;
125 }