Move encoder config to data driven (#19923)
Co-authored-by: Nick Brassel <nick@tzarc.org>
This commit is contained in:
parent
314f6c1ddb
commit
7e0299117b
972 changed files with 2898 additions and 2569 deletions
|
@ -3,18 +3,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
// Encoder pins.
|
||||
// Encoder numbering (assuming the default board orientation with encoders on
|
||||
// the top side):
|
||||
// 0 - left
|
||||
// 1 - center (with a longer shaft and a larger knob)
|
||||
// 2 - right
|
||||
#define ENCODERS_PAD_A { F1, B0, B3 }
|
||||
#define ENCODERS_PAD_B { F0, B1, B7 }
|
||||
#define ENCODER_RESOLUTION 4
|
||||
|
||||
// Encoder mappings (used for VIA).
|
||||
#define ENCODERS 3
|
||||
#define ENCODERS_CW_KEY { { 22, 0 }, { 18, 0 }, { 20, 0 } }
|
||||
#define ENCODERS_CCW_KEY { { 23, 0 }, { 19, 0 }, { 21, 0 } }
|
||||
|
||||
|
|
|
@ -8,6 +8,13 @@
|
|||
"pid": "0x0315",
|
||||
"vid": "0xF1F1"
|
||||
},
|
||||
"encoder": {
|
||||
"rotary": [
|
||||
{"pin_a": "F1", "pin_b": "F0"},
|
||||
{"pin_a": "B0", "pin_b": "B1"},
|
||||
{"pin_a": "B3", "pin_b": "B7"}
|
||||
]
|
||||
},
|
||||
"processor": "atmega32u4",
|
||||
"bootloader": "atmel-dfu",
|
||||
"matrix_pins": {
|
||||
|
|
|
@ -27,11 +27,10 @@
|
|||
# define ENCODER_STATE_CW 0x01
|
||||
# define ENCODER_STATE_CCW 0x02
|
||||
|
||||
# ifdef ENCODERS
|
||||
static uint8_t encoder_state[ENCODERS] = {0};
|
||||
static uint16_t encoder_timer[ENCODERS] = {0};
|
||||
static keypos_t encoder_cw[ENCODERS] = ENCODERS_CW_KEY;
|
||||
static keypos_t encoder_ccw[ENCODERS] = ENCODERS_CCW_KEY;
|
||||
static uint8_t encoder_state[NUM_ENCODERS] = {0};
|
||||
static uint16_t encoder_timer[NUM_ENCODERS] = {0};
|
||||
static keypos_t encoder_cw[NUM_ENCODERS] = ENCODERS_CW_KEY;
|
||||
static keypos_t encoder_ccw[NUM_ENCODERS] = ENCODERS_CCW_KEY;
|
||||
|
||||
static void exec_encoder_action(uint8_t index, bool clockwise, bool pressed) {
|
||||
// clang-format off
|
||||
|
@ -43,22 +42,18 @@ static void exec_encoder_action(uint8_t index, bool clockwise, bool pressed) {
|
|||
// clang-format on
|
||||
action_exec(encoder_event);
|
||||
}
|
||||
# endif
|
||||
|
||||
void encoder_action_unregister(void) {
|
||||
# ifdef ENCODERS
|
||||
for (int index = 0; index < ENCODERS; ++index) {
|
||||
for (int index = 0; index < NUM_ENCODERS; ++index) {
|
||||
if (encoder_state[index] && (timer_elapsed(encoder_timer[index]) >= ENCODER_TAP_DURATION_MS)) {
|
||||
bool clockwise = !!(encoder_state[index] & ENCODER_STATE_CW);
|
||||
encoder_state[index] = 0;
|
||||
exec_encoder_action(index, clockwise, false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
void encoder_action_register(uint8_t index, bool clockwise) {
|
||||
# ifdef ENCODERS
|
||||
if (encoder_state[index]) {
|
||||
bool was_clockwise = !!(encoder_state[index] & ENCODER_STATE_CW);
|
||||
encoder_state[index] = 0;
|
||||
|
@ -67,7 +62,6 @@ void encoder_action_register(uint8_t index, bool clockwise) {
|
|||
encoder_state[index] = clockwise ? ENCODER_STATE_CW : ENCODER_STATE_CCW;
|
||||
encoder_timer[index] = timer_read();
|
||||
exec_encoder_action(index, clockwise, true);
|
||||
# endif
|
||||
}
|
||||
|
||||
void matrix_scan_kb(void) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue