You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB

  1. #include "quantum.h"
  2. #include "backlight.h"
  3. #include "backlight_driver_common.h"
  4. #if !defined(BACKLIGHT_PIN) && !defined(BACKLIGHT_PINS)
  5. # error "Backlight pin/pins not defined. Please configure."
  6. #endif
  7. #if defined(BACKLIGHT_PINS)
  8. static const pin_t backlight_pins[] = BACKLIGHT_PINS;
  9. # ifndef BACKLIGHT_LED_COUNT
  10. # define BACKLIGHT_LED_COUNT (sizeof(backlight_pins) / sizeof(pin_t))
  11. # endif
  12. # define FOR_EACH_LED(x) \
  13. for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) { \
  14. pin_t backlight_pin = backlight_pins[i]; \
  15. { x } \
  16. }
  17. #else
  18. // we support only one backlight pin
  19. static const pin_t backlight_pin = BACKLIGHT_PIN;
  20. # define FOR_EACH_LED(x) x
  21. #endif
  22. static inline void backlight_on(pin_t backlight_pin) {
  23. #if BACKLIGHT_ON_STATE == 0
  24. writePinLow(backlight_pin);
  25. #else
  26. writePinHigh(backlight_pin);
  27. #endif
  28. }
  29. static inline void backlight_off(pin_t backlight_pin) {
  30. #if BACKLIGHT_ON_STATE == 0
  31. writePinHigh(backlight_pin);
  32. #else
  33. writePinLow(backlight_pin);
  34. #endif
  35. }
  36. void backlight_pins_init(void) {
  37. // Setup backlight pin as output and output to off state.
  38. FOR_EACH_LED(setPinOutput(backlight_pin); backlight_off(backlight_pin);)
  39. }
  40. void backlight_pins_on(void) { FOR_EACH_LED(backlight_on(backlight_pin);) }
  41. void backlight_pins_off(void) { FOR_EACH_LED(backlight_off(backlight_pin);) }