diff options
| author | Nick Brassel <nick@tzarc.org> | 2024-03-10 22:24:17 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-10 22:24:17 +1100 |
| commit | 3e1ac7a38fa4e6885053a762bc75f7c4e068eccb (patch) | |
| tree | 102642e387cebb67a840ae23ffda5d7413f33a71 /quantum/split_common | |
| parent | be42ea306b36bf7fac8b790452536156de8efcf6 (diff) | |
Fixes for encoder abstraction. (#23195)
Diffstat (limited to 'quantum/split_common')
| -rw-r--r-- | quantum/split_common/transaction_id_define.h | 2 | ||||
| -rw-r--r-- | quantum/split_common/transactions.c | 32 |
2 files changed, 25 insertions, 9 deletions
diff --git a/quantum/split_common/transaction_id_define.h b/quantum/split_common/transaction_id_define.h index 05b3bf7b62..5bfbe2aec7 100644 --- a/quantum/split_common/transaction_id_define.h +++ b/quantum/split_common/transaction_id_define.h | |||
| @@ -31,7 +31,7 @@ enum serial_transaction_id { | |||
| 31 | #ifdef ENCODER_ENABLE | 31 | #ifdef ENCODER_ENABLE |
| 32 | GET_ENCODERS_CHECKSUM, | 32 | GET_ENCODERS_CHECKSUM, |
| 33 | GET_ENCODERS_DATA, | 33 | GET_ENCODERS_DATA, |
| 34 | PUT_ENCODER_TAIL, | 34 | CMD_ENCODER_DRAIN, |
| 35 | #endif // ENCODER_ENABLE | 35 | #endif // ENCODER_ENABLE |
| 36 | 36 | ||
| 37 | #ifndef DISABLE_SYNC_TIMER | 37 | #ifndef DISABLE_SYNC_TIMER |
diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index 2cfa83e7a3..33bc9e9f57 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | #include <stdint.h> | ||
| 17 | #include <string.h> | 18 | #include <string.h> |
| 18 | #include <stddef.h> | 19 | #include <stddef.h> |
| 19 | 20 | ||
| @@ -80,8 +81,12 @@ | |||
| 80 | { 0, 0, sizeof_member(split_shared_memory_t, member), offsetof(split_shared_memory_t, member), cb } | 81 | { 0, 0, sizeof_member(split_shared_memory_t, member), offsetof(split_shared_memory_t, member), cb } |
| 81 | #define trans_target2initiator_initializer(member) trans_target2initiator_initializer_cb(member, NULL) | 82 | #define trans_target2initiator_initializer(member) trans_target2initiator_initializer_cb(member, NULL) |
| 82 | 83 | ||
| 84 | #define trans_initiator2target_cb(cb) \ | ||
| 85 | { 0, 0, 0, 0, cb } | ||
| 86 | |||
| 83 | #define transport_write(id, data, length) transport_execute_transaction(id, data, length, NULL, 0) | 87 | #define transport_write(id, data, length) transport_execute_transaction(id, data, length, NULL, 0) |
| 84 | #define transport_read(id, data, length) transport_execute_transaction(id, NULL, 0, data, length) | 88 | #define transport_read(id, data, length) transport_execute_transaction(id, NULL, 0, data, length) |
| 89 | #define transport_exec(id) transport_execute_transaction(id, NULL, 0, NULL, 0) | ||
| 85 | 90 | ||
| 86 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) | 91 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) |
| 87 | // Forward-declare the RPC callback handlers | 92 | // Forward-declare the RPC callback handlers |
| @@ -234,14 +239,26 @@ static void master_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_ro | |||
| 234 | #ifdef ENCODER_ENABLE | 239 | #ifdef ENCODER_ENABLE |
| 235 | 240 | ||
| 236 | static bool encoder_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { | 241 | static bool encoder_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { |
| 237 | static uint32_t last_update = 0; | 242 | static uint32_t last_update = 0; |
| 243 | static uint8_t last_checksum = 0; | ||
| 238 | encoder_events_t temp_events; | 244 | encoder_events_t temp_events; |
| 239 | 245 | ||
| 240 | bool okay = read_if_checksum_mismatch(GET_ENCODERS_CHECKSUM, GET_ENCODERS_DATA, &last_update, &temp_events, &split_shmem->encoders.events, sizeof(temp_events)); | 246 | bool okay = read_if_checksum_mismatch(GET_ENCODERS_CHECKSUM, GET_ENCODERS_DATA, &last_update, &temp_events, &split_shmem->encoders.events, sizeof(temp_events)); |
| 241 | if (okay) { | 247 | if (okay) { |
| 242 | encoder_handle_slave_events(&split_shmem->encoders.events); | 248 | if (last_checksum != split_shmem->encoders.checksum) { |
| 243 | transport_write(PUT_ENCODER_TAIL, &split_shmem->encoders.events.tail, sizeof(split_shmem->encoders.events.tail)); | 249 | bool actioned = false; |
| 244 | split_shmem->encoders.checksum = crc8(&split_shmem->encoders.events, sizeof(split_shmem->encoders.events)); | 250 | uint8_t index; |
| 251 | bool clockwise; | ||
| 252 | while (okay && encoder_dequeue_event_advanced(&split_shmem->encoders.events, &index, &clockwise)) { | ||
| 253 | okay &= encoder_queue_event(index, clockwise); | ||
| 254 | actioned = true; | ||
| 255 | } | ||
| 256 | |||
| 257 | if (actioned) { | ||
| 258 | okay &= transport_exec(CMD_ENCODER_DRAIN); | ||
| 259 | } | ||
| 260 | last_checksum = split_shmem->encoders.checksum; | ||
| 261 | } | ||
| 245 | } | 262 | } |
| 246 | return okay; | 263 | return okay; |
| 247 | } | 264 | } |
| @@ -253,9 +270,8 @@ static void encoder_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sl | |||
| 253 | split_shmem->encoders.checksum = crc8(&split_shmem->encoders.events, sizeof(split_shmem->encoders.events)); | 270 | split_shmem->encoders.checksum = crc8(&split_shmem->encoders.events, sizeof(split_shmem->encoders.events)); |
| 254 | } | 271 | } |
| 255 | 272 | ||
| 256 | static void encoder_handlers_slave_reset(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer) { | 273 | static void encoder_handlers_slave_drain(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer) { |
| 257 | uint8_t tail_index = *(uint8_t *)initiator2target_buffer; | 274 | encoder_signal_queue_drain(); |
| 258 | encoder_set_tail_index(tail_index); | ||
| 259 | } | 275 | } |
| 260 | 276 | ||
| 261 | // clang-format off | 277 | // clang-format off |
| @@ -264,7 +280,7 @@ static void encoder_handlers_slave_reset(uint8_t initiator2target_buffer_size, c | |||
| 264 | # define TRANSACTIONS_ENCODERS_REGISTRATIONS \ | 280 | # define TRANSACTIONS_ENCODERS_REGISTRATIONS \ |
| 265 | [GET_ENCODERS_CHECKSUM] = trans_target2initiator_initializer(encoders.checksum), \ | 281 | [GET_ENCODERS_CHECKSUM] = trans_target2initiator_initializer(encoders.checksum), \ |
| 266 | [GET_ENCODERS_DATA] = trans_target2initiator_initializer(encoders.events), \ | 282 | [GET_ENCODERS_DATA] = trans_target2initiator_initializer(encoders.events), \ |
| 267 | [PUT_ENCODER_TAIL] = trans_initiator2target_initializer_cb(encoders.events.tail, encoder_handlers_slave_reset), | 283 | [CMD_ENCODER_DRAIN] = trans_initiator2target_cb(encoder_handlers_slave_drain), |
| 268 | // clang-format on | 284 | // clang-format on |
| 269 | 285 | ||
| 270 | #else // ENCODER_ENABLE | 286 | #else // ENCODER_ENABLE |
