diff options
author | James Churchill <pelrun@gmail.com> | 2018-12-29 16:53:21 +1100 |
---|---|---|
committer | Drashna Jaelre <drashna@live.com> | 2019-01-03 20:00:27 -0800 |
commit | 38e01a7480f6826b3d220c4c8357788558b2af07 (patch) | |
tree | 25ccc41022e2c2486d44ad4a1e5a0cae4e9f5a55 /quantum/split_common/matrix.c | |
parent | 54b572159f62913ead47b0a6ee8d2d09dfb8f19a (diff) |
Convert split_common to use generic GPIO api
Diffstat (limited to 'quantum/split_common/matrix.c')
-rw-r--r-- | quantum/split_common/matrix.c | 60 |
1 files changed, 19 insertions, 41 deletions
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index 2611376386..2c37053f88 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c @@ -20,17 +20,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <stdint.h> #include <stdbool.h> -#include <avr/io.h> #include "wait.h" -#include "print.h" -#include "debug.h" #include "util.h" #include "matrix.h" #include "split_util.h" -#include "pro_micro.h" #include "config.h" #include "timer.h" #include "split_flags.h" +#include "quantum.h" #ifdef BACKLIGHT_ENABLE # include "backlight.h" @@ -91,8 +88,8 @@ static matrix_row_t matrix_debouncing[MATRIX_ROWS]; static uint8_t error_count = 0; -static uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; -static uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; +static pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; +static pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; /* matrix state(1:on, 0:off) */ static matrix_row_t matrix[MATRIX_ROWS]; @@ -440,9 +437,7 @@ uint8_t matrix_key_count(void) static void init_cols(void) { for(uint8_t x = 0; x < MATRIX_COLS; x++) { - uint8_t pin = col_pins[x]; - _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN - _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI + setPinInputHigh(col_pins[x]); } } @@ -460,13 +455,8 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) // For each col... for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { - - // Select the col pin to read (active low) - uint8_t pin = col_pins[col_index]; - uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)); - // Populate the matrix row with the state of the col pin - current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index); + current_matrix[current_row] |= readPin(col_pins[col_index]) ? 0 : (ROW_SHIFTER << col_index); } // Unselect row @@ -477,24 +467,19 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) static void select_row(uint8_t row) { - uint8_t pin = row_pins[row]; - _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT - _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW + writePinLow(row_pins[row]); + setPinOutput(row_pins[row]); } static void unselect_row(uint8_t row) { - uint8_t pin = row_pins[row]; - _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN - _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI + setPinInputHigh(row_pins[row]); } static void unselect_rows(void) { for(uint8_t x = 0; x < ROWS_PER_HAND; x++) { - uint8_t pin = row_pins[x]; - _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN - _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI + setPinInputHigh(row_pins[x]); } } @@ -503,9 +488,7 @@ static void unselect_rows(void) static void init_rows(void) { for(uint8_t x = 0; x < ROWS_PER_HAND; x++) { - uint8_t pin = row_pins[x]; - _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN - _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI + setPinInputHigh(row_pins[x]); } } @@ -525,15 +508,15 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) matrix_row_t last_row_value = current_matrix[row_index]; // Check row pin state - if ((_SFR_IO8(row_pins[row_index] >> 4) & _BV(row_pins[row_index] & 0xF)) == 0) + if (readPin(row_pins[row_index])) { - // Pin LO, set col bit - current_matrix[row_index] |= (ROW_SHIFTER << current_col); + // Pin HI, clear col bit + current_matrix[row_index] &= ~(ROW_SHIFTER << current_col); } else { - // Pin HI, clear col bit - current_matrix[row_index] &= ~(ROW_SHIFTER << current_col); + // Pin LO, set col bit + current_matrix[row_index] |= (ROW_SHIFTER << current_col); } // Determine if the matrix changed state @@ -551,24 +534,19 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) static void select_col(uint8_t col) { - uint8_t pin = col_pins[col]; - _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT - _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW + writePinLow(col_pins[col]); + setPinOutput(col_pins[col]); } static void unselect_col(uint8_t col) { - uint8_t pin = col_pins[col]; - _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN - _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI + setPinInputHigh(col_pins[col]); } static void unselect_cols(void) { for(uint8_t x = 0; x < MATRIX_COLS; x++) { - uint8_t pin = col_pins[x]; - _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN - _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI + setPinInputHigh(col_pins[x]); } } |