Keyboard firmwares for Atmel AVR and Cortex-M
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.

backlight.c 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. Copyright 2014 Ralf Schmitt <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <avr/io.h>
  15. #include "backlight.h"
  16. void backlight_init_ports()
  17. {
  18. DDRB |= 0b11100000; // PB7 (switch), PB6 (pcb), PB5 (caps)
  19. }
  20. void backlight_set(uint8_t level)
  21. {
  22. (level & BACKLIGHT_SWITCH) ? backlight_switch_enable() : backlight_switch_disable();
  23. (level & BACKLIGHT_PCB) ? backlight_pcb_enable() : backlight_pcb_disable();
  24. }
  25. void backlight_switch_enable()
  26. {
  27. PORTB |= 0b10000000;
  28. }
  29. void backlight_switch_disable()
  30. {
  31. PORTB &= ~0b10000000;
  32. }
  33. void backlight_switch_invert()
  34. {
  35. PORTB ^= 0b10000000;
  36. }
  37. void backlight_pcb_enable()
  38. {
  39. PORTB |= 0b01000000;
  40. }
  41. void backlight_pcb_disable()
  42. {
  43. PORTB &= ~0b01000000;
  44. }
  45. void backlight_pcb_invert()
  46. {
  47. PORTB ^= 0b01000000;
  48. }
  49. void backlight_caps_enable()
  50. {
  51. PORTB |= 0b00100000;
  52. }
  53. void backlight_caps_disable()
  54. {
  55. PORTB &= ~0b00100000;
  56. }
  57. void backlight_caps_invert()
  58. {
  59. PORTB ^= 0b00100000;
  60. }