Skip to content

Commit

Permalink
refactor(kscan): Auto enable kscan drivers
Browse files Browse the repository at this point in the history
The key scanning drivers are now automatically enabled when a DT node
with the matching "compatible" property is present and enabled, so they
no longer need to be manually set for each board.
  • Loading branch information
joelspadin authored and petejohanson committed Apr 26, 2022
1 parent a3a9510 commit 6d6efa3
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 58 deletions.
6 changes: 0 additions & 6 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,6 @@ config ZMK_KSCAN_EVENT_QUEUE_SIZE
int "Size of the event queue for KSCAN events to buffer events"
default 4

config ZMK_KSCAN_MOCK_DRIVER
bool "Enable mock kscan driver to simulate key presses"

config ZMK_KSCAN_COMPOSITE_DRIVER
bool "Enable composite kscan driver to combine kscan devices"

#KSCAN Settings
endmenu

Expand Down
3 changes: 0 additions & 3 deletions app/boards/arm/ferris/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,4 @@ config ZMK_USB
config ZMK_KSCAN_MATRIX_POLLING
default y

config ZMK_KSCAN_COMPOSITE_DRIVER
default y

endif # BOARD_FERRIS
2 changes: 0 additions & 2 deletions app/boards/arm/ferris/ferris_rev02_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ CONFIG_I2C=y

# ZMK Settings
CONFIG_ZMK_USB=y
CONFIG_ZMK_KSCAN_GPIO_DRIVER=y
CONFIG_ZMK_KSCAN_COMPOSITE_DRIVER=y
CONFIG_ZMK_KSCAN_MATRIX_POLLING=y
CONFIG_USB_SELF_POWERED=n

Expand Down
3 changes: 0 additions & 3 deletions app/boards/native_posix.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CONFIG_KSCAN=n
CONFIG_ZMK_KSCAN_MOCK_DRIVER=y
CONFIG_ZMK_KSCAN_GPIO_DRIVER=n
CONFIG_GPIO=n
CONFIG_ZMK_BLE=n
CONFIG_LOG=y
Expand Down
3 changes: 0 additions & 3 deletions app/boards/native_posix_64.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CONFIG_KSCAN=n
CONFIG_ZMK_KSCAN_MOCK_DRIVER=y
CONFIG_ZMK_KSCAN_GPIO_DRIVER=n
CONFIG_GPIO=n
# Enable to have the native posix build expose USBIP device(s)
# CONFIG_ZMK_USB=y
Expand Down
6 changes: 3 additions & 3 deletions app/drivers/kscan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ zephyr_library_named(zmk__drivers__kscan)
zephyr_library_include_directories(${CMAKE_SOURCE_DIR}/include)

zephyr_library_sources_ifdef(CONFIG_ZMK_KSCAN_GPIO_DRIVER debounce.c)
zephyr_library_sources_ifdef(CONFIG_ZMK_KSCAN_GPIO_DRIVER kscan_gpio_matrix.c)
zephyr_library_sources_ifdef(CONFIG_ZMK_KSCAN_GPIO_DRIVER kscan_gpio_direct.c)
zephyr_library_sources_ifdef(CONFIG_ZMK_KSCAN_GPIO_DRIVER kscan_gpio_demux.c)
zephyr_library_sources_ifdef(CONFIG_ZMK_KSCAN_GPIO_MATRIX kscan_gpio_matrix.c)
zephyr_library_sources_ifdef(CONFIG_ZMK_KSCAN_GPIO_DIRECT kscan_gpio_direct.c)
zephyr_library_sources_ifdef(CONFIG_ZMK_KSCAN_GPIO_DEMUX kscan_gpio_demux.c)
zephyr_library_sources_ifdef(CONFIG_ZMK_KSCAN_MOCK_DRIVER kscan_mock.c)
zephyr_library_sources_ifdef(CONFIG_ZMK_KSCAN_COMPOSITE_DRIVER kscan_composite.c)
32 changes: 30 additions & 2 deletions app/drivers/kscan/Kconfig
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
# Copyright (c) 2020 The ZMK Contributors
# SPDX-License-Identifier: MIT

DT_COMPAT_ZMK_KSCAN_COMPOSITE := zmk,kscan-composite
DT_COMPAT_ZMK_KSCAN_GPIO_DEMUX := zmk,kscan-gpio-demux
DT_COMPAT_ZMK_KSCAN_GPIO_DIRECT := zmk,kscan-gpio-direct
DT_COMPAT_ZMK_KSCAN_GPIO_MATRIX := zmk,kscan-gpio-matrix
DT_COMPAT_ZMK_KSCAN_MOCK := zmk,kscan-mock

config ZMK_KSCAN_COMPOSITE_DRIVER
bool
default $(dt_compat_enabled,$(DT_COMPAT_ZMK_KSCAN_COMPOSITE))

config ZMK_KSCAN_GPIO_DRIVER
bool "Enable GPIO kscan driver to detect key presses"
default y
bool
select GPIO

config ZMK_KSCAN_GPIO_DEMUX
bool
default $(dt_compat_enabled,$(DT_COMPAT_ZMK_KSCAN_GPIO_DEMUX))
select ZMK_KSCAN_GPIO_DRIVER

config ZMK_KSCAN_GPIO_DIRECT
bool
default $(dt_compat_enabled,$(DT_COMPAT_ZMK_KSCAN_GPIO_DIRECT))
select ZMK_KSCAN_GPIO_DRIVER

