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
This commit is contained in:
parent
116c0e44a1
commit
918a85d342
5 changed files with 78 additions and 112 deletions
|
@ -15,14 +15,62 @@ You should have received a copy of the GNU General Public License
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "quantum.h"
|
||||
#include "backlight.h"
|
||||
#include "eeconfig.h"
|
||||
#include "debug.h"
|
||||
|
||||
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
|
||||
*
|
||||
|
@ -205,7 +253,6 @@ void backlight_disable_breathing(void) {
|
|||
* FIXME: needs doc
|
||||
*/
|
||||
bool is_backlight_breathing(void) { return backlight_config.breathing; }
|
||||
#endif
|
||||
|
||||
// following are marked as weak purely for backwards compatibility
|
||||
__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
|
|||
|
||||
__attribute__((weak)) void breathing_period_dec(void) { breathing_period_set(breathing_period - 1); }
|
||||
|
||||
__attribute__((weak)) void breathing_toggle(void) {
|
||||
if (is_breathing())
|
||||
breathing_disable();
|
||||
else
|
||||
breathing_enable();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// defaults for backlight api
|
||||
__attribute__((weak)) void backlight_init_ports(void) {}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue