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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

backlight.c 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include "led.h"
  17. void backlight_init_ports()
  18. {
  19. DDRB |= 0b11100000; // PB7 (switch), PB6 (pcb), PB5 (caps)
  20. }
  21. void led_set(uint8_t usb_led)
  22. {
  23. (usb_led & (1<<USB_LED_CAPS_LOCK)) ? backlight_caps_enable() : backlight_caps_disable();
  24. }
  25. void backlight_set(uint8_t level)
  26. {
  27. (level & BACKLIGHT_SWITCH) ? backlight_switch_enable() : backlight_switch_disable();
  28. (level & BACKLIGHT_PCB) ? backlight_pcb_enable() : backlight_pcb_disable();
  29. }
  30. void backlight_switch_enable()
  31. {
  32. PORTB |= 0b10000000;
  33. }
  34. void backlight_switch_disable()
  35. {
  36. PORTB &= ~0b10000000;
  37. }
  38. void backlight_switch_invert()
  39. {
  40. PORTB ^= 0b10000000;
  41. }
  42. void backlight_pcb_enable()
  43. {
  44. PORTB |= 0b01000000;
  45. }
  46. void backlight_pcb_disable()
  47. {
  48. PORTB &= ~0b01000000;
  49. }
  50. void backlight_pcb_invert()
  51. {
  52. PORTB ^= 0b01000000;
  53. }
  54. void backlight_caps_enable()
  55. {
  56. PORTB |= 0b00100000;
  57. }
  58. void backlight_caps_disable()
  59. {
  60. PORTB &= ~0b00100000;
  61. }
  62. void backlight_caps_invert()
  63. {
  64. PORTB ^= 0b00100000;
  65. }