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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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, // CapsLock
  19. [1] = LEDMAP_NUM_LOCK, // NumLock
  20. [2] = LEDMAP_SCROLL_LOCK, // Logo
  21. [3] = LEDMAP_BACKLIGHT, // Backlight
  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. * CapsLock: PC7
  29. * NumLock: PE6
  30. * Logo: PC6
  31. * Backlight: PB7
  32. */
  33. void ledmap_led_init(void)
  34. {
  35. DDRC |= (1<<PC7);
  36. PORTC |= (1<<PC7);
  37. DDRE |= (1<<PE6);
  38. PORTE |= (1<<PE6);
  39. DDRC |= (1<<PC6);
  40. PORTC &= ~(1<<PC6);
  41. DDRB |= (1<<PB7);
  42. PORTB &= ~(1<<PB7);
  43. }
  44. void ledmap_led_on(uint8_t index)
  45. {
  46. switch (index) {
  47. case 0:
  48. PORTC &= ~(1<<PC7);
  49. break;
  50. case 1:
  51. PORTE &= ~(1<<PE6);
  52. break;
  53. case 2:
  54. PORTC |= (1<<PC6);
  55. break;
  56. case 3:
  57. PORTB |= (1<<PB7);
  58. break;
  59. }
  60. }
  61. void ledmap_led_off(uint8_t index)
  62. {
  63. switch (index) {
  64. case 0:
  65. PORTC |= (1<<PC7);
  66. break;
  67. case 1:
  68. PORTE |= (1<<PE6);
  69. break;
  70. case 2:
  71. PORTC &= ~(1<<PB6);
  72. break;
  73. case 3:
  74. PORTB &= ~(1<<PB7);
  75. break;
  76. }
  77. }
  78. #endif