aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfauxpark <fauxpark@gmail.com>2019-07-16 17:56:36 +1000
committerskullydazed <skullydazed@users.noreply.github.com>2019-07-16 00:56:36 -0700
commita32f7e1a25a8a200d838aa8256ffe39708fbd723 (patch)
treeb1ede8bd7ce3d6b31c7bfd83d0f23a804c8efc8f
parente2dfb787da2a2ba88e0e074b396a2b988e10eccf (diff)
downloadqmk_firmware-a32f7e1a25a8a200d838aa8256ffe39708fbd723.tar.gz
qmk_firmware-a32f7e1a25a8a200d838aa8256ffe39708fbd723.zip
Store backlight breathing state in EEPROM (#6105)
* Store backlight breathing state in EEPROM * Reduce backlight_config.level from 6 bits to 4 (max 15 "on" levels) * Error out if BACKLIGHT_LEVELS is > 15 * Remove mention of default backlight pin in rules.mk template * Remove pointless comment
-rw-r--r--quantum/quantum.c12
-rw-r--r--quantum/template/avr/config.h2
-rw-r--r--quantum/template/avr/rules.mk2
-rw-r--r--tmk_core/common/backlight.c55
-rw-r--r--tmk_core/common/backlight.h19
5 files changed, 82 insertions, 8 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 31dfa60cd..d98c601d9 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -708,7 +708,7 @@ bool process_record_quantum(keyrecord_t *record) {
708#if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_BREATHING) 708#if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_BREATHING)
709 case BL_BRTG: { 709 case BL_BRTG: {
710 if (record->event.pressed) { 710 if (record->event.pressed) {
711 breathing_toggle(); 711 backlight_toggle_breathing();
712 } 712 }
713 return false; 713 return false;
714 } 714 }
@@ -1196,6 +1196,12 @@ void backlight_init_ports(void)
1196 setPinOutput(backlight_pin); 1196 setPinOutput(backlight_pin);
1197 backlight_on(backlight_pin); 1197 backlight_on(backlight_pin);
1198 ) 1198 )
1199
1200 #ifdef BACKLIGHT_BREATHING
1201 if (is_backlight_breathing()) {
1202 breathing_enable();
1203 }
1204 #endif
1199} 1205}
1200 1206
1201__attribute__ ((weak)) 1207__attribute__ ((weak))
@@ -1500,7 +1506,9 @@ void backlight_init_ports(void)
1500 1506
1501 backlight_init(); 1507 backlight_init();
1502 #ifdef BACKLIGHT_BREATHING 1508 #ifdef BACKLIGHT_BREATHING
1503 breathing_enable(); 1509 if (is_backlight_breathing()) {
1510 breathing_enable();
1511 }
1504 #endif 1512 #endif
1505} 1513}
1506 1514
diff --git a/quantum/template/avr/config.h b/quantum/template/avr/config.h
index 1e41a2d31..fc65bb597 100644
--- a/quantum/template/avr/config.h
+++ b/quantum/template/avr/config.h
@@ -91,8 +91,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
91/* define if matrix has ghost (lacks anti-ghosting diodes) */ 91/* define if matrix has ghost (lacks anti-ghosting diodes) */
92//#define MATRIX_HAS_GHOST 92//#define MATRIX_HAS_GHOST
93 93
94/* number of backlight levels */
95
96/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ 94/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
97#define LOCKING_SUPPORT_ENABLE 95#define LOCKING_SUPPORT_ENABLE
98/* Locking resynchronize hack */ 96/* Locking resynchronize hack */
diff --git a/quantum/template/avr/rules.mk b/quantum/template/avr/rules.mk
index bc370be03..133c9e363 100644
--- a/quantum/template/avr/rules.mk
+++ b/quantum/template/avr/rules.mk
@@ -70,7 +70,7 @@ COMMAND_ENABLE = yes # Commands for debug and configuration
70SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend 70SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
71# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work 71# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
72NKRO_ENABLE = no # USB Nkey Rollover 72NKRO_ENABLE = no # USB Nkey Rollover
73BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default 73BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
74RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow 74RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
75MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config) 75MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
76UNICODE_ENABLE = no # Unicode 76UNICODE_ENABLE = no # Unicode
diff --git a/tmk_core/common/backlight.c b/tmk_core/common/backlight.c
index 8ddacd98b..c0e9fb5ee 100644
--- a/tmk_core/common/backlight.c
+++ b/tmk_core/common/backlight.c
@@ -100,7 +100,7 @@ void backlight_enable(void)
100 backlight_set(backlight_config.level); 100 backlight_set(backlight_config.level);
101} 101}
102 102
103/** /brief Disable backlight 103/** \brief Disable backlight
104 * 104 *
105 * FIXME: needs doc 105 * FIXME: needs doc
106 */ 106 */
@@ -162,3 +162,56 @@ uint8_t get_backlight_level(void)
162{ 162{
163 return backlight_config.level; 163 return backlight_config.level;
164} 164}
165
166#ifdef BACKLIGHT_BREATHING
167/** \brief Backlight breathing toggle
168 *
169 * FIXME: needs doc
170 */
171void backlight_toggle_breathing(void)
172{
173 bool breathing = backlight_config.breathing;
174 dprintf("backlight breathing toggle: %u\n", breathing);
175 if (breathing)
176 backlight_disable_breathing();
177 else
178 backlight_enable_breathing();
179}
180
181/** \brief Enable backlight breathing
182 *
183 * FIXME: needs doc
184 */
185void backlight_enable_breathing(void)
186{
187 if (backlight_config.breathing) return; // do nothing if breathing is already on
188
189 backlight_config.breathing = true;
190 eeconfig_update_backlight(backlight_config.raw);
191 dprintf("backlight breathing enable\n");
192 breathing_enable();
193}
194
195/** \brief Disable backlight breathing
196 *
197 * FIXME: needs doc
198 */
199void backlight_disable_breathing(void)
200{
201 if (!backlight_config.breathing) return; // do nothing if breathing is already off
202
203 backlight_config.breathing = false;
204 eeconfig_update_backlight(backlight_config.raw);
205 dprintf("backlight breathing disable\n");
206 breathing_disable();
207}
208
209/** \brief Get the backlight breathing status
210 *
211 * FIXME: needs doc
212 */
213bool is_backlight_breathing(void)
214{
215 return backlight_config.breathing;
216}
217#endif
diff --git a/tmk_core/common/backlight.h b/tmk_core/common/backlight.h
index 420c9d19e..cc56fb9af 100644
--- a/tmk_core/common/backlight.h
+++ b/tmk_core/common/backlight.h
@@ -20,11 +20,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20#include <stdint.h> 20#include <stdint.h>
21#include <stdbool.h> 21#include <stdbool.h>
22 22
23#ifndef BACKLIGHT_LEVELS
24 #define BACKLIGHT_LEVELS 3
25#elif BACKLIGHT_LEVELS > 15
26 #error "Maximum value of BACKLIGHT_LEVELS is 15"
27#endif
28
23typedef union { 29typedef union {
24 uint8_t raw; 30 uint8_t raw;
25 struct { 31 struct {
26 bool enable :1; 32 bool enable :1;
27 uint8_t level :7; 33 bool breathing :1;
34 uint8_t level :4;
28 }; 35 };
29} backlight_config_t; 36} backlight_config_t;
30 37
@@ -40,3 +47,11 @@ void backlight_set(uint8_t level);
40void backlight_level(uint8_t level); 47void backlight_level(uint8_t level);
41uint8_t get_backlight_level(void); 48uint8_t get_backlight_level(void);
42 49
50#ifdef BACKLIGHT_BREATHING
51void backlight_toggle_breathing(void);
52void backlight_enable_breathing(void);
53void backlight_disable_breathing(void);
54bool is_backlight_breathing(void);
55void breathing_enable(void);
56void breathing_disable(void);
57#endif