input: unify gpio-keys and zephyr,gpio-keys
Change the gpio-keys and zephyr,gpio-keys so that they can both be used with the input subsystem driver. Make the zephyr,code property optional so that existing out of tree board can still use this node with their custom code, but change everything else so that an existin gpio-keys node can be used with the input driver as long as the codes are defined. From the application perspective, this means that the application can still use the GPIOs directly, the input specific driver only gets enabled if CONFIG_INPUT is enabled and the driver can always be turned off manually. This makes gpio-keys behave the same as gpio-leds with CONFIG_LED. Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
This commit is contained in:
parent
57e0da4d80
commit
2b489fd1f2
|
@ -2,9 +2,9 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config INPUT_GPIO_KEYS
|
||||
bool "Zephyr GPIO Keys"
|
||||
bool "GPIO Keys input driver"
|
||||
default y
|
||||
depends on DT_HAS_ZEPHYR_GPIO_KEYS_ENABLED
|
||||
depends on DT_HAS_GPIO_KEYS_ENABLED || DT_HAS_ZEPHYR_GPIO_KEYS_ENABLED
|
||||
depends on GPIO
|
||||
help
|
||||
Enable support for Zephyr GPIO Keys.
|
||||
Enable support for GPIO Keys input driver.
|
||||
|
|
|
@ -10,9 +10,7 @@
|
|||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
LOG_MODULE_REGISTER(zephyr_gpio_keys, CONFIG_INPUT_LOG_LEVEL);
|
||||
|
||||
#define DT_DRV_COMPAT zephyr_gpio_keys
|
||||
LOG_MODULE_REGISTER(gpio_keys, CONFIG_INPUT_LOG_LEVEL);
|
||||
|
||||
struct gpio_keys_callback {
|
||||
struct gpio_callback gpio_cb;
|
||||
|
@ -154,6 +152,10 @@ static int gpio_keys_init(const struct device *dev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#define GPIO_KEYS_CFG_CHECK(node_id) \
|
||||
BUILD_ASSERT(DT_NODE_HAS_PROP(node_id, zephyr_code), \
|
||||
"zephyr-code must be specified to use the input-gpio-keys driver");
|
||||
|
||||
#define GPIO_KEYS_CFG_DEF(node_id) \
|
||||
{ \
|
||||
.spec = GPIO_DT_SPEC_GET(node_id, gpios), \
|
||||
|
@ -161,6 +163,7 @@ static int gpio_keys_init(const struct device *dev)
|
|||
}
|
||||
|
||||
#define GPIO_KEYS_INIT(i) \
|
||||
DT_INST_FOREACH_CHILD_STATUS_OKAY(i, GPIO_KEYS_CFG_CHECK); \
|
||||
static const struct gpio_keys_pin_config gpio_keys_pin_config_##i[] = { \
|
||||
DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(i, GPIO_KEYS_CFG_DEF, (,))}; \
|
||||
static struct gpio_keys_config gpio_keys_config_##i = { \
|
||||
|
@ -177,4 +180,9 @@ static int gpio_keys_init(const struct device *dev)
|
|||
&gpio_keys_config_##i, POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, \
|
||||
NULL);
|
||||
|
||||
#define DT_DRV_COMPAT gpio_keys
|
||||
DT_INST_FOREACH_STATUS_OKAY(GPIO_KEYS_INIT)
|
||||
|
||||
#undef DT_DRV_COMPAT
|
||||
#define DT_DRV_COMPAT zephyr_gpio_keys
|
||||
DT_INST_FOREACH_STATUS_OKAY(GPIO_KEYS_INIT)
|
||||
|
|
|
@ -1,7 +1,27 @@
|
|||
# Copyright (c) 2018, Linaro Limited
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: GPIO KEYS parent node
|
||||
description: |
|
||||
Zephyr Input GPIO KEYS parent node
|
||||
|
||||
This defines a group of buttons that can generate input events. Each button
|
||||
is defined in a child node of the gpio-keys node and defines a specific key
|
||||
code.
|
||||
|
||||
For example:
|
||||
|
||||
#include <zephyr/dt-bindings/input/input-event-codes.h>
|
||||
|
||||
/ {
|
||||
buttons {
|
||||
compatible = "gpio-keys";
|
||||
button_0 {
|
||||
gpios = <&gpio0 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
zephyr,code = <INPUT_KEY_0>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
compatible: "gpio-keys"
|
||||
|
||||
|
@ -26,5 +46,4 @@ child-binding:
|
|||
description: Descriptive name of the key
|
||||
zephyr,code:
|
||||
type: int
|
||||
default: 0
|
||||
description: Key code to emit.
|
||||
|
|
|
@ -1,32 +1,6 @@
|
|||
# Copyright (c) 2022 Google LLC
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: |
|
||||
Zephyr Input GPIO KEYS parent node
|
||||
|
||||
This defines a group of buttons that can generate input events. Each button
|
||||
is defined in a child node of the zephyr,gpio-keys node and define a specific
|
||||
key code.
|
||||
|
||||
For example:
|
||||
|
||||
#include <zephyr/dt-bindings/input/input-event-codes.h>
|
||||
|
||||
/ {
|
||||
buttons {
|
||||
compatible = "zephyr,gpio-keys";
|
||||
button_0 {
|
||||
gpios = <&gpio0 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
zephyr,code = <INPUT_KEY_0>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
compatible: "zephyr,gpio-keys"
|
||||
|
||||
include: [gpio-keys.yaml]
|
||||
|
||||
child-binding:
|
||||
properties:
|
||||
zephyr,code:
|
||||
required: true
|
||||
|
|
Loading…
Reference in a new issue