diff options
author | zvecr <git@zvecr.com> | 2022-02-25 23:45:40 +0000 |
---|---|---|
committer | zvecr <git@zvecr.com> | 2022-02-25 23:45:40 +0000 |
commit | e7931289918221081cbe2a7ea5df27a5d86324db (patch) | |
tree | 0b06145520f8aaf5ff5cb928aa5176fc2dd23619 /quantum/split_common | |
parent | c0ee3d2c79388187883b1b1b1d1a0b6842acf741 (diff) | |
parent | cf31355f08dca311a013168eb3eb995e2fc6a3d1 (diff) |
Merge remote-tracking branch 'origin/develop'
Diffstat (limited to 'quantum/split_common')
-rw-r--r-- | quantum/split_common/post_config.h | 2 | ||||
-rw-r--r-- | quantum/split_common/split_util.c | 20 | ||||
-rw-r--r-- | quantum/split_common/split_util.h | 1 | ||||
-rw-r--r-- | quantum/split_common/transaction_id_define.h | 40 | ||||
-rw-r--r-- | quantum/split_common/transactions.c | 176 | ||||
-rw-r--r-- | quantum/split_common/transactions.h | 1 | ||||
-rw-r--r-- | quantum/split_common/transport.c | 32 | ||||
-rw-r--r-- | quantum/split_common/transport.h | 69 |
8 files changed, 231 insertions, 110 deletions
diff --git a/quantum/split_common/post_config.h b/quantum/split_common/post_config.h index a4c0a1956b..8f79beb6ed 100644 --- a/quantum/split_common/post_config.h +++ b/quantum/split_common/post_config.h @@ -5,6 +5,6 @@ # endif # ifndef F_SCL -# define F_SCL 100000UL // SCL frequency +# define F_SCL 100000UL // SCL frequency # endif #endif diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c index 35f0a9d181..7d50adf758 100644 --- a/quantum/split_common/split_util.c +++ b/quantum/split_common/split_util.c @@ -43,14 +43,14 @@ // Set to 0 to disable the disconnection check altogether. #ifndef SPLIT_MAX_CONNECTION_ERRORS # define SPLIT_MAX_CONNECTION_ERRORS 10 -#endif // SPLIT_MAX_CONNECTION_ERRORS +#endif // SPLIT_MAX_CONNECTION_ERRORS // How long (in milliseconds) to block all connection attempts after the communication has been flagged as disconnected. // One communication attempt will be allowed everytime this amount of time has passed since the last attempt. If that attempt succeeds, the communication is seen as working again. // Set to 0 to disable communication throttling while disconnected #ifndef SPLIT_CONNECTION_CHECK_TIMEOUT # define SPLIT_CONNECTION_CHECK_TIMEOUT 500 -#endif // SPLIT_CONNECTION_CHECK_TIMEOUT +#endif // SPLIT_CONNECTION_CHECK_TIMEOUT static uint8_t connection_errors = 0; @@ -68,7 +68,9 @@ static bool usbIsActive(void) { return false; } #else -static inline bool usbIsActive(void) { return usb_vbus_state(); } +static inline bool usbIsActive(void) { + return usb_vbus_state(); +} #endif #ifdef SPLIT_HAND_MATRIX_GRID @@ -83,7 +85,7 @@ static uint8_t peek_matrix_intersection(pin_t out_pin, pin_t in_pin) { uint8_t pin_state = readPin(in_pin); // Set out_pin to a setting that is less susceptible to noise. setPinInputHigh(out_pin); - matrix_io_delay(); // Wait for the pull-up to go HIGH. + matrix_io_delay(); // Wait for the pull-up to go HIGH. return pin_state; } #endif @@ -158,7 +160,9 @@ void split_post_init(void) { } } -bool is_transport_connected(void) { return connection_errors < SPLIT_MAX_CONNECTION_ERRORS; } +bool is_transport_connected(void) { + return connection_errors < SPLIT_MAX_CONNECTION_ERRORS; +} bool transport_master_if_connected(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { #if SPLIT_MAX_CONNECTION_ERRORS > 0 && SPLIT_CONNECTION_CHECK_TIMEOUT > 0 @@ -169,7 +173,7 @@ bool transport_master_if_connected(matrix_row_t master_matrix[], matrix_row_t sl if (is_disconnected && timer_elapsed(connection_check_timer) < SPLIT_CONNECTION_CHECK_TIMEOUT) { return false; } -#endif // SPLIT_MAX_CONNECTION_ERRORS > 0 && SPLIT_CONNECTION_CHECK_TIMEOUT > 0 +#endif // SPLIT_MAX_CONNECTION_ERRORS > 0 && SPLIT_CONNECTION_CHECK_TIMEOUT > 0 __attribute__((unused)) bool okay = transport_master(master_matrix, slave_matrix); #if SPLIT_MAX_CONNECTION_ERRORS > 0 @@ -186,10 +190,10 @@ bool transport_master_if_connected(matrix_row_t master_matrix[], matrix_row_t sl return connected; } else if (is_disconnected) { dprintln("Target connected"); -# endif // SPLIT_CONNECTION_CHECK_TIMEOUT > 0 +# endif // SPLIT_CONNECTION_CHECK_TIMEOUT > 0 } connection_errors = 0; -#endif // SPLIT_MAX_CONNECTION_ERRORS > 0 +#endif // SPLIT_MAX_CONNECTION_ERRORS > 0 return true; } diff --git a/quantum/split_common/split_util.h b/quantum/split_common/split_util.h index ef72043bb7..c7eabea233 100644 --- a/quantum/split_common/split_util.h +++ b/quantum/split_common/split_util.h @@ -2,7 +2,6 @@ #include <stdbool.h> #include <stdint.h> -#include <stdio.h> #include <stdlib.h> #include "matrix.h" diff --git a/quantum/split_common/transaction_id_define.h b/quantum/split_common/transaction_id_define.h index 535bc21aea..761a8884f4 100644 --- a/quantum/split_common/transaction_id_define.h +++ b/quantum/split_common/transaction_id_define.h @@ -19,81 +19,87 @@ enum serial_transaction_id { #ifdef USE_I2C I2C_EXECUTE_CALLBACK, -#endif // USE_I2C +#endif // USE_I2C GET_SLAVE_MATRIX_CHECKSUM, GET_SLAVE_MATRIX_DATA, #ifdef SPLIT_TRANSPORT_MIRROR PUT_MASTER_MATRIX, -#endif // SPLIT_TRANSPORT_MIRROR +#endif // SPLIT_TRANSPORT_MIRROR #ifdef ENCODER_ENABLE GET_ENCODERS_CHECKSUM, GET_ENCODERS_DATA, -#endif // ENCODER_ENABLE +#endif // ENCODER_ENABLE #ifndef DISABLE_SYNC_TIMER PUT_SYNC_TIMER, -#endif // DISABLE_SYNC_TIMER +#endif // DISABLE_SYNC_TIMER #if !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) PUT_LAYER_STATE, PUT_DEFAULT_LAYER_STATE, -#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) +#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) #ifdef SPLIT_LED_STATE_ENABLE PUT_LED_STATE, -#endif // SPLIT_LED_STATE_ENABLE +#endif // SPLIT_LED_STATE_ENABLE #ifdef SPLIT_MODS_ENABLE PUT_MODS, -#endif // SPLIT_MODS_ENABLE +#endif // SPLIT_MODS_ENABLE #ifdef BACKLIGHT_ENABLE PUT_BACKLIGHT, -#endif // BACKLIGHT_ENABLE +#endif // BACKLIGHT_ENABLE #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) PUT_RGBLIGHT, -#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) +#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) PUT_LED_MATRIX, -#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) +#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) PUT_RGB_MATRIX, -#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) +#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) #if defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) PUT_WPM, -#endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) +#endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) #if defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) PUT_OLED, -#endif // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) +#endif // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) #if defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) PUT_ST7565, -#endif // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) +#endif // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) + +#if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) + GET_POINTING_CHECKSUM, + GET_POINTING_DATA, + PUT_POINTING_CPI, +#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) PUT_RPC_INFO, PUT_RPC_REQ_DATA, EXECUTE_RPC, GET_RPC_RESP_DATA, -#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) +#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) // keyboard-specific #ifdef SPLIT_TRANSACTION_IDS_KB SPLIT_TRANSACTION_IDS_KB, -#endif // SPLIT_TRANSACTION_IDS_KB +#endif // SPLIT_TRANSACTION_IDS_KB // user/keymap-specific #ifdef SPLIT_TRANSACTION_IDS_USER SPLIT_TRANSACTION_IDS_USER, -#endif // SPLIT_TRANSACTION_IDS_USER +#endif // SPLIT_TRANSACTION_IDS_USER NUM_TOTAL_TRANSACTIONS }; diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index 3ff87710e7..cffbccaeee 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c @@ -30,16 +30,16 @@ #ifndef FORCED_SYNC_THROTTLE_MS # define FORCED_SYNC_THROTTLE_MS 100 -#endif // FORCED_SYNC_THROTTLE_MS +#endif // FORCED_SYNC_THROTTLE_MS #define sizeof_member(type, member) sizeof(((type *)NULL)->member) #define trans_initiator2target_initializer_cb(member, cb) \ - { &dummy, sizeof_member(split_shared_memory_t, member), offsetof(split_shared_memory_t, member), 0, 0, cb } + { sizeof_member(split_shared_memory_t, member), offsetof(split_shared_memory_t, member), 0, 0, cb } #define trans_initiator2target_initializer(member) trans_initiator2target_initializer_cb(member, NULL) #define trans_target2initiator_initializer_cb(member, cb) \ - { &dummy, 0, 0, sizeof_member(split_shared_memory_t, member), offsetof(split_shared_memory_t, member), cb } + { 0, 0, sizeof_member(split_shared_memory_t, member), offsetof(split_shared_memory_t, member), cb } #define trans_target2initiator_initializer(member) trans_target2initiator_initializer_cb(member, NULL) #define transport_write(id, data, length) transport_execute_transaction(id, data, length, NULL, 0) @@ -49,7 +49,7 @@ // Forward-declare the RPC callback handlers void slave_rpc_info_callback(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer); void slave_rpc_exec_callback(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer); -#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) +#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) //////////////////////////////////////////////////// // Helpers @@ -63,7 +63,9 @@ static bool transaction_handler_master(matrix_row_t master_matrix[], matrix_row_ } } bool this_okay = true; - ATOMIC_BLOCK_FORCEON { this_okay = handler(master_matrix, slave_matrix); }; + ATOMIC_BLOCK_FORCEON { + this_okay = handler(master_matrix, slave_matrix); + }; if (this_okay) return true; } dprintf("Failed to execute %s\n", prefix); @@ -75,9 +77,11 @@ static bool transaction_handler_master(matrix_row_t master_matrix[], matrix_row_ if (!transaction_handler_master(master_matrix, slave_matrix, #prefix, &prefix##_handlers_master)) return false; \ } while (0) -#define TRANSACTION_HANDLER_SLAVE(prefix) \ - do { \ - ATOMIC_BLOCK_FORCEON { prefix##_handlers_slave(master_matrix, slave_matrix); }; \ +#define TRANSACTION_HANDLER_SLAVE(prefix) \ + do { \ + ATOMIC_BLOCK_FORCEON { \ + prefix##_handlers_slave(master_matrix, slave_matrix); \ + }; \ } while (0) inline static bool read_if_checksum_mismatch(int8_t trans_id_checksum, int8_t trans_id_retrieve, uint32_t *last_update, void *destination, const void *equiv_shmem, size_t length) { @@ -116,8 +120,8 @@ inline static bool send_if_data_mismatch(int8_t trans_id, uint32_t *last_update, static bool slave_matrix_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { static uint32_t last_update = 0; - static matrix_row_t last_matrix[(MATRIX_ROWS) / 2] = {0}; // last successfully-read matrix, so we can replicate if there are checksum errors - matrix_row_t temp_matrix[(MATRIX_ROWS) / 2]; // holding area while we test whether or not checksum is correct + static matrix_row_t last_matrix[(MATRIX_ROWS) / 2] = {0}; // last successfully-read matrix, so we can replicate if there are checksum errors + matrix_row_t temp_matrix[(MATRIX_ROWS) / 2]; // holding area while we test whether or not checksum is correct bool okay = read_if_checksum_mismatch(GET_SLAVE_MATRIX_CHECKSUM, GET_SLAVE_MATRIX_DATA, &last_update, temp_matrix, split_shmem->smatrix.matrix, sizeof(split_shmem->smatrix.matrix)); if (okay) { @@ -161,13 +165,13 @@ static void master_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_ro # define TRANSACTIONS_MASTER_MATRIX_SLAVE() TRANSACTION_HANDLER_SLAVE(master_matrix) # define TRANSACTIONS_MASTER_MATRIX_REGISTRATIONS [PUT_MASTER_MATRIX] = trans_initiator2target_initializer(mmatrix.matrix), -#else // SPLIT_TRANSPORT_MIRROR +#else // SPLIT_TRANSPORT_MIRROR # define TRANSACTIONS_MASTER_MATRIX_MASTER() # define TRANSACTIONS_MASTER_MATRIX_SLAVE() # define TRANSACTIONS_MASTER_MATRIX_REGISTRATIONS -#endif // SPLIT_TRANSPORT_MIRROR +#endif // SPLIT_TRANSPORT_MIRROR //////////////////////////////////////////////////// // Encoders @@ -200,13 +204,13 @@ static void encoder_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sl [GET_ENCODERS_DATA] = trans_target2initiator_initializer(encoders.state), // clang-format on -#else // ENCODER_ENABLE +#else // ENCODER_ENABLE # define TRANSACTIONS_ENCODERS_MASTER() # define TRANSACTIONS_ENCODERS_SLAVE() # define TRANSACTIONS_ENCODERS_REGISTRATIONS -#endif // ENCODER_ENABLE +#endif // ENCODER_ENABLE //////////////////////////////////////////////////// // Sync timer @@ -239,13 +243,13 @@ static void sync_timer_handlers_slave(matrix_row_t master_matrix[], matrix_row_t # define TRANSACTIONS_SYNC_TIMER_SLAVE() TRANSACTION_HANDLER_SLAVE(sync_timer) # define TRANSACTIONS_SYNC_TIMER_REGISTRATIONS [PUT_SYNC_TIMER] = trans_initiator2target_initializer(sync_timer), -#else // DISABLE_SYNC_TIMER +#else // DISABLE_SYNC_TIMER # define TRANSACTIONS_SYNC_TIMER_MASTER() # define TRANSACTIONS_SYNC_TIMER_SLAVE() # define TRANSACTIONS_SYNC_TIMER_REGISTRATIONS -#endif // DISABLE_SYNC_TIMER +#endif // DISABLE_SYNC_TIMER //////////////////////////////////////////////////// // Layer state @@ -276,13 +280,13 @@ static void layer_state_handlers_slave(matrix_row_t master_matrix[], matrix_row_ [PUT_DEFAULT_LAYER_STATE] = trans_initiator2target_initializer(layers.default_layer_state), // clang-format on -#else // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) +#else // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) # define TRANSACTIONS_LAYER_STATE_MASTER() # define TRANSACTIONS_LAYER_STATE_SLAVE() # define TRANSACTIONS_LAYER_STATE_REGISTRATIONS -#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) +#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) //////////////////////////////////////////////////// // LED state @@ -304,13 +308,13 @@ static void led_state_handlers_slave(matrix_row_t master_matrix[], matrix_row_t # define TRANSACTIONS_LED_STATE_SLAVE() TRANSACTION_HANDLER_SLAVE(led_state) # define TRANSACTIONS_LED_STATE_REGISTRATIONS [PUT_LED_STATE] = trans_initiator2target_initializer(led_state), -#else // SPLIT_LED_STATE_ENABLE +#else // SPLIT_LED_STATE_ENABLE # define TRANSACTIONS_LED_STATE_MASTER() # define TRANSACTIONS_LED_STATE_SLAVE() # define TRANSACTIONS_LED_STATE_REGISTRATIONS -#endif // SPLIT_LED_STATE_ENABLE +#endif // SPLIT_LED_STATE_ENABLE //////////////////////////////////////////////////// // Mods @@ -336,7 +340,7 @@ static bool mods_handlers_master(matrix_row_t master_matrix[], matrix_row_t slav if (!mods_need_sync && new_mods.oneshot_mods != split_shmem->mods.oneshot_mods) { mods_need_sync = true; } -# endif // NO_ACTION_ONESHOT +# endif // NO_ACTION_ONESHOT bool okay = true; if (mods_need_sync) { @@ -361,13 +365,13 @@ static void mods_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave # define TRANSACTIONS_MODS_SLAVE() TRANSACTION_HANDLER_SLAVE(mods) # define TRANSACTIONS_MODS_REGISTRATIONS [PUT_MODS] = trans_initiator2target_initializer(mods), -#else // SPLIT_MODS_ENABLE +#else // SPLIT_MODS_ENABLE # define TRANSACTIONS_MODS_MASTER() # define TRANSACTIONS_MODS_SLAVE() # define TRANSACTIONS_MODS_REGISTRATIONS -#endif // SPLIT_MODS_ENABLE +#endif // SPLIT_MODS_ENABLE //////////////////////////////////////////////////// // Backlight @@ -380,19 +384,21 @@ static bool backlight_handlers_master(matrix_row_t master_matrix[], matrix_row_t return send_if_condition(PUT_BACKLIGHT, &last_update, (level != split_shmem->backlight_level), &level, sizeof(level)); } -static void backlight_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { backlight_set(split_shmem->backlight_level); } +static void backlight_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + backlight_set(split_shmem->backlight_level); +} # define TRANSACTIONS_BACKLIGHT_MASTER() TRANSACTION_HANDLER_MASTER(backlight) # define TRANSACTIONS_BACKLIGHT_SLAVE() TRANSACTION_HANDLER_SLAVE(backlight) # define TRANSACTIONS_BACKLIGHT_REGISTRATIONS [PUT_BACKLIGHT] = trans_initiator2target_initializer(backlight_level), -#else // BACKLIGHT_ENABLE +#else // BACKLIGHT_ENABLE # define TRANSACTIONS_BACKLIGHT_MASTER() # define TRANSACTIONS_BACKLIGHT_SLAVE() # define TRANSACTIONS_BACKLIGHT_REGISTRATIONS -#endif // BACKLIGHT_ENABLE +#endif // BACKLIGHT_ENABLE //////////////////////////////////////////////////// // RGBLIGHT @@ -423,13 +429,13 @@ static void rgblight_handlers_slave(matrix_row_t master_matrix[], matrix_row_t s # define TRANSACTIONS_RGBLIGHT_SLAVE() TRANSACTION_HANDLER_SLAVE(rgblight) # define TRANSACTIONS_RGBLIGHT_REGISTRATIONS [PUT_RGBLIGHT] = trans_initiator2target_initializer(rgblight_sync), -#else // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) +#else // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) # define TRANSACTIONS_RGBLIGHT_MASTER() # define TRANSACTIONS_RGBLIGHT_SLAVE() # define TRANSACTIONS_RGBLIGHT_REGISTRATIONS -#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) +#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) //////////////////////////////////////////////////// // LED Matrix @@ -453,13 +459,13 @@ static void led_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_row_t # define TRANSACTIONS_LED_MATRIX_SLAVE() TRANSACTION_HANDLER_SLAVE(led_matrix) # define TRANSACTIONS_LED_MATRIX_REGISTRATIONS [PUT_LED_MATRIX] = trans_initiator2target_initializer(led_matrix_sync), -#else // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) +#else // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) # define TRANSACTIONS_LED_MATRIX_MASTER() # define TRANSACTIONS_LED_MATRIX_SLAVE() # define TRANSACTIONS_LED_MATRIX_REGISTRATIONS -#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) +#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) //////////////////////////////////////////////////// // RGB Matrix @@ -483,13 +489,13 @@ static void rgb_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_row_t # define TRANSACTIONS_RGB_MATRIX_SLAVE() TRANSACTION_HANDLER_SLAVE(rgb_matrix) # define TRANSACTIONS_RGB_MATRIX_REGISTRATIONS [PUT_RGB_MATRIX] = trans_initiator2target_initializer(rgb_matrix_sync), -#else // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) +#else // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) # define TRANSACTIONS_RGB_MATRIX_MASTER() # define TRANSACTIONS_RGB_MATRIX_SLAVE() # define TRANSACTIONS_RGB_MATRIX_REGISTRATIONS -#endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) +#endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) //////////////////////////////////////////////////// // WPM @@ -502,19 +508,21 @@ static bool wpm_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave return send_if_condition(PUT_WPM, &last_update, (current_wpm != split_shmem->current_wpm), ¤t_wpm, sizeof(current_wpm)); } -static void wpm_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { set_current_wpm(split_shmem->current_wpm); } +static void wpm_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + set_current_wpm(split_shmem->current_wpm); +} # define TRANSACTIONS_WPM_MASTER() TRANSACTION_HANDLER_MASTER(wpm) # define TRANSACTIONS_WPM_SLAVE() TRANSACTION_HANDLER_SLAVE(wpm) # define TRANSACTIONS_WPM_REGISTRATIONS [PUT_WPM] = trans_initiator2target_initializer(current_wpm), -#else // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) +#else // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) # define TRANSACTIONS_WPM_MASTER() # define TRANSACTIONS_WPM_SLAVE() # define TRANSACTIONS_WPM_REGISTRATIONS -#endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) +#endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) //////////////////////////////////////////////////// // OLED @@ -539,13 +547,13 @@ static void oled_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave # define TRANSACTIONS_OLED_SLAVE() TRANSACTION_HANDLER_SLAVE(oled) # define TRANSACTIONS_OLED_REGISTRATIONS [PUT_OLED] = trans_initiator2target_initializer(current_oled_state), -#else // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) +#else // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) # define TRANSACTIONS_OLED_MASTER() # define TRANSACTIONS_OLED_SLAVE() # define TRANSACTIONS_OLED_REGISTRATIONS -#endif // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) +#endif // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) //////////////////////////////////////////////////// // ST7565 @@ -570,24 +578,101 @@ static void st7565_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sla # define TRANSACTIONS_ST7565_SLAVE() TRANSACTION_HANDLER_SLAVE(st7565) # define TRANSACTIONS_ST7565_REGISTRATIONS [PUT_ST7565] = trans_initiator2target_initializer(current_st7565_state), -#else // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) +#else // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) # define TRANSACTIONS_ST7565_MASTER() # define TRANSACTIONS_ST7565_SLAVE() # define TRANSACTIONS_ST7565_REGISTRATIONS -#endif // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) +#endif // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) + +//////////////////////////////////////////////////// +// POINTING + +#if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) + +static bool pointing_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { +# if defined(POINTING_DEVICE_LEFT) + if (is_keyboard_left()) { + return true; + } +# elif defined(POINTING_DEVICE_RIGHT) + if (!is_keyboard_left()) { + return true; + } +# endif + static uint32_t last_update = 0; + static uint16_t last_cpi = 0; + report_mouse_t temp_state; + uint16_t temp_cpi; + bool okay = read_if_checksum_mismatch(GET_POINTING_CHECKSUM, GET_POINTING_DATA, &last_update, &temp_state, &split_shmem->pointing.report, sizeof(temp_state)); + if (okay) pointing_device_set_shared_report(temp_state); + temp_cpi = pointing_device_get_shared_cpi(); + if (temp_cpi && memcmp(&last_cpi, &temp_cpi, sizeof(temp_cpi)) != 0) { + memcpy(&split_shmem->pointing.cpi, &temp_cpi, sizeof(temp_cpi)); + okay = transport_write(PUT_POINTING_CPI, &split_shmem->pointing.cpi, sizeof(split_shmem->pointing.cpi)); + if (okay) { + last_cpi = temp_cpi; + } + } + return okay; +} + +extern const pointing_device_driver_t pointing_device_driver; + +static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { +# if defined(POINTING_DEVICE_LEFT) + if (!is_keyboard_left()) { + return; + } +# elif defined(POINTING_DEVICE_RIGHT) + if (is_keyboard_left()) { + return; + } +# endif + report_mouse_t temp_report; + uint16_t temp_cpi; +# if (POINTING_DEVICE_TASK_THROTTLE_MS > 0) + static uint32_t last_exec = 0; + if (timer_elapsed32(last_exec) < POINTING_DEVICE_TASK_THROTTLE_MS) { + return; + } + last_exec = timer_read32(); +# endif + temp_cpi = !pointing_device_driver.get_cpi ? 0 : pointing_device_driver.get_cpi(); // check for NULL + if (split_shmem->pointing.cpi && memcmp(&split_shmem->pointing.cpi, &temp_cpi, sizeof(temp_cpi)) != 0) { + if (pointing_device_driver.set_cpi) { + pointing_device_driver.set_cpi(split_shmem->pointing.cpi); + } + } + memset(&temp_report, 0, sizeof(temp_report)); + temp_report = pointing_device_driver.get_report(temp_report); + memcpy(&split_shmem->pointing.report, &temp_report, sizeof(temp_report)); + // Now update the checksum given that the pointing has been written to + split_shmem->pointing.checksum = crc8(&temp_report, sizeof(temp_report)); +} + +# define TRANSACTIONS_POINTING_MASTER() TRANSACTION_HANDLER_MASTER(pointing) +# define TRANSACTIONS_POINTING_SLAVE() TRANSACTION_HANDLER_SLAVE(pointing) +# define TRANSACTIONS_POINTING_REGISTRATIONS [GET_POINTING_CHECKSUM] = trans_target2initiator_initializer(pointing.checksum), [GET_POINTING_DATA] = trans_target2initiator_initializer(pointing.report), [PUT_POINTING_CPI] = trans_initiator2target_initializer(pointing.cpi), + +#else // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) + +# define TRANSACTIONS_POINTING_MASTER() +# define TRANSACTIONS_POINTING_SLAVE() +# define TRANSACTIONS_POINTING_REGISTRATIONS + +#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) //////////////////////////////////////////////////// -uint8_t dummy; split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { // Set defaults - [0 ...(NUM_TOTAL_TRANSACTIONS - 1)] = {NULL, 0, 0, 0, 0, 0}, + [0 ...(NUM_TOTAL_TRANSACTIONS - 1)] = {0, 0, 0, 0, 0}, #ifdef USE_I2C [I2C_EXECUTE_CALLBACK] = trans_initiator2target_initializer(transaction_id), -#endif // USE_I2C +#endif // USE_I2C // clang-format off TRANSACTIONS_SLAVE_MATRIX_REGISTRATIONS @@ -604,6 +689,7 @@ split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { TRANSACTIONS_WPM_REGISTRATIONS TRANSACTIONS_OLED_REGISTRATIONS TRANSACTIONS_ST7565_REGISTRATIONS + TRANSACTIONS_POINTING_REGISTRATIONS // clang-format on #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) @@ -611,7 +697,7 @@ split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { [PUT_RPC_REQ_DATA] = trans_initiator2target_initializer(rpc_m2s_buffer), [EXECUTE_RPC] = trans_initiator2target_initializer_cb(rpc_info.transaction_id, slave_rpc_exec_callback), [GET_RPC_RESP_DATA] = trans_target2initiator_initializer(rpc_s2m_buffer), -#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) +#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) }; bool transactions_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { @@ -629,6 +715,7 @@ bool transactions_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix TRANSACTIONS_WPM_MASTER(); TRANSACTIONS_OLED_MASTER(); TRANSACTIONS_ST7565_MASTER(); + TRANSACTIONS_POINTING_MASTER(); return true; } @@ -647,6 +734,7 @@ void transactions_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[ TRANSACTIONS_WPM_SLAVE(); TRANSACTIONS_OLED_SLAVE(); TRANSACTIONS_ST7565_SLAVE(); + TRANSACTIONS_POINTING_SLAVE(); } #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) @@ -720,4 +808,4 @@ void slave_rpc_exec_callback(uint8_t initiator2target_buffer_size, const void *i } } -#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) +#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) diff --git a/quantum/split_common/transactions.h b/quantum/split_common/transactions.h index 53610d6f8e..e38ec79ce9 100644 --- a/quantum/split_common/transactions.h +++ b/quantum/split_common/transactions.h @@ -27,7 +27,6 @@ typedef void (*slave_callback_t)(uint8_t initiator2target_buffer_size, const voi // Split transaction Descriptor typedef struct _split_transaction_desc_t { - uint8_t * status; uint8_t initiator2target_buffer_size; uint16_t initiator2target_offset; uint8_t target2initiator_buffer_size; diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index bcc0261417..aade3c98d7 100644 --- a/quantum/split_common/transport.c +++ b/quantum/split_common/transport.c @@ -26,7 +26,7 @@ # ifndef SLAVE_I2C_TIMEOUT # define SLAVE_I2C_TIMEOUT 100 -# endif // SLAVE_I2C_TIMEOUT +# endif // SLAVE_I2C_TIMEOUT # ifndef SLAVE_I2C_ADDRESS # define SLAVE_I2C_ADDRESS 0x32 @@ -40,8 +40,12 @@ _Static_assert(sizeof(split_shared_memory_t) <= I2C_SLAVE_REG_COUNT, "split_shar split_shared_memory_t *const split_shmem = (split_shared_memory_t *)i2c_slave_reg; -void transport_master_init(void) { i2c_init(); } -void transport_slave_init(void) { i2c_slave_init(SLAVE_I2C_ADDRESS); } +void transport_master_init(void) { + i2c_init(); +} +void transport_slave_init(void) { + i2c_slave_init(SLAVE_I2C_ADDRESS); +} i2c_status_t transport_trigger_callback(int8_t id) { // If there's no callback, indicate that we were successful @@ -82,15 +86,19 @@ bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, return true; } -#else // USE_I2C +#else // USE_I2C # include "serial.h" static split_shared_memory_t shared_memory; split_shared_memory_t *const split_shmem = &shared_memory; -void transport_master_init(void) { soft_serial_initiator_init(); } -void transport_slave_init(void) { soft_serial_target_init(); } +void transport_master_init(void) { + soft_serial_initiator_init(); +} +void transport_slave_init(void) { + soft_serial_target_init(); +} bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, uint16_t initiator2target_length, void *target2initiator_buf, uint16_t target2initiator_length) { split_transaction_desc_t *trans = &split_transaction_table[id]; @@ -99,7 +107,7 @@ bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, memcpy(split_trans_initiator2target_buffer(trans), initiator2target_buf, len); } - if (soft_serial_transaction(id) != TRANSACTION_END) { + if (!soft_serial_transaction(id)) { return false; } @@ -111,8 +119,12 @@ bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, return true; } -#endif // USE_I2C +#endif // USE_I2C -bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { return transactions_master(master_matrix, slave_matrix); } +bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + return transactions_master(master_matrix, slave_matrix); +} -void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { transactions_slave(master_matrix, slave_matrix); } +void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + transactions_slave(master_matrix, slave_matrix); +} diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h index 1d4f6ed0cd..26bd136728 100644 --- a/quantum/split_common/transport.h +++ b/quantum/split_common/transport.h @@ -25,11 +25,11 @@ #ifndef RPC_M2S_BUFFER_SIZE # define RPC_M2S_BUFFER_SIZE 32 -#endif // RPC_M2S_BUFFER_SIZE +#endif // RPC_M2S_BUFFER_SIZE #ifndef RPC_S2M_BUFFER_SIZE # define RPC_S2M_BUFFER_SIZE 32 -#endif // RPC_S2M_BUFFER_SIZE +#endif // RPC_S2M_BUFFER_SIZE void transport_master_init(void); void transport_slave_init(void); @@ -43,15 +43,15 @@ bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, #ifdef ENCODER_ENABLE # include "encoder.h" # define NUMBER_OF_ENCODERS (sizeof((pin_t[])ENCODERS_PAD_A) / sizeof(pin_t)) -#endif // ENCODER_ENABLE +#endif // ENCODER_ENABLE #ifdef BACKLIGHT_ENABLE # include "backlight.h" -#endif // BACKLIGHT_ENABLE +#endif // BACKLIGHT_ENABLE #ifdef RGBLIGHT_ENABLE # include "rgblight.h" -#endif // RGBLIGHT_ENABLE +#endif // RGBLIGHT_ENABLE typedef struct _split_slave_matrix_sync_t { uint8_t checksum; @@ -62,21 +62,21 @@ typedef struct _split_slave_matrix_sync_t { typedef struct _split_master_matrix_sync_t { matrix_row_t matrix[(MATRIX_ROWS) / 2]; } split_master_matrix_sync_t; -#endif // SPLIT_TRANSPORT_MIRROR +#endif // SPLIT_TRANSPORT_MIRROR #ifdef ENCODER_ENABLE typedef struct _split_slave_encoder_sync_t { uint8_t checksum; uint8_t state[NUMBER_OF_ENCODERS]; } split_slave_encoder_sync_t; -#endif // ENCODER_ENABLE +#endif // ENCODER_ENABLE #if !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) typedef struct _split_layers_sync_t { layer_state_t layer_state; layer_state_t default_layer_state; } split_layers_sync_t; -#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) +#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) # include "led_matrix.h" @@ -85,7 +85,7 @@ typedef struct _led_matrix_sync_t { led_eeconfig_t led_matrix; bool led_suspend_state; } led_matrix_sync_t; -#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) +#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) # include "rgb_matrix.h" @@ -94,7 +94,7 @@ typedef struct _rgb_matrix_sync_t { rgb_config_t rgb_matrix; bool rgb_suspend_state; } rgb_matrix_sync_t; -#endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) +#endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) #ifdef SPLIT_MODS_ENABLE typedef struct _split_mods_sync_t { @@ -102,9 +102,18 @@ typedef struct _split_mods_sync_t { uint8_t weak_mods; # ifndef NO_ACTION_ONESHOT uint8_t oneshot_mods; -# endif // NO_ACTION_ONESHOT +# endif // NO_ACTION_ONESHOT } split_mods_sync_t; -#endif // SPLIT_MODS_ENABLE +#endif // SPLIT_MODS_ENABLE + +#if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) +# include "pointing_device.h" +typedef struct _split_slave_pointing_sync_t { + uint8_t checksum; + report_mouse_t report; + uint16_t cpi; +} split_slave_pointing_sync_t; +#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) typedef struct _rpc_sync_info_t { @@ -112,72 +121,76 @@ typedef struct _rpc_sync_info_t { uint8_t m2s_length; uint8_t s2m_length; } rpc_sync_info_t; -#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) +#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) typedef struct _split_shared_memory_t { #ifdef USE_I2C int8_t transaction_id; -#endif // USE_I2C +#endif // USE_I2C split_slave_matrix_sync_t smatrix; #ifdef SPLIT_TRANSPORT_MIRROR split_master_matrix_sync_t mmatrix; -#endif // SPLIT_TRANSPORT_MIRROR +#endif // SPLIT_TRANSPORT_MIRROR #ifdef ENCODER_ENABLE split_slave_encoder_sync_t encoders; -#endif // ENCODER_ENABLE +#endif // ENCODER_ENABLE #ifndef DISABLE_SYNC_TIMER uint32_t sync_timer; -#endif // DISABLE_SYNC_TIMER +#endif // DISABLE_SYNC_TIMER #if !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) split_layers_sync_t layers; -#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) +#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) #ifdef SPLIT_LED_STATE_ENABLE uint8_t led_state; -#endif // SPLIT_LED_STATE_ENABLE +#endif // SPLIT_LED_STATE_ENABLE #ifdef SPLIT_MODS_ENABLE split_mods_sync_t mods; -#endif // SPLIT_MODS_ENABLE +#endif // SPLIT_MODS_ENABLE #ifdef BACKLIGHT_ENABLE uint8_t backlight_level; -#endif // BACKLIGHT_ENABLE +#endif // BACKLIGHT_ENABLE #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) rgblight_syncinfo_t rgblight_sync; -#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) +#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) led_matrix_sync_t led_matrix_sync; -#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) +#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) rgb_matrix_sync_t rgb_matrix_sync; -#endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) +#endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) #if defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) uint8_t current_wpm; -#endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) +#endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) #if defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) uint8_t current_oled_state; -#endif // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) +#endif // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) #if defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) uint8_t current_st7565_state; -#endif // ST7565_ENABLE(OLED_ENABLE) && defined(SPLIT_ST7565_ENABLE) +#endif // ST7565_ENABLE(OLED_ENABLE) && defined(SPLIT_ST7565_ENABLE) + +#if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) + split_slave_pointing_sync_t pointing; +#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) rpc_sync_info_t rpc_info; uint8_t rpc_m2s_buffer[RPC_M2S_BUFFER_SIZE]; uint8_t rpc_s2m_buffer[RPC_S2M_BUFFER_SIZE]; -#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) +#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) } split_shared_memory_t; extern split_shared_memory_t *const split_shmem; |