vial-kb / vial-qmk

QMK fork with Vial-specific features.
https://get.vial.today/
GNU General Public License v2.0
822 stars 2.37k forks source link

4 Rotary encoders does not work #736

Open jeriellopez opened 4 months ago

jeriellopez commented 4 months ago

This works: main keyboard info.json

    "encoder": {
        "rotary": [
            { "pin_a": "GP28", "pin_b": "GP27", "resolution": 4 },
            { "pin_a": "GP22", "pin_b": "GP26", "resolution": 4 },
            { "pin_a": "GP4", "pin_b": "GP3", "resolution": 4 }
        ]
    },

keymap.c

#if defined(ENCODER_MAP_ENABLE)
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
    [0] =   { ENCODER_CCW_CW(KC_VOLD, KC_VOLU), ENCODER_CCW_CW(KC_VOLD, KC_VOLU), ENCODER_CCW_CW(KC_VOLD, KC_VOLU) },
};
#endif

This builds, but none of the rotary encoders work:

    "encoder": {
        "rotary": [
            { "pin_a": "GP28", "pin_b": "GP27", "resolution": 4 },
            { "pin_a": "GP22", "pin_b": "GP26", "resolution": 4 },
            { "pin_a": "GP4", "pin_b": "GP3", "resolution": 4 },
            { "pin_a": "GP9", "pin_b": "GP5", "resolution": 4 }
        ]
    },

keymap.c:

#if defined(ENCODER_MAP_ENABLE)
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
    [0] =   { ENCODER_CCW_CW(KC_VOLD, KC_VOLU), ENCODER_CCW_CW(KC_VOLD, KC_VOLU), ENCODER_CCW_CW(KC_VOLD, KC_VOLU), ENCODER_CCW_CW(KC_VOLD, KC_VOLU) },
};
#endif

My board uses an rp2040. This old precompiled firmware works with 4 encoders: https://github.com/pabile/Pabile-Keyboards/blob/main/firmware_precompiled/vial/pabile_p20v8iii_wowenkho.uf2

jeriellopez commented 4 months ago

Update quantum/encoder.c

bool encoder_queue_full_advanced(encoder_events_t *events) {
    // Maximum is 128 since uint8_t's max is 255.
    return events->head == ((events->tail + MAX_QUEUED_ENCODER_EVENTS - 1) % MAX_QUEUED_ENCODER_EVENTS);
    // at 4 encoders, MAX_QUEUED_ENCODER_EVENTS becomes 5. 0 - 1 is 255, and 255 % 5 is 0
    // which will evaluate to true for the code below, indicating "full", even though it is actually empty.
    // return events->head == (events->tail - 1) % MAX_QUEUED_ENCODER_EVENTS;
}