Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 "action.h"
  20. #include "timer.h"
  21. #include "rgb.h"
  22. #ifdef BACKLIGHT_ENABLE
  23. static const uint8_t backlight_table[] PROGMEM = {
  24. 0, 16, 128, 255
  25. };
  26. extern backlight_config_t backlight_config;
  27. uint8_t backlight_brightness;
  28. void backlight_set(uint8_t level)
  29. {
  30. softpwm_led_enable();
  31. switch (level) {
  32. case 1:
  33. case 2:
  34. case 3:
  35. fading_led_disable_all();
  36. breathing_led_disable_all();
  37. backlight_brightness = pgm_read_byte(&backlight_table[level]);
  38. softpwm_led_set_all(backlight_brightness);
  39. rgb_set_brightness(backlight_brightness);
  40. break;
  41. case 4:
  42. case 5:
  43. case 6:
  44. fading_led_disable_all();
  45. breathing_led_set_duration(6 - level);
  46. breathing_led_set_index_all(0);
  47. breathing_led_enable_all();
  48. break;
  49. case 7:
  50. fading_led_disable_all();
  51. breathing_led_disable_all();
  52. breathing_led_set_duration(1);
  53. breathing_led_set_index_all(0);
  54. break;
  55. case 8:
  56. breathing_led_disable_all();
  57. fading_led_set_direction_all(FADING_LED_FADE_OUT);
  58. fading_led_set_duration(3);
  59. fading_led_enable_all();
  60. break;
  61. case 0:
  62. default:
  63. fading_led_disable_all();
  64. breathing_led_disable_all();
  65. backlight_brightness = 0;
  66. softpwm_led_set_all(backlight_brightness);
  67. break;
  68. }
  69. }
  70. #ifndef LEDMAP_ENABLE
  71. void softpwm_led_init(void)
  72. {
  73. DDRC |= (1<<PC2 | 1<<PC7);
  74. DDRD |= (1<<PD5 | 1<<PD6);
  75. DDRB |= (1<<PB0);
  76. }
  77. void softpwm_led_on(uint8_t index)
  78. {
  79. switch (index) {
  80. case 1:
  81. PORTC &= ~(1<<PC2);
  82. break;
  83. case 2:
  84. PORTC &= ~(1<<PC7);
  85. break;
  86. case 3:
  87. PORTD &= ~(1<<PD5);
  88. break;
  89. case 4:
  90. PORTD &= ~(1<<PD6);
  91. break;
  92. case 5:
  93. PORTB &= ~(1<<PB0);
  94. break;
  95. }
  96. }
  97. void softpwm_led_off(uint8_t index)
  98. {
  99. switch (index) {
  100. case 1:
  101. PORTC |= (1<<PC2);
  102. break;
  103. case 2:
  104. PORTC |= (1<<PC7);
  105. break;
  106. case 3:
  107. PORTD |= (1<<PD5);
  108. break;
  109. case 4:
  110. PORTD |= (1<<PD6);
  111. break;
  112. case 5:
  113. PORTB |= (1<<PB0);
  114. break;
  115. }
  116. }
  117. #endif
  118. void action_keyevent(keyevent_t event)
  119. {
  120. if (backlight_config.enable) {
  121. if (backlight_config.level == 8) {
  122. if (event.pressed) {
  123. uint8_t key = event.key.col + 1;
  124. fading_led_set_delay(key, 64);
  125. softpwm_led_increase(key, 32);
  126. }
  127. }
  128. }
  129. }
  130. #ifdef CUSTOM_LED_ENABLE
  131. void softpwm_led_custom(void)
  132. {
  133. rgb_fading();
  134. if (backlight_config.level == 7) {
  135. static uint8_t index = 0;
  136. static uint16_t last = 0;
  137. if (timer_elapsed(last) > 250) {
  138. last = timer_read();
  139. breathing_led_enable_once(index);
  140. index = (index + 1) % 6;
  141. }
  142. }
  143. }
  144. void fading_led_custom(uint8_t *value)
  145. {
  146. if (backlight_config.level == 8) {
  147. uint8_t max = value[0];
  148. for (uint8_t i = 1; i < LED_COUNT; i++) {
  149. if (value[i] > max) max = value[i];
  150. }
  151. rgb_set_brightness(max);
  152. }
  153. }
  154. void breathing_led_custom(uint8_t *value)
  155. {
  156. rgb_set_brightness(value[0]);
  157. }
  158. #endif
  159. #endif