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 <fabiobaltieri@google.com>
This commit is contained in:
parent
eef3e85c09
commit
06236ba883
11 changed files with 11 additions and 141 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ menuconfig KSCAN
|
|||
|
||||
if KSCAN
|
||||
|
||||
source "drivers/kscan/Kconfig.ht16k33"
|
||||
source "drivers/kscan/Kconfig.input"
|
||||
|
||||
module = KSCAN
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
# Copyright (c) 2019 - 2021 Henrik Brix Andersen <henrik@brixandersen.dk>
|
||||
# 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.
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 - 2021 Henrik Brix Andersen <henrik@brixandersen.dk>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT holtek_ht16k33_keyscan
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Keyscan driver for the HT16K33 I2C LED driver
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/drivers/kscan.h>
|
||||
#include <zephyr/drivers/led/ht16k33.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
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)
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@
|
|||
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/drivers/i2c.h>
|
||||
#include <zephyr/input/input.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/drivers/led.h>
|
||||
#include <zephyr/drivers/led/ht16k33.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
|
|
@ -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) {
|
||||
for (col = 0; col < HT16K33_KEYSCAN_COLS; col++) {
|
||||
if ((changed & BIT(col)) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (col = 0; col < HT16K33_KEYSCAN_COLS; col++) {
|
||||
if (changed & BIT(col)) {
|
||||
data->kscan_cb(data->child, row, col,
|
||||
state & BIT(col));
|
||||
}
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
description: Holtek HT16K33 keyscan
|
||||
|
||||
compatible: "holtek,ht16k33-keyscan"
|
||||
|
||||
include: base.yaml
|
||||
|
||||
on-bus: ht16k33
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Henrik Brix Andersen <henrik@brixandersen.dk>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_DRIVERS_LED_HT16K33_H_
|
||||
#define ZEPHYR_INCLUDE_DRIVERS_LED_HT16K33_H_
|
||||
|
||||
#include <zephyr/drivers/kscan.h>
|
||||
|
||||
/**
|
||||
* 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_ */
|
||||
|
|
@ -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";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue