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

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