aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/feature_backlight.md50
1 files changed, 37 insertions, 13 deletions
diff --git a/docs/feature_backlight.md b/docs/feature_backlight.md
index 556da7385..6a2946fd6 100644
--- a/docs/feature_backlight.md
+++ b/docs/feature_backlight.md
@@ -1,6 +1,8 @@
1# Backlighting 1# Backlighting
2 2
3Many keyboards support backlit keys by way of individual LEDs placed through or underneath the keyswitches. QMK is able to control the brightness of these LEDs by switching them on and off rapidly in a certain ratio, a technique known as *Pulse Width Modulation*, or PWM. By altering the duty cycle of the PWM signal, it creates the illusion of dimming. 3Many keyboards support backlit keys by way of individual LEDs placed through or underneath the keyswitches. This 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 install multiple different single coloured LEDs on a keyboard.
4
5QMK is able to control the brightness of these LEDs by switching them on and off rapidly in a certain ratio, a technique known as *Pulse Width Modulation*, or PWM. By altering the duty cycle of the PWM signal, it creates the illusion of dimming.
4 6
5The MCU can only supply so much current to its GPIO pins. Instead of powering the backlight directly from the MCU, the backlight pin is connected to a transistor or MOSFET that switches the power to the LEDs. 7The MCU can only supply so much current to its GPIO pins. Instead of powering the backlight directly from the MCU, the backlight pin is connected to a transistor or MOSFET that switches the power to the LEDs.
6 8
@@ -12,9 +14,8 @@ Most keyboards have backlighting enabled by default if they support it, but if i
12BACKLIGHT_ENABLE = yes 14BACKLIGHT_ENABLE = yes
13``` 15```
14 16
15You should then be able to use the keycodes below to change the backlight level.
16
17## Keycodes 17## Keycodes
18Once enabled the following keycodes below can be used to change the backlight level.
18 19
19|Key |Description | 20|Key |Description |
20|---------|------------------------------------------| 21|---------|------------------------------------------|
@@ -26,9 +27,9 @@ You should then be able to use the keycodes below to change the backlight level.
26|`BL_DEC` |Decrease the backlight level | 27|`BL_DEC` |Decrease the backlight level |
27|`BL_BRTG`|Toggle backlight breathing | 28|`BL_BRTG`|Toggle backlight breathing |
28 29
29## Caveats 30## AVR driver
30 31
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### Caveats
32 33
33Hardware PWM is supported according to the following table: 34Hardware PWM is supported according to the following table:
34 35
@@ -58,9 +59,9 @@ All other pins will use software PWM. If the [Audio](feature_audio.md) feature i
58 59
59When both timers are in use for Audio, the backlight PWM will not use a hardware timer, but will instead be triggered during the matrix scan. In this case, breathing is not supported, and the backlight might flicker, because the PWM computation may not be called with enough timing precision. 60When both timers are in use for Audio, the backlight PWM will not use a hardware timer, but will instead be triggered during the matrix scan. In this case, breathing is not supported, and the backlight might flicker, because the PWM computation may not be called with enough timing precision.
60 61
61## Configuration 62### AVR Configuration
62 63
63To change the behaviour of the backlighting, `#define` these in your `config.h`: 64To change the behavior of the backlighting, `#define` these in your `config.h`:
64 65
65|Define |Default |Description | 66|Define |Default |Description |
66|---------------------|-------------|-------------------------------------------------------------------------------------------------------------| 67|---------------------|-------------|-------------------------------------------------------------------------------------------------------------|
@@ -72,14 +73,14 @@ To change the behaviour of the backlighting, `#define` these in your `config.h`:
72|`BREATHING_PERIOD` |`6` |The length of one backlight "breath" in seconds | 73|`BREATHING_PERIOD` |`6` |The length of one backlight "breath" in seconds |
73|`BACKLIGHT_ON_STATE` |`0` |The state of the backlight pin when the backlight is "on" - `1` for high, `0` for low | 74|`BACKLIGHT_ON_STATE` |`0` |The state of the backlight pin when the backlight is "on" - `1` for high, `0` for low |
74 75
75## Backlight On State 76### Backlight On State
76 77
77Most 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, *high*. 78Most 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, *high*.
78Sometimes, however, a P-channel MOSFET, or a PNP transistor is used. In this case, when the transistor is on, the pin is driven *low* instead. 79Sometimes, however, a P-channel MOSFET, or a PNP transistor is used. In this case, when the transistor is on, the pin is driven *low* instead.
79 80
80This functionality is configured at the keyboard level with the `BACKLIGHT_ON_STATE` define. 81This functionality is configured at the keyboard level with the `BACKLIGHT_ON_STATE` define.
81 82
82## Multiple backlight pins 83### Multiple backlight pins
83 84
84Most keyboards have only one backlight pin which control all backlight LEDs (especially if the backlight is connected to an hardware PWM pin). 85Most keyboards have only one backlight pin which control all backlight LEDs (especially if the backlight is connected to an hardware PWM pin).
85In 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. 86In 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.
@@ -87,13 +88,13 @@ This feature allows to set for instance the Caps Lock LED (or any other controll
87 88
88To activate multiple backlight pins, you need to add something like this to your user `config.h`: 89To activate multiple backlight pins, you need to add something like this to your user `config.h`:
89 90
90~~~c 91```c
91#define BACKLIGHT_LED_COUNT 2 92#define BACKLIGHT_LED_COUNT 2
92#undef BACKLIGHT_PIN 93#undef BACKLIGHT_PIN
93#define BACKLIGHT_PINS { F5, B2 } 94#define BACKLIGHT_PINS { F5, B2 }
94~~~ 95```
95 96
96## Hardware PWM Implementation 97### Hardware PWM Implementation
97 98
98When 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. 99When 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.
99The desired brightness is calculated and stored in the `OCRxx` register. When the counter reaches this value, the backlight pin will go low, and is pulled high again when the counter resets. 100The desired brightness is calculated and stored in the `OCRxx` register. When the counter reaches this value, the backlight pin will go low, and is pulled high again when the counter resets.
@@ -102,7 +103,7 @@ In this way `OCRxx` essentially controls the duty cycle of the LEDs, and thus th
102The 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. 103The 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.
103In 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. 104In 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.
104 105
105## Software PWM Implementation 106### Software PWM Implementation
106 107
107When `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. 108When `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.
108When resetting to 0, the CPU will fire an OVF (overflow) interrupt that will turn the LEDs on, starting the duty cycle. 109When resetting to 0, the CPU will fire an OVF (overflow) interrupt that will turn the LEDs on, starting the duty cycle.
@@ -111,6 +112,29 @@ In this way `OCRxx` essentially controls the duty cycle of the LEDs, and thus th
111 112
112The breathing effect is the same as in the hardware PWM implementation. 113The breathing effect is the same as in the hardware PWM implementation.
113 114
115## ARM Driver
116
117### Caveats
118
119Currently only hardware PWM is supported, and does not provide automatic configuration.
120
121?> STMF072 support is being investigated.
122
123### ARM Configuration
124
125To change the behavior of the backlighting, `#define` these in your `config.h`:
126
127|Define |Default |Description |
128|------------------------|-------------|-------------------------------------------------------------------------------------------------------------|
129|`BACKLIGHT_PIN` |`B7` |The pin that controls the LEDs. Unless you are designing your own keyboard, you shouldn't need to change this|
130|`BACKLIGHT_PWM_DRIVER` |`PWMD4` |The PWM driver to use, see ST datasheets for pin to PWM timer mapping. Unless you are designing your own keyboard, you shouldn't need to change this|
131|`BACKLIGHT_PWM_CHANNEL` |`3` |The PWM channel to use, see ST datasheets for pin to PWM channel mapping. Unless you are designing your own keyboard, you shouldn't need to change this|
132|`BACKLIGHT_PAL_MODE` |`2` |The pin alternative function to use, see ST datasheets for pin AF mapping. Unless you are designing your own keyboard, you shouldn't need to change this|
133|`BACKLIGHT_LEVELS` |`3` |The number of brightness levels (maximum 31 excluding off) |
134|`BACKLIGHT_CAPS_LOCK` |*Not defined*|Enable Caps Lock indicator using backlight (for keyboards without dedicated LED) |
135|`BACKLIGHT_BREATHING` |*Not defined*|Enable backlight breathing, if supported |
136|`BREATHING_PERIOD` |`6` |The length of one backlight "breath" in seconds |
137
114## Backlight Functions 138## Backlight Functions
115 139
116|Function |Description | 140|Function |Description |