bandominedoni.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright 2021 3araht
  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 "bandominedoni.h"
  17. #if defined(SPLIT_HAND_MATRIX_GRID)
  18. static uint8_t peek_matrix_intersection(pin_t out_pin, pin_t in_pin) {
  19. gpio_set_pin_input_high(in_pin);
  20. gpio_set_pin_output(out_pin);
  21. gpio_write_pin_low(out_pin);
  22. // It's almost unnecessary, but wait until it's down to low, just in case.
  23. wait_us(1);
  24. uint8_t pin_state = gpio_read_pin(in_pin);
  25. // Set out_pin to a setting that is less susceptible to noise.
  26. gpio_set_pin_input_high(out_pin);
  27. matrix_io_delay(); // Wait for the pull-up to go HIGH.
  28. return pin_state;
  29. }
  30. #endif
  31. // Overriding is_keyboard_left() in qmk_firmware/quantum/split_common/split_util.c to limit the handedness check only once.
  32. // reason: bandoMIneDonI has no space on right hand side to use "SPLIT_HAND_MATRIX_GRID".
  33. // However, It enables to decide the handedness by the HW by adding one condition: "not to press any keys (especially r30) dusing startup."
  34. bool is_keyboard_left(void) {
  35. static enum { UNKNOWN, LEFT, RIGHT } hand_side = UNKNOWN;
  36. // only check once, as this is called often
  37. if (hand_side == UNKNOWN) {
  38. #if defined(SPLIT_HAND_PIN)
  39. // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand
  40. gpio_set_pin_input(SPLIT_HAND_PIN);
  41. hand_side = gpio_read_pin(SPLIT_HAND_PIN) ? LEFT : RIGHT;
  42. return (hand_side == LEFT);
  43. #elif defined(SPLIT_HAND_MATRIX_GRID)
  44. # ifdef SPLIT_HAND_MATRIX_GRID_LOW_IS_LEFT
  45. hand_side = peek_matrix_intersection(SPLIT_HAND_MATRIX_GRID) ? RIGHT : LEFT;
  46. return (hand_side == LEFT);
  47. # else
  48. hand_side = peek_matrix_intersection(SPLIT_HAND_MATRIX_GRID) ? LEFT : RIGHT;
  49. return (hand_side == LEFT);
  50. # endif
  51. #elif defined(EE_HANDS)
  52. hand_side = eeconfig_read_handedness() ? LEFT : RIGHT;
  53. return (hand_side == LEFT);
  54. #elif defined(MASTER_RIGHT)
  55. hand_side = !is_keyboard_master() ? LEFT : RIGHT;
  56. return (hand_side == LEFT);
  57. #endif
  58. hand_side = is_keyboard_master() ? LEFT : RIGHT;
  59. return (hand_side == LEFT);
  60. } else {
  61. return (hand_side == LEFT);
  62. }
  63. }