summaryrefslogtreecommitdiffstats
path: root/quantum/quantum.c
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2017-02-12 11:29:42 -0500
committerJack Humbert <jack.humb@gmail.com>2017-02-12 11:29:42 -0500
commit8d0fdf10086a0e8a1615f0521fccf1f5a2806497 (patch)
treea64c77717d4b4cc7ffe08a6cdfc7e8091bd3c32a /quantum/quantum.c
parenta0c2305bd1153d9d578d73effd33896c2dbc26c8 (diff)
adds soft pwm for non-timed ports
Diffstat (limited to 'quantum/quantum.c')
-rw-r--r--quantum/quantum.c59
1 files changed, 45 insertions, 14 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 45ea8cb73c..95f06d95d4 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -7,6 +7,9 @@
#define TAPPING_TERM 200
#endif
+#include "backlight.h"
+extern backlight_config_t backlight_config;
+
static void do_code16 (uint16_t code, void (*f) (uint8_t)) {
switch (code) {
case QK_MODS ... QK_MODS_MAX:
@@ -577,6 +580,10 @@ void matrix_scan_quantum() {
matrix_scan_combo();
#endif
+ #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
+ backlight_task();
+ #endif
+
matrix_scan_kb();
}
@@ -644,13 +651,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
@@ -658,13 +665,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
@@ -687,6 +694,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