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 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. /* Backlight pin configuration
  17. *
  18. * FN1 PB0 (low)
  19. * FN2 PB5 (low)
  20. * FN3 PB4 (low)
  21. * FN4 PD7 (low)
  22. * REAR PD6 (high)
  23. * NUMPAD PB2 (high)
  24. * NUMLOCK PB1 (low)
  25. */
  26. void backlight_init_ports() {
  27. DDRB |= (1<<0) | (1<<1) | (1<<2) | (1<<4) | (1<<5);
  28. DDRD |= (1<<6) | (1<<7);
  29. backlight_disable_numlock();
  30. }
  31. void backlight_set(uint8_t level) {
  32. (level & BACKLIGHT_FN1) ? backlight_enable_fn1() : backlight_disable_fn1();
  33. (level & BACKLIGHT_FN2) ? backlight_enable_fn2() : backlight_disable_fn2();
  34. (level & BACKLIGHT_FN3) ? backlight_enable_fn3() : backlight_disable_fn3();
  35. (level & BACKLIGHT_FN4) ? backlight_enable_fn4() : backlight_disable_fn4();
  36. (level & BACKLIGHT_NUMPAD) ? backlight_enable_numpad() : backlight_disable_numpad();
  37. (level & BACKLIGHT_REAR) ? backlight_enable_rear() : backlight_disable_rear();
  38. }
  39. void backlight_enable_fn1() {
  40. PORTB &= ~(1<<0);
  41. }
  42. void backlight_disable_fn1() {
  43. PORTB |= (1<<0);
  44. }
  45. void backlight_invert_fn1() {
  46. PORTB ^= (1<<0);
  47. }
  48. void backlight_enable_fn2() {
  49. PORTB &= ~(1<<5);
  50. }
  51. void backlight_disable_fn2() {
  52. PORTB |= (1<<5);
  53. }
  54. void backlight_invert_fn2() {
  55. PORTB ^= (1<<5);
  56. }
  57. void backlight_enable_fn3() {
  58. PORTB &= ~(1<<4);
  59. }
  60. void backlight_disable_fn3() {
  61. PORTB |= (1<<4);
  62. }
  63. void backlight_invert_fn3() {
  64. PORTB ^= (1<<4);
  65. }
  66. void backlight_enable_fn4() {
  67. PORTD &= ~(1<<7);
  68. }
  69. void backlight_disable_fn4() {
  70. PORTD |= (1<<7);
  71. }
  72. void backlight_invert_fn4() {
  73. PORTD ^= (1<<7);
  74. }
  75. void backlight_enable_numpad() {
  76. PORTB |= (1<<2);
  77. }
  78. void backlight_disable_numpad() {
  79. PORTB &= ~(1<<2);
  80. }
  81. void backlight_invert_numpad() {
  82. PORTB ^= (1<<2);
  83. }
  84. void backlight_enable_numlock() {
  85. PORTB &= ~(1<<1);
  86. }
  87. void backlight_disable_numlock() {
  88. PORTB |= (1<<1);
  89. }
  90. void backlight_invert_numlock() {
  91. PORTB ^= (1<<1);
  92. }
  93. void backlight_enable_rear() {
  94. PORTD |= (1<<6);
  95. }
  96. void backlight_disable_rear() {
  97. PORTD &= ~(1<<6);
  98. }
  99. void backlight_invert_rear() {
  100. PORTD ^= (1<<6);
  101. }