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
This commit is contained in:
Joel Challis 2020-03-07 12:09:49 +00:00 committed by GitHub
parent d7ba0ad684
commit 3a303bd2ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 73 additions and 69 deletions

View file

@ -297,24 +297,27 @@ VALID_BACKLIGHT_TYPES := pwm software custom
BACKLIGHT_ENABLE ?= no
BACKLIGHT_DRIVER ?= pwm
ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
SRC += $(QUANTUM_DIR)/process_keycode/process_backlight.c
ifeq ($(filter $(BACKLIGHT_DRIVER),$(VALID_BACKLIGHT_TYPES)),)
$(error BACKLIGHT_DRIVER="$(BACKLIGHT_DRIVER)" is not a valid backlight type)
endif
COMMON_VPATH += $(QUANTUM_DIR)/backlight
SRC += $(QUANTUM_DIR)/backlight/backlight.c
SRC += $(QUANTUM_DIR)/process_keycode/process_backlight.c
OPT_DEFS += -DBACKLIGHT_ENABLE
ifeq ($(strip $(BACKLIGHT_DRIVER)), custom)
OPT_DEFS += -DBACKLIGHT_CUSTOM_DRIVER
else ifeq ($(strip $(BACKLIGHT_DRIVER)), software)
SRC += $(QUANTUM_DIR)/backlight/backlight_soft.c
else
ifeq ($(PLATFORM),AVR)
SRC += $(QUANTUM_DIR)/backlight/backlight_avr.c
SRC += $(QUANTUM_DIR)/backlight/backlight_driver_common.c
ifeq ($(strip $(BACKLIGHT_DRIVER)), pwm)
ifeq ($(PLATFORM),AVR)
SRC += $(QUANTUM_DIR)/backlight/backlight_avr.c
else
SRC += $(QUANTUM_DIR)/backlight/backlight_arm.c
endif
else
SRC += $(QUANTUM_DIR)/backlight/backlight_arm.c
SRC += $(QUANTUM_DIR)/backlight/backlight_$(strip $(BACKLIGHT_DRIVER)).c
endif
endif
endif

View file

