diff options
Diffstat (limited to 'quantum/backlight/backlight.c')
-rw-r--r-- | quantum/backlight/backlight.c | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/quantum/backlight/backlight.c b/quantum/backlight/backlight.c index 4aa74667d..4a0eac64c 100644 --- a/quantum/backlight/backlight.c +++ b/quantum/backlight/backlight.c | |||
@@ -15,14 +15,62 @@ You should have received a copy of the GNU General Public License | |||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "quantum.h" | ||
18 | #include "backlight.h" | 19 | #include "backlight.h" |
19 | #include "eeconfig.h" | 20 | #include "eeconfig.h" |
20 | #include "debug.h" | 21 | #include "debug.h" |
21 | 22 | ||
22 | backlight_config_t backlight_config; | 23 | backlight_config_t backlight_config; |
23 | 24 | ||
25 | #ifdef BACKLIGHT_BREATHING | ||
24 | // TODO: migrate to backlight_config_t | 26 | // TODO: migrate to backlight_config_t |
25 | static uint8_t breathing_period = BREATHING_PERIOD; | 27 | static uint8_t breathing_period = BREATHING_PERIOD; |
28 | #endif | ||
29 | |||
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 | ||
26 | 74 | ||
27 | /** \brief Backlight initialization | 75 | /** \brief Backlight initialization |
28 | * | 76 | * |
@@ -205,7 +253,6 @@ void backlight_disable_breathing(void) { | |||
205 | * FIXME: needs doc | 253 | * FIXME: needs doc |
206 | */ | 254 | */ |
207 | bool is_backlight_breathing(void) { return backlight_config.breathing; } | 255 | bool is_backlight_breathing(void) { return backlight_config.breathing; } |
208 | #endif | ||
209 | 256 | ||
210 | // following are marked as weak purely for backwards compatibility | 257 | // following are marked as weak purely for backwards compatibility |
211 | __attribute__((weak)) void breathing_period_set(uint8_t value) { breathing_period = value ? value : 1; } | 258 | __attribute__((weak)) void breathing_period_set(uint8_t value) { breathing_period = value ? value : 1; } |
@@ -218,6 +265,15 @@ __attribute__((weak)) void breathing_period_inc(void) { breathing_period_set(bre | |||
218 | 265 | ||
219 | __attribute__((weak)) void breathing_period_dec(void) { breathing_period_set(breathing_period - 1); } | 266 | __attribute__((weak)) void breathing_period_dec(void) { breathing_period_set(breathing_period - 1); } |
220 | 267 | ||
268 | __attribute__((weak)) void breathing_toggle(void) { | ||
269 | if (is_breathing()) | ||
270 | breathing_disable(); | ||
271 | else | ||
272 | breathing_enable(); | ||
273 | } | ||
274 | |||
275 | #endif | ||
276 | |||
221 | // defaults for backlight api | 277 | // defaults for backlight api |
222 | __attribute__((weak)) void backlight_init_ports(void) {} | 278 | __attribute__((weak)) void backlight_init_ports(void) {} |
223 | 279 | ||