zmk_mf68/app/src/matrix_transform.c
Pete Johanson 5ffd95694f Kyria left/right overlays, matrix transform fixes
* Refactor Kyria into separate left/right "revisions"
  of the Kyria shield, and include central
  kyria.dtsi file with common definition.
* Fixes for keymaps to work fully with matrix
  transforms that override effective rows/columns.
* Add ability for matrix transform to do row/col
  offsets, which is needed for split keyboards.
2020-06-27 00:16:15 -04:00

36 lines
991 B
C

#include <zephyr.h>
#include <zmk/matrix_transform.h>
#include <zmk/matrix.h>
#include <dt-bindings/zmk/matrix-transform.h>
#ifdef ZMK_KEYMAP_TRANSFORM_NODE
#define _TRANSFORM_ENTRY(i, _) \
[(KT_ROW(DT_PROP_BY_IDX(ZMK_KEYMAP_TRANSFORM_NODE, map, i)) * ZMK_MATRIX_COLS) + KT_COL(DT_PROP_BY_IDX(ZMK_KEYMAP_TRANSFORM_NODE, map, i))] = i,
static u32_t transform[] =
{ UTIL_LISTIFY(ZMK_KEYMAP_LEN, _TRANSFORM_ENTRY, 0) };
#endif
u32_t zmk_matrix_transform_row_column_to_position(u32_t row, u32_t column)
{
u32_t matrix_index;
#if DT_NODE_HAS_PROP(ZMK_KEYMAP_TRANSFORM_NODE, col_offset)
column += DT_PROP(ZMK_KEYMAP_TRANSFORM_NODE, col_offset);
#endif
#if DT_NODE_HAS_PROP(ZMK_KEYMAP_TRANSFORM_NODE, row_offset)
row += DT_PROP(ZMK_KEYMAP_TRANSFORM_NODE, row_offset);
#endif
matrix_index = (row * ZMK_MATRIX_COLS) + column;
#ifdef ZMK_KEYMAP_TRANSFORM_NODE
return transform[matrix_index];
#else
return matrix_index;
#endif /* ZMK_KEYMAP_TRANSFORM_NODE */
};