summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/quantum.c61
-rw-r--r--quantum/quantum.h1
2 files changed, 48 insertions, 14 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 4a6d0355fa..761ba37f37 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -7,9 +7,14 @@
#define TAPPING_TERM 200
#endif
+<<<<<<< HEAD
+#include "backlight.h"
+extern backlight_config_t backlight_config;
+=======
#ifdef FAUXCLICKY_ENABLE
#include "fauxclicky.h"
#endif
+>>>>>>> 49e72632d2200fc3bf71d5ced2aa43058da3b2e0
static void do_code16 (uint16_t code, void (*f) (uint8_t)) {
switch (code) {
@@ -601,6 +606,10 @@ void matrix_scan_quantum() {
matrix_scan_combo();
#endif
+ #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
+ backlight_task();
+ #endif
+
matrix_scan_kb();
}
@@ -668,13 +677,13 @@ __attribute__ ((weak))
void backlight_set(uint8_t level)
{
// Prevent backlight blink on lowest level
- #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);
- #endif
+ // #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);
+ // #endif
if ( level == 0 ) {
#ifndef NO_BACKLIGHT_CLOCK
@@ -682,13 +691,13 @@ void backlight_set(uint8_t level)
TCCR1A &= ~(_BV(COM1x1));
OCR1x = 0x0;
#else
- #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);
- #endif
+ // #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);
+ // #endif
#endif
}
#ifndef NO_BACKLIGHT_CLOCK
@@ -711,6 +720,30 @@ void backlight_set(uint8_t level)
#endif
}
+uint8_t backlight_tick = 0;
+
+void backlight_task(void) {
+ #ifdef NO_BACKLIGHT_CLOCK
+ if ((0xFFFF >> ((BACKLIGHT_LEVELS - backlight_config.level) * ((BACKLIGHT_LEVELS + 1) / 2))) & (1 << backlight_tick)) {
+ #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);
+ #endif
+ } else {
+ #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);
+ #endif
+ }
+ backlight_tick = (backlight_tick + 1) % 16;
+ #endif
+}
#ifdef BACKLIGHT_BREATHING
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 580d51202a..259bac3697 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -103,6 +103,7 @@ void unregister_code16 (uint16_t code);
#ifdef BACKLIGHT_ENABLE
void backlight_init_ports(void);
+void backlight_task(void);
#ifdef BACKLIGHT_BREATHING
void breathing_enable(void);