2020-09-10 13:57:44 +10:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 The ZMK Contributors
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*/
|
2020-06-21 07:54:52 +10:00
|
|
|
|
|
|
|
#include <zephyr.h>
|
|
|
|
#include <zmk/matrix_transform.h>
|
|
|
|
#include <zmk/matrix.h>
|
2020-12-23 02:56:00 +11:00
|
|
|
#include <dt-bindings/zmk/matrix_transform.h>
|
2020-06-21 07:54:52 +10:00
|
|
|
|
2020-06-27 14:16:15 +10:00
|
|
|
#ifdef ZMK_KEYMAP_TRANSFORM_NODE
|
2020-06-21 07:54:52 +10:00
|
|
|
|
2020-09-14 12:53:24 +10:00
|
|
|
#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,
|
2020-06-21 07:54:52 +10:00
|
|
|
|
2020-12-03 03:41:57 +11:00
|
|
|
static uint32_t transform[] = {UTIL_LISTIFY(ZMK_KEYMAP_LEN, _TRANSFORM_ENTRY, 0)};
|
2020-06-21 07:54:52 +10:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-12-03 03:41:57 +11:00
|
|
|
uint32_t zmk_matrix_transform_row_column_to_position(uint32_t row, uint32_t column) {
|
|
|
|
uint32_t matrix_index;
|
2020-06-27 14:16:15 +10:00
|
|
|
|
|
|
|
#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;
|
2020-06-21 07:54:52 +10:00
|
|
|
|
2020-06-27 14:16:15 +10:00
|
|
|
#ifdef ZMK_KEYMAP_TRANSFORM_NODE
|
2020-06-21 07:54:52 +10:00
|
|
|
return transform[matrix_index];
|
|
|
|
#else
|
|
|
|
return matrix_index;
|
2020-06-27 14:16:15 +10:00
|
|
|
#endif /* ZMK_KEYMAP_TRANSFORM_NODE */
|
2020-06-21 07:54:52 +10:00
|
|
|
};
|