diff options
author | Joel Challis <git@zvecr.com> | 2020-03-06 12:49:45 +0000 |
---|---|---|
committer | Florian Didron <fdidron@users.noreply.github.com> | 2020-06-12 17:00:27 +0900 |
commit | c90f03da99ce7ec515ca305d07239d9ccc6c2f47 (patch) | |
tree | 717aec3dcb68649aec724e7377a4fda3008957c6 /quantum/backlight/backlight_avr.c | |
parent | 2aa0d5f3d1d34f7018a28087e154688fba7eed90 (diff) |
Refactor more backlight to a common location (#8292)
* Refactor more backlight to a common location
* BACKLIGHT_PIN not defined for custom backlight
* align function names
Diffstat (limited to 'quantum/backlight/backlight_avr.c')
-rw-r--r-- | quantum/backlight/backlight_avr.c | 63 |
1 files changed, 5 insertions, 58 deletions
diff --git a/quantum/backlight/backlight_avr.c b/quantum/backlight/backlight_avr.c index ce6611fb5a..40291d3821 100644 --- a/quantum/backlight/backlight_avr.c +++ b/quantum/backlight/backlight_avr.c @@ -164,49 +164,7 @@ error("Please set 'BACKLIGHT_DRIVER = custom' within rules.mk") error("Please set 'BACKLIGHT_DRIVER = software' within rules.mk") #endif -#ifndef BACKLIGHT_ON_STATE -# define BACKLIGHT_ON_STATE 1 -#endif - -void backlight_on(pin_t backlight_pin) { -#if BACKLIGHT_ON_STATE == 1 - writePinHigh(backlight_pin); -#else - writePinLow(backlight_pin); -#endif -} - -void backlight_off(pin_t backlight_pin) { -#if BACKLIGHT_ON_STATE == 1 - writePinLow(backlight_pin); -#else - writePinHigh(backlight_pin); -#endif -} - -#ifdef BACKLIGHT_PWM_TIMER // pwm through software - -// we support multiple backlight pins -# ifndef BACKLIGHT_LED_COUNT -# define BACKLIGHT_LED_COUNT 1 -# endif - -# if BACKLIGHT_LED_COUNT == 1 -# define BACKLIGHT_PIN_INIT \ - { BACKLIGHT_PIN } -# else -# define BACKLIGHT_PIN_INIT BACKLIGHT_PINS -# endif - -# define FOR_EACH_LED(x) \ - for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) { \ - pin_t backlight_pin = backlight_pins[i]; \ - { x } \ - } - -static const pin_t backlight_pins[BACKLIGHT_LED_COUNT] = BACKLIGHT_PIN_INIT; - -#else // full hardware PWM +#ifndef BACKLIGHT_PWM_TIMER // pwm through software static inline void enable_pwm(void) { # if BACKLIGHT_ON_STATE == 1 @@ -224,10 +182,6 @@ static inline void disable_pwm(void) { # endif } -// we support only one backlight pin -static const pin_t backlight_pin = BACKLIGHT_PIN; -# define FOR_EACH_LED(x) x - #endif #ifdef BACKLIGHT_PWM_TIMER @@ -246,7 +200,7 @@ static const pin_t backlight_pin = BACKLIGHT_PIN; // The LED will then be on for OCRxx/0xFFFF time, adjusted every 244Hz. // Triggered when the counter reaches the OCRx value -ISR(TIMERx_COMPA_vect) { FOR_EACH_LED(backlight_off(backlight_pin);) } +ISR(TIMERx_COMPA_vect) { backlight_pins_off(); } // Triggered when the counter reaches the TOP value // this one triggers at F_CPU/65536 =~ 244 Hz @@ -265,7 +219,7 @@ ISR(TIMERx_OVF_vect) { // takes many computation cycles). // so better not turn them on while the counter TOP is very low. if (OCRxx > 256) { - FOR_EACH_LED(backlight_on(backlight_pin);) + backlight_pins_on(); } } @@ -305,7 +259,7 @@ void backlight_set(uint8_t level) { // Turn off PWM control on backlight pin disable_pwm(); #endif - FOR_EACH_LED(backlight_off(backlight_pin);) + backlight_pins_off(); } else { #ifdef BACKLIGHT_PWM_TIMER if (!OCRxx) { @@ -397,13 +351,6 @@ void breathing_self_disable(void) { breathing_halt = BREATHING_HALT_ON; } -void breathing_toggle(void) { - if (is_breathing()) - breathing_disable(); - else - breathing_enable(); -} - /* To generate breathing curve in python: * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] */ @@ -438,7 +385,7 @@ ISR(TIMERx_OVF_vect) void backlight_init_ports(void) { // Setup backlight pin as output and output to on state. - FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);) + backlight_pins_init(); // I could write a wall of text here to explain... but TL;DW // Go read the ATmega32u4 datasheet. |