aboutsummaryrefslogtreecommitdiff
path: root/docs/feature_backlight.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/feature_backlight.md')
-rw-r--r--docs/feature_backlight.md52
1 files changed, 50 insertions, 2 deletions
diff --git a/docs/feature_backlight.md b/docs/feature_backlight.md
index c7a1f131e..048d75390 100644
--- a/docs/feature_backlight.md
+++ b/docs/feature_backlight.md
@@ -30,7 +30,31 @@ You should then be able to use the keycodes below to change the backlight level.
30 30
31This feature is distinct from both the [RGB underglow](feature_rgblight.md) and [RGB matrix](feature_rgb_matrix.md) features as it usually allows for only a single colour per switch, though you can obviously use multiple different coloured LEDs on a keyboard. 31This feature is distinct from both the [RGB underglow](feature_rgblight.md) and [RGB matrix](feature_rgb_matrix.md) features as it usually allows for only a single colour per switch, though you can obviously use multiple different coloured LEDs on a keyboard.
32 32
33Hardware PWM is only supported on certain pins of the MCU, so if the backlighting is not connected to one of them, a software implementation will be used, and backlight breathing will not be available. Currently the supported pins are `B5`, `B6`, `B7`, and `C6`. 33Hardware PWM is only supported on certain pins of the MCU, so if the backlighting is not connected to one of them, a software PWM implementation triggered by hardware timer interrupts will be used.
34
35Hardware PWM is supported according to the following table:
36
37| Backlight Pin | Hardware timer |
38|---------------|----------------|
39|`B5` | Timer 1 |
40|`B6` | Timer 1 |
41|`B7` | Timer 1 |
42|`C6` | Timer 3 |
43| other | Software PWM |
44
45The [audio feature](feature_audio.md) also uses hardware timers. Please refer to the following table to know what hardware timer the software PWM will use depending on the audio configuration:
46
47| Audio Pin(s) | Audio Timer | Software PWM Timer |
48|--------------|-------------|--------------------|
49| `C4` | Timer 3 | Timer 1 |
50| `C5` | Timer 3 | Timer 1 |
51| `C6` | Timer 3 | Timer 1 |
52| `B5` | Timer 1 | Timer 3 |
53| `B6` | Timer 1 | Timer 3 |
54| `B7` | Timer 1 | Timer 3 |
55| `Bx` & `Cx` | Timer 1 & 3 | None |
56
57When all timers are in use for [audio](feature_audio.md), the backlight software PWM will not use a hardware timer, but instead will be triggered during the matrix scan. In this case the backlight doesn't support breathing and might show lighting artifacts (for instance flickering), because the PWM computation might not be called with enough timing precision.
34 58
35## Configuration 59## Configuration
36 60
@@ -39,11 +63,26 @@ To change the behaviour of the backlighting, `#define` these in your `config.h`:
39|Define |Default |Description | 63|Define |Default |Description |
40|---------------------|-------------|-------------------------------------------------------------------------------------------------------------| 64|---------------------|-------------|-------------------------------------------------------------------------------------------------------------|
41|`BACKLIGHT_PIN` |`B7` |The pin that controls the LEDs. Unless you are designing your own keyboard, you shouldn't need to change this| 65|`BACKLIGHT_PIN` |`B7` |The pin that controls the LEDs. Unless you are designing your own keyboard, you shouldn't need to change this|
66|`BACKLIGHT_PINS` |*Not defined*|experimental: see below for more information|
42|`BACKLIGHT_LEVELS` |`3` |The number of brightness levels (maximum 15 excluding off) | 67|`BACKLIGHT_LEVELS` |`3` |The number of brightness levels (maximum 15 excluding off) |
43|`BACKLIGHT_CAPS_LOCK`|*Not defined*|Enable Caps Lock indicator using backlight (for keyboards without dedicated LED) | 68|`BACKLIGHT_CAPS_LOCK`|*Not defined*|Enable Caps Lock indicator using backlight (for keyboards without dedicated LED) |
44|`BACKLIGHT_BREATHING`|*Not defined*|Enable backlight breathing, if hardware PWM is used | 69|`BACKLIGHT_BREATHING`|*Not defined*|Enable backlight breathing, if supported |
45|`BREATHING_PERIOD` |`6` |The length of one backlight "breath" in seconds | 70|`BREATHING_PERIOD` |`6` |The length of one backlight "breath" in seconds |
46 71
72## Multiple backlight pins
73
74Most keyboards have only one backlight pin which control all backlight LEDs (especially if the backlight is connected to an hardware PWM pin).
75In software PWM, it is possible to define multiple backlight pins. All those pins will be turned on and off at the same time during the PWM duty cycle.
76This feature allows to set for instance the Caps Lock LED (or any other controllable LED) brightness at the same level as the other LEDs of the backlight. This is useful if you have mapped LCTRL in place of Caps Lock and you need the Caps Lock LED to be part of the backlight instead of being activated when Caps Lock is on.
77
78To activate multiple backlight pins, you need to add something like this to your user `config.h`:
79
80~~~c
81#define BACKLIGHT_LED_COUNT 2
82#undef BACKLIGHT_PIN
83#define BACKLIGHT_PINS { F5, B2 }
84~~~
85
47## Hardware PWM Implementation 86## Hardware PWM Implementation
48 87
49When using the supported pins for backlighting, QMK will use a hardware timer configured to output a PWM signal. This timer will count up to `ICRx` (by default `0xFFFF`) before resetting to 0. 88When using the supported pins for backlighting, QMK will use a hardware timer configured to output a PWM signal. This timer will count up to `ICRx` (by default `0xFFFF`) before resetting to 0.
@@ -53,6 +92,15 @@ In this way `OCRxx` essentially controls the duty cycle of the LEDs, and thus th
53The breathing effect is achieved by registering an interrupt handler for `TIMER1_OVF_vect` that is called whenever the counter resets, roughly 244 times per second. 92The breathing effect is achieved by registering an interrupt handler for `TIMER1_OVF_vect` that is called whenever the counter resets, roughly 244 times per second.
54In this handler, the value of an incrementing counter is mapped onto a precomputed brightness curve. To turn off breathing, the interrupt handler is simply disabled, and the brightness reset to the level stored in EEPROM. 93In this handler, the value of an incrementing counter is mapped onto a precomputed brightness curve. To turn off breathing, the interrupt handler is simply disabled, and the brightness reset to the level stored in EEPROM.
55 94
95## Software PWM Implementation
96
97When `BACKLIGHT_PIN` is not set to a hardware backlight pin, QMK will use a hardware timer configured to trigger software interrupts. This time will count up to `ICRx` (by default `0xFFFF`) before resetting to 0.
98When resetting to 0, the CPU will fire an OVF (overflow) interrupt that will turn the LEDs on, starting the duty cycle.
99The desired brightness is calculated and stored in the `OCRxx` register. When the counter reaches this value, the CPU will fire a Compare Output match interrupt, which will turn the LEDs off.
100In this way `OCRxx` essentially controls the duty cycle of the LEDs, and thus the brightness, where `0x0000` is completely off and `0xFFFF` is completely on.
101
102The breathing effect is the same as in the hardware PWM implementation.
103
56## Backlight Functions 104## Backlight Functions
57 105
58|Function |Description | 106|Function |Description |