diff options
author | Takeshi ISHII <2170248+mtei@users.noreply.github.com> | 2018-12-25 04:14:57 +0900 |
---|---|---|
committer | Drashna Jaelre <drashna@live.com> | 2018-12-24 11:14:57 -0800 |
commit | 72d4e4bfd76b2c83b89787f8b3a8ba779a3e8d81 (patch) | |
tree | 694d3d9251aa752c11788e1e8550cba0cb78578b /quantum/split_common/matrix.c | |
parent | 2149f3b5889f898fecde845a03d61c1a854d9393 (diff) | |
download | qmk_firmware-72d4e4bfd76b2c83b89787f8b3a8ba779a3e8d81.tar.gz qmk_firmware-72d4e4bfd76b2c83b89787f8b3a8ba779a3e8d81.zip |
Replace serial.c of quantum/split_common/ (#4669)
* Add provisional Helix implementation to test the quantum/split_common.
* copy keyboards/helix/serial.[ch] to quantum/split_common/
* Make serial.c a pure driver.
Remove buffer name and buffer size from serial.c. They should be placed in the caller(matrix.c, split_utils.c).
* remove quantum/split_common/serial_backward_compatibility.h
* Changed array serial_master_buffer to structure serial_m2s_buffer.
* Changed array serial_slave_buffer to structure serial_s2m_buffer.
* Change keyboards/miniaxe/matrix.c
I also made changes to quantum/split_comon/matrix.c to keyboards/miniaxe/matrix.c.
Note: I contacted @ka2hiro, creator of miniaxe, and I got permission to change keyboards/miniaxe/matrix.c.
* update history comment in quantum/split_common/serial.c
* Revert "Add provisional Helix implementation to test the quantum/split_common."
This reverts commit 168c82ef82c88e79979d9796bab9cc819cc2f685.
* fix keyboards/miniaxe/matrix.c, quantum/split_common/matrix.c
avr-gcc 4.9.[23] report error.
avr-gcc 5.4.0, avr-gcc 7.3.0 pass.
It is funny.
* update comment quantum/split_common/serial.c
* Reserve RGBLIGHT_SPLIT macro in quantum/split_common
Diffstat (limited to 'quantum/split_common/matrix.c')
-rw-r--r-- | quantum/split_common/matrix.c | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index d6359b51f..261137638 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/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 |
@@ -286,24 +306,48 @@ i2c_error: // the cable is disconnceted, or something else went wrong | |||
286 | 306 | ||
287 | #else // USE_SERIAL | 307 | #else // USE_SERIAL |
288 | 308 | ||
309 | |||
310 | typedef struct _Serial_s2m_buffer_t { | ||
311 | // TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack | ||
312 | matrix_row_t smatrix[ROWS_PER_HAND]; | ||
313 | } Serial_s2m_buffer_t; | ||
314 | |||
315 | volatile Serial_s2m_buffer_t serial_s2m_buffer = {}; | ||
316 | volatile Serial_m2s_buffer_t serial_m2s_buffer = {}; | ||
317 | uint8_t volatile status0 = 0; | ||
318 | |||
319 | SSTD_t transactions[] = { | ||
320 | { (uint8_t *)&status0, | ||
321 | sizeof(serial_m2s_buffer), (uint8_t *)&serial_m2s_buffer, | ||
322 | sizeof(serial_s2m_buffer), (uint8_t *)&serial_s2m_buffer | ||
323 | } | ||
324 | }; | ||
325 | |||
326 | void serial_master_init(void) | ||
327 | { soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); } | ||
328 | |||
329 | void serial_slave_init(void) | ||
330 | { soft_serial_target_init(transactions, TID_LIMIT(transactions)); } | ||
331 | |||
289 | int serial_transaction(void) { | 332 | int serial_transaction(void) { |
290 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | 333 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; |
291 | 334 | ||
292 | if (serial_update_buffers()) { | 335 | if (soft_serial_transaction()) { |
293 | return 1; | 336 | return 1; |
294 | } | 337 | } |
295 | 338 | ||
339 | // TODO: if MATRIX_COLS > 8 change to unpack() | ||
296 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | 340 | for (int i = 0; i < ROWS_PER_HAND; ++i) { |
297 | matrix[slaveOffset+i] = serial_slave_buffer[i]; | 341 | matrix[slaveOffset+i] = serial_s2m_buffer.smatrix[i]; |
298 | } | 342 | } |
299 | 343 | ||
300 | #ifdef RGBLIGHT_ENABLE | 344 | #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) |
301 | // Code to send RGB over serial goes here (not implemented yet) | 345 | // Code to send RGB over serial goes here (not implemented yet) |
302 | #endif | 346 | #endif |
303 | 347 | ||
304 | #ifdef BACKLIGHT_ENABLE | 348 | #ifdef BACKLIGHT_ENABLE |
305 | // Write backlight level for slave to read | 349 | // Write backlight level for slave to read |
306 | serial_master_buffer[SERIAL_BACKLIT_START] = backlight_config.enable ? backlight_config.level : 0; | 350 | serial_m2s_buffer.backlight_level = backlight_config.enable ? backlight_config.level : 0; |
307 | #endif | 351 | #endif |
308 | 352 | ||
309 | return 0; | 353 | return 0; |
@@ -346,8 +390,9 @@ void matrix_slave_scan(void) { | |||
346 | i2c_slave_buffer[I2C_KEYMAP_START+i] = matrix[offset+i]; | 390 | i2c_slave_buffer[I2C_KEYMAP_START+i] = matrix[offset+i]; |
347 | } | 391 | } |
348 | #else // USE_SERIAL | 392 | #else // USE_SERIAL |
393 | // TODO: if MATRIX_COLS > 8 change to pack() | ||
349 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | 394 | for (int i = 0; i < ROWS_PER_HAND; ++i) { |
350 | serial_slave_buffer[i] = matrix[offset+i]; | 395 | serial_s2m_buffer.smatrix[i] = matrix[offset+i]; |
351 | } | 396 | } |
352 | #endif | 397 | #endif |
353 | matrix_slave_scan_user(); | 398 | matrix_slave_scan_user(); |