Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
Este repositório está arquivado. Você pode visualizar os arquivos e realizar clone, mas não poderá realizar push nem abrir issues e pull requests.

backlight.c 3.7KB

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