2020-03-07 12:09:49 +00:00
|
|
|
#include "backlight.h"
|
|
|
|
#include "backlight_driver_common.h"
|
2023-07-08 13:13:10 +00:00
|
|
|
#include "gpio.h"
|
|
|
|
#include "util.h"
|
2020-03-07 12:09:49 +00:00
|
|
|
|
|
|
|
#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
|
2022-08-30 08:20:04 +00:00
|
|
|
# define BACKLIGHT_LED_COUNT ARRAY_SIZE(backlight_pins)
|
2020-03-07 12:09:49 +00:00
|
|
|
# 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
|
2024-02-18 06:08:27 +00:00
|
|
|
gpio_write_pin_low(backlight_pin);
|
2020-03-07 12:09:49 +00:00
|
|
|
#else
|
2024-02-18 06:08:27 +00:00
|
|
|
gpio_write_pin_high(backlight_pin);
|
2020-03-07 12:09:49 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void backlight_off(pin_t backlight_pin) {
|
|
|
|
#if BACKLIGHT_ON_STATE == 0
|
2024-02-18 06:08:27 +00:00
|
|
|
gpio_write_pin_high(backlight_pin);
|
2020-03-07 12:09:49 +00:00
|
|
|
#else
|
2024-02-18 06:08:27 +00:00
|
|
|
gpio_write_pin_low(backlight_pin);
|
2020-03-07 12:09:49 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void backlight_pins_init(void) {
|
|
|
|
// Setup backlight pin as output and output to off state.
|
2024-02-18 06:08:27 +00:00
|
|
|
FOR_EACH_LED(gpio_set_pin_output(backlight_pin); backlight_off(backlight_pin);)
|
2020-03-07 12:09:49 +00:00
|
|
|
}
|
|
|
|
|
2022-02-12 18:29:31 +00:00
|
|
|
void backlight_pins_on(void) {
|
|
|
|
FOR_EACH_LED(backlight_on(backlight_pin);)
|
|
|
|
}
|
2020-03-07 12:09:49 +00:00
|
|
|
|
2022-02-12 18:29:31 +00:00
|
|
|
void backlight_pins_off(void) {
|
|
|
|
FOR_EACH_LED(backlight_off(backlight_pin);)
|
|
|
|
}
|