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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include <avr/pgmspace.h>
  2. #include "ledmap.h"
  3. #include "debug.h"
  4. #ifdef LEDMAP_ENABLE
  5. static const uint16_t ledmaps[LED_COUNT] PROGMEM = {
  6. #if defined(GH60_REV_CHN)
  7. [0] = LEDMAP_CAPS_LOCK | LEDMAP_BACKLIGHT, // CapsLock - PB2
  8. [1] = LEDMAP_BACKLIGHT, // PWM - PB6
  9. #else
  10. [0] = LEDMAP_CAPS_LOCK | LEDMAP_BACKLIGHT, // CapsLock - PB2
  11. [1] = LEDMAP_BACKLIGHT, // Esc - GPIO1 - PF6
  12. [2] = LEDMAP_LAYER(1) | LEDMAP_BACKLIGHT, // WASD - GPIO0 - PF7
  13. [3] = LEDMAP_LAYER(2) | LEDMAP_BACKLIGHT, // Sh/Al/Ct - GPIO3 - PF4
  14. [4] = LEDMAP_LAYER(1) | LEDMAP_BACKLIGHT, // Fn - GPIO2 - PF5
  15. #endif
  16. };
  17. ledmap_t ledmap_get_code(uint8_t index)
  18. {
  19. return (ledmap_t) { .code = pgm_read_word(&ledmaps[index]) };
  20. }
  21. void ledmap_led_init(void)
  22. {
  23. DDRB |= (1<<PB2);
  24. PORTB |= (1<<PB2);
  25. #if defined(GH60_REV_CHN)
  26. DDRB |= (1<<PB6);
  27. PORTB &= ~(1<<PB6);
  28. #else
  29. DDRF |= (1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4);
  30. PORTF |= (1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4);
  31. #endif
  32. }
  33. void ledmap_led_on(uint8_t index)
  34. {
  35. #if defined(GH60_REV_CHN)
  36. switch (index) {
  37. case 0:
  38. PORTB &= ~(1<<PB2);
  39. break;
  40. case 1:
  41. PORTB |= (1<<PB6);
  42. break;
  43. }
  44. #else
  45. switch (index) {
  46. case 0:
  47. PORTB &= ~(1<<PB2);
  48. break;
  49. case 1:
  50. PORTF &= ~(1<<PF6);
  51. break;
  52. case 2:
  53. PORTF &= ~(1<<PF7);
  54. break;
  55. case 3:
  56. PORTF &= ~(1<<PF4);
  57. break;
  58. case 4:
  59. PORTF &= ~(1<<PF5);
  60. break;
  61. }
  62. #endif
  63. }
  64. void ledmap_led_off(uint8_t index)
  65. {
  66. #if defined(GH60_REV_CHN)
  67. switch (index) {
  68. case 0:
  69. PORTB |= (1<<PB2);
  70. break;
  71. case 1:
  72. PORTB &= ~(1<<PB6);
  73. break;
  74. }
  75. #else
  76. switch (index) {
  77. case 0:
  78. PORTB |= (1<<PB2);
  79. break;
  80. case 1:
  81. PORTF |= (1<<PF6);
  82. break;
  83. case 2:
  84. PORTF |= (1<<PF7);
  85. break;
  86. case 3:
  87. PORTF |= (1<<PF4);
  88. break;
  89. case 4:
  90. PORTF |= (1<<PF5);
  91. break;
  92. }
  93. #endif
  94. }
  95. #endif