logo

qmk_firmware

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

sagittarius.c (1483B)


  1. // Copyright 2024 Nick Brassel (@tzarc)
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include QMK_KEYBOARD_H
  4. #if defined(ENCODER_ENABLE) || defined(ENCODER_MAP_ENABLE)
  5. # if !defined(ENCODER_SETTLE_PIN_STATE_DELAY_US)
  6. # define ENCODER_SETTLE_PIN_STATE_DELAY_US 2
  7. # endif
  8. static pin_t matrix_row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
  9. void encoder_driver_task(void) {
  10. // Set all relevant rows to output, which is different to the matrix expectations
  11. for (uint8_t i = 0; i < 4; i++) {
  12. gpio_set_pin_output(matrix_row_pins[i]);
  13. }
  14. // Read each encoder
  15. for (uint8_t i = 0; i < 4; i++) {
  16. // Set the row pin low for the corresponding encoder...
  17. for (uint8_t j = 0; j < 4; j++) {
  18. gpio_write_pin(matrix_row_pins[j], (i == j) ? 0 : 1);
  19. }
  20. // ...and let them settle.
  21. wait_us(ENCODER_SETTLE_PIN_STATE_DELAY_US);
  22. // Run the normal encoder handling
  23. extern void encoder_quadrature_handle_read(uint8_t index, uint8_t pin_a_state, uint8_t pin_b_state);
  24. extern uint8_t encoder_quadrature_read_pin(uint8_t index, bool pad_b);
  25. encoder_quadrature_handle_read(i, encoder_quadrature_read_pin(i, false), encoder_quadrature_read_pin(i, true));
  26. }
  27. // Set all rows back to input-high as per matrix expectations
  28. for (uint8_t i = 0; i < 4; i++) {
  29. gpio_set_pin_input_high(matrix_row_pins[i]);
  30. }
  31. }
  32. #endif // defined(ENCODER_ENABLE) || defined(ENCODER_MAP_ENABLE)