rev2.c 2.9 KB

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