summaryrefslogtreecommitdiff
path: root/quantum/split_common
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/split_common')
-rw-r--r--quantum/split_common/split_util.c22
-rw-r--r--quantum/split_common/transaction_id_define.h1
-rw-r--r--quantum/split_common/transactions.c26
-rw-r--r--quantum/split_common/transport.c6
-rw-r--r--quantum/split_common/transport.h4
5 files changed, 34 insertions, 25 deletions
diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c
index 874339361d..96f19bfd84 100644
--- a/quantum/split_common/split_util.c
+++ b/quantum/split_common/split_util.c
@@ -123,14 +123,14 @@ void split_watchdog_task(void) {
void matrix_io_delay(void);
static uint8_t peek_matrix_intersection(pin_t out_pin, pin_t in_pin) {
- setPinInputHigh(in_pin);
- setPinOutput(out_pin);
- writePinLow(out_pin);
+ gpio_set_pin_input_high(in_pin);
+ gpio_set_pin_output(out_pin);
+ gpio_write_pin_low(out_pin);
// It's almost unnecessary, but wait until it's down to low, just in case.
wait_us(1);
- uint8_t pin_state = readPin(in_pin);
+ uint8_t pin_state = gpio_read_pin(in_pin);
// Set out_pin to a setting that is less susceptible to noise.
- setPinInputHigh(out_pin);
+ gpio_set_pin_input_high(out_pin);
matrix_io_delay(); // Wait for the pull-up to go HIGH.
return pin_state;
}
@@ -138,19 +138,19 @@ static uint8_t peek_matrix_intersection(pin_t out_pin, pin_t in_pin) {
__attribute__((weak)) bool is_keyboard_left_impl(void) {
#if defined(SPLIT_HAND_PIN)
- setPinInput(SPLIT_HAND_PIN);
+ gpio_set_pin_input(SPLIT_HAND_PIN);
wait_us(100);
// Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand
# ifdef SPLIT_HAND_PIN_LOW_IS_LEFT
- return !readPin(SPLIT_HAND_PIN);
+ return !gpio_read_pin(SPLIT_HAND_PIN);
# else
- return readPin(SPLIT_HAND_PIN);
+ return gpio_read_pin(SPLIT_HAND_PIN);
# endif
#elif defined(SPLIT_HAND_MATRIX_GRID)
-# ifdef SPLIT_HAND_MATRIX_GRID_LOW_IS_RIGHT
- return peek_matrix_intersection(SPLIT_HAND_MATRIX_GRID);
-# else
+# ifdef SPLIT_HAND_MATRIX_GRID_LOW_IS_LEFT
return !peek_matrix_intersection(SPLIT_HAND_MATRIX_GRID);
+# else
+ return peek_matrix_intersection(SPLIT_HAND_MATRIX_GRID);
# endif
#elif defined(EE_HANDS)
if (!eeconfig_is_enabled()) {
diff --git a/quantum/split_common/transaction_id_define.h b/quantum/split_common/transaction_id_define.h
index 4d4d2b9570..05b3bf7b62 100644
--- a/quantum/split_common/transaction_id_define.h
+++ b/quantum/split_common/transaction_id_define.h
@@ -31,6 +31,7 @@ enum serial_transaction_id {
#ifdef ENCODER_ENABLE
GET_ENCODERS_CHECKSUM,
GET_ENCODERS_DATA,
+ PUT_ENCODER_TAIL,
#endif // ENCODER_ENABLE
#ifndef DISABLE_SYNC_TIMER
diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c
index 2b9423cd63..2cfa83e7a3 100644
--- a/quantum/split_common/transactions.c
+++ b/quantum/split_common/transactions.c
@@ -234,21 +234,28 @@ static void master_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_ro
#ifdef ENCODER_ENABLE
static bool encoder_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
- static uint32_t last_update = 0;
- uint8_t temp_state[NUM_ENCODERS_MAX_PER_SIDE];
+ static uint32_t last_update = 0;
+ encoder_events_t temp_events;
- bool okay = read_if_checksum_mismatch(GET_ENCODERS_CHECKSUM, GET_ENCODERS_DATA, &last_update, temp_state, split_shmem->encoders.state, sizeof(temp_state));
- if (okay) encoder_update_raw(temp_state);
+ bool okay = read_if_checksum_mismatch(GET_ENCODERS_CHECKSUM, GET_ENCODERS_DATA, &last_update, &temp_events, &split_shmem->encoders.events, sizeof(temp_events));
+ if (okay) {
+ encoder_handle_slave_events(&split_shmem->encoders.events);
+ transport_write(PUT_ENCODER_TAIL, &split_shmem->encoders.events.tail, sizeof(split_shmem->encoders.events.tail));
+ split_shmem->encoders.checksum = crc8(&split_shmem->encoders.events, sizeof(split_shmem->encoders.events));
+ }
return okay;
}
static void encoder_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
- uint8_t encoder_state[NUM_ENCODERS_MAX_PER_SIDE];
- encoder_state_raw(encoder_state);
// Always prepare the encoder state for read.
- memcpy(split_shmem->encoders.state, encoder_state, sizeof(encoder_state));
+ encoder_retrieve_events(&split_shmem->encoders.events);
// Now update the checksum given that the encoders has been written to
- split_shmem->encoders.checksum = crc8(encoder_state, sizeof(encoder_state));
+ split_shmem->encoders.checksum = crc8(&split_shmem->encoders.events, sizeof(split_shmem->encoders.events));
+}
+
+static void encoder_handlers_slave_reset(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer) {
+ uint8_t tail_index = *(uint8_t *)initiator2target_buffer;
+ encoder_set_tail_index(tail_index);
}
// clang-format off
@@ -256,7 +263,8 @@ static void encoder_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sl
# define TRANSACTIONS_ENCODERS_SLAVE() TRANSACTION_HANDLER_SLAVE_AUTOLOCK(encoder)
# define TRANSACTIONS_ENCODERS_REGISTRATIONS \
[GET_ENCODERS_CHECKSUM] = trans_target2initiator_initializer(encoders.checksum), \
- [GET_ENCODERS_DATA] = trans_target2initiator_initializer(encoders.state),
+ [GET_ENCODERS_DATA] = trans_target2initiator_initializer(encoders.events), \
+ [PUT_ENCODER_TAIL] = trans_initiator2target_initializer_cb(encoders.events.tail, encoder_handlers_slave_reset),
// clang-format on
#else // ENCODER_ENABLE
diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c
index aade3c98d7..83edc34859 100644
--- a/quantum/split_common/transport.c
+++ b/quantum/split_common/transport.c
@@ -56,7 +56,7 @@ i2c_status_t transport_trigger_callback(int8_t id) {
// Kick off the "callback executor", now that data has been written to the slave
split_shmem->transaction_id = id;
split_transaction_desc_t *trans = &split_transaction_table[I2C_EXECUTE_CALLBACK];
- return i2c_writeReg(SLAVE_I2C_ADDRESS, trans->initiator2target_offset, split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size, SLAVE_I2C_TIMEOUT);
+ return i2c_write_register(SLAVE_I2C_ADDRESS, trans->initiator2target_offset, split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size, SLAVE_I2C_TIMEOUT);
}
bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, uint16_t initiator2target_length, void *target2initiator_buf, uint16_t target2initiator_length) {
@@ -65,7 +65,7 @@ bool transport_execute_transaction(int8_t id, const void *initiator2target_buf,
if (initiator2target_length > 0) {
size_t len = trans->initiator2target_buffer_size < initiator2target_length ? trans->initiator2target_buffer_size : initiator2target_length;
memcpy(split_trans_initiator2target_buffer(trans), initiator2target_buf, len);
- if ((status = i2c_writeReg(SLAVE_I2C_ADDRESS, trans->initiator2target_offset, split_trans_initiator2target_buffer(trans), len, SLAVE_I2C_TIMEOUT)) < 0) {
+ if ((status = i2c_write_register(SLAVE_I2C_ADDRESS, trans->initiator2target_offset, split_trans_initiator2target_buffer(trans), len, SLAVE_I2C_TIMEOUT)) < 0) {
return false;
}
}
@@ -77,7 +77,7 @@ bool transport_execute_transaction(int8_t id, const void *initiator2target_buf,
if (target2initiator_length > 0) {
size_t len = trans->target2initiator_buffer_size < target2initiator_length ? trans->target2initiator_buffer_size : target2initiator_length;
- if ((status = i2c_readReg(SLAVE_I2C_ADDRESS, trans->target2initiator_offset, split_trans_target2initiator_buffer(trans), len, SLAVE_I2C_TIMEOUT)) < 0) {
+ if ((status = i2c_read_register(SLAVE_I2C_ADDRESS, trans->target2initiator_offset, split_trans_target2initiator_buffer(trans), len, SLAVE_I2C_TIMEOUT)) < 0) {
return false;
}
memcpy(target2initiator_buf, split_trans_target2initiator_buffer(trans), len);
diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h
index 2e2b918d45..4f6b968fa8 100644
--- a/quantum/split_common/transport.h
+++ b/quantum/split_common/transport.h
@@ -65,8 +65,8 @@ typedef struct _split_master_matrix_sync_t {
#ifdef ENCODER_ENABLE
typedef struct _split_slave_encoder_sync_t {
- uint8_t checksum;
- uint8_t state[NUM_ENCODERS_MAX_PER_SIDE];
+ uint8_t checksum;
+ encoder_events_t events;
} split_slave_encoder_sync_t;
#endif // ENCODER_ENABLE