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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. Copyright 2016 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_CAPS_LOCK | LEDMAP_BACKLIGHT, // CapsLock - PC6
  19. [1] = LEDMAP_LAYER(3) | LEDMAP_BACKLIGHT, // Esc - PD7
  20. [2] = LEDMAP_LAYER(1) | LEDMAP_BACKLIGHT, // WASD - PD6
  21. [3] = LEDMAP_BACKLIGHT, // Backlight - PE6
  22. };
  23. ledmap_t ledmap_get_code(uint8_t index)
  24. {
  25. return (ledmap_t) { .code = pgm_read_word(&ledmaps[index]) };
  26. }
  27. /* LED pin configration
  28. */
  29. void ledmap_led_init(void)
  30. {
  31. #ifdef VER_PROTOTYPE
  32. DDRC |= (1<<PC6);
  33. PORTC &= ~(1<<PC6);
  34. DDRD |= (1<<PD7 | 1<<PC6);
  35. PORTD &= ~(1<<PD7 | 1<<PC6);
  36. DDRE |= (1<<PE6);
  37. PORTE |= (1<<PE6);
  38. #else
  39. DDRC |= (1<<PC6);
  40. PORTC |= (1<<PC6);
  41. DDRD |= (1<<PD7 | 1<<PC6);
  42. PORTD |= (1<<PD7 | 1<<PC6);
  43. DDRE |= (1<<PE6);
  44. PORTE |= (1<<PE6);
  45. #endif
  46. }
  47. void ledmap_led_on(uint8_t index)
  48. {
  49. switch (index) {
  50. #ifdef VER_PROTOTYPE
  51. case 0:
  52. PORTC |= (1<<PC6);
  53. break;
  54. case 1:
  55. PORTD |= (1<<PD7);
  56. break;
  57. case 2:
  58. PORTD |= (1<<PD6);
  59. break;
  60. #else
  61. case 0:
  62. PORTC &= ~(1<<PC6);
  63. break;
  64. case 1:
  65. PORTD &= ~(1<<PD7);
  66. break;
  67. case 2:
  68. PORTD &= ~(1<<PD6);
  69. break;
  70. #endif
  71. case 3:
  72. PORTE &= ~(1<<PE6);
  73. break;
  74. }
  75. }
  76. void ledmap_led_off(uint8_t index)
  77. {
  78. switch (index) {
  79. #ifdef VER_PROTOTYPE
  80. case 0:
  81. PORTC &= ~(1<<PC6);
  82. break;
  83. case 1:
  84. PORTD &= ~(1<<PD7);
  85. break;
  86. case 2:
  87. PORTD &= ~(1<<PD6);
  88. break;
  89. #else
  90. case 0:
  91. PORTC |= (1<<PC6);
  92. break;
  93. case 1:
  94. PORTD |= (1<<PD7);
  95. break;
  96. case 2:
  97. PORTD |= (1<<PD6);
  98. break;
  99. #endif
  100. case 3:
  101. PORTE |= (1<<PE6);
  102. break;
  103. }
  104. }
  105. #endif