diff options
| author | Fred Sundvik <fsundvik@gmail.com> | 2016-02-28 22:52:30 +0200 |
|---|---|---|
| committer | Fred Sundvik <fsundvik@gmail.com> | 2016-02-28 22:52:30 +0200 |
| commit | 6fe6d111bf563962e0d3cc2e4812b6d7959836a3 (patch) | |
| tree | 22705eef7e6fbe0eeb8d8c8132a819cdfb101d75 | |
| parent | d8d4622802c1a50779830eade0f79a0680def34a (diff) | |
| download | qmk_firmware-6fe6d111bf563962e0d3cc2e4812b6d7959836a3.tar.gz qmk_firmware-6fe6d111bf563962e0d3cc2e4812b6d7959836a3.zip | |
Send the keyboard matrix over the serial link
| -rw-r--r-- | serial_link/system/system.c | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/serial_link/system/system.c b/serial_link/system/system.c index c38bcd87d..68ccbdb45 100644 --- a/serial_link/system/system.c +++ b/serial_link/system/system.c | |||
| @@ -29,6 +29,7 @@ SOFTWARE. | |||
| 29 | #include "serial_link/protocol/byte_stuffer.h" | 29 | #include "serial_link/protocol/byte_stuffer.h" |
| 30 | #include "serial_link/protocol/transport.h" | 30 | #include "serial_link/protocol/transport.h" |
| 31 | #include "serial_link/protocol/frame_router.h" | 31 | #include "serial_link/protocol/frame_router.h" |
| 32 | #include "matrix.h" | ||
| 32 | #include <stdbool.h> | 33 | #include <stdbool.h> |
| 33 | #include "print.h" | 34 | #include "print.h" |
| 34 | 35 | ||
| @@ -111,16 +112,17 @@ void send_data(uint8_t link, const uint8_t* data, uint16_t size) { | |||
| 111 | static systime_t last_update = 0; | 112 | static systime_t last_update = 0; |
| 112 | 113 | ||
| 113 | typedef struct { | 114 | typedef struct { |
| 114 | uint32_t test; | 115 | matrix_row_t rows[MATRIX_ROWS]; |
| 115 | } test_object1_t; | 116 | } matrix_object_t; |
| 116 | 117 | ||
| 118 | static matrix_object_t last_matrix = {}; | ||
| 117 | 119 | ||
| 118 | SLAVE_TO_MASTER_OBJECT(slave_to_master, test_object1_t); | 120 | SLAVE_TO_MASTER_OBJECT(keyboard_matrix, matrix_object_t); |
| 119 | MASTER_TO_ALL_SLAVES_OBJECT(serial_link_connected, bool); | 121 | MASTER_TO_ALL_SLAVES_OBJECT(serial_link_connected, bool); |
| 120 | 122 | ||
| 121 | remote_object_t* test_remote_objects[] = { | 123 | remote_object_t* test_remote_objects[] = { |
| 122 | REMOTE_OBJECT(serial_link_connected), | 124 | REMOTE_OBJECT(serial_link_connected), |
| 123 | REMOTE_OBJECT(slave_to_master), | 125 | REMOTE_OBJECT(keyboard_matrix), |
| 124 | }; | 126 | }; |
| 125 | 127 | ||
| 126 | void init_serial_link(void) { | 128 | void init_serial_link(void) { |
| @@ -140,24 +142,42 @@ void serial_link_update(void) { | |||
| 140 | if (current_time - last_update > 1000) { | 142 | if (current_time - last_update > 1000) { |
| 141 | *begin_write_serial_link_connected() = true; | 143 | *begin_write_serial_link_connected() = true; |
| 142 | end_write_serial_link_connected(); | 144 | end_write_serial_link_connected(); |
| 143 | test_object1_t* obj = begin_write_slave_to_master(); | ||
| 144 | obj->test = current_time; | ||
| 145 | end_write_slave_to_master(); | ||
| 146 | xprintf("writing %d\n", current_time); | ||
| 147 | last_update = current_time; | 145 | last_update = current_time; |
| 148 | } | 146 | } |
| 149 | test_object1_t* obj = read_slave_to_master(0); | ||
| 150 | if (obj) { | ||
| 151 | xprintf("%d\n", obj->test); | ||
| 152 | } | ||
| 153 | obj = read_slave_to_master(1); | ||
| 154 | if (obj) { | ||
| 155 | xprintf("%d\n", obj->test); | ||
| 156 | } | ||
| 157 | 147 | ||
| 158 | if (read_serial_link_connected()) { | 148 | if (read_serial_link_connected()) { |
| 159 | serial_link_connected = true; | 149 | serial_link_connected = true; |
| 160 | } | 150 | } |
| 151 | |||
| 152 | matrix_object_t matrix; | ||
| 153 | bool changed = false; | ||
| 154 | for(uint8_t i=0;i<MATRIX_ROWS;i++) { | ||
| 155 | matrix.rows[i] = matrix_get_row(i); | ||
| 156 | changed |= matrix.rows[i] != last_matrix.rows[i]; | ||
| 157 | } | ||
| 158 | if (changed) { | ||
| 159 | last_matrix = matrix; | ||
| 160 | matrix_object_t* m = begin_write_keyboard_matrix(); | ||
| 161 | for(uint8_t i=0;i<MATRIX_ROWS;i++) { | ||
| 162 | m->rows[i] = matrix.rows[i]; | ||
| 163 | } | ||
| 164 | end_write_keyboard_matrix(); | ||
| 165 | } | ||
| 166 | |||
| 167 | matrix_object_t* m = read_keyboard_matrix(0); | ||
| 168 | if (m) { | ||
| 169 | xprintf("\nr/c 01234567\n"); | ||
| 170 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 171 | xprintf("%X0: ", row); | ||
| 172 | for (int col = 0; col < MATRIX_COLS; col++) { | ||
| 173 | if (m->rows[row] & (1<<col)) | ||
| 174 | xprintf("1"); | ||
| 175 | else | ||
| 176 | xprintf("0"); | ||
| 177 | } | ||
| 178 | xprintf("\n"); | ||
| 179 | } | ||
| 180 | } | ||
| 161 | } | 181 | } |
| 162 | 182 | ||
| 163 | void signal_data_written(void) { | 183 | void signal_data_written(void) { |
| @@ -172,6 +192,7 @@ host_driver_t* get_serial_link_driver(void) { | |||
| 172 | return &serial_driver; | 192 | return &serial_driver; |
| 173 | } | 193 | } |
| 174 | 194 | ||
| 195 | // NOTE: The driver does nothing, because the master handles everything | ||
| 175 | uint8_t keyboard_leds(void) { | 196 | uint8_t keyboard_leds(void) { |
| 176 | return 0; | 197 | return 0; |
| 177 | } | 198 | } |
