qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

sagittarius.c (1483B)


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