aboutsummaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/common.mk5
-rw-r--r--tmk_core/common/action.c5
-rw-r--r--tmk_core/common/avr/suspend.c5
-rw-r--r--tmk_core/common/backlight.c193
-rw-r--r--tmk_core/common/backlight.h62
-rw-r--r--tmk_core/common/chibios/suspend.c5
-rw-r--r--tmk_core/common/command.c5
-rw-r--r--tmk_core/common/keyboard.c4
8 files changed, 19 insertions, 265 deletions
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index 221688755..db5535346 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -153,11 +153,6 @@ ifeq ($(strip $(NO_SUSPEND_POWER_DOWN)), yes)
153 TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN 153 TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN
154endif 154endif
155 155
156ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
157 TMK_COMMON_SRC += $(COMMON_DIR)/backlight.c
158 TMK_COMMON_DEFS += -DBACKLIGHT_ENABLE
159endif
160
161ifeq ($(strip $(BLUETOOTH_ENABLE)), yes) 156ifeq ($(strip $(BLUETOOTH_ENABLE)), yes)
162 TMK_COMMON_DEFS += -DBLUETOOTH_ENABLE 157 TMK_COMMON_DEFS += -DBLUETOOTH_ENABLE
163 TMK_COMMON_DEFS += -DNO_USB_STARTUP_CHECK 158 TMK_COMMON_DEFS += -DNO_USB_STARTUP_CHECK
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index 44b19d368..bd6aeba4f 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -20,7 +20,6 @@ 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"
24#include "action_layer.h" 23#include "action_layer.h"
25#include "action_tapping.h" 24#include "action_tapping.h"
26#include "action_macro.h" 25#include "action_macro.h"
@@ -28,6 +27,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
28#include "action.h" 27#include "action.h"
29#include "wait.h" 28#include "wait.h"
30 29
30#ifdef BACKLIGHT_ENABLE
31# include "backlight.h"
32#endif
33
31#ifdef DEBUG_ACTION 34#ifdef DEBUG_ACTION
32# include "debug.h" 35# include "debug.h"
33#else 36#else
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c
index 574000fcd..c59c19688 100644
--- a/tmk_core/common/avr/suspend.c
+++ b/tmk_core/common/avr/suspend.c
@@ -4,7 +4,6 @@
4#include <avr/interrupt.h> 4#include <avr/interrupt.h>
5#include "matrix.h" 5#include "matrix.h"
6#include "action.h" 6#include "action.h"
7#include "backlight.h"
8#include "suspend_avr.h" 7#include "suspend_avr.h"
9#include "suspend.h" 8#include "suspend.h"
10#include "timer.h" 9#include "timer.h"
@@ -16,6 +15,10 @@
16# include "lufa.h" 15# include "lufa.h"
17#endif 16#endif
18 17
18#ifdef BACKLIGHT_ENABLE
19# include "backlight.h"
20#endif
21
19#ifdef AUDIO_ENABLE 22#ifdef AUDIO_ENABLE
20# include "audio.h" 23# include "audio.h"
21#endif /* AUDIO_ENABLE */ 24#endif /* AUDIO_ENABLE */
diff --git a/tmk_core/common/backlight.c b/tmk_core/common/backlight.c
deleted file mode 100644
index 708022f68..000000000
--- a/tmk_core/common/backlight.c
+++ /dev/null
@@ -1,193 +0,0 @@
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/tmk_core/common/backlight.h b/tmk_core/common/backlight.h
deleted file mode 100644
index 1e581055d..000000000
--- a/tmk_core/common/backlight.h
+++ /dev/null
@@ -1,62 +0,0 @@
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/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c
index ae1c6f53e..c0f9c28d4 100644
--- a/tmk_core/common/chibios/suspend.c
+++ b/tmk_core/common/chibios/suspend.c
@@ -8,10 +8,13 @@
8#include "action_util.h" 8#include "action_util.h"
9#include "mousekey.h" 9#include "mousekey.h"
10#include "host.h" 10#include "host.h"
11#include "backlight.h"
12#include "suspend.h" 11#include "suspend.h"
13#include "wait.h" 12#include "wait.h"
14 13
14#ifdef BACKLIGHT_ENABLE
15# include "backlight.h"
16#endif
17
15/** \brief suspend idle 18/** \brief suspend idle
16 * 19 *
17 * FIXME: needs doc 20 * FIXME: needs doc
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c
index 8bf72ef25..82cd80609 100644
--- a/tmk_core/common/command.c
+++ b/tmk_core/common/command.c
@@ -32,10 +32,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
32#include "sleep_led.h" 32#include "sleep_led.h"
33#include "led.h" 33#include "led.h"
34#include "command.h" 34#include "command.h"
35#include "backlight.h"
36#include "quantum.h" 35#include "quantum.h"
37#include "version.h" 36#include "version.h"
38 37
38#ifdef BACKLIGHT_ENABLE
39# include "backlight.h"
40#endif
41
39#ifdef MOUSEKEY_ENABLE 42#ifdef MOUSEKEY_ENABLE
40# include "mousekey.h" 43# include "mousekey.h"
41#endif 44#endif
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 9806b5015..63ace9793 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -29,8 +29,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
29#include "util.h" 29#include "util.h"
30#include "sendchar.h" 30#include "sendchar.h"
31#include "eeconfig.h" 31#include "eeconfig.h"
32#include "backlight.h"
33#include "action_layer.h" 32#include "action_layer.h"
33#ifdef BACKLIGHT_ENABLE
34# include "backlight.h"
35#endif
34#ifdef BOOTMAGIC_ENABLE 36#ifdef BOOTMAGIC_ENABLE
35# include "bootmagic.h" 37# include "bootmagic.h"
36#else 38#else