transport.h 6.3 KB

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