diff options
Diffstat (limited to 'keyboards/miniaxe/matrix.c')
-rw-r--r-- | keyboards/miniaxe/matrix.c | 59 |
1 files changed, 52 insertions, 7 deletions
diff --git a/keyboards/miniaxe/matrix.c b/keyboards/miniaxe/matrix.c index 55c458e1f..5fec1281d 100644 --- a/keyboards/miniaxe/matrix.c +++ b/keyboards/miniaxe/matrix.c | |||
@@ -32,9 +32,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
32 | #include "timer.h" | 32 | #include "timer.h" |
33 | #include "split_flags.h" | 33 | #include "split_flags.h" |
34 | 34 | ||
35 | #ifdef RGBLIGHT_ENABLE | ||
36 | # include "rgblight.h" | ||
37 | #endif | ||
38 | #ifdef BACKLIGHT_ENABLE | 35 | #ifdef BACKLIGHT_ENABLE |
39 | # include "backlight.h" | 36 | # include "backlight.h" |
40 | extern backlight_config_t backlight_config; | 37 | extern backlight_config_t backlight_config; |
@@ -55,6 +52,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
55 | static bool debouncing = false; | 52 | static bool debouncing = false; |
56 | #endif | 53 | #endif |
57 | 54 | ||
55 | #if defined(USE_I2C) || defined(EH) | ||
56 | |||
58 | #if (MATRIX_COLS <= 8) | 57 | #if (MATRIX_COLS <= 8) |
59 | # define print_matrix_header() print("\nr/c 01234567\n") | 58 | # define print_matrix_header() print("\nr/c 01234567\n") |
60 | # define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) | 59 | # define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) |
@@ -63,6 +62,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
63 | #else | 62 | #else |
64 | # error "Currently only supports 8 COLS" | 63 | # error "Currently only supports 8 COLS" |
65 | #endif | 64 | #endif |
65 | |||
66 | #else // USE_SERIAL | ||
67 | |||
68 | #if (MATRIX_COLS <= 8) | ||
69 | # define print_matrix_header() print("\nr/c 01234567\n") | ||
70 | # define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) | ||
71 | # define matrix_bitpop(i) bitpop(matrix[i]) | ||
72 | # define ROW_SHIFTER ((uint8_t)1) | ||
73 | #elif (MATRIX_COLS <= 16) | ||
74 | # define print_matrix_header() print("\nr/c 0123456789ABCDEF\n") | ||
75 | # define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row)) | ||
76 | # define matrix_bitpop(i) bitpop16(matrix[i]) | ||
77 | # define ROW_SHIFTER ((uint16_t)1) | ||
78 | #elif (MATRIX_COLS <= 32) | ||
79 | # define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n") | ||
80 | # define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row)) | ||
81 | # define matrix_bitpop(i) bitpop32(matrix[i]) | ||
82 | # define ROW_SHIFTER ((uint32_t)1) | ||
83 | #endif | ||
84 | |||
85 | #endif | ||
66 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | 86 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; |
67 | 87 | ||
68 | #define ERROR_DISCONNECT_COUNT 5 | 88 | #define ERROR_DISCONNECT_COUNT 5 |
@@ -315,15 +335,39 @@ i2c_error: // the cable is disconnceted, or something else went wrong | |||
315 | 335 | ||
316 | #else // USE_SERIAL | 336 | #else // USE_SERIAL |
317 | 337 | ||
338 | |||
339 | typedef struct _Serial_s2m_buffer_t { | ||
340 | // TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack | ||
341 | matrix_row_t smatrix[ROWS_PER_HAND]; | ||
342 | } Serial_s2m_buffer_t; | ||
343 | |||
344 | volatile Serial_s2m_buffer_t serial_s2m_buffer = {}; | ||
345 | volatile Serial_m2s_buffer_t serial_m2s_buffer = {}; | ||
346 | uint8_t volatile status0 = 0; | ||
347 | |||
348 | SSTD_t transactions[] = { | ||
349 | { (uint8_t *)&status0, | ||
350 | sizeof(serial_m2s_buffer), (uint8_t *)&serial_m2s_buffer, | ||
351 | sizeof(serial_s2m_buffer), (uint8_t *)&serial_s2m_buffer | ||
352 | } | ||
353 | }; | ||
354 | |||
355 | void serial_master_init(void) | ||
356 | { soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); } | ||
357 | |||
358 | void serial_slave_init(void) | ||
359 | { soft_serial_target_init(transactions, TID_LIMIT(transactions)); } | ||
360 | |||
318 | int serial_transaction(void) { | 361 | int serial_transaction(void) { |
319 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | 362 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; |
320 | 363 | ||
321 | if (serial_update_buffers()) { | 364 | if (soft_serial_transaction()) { |
322 | return 1; | 365 | return 1; |
323 | } | 366 | } |
324 | 367 | ||
368 | // TODO: if MATRIX_COLS > 8 change to unpack() | ||
325 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | 369 | for (int i = 0; i < ROWS_PER_HAND; ++i) { |
326 | matrix[slaveOffset+i] = serial_slave_buffer[i]; | 370 | matrix[slaveOffset+i] = serial_s2m_buffer.smatrix[i]; |
327 | } | 371 | } |
328 | 372 | ||
329 | #ifdef RGBLIGHT_ENABLE | 373 | #ifdef RGBLIGHT_ENABLE |
@@ -332,7 +376,7 @@ int serial_transaction(void) { | |||
332 | 376 | ||
333 | #ifdef BACKLIGHT_ENABLE | 377 | #ifdef BACKLIGHT_ENABLE |
334 | // Write backlight level for slave to read | 378 | // Write backlight level for slave to read |
335 | serial_master_buffer[SERIAL_BACKLIT_START] = backlight_config.enable ? backlight_config.level : 0; | 379 | serial_m2s_buffer.backlight_level = backlight_config.enable ? backlight_config.level : 0; |
336 | #endif | 380 | #endif |
337 | 381 | ||
338 | return 0; | 382 | return 0; |
@@ -375,8 +419,9 @@ void matrix_slave_scan(void) { | |||
375 | i2c_slave_buffer[I2C_KEYMAP_START+i] = matrix[offset+i]; | 419 | i2c_slave_buffer[I2C_KEYMAP_START+i] = matrix[offset+i]; |
376 | } | 420 | } |
377 | #else // USE_SERIAL | 421 | #else // USE_SERIAL |
422 | // TODO: if MATRIX_COLS > 8 change to pack() | ||
378 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | 423 | for (int i = 0; i < ROWS_PER_HAND; ++i) { |
379 | serial_slave_buffer[i] = matrix[offset+i]; | 424 | serial_s2m_buffer.smatrix[i] = matrix[offset+i]; |
380 | } | 425 | } |
381 | #endif | 426 | #endif |
382 | matrix_slave_scan_user(); | 427 | matrix_slave_scan_user(); |