From 21dc825c0c065cfc9d50261320858d9160f0b434 Mon Sep 17 00:00:00 2001 From: down Date: Sat, 23 Jul 2022 01:19:07 +0700 Subject: [PATCH] Revert "feat(kscan): remove property input-gpios" This reverts commit 9935fb29d2f312c812ea7ed5729e96afd8047fa6. --- .../kscan/kscan_gpio_round_robin_matrix.c | 20 +++++++------------ .../zmk,kscan-gpio-round-robin-matrix.yaml | 5 ++++- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/drivers/kscan/kscan_gpio_round_robin_matrix.c b/app/drivers/kscan/kscan_gpio_round_robin_matrix.c index 8cfd622d..def9c804 100644 --- a/app/drivers/kscan/kscan_gpio_round_robin_matrix.c +++ b/app/drivers/kscan/kscan_gpio_round_robin_matrix.c @@ -19,8 +19,9 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #define DT_DRV_COMPAT zmk_kscan_gpio_round_robin_matrix -#define INST_GPIOS_LEN(n) DT_INST_PROP_LEN(n, gpios) -#define INST_MATRIX_LEN(n) (INST_GPIOS_LEN(n) * INST_GPIOS_LEN(n)) +#define INST_INPUTS_LEN(n) DT_INST_PROP_LEN(n, input_gpios) +#define INST_OUTPUTS_LEN(n) DT_INST_PROP_LEN(n, output_gpios) +#define INST_MATRIX_LEN(n) (INST_INPUTS_LEN(n) * INST_OUTPUTS_LEN(n)) #if CONFIG_ZMK_KSCAN_DEBOUNCE_PRESS_MS >= 0 #define INST_DEBOUNCE_PRESS_MS(n) CONFIG_ZMK_KSCAN_DEBOUNCE_PRESS_MS @@ -36,17 +37,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); DT_INST_PROP(n, debounce_release_ms) #endif -#define KSCAN_GPIO_ITEM_CFG_INIT(node_id, prop, idx, flags) \ - { \ - .port = DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx)), \ - .pin = DT_GPIO_PIN_BY_IDX(node_id, prop, idx), \ - .dt_flags = flags, \ - }, - #define KSCAN_GPIO_INPUT_CFG_INIT(idx, inst_idx) \ - KSCAN_GPIO_ITEM_CFG_INIT(DT_DRV_INST(inst_idx), gpios, idx, \ - (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)) - + GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst_idx), input_gpios, idx), #define KSCAN_GPIO_OUTPUT_CFG_INIT(idx, inst_idx) \ KSCAN_GPIO_ITEM_CFG_INIT(DT_DRV_INST(inst_idx), gpios, idx, GPIO_ACTIVE_HIGH) @@ -209,13 +201,15 @@ static const struct kscan_driver_api kscan_round_robin_matrix_api = { }; #define KSCAN_ROUND_ROBIN_MATRIX_INIT(n) \ + BUILD_ASSERT(INST_INPUTS_LEN(n) == INST_OUTPUTS_LEN(n), \ + "the number of input-gpios must be equal to output-gpios"); \ BUILD_ASSERT(INST_DEBOUNCE_PRESS_MS(n) <= DEBOUNCE_COUNTER_MAX, \ "ZMK_KSCAN_DEBOUNCE_PRESS_MS or debounce-press-ms is too large"); \ BUILD_ASSERT(INST_DEBOUNCE_RELEASE_MS(n) <= DEBOUNCE_COUNTER_MAX, \ "ZMK_KSCAN_DEBOUNCE_RELEASE_MS or debounce-release-ms is too large"); \ \ static const struct gpio_dt_spec kscan_round_robin_matrix_inputs_##n[] = { \ - UTIL_LISTIFY(INST_GPIOS_LEN(n), KSCAN_GPIO_INPUT_CFG_INIT, n)}; \ + UTIL_LISTIFY(INST_INPUTS_LEN(n), KSCAN_GPIO_INPUT_CFG_INIT, n)}; \ \ static const struct gpio_dt_spec kscan_round_robin_matrix_outputs_##n[] = { \ UTIL_LISTIFY(INST_GPIOS_LEN(n), KSCAN_GPIO_OUTPUT_CFG_INIT, n)}; \ diff --git a/app/drivers/zephyr/dts/bindings/kscan/zmk,kscan-gpio-round-robin-matrix.yaml b/app/drivers/zephyr/dts/bindings/kscan/zmk,kscan-gpio-round-robin-matrix.yaml index 488c967e..686fb418 100644 --- a/app/drivers/zephyr/dts/bindings/kscan/zmk,kscan-gpio-round-robin-matrix.yaml +++ b/app/drivers/zephyr/dts/bindings/kscan/zmk,kscan-gpio-round-robin-matrix.yaml @@ -8,7 +8,10 @@ compatible: "zmk,kscan-gpio-round-robin-matrix" include: kscan.yaml properties: - gpios: + input-gpios: + type: phandle-array + required: true + output-gpios: type: phandle-array required: true debounce-press-ms: