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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. Copyright 2013,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 uint8_t backlight_mode;
  22. static const uint8_t backlight_table[] PROGMEM = {
  23. 0, 16, 128, 255
  24. };
  25. /* Backlight pin configuration
  26. * PWM: PB5 (RevRS)
  27. * GPIO: PF7 PF6 PF5
  28. */
  29. void backlight_set(uint8_t level)
  30. {
  31. backlight_mode = level;
  32. switch (level) {
  33. case 1:
  34. case 2:
  35. case 3:
  36. softpwm_led_enable();
  37. fading_led_disable_all();
  38. breathing_led_disable_all();
  39. softpwm_led_set_all(pgm_read_byte(&backlight_table[level]));
  40. break;
  41. case 4:
  42. case 5:
  43. case 6:
  44. softpwm_led_enable();
  45. breathing_led_enable_all();
  46. fading_led_disable_all();
  47. breathing_led_set_duration(6 - level);
  48. break;
  49. case 7:
  50. softpwm_led_enable();
  51. fading_led_enable_all();
  52. breathing_led_disable_all();
  53. fading_led_set_direction_all(FADING_LED_FADE_IN);
  54. fading_led_set_duration(4);
  55. break;
  56. case 8:
  57. softpwm_led_enable();
  58. fading_led_enable_all();
  59. breathing_led_disable_all();
  60. fading_led_set_direction_all(FADING_LED_FADE_OUT);
  61. fading_led_set_duration(2);
  62. break;
  63. case 0:
  64. default:
  65. fading_led_disable_all();
  66. breathing_led_disable_all();
  67. softpwm_led_disable();
  68. break;
  69. }
  70. }
  71. #ifndef LEDMAP_ENABLE
  72. void softpwm_led_init(void)
  73. {
  74. DDRB |= (1<<PB5);
  75. DDRF |= (1<<PF7 | 1<<PF6 | 1<<PF5);
  76. }
  77. void softpwm_led_on(uint8_t index)
  78. {
  79. PORTB |= (1<<PB5);
  80. PORTF &= ~(1<<PF7 | 1<<PF6 | 1<<PF5);
  81. }
  82. void softpwm_led_off(uint8_t index)
  83. {
  84. PORTB &= ~(1<<PB5);
  85. PORTF |= (1<<PF7 | 1<<PF6 | 1<<PF5);
  86. }
  87. #endif
  88. void action_keyevent(keyevent_t event)
  89. {
  90. if (backlight_mode == 7) {
  91. if (event.pressed) {
  92. softpwm_led_decrease_all(32);
  93. }
  94. }
  95. if (backlight_mode == 8) {
  96. if (event.pressed) {
  97. softpwm_led_increase_all(32);
  98. }
  99. }
  100. }
  101. #endif