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 | |
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
-rw-r--r-- | common_features.mk | 15 | ||||
-rw-r--r-- | quantum/backlight/backlight.c | 49 | ||||
-rw-r--r-- | quantum/backlight/backlight.h | 8 | ||||
-rw-r--r-- | quantum/backlight/backlight_arm.c | 4 | ||||
-rw-r--r-- | quantum/backlight/backlight_avr.c | 5 | ||||
-rw-r--r-- | quantum/backlight/backlight_driver_common.c | 49 | ||||
-rw-r--r-- | quantum/backlight/backlight_driver_common.h | 7 | ||||
-rw-r--r-- | quantum/backlight/backlight_software.c (renamed from quantum/backlight/backlight_soft.c) | 5 |
8 files changed, 73 insertions, 69 deletions
diff --git a/common_features.mk b/common_features.mk index 36cae7865..fe65974e7 100644 --- a/common_features.mk +++ b/common_features.mk | |||
@@ -297,24 +297,27 @@ VALID_BACKLIGHT_TYPES := pwm software custom | |||
297 | BACKLIGHT_ENABLE ?= no | 297 | BACKLIGHT_ENABLE ?= no |
298 | BACKLIGHT_DRIVER ?= pwm | 298 | BACKLIGHT_DRIVER ?= pwm |
299 | ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) | 299 | ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) |
300 | SRC += $(QUANTUM_DIR)/process_keycode/process_backlight.c | ||
301 | ifeq ($(filter $(BACKLIGHT_DRIVER),$(VALID_BACKLIGHT_TYPES)),) | 300 | ifeq ($(filter $(BACKLIGHT_DRIVER),$(VALID_BACKLIGHT_TYPES)),) |
302 | $(error BACKLIGHT_DRIVER="$(BACKLIGHT_DRIVER)" is not a valid backlight type) | 301 | $(error BACKLIGHT_DRIVER="$(BACKLIGHT_DRIVER)" is not a valid backlight type) |
303 | endif | 302 | endif |
304 | 303 | ||
305 | COMMON_VPATH += $(QUANTUM_DIR)/backlight | 304 | COMMON_VPATH += $(QUANTUM_DIR)/backlight |
306 | SRC += $(QUANTUM_DIR)/backlight/backlight.c | 305 | SRC += $(QUANTUM_DIR)/backlight/backlight.c |
306 | SRC += $(QUANTUM_DIR)/process_keycode/process_backlight.c | ||
307 | OPT_DEFS += -DBACKLIGHT_ENABLE | 307 | OPT_DEFS += -DBACKLIGHT_ENABLE |
308 | 308 | ||
309 | ifeq ($(strip $(BACKLIGHT_DRIVER)), custom) | 309 | ifeq ($(strip $(BACKLIGHT_DRIVER)), custom) |
310 | OPT_DEFS += -DBACKLIGHT_CUSTOM_DRIVER | 310 | OPT_DEFS += -DBACKLIGHT_CUSTOM_DRIVER |
311 | else ifeq ($(strip $(BACKLIGHT_DRIVER)), software) | ||
312 | SRC += $(QUANTUM_DIR)/backlight/backlight_soft.c | ||
313 | else | 311 | else |
314 | ifeq ($(PLATFORM),AVR) | 312 | SRC += $(QUANTUM_DIR)/backlight/backlight_driver_common.c |
315 | SRC += $(QUANTUM_DIR)/backlight/backlight_avr.c | 313 | ifeq ($(strip $(BACKLIGHT_DRIVER)), pwm) |
314 | ifeq ($(PLATFORM),AVR) | ||
315 | SRC += $(QUANTUM_DIR)/backlight/backlight_avr.c | ||
316 | else | ||
317 | SRC += $(QUANTUM_DIR)/backlight/backlight_arm.c | ||
318 | endif | ||
316 | else | 319 | else |
317 | SRC += $(QUANTUM_DIR)/backlight/backlight_arm.c | 320 | SRC += $(QUANTUM_DIR)/backlight/backlight_$(strip $(BACKLIGHT_DRIVER)).c |
318 | endif | 321 | endif |
319 | endif | 322 | endif |
320 | endif | 323 | endif |
diff --git a/quantum/backlight/backlight.c b/quantum/backlight/backlight.c index 4a0eac64c..34dd8cbdb 100644 --- a/quantum/backlight/backlight.c +++ b/quantum/backlight/backlight.c | |||
@@ -20,6 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
20 | #include "eeconfig.h" | 20 | #include "eeconfig.h" |
21 | #include "debug.h" | 21 | #include "debug.h" |
22 | 22 | ||
23 | #if defined(STM32F0XX) || defined(STM32F0xx) | ||
24 | # pragma message("Backlight support for STMF072 has had limited testing, YMMV. If unsure, set 'BACKLIGHT_ENABLE = no' in your rules.mk") | ||
25 | #endif | ||
26 | |||
23 | backlight_config_t backlight_config; | 27 | backlight_config_t backlight_config; |
24 | 28 | ||
25 | #ifdef BACKLIGHT_BREATHING | 29 | #ifdef BACKLIGHT_BREATHING |
@@ -27,51 +31,6 @@ backlight_config_t backlight_config; | |||
27 | static uint8_t breathing_period = BREATHING_PERIOD; | 31 | static uint8_t breathing_period = BREATHING_PERIOD; |
28 | #endif | 32 | #endif |
29 | 33 | ||
30 | #ifndef BACKLIGHT_CUSTOM_DRIVER | ||
31 | # if defined(BACKLIGHT_PINS) | ||
32 | static const pin_t backlight_pins[] = BACKLIGHT_PINS; | ||
33 | # ifndef BACKLIGHT_LED_COUNT | ||
34 | # define BACKLIGHT_LED_COUNT (sizeof(backlight_pins) / sizeof(pin_t)) | ||
35 | # endif | ||
36 | |||
37 | # define FOR_EACH_LED(x) \ | ||
38 | for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) { \ | ||
39 | pin_t backlight_pin = backlight_pins[i]; \ | ||
40 | { x } \ | ||
41 | } | ||
42 | # else | ||
43 | // we support only one backlight pin | ||
44 | static const pin_t backlight_pin = BACKLIGHT_PIN; | ||
45 | # define FOR_EACH_LED(x) x | ||
46 | # endif | ||
47 | |||
48 | static inline void backlight_on(pin_t backlight_pin) { | ||
49 | # if BACKLIGHT_ON_STATE == 0 | ||
50 | writePinLow(backlight_pin); | ||
51 | # else | ||
52 | writePinHigh(backlight_pin); | ||
53 | # endif | ||
54 | } | ||
55 | |||
56 | static inline void backlight_off(pin_t backlight_pin) { | ||
57 | # if BACKLIGHT_ON_STATE == 0 | ||
58 | writePinHigh(backlight_pin); | ||
59 | # else | ||
60 | writePinLow(backlight_pin); | ||
61 | # endif | ||
62 | } | ||
63 | |||
64 | void backlight_pins_init(void) { | ||
65 | // Setup backlight pin as output and output to off state. | ||
66 | FOR_EACH_LED(setPinOutput(backlight_pin); backlight_off(backlight_pin);) | ||
67 | } | ||
68 | |||
69 | void backlight_pins_on(void) { FOR_EACH_LED(backlight_on(backlight_pin);) } | ||
70 | |||
71 | void backlight_pins_off(void) { FOR_EACH_LED(backlight_off(backlight_pin);) } | ||
72 | |||
73 | #endif | ||
74 | |||
75 | /** \brief Backlight initialization | 34 | /** \brief Backlight initialization |
76 | * | 35 | * |
77 | * FIXME: needs doc | 36 | * FIXME: needs doc |
diff --git a/quantum/backlight/backlight.h b/quantum/backlight/backlight.h index 07a4880e9..3e506737d 100644 --- a/quantum/backlight/backlight.h +++ b/quantum/backlight/backlight.h | |||
@@ -44,10 +44,6 @@ typedef union { | |||
44 | }; | 44 | }; |
45 | } backlight_config_t; | 45 | } backlight_config_t; |
46 | 46 | ||
47 | void backlight_pins_init(void); | ||
48 | void backlight_pins_on(void); | ||
49 | void backlight_pins_off(void); | ||
50 | |||
51 | void backlight_init(void); | 47 | void backlight_init(void); |
52 | void backlight_toggle(void); | 48 | void backlight_toggle(void); |
53 | void backlight_enable(void); | 49 | void backlight_enable(void); |
@@ -79,11 +75,11 @@ void breathing_period_default(void); | |||
79 | void breathing_period_inc(void); | 75 | void breathing_period_inc(void); |
80 | void breathing_period_dec(void); | 76 | void breathing_period_dec(void); |
81 | 77 | ||
78 | void breathing_toggle(void); | ||
79 | |||
82 | // implementation specific | 80 | // implementation specific |
83 | void breathing_enable(void); | 81 | void breathing_enable(void); |
84 | void breathing_disable(void); | 82 | void breathing_disable(void); |
85 | void breathing_toggle(void); | ||
86 | bool is_breathing(void); | 83 | bool is_breathing(void); |
87 | void breathing_pulse(void); | 84 | void breathing_pulse(void); |
88 | void breathing_task(void); | ||
89 | #endif | 85 | #endif |
diff --git a/quantum/backlight/backlight_arm.c b/quantum/backlight/backlight_arm.c index a6d38a1a0..723544adb 100644 --- a/quantum/backlight/backlight_arm.c +++ b/quantum/backlight/backlight_arm.c | |||
@@ -6,10 +6,6 @@ | |||
6 | // TODO: remove short term bodge when refactoring BACKLIGHT_CUSTOM_DRIVER out | 6 | // TODO: remove short term bodge when refactoring BACKLIGHT_CUSTOM_DRIVER out |
7 | #ifdef BACKLIGHT_PIN | 7 | #ifdef BACKLIGHT_PIN |
8 | 8 | ||
9 | # if defined(STM32F0XX) || defined(STM32F0xx) | ||
10 | # pragma message("Backlight support for STMF072 has had limited testing, YMMV. If unsure, set 'BACKLIGHT_ENABLE = no' in your rules.mk") | ||
11 | # endif | ||
12 | |||
13 | // GPIOV2 && GPIOV3 | 9 | // GPIOV2 && GPIOV3 |
14 | # ifndef BACKLIGHT_PAL_MODE | 10 | # ifndef BACKLIGHT_PAL_MODE |
15 | # define BACKLIGHT_PAL_MODE 2 | 11 | # define BACKLIGHT_PAL_MODE 2 |
diff --git a/quantum/backlight/backlight_avr.c b/quantum/backlight/backlight_avr.c index 40291d382..ce13f1118 100644 --- a/quantum/backlight/backlight_avr.c +++ b/quantum/backlight/backlight_avr.c | |||
@@ -1,11 +1,8 @@ | |||
1 | #include "quantum.h" | 1 | #include "quantum.h" |
2 | #include "backlight.h" | 2 | #include "backlight.h" |
3 | #include "backlight_driver_common.h" | ||
3 | #include "debug.h" | 4 | #include "debug.h" |
4 | 5 | ||
5 | #if !defined(BACKLIGHT_PIN) && !defined(BACKLIGHT_PINS) | ||
6 | # error "Backlight pin/pins not defined. Please configure." | ||
7 | #endif | ||
8 | |||
9 | // This logic is a bit complex, we support 3 setups: | 6 | // This logic is a bit complex, we support 3 setups: |
10 | // | 7 | // |
11 | // 1. Hardware PWM when backlight is wired to a PWM pin. | 8 | // 1. Hardware PWM when backlight is wired to a PWM pin. |
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);) } | ||
diff --git a/quantum/backlight/backlight_driver_common.h b/quantum/backlight/backlight_driver_common.h new file mode 100644 index 000000000..36e8a5fa6 --- /dev/null +++ b/quantum/backlight/backlight_driver_common.h | |||
@@ -0,0 +1,7 @@ | |||
1 | #pragma once | ||
2 | |||
3 | void backlight_pins_init(void); | ||
4 | void backlight_pins_on(void); | ||
5 | void backlight_pins_off(void); | ||
6 | |||
7 | void breathing_task(void); | ||
diff --git a/quantum/backlight/backlight_soft.c b/quantum/backlight/backlight_software.c index 8552384a4..709304f55 100644 --- a/quantum/backlight/backlight_soft.c +++ b/quantum/backlight/backlight_software.c | |||
@@ -1,9 +1,6 @@ | |||
1 | #include "quantum.h" | 1 | #include "quantum.h" |
2 | #include "backlight.h" | 2 | #include "backlight.h" |
3 | 3 | #include "backlight_driver_common.h" | |
4 | #if !defined(BACKLIGHT_PIN) && !defined(BACKLIGHT_PINS) | ||
5 | # error "Backlight pin/pins not defined. Please configure." | ||
6 | #endif | ||
7 | 4 | ||
8 | #ifdef BACKLIGHT_BREATHING | 5 | #ifdef BACKLIGHT_BREATHING |
9 | # error "Backlight breathing is not available for software PWM. Please disable." | 6 | # error "Backlight breathing is not available for software PWM. Please disable." |