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.3KB

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