logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

yang.c (2894B)


  1. /* Copyright 2021 Kan-Ru Chen <kanru@kanru.info>
  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. extern uint8_t power_save_level;
  18. void hhkb_led_on(uint8_t led) {
  19. switch (led) {
  20. case 1:
  21. gpio_write_pin_high(F4);
  22. break;
  23. case 2:
  24. gpio_write_pin_high(F2);
  25. break;
  26. case 3:
  27. gpio_write_pin_high(F0);
  28. break;
  29. }
  30. }
  31. void hhkb_led_off(uint8_t led) {
  32. switch (led) {
  33. case 1:
  34. gpio_write_pin_low(F4);
  35. break;
  36. case 2:
  37. gpio_write_pin_low(F2);
  38. break;
  39. case 3:
  40. gpio_write_pin_low(F0);
  41. break;
  42. }
  43. }
  44. void keyboard_pre_init_kb(void) {
  45. // BT power up
  46. gpio_set_pin_output(D5);
  47. gpio_write_pin_low(D5);
  48. // Row selectors
  49. gpio_set_pin_output(B0);
  50. gpio_set_pin_output(B1);
  51. gpio_set_pin_output(B2);
  52. // Col selectors
  53. gpio_set_pin_output(B3);
  54. gpio_set_pin_output(B4);
  55. gpio_set_pin_output(B5);
  56. // Key strobe
  57. gpio_set_pin_output(B6);
  58. gpio_write_pin_high(B6);
  59. // Key: input with pull-up
  60. gpio_set_pin_input_high(D7);
  61. // Unused pins on Pro2 ANSI
  62. // Input with pull up to save power
  63. gpio_set_pin_input_high(C6);
  64. gpio_set_pin_input_high(C7);
  65. // LED pin configuration
  66. gpio_set_pin_output(F0);
  67. gpio_set_pin_output(F1);
  68. gpio_set_pin_output(F4);
  69. gpio_write_pin_low(F0);
  70. gpio_write_pin_low(F1);
  71. gpio_write_pin_low(F4);
  72. // Turn on switch PCB
  73. gpio_set_pin_output(D6);
  74. gpio_write_pin_low(D6);
  75. keyboard_pre_init_user();
  76. }
  77. void suspend_power_down_kb(void) {
  78. if (power_save_level > 2) {
  79. // Disable UART TX to avoid current leakage
  80. UCSR1B &= ~_BV(TXEN1);
  81. // Power down BLE module
  82. gpio_write_pin_high(D5);
  83. }
  84. suspend_power_down_user();
  85. }
  86. void suspend_wakeup_init_kb(void) {
  87. // Power up BLE module
  88. gpio_write_pin_low(D5);
  89. // Enable UART TX
  90. UCSR1B |= _BV(TXEN1);
  91. suspend_wakeup_init_user();
  92. }
  93. layer_state_t layer_state_set_kb(layer_state_t state) {
  94. state = layer_state_set_user(state);
  95. gpio_write_pin(F1, IS_LAYER_ON_STATE(state, 1));
  96. gpio_write_pin(F0, IS_LAYER_ON_STATE(state, 2));
  97. return state;
  98. }