~jacqueline/reform

5512a3ca224b747cd68f364a1b671139f009ef84 — jacqueline 2 months ago e3037df master
Fix double-inputs when releasing layer keys
1 files changed, 19 insertions(+), 7 deletions(-)

M reform2-keyboard-fw/keyboard.c
M reform2-keyboard-fw/keyboard.c => reform2-keyboard-fw/keyboard.c +19 -7
@@ 12,6 12,7 @@
  SPDX-License-Identifier: MIT
*/

#include <stdint.h>
#include <stdlib.h>
#include <avr/io.h>
#include "backlight.h"


@@ 74,6 75,7 @@ USB_ClassInfo_HID_Device_t MediaControl_HID_Interface =

uint8_t matrix_debounce[KBD_COLS*KBD_ROWS];
uint8_t matrix_state[KBD_COLS*KBD_ROWS];
uint16_t matrix_key_when_pressed[KBD_COLS*KBD_ROWS];

int active_meta_mode = 0;
uint16_t last_meta_key = 0;


@@ 142,15 144,8 @@ int process_keyboard(uint8_t* resulting_scancodes) {

    // check input COLs
    for (int x=0; x<14; x++) {
      uint16_t keycode;
      uint16_t loc = y*KBD_COLS+x;

      keycode = active_matrix[loc];
      // Fall through to the default layer if there isn't anything on this one.
      if (keycode == 0x00) {
        keycode = matrix[loc];
      }

      uint8_t  pressed = 0;
      uint8_t  debounced_pressed = 0;



@@ 183,6 178,23 @@ int process_keyboard(uint8_t* resulting_scancodes) {
      }
      debounced_pressed = matrix_state[loc];

      // Only get the keycode from the current matrix if it's released.
      // Otherwise, we use the keycode that this key had when it was last
      // pressed. This ensures that the keycode doesn't change mid-press if,
      // e.g. a layer key is released before a key that is affected by the
      // layer.
      uint16_t keycode;
      if (debounced_pressed) {
        keycode = matrix_key_when_pressed[loc];
      } else {
        keycode = active_matrix[loc];
        // Fall through to the default layer if there isn't anything on this one.
        if (keycode == 0x00) {
          keycode = matrix[loc];
        }
        matrix_key_when_pressed[loc] = keycode;
      }

      if (debounced_pressed) {
        total_pressed++;