diff options
| author | Dasky <32983009+daskygit@users.noreply.github.com> | 2021-12-27 01:05:51 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-27 12:05:51 +1100 |
| commit | 7f7364c55912879baaff8fafca550d02f17b4d44 (patch) | |
| tree | 8afd414f6b202a126632a8c047dcf200312c78ff /quantum/split_common | |
| parent | 76a673233c8cb3d97130a6dece364c24b29f5fd7 (diff) | |
[Core] Split support for pointing devices. (#15304)
* Draft implementation
* formatting
* fix combined buttons
* remove pimoroni throttle
* sync pointing on a throttle loop with checksum
* no longer used
* doh
Co-authored-by: Drashna Jaelre <drashna@live.com>
* switch pimoroni to a cpi equivalent
* add cpi support
* allow user modification of seperate mouse reports
* a little tidy up
* add *_RIGHT defines.
* docs
* doxygen comments
* basic changelog
* clean up pimoroni
* small doc fixes
* Update docs/feature_pointing_device.md
Co-authored-by: Drashna Jaelre <drashna@live.com>
* performance tweak if side has usb
* Don't run init funtions on wrong side
* renamed some variables for consistency
* fix pimoroni typos
* Clamp instead of OR
* Promote combined values to uint16_t
* Update pointing_device.c
Co-authored-by: Drashna Jaelre <drashna@live.com>
Co-authored-by: Nick Brassel <nick@tzarc.org>
Diffstat (limited to 'quantum/split_common')
| -rw-r--r-- | quantum/split_common/transaction_id_define.h | 6 | ||||
| -rw-r--r-- | quantum/split_common/transactions.c | 79 | ||||
| -rw-r--r-- | quantum/split_common/transport.h | 13 |
3 files changed, 98 insertions, 0 deletions
diff --git a/quantum/split_common/transaction_id_define.h b/quantum/split_common/transaction_id_define.h index 535bc21aea..aa71c3621e 100644 --- a/quantum/split_common/transaction_id_define.h +++ b/quantum/split_common/transaction_id_define.h | |||
| @@ -78,6 +78,12 @@ enum serial_transaction_id { | |||
| 78 | PUT_ST7565, | 78 | PUT_ST7565, |
| 79 | #endif // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) | 79 | #endif // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) |
| 80 | 80 | ||
| 81 | #if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) | ||
| 82 | GET_POINTING_CHECKSUM, | ||
| 83 | GET_POINTING_DATA, | ||
| 84 | PUT_POINTING_CPI, | ||
| 85 | #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) | ||
| 86 | |||
| 81 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) | 87 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) |
| 82 | PUT_RPC_INFO, | 88 | PUT_RPC_INFO, |
| 83 | PUT_RPC_REQ_DATA, | 89 | PUT_RPC_REQ_DATA, |
diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index 3ff87710e7..9622acb377 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c | |||
| @@ -579,6 +579,82 @@ static void st7565_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sla | |||
| 579 | #endif // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) | 579 | #endif // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) |
| 580 | 580 | ||
| 581 | //////////////////////////////////////////////////// | 581 | //////////////////////////////////////////////////// |
| 582 | // POINTING | ||
| 583 | |||
| 584 | #if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) | ||
| 585 | |||
| 586 | static bool pointing_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { | ||
| 587 | # if defined(POINTING_DEVICE_LEFT) | ||
| 588 | if (is_keyboard_left()) { | ||
| 589 | return true; | ||
| 590 | } | ||
| 591 | # elif defined(POINTING_DEVICE_RIGHT) | ||
| 592 | if (!is_keyboard_left()) { | ||
| 593 | return true; | ||
| 594 | } | ||
| 595 | # endif | ||
| 596 | static uint32_t last_update = 0; | ||
| 597 | static uint16_t last_cpi = 0; | ||
| 598 | report_mouse_t temp_state; | ||
| 599 | uint16_t temp_cpi; | ||
| 600 | bool okay = read_if_checksum_mismatch(GET_POINTING_CHECKSUM, GET_POINTING_DATA, &last_update, &temp_state, &split_shmem->pointing.report, sizeof(temp_state)); | ||
| 601 | if (okay) pointing_device_set_shared_report(temp_state); | ||
| 602 | temp_cpi = pointing_device_get_shared_cpi(); | ||
| 603 | if (temp_cpi && memcmp(&last_cpi, &temp_cpi, sizeof(temp_cpi)) != 0) { | ||
| 604 | memcpy(&split_shmem->pointing.cpi, &temp_cpi, sizeof(temp_cpi)); | ||
| 605 | okay = transport_write(PUT_POINTING_CPI, &split_shmem->pointing.cpi, sizeof(split_shmem->pointing.cpi)); | ||
| 606 | if (okay) { | ||
| 607 | last_cpi = temp_cpi; | ||
| 608 | } | ||
| 609 | } | ||
| 610 | return okay; | ||
| 611 | } | ||
| 612 | |||
| 613 | extern const pointing_device_driver_t pointing_device_driver; | ||
| 614 | |||
| 615 | static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { | ||
| 616 | # if defined(POINTING_DEVICE_LEFT) | ||
| 617 | if (!is_keyboard_left()) { | ||
| 618 | return; | ||
| 619 | } | ||
| 620 | # elif defined(POINTING_DEVICE_RIGHT) | ||
| 621 | if (is_keyboard_left()) { | ||
| 622 | return; | ||
| 623 | } | ||
| 624 | # endif | ||
| 625 | report_mouse_t temp_report; | ||
| 626 | uint16_t temp_cpi; | ||
| 627 | # ifdef POINTING_DEVICE_TASK_THROTTLE_MS | ||
| 628 | static uint32_t last_exec = 0; | ||
| 629 | if (timer_elapsed32(last_exec) < POINTING_DEVICE_TASK_THROTTLE_MS) { | ||
| 630 | return; | ||
| 631 | } | ||
| 632 | last_exec = timer_read32(); | ||
| 633 | # endif | ||
| 634 | temp_cpi = pointing_device_driver.get_cpi(); | ||
| 635 | if (split_shmem->pointing.cpi && memcmp(&split_shmem->pointing.cpi, &temp_cpi, sizeof(temp_cpi)) != 0) { | ||
| 636 | pointing_device_driver.set_cpi(split_shmem->pointing.cpi); | ||
| 637 | } | ||
| 638 | memset(&temp_report, 0, sizeof(temp_report)); | ||
| 639 | temp_report = pointing_device_driver.get_report(temp_report); | ||
| 640 | memcpy(&split_shmem->pointing.report, &temp_report, sizeof(temp_report)); | ||
| 641 | // Now update the checksum given that the pointing has been written to | ||
| 642 | split_shmem->pointing.checksum = crc8(&temp_report, sizeof(temp_report)); | ||
| 643 | } | ||
| 644 | |||
| 645 | # define TRANSACTIONS_POINTING_MASTER() TRANSACTION_HANDLER_MASTER(pointing) | ||
| 646 | # define TRANSACTIONS_POINTING_SLAVE() TRANSACTION_HANDLER_SLAVE(pointing) | ||
| 647 | # define TRANSACTIONS_POINTING_REGISTRATIONS [GET_POINTING_CHECKSUM] = trans_target2initiator_initializer(pointing.checksum), [GET_POINTING_DATA] = trans_target2initiator_initializer(pointing.report), [PUT_POINTING_CPI] = trans_initiator2target_initializer(pointing.cpi), | ||
| 648 | |||
| 649 | #else // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) | ||
| 650 | |||
| 651 | # define TRANSACTIONS_POINTING_MASTER() | ||
| 652 | # define TRANSACTIONS_POINTING_SLAVE() | ||
| 653 | # define TRANSACTIONS_POINTING_REGISTRATIONS | ||
| 654 | |||
| 655 | #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) | ||
| 656 | |||
| 657 | //////////////////////////////////////////////////// | ||
| 582 | 658 | ||
| 583 | uint8_t dummy; | 659 | uint8_t dummy; |
| 584 | split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { | 660 | split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { |
| @@ -604,6 +680,7 @@ split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { | |||
| 604 | TRANSACTIONS_WPM_REGISTRATIONS | 680 | TRANSACTIONS_WPM_REGISTRATIONS |
| 605 | TRANSACTIONS_OLED_REGISTRATIONS | 681 | TRANSACTIONS_OLED_REGISTRATIONS |
| 606 | TRANSACTIONS_ST7565_REGISTRATIONS | 682 | TRANSACTIONS_ST7565_REGISTRATIONS |
| 683 | TRANSACTIONS_POINTING_REGISTRATIONS | ||
| 607 | // clang-format on | 684 | // clang-format on |
| 608 | 685 | ||
| 609 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) | 686 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) |
| @@ -629,6 +706,7 @@ bool transactions_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix | |||
| 629 | TRANSACTIONS_WPM_MASTER(); | 706 | TRANSACTIONS_WPM_MASTER(); |
| 630 | TRANSACTIONS_OLED_MASTER(); | 707 | TRANSACTIONS_OLED_MASTER(); |
| 631 | TRANSACTIONS_ST7565_MASTER(); | 708 | TRANSACTIONS_ST7565_MASTER(); |
| 709 | TRANSACTIONS_POINTING_MASTER(); | ||
| 632 | return true; | 710 | return true; |
| 633 | } | 711 | } |
| 634 | 712 | ||
| @@ -647,6 +725,7 @@ void transactions_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[ | |||
| 647 | TRANSACTIONS_WPM_SLAVE(); | 725 | TRANSACTIONS_WPM_SLAVE(); |
| 648 | TRANSACTIONS_OLED_SLAVE(); | 726 | TRANSACTIONS_OLED_SLAVE(); |
| 649 | TRANSACTIONS_ST7565_SLAVE(); | 727 | TRANSACTIONS_ST7565_SLAVE(); |
| 728 | TRANSACTIONS_POINTING_SLAVE(); | ||
| 650 | } | 729 | } |
| 651 | 730 | ||
| 652 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) | 731 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) |
diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h index 1d4f6ed0cd..31b804908b 100644 --- a/quantum/split_common/transport.h +++ b/quantum/split_common/transport.h | |||
| @@ -106,6 +106,15 @@ typedef struct _split_mods_sync_t { | |||
| 106 | } split_mods_sync_t; | 106 | } split_mods_sync_t; |
| 107 | #endif // SPLIT_MODS_ENABLE | 107 | #endif // SPLIT_MODS_ENABLE |
| 108 | 108 | ||
| 109 | #if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) | ||
| 110 | # include "pointing_device.h" | ||
| 111 | typedef struct _split_slave_pointing_sync_t { | ||
| 112 | uint8_t checksum; | ||
| 113 | report_mouse_t report; | ||
| 114 | uint16_t cpi; | ||
| 115 | } split_slave_pointing_sync_t; | ||
| 116 | #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) | ||
| 117 | |||
| 109 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) | 118 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) |
| 110 | typedef struct _rpc_sync_info_t { | 119 | typedef struct _rpc_sync_info_t { |
| 111 | int8_t transaction_id; | 120 | int8_t transaction_id; |
| @@ -173,6 +182,10 @@ typedef struct _split_shared_memory_t { | |||
| 173 | uint8_t current_st7565_state; | 182 | uint8_t current_st7565_state; |
| 174 | #endif // ST7565_ENABLE(OLED_ENABLE) && defined(SPLIT_ST7565_ENABLE) | 183 | #endif // ST7565_ENABLE(OLED_ENABLE) && defined(SPLIT_ST7565_ENABLE) |
| 175 | 184 | ||
| 185 | #if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) | ||
| 186 | split_slave_pointing_sync_t pointing; | ||
| 187 | #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) | ||
| 188 | |||
| 176 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) | 189 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) |
| 177 | rpc_sync_info_t rpc_info; | 190 | rpc_sync_info_t rpc_info; |
| 178 | uint8_t rpc_m2s_buffer[RPC_M2S_BUFFER_SIZE]; | 191 | uint8_t rpc_m2s_buffer[RPC_M2S_BUFFER_SIZE]; |
