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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. Copyright 2014 Kai Ryu <[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 <avr/interrupt.h>
  16. #include <avr/pgmspace.h>
  17. #include "backlight.h"
  18. #include "softpwm_led.h"
  19. #include "keymap_common.h"
  20. #include "tentapad.h"
  21. #ifdef BACKLIGHT_ENABLE
  22. uint8_t backlight_mode;
  23. const uint8_t backlight_brightness_mid = 64;
  24. const uint8_t backlight_brightness_high = 255;
  25. void backlight_set(uint8_t level)
  26. {
  27. backlight_mode = level;
  28. softpwm_led_set_all(0);
  29. fading_led_set_duration(2);
  30. fading_led_set_direction_all(FADING_LED_FADE_OUT);
  31. breathing_led_set_duration(3);
  32. switch (level) {
  33. case 0:
  34. softpwm_led_disable();
  35. fading_led_disable_all();
  36. breathing_led_disable_all();
  37. softpwm_led_on(LED_KEY_SIDE);
  38. softpwm_led_on(LED_BOARD_SIDE);
  39. break;
  40. case 1:
  41. softpwm_led_set(LED_BOARD_SIDE, backlight_brightness_mid);
  42. fading_led_disable_all();
  43. fading_led_enable(LED_KEY_SIDE);
  44. breathing_led_disable_all();
  45. softpwm_led_enable();
  46. break;
  47. case 2:
  48. softpwm_led_set(LED_KEY_SIDE, backlight_brightness_mid);
  49. fading_led_disable_all();
  50. fading_led_enable(LED_BOARD_SIDE);
  51. breathing_led_disable_all();
  52. softpwm_led_enable();
  53. break;
  54. case 3:
  55. fading_led_disable_all();
  56. breathing_led_disable_all();
  57. breathing_led_enable(LED_KEY_SIDE);
  58. breathing_led_enable(LED_BOARD_SIDE);
  59. softpwm_led_enable();
  60. break;
  61. case 4:
  62. softpwm_led_set(LED_KEY_SIDE, backlight_brightness_mid);
  63. breathing_led_disable_all();
  64. breathing_led_enable(LED_BOARD_SIDE);
  65. fading_led_disable_all();
  66. softpwm_led_enable();
  67. break;
  68. case 5:
  69. softpwm_led_set(LED_BOARD_SIDE, backlight_brightness_mid);
  70. breathing_led_disable_all();
  71. breathing_led_enable(LED_KEY_SIDE);
  72. fading_led_disable_all();
  73. softpwm_led_enable();
  74. break;
  75. case 6:
  76. fading_led_disable_all();
  77. breathing_led_disable_all();
  78. softpwm_led_disable();
  79. break;
  80. case 7:
  81. fading_led_disable_all();
  82. breathing_led_disable_all();
  83. softpwm_led_disable();
  84. break;
  85. case 8:
  86. softpwm_led_set_all(16);
  87. fading_led_disable_all();
  88. breathing_led_disable_all();
  89. softpwm_led_enable();
  90. break;
  91. }
  92. }
  93. #ifndef LEDMAP_ENABLE
  94. void softpwm_led_init(void)
  95. {
  96. #ifndef EXPERIMENTAL
  97. DDRD |= (1<<PD0);
  98. DDRB |= (1<<PB7);
  99. DDRC |= (1<<PD5 | 1<<PD6);
  100. #else
  101. DDRB |= (1<<PB6);
  102. #endif
  103. }
  104. void softpwm_led_on(uint8_t index)
  105. {
  106. #ifndef EXPERIMENTAL
  107. switch (index) {
  108. case LED_KEY_1:
  109. PORTC |= (1<<PC5);
  110. break;
  111. case LED_KEY_2:
  112. PORTC |= (1<<PC6);
  113. break;
  114. case LED_KEY_SIDE:
  115. PORTB |= (1<<PB7);
  116. break;
  117. case LED_BOARD_SIDE:
  118. PORTD |= (1<<PD0);
  119. break;
  120. }
  121. #else
  122. PORTB |= (1<<PB6);
  123. #endif
  124. }
  125. void softpwm_led_off(uint8_t index)
  126. {
  127. #ifndef EXPERIMENTAL
  128. switch (index) {
  129. case LED_KEY_1:
  130. PORTC &= ~(1<<PC5);
  131. break;
  132. case LED_KEY_2:
  133. PORTC &= ~(1<<PC6);
  134. break;
  135. case LED_KEY_SIDE:
  136. PORTB &= ~(1<<PB7);
  137. break;
  138. case LED_BOARD_SIDE:
  139. PORTD &= ~(1<<PD0);
  140. break;
  141. }
  142. #else
  143. PORTB &= ~(1<<PB6);
  144. #endif
  145. }
  146. #endif
  147. #endif