summaryrefslogtreecommitdiff
path: root/keyboards/converter/xmk/xmk_matrix.c
blob: 41eca9fe46a77f176576b020f8fbd77f0337bcfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2022 Manna Harbour (@manna-harbour)
// https://github.com/manna-harbour/xmk

// SPDX-License-Identifier: GPL-2.0-or-later

#include "xmk_matrix.h"
#include "matrix.h"
#include "debug.h"

bool xmk_changed = false;
matrix_row_t xmk_rows[MATRIX_ROWS];

bool matrix_scan_custom(matrix_row_t current_matrix[]) {
  if (xmk_changed) {
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
      current_matrix[row] = xmk_rows[row];
    }
    xmk_changed = false;
    return true;
  } else {
    return false;
  }
}

void xmk_matrix_key(bool press, uint8_t key) {
  dprintf("xmk_matrix_key: press: %s, key: %u\n", press?"true":"false", key);
  uint8_t row = key / MATRIX_COLS;
  if (row < MATRIX_ROWS) {
    uint8_t col = key % MATRIX_COLS;
    xmk_changed = true;
    if (press) {
      xmk_rows[row] |= (MATRIX_ROW_SHIFTER << col);
    } else {
      xmk_rows[row] &= ~(MATRIX_ROW_SHIFTER << col);
    }
  }
}