qmk_firmware

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

matrix.h (2510B)


      1 /*
      2 Copyright 2011 Jun Wako <wakojun@gmail.com>
      3 
      4 This program is free software: you can redistribute it and/or modify
      5 it under the terms of the GNU General Public License as published by
      6 the Free Software Foundation, either version 2 of the License, or
      7 (at your option) any later version.
      8 
      9 This program is distributed in the hope that it will be useful,
     10 but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 GNU General Public License for more details.
     13 
     14 You should have received a copy of the GNU General Public License
     15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16 */
     17 
     18 #pragma once
     19 
     20 #include <stdint.h>
     21 #include <stdbool.h>
     22 #include "gpio.h"
     23 
     24 /* diode directions */
     25 #define COL2ROW 0
     26 #define ROW2COL 1
     27 
     28 #if (MATRIX_COLS <= 8)
     29 typedef uint8_t matrix_row_t;
     30 #elif (MATRIX_COLS <= 16)
     31 typedef uint16_t matrix_row_t;
     32 #elif (MATRIX_COLS <= 32)
     33 typedef uint32_t matrix_row_t;
     34 #else
     35 #    error "MATRIX_COLS: invalid value"
     36 #endif
     37 
     38 #ifdef SPLIT_KEYBOARD
     39 #    define MATRIX_ROWS_PER_HAND (MATRIX_ROWS / 2)
     40 #else
     41 #    define MATRIX_ROWS_PER_HAND (MATRIX_ROWS)
     42 #endif
     43 
     44 #define MATRIX_ROW_SHIFTER ((matrix_row_t)1)
     45 
     46 #ifdef __cplusplus
     47 extern "C" {
     48 #endif
     49 
     50 /* number of matrix rows */
     51 uint8_t matrix_rows(void);
     52 /* number of matrix columns */
     53 uint8_t matrix_cols(void);
     54 /* should be called at early stage of startup before matrix_init.(optional) */
     55 void matrix_setup(void);
     56 /* intialize matrix for scaning. */
     57 void matrix_init(void);
     58 /* scan all key states on matrix */
     59 uint8_t matrix_scan(void);
     60 /* whether matrix scanning operations should be executed */
     61 bool matrix_can_read(void);
     62 /* whether a switch is on */
     63 bool matrix_is_on(uint8_t row, uint8_t col);
     64 /* matrix state on row */
     65 matrix_row_t matrix_get_row(uint8_t row);
     66 /* print matrix for debug */
     67 void matrix_print(void);
     68 /* delay between changing matrix pin state and reading values */
     69 void matrix_output_select_delay(void);
     70 void matrix_output_unselect_delay(uint8_t line, bool key_pressed);
     71 /* only for backwards compatibility. delay between changing matrix pin state and reading values */
     72 void matrix_io_delay(void);
     73 
     74 /* power control */
     75 void matrix_power_up(void);
     76 void matrix_power_down(void);
     77 
     78 void matrix_init_kb(void);
     79 void matrix_scan_kb(void);
     80 
     81 void matrix_init_user(void);
     82 void matrix_scan_user(void);
     83 
     84 #ifdef SPLIT_KEYBOARD
     85 bool matrix_post_scan(void);
     86 void matrix_slave_scan_kb(void);
     87 void matrix_slave_scan_user(void);
     88 #endif
     89 
     90 #ifdef __cplusplus
     91 }
     92 #endif