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.

103 lines
3.0 KiB

  1. /* Copyright 2020 Harrison Chan (Xelus)
  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 "quantum.h"
  17. // Tested and verified working on ext65rev2
  18. void matrix_io_delay(void) {
  19. __asm__ volatile("nop\nnop\nnop\n");
  20. }
  21. #ifdef OLED_ENABLE
  22. void board_init(void) {
  23. SYSCFG->CFGR1 |= SYSCFG_CFGR1_I2C1_DMA_RMP;
  24. SYSCFG->CFGR1 &= ~(SYSCFG_CFGR1_SPI2_DMA_RMP);
  25. }
  26. oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
  27. return OLED_ROTATION_90; // rotates the display 90 degrees
  28. }
  29. void render_layer_state(void) {
  30. oled_write_ln(PSTR("LAYER"), false);
  31. oled_write_ln(PSTR("L1"), layer_state_is(1));
  32. oled_write_ln(PSTR("L2"), layer_state_is(2));
  33. oled_write_ln(PSTR("L3"), layer_state_is(3));
  34. oled_write_ln(PSTR(" "), false);
  35. }
  36. void render_keylock_status(led_t led_state) {
  37. oled_write_ln(PSTR("Lock:"), false);
  38. oled_write(PSTR("N"), led_state.num_lock);
  39. oled_write(PSTR("C"), led_state.caps_lock);
  40. oled_write_ln(PSTR("S"), led_state.scroll_lock);
  41. oled_write_ln(PSTR(" "), false);
  42. }
  43. void render_mod_status(uint8_t modifiers) {
  44. oled_write_ln(PSTR("Mods:"), false);
  45. oled_write(PSTR("S"), (modifiers & MOD_MASK_SHIFT));
  46. oled_write(PSTR("C"), (modifiers & MOD_MASK_CTRL));
  47. oled_write(PSTR("A"), (modifiers & MOD_MASK_ALT));
  48. oled_write_ln(PSTR("G"), (modifiers & MOD_MASK_GUI));
  49. oled_write_ln(PSTR(" "), false);
  50. }
  51. bool oled_task_kb(void) {
  52. if (!oled_task_user()) {
  53. return false;
  54. }
  55. render_layer_state();
  56. render_keylock_status(host_keyboard_led_state());
  57. render_mod_status(get_mods() | get_oneshot_mods());
  58. return true;
  59. }
  60. #else
  61. void keyboard_pre_init_kb(void) {
  62. // Call the keyboard pre init code.
  63. // Set our LED pins as output
  64. setPinOutput(B4);
  65. setPinOutput(B3);
  66. setPinOutput(A15);
  67. setPinOutput(A14);
  68. keyboard_pre_init_user();
  69. }
  70. bool led_update_kb(led_t led_state) {
  71. bool res = led_update_user(led_state);
  72. if (res) {
  73. writePin(B4, led_state.num_lock);
  74. writePin(B3, led_state.caps_lock);
  75. writePin(A15, led_state.scroll_lock);
  76. }
  77. return res;
  78. }
  79. layer_state_t layer_state_set_kb(layer_state_t state) {
  80. switch (get_highest_layer(state)) {
  81. case 1:
  82. writePinHigh(A14);
  83. break;
  84. default: // for any other layers, or the default layer
  85. writePinLow(A14);
  86. break;
  87. }
  88. return layer_state_set_user(state);
  89. }
  90. #endif