yang.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 "yang.h"
  17. extern uint8_t power_save_level;
  18. void hhkb_led_on(uint8_t led) {
  19. switch (led) {
  20. case 1:
  21. writePinHigh(F4);
  22. break;
  23. case 2:
  24. writePinHigh(F2);
  25. break;
  26. case 3:
  27. writePinHigh(F0);
  28. break;
  29. }
  30. }
  31. void hhkb_led_off(uint8_t led) {
  32. switch (led) {
  33. case 1:
  34. writePinLow(F4);
  35. break;
  36. case 2:
  37. writePinLow(F2);
  38. break;
  39. case 3:
  40. writePinLow(F0);
  41. break;
  42. }
  43. }
  44. void keyboard_pre_init_kb(void) {
  45. // BT power up
  46. setPinOutput(D5);
  47. writePinLow(D5);
  48. // Row selectors
  49. setPinOutput(B0);
  50. setPinOutput(B1);
  51. setPinOutput(B2);
  52. // Col selectors
  53. setPinOutput(B3);
  54. setPinOutput(B4);
  55. setPinOutput(B5);
  56. // Key strobe
  57. setPinOutput(B6);
  58. writePinHigh(B6);
  59. // Key: input with pull-up
  60. setPinInputHigh(D7);
  61. // Unused pins on Pro2 ANSI
  62. // Input with pull up to save power
  63. setPinInputHigh(C6);
  64. setPinInputHigh(C7);
  65. // LED pin configuration
  66. setPinOutput(F0);
  67. setPinOutput(F1);
  68. setPinOutput(F4);
  69. writePinLow(F0);
  70. writePinLow(F1);
  71. writePinLow(F4);
  72. // Turn on switch PCB
  73. setPinOutput(D6);
  74. writePinLow(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. writePinHigh(D5);
  83. }
  84. suspend_power_down_user();
  85. }
  86. void suspend_wakeup_init_kb(void) {
  87. // Power up BLE module
  88. writePinLow(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. writePin(F1, IS_LAYER_ON_STATE(state, 1));
  96. writePin(F0, IS_LAYER_ON_STATE(state, 2));
  97. return state;
  98. }