diff options
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/encoder.c | 17 | ||||
-rw-r--r-- | quantum/encoder.h | 1 |
2 files changed, 15 insertions, 3 deletions
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; + } +} diff --git a/quantum/encoder.h b/quantum/encoder.h index 4eb67fa25d..bc02889ee8 100644 --- a/quantum/encoder.h +++ b/quantum/encoder.h @@ -25,6 +25,7 @@ bool encoder_read(void); bool encoder_update_kb(uint8_t index, bool clockwise); bool encoder_update_user(uint8_t index, bool clockwise); +void encoder_insert_state(void); #ifdef SPLIT_KEYBOARD |