Skip to content

Commit

Permalink
Backlight - Carve out a better location for private driver functional…
Browse files Browse the repository at this point in the history
…ity (qmk#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
  • Loading branch information
zvecr authored Mar 7, 2020
1 parent d7ba0ad commit 3a303bd
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 69 deletions.
15 changes: 9 additions & 6 deletions common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 4 additions & 45 deletions quantum/backlight/backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,58 +20,17 @@ 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
// TODO: migrate to backlight_config_t
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
Expand Down
8 changes: 2 additions & 6 deletions quantum/backlight/backlight.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
4 changes: 0 additions & 4 deletions quantum/backlight/backlight_arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions quantum/backlight/backlight_avr.c
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
49 changes: 49 additions & 0 deletions quantum/backlight/backlight_driver_common.c
Original file line number Diff line number Diff line change
@@ -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);) }
7 changes: 7 additions & 0 deletions quantum/backlight/backlight_driver_common.h
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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."
Expand Down

0 comments on commit 3a303bd

Please sign in to comment.