Skip to content

Commit

Permalink
Update encoder.c and encoder.h
Browse files Browse the repository at this point in the history
  • Loading branch information
galican committed Mar 16, 2023
1 parent 1ff70d6 commit 89be39f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 10 additions & 12 deletions quantum/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion quantum/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +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);
void encoder_inerrupt_read(uint8_t index);

#ifdef SPLIT_KEYBOARD

Expand Down

0 comments on commit 89be39f

Please sign in to comment.