diff --git a/keyboards/bastardkb/charybdis/charybdis.c b/keyboards/bastardkb/charybdis/charybdis.c index f0f31a10d59..29603042b28 100644 --- a/keyboards/bastardkb/charybdis/charybdis.c +++ b/keyboards/bastardkb/charybdis/charybdis.c @@ -18,6 +18,8 @@ */ #include "charybdis.h" +#include "transactions.h" +#include #ifdef CONSOLE_ENABLE # include "print.h" @@ -339,8 +341,48 @@ void matrix_init_kb(void) { matrix_init_user(); } +# ifdef CHARYBDIS_CONFIG_SYNC +void charybdis_config_sync_handler(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) { + if (initiator2target_buffer_size == sizeof(g_charybdis_config)) { + memcpy(&g_charybdis_config, initiator2target_buffer, sizeof(g_charybdis_config)); + } +} +# endif + void keyboard_post_init_kb(void) { maybe_update_pointing_device_cpi(&g_charybdis_config); +# ifdef CHARYBDIS_CONFIG_SYNC + transaction_register_rpc(RPC_ID_KB_CONFIG_SYNC, charybdis_config_sync_handler); +# endif keyboard_post_init_user(); } + +# ifdef CHARYBDIS_CONFIG_SYNC +void housekeeping_task_kb(void) { + if (is_keyboard_master()) { + // Keep track of the last state, so that we can tell if we need to propagate to slave + static charybdis_config_t last_charybdis_config = {0}; + static uint32_t last_sync = 0; + bool needs_sync = false; + + // Check if the state values are different + if (memcmp(&g_charybdis_config, &last_charybdis_config, sizeof(g_charybdis_config))) { + needs_sync = true; + memcpy(&last_charybdis_config, &g_charybdis_config, sizeof(g_charybdis_config)); + } + // Send to slave every 500ms regardless of state change + if (timer_elapsed32(last_sync) > 500) { + needs_sync = true; + } + + // Perform the sync if requested + if (needs_sync) { + if (transaction_rpc_send(RPC_ID_KB_CONFIG_SYNC, sizeof(g_charybdis_config), &g_charybdis_config)) { + last_sync = timer_read32(); + } + } + } + // no need for user function, is called already +} +# endif // CHARYBDIS_CONFIG_SYNC #endif // POINTING_DEVICE_ENABLE diff --git a/keyboards/bastardkb/charybdis/post_config.h b/keyboards/bastardkb/charybdis/post_config.h index 540751f6c64..b769722b64e 100644 --- a/keyboards/bastardkb/charybdis/post_config.h +++ b/keyboards/bastardkb/charybdis/post_config.h @@ -20,6 +20,11 @@ #pragma once +// Enable syncing of charybdis config +#ifdef CHARYBDIS_CONFIG_SYNC +# define SPLIT_TRANSACTION_IDS_KB RPC_ID_KB_CONFIG_SYNC +#endif + /* Mouse config. */ #ifndef MOUSEKEY_MOVE_DELTA diff --git a/keyboards/bastardkb/charybdis/readme.md b/keyboards/bastardkb/charybdis/readme.md index 461f33117c5..d786abf36e3 100644 --- a/keyboards/bastardkb/charybdis/readme.md +++ b/keyboards/bastardkb/charybdis/readme.md @@ -176,3 +176,23 @@ To disable the custom keycodes, and reduce binary size, simply add a definition ```c #define NO_CHARYBDIS_KEYCODES ``` + +### Configuration Syncing + +If you want/need to enable syncing of the charybdis config, such as to read the sniping or drag scroll modes on the other half (such as for displaying the status via rgb matrix, or added on screens, or what not), you can enabled this. To do so, add this to your `config.h`: + +```c +#define CHARYBDIS_CONFIG_SYNC +``` + +Note that you will need to reflash both sides when enabling this. + +### Enable Large Mouse Reports + +By default, the X and Y motion for the pointing device/mouse reports is -127 to 127. You can definitely hit the limit for that with the sensors. You can enable support for -32767 to 32767 by adding this to your `config.h`: + +```c +#define MOUSE_EXTENDED_REPORT +``` + +Note that you will need to reflash both sides when enabling this.