summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfauxpark <fauxpark@gmail.com>2019-07-16 17:56:36 +1000
committerFlorian Didron <fdidron@users.noreply.github.com>2019-07-19 10:16:35 +0900
commit408356533460cb12adad96f65e4c8a8494afa4b7 (patch)
tree88980cfe237ca1c749af01152c4146db63c3d722
parentb279d2b94e1687180a1d4da354888152e584a900 (diff)
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.c26
-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, 87 insertions, 17 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 903ca775b6..4d80cc1470 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -703,8 +703,9 @@ bool process_record_quantum(keyrecord_t *record) {
#if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_BREATHING)
case BL_BRTG: {
- if (record->event.pressed)
- breathing_toggle();
+ if (record->event.pressed) {
+ backlight_toggle_breathing();
+ }
return false;
}
#endif
@@ -1070,14 +1071,15 @@ __attribute__ ((weak))
void backlight_init_ports(void)
{
// Setup backlight pin as output and output to on state.
- // DDRx |= n
- _SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF);
- #if BACKLIGHT_ON_STATE == 0
- // PORTx &= ~n
- _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
- #else
- // PORTx |= n
- _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
+ FOR_EACH_LED(
+ setPinOutput(backlight_pin);
+ backlight_on(backlight_pin);
+ )
+
+ #ifdef BACKLIGHT_BREATHING
+ if (is_backlight_breathing()) {
+ breathing_enable();
+ }
#endif
}
@@ -1303,7 +1305,9 @@ void backlight_init_ports(void)
backlight_init();
#ifdef BACKLIGHT_BREATHING
- breathing_enable();
+ if (is_backlight_breathing()) {
+ breathing_enable();
+ }
#endif
}
diff --git a/quantum/template/avr/config.h b/quantum/template/avr/config.h
index 1e41a2d31d..fc65bb5976 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/>.
/* define if matrix has ghost (lacks anti-ghosting diodes) */
//#define MATRIX_HAS_GHOST
-/* number of backlight levels */
-
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
#define LOCKING_SUPPORT_ENABLE
/* Locking resynchronize hack */
diff --git a/quantum/template/avr/rules.mk b/quantum/template/avr/rules.mk
index 383a3594b4..a1398f918a 100644
--- a/quantum/template/avr/rules.mk
+++ b/quantum/template/avr/rules.mk
@@ -71,7 +71,7 @@ COMMAND_ENABLE = yes # Commands for debug and configuration
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
NKRO_ENABLE = no # USB Nkey Rollover
-BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default
+BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
UNICODE_ENABLE = no # Unicode
diff --git a/tmk_core/common/backlight.c b/tmk_core/common/backlight.c
index 8ddacd98b6..c0e9fb5ee4 100644
--- a/tmk_core/common/backlight.c
+++ b/tmk_core/common/backlight.c
@@ -100,7 +100,7 @@ void backlight_enable(void)
backlight_set(backlight_config.level);
}
-/** /brief Disable backlight
+/** \brief Disable backlight
*
* FIXME: needs doc
*/
@@ -162,3 +162,56 @@ uint8_t get_backlight_level(void)
{
return backlight_config.level;
}
+
+#ifdef BACKLIGHT_BREATHING
+/** \brief Backlight breathing toggle
+ *
+ * FIXME: needs doc
+ */
+void backlight_toggle_breathing(void)
+{
+ bool breathing = backlight_config.breathing;
+ dprintf("backlight breathing toggle: %u\n", breathing);
+ if (breathing)
+ backlight_disable_breathing();
+ else
+ backlight_enable_breathing();
+}
+
+/** \brief Enable backlight breathing
+ *
+ * FIXME: needs doc
+ */
+void backlight_enable_breathing(void)
+{
+ if (backlight_config.breathing) return; // do nothing if breathing is already on
+
+ backlight_config.breathing = true;
+ eeconfig_update_backlight(backlight_config.raw);
+ dprintf("backlight breathing enable\n");
+ breathing_enable();
+}
+
+/** \brief Disable backlight breathing
+ *
+ * FIXME: needs doc
+ */
+void backlight_disable_breathing(void)
+{
+ if (!backlight_config.breathing) return; // do nothing if breathing is already off
+
+ backlight_config.breathing = false;
+ eeconfig_update_backlight(backlight_config.raw);
+ dprintf("backlight breathing disable\n");
+ breathing_disable();
+}
+
+/** \brief Get the backlight breathing status
+ *
+ * FIXME: needs doc
+ */
+bool is_backlight_breathing(void)
+{
+ return backlight_config.breathing;
+}
+#endif
diff --git a/tmk_core/common/backlight.h b/tmk_core/common/backlight.h
index 420c9d19ed..cc56fb9af0 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/>.
#include <stdint.h>
#include <stdbool.h>
+#ifndef BACKLIGHT_LEVELS
+ #define BACKLIGHT_LEVELS 3
+#elif BACKLIGHT_LEVELS > 15
+ #error "Maximum value of BACKLIGHT_LEVELS is 15"
+#endif
+
typedef union {
uint8_t raw;
struct {
- bool enable :1;
- uint8_t level :7;
+ bool enable :1;
+ bool breathing :1;
+ uint8_t level :4;
};
} backlight_config_t;
@@ -40,3 +47,11 @@ void backlight_set(uint8_t level);
void backlight_level(uint8_t level);
uint8_t get_backlight_level(void);
+#ifdef BACKLIGHT_BREATHING
+void backlight_toggle_breathing(void);
+void backlight_enable_breathing(void);
+void backlight_disable_breathing(void);
+bool is_backlight_breathing(void);
+void breathing_enable(void);
+void breathing_disable(void);
+#endif