diff options
author | Joel Challis <git@zvecr.com> | 2020-03-07 12:09:49 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-07 12:09:49 +0000 |
commit | 3a303bd2aec57fd2d4d0f6d3e5583d746367d6e1 (patch) | |
tree | 8ab57281f90be800b6e3556e2705ffbcabf1494c /quantum/backlight/backlight_driver_common.c | |
parent | d7ba0ad684a18c07952963427ca89a8e8e7e1903 (diff) | |
download | qmk_firmware-3a303bd2aec57fd2d4d0f6d3e5583d746367d6e1.tar.gz qmk_firmware-3a303bd2aec57fd2d4d0f6d3e5583d746367d6e1.zip |
Backlight - Carve out a better location for private driver functionality (#8329)
* rename backlight_soft to match rules.mk
* rename backlight_soft to match rules.mk - update common_features
* Carve out a better location for private driver backlight functionality
Diffstat (limited to 'quantum/backlight/backlight_driver_common.c')
-rw-r--r-- | quantum/backlight/backlight_driver_common.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/quantum/backlight/backlight_driver_common.c b/quantum/backlight/backlight_driver_common.c new file mode 100644 index 000000000..270a43c67 --- /dev/null +++ b/quantum/backlight/backlight_driver_common.c | |||
@@ -0,0 +1,49 @@ | |||
1 | #include "quantum.h" | ||
2 | #include "backlight.h" | ||
3 | #include "backlight_driver_common.h" | ||
4 | |||
5 | #if !defined(BACKLIGHT_PIN) && !defined(BACKLIGHT_PINS) | ||
6 | # error "Backlight pin/pins not defined. Please configure." | ||
7 | #endif | ||
8 | |||
9 | #if defined(BACKLIGHT_PINS) | ||
10 | static const pin_t backlight_pins[] = BACKLIGHT_PINS; | ||
11 | # ifndef BACKLIGHT_LED_COUNT | ||
12 | # define BACKLIGHT_LED_COUNT (sizeof(backlight_pins) / sizeof(pin_t)) | ||
13 | # endif | ||
14 | |||
15 | # define FOR_EACH_LED(x) \ | ||
16 | for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) { \ | ||
17 | pin_t backlight_pin = backlight_pins[i]; \ | ||
18 | { x } \ | ||
19 | } | ||
20 | #else | ||
21 | // we support only one backlight pin | ||
22 | static const pin_t backlight_pin = BACKLIGHT_PIN; | ||
23 | # define FOR_EACH_LED(x) x | ||
24 | #endif | ||
25 | |||
26 | static inline void backlight_on(pin_t backlight_pin) { | ||
27 | #if BACKLIGHT_ON_STATE == 0 | ||
28 | writePinLow(backlight_pin); | ||
29 | #else | ||
30 | writePinHigh(backlight_pin); | ||
31 | #endif | ||
32 | } | ||
33 | |||
34 | static inline void backlight_off(pin_t backlight_pin) { | ||
35 | #if BACKLIGHT_ON_STATE == 0 | ||
36 | writePinHigh(backlight_pin); | ||
37 | #else | ||
38 | writePinLow(backlight_pin); | ||
39 | #endif | ||
40 | } | ||
41 | |||
42 | void backlight_pins_init(void) { | ||
43 | // Setup backlight pin as output and output to off state. | ||
44 | FOR_EACH_LED(setPinOutput(backlight_pin); backlight_off(backlight_pin);) | ||
45 | } | ||
46 | |||
47 | void backlight_pins_on(void) { FOR_EACH_LED(backlight_on(backlight_pin);) } | ||
48 | |||
49 | void backlight_pins_off(void) { FOR_EACH_LED(backlight_off(backlight_pin);) } | ||