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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_NUM_LOCK, // LED_A - PB5
  19. [1] = LEDMAP_CAPS_LOCK, // LED_B - PB6
  20. [2] = LEDMAP_SCROLL_LOCK, // LED_C - PB3
  21. [3] = LEDMAP_LAYER(1), // RX - PB0
  22. [4] = LEDMAP_LAYER(2), // TX - PD5
  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. DDRB |= (1<<PB5 | 1<<PB6 | 1<<PB3);
  31. PORTB &= ~(1<<PB5 | 1<<PB6 | 1<<PB3);
  32. DDRB |= (1<<PB0);
  33. PORTB |= (1<<PB0);
  34. DDRD |= (1<<PD5);
  35. PORTD |= (1<<PD5);
  36. }
  37. void ledmap_led_on(uint8_t index)
  38. {
  39. switch (index) {
  40. case 0:
  41. PORTB |= (1<<PB5);
  42. break;
  43. case 1:
  44. PORTB |= (1<<PB6);
  45. break;
  46. case 2:
  47. PORTB |= (1<<PB3);
  48. break;
  49. case 3:
  50. PORTB &= ~(1<<PB0);
  51. break;
  52. case 4:
  53. PORTD &= ~(1<<PD5);
  54. break;
  55. }
  56. }
  57. void ledmap_led_off(uint8_t index)
  58. {
  59. switch (index) {
  60. case 0:
  61. PORTB &= ~(1<<PB5);
  62. break;
  63. case 1:
  64. PORTB &= ~(1<<PB6);
  65. break;
  66. case 2:
  67. PORTB &= ~(1<<PB3);
  68. break;
  69. case 3:
  70. PORTB |= (1<<PB0);
  71. break;
  72. case 4:
  73. PORTD |= (1<<PD5);
  74. break;
  75. }
  76. }
  77. #endif