From 716924de3e07eb4a6f39a9c8da9ba0fc64c7f796 Mon Sep 17 00:00:00 2001 From: Brad Arnett Date: Thu, 18 Jun 2020 03:01:22 -0700 Subject: [Keyboard] Added ymdk split64 based on walston's work (#9183) * Added ymdk split64 based on walson's work * Commented out features on walston's keymap as it was too big to compile * Update keyboards/ymdk_sp64/config.h * Update keyboards/ymdk_sp64/keymaps/daed/keymap.c * Update keyboards/ymdk_sp64/matrix.c * Update keyboards/ymdk_sp64/matrix.c * Update keyboards/ymdk_sp64/matrix.c * keymap changes * Update keyboards/ymdk_sp64/matrix.c * Update keyboards/ymdk_sp64/matrix.c * Update keyboards/ymdk_sp64/rules.mk * Update keyboards/ymdk_sp64/config.h * Update keyboards/ymdk_sp64/config.h * Update keyboards/ymdk_sp64/readme.md * Update keyboards/ymdk_sp64/rules.mk * Update keyboards/ymdk_sp64/config.h * Update keyboards/ymdk_sp64/rules.mk * Update keyboards/ymdk_sp64/ymdk_sp64.c * Update keyboards/ymdk_sp64/keymaps/walston/rules.mk * Update keyboards/ymdk_sp64/readme.md * Made requested changes and moved keyboard under ymdk directory * Update keyboards/ymdk/ymdk_sp64/keymaps/walston/keymap.c * Update keyboards/ymdk/ymdk_sp64/config.h * Update keyboards/ymdk/ymdk_sp64/config.h * Update keyboards/ymdk/ymdk_sp64/keymaps/default/keymap.c * Update keyboards/ymdk/ymdk_sp64/keymaps/default/keymap.c * updated changes for pr 9183 * updated changes for pr 9183 * updated changes for pr 9183 * Removed redundant "QMK_KEYBOARD_H" include --- keyboards/ymdk/sp64/matrix.c | 169 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 keyboards/ymdk/sp64/matrix.c (limited to 'keyboards/ymdk/sp64/matrix.c') diff --git a/keyboards/ymdk/sp64/matrix.c b/keyboards/ymdk/sp64/matrix.c new file mode 100644 index 0000000000..8dd2bb8d76 --- /dev/null +++ b/keyboards/ymdk/sp64/matrix.c @@ -0,0 +1,169 @@ +/* +Copyright 2013 Oleg Kostyuk +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 . +*/ + +#include "matrix.h" +#include +#include +#include +#include "wait.h" +#include "action_layer.h" +#include "print.h" +#include "debug.h" +#include "util.h" +#include "sp64.h" +#include "debounce.h" + +/* matrix state(1:on, 0:off) */ +static matrix_row_t matrix[MATRIX_ROWS]; + +// Debouncing: store for each key the number of scans until it's eligible to +// change. When scanning the matrix, ignore any changes in keys that have +// already changed in the last DEBOUNCE scans. +static matrix_row_t matrix_debouncing[MATRIX_ROWS]; + +static void matrix_select_row(uint8_t row); + +#ifdef RIGHT_HALF +static uint8_t mcp23018_reset_loop = 0; +#endif + +void matrix_init(void) +{ + // all outputs for rows high + DDRB = 0xFF; + PORTB = 0xFF; + // all inputs for columns + DDRA = 0x00; + DDRC &= ~(0x111111<<2); + DDRD &= ~(1<= 1300) { + // since mcp23018_reset_loop is 8 bit - we'll try to reset once in 255 matrix scans + // this will be approx bit more frequent than once per second + print("trying to reset mcp23018\n"); + mcp23018_status = init_mcp23018(); + if (mcp23018_status) { + print("left side not responding\n"); + } else { + print("left side attached\n"); + } + } + } +#endif + bool changed = false; + for (uint8_t row = 0; row < MATRIX_ROWS; row++) + { + matrix_row_t cols; + + matrix_select_row(row); +#ifndef RIGHT_HALF + _delay_us(5); +#endif + + cols = ( + // cols 0..7, PORTA 0 -> 7 + (~PINA) & 0xFF + ); + +#ifdef RIGHT_HALF + uint8_t data = 0x7F; + // Receive the columns from right half + i2c_receive(I2C_ADDR_WRITE, &data, 1, MCP23018_I2C_TIMEOUT); + cols |= ((~(data) & 0x7F) << 7); +#endif + + if (matrix_debouncing[row] != cols) { + matrix_debouncing[row] = cols; + //debouncing = DEBOUNCE; + changed = true; + } + } + + debounce(matrix_debouncing, matrix, MATRIX_ROWS, changed); + + matrix_scan_quantum(); + +#ifdef DEBUG_MATRIX + for (uint8_t c = 0; c < MATRIX_COLS; c++) + for (uint8_t r = 0; r < MATRIX_ROWS; r++) + if (matrix_is_on(r, c)) xprintf("r:%d c:%d \n", r, c); +#endif + + return (uint8_t)changed; +} + +inline +matrix_row_t matrix_get_row(uint8_t row) +{ + return matrix[row]; +} + +void matrix_print(void) +{ + print("\nr/c 0123456789ABCDEF\n"); + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + phex(row); print(": "); + pbin_reverse16(matrix_get_row(row)); + print("\n"); + } +} + +uint8_t matrix_key_count(void) +{ + uint8_t count = 0; + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + count += bitpop16(matrix[i]); + } + return count; +} + +static void matrix_select_row(uint8_t row) +{ +#ifdef RIGHT_HALF + uint8_t txdata[3]; + + //Set the remote row on port A + txdata[0] = GPIOA; + txdata[1] = 0xFF & ~(1<