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.

ledmap.c 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Copyright 2015 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/pgmspace.h>
  15. #include "ledmap.h"
  16. #ifdef LEDMAP_ENABLE
  17. static const uint16_t ledmaps[LED_COUNT] PROGMEM = {
  18. [0] = LEDMAP_BACKLIGHT,
  19. [1] = LEDMAP_BACKLIGHT,
  20. [2] = LEDMAP_BACKLIGHT,
  21. [3] = LEDMAP_BACKLIGHT,
  22. [4] = LEDMAP_BACKLIGHT
  23. };
  24. ledmap_t ledmap_get_code(uint8_t index)
  25. {
  26. return (ledmap_t) { .code = pgm_read_word(&ledmaps[index]) };
  27. }
  28. void ledmap_led_init(void)
  29. {
  30. DDRC |= (1<<PC2 | 1<<PC7);
  31. DDRD |= (1<<PD5 | 1<<PD6);
  32. DDRB |= (1<<PB0);
  33. }
  34. void ledmap_led_on(uint8_t index)
  35. {
  36. switch (index) {
  37. case 0:
  38. PORTC |= (1<<PC2);
  39. break;
  40. case 1:
  41. PORTC |= (1<<PC7);
  42. break;
  43. case 2:
  44. PORTD |= (1<<PD5);
  45. break;
  46. case 3:
  47. PORTD |= (1<<PD6);
  48. break;
  49. case 4:
  50. PORTB |= (1<<PB0);
  51. break;
  52. }
  53. }
  54. void ledmap_led_off(uint8_t index)
  55. {
  56. switch (index) {
  57. case 0:
  58. PORTC &= ~(1<<PC2);
  59. break;
  60. case 1:
  61. PORTC &= ~(1<<PC7);
  62. break;
  63. case 2:
  64. PORTD &= ~(1<<PD5);
  65. break;
  66. case 3:
  67. PORTD &= ~(1<<PD6);
  68. break;
  69. case 4:
  70. PORTB &= ~(1<<PB0);
  71. break;
  72. }
  73. }
  74. #endif