]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Fix breathing always on for soft PWM (#5983)
authorfauxpark <fauxpark@gmail.com>
Thu, 20 Jun 2019 05:33:39 +0000 (15:33 +1000)
committerDrashna Jaelre <drashna@live.com>
Thu, 20 Jun 2019 05:33:39 +0000 (22:33 -0700)
* 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

docs/config_options.md
docs/feature_backlight.md
quantum/quantum.c

index 7418e8dbf99ce36f278677e0e63858cbf542fc35..eb0a441cccc34e8a2decf57f3b1c35eb1070eabe 100644 (file)
@@ -80,7 +80,7 @@ This is a C header file that is one of the first things included, and will persi
 * `#define BACKLIGHT_LEVELS 3`
   * number of levels your backlight will have (maximum 15 excluding off)
 * `#define BACKLIGHT_BREATHING`
-  * enables backlight breathing (only works with backlight pins B5, B6 and B7)
+  * enables backlight breathing
 * `#define BREATHING_PERIOD 6`
   * the length of one backlight "breath" in seconds
 * `#define DEBOUNCE 5`
index 5a21a679017a4f3378a2f3af9c0cee2db324652d..b06db89e4df9fa6fcd19be0349b2abf1a5fda973 100644 (file)
@@ -64,11 +64,17 @@ To change the behaviour of the backlighting, `#define` these in your `config.h`:
 |Define               |Default      |Description                                                                                                  |
 |---------------------|-------------|-------------------------------------------------------------------------------------------------------------|
 |`BACKLIGHT_PIN`      |`B7`         |The pin that controls the LEDs. Unless you are designing your own keyboard, you shouldn't need to change this|
-|`BACKLIGHT_PINS`     |*Not defined*|experimental: see below for more information|
+|`BACKLIGHT_PINS`     |*Not defined*|experimental: see below for more information                                                                 |
 |`BACKLIGHT_LEVELS`   |`3`          |The number of brightness levels (maximum 15 excluding off)                                                   |
 |`BACKLIGHT_CAPS_LOCK`|*Not defined*|Enable Caps Lock indicator using backlight (for keyboards without dedicated LED)                             |
-|`BACKLIGHT_BREATHING`|*Not defined*|Enable backlight breathing, if supported                                                          |
+|`BACKLIGHT_BREATHING`|*Not defined*|Enable backlight breathing, if supported                                                                     |
 |`BREATHING_PERIOD`   |`6`          |The length of one backlight "breath" in seconds                                                              |
+|`BACKLIGHT_ON_STATE` |`0`          |The state of the backlight pin when the backlight is "on" - `1` for high, `0` for low                        |
+
+## Backlight On State
+
+Most backlight circuits are driven by an N-channel MOSFET or NPN transistor. This means that to turn the transistor *on* and light the LEDs, you must drive the backlight pin, connected to the gate or base, *low*.
+Sometimes, however, a P-channel MOSFET, or a PNP transistor is used. In this case you must `#define BACKLIGHT_ON_STATE 1`, so that when the transistor is on, the pin is driven *high* instead.
 
 ## Multiple backlight pins
 
index 36b7942d5d8d73a02f4993711d7a14dbe20ac0e8..6530738b71d38c10eca656d97e1f98c3ed58e133 100644 (file)
@@ -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