summaryrefslogtreecommitdiffstats
path: root/quantum/quantum.h
diff options
context:
space:
mode:
authorBrice Figureau <brice@daysofwonder.com>2019-04-22 17:34:13 +0200
committerMechMerlin <30334081+mechmerlin@users.noreply.github.com>2019-04-22 17:34:13 +0200
commitb61baf4281bde34bfe28aaa1109bd5d5c6471116 (patch)
treefa60f457b48bbb4d635b32f5b48b03a7dd0dccf7 /quantum/quantum.h
parentc28a4321123131b6ff1e6c6b302fba764255623b (diff)
downloadqmk_firmware-b61baf4281bde34bfe28aaa1109bd5d5c6471116.tar.gz
qmk_firmware-b61baf4281bde34bfe28aaa1109bd5d5c6471116.tar.xz
Fix #3566 use an hardware timer for software PWM stability (#3615)
With my XD60, I noticed that when typing the backlight was flickering. The XD60 doesn't have the backlight wired to a hardware PWM pin. I assumed it was a timing issue in the matrix scan that made the PWM lit the LED a bit too longer. I verified it because the more keys that were pressed, the more lighting I observed. This patch makes the software PWM be called during CPU interruptions. It works almost like the hardware PWM, except instead of using the CPU waveform generation, the CPU will fire interruption when the LEDs need be turned on or off. Using the same timer system as for hardware PWM, when the counter will reach OCRxx (the current backlight level), an Output Compare match interrupt will be fired and we'll turn the LEDs off. When the counter reaches its maximum value, an overflow interrupt will be triggered in which we turn the LEDs on. This way we replicate the hardware backlight PWM duty cycle. This gives a better time stability of the PWM computation than pure software PWM, leading to a flicker free backlight. Since this is reusing the hardware PWM code, software PWM also supports backlight breathing. Note that if timer1 is used for audio, backlight will use timer3, and if timer3 is used for audio backlight will use timer1. If both timers are used for audio, then this feature is disabled and we revert to the matrix scan based PWM computation. Signed-off-by: Brice Figureau <brice@daysofwonder.com>
Diffstat (limited to 'quantum/quantum.h')
-rw-r--r--quantum/quantum.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 987516ded..17cb90274 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -260,8 +260,12 @@ void tap_code16(uint16_t code);
#ifdef BACKLIGHT_ENABLE
void backlight_init_ports(void);
void backlight_task(void);
+void backlight_task_internal(void);
+void backlight_on(uint8_t backlight_pin);
+void backlight_off(uint8_t backlight_pin);
#ifdef BACKLIGHT_BREATHING
+void breathing_task(void);
void breathing_enable(void);
void breathing_pulse(void);
void breathing_disable(void);