From 1ff70d666a4c5f8ffa45adbdbd3f2628a4cbbdb4 Mon Sep 17 00:00:00 2001 From: lalalademaxiya1 <2831039915@qq.com> Date: Thu, 16 Mar 2023 11:49:53 +0800 Subject: Added pal callback function for Q2Pro and Q3Pro --- quantum/encoder.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'quantum/encoder.c') diff --git a/quantum/encoder.c b/quantum/encoder.c index 3aee340249..25ddab0c3c 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -54,8 +54,9 @@ static uint8_t encoder_resolutions[NUM_ENCODERS] = ENCODER_RESOLUTIONS; #endif static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0}; -static uint8_t encoder_state[NUM_ENCODERS] = {0}; -static int8_t encoder_pulses[NUM_ENCODERS] = {0}; +static uint8_t encoder_state[NUM_ENCODERS] = {0}; +static int8_t encoder_pulses[NUM_ENCODERS] = {0}; +static bool encoder_external_update[NUM_ENCODERS] = {false}; // encoder counts static uint8_t thisCount; @@ -221,10 +222,11 @@ bool encoder_read(void) { bool changed = false; for (uint8_t i = 0; i < thisCount; i++) { uint8_t new_status = (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); - if ((encoder_state[i] & 0x3) != new_status) { + if ((encoder_state[i] & 0x3) != new_status || encoder_external_update[i]) { encoder_state[i] <<= 2; encoder_state[i] |= new_status; changed |= encoder_update(i, encoder_state[i]); + encoder_external_update[i] = false; } } return changed; @@ -268,3 +270,12 @@ void encoder_update_raw(uint8_t *slave_state) { if (changed) last_encoder_activity_trigger(); } #endif + +void encoder_insert_state(void) { + for (uint8_t i = 0; i < thisCount; i++) { + encoder_state[i] <<= 2; + encoder_state[i] |= (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); + encoder_pulses[i] += encoder_LUT[encoder_state[i] & 0xF]; + encoder_external_update[i] = true; + } +} -- cgit v1.2.3 From 89be39f130c8a16db6763c849cbff2975fd3a9b9 Mon Sep 17 00:00:00 2001 From: lalalademaxiya1 <2831039915@qq.com> Date: Thu, 16 Mar 2023 12:16:36 +0800 Subject: Update encoder.c and encoder.h --- quantum/encoder.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'quantum/encoder.c') diff --git a/quantum/encoder.c b/quantum/encoder.c index 25ddab0c3c..7b3738f9a1 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -56,7 +56,7 @@ static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, static uint8_t encoder_state[NUM_ENCODERS] = {0}; static int8_t encoder_pulses[NUM_ENCODERS] = {0}; -static bool encoder_external_update[NUM_ENCODERS] = {false}; +static bool encoder_interrupt_update[NUM_ENCODERS] = {false}; // encoder counts static uint8_t thisCount; @@ -222,16 +222,23 @@ bool encoder_read(void) { bool changed = false; for (uint8_t i = 0; i < thisCount; i++) { uint8_t new_status = (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); - if ((encoder_state[i] & 0x3) != new_status || encoder_external_update[i]) { + if ((encoder_state[i] & 0x3) != new_status || encoder_interrupt_update[i]) { encoder_state[i] <<= 2; encoder_state[i] |= new_status; changed |= encoder_update(i, encoder_state[i]); - encoder_external_update[i] = false; + encoder_interrupt_update[i] = false; } } return changed; } +void encoder_inerrupt_read(uint8_t index) { + encoder_state[index] <<= 2; + encoder_state[index] |= (readPin(encoders_pad_a[index]) << 0) | (readPin(encoders_pad_b[index]) << 1); + encoder_pulses[index] += encoder_LUT[encoder_state[index] & 0xF]; + encoder_interrupt_update[index] = true; +} + #ifdef SPLIT_KEYBOARD void last_encoder_activity_trigger(void); @@ -270,12 +277,3 @@ void encoder_update_raw(uint8_t *slave_state) { if (changed) last_encoder_activity_trigger(); } #endif - -void encoder_insert_state(void) { - for (uint8_t i = 0; i < thisCount; i++) { - encoder_state[i] <<= 2; - encoder_state[i] |= (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); - encoder_pulses[i] += encoder_LUT[encoder_state[i] & 0xF]; - encoder_external_update[i] = true; - } -} -- cgit v1.2.3 From 0f35f0e2ed1343765422bc9abf4fe240768b4130 Mon Sep 17 00:00:00 2001 From: lalalademaxiya1 <2831039915@qq.com> Date: Thu, 16 Mar 2023 14:56:17 +0800 Subject: Update encoder.c --- quantum/encoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quantum/encoder.c') diff --git a/quantum/encoder.c b/quantum/encoder.c index 7b3738f9a1..e2029fa376 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -40,6 +40,7 @@ extern volatile bool isLeftHand; static pin_t encoders_pad_a[NUM_ENCODERS_MAX_PER_SIDE] = ENCODERS_PAD_A; static pin_t encoders_pad_b[NUM_ENCODERS_MAX_PER_SIDE] = ENCODERS_PAD_B; +static bool encoder_interrupt_update[NUM_ENCODERS] = {false}; #ifdef ENCODER_RESOLUTIONS static uint8_t encoder_resolutions[NUM_ENCODERS] = ENCODER_RESOLUTIONS; @@ -56,7 +57,6 @@ static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, static uint8_t encoder_state[NUM_ENCODERS] = {0}; static int8_t encoder_pulses[NUM_ENCODERS] = {0}; -static bool encoder_interrupt_update[NUM_ENCODERS] = {false}; // encoder counts static uint8_t thisCount; -- cgit v1.2.3