transport.h (7628B)
1 /* Copyright 2021 QMK 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16 17 #pragma once 18 19 #include <stdint.h> 20 #include <stdbool.h> 21 22 #include "progmem.h" 23 #include "action_layer.h" 24 #include "matrix.h" 25 26 #ifndef RPC_M2S_BUFFER_SIZE 27 # define RPC_M2S_BUFFER_SIZE 32 28 #endif // RPC_M2S_BUFFER_SIZE 29 30 #ifndef RPC_S2M_BUFFER_SIZE 31 # define RPC_S2M_BUFFER_SIZE 32 32 #endif // RPC_S2M_BUFFER_SIZE 33 34 void transport_master_init(void); 35 void transport_slave_init(void); 36 37 // returns false if valid data not received from slave 38 bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]); 39 void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]); 40 41 bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, uint16_t initiator2target_length, void *target2initiator_buf, uint16_t target2initiator_length); 42 43 #ifdef ENCODER_ENABLE 44 # include "encoder.h" 45 #endif // ENCODER_ENABLE 46 47 #ifdef BACKLIGHT_ENABLE 48 # include "backlight.h" 49 #endif // BACKLIGHT_ENABLE 50 51 #ifdef RGBLIGHT_ENABLE 52 # include "rgblight.h" 53 #endif // RGBLIGHT_ENABLE 54 55 typedef struct _split_slave_matrix_sync_t { 56 uint8_t checksum; 57 matrix_row_t matrix[(MATRIX_ROWS) / 2]; 58 } split_slave_matrix_sync_t; 59 60 #ifdef SPLIT_TRANSPORT_MIRROR 61 typedef struct _split_master_matrix_sync_t { 62 matrix_row_t matrix[(MATRIX_ROWS) / 2]; 63 } split_master_matrix_sync_t; 64 #endif // SPLIT_TRANSPORT_MIRROR 65 66 #ifdef ENCODER_ENABLE 67 typedef struct _split_slave_encoder_sync_t { 68 uint8_t checksum; 69 encoder_events_t events; 70 } split_slave_encoder_sync_t; 71 #endif // ENCODER_ENABLE 72 73 #if !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) 74 typedef struct _split_layers_sync_t { 75 layer_state_t layer_state; 76 layer_state_t default_layer_state; 77 } split_layers_sync_t; 78 #endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) 79 80 #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) 81 # include "led_matrix.h" 82 83 typedef struct _led_matrix_sync_t { 84 led_eeconfig_t led_matrix; 85 bool led_suspend_state; 86 } led_matrix_sync_t; 87 #endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) 88 89 #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) 90 # include "rgb_matrix.h" 91 92 typedef struct _rgb_matrix_sync_t { 93 rgb_config_t rgb_matrix; 94 bool rgb_suspend_state; 95 } rgb_matrix_sync_t; 96 #endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) 97 98 #ifdef SPLIT_MODS_ENABLE 99 typedef struct _split_mods_sync_t { 100 uint8_t real_mods; 101 uint8_t weak_mods; 102 # ifndef NO_ACTION_ONESHOT 103 uint8_t oneshot_mods; 104 uint8_t oneshot_locked_mods; 105 # endif // NO_ACTION_ONESHOT 106 } split_mods_sync_t; 107 #endif // SPLIT_MODS_ENABLE 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 118 #if defined(HAPTIC_ENABLE) && defined(SPLIT_HAPTIC_ENABLE) 119 # include "haptic.h" 120 typedef struct _split_slave_haptic_sync_t { 121 haptic_config_t haptic_config; 122 uint8_t haptic_play; 123 } split_slave_haptic_sync_t; 124 #endif // defined(HAPTIC_ENABLE) && defined(SPLIT_HAPTIC_ENABLE) 125 126 #if defined(SPLIT_ACTIVITY_ENABLE) 127 # include "keyboard.h" 128 typedef struct _split_slave_activity_sync_t { 129 uint32_t matrix_timestamp; 130 uint32_t encoder_timestamp; 131 uint32_t pointing_device_timestamp; 132 } split_slave_activity_sync_t; 133 #endif // defined(SPLIT_ACTIVITY_ENABLE) 134 135 #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) 136 typedef struct _rpc_sync_info_t { 137 uint8_t checksum; 138 struct { 139 int8_t transaction_id; 140 uint8_t m2s_length; 141 uint8_t s2m_length; 142 } payload; 143 } rpc_sync_info_t; 144 #endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) 145 146 #if defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) 147 # include "os_detection.h" 148 #endif // defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) 149 150 typedef struct _split_shared_memory_t { 151 #ifdef USE_I2C 152 int8_t transaction_id; 153 #endif // USE_I2C 154 155 split_slave_matrix_sync_t smatrix; 156 157 #ifdef SPLIT_TRANSPORT_MIRROR 158 split_master_matrix_sync_t mmatrix; 159 #endif // SPLIT_TRANSPORT_MIRROR 160 161 #ifdef ENCODER_ENABLE 162 split_slave_encoder_sync_t encoders; 163 #endif // ENCODER_ENABLE 164 165 #ifndef DISABLE_SYNC_TIMER 166 uint32_t sync_timer; 167 #endif // DISABLE_SYNC_TIMER 168 169 #if !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) 170 split_layers_sync_t layers; 171 #endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) 172 173 #ifdef SPLIT_LED_STATE_ENABLE 174 uint8_t led_state; 175 #endif // SPLIT_LED_STATE_ENABLE 176 177 #ifdef SPLIT_MODS_ENABLE 178 split_mods_sync_t mods; 179 #endif // SPLIT_MODS_ENABLE 180 181 #ifdef BACKLIGHT_ENABLE 182 uint8_t backlight_level; 183 #endif // BACKLIGHT_ENABLE 184 185 #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) 186 rgblight_syncinfo_t rgblight_sync; 187 #endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) 188 189 #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) 190 led_matrix_sync_t led_matrix_sync; 191 #endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) 192 193 #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) 194 rgb_matrix_sync_t rgb_matrix_sync; 195 #endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) 196 197 #if defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) 198 uint8_t current_wpm; 199 #endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) 200 201 #if defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) 202 uint8_t current_oled_state; 203 #endif // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) 204 205 #if defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) 206 uint8_t current_st7565_state; 207 #endif // ST7565_ENABLE(OLED_ENABLE) && defined(SPLIT_ST7565_ENABLE) 208 209 #if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) 210 split_slave_pointing_sync_t pointing; 211 #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) 212 213 #if defined(SPLIT_WATCHDOG_ENABLE) 214 bool watchdog_pinged; 215 #endif // defined(SPLIT_WATCHDOG_ENABLE) 216 217 #if defined(HAPTIC_ENABLE) && defined(SPLIT_HAPTIC_ENABLE) 218 split_slave_haptic_sync_t haptic_sync; 219 #endif // defined(HAPTIC_ENABLE) 220 221 #if defined(SPLIT_ACTIVITY_ENABLE) 222 split_slave_activity_sync_t activity_sync; 223 #endif // defined(SPLIT_ACTIVITY_ENABLE) 224 225 #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) 226 rpc_sync_info_t rpc_info; 227 uint8_t rpc_m2s_buffer[RPC_M2S_BUFFER_SIZE]; 228 uint8_t rpc_s2m_buffer[RPC_S2M_BUFFER_SIZE]; 229 #endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) 230 231 #if defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) 232 os_variant_t detected_os; 233 #endif // defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) 234 } split_shared_memory_t; 235 236 extern split_shared_memory_t *const split_shmem;