transport.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. #pragma once
  17. #include <stdint.h>
  18. #include <stdbool.h>
  19. #include "progmem.h"
  20. #include "action_layer.h"
  21. #include "matrix.h"
  22. #include "transaction_id_define.h"
  23. #ifndef RPC_M2S_BUFFER_SIZE
  24. # define RPC_M2S_BUFFER_SIZE 32
  25. #endif // RPC_M2S_BUFFER_SIZE
  26. #ifndef RPC_S2M_BUFFER_SIZE
  27. # define RPC_S2M_BUFFER_SIZE 32
  28. #endif // RPC_S2M_BUFFER_SIZE
  29. void transport_master_init(void);
  30. void transport_slave_init(void);
  31. // returns false if valid data not received from slave
  32. bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]);
  33. void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]);
  34. bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, uint16_t initiator2target_length, void *target2initiator_buf, uint16_t target2initiator_length);
  35. #ifdef ENCODER_ENABLE
  36. # include "encoder.h"
  37. #endif // ENCODER_ENABLE
  38. #ifdef BACKLIGHT_ENABLE
  39. # include "backlight.h"
  40. #endif // BACKLIGHT_ENABLE
  41. #ifdef RGBLIGHT_ENABLE
  42. # include "rgblight.h"
  43. #endif // RGBLIGHT_ENABLE
  44. typedef struct _split_slave_matrix_sync_t {
  45. uint8_t checksum;
  46. matrix_row_t matrix[(MATRIX_ROWS) / 2];
  47. } split_slave_matrix_sync_t;
  48. #ifdef SPLIT_TRANSPORT_MIRROR
  49. typedef struct _split_master_matrix_sync_t {
  50. matrix_row_t matrix[(MATRIX_ROWS) / 2];
  51. } split_master_matrix_sync_t;
  52. #endif // SPLIT_TRANSPORT_MIRROR
  53. #ifdef ENCODER_ENABLE
  54. typedef struct _split_slave_encoder_sync_t {
  55. uint8_t checksum;
  56. encoder_events_t events;
  57. } split_slave_encoder_sync_t;
  58. #endif // ENCODER_ENABLE
  59. #if !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE)
  60. typedef struct _split_layers_sync_t {
  61. layer_state_t layer_state;
  62. layer_state_t default_layer_state;
  63. } split_layers_sync_t;
  64. #endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE)
  65. #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
  66. # include "led_matrix.h"
  67. typedef struct _led_matrix_sync_t {
  68. led_eeconfig_t led_matrix;
  69. bool led_suspend_state;
  70. } led_matrix_sync_t;
  71. #endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
  72. #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
  73. # include "rgb_matrix.h"
  74. typedef struct _rgb_matrix_sync_t {
  75. rgb_config_t rgb_matrix;
  76. bool rgb_suspend_state;
  77. } rgb_matrix_sync_t;
  78. #endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
  79. #ifdef SPLIT_MODS_ENABLE
  80. typedef struct _split_mods_sync_t {
  81. uint8_t real_mods;
  82. uint8_t weak_mods;
  83. # ifndef NO_ACTION_ONESHOT
  84. uint8_t oneshot_mods;
  85. uint8_t oneshot_locked_mods;
  86. # endif // NO_ACTION_ONESHOT
  87. } split_mods_sync_t;
  88. #endif // SPLIT_MODS_ENABLE
  89. #if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE)
  90. # include "pointing_device.h"
  91. typedef struct _split_slave_pointing_sync_t {
  92. uint8_t checksum;
  93. report_mouse_t report;
  94. uint16_t cpi;
  95. } split_slave_pointing_sync_t;
  96. #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE)
  97. #if defined(HAPTIC_ENABLE) && defined(SPLIT_HAPTIC_ENABLE)
  98. # include "haptic.h"
  99. typedef struct _split_slave_haptic_sync_t {
  100. haptic_config_t haptic_config;
  101. uint8_t haptic_play;
  102. } split_slave_haptic_sync_t;
  103. #endif // defined(HAPTIC_ENABLE) && defined(SPLIT_HAPTIC_ENABLE)
  104. #if defined(SPLIT_ACTIVITY_ENABLE)
  105. # include "keyboard.h"
  106. typedef struct _split_slave_activity_sync_t {
  107. uint32_t matrix_timestamp;
  108. uint32_t encoder_timestamp;
  109. uint32_t pointing_device_timestamp;
  110. } split_slave_activity_sync_t;
  111. #endif // defined(SPLIT_ACTIVITY_ENABLE)
  112. #if defined(SPLIT_TRANSACTION_RPC)
  113. typedef struct _rpc_sync_info_t {
  114. uint8_t checksum;
  115. struct {
  116. int8_t transaction_id;
  117. uint8_t m2s_length;
  118. uint8_t s2m_length;
  119. } payload;
  120. } rpc_sync_info_t;
  121. #endif // defined(SPLIT_TRANSACTION_RPC)
  122. #if defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE)
  123. # include "os_detection.h"
  124. #endif // defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE)
  125. typedef struct _split_shared_memory_t {
  126. #ifdef USE_I2C
  127. int8_t transaction_id;
  128. #endif // USE_I2C
  129. split_slave_matrix_sync_t smatrix;
  130. #ifdef SPLIT_TRANSPORT_MIRROR
  131. split_master_matrix_sync_t mmatrix;
  132. #endif // SPLIT_TRANSPORT_MIRROR
  133. #ifdef ENCODER_ENABLE
  134. split_slave_encoder_sync_t encoders;
  135. #endif // ENCODER_ENABLE
  136. #ifndef DISABLE_SYNC_TIMER
  137. uint32_t sync_timer;
  138. #endif // DISABLE_SYNC_TIMER
  139. #if !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE)
  140. split_layers_sync_t layers;
  141. #endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE)
  142. #ifdef SPLIT_LED_STATE_ENABLE
  143. uint8_t led_state;
  144. #endif // SPLIT_LED_STATE_ENABLE
  145. #ifdef SPLIT_MODS_ENABLE
  146. split_mods_sync_t mods;
  147. #endif // SPLIT_MODS_ENABLE
  148. #ifdef BACKLIGHT_ENABLE
  149. uint8_t backlight_level;
  150. #endif // BACKLIGHT_ENABLE
  151. #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
  152. rgblight_syncinfo_t rgblight_sync;
  153. #endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
  154. #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
  155. led_matrix_sync_t led_matrix_sync;
  156. #endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
  157. #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
  158. rgb_matrix_sync_t rgb_matrix_sync;
  159. #endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
  160. #if defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE)
  161. uint8_t current_wpm;
  162. #endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE)
  163. #if defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE)
  164. uint8_t current_oled_state;
  165. #endif // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE)
  166. #if defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE)
  167. uint8_t current_st7565_state;
  168. #endif // ST7565_ENABLE(OLED_ENABLE) && defined(SPLIT_ST7565_ENABLE)
  169. #if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE)
  170. split_slave_pointing_sync_t pointing;
  171. #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE)
  172. #if defined(SPLIT_WATCHDOG_ENABLE)
  173. bool watchdog_pinged;
  174. #endif // defined(SPLIT_WATCHDOG_ENABLE)
  175. #if defined(HAPTIC_ENABLE) && defined(SPLIT_HAPTIC_ENABLE)
  176. split_slave_haptic_sync_t haptic_sync;
  177. #endif // defined(HAPTIC_ENABLE)
  178. #if defined(SPLIT_ACTIVITY_ENABLE)
  179. split_slave_activity_sync_t activity_sync;
  180. #endif // defined(SPLIT_ACTIVITY_ENABLE)
  181. #if defined(SPLIT_TRANSACTION_RPC)
  182. rpc_sync_info_t rpc_info;
  183. uint8_t rpc_m2s_buffer[RPC_M2S_BUFFER_SIZE];
  184. uint8_t rpc_s2m_buffer[RPC_S2M_BUFFER_SIZE];
  185. #endif // defined(SPLIT_TRANSACTION_RPC)
  186. #if defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE)
  187. os_variant_t detected_os;
  188. #endif // defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE)
  189. } split_shared_memory_t;
  190. extern split_shared_memory_t *const split_shmem;