transport.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. # define NUMBER_OF_ENCODERS (sizeof((pin_t[])ENCODERS_PAD_A) / sizeof(pin_t))
  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. uint8_t state[NUMBER_OF_ENCODERS];
  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. # endif // NO_ACTION_ONESHOT
  86. } split_mods_sync_t;
  87. #endif // SPLIT_MODS_ENABLE
  88. #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
  89. typedef struct _rpc_sync_info_t {
  90. int8_t transaction_id;
  91. uint8_t m2s_length;
  92. uint8_t s2m_length;
  93. } rpc_sync_info_t;
  94. #endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
  95. typedef struct _split_shared_memory_t {
  96. #ifdef USE_I2C
  97. int8_t transaction_id;
  98. #endif // USE_I2C
  99. split_slave_matrix_sync_t smatrix;
  100. #ifdef SPLIT_TRANSPORT_MIRROR
  101. split_master_matrix_sync_t mmatrix;
  102. #endif // SPLIT_TRANSPORT_MIRROR
  103. #ifdef ENCODER_ENABLE
  104. split_slave_encoder_sync_t encoders;
  105. #endif // ENCODER_ENABLE
  106. #ifndef DISABLE_SYNC_TIMER
  107. uint32_t sync_timer;
  108. #endif // DISABLE_SYNC_TIMER
  109. #if !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE)
  110. split_layers_sync_t layers;
  111. #endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE)
  112. #ifdef SPLIT_LED_STATE_ENABLE
  113. uint8_t led_state;
  114. #endif // SPLIT_LED_STATE_ENABLE
  115. #ifdef SPLIT_MODS_ENABLE
  116. split_mods_sync_t mods;
  117. #endif // SPLIT_MODS_ENABLE
  118. #ifdef BACKLIGHT_ENABLE
  119. uint8_t backlight_level;
  120. #endif // BACKLIGHT_ENABLE
  121. #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
  122. rgblight_syncinfo_t rgblight_sync;
  123. #endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
  124. #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
  125. led_matrix_sync_t led_matrix_sync;
  126. #endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
  127. #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
  128. rgb_matrix_sync_t rgb_matrix_sync;
  129. #endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
  130. #if defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE)
  131. uint8_t current_wpm;
  132. #endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE)
  133. #if defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE)
  134. uint8_t current_oled_state;
  135. #endif // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE)
  136. #if defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE)
  137. uint8_t current_st7565_state;
  138. #endif // ST7565_ENABLE(OLED_ENABLE) && defined(SPLIT_ST7565_ENABLE)
  139. #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
  140. rpc_sync_info_t rpc_info;
  141. uint8_t rpc_m2s_buffer[RPC_M2S_BUFFER_SIZE];
  142. uint8_t rpc_s2m_buffer[RPC_S2M_BUFFER_SIZE];
  143. #endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
  144. } split_shared_memory_t;
  145. extern split_shared_memory_t *const split_shmem;