diff options
author | Nick Brassel <nick@tzarc.org> | 2022-06-20 14:20:56 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-20 14:20:56 +1000 |
commit | aa06893b58ac3ed88e796968d237f60f4c156875 (patch) | |
tree | ad4b3a637b7bba88de772dd50150262d2992603e /keyboards/tzarc/djinn/djinn_split_sync.c | |
parent | ad2e85361128a2252798a7bb4c1cbc0bcd58e8ab (diff) | |
download | qmk_firmware-aa06893b58ac3ed88e796968d237f60f4c156875.tar.gz qmk_firmware-aa06893b58ac3ed88e796968d237f60f4c156875.zip |
Add Djinn. (#17382)
* Add Djinn.
* Review comments.
* Further cleanup.
Diffstat (limited to 'keyboards/tzarc/djinn/djinn_split_sync.c')
-rw-r--r-- | keyboards/tzarc/djinn/djinn_split_sync.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/keyboards/tzarc/djinn/djinn_split_sync.c b/keyboards/tzarc/djinn/djinn_split_sync.c new file mode 100644 index 0000000000..3c7a58d155 --- /dev/null +++ b/keyboards/tzarc/djinn/djinn_split_sync.c @@ -0,0 +1,58 @@ +// Copyright 2018-2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#include <string.h> +#include "quantum.h" +#include "transactions.h" +#include "split_util.h" +#include "djinn.h" + +kb_runtime_config kb_state; +uint32_t last_slave_sync_time = 0; + +void kb_state_update(void) { + if (is_keyboard_master()) { + // Modify allowed current limits + usbpd_update(); + + // Turn off the LCD if there's been no matrix activity + kb_state.lcd_power = (last_input_activity_elapsed() < LCD_ACTIVITY_TIMEOUT) ? 1 : 0; + } +} + +void kb_state_sync(void) { + if (!is_transport_connected()) return; + + 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 last_kb_state; + static uint32_t last_sync; + bool needs_sync = false; + + // Check if the state values are different + if (memcmp(&kb_state, &last_kb_state, sizeof(kb_runtime_config))) { + needs_sync = true; + memcpy(&last_kb_state, &kb_state, sizeof(kb_runtime_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_SYNC_STATE_KB, sizeof(kb_runtime_config), &kb_state)) { + last_sync = timer_read32(); + } else { + dprint("Failed to perform data transaction\n"); + } + } + } +} + +void kb_state_sync_slave(uint8_t m2s_size, const void* m2s_buffer, uint8_t s2m_size, void* s2m_buffer) { + if (m2s_size == sizeof(kb_runtime_config)) { + memcpy(&kb_state, m2s_buffer, sizeof(kb_runtime_config)); + last_slave_sync_time = timer_read32(); + } +} |