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.

136 lines
4.1 KiB

  1. /* Copyright 2020 cmdremily
  2. *
  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. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "rev1.h"
  17. #ifdef RGB_MATRIX_ENABLE
  18. const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT] = {
  19. /* Refer to IS31 manual for these locations
  20. * driver
  21. * | R location
  22. * | | G location
  23. * | | | B location
  24. * | | | | */
  25. // clang-format off
  26. {0, C4_1, C5_1, C6_1},
  27. {0, C4_2, C5_2, C6_2},
  28. {0, C4_3, C5_3, C6_3},
  29. {0, C1_4, C2_4, C3_4},
  30. {0, C4_9, C5_9, C6_9},
  31. {0, C4_10, C5_10, C6_10},
  32. {0, C4_11, C5_11, C6_11},
  33. {0, C1_12, C2_12, C3_12},
  34. {0, C7_1, C8_1, C9_1},
  35. {0, C7_2, C8_2, C9_2},
  36. {0, C7_3, C8_3, C9_3},
  37. {0, C7_4, C8_4, C9_4},
  38. {0, C7_9, C8_9, C9_9},
  39. {0, C7_10, C8_10, C9_10},
  40. {0, C7_11, C8_11, C9_11},
  41. {0, C7_12, C8_12, C9_12},
  42. {0, C1_5, C2_5, C3_5},
  43. {0, C1_6, C2_6, C3_6},
  44. {0, C1_7, C2_7, C3_7},
  45. {0, C1_8, C2_8, C3_8},
  46. {0, C1_13, C2_13, C3_13},
  47. {0, C1_14, C2_14, C3_14},
  48. {0, C1_15, C2_15, C3_15},
  49. {0, C1_16, C2_16, C3_16},
  50. {0, C7_5, C8_5, C9_5},
  51. {0, C7_6, C8_6, C9_6},
  52. {0, C4_7, C5_7, C6_7},
  53. {0, C4_8, C5_8, C6_8},
  54. {0, C7_13, C8_13, C9_13},
  55. {0, C7_14, C8_14, C9_14},
  56. {0, C4_15, C5_15, C6_15},
  57. {0, C4_16, C5_16, C6_16},
  58. // clang-format on
  59. };
  60. // clang-format off
  61. led_config_t g_led_config = {
  62. {
  63. // Key Matrix to LED Index
  64. { 0, 1, 2, 3, 4, 5, 6, 7 },
  65. { 8, 9, 10, 11, 12, 13, 14, 15 },
  66. { 16, 17, 18, 19, 20, 21, 22, 23 },
  67. { 24, 25, 26, 27, 28, 29, 30, 31 }
  68. }, {
  69. // LED Index to Physical Position
  70. { 0, 0 }, { 32, 0 }, { 64, 0 }, { 96, 0 }, { 128, 0 }, { 160, 0 }, { 192, 0 }, { 224, 0 },
  71. { 0, 21 }, { 32, 21 }, { 64, 21 }, { 96, 21 }, { 128, 21 }, { 160, 21 }, { 192, 21 }, { 224, 21 },
  72. { 0, 43 }, { 32, 43 }, { 64, 43 }, { 96, 43 }, { 128, 43 }, { 160, 43 }, { 192, 43 }, { 224, 43 },
  73. { 0, 64 }, { 32, 64 }, { 64, 64 }, { 96, 64 }, { 128, 64 }, { 160, 64 }, { 192, 64 }, { 224, 64 }
  74. }, {
  75. // LED Index to Flag
  76. 4, 4, 4, 4, 4, 4, 4, 4,
  77. 4, 4, 4, 4, 4, 4, 4, 4,
  78. 4, 4, 4, 4, 4, 4, 4, 4,
  79. 4, 4, 4, 4, 4, 4, 4, 4
  80. }
  81. };
  82. // clang-format on
  83. void keyboard_pre_init_kb(void) {
  84. // Light power LED
  85. gpio_set_pin_output(POWER_LED_PIN);
  86. gpio_write_pin_low(POWER_LED_PIN);
  87. // We don't use this feature of the IS31FL3731 but it is electrically connected
  88. // Make sure not to drive it
  89. gpio_set_pin_input(IS31FL3731_IRQ_PIN);
  90. keyboard_pre_init_user();
  91. }
  92. void keyboard_post_init_kb(void) {
  93. // RGB enabled by default, no way to turn off. No need to expend EEPROM write cycles here.
  94. rgb_matrix_enable_noeeprom();
  95. keyboard_post_init_user();
  96. }
  97. #endif
  98. #if defined(KC_WRAPPER_KEY)
  99. static uint8_t g_key_wrapper_tracker = 0;
  100. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  101. if (!process_record_user(keycode, record)) { return false; }
  102. if (record->event.pressed && keycode != KC_WRAPPER_KEY) {
  103. register_code(KC_WRAPPER_KEY);
  104. register_code(keycode);
  105. g_key_wrapper_tracker++;
  106. return false;
  107. }
  108. return true;
  109. }
  110. void post_process_record_kb(uint16_t keycode, keyrecord_t *record) {
  111. if (!record->event.pressed && keycode != KC_WRAPPER_KEY) {
  112. --g_key_wrapper_tracker;
  113. if (g_key_wrapper_tracker <= 0) {
  114. unregister_code(KC_WRAPPER_KEY);
  115. g_key_wrapper_tracker = 0;
  116. }
  117. }
  118. post_process_record_user(keycode, record);
  119. }
  120. #endif