@ -20,6 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "eeconfig.h"
#include "debug.h"
#if defined(STM32F0XX) || defined(STM32F0xx)
# pragma message("Backlight support for STMF072 has had limited testing, YMMV. If unsure, set 'BACKLIGHT_ENABLE = no' in your rules.mk")
#endif
backlight_config_t backlight_config;
#ifdef BACKLIGHT_BREATHING
@ -27,51 +31,6 @@ backlight_config_t backlight_config;
static uint8_t breathing_period = BREATHING_PERIOD;
#endif
#ifndef BACKLIGHT_CUSTOM_DRIVER
# if defined(BACKLIGHT_PINS)
static const pin_t backlight_pins[] = BACKLIGHT_PINS;
# ifndef BACKLIGHT_LED_COUNT
# define BACKLIGHT_LED_COUNT (sizeof(backlight_pins) / sizeof(pin_t))
# endif
# define FOR_EACH_LED(x) \
for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) { \
pin_t backlight_pin = backlight_pins[i]; \
{ x } \
}
# else
// we support only one backlight pin
static const pin_t backlight_pin = BACKLIGHT_PIN;
# define FOR_EACH_LED(x) x
# endif
static inline void backlight_on(pin_t backlight_pin) {
# if BACKLIGHT_ON_STATE == 0
writePinLow(backlight_pin);
# else
writePinHigh(backlight_pin);
# endif
}
static inline void backlight_off(pin_t backlight_pin) {
# if BACKLIGHT_ON_STATE == 0
writePinHigh(backlight_pin);
# else
writePinLow(backlight_pin);
# endif
}
void backlight_pins_init(void) {
// Setup backlight pin as output and output to off state.
FOR_EACH_LED(setPinOutput(backlight_pin); backlight_off(backlight_pin);)
}
void backlight_pins_on(void) { FOR_EACH_LED(backlight_on(backlight_pin);) }
void backlight_pins_off(void) { FOR_EACH_LED(backlight_off(backlight_pin);) }
#endif
/** \brief Backlight initialization
*
* FIXME: needs doc

View file

@ -44,10 +44,6 @@ typedef union {
};
} backlight_config_t;
void backlight_pins_init(void);
void backlight_pins_on(void);
void backlight_pins_off(void);
void backlight_init(void);
void backlight_toggle(void);
void backlight_enable(void);
@ -79,11 +75,11 @@ void breathing_period_default(void);
void breathing_period_inc(void);
void breathing_period_dec(void);
void breathing_toggle(void);
// implementation specific
void breathing_enable(void);
void breathing_disable(void);
void breathing_toggle(void);
bool is_breathing(void);
void breathing_pulse(void);
void breathing_task(void);
#endif

View file

@ -6,10 +6,6 @@
// TODO: remove short term bodge when refactoring BACKLIGHT_CUSTOM_DRIVER out
#ifdef BACKLIGHT_PIN
# if defined(STM32F0XX) || defined(STM32F0xx)
# pragma message("Backlight support for STMF072 has had limited testing, YMMV. If unsure, set 'BACKLIGHT_ENABLE = no' in your rules.mk")
# endif
// GPIOV2 && GPIOV3
# ifndef BACKLIGHT_PAL_MODE
# define BACKLIGHT_PAL_MODE 2

View file

@ -1,11 +1,8 @@
#include "quantum.h"
#include "backlight.h"
#include "backlight_driver_common.h"
#include "debug.h"
#if !defined(BACKLIGHT_PIN) && !defined(BACKLIGHT_PINS)
# error "Backlight pin/pins not defined. Please configure."
#endif
// This logic is a bit complex, we support 3 setups:
//
// 1. Hardware PWM when backlight is wired to a PWM pin.

View file

@ -0,0 +1,49 @@
#include "quantum.h"
#include "backlight.h"
#include "backlight_driver_common.h"
#if !defined(BACKLIGHT_PIN) && !defined(BACKLIGHT_PINS)
# error "Backlight pin/pins not defined. Please configure."
#endif
#if defined(BACKLIGHT_PINS)
static const pin_t backlight_pins[] = BACKLIGHT_PINS;
# ifndef BACKLIGHT_LED_COUNT
# define BACKLIGHT_LED_COUNT (sizeof(backlight_pins) / sizeof(pin_t))
# endif
# define FOR_EACH_LED(x) \
for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) { \
pin_t backlight_pin = backlight_pins[i]; \
{ x } \
}
#else
// we support only one backlight pin
static const pin_t backlight_pin = BACKLIGHT_PIN;
# define FOR_EACH_LED(x) x
#endif
static inline void backlight_on(pin_t backlight_pin) {
#if BACKLIGHT_ON_STATE == 0
writePinLow(backlight_pin);
#else
writePinHigh(backlight_pin);
#endif
}
static inline void backlight_off(pin_t backlight_pin) {
#if BACKLIGHT_ON_STATE == 0
writePinHigh(backlight_pin);
#else
writePinLow(backlight_pin);
#endif
}
void backlight_pins_init(void) {
// Setup backlight pin as output and output to off state.
FOR_EACH_LED(setPinOutput(backlight_pin); backlight_off(backlight_pin);)
}
void backlight_pins_on(void) { FOR_EACH_LED(backlight_on(backlight_pin);) }
void backlight_pins_off(void) { FOR_EACH_LED(backlight_off(backlight_pin);) }

View file

@ -0,0 +1,7 @@
#pragma once
void backlight_pins_init(void);
void backlight_pins_on(void);
void backlight_pins_off(void);
void breathing_task(void);

View file

@ -1,9 +1,6 @@
#include "quantum.h"
#include "backlight.h"
#if !defined(BACKLIGHT_PIN) && !defined(BACKLIGHT_PINS)
# error "Backlight pin/pins not defined. Please configure."
#endif
#include "backlight_driver_common.h"
#ifdef BACKLIGHT_BREATHING
# error "Backlight breathing is not available for software PWM. Please disable."