aboutsummaryrefslogtreecommitdiff
path: root/keyboards/lets_split/matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/lets_split/matrix.c')
-rw-r--r--keyboards/lets_split/matrix.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/keyboards/lets_split/matrix.c b/keyboards/lets_split/matrix.c
index 1d768c59b..138969004 100644
--- a/keyboards/lets_split/matrix.c
+++ b/keyboards/lets_split/matrix.c
@@ -28,14 +28,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
28#include "debug.h" 28#include "debug.h"
29#include "util.h" 29#include "util.h"
30#include "matrix.h" 30#include "matrix.h"
31#include "i2c.h"
32#include "serial.h"
33#include "split_util.h" 31#include "split_util.h"
34#include "pro_micro.h" 32#include "pro_micro.h"
35#include "config.h" 33#include "config.h"
36 34
35#ifdef USE_I2C
36# include "i2c.h"
37#else // USE_SERIAL
38# include "serial.h"
39#endif
40
37#ifndef DEBOUNCE 41#ifndef DEBOUNCE
38# define DEBOUNCE 5 42# define DEBOUNCE 5
39#endif 43#endif
40 44
41#define ERROR_DISCONNECT_COUNT 5 45#define ERROR_DISCONNECT_COUNT 5
@@ -145,6 +149,8 @@ uint8_t _matrix_scan(void)
145 return 1; 149 return 1;
146} 150}
147 151
152#ifdef USE_I2C
153
148// Get rows from other half over i2c 154// Get rows from other half over i2c
149int i2c_transaction(void) { 155int i2c_transaction(void) {
150 int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; 156 int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
@@ -176,7 +182,8 @@ i2c_error: // the cable is disconnceted, or something else went wrong
176 return 0; 182 return 0;
177} 183}
178 184
179#ifndef USE_I2C 185#else // USE_SERIAL
186
180int serial_transaction(void) { 187int serial_transaction(void) {
181 int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; 188 int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
182 189
@@ -199,7 +206,7 @@ uint8_t matrix_scan(void)
199 206
200#ifdef USE_I2C 207#ifdef USE_I2C
201 if( i2c_transaction() ) { 208 if( i2c_transaction() ) {
202#else 209#else // USE_SERIAL
203 if( serial_transaction() ) { 210 if( serial_transaction() ) {
204#endif 211#endif
205 // turn on the indicator led when halves are disconnected 212 // turn on the indicator led when halves are disconnected
@@ -235,7 +242,7 @@ void matrix_slave_scan(void) {
235 /* i2c_slave_buffer[i] = matrix[offset+i]; */ 242 /* i2c_slave_buffer[i] = matrix[offset+i]; */
236 i2c_slave_buffer[i] = matrix[offset+i]; 243 i2c_slave_buffer[i] = matrix[offset+i];
237 } 244 }
238#else 245#else // USE_SERIAL
239 for (int i = 0; i < ROWS_PER_HAND; ++i) { 246 for (int i = 0; i < ROWS_PER_HAND; ++i) {
240 serial_slave_buffer[i] = matrix[offset+i]; 247 serial_slave_buffer[i] = matrix[offset+i];
241 } 248 }
@@ -290,7 +297,7 @@ static void init_cols(void)
290static matrix_row_t read_cols(void) 297static matrix_row_t read_cols(void)
291{ 298{
292 matrix_row_t result = 0; 299 matrix_row_t result = 0;
293 for(int x = 0; x < MATRIX_COLS; x++) { 300 for(int x = 0; x < MATRIX_COLS; x++) {
294 result |= (_SFR_IO8(col_pins[x] >> 4) & _BV(col_pins[x] & 0xF)) ? 0 : (1 << x); 301 result |= (_SFR_IO8(col_pins[x] >> 4) & _BV(col_pins[x] & 0xF)) ? 0 : (1 << x);
295 } 302 }
296 return result; 303 return result;
@@ -298,7 +305,7 @@ static matrix_row_t read_cols(void)
298 305
299static void unselect_rows(void) 306static void unselect_rows(void)
300{ 307{
301 for(int x = 0; x < ROWS_PER_HAND; x++) { 308 for(int x = 0; x < ROWS_PER_HAND; x++) {
302 _SFR_IO8((row_pins[x] >> 4) + 1) &= ~_BV(row_pins[x] & 0xF); 309 _SFR_IO8((row_pins[x] >> 4) + 1) &= ~_BV(row_pins[x] & 0xF);
303 _SFR_IO8((row_pins[x] >> 4) + 2) |= _BV(row_pins[x] & 0xF); 310 _SFR_IO8((row_pins[x] >> 4) + 2) |= _BV(row_pins[x] & 0xF);
304 } 311 }