From 46e7fb2d3ccd699c0a1b1fd9d02860b1f2a44141 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Mon, 26 Oct 2015 14:49:46 -0400 Subject: quantum separated --- quantum/matrix.c | 301 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 301 insertions(+) create mode 100644 quantum/matrix.c (limited to 'quantum/matrix.c') diff --git a/quantum/matrix.c b/quantum/matrix.c new file mode 100644 index 000000000..97642a4a4 --- /dev/null +++ b/quantum/matrix.c @@ -0,0 +1,301 @@ +/* +Copyright 2012 Jun Wako +Generated by planckkeyboard.com (2014 Jack Humbert) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/* + * scan matrix + */ +#include +#include +#include +#include +#include "print.h" +#include "debug.h" +#include "util.h" +#include "matrix.h" + +#ifndef DEBOUNCE +# define DEBOUNCE 10 +#endif +static uint8_t debouncing = DEBOUNCE; + +/* matrix state(1:on, 0:off) */ +static matrix_row_t matrix[MATRIX_ROWS]; +static matrix_row_t matrix_debouncing[MATRIX_ROWS]; + +#if DIODE_DIRECTION == ROW2COL + static matrix_row_t matrix_reversed[MATRIX_COLS]; + static matrix_row_t matrix_reversed_debouncing[MATRIX_COLS]; +#endif + +static matrix_row_t read_cols(void); +static void init_cols(void); +static void unselect_rows(void); +static void select_row(uint8_t row); + +inline +uint8_t matrix_rows(void) +{ + return MATRIX_ROWS; +} + +inline +uint8_t matrix_cols(void) +{ + return MATRIX_COLS; +} + +void matrix_init(void) +{ + // To use PORTF disable JTAG with writing JTD bit twice within four cycles. + MCUCR |= (1<> y) << x; + } + matrix[y] = row; + } +#endif + + if (matrix_scan_kb) { + (*matrix_scan_kb)(); + } + + return 1; +} + +bool matrix_is_modified(void) +{ + if (debouncing) return false; + return true; +} + +inline +bool matrix_is_on(uint8_t row, uint8_t col) +{ + return (matrix[row] & ((matrix_row_t)1