mirror of
https://github.com/Keychron/qmk_firmware.git
synced 2024-11-26 02:17:38 +06:00
Update encoder.c and encoder.h
This commit is contained in:
parent
1ff70d666a
commit
89be39f130
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user