From 317b8095647e208a7ac1ecf6b110051ca46553a8 Mon Sep 17 00:00:00 2001
From: fauxpark <fauxpark@gmail.com>
Date: Thu, 20 Jun 2019 15:33:39 +1000
Subject: Fix breathing always on for soft PWM (#5983)

* Fix breathing always on for soft PWM

* Remove reference to hardware PWM pins in BACKLIGHT_BREATHING description

Now, breathing will only be unsupported when Timers 1 and 3 are both used by Audio

* Document BACKLIGHT_ON_STATE and its purpose
---
 quantum/quantum.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

(limited to 'quantum')

diff --git a/quantum/quantum.c b/quantum/quantum.c
index 36b7942d5..6530738b7 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -707,8 +707,9 @@ bool process_record_quantum(keyrecord_t *record) {
 
 #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_BREATHING)
     case BL_BRTG: {
-      if (record->event.pressed)
+      if (record->event.pressed) {
         breathing_toggle();
+      }
       return false;
     }
 #endif
@@ -1148,13 +1149,13 @@ void backlight_off(uint8_t backlight_pin) {
 #define BACKLIGHT_PIN_INIT BACKLIGHT_PINS
 #endif
 
-#define FOR_EACH_LED(x)                             \
+#define FOR_EACH_LED(x) \
   for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) \
-  {                                                 \
-    uint8_t backlight_pin = backlight_pins[i];      \
+  { \
+    uint8_t backlight_pin = backlight_pins[i]; \
     { \
-      x                         \
-    }                                             \
+      x \
+    } \
   }
 
 static const uint8_t backlight_pins[BACKLIGHT_LED_COUNT] = BACKLIGHT_PIN_INIT;
@@ -1233,7 +1234,9 @@ ISR(TIMERx_COMPA_vect) {
 // this one triggers at F_CPU/65536 =~ 244 Hz
 ISR(TIMERx_OVF_vect) {
 #ifdef BACKLIGHT_BREATHING
-  breathing_task();
+  if(is_breathing()) {
+    breathing_task();
+  }
 #endif
   // for very small values of OCRxx (or backlight level)
   // we can't guarantee this whole code won't execute
-- 
cgit v1.2.3