diff --git a/boards/shields/rk055hdmipi4m/Kconfig.defconfig b/boards/shields/rk055hdmipi4m/Kconfig.defconfig index 4a95cdbd96..2ee4791d4d 100644 --- a/boards/shields/rk055hdmipi4m/Kconfig.defconfig +++ b/boards/shields/rk055hdmipi4m/Kconfig.defconfig @@ -19,7 +19,10 @@ if LVGL config KSCAN default y -config KSCAN_GT911_INTERRUPT +config INPUT + default y if KSCAN + +config INPUT_GT911_INTERRUPT default y config LV_Z_POINTER_KSCAN diff --git a/boards/shields/rk055hdmipi4m/rk055hdmipi4m.overlay b/boards/shields/rk055hdmipi4m/rk055hdmipi4m.overlay index 709048f8b7..ae1c42a521 100644 --- a/boards/shields/rk055hdmipi4m/rk055hdmipi4m.overlay +++ b/boards/shields/rk055hdmipi4m/rk055hdmipi4m.overlay @@ -8,12 +8,12 @@ /{ aliases { - kscan0 = &touch_controller; + kscan0 = &kscan_input_gt911; }; chosen { zephyr,display = &lcdif; - zephyr,keyboard-scan = &touch_controller; + zephyr,keyboard-scan = &kscan_input_gt911; }; en_mipi_display: enable-mipi-display { @@ -31,6 +31,10 @@ reg = <0x5d>; irq-gpios = <&nxp_mipi_connector 29 GPIO_ACTIVE_HIGH>; reset-gpios = <&nxp_mipi_connector 28 GPIO_ACTIVE_HIGH>; + + kscan_input_gt911: kscan-input { + compatible = "zephyr,kscan-input"; + }; }; }; diff --git a/drivers/input/CMakeLists.txt b/drivers/input/CMakeLists.txt index 32280c42e1..3872f182b3 100644 --- a/drivers/input/CMakeLists.txt +++ b/drivers/input/CMakeLists.txt @@ -6,6 +6,7 @@ zephyr_library_property(ALLOW_EMPTY TRUE) zephyr_library_sources_ifdef(CONFIG_INPUT_FT5336 input_ft5336.c) zephyr_library_sources_ifdef(CONFIG_INPUT_GPIO_KEYS input_gpio_keys.c) zephyr_library_sources_ifdef(CONFIG_INPUT_GPIO_QDEC input_gpio_qdec.c) +zephyr_library_sources_ifdef(CONFIG_INPUT_GT911 input_gt911.c) zephyr_library_sources_ifdef(CONFIG_INPUT_NPCX_KBD input_npcx_kbd.c) zephyr_library_sources_ifdef(CONFIG_INPUT_XPT2046 input_xpt2046.c) diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index 6e1d8abf5e..226c9c9d6c 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig @@ -8,6 +8,7 @@ menu "Input drivers" source "drivers/input/Kconfig.ft5336" source "drivers/input/Kconfig.gpio_keys" source "drivers/input/Kconfig.gpio_qdec" +source "drivers/input/Kconfig.gt911" source "drivers/input/Kconfig.npcx" source "drivers/input/Kconfig.sdl" source "drivers/input/Kconfig.xpt2046" diff --git a/drivers/kscan/Kconfig.gt911 b/drivers/input/Kconfig.gt911 similarity index 57% rename from drivers/kscan/Kconfig.gt911 rename to drivers/input/Kconfig.gt911 index 9179bb98d0..e4857463d2 100644 --- a/drivers/kscan/Kconfig.gt911 +++ b/drivers/input/Kconfig.gt911 @@ -2,28 +2,28 @@ # Copyright (c) 2020 Teslabs Engineering S.L. # SPDX-License-Identifier: Apache-2.0 -menuconfig KSCAN_GT911 +menuconfig INPUT_GT911 bool "GT9xx / GT9xxx capacitive touch panel driver" default y depends on DT_HAS_GOODIX_GT911_ENABLED select I2C help - Enable driver for multiple Goodix capacitive touch panel - controllers. This driver should support gt9110, gt912, - gt927, gt9271, gt928, gt967 + Enable driver for multiple Goodix capacitive touch panel controllers. + This driver should support gt9110, gt912, gt927, gt9271, gt928, + gt967. -if KSCAN_GT911 +if INPUT_GT911 -config KSCAN_GT911_PERIOD +config INPUT_GT911_PERIOD_MS int "Sample period" - depends on !KSCAN_GT911_INTERRUPT + depends on !INPUT_GT911_INTERRUPT default 10 help Sample period in milliseconds when in polling mode. -config KSCAN_GT911_INTERRUPT +config INPUT_GT911_INTERRUPT bool "Interrupt" help Enable interrupt support (requires GPIO). -endif # KSCAN_GT911 +endif # INPUT_GT911 diff --git a/drivers/kscan/kscan_gt911.c b/drivers/input/input_gt911.c similarity index 83% rename from drivers/kscan/kscan_gt911.c rename to drivers/input/input_gt911.c index ba4e875018..e2fd67188e 100644 --- a/drivers/kscan/kscan_gt911.c +++ b/drivers/input/input_gt911.c @@ -8,13 +8,13 @@ #define DT_DRV_COMPAT goodix_gt911 -#include -#include #include +#include +#include #include #include -LOG_MODULE_REGISTER(gt911, CONFIG_KSCAN_LOG_LEVEL); +LOG_MODULE_REGISTER(gt911, CONFIG_INPUT_LOG_LEVEL); /* GT911 used registers */ #define DEVICE_ID __bswap_16(0x8140U) @@ -45,11 +45,9 @@ struct gt911_config { struct gt911_data { /** Device pointer. */ const struct device *dev; - /** KSCAN Callback. */ - kscan_callback_t callback; /** Work queue (for deferred read). */ struct k_work work; -#ifdef CONFIG_KSCAN_GT911_INTERRUPT +#ifdef CONFIG_INPUT_GT911_INTERRUPT /** Interrupt GPIO callback. */ struct gpio_callback int_gpio_cb; #else @@ -73,7 +71,6 @@ struct gt911_point_reg_t { static int gt911_process(const struct device *dev) { const struct gt911_config *config = dev->config; - struct gt911_data *data = dev->data; int r; uint16_t reg_addr; @@ -124,7 +121,13 @@ static int gt911_process(const struct device *dev) LOG_DBG("pressed: %d, row: %d, col: %d", pressed, row, col); - data->callback(dev, row, col, pressed); + if (pressed) { + input_report_abs(dev, INPUT_ABS_X, col, false, K_FOREVER); + input_report_abs(dev, INPUT_ABS_Y, row, false, K_FOREVER); + input_report_key(dev, INPUT_BTN_TOUCH, 1, true, K_FOREVER); + } else { + input_report_key(dev, INPUT_BTN_TOUCH, 0, true, K_FOREVER); + } return 0; } @@ -136,7 +139,7 @@ static void gt911_work_handler(struct k_work *work) gt911_process(data->dev); } -#ifdef CONFIG_KSCAN_GT911_INTERRUPT +#ifdef CONFIG_INPUT_GT911_INTERRUPT static void gt911_isr_handler(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { @@ -153,52 +156,6 @@ static void gt911_timer_handler(struct k_timer *timer) } #endif -static int gt911_configure(const struct device *dev, - kscan_callback_t callback) -{ - struct gt911_data *data = dev->data; - - if (!callback) { - LOG_ERR("Invalid callback (NULL)"); - return -EINVAL; - } - - data->callback = callback; - - return 0; -} - -static int gt911_enable_callback(const struct device *dev) -{ - struct gt911_data *data = dev->data; - -#ifdef CONFIG_KSCAN_GT911_INTERRUPT - const struct gt911_config *config = dev->config; - - gpio_add_callback(config->int_gpio.port, &data->int_gpio_cb); -#else - k_timer_start(&data->timer, K_MSEC(CONFIG_KSCAN_GT911_PERIOD), - K_MSEC(CONFIG_KSCAN_GT911_PERIOD)); -#endif - - return 0; -} - -static int gt911_disable_callback(const struct device *dev) -{ - struct gt911_data *data = dev->data; - -#ifdef CONFIG_KSCAN_GT911_INTERRUPT - const struct gt911_config *config = dev->config; - - gpio_remove_callback(config->int_gpio.port, &data->int_gpio_cb); -#else - k_timer_stop(&data->timer); -#endif - - return 0; -} - static uint8_t gt911_get_firmware_checksum(const uint8_t *firmware) { uint8_t sum = 0; @@ -269,7 +226,7 @@ static int gt911_init(const struct device *dev) return r; } -#ifdef CONFIG_KSCAN_GT911_INTERRUPT +#ifdef CONFIG_INPUT_GT911_INTERRUPT r = gpio_pin_interrupt_configure_dt(&config->int_gpio, GPIO_INT_EDGE_TO_ACTIVE); if (r < 0) { @@ -320,15 +277,16 @@ static int gt911_init(const struct device *dev) return r; } +#ifdef CONFIG_INPUT_GT911_INTERRUPT + gpio_add_callback(config->int_gpio.port, &data->int_gpio_cb); +#else + k_timer_start(&data->timer, K_MSEC(CONFIG_INPUT_GT911_PERIOD_MS), + K_MSEC(CONFIG_INPUT_GT911_PERIOD_MS)); +#endif + return 0; } -static const struct kscan_driver_api gt911_driver_api = { - .config = gt911_configure, - .enable_callback = gt911_enable_callback, - .disable_callback = gt911_disable_callback, -}; - #define GT911_INIT(index) \ static const struct gt911_config gt911_config_##index = { \ .bus = I2C_DT_SPEC_INST_GET(index), \ @@ -338,7 +296,7 @@ static const struct kscan_driver_api gt911_driver_api = { static struct gt911_data gt911_data_##index; \ DEVICE_DT_INST_DEFINE(index, gt911_init, NULL, \ >911_data_##index, >911_config_##index, \ - POST_KERNEL, CONFIG_KSCAN_INIT_PRIORITY, \ - >911_driver_api); + POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, \ + NULL); DT_INST_FOREACH_STATUS_OKAY(GT911_INIT) diff --git a/drivers/kscan/CMakeLists.txt b/drivers/kscan/CMakeLists.txt index b9b150873c..2f27d65ff2 100644 --- a/drivers/kscan/CMakeLists.txt +++ b/drivers/kscan/CMakeLists.txt @@ -4,7 +4,6 @@ zephyr_syscall_header(${ZEPHYR_BASE}/include/zephyr/drivers/kscan.h) zephyr_library() -zephyr_library_sources_ifdef(CONFIG_KSCAN_GT911 kscan_gt911.c) zephyr_library_sources_ifdef(CONFIG_KSCAN_ITE_IT8XXX2 kscan_ite_it8xxx2.c) zephyr_library_sources_ifdef(CONFIG_KSCAN_XEC kscan_mchp_xec.c) zephyr_library_sources_ifdef(CONFIG_KSCAN_HT16K33 kscan_ht16k33.c) diff --git a/drivers/kscan/Kconfig b/drivers/kscan/Kconfig index c5fcee278d..4c08a2d888 100644 --- a/drivers/kscan/Kconfig +++ b/drivers/kscan/Kconfig @@ -10,7 +10,6 @@ menuconfig KSCAN if KSCAN -source "drivers/kscan/Kconfig.gt911" source "drivers/kscan/Kconfig.it8xxx2" source "drivers/kscan/Kconfig.xec" source "drivers/kscan/Kconfig.ht16k33" diff --git a/dts/bindings/kscan/goodix,gt911.yaml b/dts/bindings/input/goodix,gt911.yaml similarity index 85% rename from dts/bindings/kscan/goodix,gt911.yaml rename to dts/bindings/input/goodix,gt911.yaml index b363cb76e2..1222032f72 100644 --- a/dts/bindings/kscan/goodix,gt911.yaml +++ b/dts/bindings/input/goodix,gt911.yaml @@ -5,7 +5,7 @@ description: GT9xx / GT9xxx capacitive touch panels compatible: "goodix,gt911" -include: [kscan.yaml, i2c-device.yaml] +include: i2c-device.yaml properties: irq-gpios: diff --git a/samples/drivers/kscan/sample.yaml b/samples/drivers/kscan/sample.yaml index be0ea2e485..e276641711 100644 --- a/samples/drivers/kscan/sample.yaml +++ b/samples/drivers/kscan/sample.yaml @@ -14,15 +14,3 @@ tests: fixture: fixture_connect_keyboard depends_on: kscan filter: dt_chosen_enabled("zephyr,keyboard-scan") - sample.drivers.kscan.rk055hdmipi4m: - tags: drivers kscan - harness: console - harness_config: - type: multi_line - ordered: true - regex: - - "kb data(.*)" - fixture: fixture_connect_rk055hdmipi4m - depends_on: kscan - extra_args: SHIELD="rk055hdmipi4m" - platform_allow: mimxrt1170_evk_cm7 mimxrt595_evk_cm33 diff --git a/tests/drivers/build_all/input/app.overlay b/tests/drivers/build_all/input/app.overlay index 746b8a6e54..686da3a418 100644 --- a/tests/drivers/build_all/input/app.overlay +++ b/tests/drivers/build_all/input/app.overlay @@ -57,6 +57,13 @@ reg = <0x0>; int-gpios = <&test_gpio 0 0>; }; + + gt911@1 { + compatible = "goodix,gt911"; + reg = <0x1>; + irq-gpios = <&gpio0 0 0>; + reset-gpios = <&gpio0 0 0>; + }; }; spi@2 { diff --git a/tests/drivers/kscan/kscan_api/testcase.yaml b/tests/drivers/kscan/kscan_api/testcase.yaml index a4b390f734..2f37671d4c 100644 --- a/tests/drivers/kscan/kscan_api/testcase.yaml +++ b/tests/drivers/kscan/kscan_api/testcase.yaml @@ -14,8 +14,3 @@ tests: - kscan extra_args: CONF_FILE="mec15xxevb_assy6853.conf" platform_allow: mec15xxevb_assy6853 - drivers.kscan.rk055hdmipi4m: - tags: drivers kscan userspace - depends_on: kscan - extra_args: SHIELD="rk055hdmipi4m" - platform_allow: mimxrt1170_evk_cm7 mimxrt595_evk_cm33