config ZMK_KSCAN_GPIO_MATRIX
bool
default $(dt_compat_enabled,$(DT_COMPAT_ZMK_KSCAN_GPIO_MATRIX))
select ZMK_KSCAN_GPIO_DRIVER

config ZMK_KSCAN_MOCK_DRIVER
bool
default $(dt_compat_enabled,$(DT_COMPAT_ZMK_KSCAN_MOCK))

if ZMK_KSCAN_GPIO_DRIVER

config ZMK_KSCAN_MATRIX_POLLING
Expand Down
4 changes: 0 additions & 4 deletions app/drivers/kscan/kscan_gpio_demux.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)

struct kscan_gpio_item_config {
char *label;
gpio_pin_t pin;
Expand Down Expand Up @@ -251,5 +249,3 @@ struct kscan_gpio_item_config {
&gpio_driver_api_##n);

DT_INST_FOREACH_STATUS_OKAY(GPIO_INST_INIT)

#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */
4 changes: 0 additions & 4 deletions app/drivers/kscan/kscan_gpio_direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)

struct kscan_gpio_item_config {
char *label;
gpio_pin_t pin;
Expand Down Expand Up @@ -242,5 +240,3 @@ static const struct kscan_driver_api gpio_driver_api = {
&gpio_driver_api);

DT_INST_FOREACH_STATUS_OKAY(GPIO_INST_INIT)

#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */
4 changes: 0 additions & 4 deletions app/drivers/kscan/kscan_gpio_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

#define DT_DRV_COMPAT zmk_kscan_gpio_matrix

#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)

#define INST_DIODE_DIR(n) DT_ENUM_IDX(DT_DRV_INST(n), diode_direction)
#define COND_DIODE_DIR(n, row2col_code, col2row_code) \
COND_CODE_0(INST_DIODE_DIR(n), row2col_code, col2row_code)
Expand Down Expand Up @@ -463,5 +461,3 @@ static const struct kscan_driver_api kscan_matrix_api = {
CONFIG_APPLICATION_INIT_PRIORITY, &kscan_matrix_api);

DT_INST_FOREACH_STATUS_OKAY(KSCAN_MATRIX_INIT);

#endif // DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)
3 changes: 0 additions & 3 deletions app/tests/backlight/basic/native_posix_64.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CONFIG_KSCAN=n
CONFIG_ZMK_KSCAN_MOCK_DRIVER=y
CONFIG_ZMK_KSCAN_GPIO_DRIVER=n
CONFIG_GPIO=y
CONFIG_GPIO_EMUL=y
CONFIG_ZMK_BLE=n
Expand Down
3 changes: 0 additions & 3 deletions app/tests/backlight/config-brt/native_posix_64.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CONFIG_KSCAN=n
CONFIG_ZMK_KSCAN_MOCK_DRIVER=y
CONFIG_ZMK_KSCAN_GPIO_DRIVER=n
CONFIG_GPIO=y
CONFIG_GPIO_EMUL=y
CONFIG_ZMK_BLE=n
Expand Down
3 changes: 0 additions & 3 deletions app/tests/backlight/config-on/native_posix_64.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CONFIG_KSCAN=n
CONFIG_ZMK_KSCAN_MOCK_DRIVER=y
CONFIG_ZMK_KSCAN_GPIO_DRIVER=n
CONFIG_GPIO=y
CONFIG_GPIO_EMUL=y
CONFIG_ZMK_BLE=n
Expand Down
3 changes: 0 additions & 3 deletions app/tests/backlight/config-step/native_posix_64.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CONFIG_KSCAN=n
CONFIG_ZMK_KSCAN_MOCK_DRIVER=y
CONFIG_ZMK_KSCAN_GPIO_DRIVER=n
CONFIG_GPIO=y
CONFIG_GPIO_EMUL=y
CONFIG_ZMK_BLE=n
Expand Down
3 changes: 0 additions & 3 deletions app/tests/backlight/cycle/native_posix_64.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CONFIG_KSCAN=n
CONFIG_ZMK_KSCAN_MOCK_DRIVER=y
CONFIG_ZMK_KSCAN_GPIO_DRIVER=n
CONFIG_GPIO=y
CONFIG_GPIO_EMUL=y
CONFIG_ZMK_BLE=n
Expand Down
3 changes: 0 additions & 3 deletions app/tests/backlight/low-brightness/native_posix_64.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CONFIG_KSCAN=n
CONFIG_ZMK_KSCAN_MOCK_DRIVER=y
CONFIG_ZMK_KSCAN_GPIO_DRIVER=n
CONFIG_GPIO=y
CONFIG_GPIO_EMUL=y
CONFIG_ZMK_BLE=n
Expand Down
3 changes: 0 additions & 3 deletions app/tests/wpm/1-single_keypress/native_posix_64.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CONFIG_KSCAN=n
CONFIG_ZMK_KSCAN_MOCK_DRIVER=y
CONFIG_ZMK_KSCAN_GPIO_DRIVER=n
CONFIG_GPIO=n
CONFIG_ZMK_BLE=n
CONFIG_LOG=y
Expand Down
3 changes: 0 additions & 3 deletions app/tests/wpm/2-multiple_keypress/native_posix_64.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CONFIG_KSCAN=n
CONFIG_ZMK_KSCAN_MOCK_DRIVER=y
CONFIG_ZMK_KSCAN_GPIO_DRIVER=n
CONFIG_GPIO=n
CONFIG_ZMK_BLE=n
CONFIG_LOG=y
Expand Down

0 comments on commit 6d6efa3

Please sign in to comment.