aboutsummaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/backlight/backlight.c194
-rw-r--r--quantum/backlight/backlight.h62
-rw-r--r--quantum/keymap_common.c5
-rw-r--r--quantum/quantum.c6
4 files changed, 263 insertions, 4 deletions
diff --git a/quantum/backlight/backlight.c b/quantum/backlight/backlight.c
index e26de86bf..708022f68 100644
--- a/quantum/backlight/backlight.c
+++ b/quantum/backlight/backlight.c
@@ -1 +1,193 @@
1// TODO: Add common code here, for example cie_lightness implementation 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
24/** \brief Backlight initialization
25 *
26 * FIXME: needs doc
27 */
28void backlight_init(void) {
29 /* check signature */
30 if (!eeconfig_is_enabled()) {
31 eeconfig_init();
32 }
33 backlight_config.raw = eeconfig_read_backlight();
34 if (backlight_config.level > BACKLIGHT_LEVELS) {
35 backlight_config.level = BACKLIGHT_LEVELS;
36 }
37 backlight_set(backlight_config.enable ? backlight_config.level : 0);
38}
39
40/** \brief Backlight increase
41 *
42 * FIXME: needs doc
43 */
44void backlight_increase(void) {
45 if (backlight_config.level < BACKLIGHT_LEVELS) {
46 backlight_config.level++;
47 }
48 backlight_config.enable = 1;
49 eeconfig_update_backlight(backlight_config.raw);
50 dprintf("backlight increase: %u\n", backlight_config.level);
51 backlight_set(backlight_config.level);
52}
53
54/** \brief Backlight decrease
55 *
56 * FIXME: needs doc
57 */
58void backlight_decrease(void) {
59 if (backlight_config.level > 0) {
60 backlight_config.level--;
61 backlight_config.enable = !!backlight_config.level;
62 eeconfig_update_backlight(backlight_config.raw);
63 }
64 dprintf("backlight decrease: %u\n", backlight_config.level);
65 backlight_set(backlight_config.level);
66}
67
68/** \brief Backlight toggle
69 *
70 * FIXME: needs doc
71 */
72void backlight_toggle(void) {
73 bool enabled = backlight_config.enable;
74 dprintf("backlight toggle: %u\n", enabled);
75 if (enabled)
76 backlight_disable();
77 else
78 backlight_enable();
79}
80
81/** \brief Enable backlight
82 *
83 * FIXME: needs doc
84 */
85void backlight_enable(void) {
86 if (backlight_config.enable) return; // do nothing if backlight is already on
87
88 backlight_config.enable = true;
89 if (backlight_config.raw == 1) // enabled but level == 0
90 backlight_config.level = 1;
91 eeconfig_update_backlight(backlight_config.raw);
92 dprintf("backlight enable\n");
93 backlight_set(backlight_config.level);
94}
95
96/** \brief Disable backlight
97 *
98 * FIXME: needs doc
99 */
100void backlight_disable(void) {
101 if (!backlight_config.enable) return; // do nothing if backlight is already off
102
103 backlight_config.enable = false;
104 eeconfig_update_backlight(backlight_config.raw);
105 dprintf("backlight disable\n");
106 backlight_set(0);
107}
108
109/** /brief Get the backlight status
110 *
111 * FIXME: needs doc
112 */
113bool is_backlight_enabled(void) { return backlight_config.enable; }
114
115/** \brief Backlight step through levels
116 *
117 * FIXME: needs doc
118 */
119void backlight_step(void) {
120 backlight_config.level++;
121 if (backlight_config.level > BACKLIGHT_LEVELS) {
122 backlight_config.level = 0;
123 }
124 backlight_config.enable = !!backlight_config.level;
125 eeconfig_update_backlight(backlight_config.raw);
126 dprintf("backlight step: %u\n", backlight_config.level);
127 backlight_set(backlight_config.level);
128}
129
130/** \brief Backlight set level
131 *
132 * FIXME: needs doc
133 */
134void backlight_level(uint8_t level) {
135 if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS;
136 backlight_config.level = level;
137 backlight_config.enable = !!backlight_config.level;
138 eeconfig_update_backlight(backlight_config.raw);
139 backlight_set(backlight_config.level);
140}
141
142/** \brief Get backlight level
143 *
144 * FIXME: needs doc
145 */
146uint8_t get_backlight_level(void) { return backlight_config.level; }
147
148#ifdef BACKLIGHT_BREATHING
149/** \brief Backlight breathing toggle
150 *
151 * FIXME: needs doc
152 */
153void backlight_toggle_breathing(void) {
154 bool breathing = backlight_config.breathing;
155 dprintf("backlight breathing toggle: %u\n", breathing);
156 if (breathing)
157 backlight_disable_breathing();
158 else
159 backlight_enable_breathing();
160}
161
162/** \brief Enable backlight breathing
163 *
164 * FIXME: needs doc
165 */
166void backlight_enable_breathing(void) {
167 if (backlight_config.breathing) return; // do nothing if breathing is already on
168
169 backlight_config.breathing = true;
170 eeconfig_update_backlight(backlight_config.raw);
171 dprintf("backlight breathing enable\n");
172 breathing_enable();
173}
174
175/** \brief Disable backlight breathing
176 *
177 * FIXME: needs doc
178 */
179void backlight_disable_breathing(void) {
180 if (!backlight_config.breathing) return; // do nothing if breathing is already off
181
182 backlight_config.breathing = false;
183 eeconfig_update_backlight(backlight_config.raw);
184 dprintf("backlight breathing disable\n");
185 breathing_disable();
186}
187
188/** \brief Get the backlight breathing status
189 *
190 * FIXME: needs doc
191 */
192bool is_backlight_breathing(void) { return backlight_config.breathing; }
193#endif
diff --git a/quantum/backlight/backlight.h b/quantum/backlight/backlight.h
new file mode 100644
index 000000000..1e581055d
--- /dev/null
+++ b/quantum/backlight/backlight.h
@@ -0,0 +1,62 @@
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#pragma once
19
20#include <stdint.h>
21#include <stdbool.h>
22
23#ifndef BACKLIGHT_LEVELS
24# define BACKLIGHT_LEVELS 3
25#elif BACKLIGHT_LEVELS > 31
26# error "Maximum value of BACKLIGHT_LEVELS is 31"
27#endif
28
29#ifndef BREATHING_PERIOD
30# define BREATHING_PERIOD 6
31#endif
32
33typedef union {
34 uint8_t raw;
35 struct {
36 bool enable : 1;
37 bool breathing : 1;
38 uint8_t reserved : 1; // Reserved for possible future backlight modes
39 uint8_t level : 5;
40 };
41} backlight_config_t;
42
43void backlight_init(void);
44void backlight_increase(void);
45void backlight_decrease(void);
46void backlight_toggle(void);
47void backlight_enable(void);
48void backlight_disable(void);
49bool is_backlight_enabled(void);
50void backlight_step(void);
51void backlight_set(uint8_t level);
52void backlight_level(uint8_t level);
53uint8_t get_backlight_level(void);
54
55#ifdef BACKLIGHT_BREATHING
56void backlight_toggle_breathing(void);
57void backlight_enable_breathing(void);
58void backlight_disable_breathing(void);
59bool is_backlight_breathing(void);
60void breathing_enable(void);
61void breathing_disable(void);
62#endif
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 9af951008..4fa45ac37 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -26,9 +26,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
26#include "action.h" 26#include "action.h"
27#include "action_macro.h" 27#include "action_macro.h"
28#include "debug.h" 28#include "debug.h"
29#include "backlight.h"
30#include "quantum.h" 29#include "quantum.h"
31 30
31#ifdef BACKLIGHT_ENABLE
32# include "backlight.h"
33#endif
34
32#ifdef MIDI_ENABLE 35#ifdef MIDI_ENABLE
33# include "process_midi.h" 36# include "process_midi.h"
34#endif 37#endif
diff --git a/quantum/quantum.c b/quantum/quantum.c
index e615cfc0f..2020770ea 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -24,8 +24,10 @@
24# include "outputselect.h" 24# include "outputselect.h"
25#endif 25#endif
26 26
27#include "backlight.h" 27#ifdef BACKLIGHT_ENABLE
28extern backlight_config_t backlight_config; 28# include "backlight.h"
29 extern backlight_config_t backlight_config;
30#endif
29 31
30#ifdef FAUXCLICKY_ENABLE 32#ifdef FAUXCLICKY_ENABLE
31# include "fauxclicky.h" 33# include "fauxclicky.h"