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

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