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

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