summaryrefslogtreecommitdiff
path: root/keyboards/handwired/tractyl_manuform/tm_sync.c
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2021-08-21 13:34:44 -0700
committerGitHub <noreply@github.com>2021-08-21 13:34:44 -0700
commit58a5030661b57f1dd05693053df2eddadc285f64 (patch)
tree025a7a2d0dc6643ce806b72798c92139eafb4ca6 /keyboards/handwired/tractyl_manuform/tm_sync.c
parentda1c011afc67dab0049b30a4c021dc38a36cb9aa (diff)
downloadqmk_firmware-58a5030661b57f1dd05693053df2eddadc285f64.tar.gz
qmk_firmware-58a5030661b57f1dd05693053df2eddadc285f64.zip
[Keymap] Drashna's Improve OLEDs and custom Split code (#14063)
* Fill the oleds with right mods * Enable double mods on x32 oleds * Disable forced NKRO * Make oleds fancy only on good MCUs * Overhaul oled display * Further enhance oled, with kitty! * Final oled form * Not working transport * Transport id of woring * Add acceleration * fix button placement for accel macro * Fix accelartion location and behavior * Remove OLED sync code * Fix alignment issue * Remove audio hack * Fix up zima keymap * Add matrix slave scan function and cleanup drashna.h * Clean up user space * Allow userspace sync to be disable-able * Fix weird issue with audio * Fix alignment issue with user split sync * Disable second rgb matrix task * Disable additional animations * Change dynamic keymap settings * Hacky fix for borked corne * Add Blackpill (F411) support to tractyl manuform * remove manual via eeprom reset * Remove all references to rgblight twinkle * Fix issues with config processing
Diffstat (limited to 'keyboards/handwired/tractyl_manuform/tm_sync.c')
-rw-r--r--keyboards/handwired/tractyl_manuform/tm_sync.c129
1 files changed, 58 insertions, 71 deletions
diff --git a/keyboards/handwired/tractyl_manuform/tm_sync.c b/keyboards/handwired/tractyl_manuform/tm_sync.c
index 0088fcc4f6..2a8847b3ef 100644
--- a/keyboards/handwired/tractyl_manuform/tm_sync.c
+++ b/keyboards/handwired/tractyl_manuform/tm_sync.c
@@ -14,86 +14,59 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifdef SPLIT_TRANSACTION_IDS_KB
-
-# include "tractyl_manuform.h"
-# include "transactions.h"
-# include <string.h>
-# include "drivers/sensors/pmw3360.h"
-
-kb_runtime_config_t kb_state;
-kb_slave_data_t kb_slave;
-
-void slave_state_sync(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) {
- if (target2initiator_buffer_size == sizeof(kb_slave)) {
- memcpy(target2initiator_buffer, &kb_slave, sizeof(kb_slave));
- if (kb_slave.mouse_x > 127) {
- kb_slave.mouse_x -= 127;
- } else if (kb_slave.mouse_x < -127) {
- kb_slave.mouse_x += 127;
- } else {
- kb_slave.mouse_x = 0;
- }
+#include "tractyl_manuform.h"
+#include "transactions.h"
+#include <string.h>
+#include "drivers/sensors/pmw3360.h"
- if (kb_slave.mouse_y > 127) {
- kb_slave.mouse_y -= 127;
- } else if (kb_slave.mouse_y < -127) {
- kb_slave.mouse_y += 127;
- } else {
- kb_slave.mouse_y = 0;
- }
+kb_config_data_t kb_config;
+kb_pointer_data_t kb_pointer;
+
+void kb_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(kb_config)) {
+ memcpy(&kb_config, initiator2target_buffer, sizeof(kb_config));
}
}
-
-void pointer_state_sync(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) {
- if (initiator2target_buffer_size == sizeof(kb_state)) {
- memcpy(&kb_state, initiator2target_buffer, sizeof(kb_state));
+void kb_pointer_sync_handler(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) {
+ if (target2initiator_buffer_size == sizeof(kb_pointer)) {
+ memcpy(target2initiator_buffer, &kb_pointer, sizeof(kb_pointer));
}
}
+void keyboard_pre_init_sync(void) {
+ memset(&kb_config, 0, sizeof(kb_config));
+ memset(&kb_pointer, 0, sizeof(kb_pointer));
+}
+
void keyboard_post_init_kb(void) {
// Register keyboard state sync split transaction
- transaction_register_rpc(RPC_ID_STATE_SYNC, pointer_state_sync);
- transaction_register_rpc(RPC_ID_SLAVE_STATE, slave_state_sync);
+ transaction_register_rpc(RPC_ID_KB_CONFIG_SYNC, kb_config_sync_handler);
+ transaction_register_rpc(RPC_ID_POINTER_STATE_SYNC, kb_pointer_sync_handler);
keyboard_post_init_user();
}
-void kb_state_update(void) {
-# ifdef POINTING_DEVICE_ENABLE
+void kb_config_update(void) {
if (is_keyboard_master()) {
static uint16_t cpi = 0;
- if (cpi != kb_state.device_cpi) {
- cpi = kb_state.device_cpi;
+ if (cpi != kb_config.device_cpi) {
+ cpi = kb_config.device_cpi;
pmw_set_cpi(cpi);
}
}
-# endif
}
-void kb_post_state_update(void) {
-# ifdef POINTING_DEVICE_ENABLE
- if (is_keyboard_master() && is_keyboard_left()) {
- report_mouse_t temp_report = pointing_device_get_report();
- temp_report.x = kb_slave.mouse_x;
- temp_report.y = kb_slave.mouse_y;
- pointing_device_set_report(temp_report);
- }
-# endif
-}
-
-void kb_state_sync(void) {
+void kb_config_sync(void) {
if (is_keyboard_master()) {
// Keep track of the last state, so that we can tell if we need to propagate to slave
- static kb_runtime_config_t last_kb_state;
- static uint32_t last_sync = 0;
- static uint32_t mouse_sync = 0;
- bool needs_sync = false;
+ static kb_config_data_t last_kb_config;
+ static uint32_t last_sync = 0;
+ bool needs_sync = false;
// Check if the state values are different
- if (memcmp(&kb_state, &last_kb_state, sizeof(kb_runtime_config_t))) {
+ if (memcmp(&kb_config, &last_kb_config, sizeof(kb_config))) {
needs_sync = true;
- memcpy(&last_kb_state, &kb_state, sizeof(kb_runtime_config_t));
+ memcpy(&last_kb_config, &kb_config, sizeof(kb_config));
}
// Send to slave every 500ms regardless of state change
if (timer_elapsed32(last_sync) > 500) {
@@ -102,31 +75,45 @@ void kb_state_sync(void) {
// Perform the sync if requested
if (needs_sync) {
- if (transaction_rpc_send(RPC_ID_STATE_SYNC, sizeof(kb_runtime_config_t), &kb_state)) {
+ if (transaction_rpc_send(RPC_ID_KB_CONFIG_SYNC, sizeof(kb_config), &kb_config)) {
last_sync = timer_read32();
}
}
+ }
+}
- if (is_keyboard_left()) {
- if (timer_elapsed32(mouse_sync) >= 5) {
- // always sync slave data, since it may contain device reports.
- if (transaction_rpc_recv(RPC_ID_SLAVE_STATE, sizeof(kb_slave_data_t), &kb_slave)) {
- if (kb_slave.mouse_x >= -127 && kb_slave.mouse_x <= 127 && kb_slave.mouse_y >= -127 && kb_slave.mouse_y <= 127) {
- mouse_sync = timer_read32();
- }
- }
+void kb_pointer_sync(void) {
+ if (is_keyboard_master() && is_keyboard_left()) {
+ // Keep track of the last state, so that we can tell if we need to propagate to slave
+ static uint32_t last_sync = 0;
+
+ // Perform the sync if requested
+ if (timer_elapsed32(last_sync) >= 5) {
+ if (transaction_rpc_recv(RPC_ID_POINTER_STATE_SYNC, sizeof(kb_pointer), &kb_pointer)) {
+ last_sync = timer_read32();
}
}
}
}
void housekeeping_task_kb(void) {
- // Update kb_state so we can send to slave
- kb_state_update();
-
+ // Update kb_config so we can send to slave
+ kb_config_update();
// Data sync from master to slave
- kb_state_sync();
+ kb_config_sync();
+ kb_pointer_sync();
+}
+
+void kb_pointer_sync_send(int8_t x, int8_t y) {
+ kb_pointer.mouse_x = x;
+ kb_pointer.mouse_y = y;
+}
- kb_post_state_update();
+kb_pointer_data_t kb_pointer_sync_get(void) { return (kb_pointer_data_t){.mouse_x = kb_pointer.mouse_x, .mouse_y = kb_pointer.mouse_y}; }
+
+void trackball_set_cpi(uint16_t cpi) {
+ kb_config.device_cpi = cpi;
+ if (!is_keyboard_left()) {
+ pmw_set_cpi(cpi);
+ }
}
-#endif