qmk_firmware

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

bandominedoni.c (2786B)


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