forked from kofal.net/zmk
feat: Add keyboard physical layout system.
* Add bindings to allow creating multiple physical layouts that specify their key's physical attributes, and the matching matrix transform and dependant kscan to use. * Synthesize a basic physical layout if none specified, for backwards compatibility. * Update matrix transform API to explicitly pass in the selected transform to the API instead of using a fixed chosen transform. * Move kscan subscription and handling into the physical layout code, so that selecting a different physical layout at runtime can also use the correct kscan instance. * Add `physical_layouts.dtsi` file to include so you can use the pre-configured `&key_physical_attrs` for adding you layout keys.
This commit is contained in:
committed by
Pete Johanson
parent
80173f8ea3
commit
c5cca5b34f
@@ -1,11 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <zephyr/device.h>
|
||||
|
||||
int zmk_kscan_init(const struct device *dev);
|
||||
@@ -9,15 +9,25 @@
|
||||
#include <zephyr/devicetree.h>
|
||||
|
||||
#define ZMK_MATRIX_NODE_ID DT_CHOSEN(zmk_kscan)
|
||||
#define ZMK_MATRIX_HAS_TRANSFORM DT_HAS_CHOSEN(zmk_matrix_transform)
|
||||
|
||||
#if DT_HAS_CHOSEN(zmk_matrix_transform)
|
||||
#if DT_HAS_COMPAT_STATUS_OKAY(zmk_physical_layout)
|
||||
|
||||
#if ZMK_MATRIX_HAS_TRANSFORM
|
||||
#error "To use physical layouts, remove the chosen `zmk,matrix-transform` value."
|
||||
#endif
|
||||
|
||||
#define ZMK_PHYSICAL_LAYOUT_BYTE_ARRAY(node_id) \
|
||||
uint8_t _CONCAT(prop_, node_id)[DT_PROP_LEN(DT_PHANDLE(node_id, transform), map)];
|
||||
|
||||
#define ZMK_KEYMAP_LEN \
|
||||
sizeof(union {DT_FOREACH_STATUS_OKAY(zmk_physical_layout, ZMK_PHYSICAL_LAYOUT_BYTE_ARRAY)})
|
||||
|
||||
#elif ZMK_MATRIX_HAS_TRANSFORM
|
||||
|
||||
#define ZMK_KEYMAP_TRANSFORM_NODE DT_CHOSEN(zmk_matrix_transform)
|
||||
#define ZMK_KEYMAP_LEN DT_PROP_LEN(ZMK_KEYMAP_TRANSFORM_NODE, map)
|
||||
|
||||
#define ZMK_MATRIX_ROWS DT_PROP(ZMK_KEYMAP_TRANSFORM_NODE, rows)
|
||||
#define ZMK_MATRIX_COLS DT_PROP(ZMK_KEYMAP_TRANSFORM_NODE, columns)
|
||||
|
||||
#else /* DT_HAS_CHOSEN(zmk_matrix_transform) */
|
||||
|
||||
#if DT_NODE_HAS_PROP(ZMK_MATRIX_NODE_ID, row_gpios)
|
||||
|
||||
@@ -6,4 +6,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
int32_t zmk_matrix_transform_row_column_to_position(uint32_t row, uint32_t column);
|
||||
#include <zephyr/sys/util.h>
|
||||
|
||||
typedef const struct zmk_matrix_transform *zmk_matrix_transform_t;
|
||||
|
||||
#define ZMK_MATRIX_TRANSFORM_DEFAULT_EXTERN() \
|
||||
extern const struct zmk_matrix_transform zmk_matrix_transform_default
|
||||
#define ZMK_MATRIX_TRANSFORM_EXTERN(node_id) \
|
||||
extern const struct zmk_matrix_transform _CONCAT(zmk_matrix_transform_, node_id)
|
||||
|
||||
#define ZMK_MATRIX_TRANSFORM_T_FOR_NODE(node_id) &_CONCAT(zmk_matrix_transform_, node_id)
|
||||
|
||||
int32_t zmk_matrix_transform_row_column_to_position(zmk_matrix_transform_t mt, uint32_t row,
|
||||
uint32_t column);
|
||||
|
||||
43
app/include/zmk/physical_layouts.h
Normal file
43
app/include/zmk/physical_layouts.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2024 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zmk/matrix_transform.h>
|
||||
|
||||
struct zmk_key_physical_attrs {
|
||||
int16_t width;
|
||||
int16_t height;
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int16_t rx;
|
||||
int16_t ry;
|
||||
int16_t r;
|
||||
};
|
||||
|
||||
struct zmk_physical_layout {
|
||||
const char *display_name;
|
||||
|
||||
zmk_matrix_transform_t matrix_transform;
|
||||
const struct device *kscan;
|
||||
|
||||
const struct zmk_key_physical_attrs *keys;
|
||||
size_t keys_len;
|
||||
};
|
||||
|
||||
#define ZMK_PHYS_LAYOUTS_FOREACH(_ref) STRUCT_SECTION_FOREACH(zmk_physical_layout, _ref)
|
||||
|
||||
size_t zmk_physical_layouts_get_list(struct zmk_physical_layout const *const **phys_layouts);
|
||||
|
||||
int zmk_physical_layouts_select(uint8_t index);
|
||||
int zmk_physical_layouts_get_selected(void);
|
||||
|
||||
int zmk_physical_layouts_check_unsaved_selection(void);
|
||||
int zmk_physical_layouts_save_selected(void);
|
||||
int zmk_physical_layouts_revert_selected(void);
|
||||
|
||||
int zmk_physical_layouts_get_position_map(uint8_t source, uint8_t dest, uint32_t *map);
|
||||
Reference in New Issue
Block a user