Skip to content

Commit

Permalink
fix(core): Warn only with layouts + chosen transform
Browse files Browse the repository at this point in the history
* Instead of erroring out, simply ignore physical layouts if we
  detect a chosen matrix transform, and warn instead.
  • Loading branch information
petejohanson committed Sep 19, 2024
1 parent 1baf18d commit de38676
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
4 changes: 0 additions & 4 deletions app/include/zmk/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@

#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)];

Expand Down
21 changes: 19 additions & 2 deletions app/src/physical_layouts.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

#define DT_DRV_COMPAT zmk_physical_layout

#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)
#define USE_PHY_LAYOUTS \
(DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) && !DT_HAS_CHOSEN(zmk_matrix_transform))

#if USE_PHY_LAYOUTS

#define ZKPA_INIT(i, n) \
(const struct zmk_key_physical_attrs) { \
Expand Down Expand Up @@ -99,6 +102,13 @@ static const struct zmk_physical_layout *const layouts[] = {

#elif DT_HAS_CHOSEN(zmk_matrix_transform)

#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)

#warning \
"Ignoring the physical layouts and using the chosen matrix transform. Consider setting a chosen physical layout instead."

#endif

ZMK_MATRIX_TRANSFORM_EXTERN(DT_CHOSEN(zmk_matrix_transform));

static const struct zmk_physical_layout _CONCAT(_zmk_physical_layout_, chosen) = {
Expand All @@ -111,6 +121,13 @@ static const struct zmk_physical_layout *const layouts[] = {

#elif DT_HAS_CHOSEN(zmk_kscan)

#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)

#warning \
"Ignoring the physical layouts and using the chosen kscan with a synthetic transform. Consider setting a chosen physical layout instead."

#endif

ZMK_MATRIX_TRANSFORM_DEFAULT_EXTERN();
static const struct zmk_physical_layout _CONCAT(_zmk_physical_layout_, chosen) = {
.display_name = "Default",
Expand Down Expand Up @@ -252,7 +269,7 @@ static int8_t saved_selected_index = -1;
int zmk_physical_layouts_select_initial(void) {
const struct zmk_physical_layout *initial;

#if DT_HAS_CHOSEN(zmk_physical_layout)
#if USE_PHY_LAYOUTS && DT_HAS_CHOSEN(zmk_physical_layout)
initial = &_CONCAT(_zmk_physical_layout_, DT_CHOSEN(zmk_physical_layout));
#else
initial = layouts[0];
Expand Down

0 comments on commit de38676

Please sign in to comment.