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

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