From 06236ba883a4e1f080cb354d71645280067ec7ae Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Wed, 6 Mar 2024 16:22:20 +0000 Subject: [PATCH] drivers: ht16k33: convert from kscan to input Convert the ht16k33 to use the input subsystem. This can still be used with the kscan API with the zephyr,kscan-input driver, or use the input-keymap one to generate input codes instead. Signed-off-by: Fabio Baltieri --- drivers/kscan/CMakeLists.txt | 1 - drivers/kscan/Kconfig | 1 - drivers/kscan/Kconfig.ht16k33 | 13 ---- drivers/kscan/kscan_ht16k33.c | 63 ------------------- drivers/led/Kconfig.ht16k33 | 3 +- drivers/led/ht16k33.c | 29 ++------- .../kscan/holtek,ht16k33-keyscan.yaml | 7 --- include/zephyr/drivers/led/ht16k33.h | 27 -------- .../boards/nrf52840dk_nrf52840.overlay | 4 +- samples/drivers/ht16k33/prj.conf | 2 +- samples/drivers/ht16k33/src/main.c | 2 +- 11 files changed, 11 insertions(+), 141 deletions(-) delete mode 100644 drivers/kscan/Kconfig.ht16k33 delete mode 100644 drivers/kscan/kscan_ht16k33.c delete mode 100644 dts/bindings/kscan/holtek,ht16k33-keyscan.yaml delete mode 100644 include/zephyr/drivers/led/ht16k33.h diff --git a/drivers/kscan/CMakeLists.txt b/drivers/kscan/CMakeLists.txt index 5e846edcb36..1108cd61629 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_HT16K33 kscan_ht16k33.c) zephyr_library_sources_ifdef(CONFIG_KSCAN_INPUT kscan_input.c) zephyr_library_sources_ifdef(CONFIG_USERSPACE kscan_handlers.c) diff --git a/drivers/kscan/Kconfig b/drivers/kscan/Kconfig index de9b79255ea..ed0910bbd27 100644 --- a/drivers/kscan/Kconfig +++ b/drivers/kscan/Kconfig @@ -10,7 +10,6 @@ menuconfig KSCAN if KSCAN -source "drivers/kscan/Kconfig.ht16k33" source "drivers/kscan/Kconfig.input" module = KSCAN diff --git a/drivers/kscan/Kconfig.ht16k33 b/drivers/kscan/Kconfig.ht16k33 deleted file mode 100644 index ef16347ede2..00000000000 --- a/drivers/kscan/Kconfig.ht16k33 +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2019 - 2021 Henrik Brix Andersen -# SPDX-License-Identifier: Apache-2.0 - -config KSCAN_HT16K33 - bool "HT16K33 keyscan driver" - default y - depends on DT_HAS_HOLTEK_HT16K33_KEYSCAN_ENABLED - help - Enable keyscan driver for HT16K33. - - The HT16K33 is a memory mapping, multifunction LED - controller driver. The controller supports matrix key scan - circuit of up to 13x3 keys. diff --git a/drivers/kscan/kscan_ht16k33.c b/drivers/kscan/kscan_ht16k33.c deleted file mode 100644 index 9595874e908..00000000000 --- a/drivers/kscan/kscan_ht16k33.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2019 - 2021 Henrik Brix Andersen - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#define DT_DRV_COMPAT holtek_ht16k33_keyscan - -/** - * @file - * @brief Keyscan driver for the HT16K33 I2C LED driver - */ - -#include -#include -#include -#include - -LOG_MODULE_REGISTER(kscan_ht16k33, CONFIG_KSCAN_LOG_LEVEL); - -BUILD_ASSERT(CONFIG_KSCAN_INIT_PRIORITY > CONFIG_LED_INIT_PRIORITY, - "HT16K33 keyscan driver must be initialized after HT16K33 LED driver"); - -struct kscan_ht16k33_cfg { - const struct device *parent; -}; - -static int kscan_ht16k33_config(const struct device *dev, - kscan_callback_t callback) -{ - const struct kscan_ht16k33_cfg *config = dev->config; - - return ht16k33_register_keyscan_callback(config->parent, dev, callback); -} - -static int kscan_ht16k33_init(const struct device *dev) -{ - const struct kscan_ht16k33_cfg *config = dev->config; - - if (!device_is_ready(config->parent)) { - LOG_ERR("HT16K33 parent device not ready"); - return -EINVAL; - } - - return 0; -} - -static const struct kscan_driver_api kscan_ht16k33_api = { - .config = kscan_ht16k33_config, -}; - -#define KSCAN_HT16K33_DEVICE(id) \ - static const struct kscan_ht16k33_cfg kscan_ht16k33_##id##_cfg = { \ - .parent = DEVICE_DT_GET(DT_INST_BUS(id)), \ - }; \ - \ - DEVICE_DT_INST_DEFINE(id, &kscan_ht16k33_init, \ - NULL, NULL, \ - &kscan_ht16k33_##id##_cfg, POST_KERNEL, \ - CONFIG_KSCAN_INIT_PRIORITY, \ - &kscan_ht16k33_api); - -DT_INST_FOREACH_STATUS_OKAY(KSCAN_HT16K33_DEVICE) diff --git a/drivers/led/Kconfig.ht16k33 b/drivers/led/Kconfig.ht16k33 index 6fd72d53837..1addae0436b 100644 --- a/drivers/led/Kconfig.ht16k33 +++ b/drivers/led/Kconfig.ht16k33 @@ -15,8 +15,7 @@ menuconfig HT16K33 config HT16K33_KEYSCAN bool "Keyscan support" - depends on (HT16K33 && KSCAN) - select KSCAN_HT16K33 + depends on (HT16K33 && INPUT) help Enable keyscan child device support in the HT16K33 LED driver. diff --git a/drivers/led/ht16k33.c b/drivers/led/ht16k33.c index 8df5b7553f6..07a1ae56ca1 100644 --- a/drivers/led/ht16k33.c +++ b/drivers/led/ht16k33.c @@ -13,9 +13,9 @@ #include #include +#include #include #include -#include #include #include @@ -77,7 +77,6 @@ struct ht16k33_data { #ifdef CONFIG_HT16K33_KEYSCAN struct k_mutex lock; const struct device *child; - kscan_callback_t kscan_cb; struct gpio_callback irq_cb; struct k_thread irq_thread; struct k_sem irq_sem; @@ -230,15 +229,13 @@ static bool ht16k33_process_keyscan_data(const struct device *dev) pressed = true; } - if (data->kscan_cb == NULL) { - continue; - } - for (col = 0; col < HT16K33_KEYSCAN_COLS; col++) { - if (changed & BIT(col)) { - data->kscan_cb(data->child, row, col, - state & BIT(col)); + if ((changed & BIT(col)) == 0) { + continue; } + 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, state & BIT(col), true, K_FOREVER); } } @@ -285,20 +282,6 @@ static void ht16k33_timer_callback(struct k_timer *timer) data = CONTAINER_OF(timer, struct ht16k33_data, timer); k_sem_give(&data->irq_sem); } - -int ht16k33_register_keyscan_callback(const struct device *parent, - const struct device *child, - kscan_callback_t callback) -{ - struct ht16k33_data *data = parent->data; - - k_mutex_lock(&data->lock, K_FOREVER); - data->child = child; - data->kscan_cb = callback; - k_mutex_unlock(&data->lock); - - return 0; -} #endif /* CONFIG_HT16K33_KEYSCAN */ static int ht16k33_init(const struct device *dev) diff --git a/dts/bindings/kscan/holtek,ht16k33-keyscan.yaml b/dts/bindings/kscan/holtek,ht16k33-keyscan.yaml deleted file mode 100644 index d39278fb66e..00000000000 --- a/dts/bindings/kscan/holtek,ht16k33-keyscan.yaml +++ /dev/null @@ -1,7 +0,0 @@ -description: Holtek HT16K33 keyscan - -compatible: "holtek,ht16k33-keyscan" - -include: base.yaml - -on-bus: ht16k33 diff --git a/include/zephyr/drivers/led/ht16k33.h b/include/zephyr/drivers/led/ht16k33.h deleted file mode 100644 index bc43b52a4be..00000000000 --- a/include/zephyr/drivers/led/ht16k33.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2019 Henrik Brix Andersen - * - * SPDX-License-Identifier: Apache-2.0 - */ - - -#ifndef ZEPHYR_INCLUDE_DRIVERS_LED_HT16K33_H_ -#define ZEPHYR_INCLUDE_DRIVERS_LED_HT16K33_H_ - -#include - -/** - * Register a HT16K33 keyscan device to be notified of relevant - * keyscan events by the keyscan interrupt thread in the HT16K33 - * parent driver. - * - * @param parent HT16K33 parent device. - * @param child HT16K33 child device. - * @param callback Keyscan callback function. - * @return 0 if successful, negative errno code on failure. - */ -int ht16k33_register_keyscan_callback(const struct device *parent, - const struct device *child, - kscan_callback_t callback); - -#endif /* ZEPHYR_INCLUDE_DRIVERS_LED_HT16K33_H_ */ diff --git a/samples/drivers/ht16k33/boards/nrf52840dk_nrf52840.overlay b/samples/drivers/ht16k33/boards/nrf52840dk_nrf52840.overlay index 8618745dcf5..c9f820cdb58 100644 --- a/samples/drivers/ht16k33/boards/nrf52840dk_nrf52840.overlay +++ b/samples/drivers/ht16k33/boards/nrf52840dk_nrf52840.overlay @@ -13,8 +13,8 @@ /* Uncomment to use IRQ instead of polling: */ /* irq-gpios = <&gpio1 8 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; */ - keyscan { - compatible = "holtek,ht16k33-keyscan"; + kscan-input { + compatible = "zephyr,kscan-input"; }; }; }; diff --git a/samples/drivers/ht16k33/prj.conf b/samples/drivers/ht16k33/prj.conf index 462075dc5f6..fb580b93002 100644 --- a/samples/drivers/ht16k33/prj.conf +++ b/samples/drivers/ht16k33/prj.conf @@ -2,5 +2,5 @@ CONFIG_LOG=y CONFIG_I2C=y CONFIG_LED=y CONFIG_KSCAN=y -CONFIG_KSCAN_INIT_PRIORITY=95 +CONFIG_INPUT=y CONFIG_HT16K33_KEYSCAN=y diff --git a/samples/drivers/ht16k33/src/main.c b/samples/drivers/ht16k33/src/main.c index 72ef587cb39..7ede8c6a0d3 100644 --- a/samples/drivers/ht16k33/src/main.c +++ b/samples/drivers/ht16k33/src/main.c @@ -13,7 +13,7 @@ LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL); #define LED_NODE DT_COMPAT_GET_ANY_STATUS_OKAY(holtek_ht16k33) -#define KEY_NODE DT_CHILD(LED_NODE, keyscan) +#define KEY_NODE DT_CHILD(LED_NODE, kscan_input) static void keyscan_callback(const struct device *dev, uint32_t row, uint32_t column, bool pressed)