diff options
Diffstat (limited to 'quantum/backlight')
-rw-r--r-- | quantum/backlight/backlight_avr.c | 10 | ||||
-rw-r--r-- | quantum/backlight/backlight_soft.c | 66 |
2 files changed, 71 insertions, 5 deletions
diff --git a/quantum/backlight/backlight_avr.c b/quantum/backlight/backlight_avr.c index 445698f47..648a37adf 100644 --- a/quantum/backlight/backlight_avr.c +++ b/quantum/backlight/backlight_avr.c | |||
@@ -159,7 +159,7 @@ | |||
159 | # define BACKLIGHT_ON_STATE 0 | 159 | # define BACKLIGHT_ON_STATE 0 |
160 | # endif | 160 | # endif |
161 | 161 | ||
162 | void backlight_on(uint8_t backlight_pin) { | 162 | void backlight_on(pin_t backlight_pin) { |
163 | # if BACKLIGHT_ON_STATE == 0 | 163 | # if BACKLIGHT_ON_STATE == 0 |
164 | writePinLow(backlight_pin); | 164 | writePinLow(backlight_pin); |
165 | # else | 165 | # else |
@@ -167,7 +167,7 @@ void backlight_on(uint8_t backlight_pin) { | |||
167 | # endif | 167 | # endif |
168 | } | 168 | } |
169 | 169 | ||
170 | void backlight_off(uint8_t backlight_pin) { | 170 | void backlight_off(pin_t backlight_pin) { |
171 | # if BACKLIGHT_ON_STATE == 0 | 171 | # if BACKLIGHT_ON_STATE == 0 |
172 | writePinHigh(backlight_pin); | 172 | writePinHigh(backlight_pin); |
173 | # else | 173 | # else |
@@ -191,16 +191,16 @@ void backlight_off(uint8_t backlight_pin) { | |||
191 | 191 | ||
192 | # define FOR_EACH_LED(x) \ | 192 | # define FOR_EACH_LED(x) \ |
193 | for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) { \ | 193 | for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) { \ |
194 | uint8_t backlight_pin = backlight_pins[i]; \ | 194 | pin_t backlight_pin = backlight_pins[i]; \ |
195 | { x } \ | 195 | { x } \ |
196 | } | 196 | } |
197 | 197 | ||
198 | static const uint8_t backlight_pins[BACKLIGHT_LED_COUNT] = BACKLIGHT_PIN_INIT; | 198 | static const pin_t backlight_pins[BACKLIGHT_LED_COUNT] = BACKLIGHT_PIN_INIT; |
199 | 199 | ||
200 | # else // full hardware PWM | 200 | # else // full hardware PWM |
201 | 201 | ||
202 | // we support only one backlight pin | 202 | // we support only one backlight pin |
203 | static const uint8_t backlight_pin = BACKLIGHT_PIN; | 203 | static const pin_t backlight_pin = BACKLIGHT_PIN; |
204 | # define FOR_EACH_LED(x) x | 204 | # define FOR_EACH_LED(x) x |
205 | 205 | ||
206 | # endif | 206 | # endif |
diff --git a/quantum/backlight/backlight_soft.c b/quantum/backlight/backlight_soft.c new file mode 100644 index 000000000..a6aba7782 --- /dev/null +++ b/quantum/backlight/backlight_soft.c | |||
@@ -0,0 +1,66 @@ | |||
1 | #include "quantum.h" | ||
2 | #include "backlight.h" | ||
3 | |||
4 | #if !defined(BACKLIGHT_PIN) && !defined(BACKLIGHT_PINS) | ||
5 | # error "Backlight pin/pins not defined. Please configure." | ||
6 | #endif | ||
7 | |||
8 | #ifdef BACKLIGHT_BREATHING | ||
9 | # error "Backlight breathing is not available for software PWM. Please disable." | ||
10 | #endif | ||
11 | |||
12 | #ifndef BACKLIGHT_ON_STATE | ||
13 | # define BACKLIGHT_ON_STATE 0 | ||
14 | #endif | ||
15 | |||
16 | #ifdef BACKLIGHT_PINS | ||
17 | # define BACKLIGHT_PIN_INIT BACKLIGHT_PINS | ||
18 | #else | ||
19 | # define BACKLIGHT_PIN_INIT \ | ||
20 | { BACKLIGHT_PIN } | ||
21 | #endif | ||
22 | |||
23 | static const pin_t backlight_pins[] = BACKLIGHT_PIN_INIT; | ||
24 | #define BACKLIGHT_LED_COUNT (sizeof(backlight_pins) / sizeof(pin_t)) | ||
25 | |||
26 | #define FOR_EACH_LED(x) \ | ||
27 | for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) { \ | ||
28 | pin_t backlight_pin = backlight_pins[i]; \ | ||
29 | { x } \ | ||
30 | } | ||
31 | |||
32 | void backlight_on(pin_t backlight_pin) { | ||
33 | #if BACKLIGHT_ON_STATE == 0 | ||
34 | writePinLow(backlight_pin); | ||
35 | #else | ||
36 | writePinHigh(backlight_pin); | ||
37 | #endif | ||
38 | } | ||
39 | |||
40 | void backlight_off(pin_t backlight_pin) { | ||
41 | #if BACKLIGHT_ON_STATE == 0 | ||
42 | writePinHigh(backlight_pin); | ||
43 | #else | ||
44 | writePinLow(backlight_pin); | ||
45 | #endif | ||
46 | } | ||
47 | |||
48 | void backlight_init_ports(void) { | ||
49 | // Setup backlight pin as output and output to on state. | ||
50 | FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);) | ||
51 | } | ||
52 | |||
53 | void backlight_task(void) { | ||
54 | static uint8_t backlight_tick = 0; | ||
55 | |||
56 | if ((0xFFFF >> (get_backlight_level() * ((BACKLIGHT_LEVELS + 1) / 2))) & (1 << backlight_tick)) { | ||
57 | FOR_EACH_LED(backlight_on(backlight_pin);) | ||
58 | } else { | ||
59 | FOR_EACH_LED(backlight_off(backlight_pin);) | ||
60 | } | ||
61 | backlight_tick = (backlight_tick + 1) % 16; | ||
62 | } | ||
63 | |||
64 | void backlight_set(uint8_t level) { | ||
65 | // noop as backlight_task uses get_backlight_level() | ||
66 | } | ||