Skip to content

Commit 2b489fd

Browse files
fabiobaltiericarlescufi
authored andcommitted
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 <[email protected]>
1 parent 57e0da4 commit 2b489fd

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

drivers/input/Kconfig.gpio_keys

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
config INPUT_GPIO_KEYS
5-
bool "Zephyr GPIO Keys"
5+
bool "GPIO Keys input driver"
66
default y
7-
depends on DT_HAS_ZEPHYR_GPIO_KEYS_ENABLED
7+
depends on DT_HAS_GPIO_KEYS_ENABLED || DT_HAS_ZEPHYR_GPIO_KEYS_ENABLED
88
depends on GPIO
99
help
10-
Enable support for Zephyr GPIO Keys.
10+
Enable support for GPIO Keys input driver.

drivers/input/input_gpio_keys.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
#include <zephyr/kernel.h>
1111
#include <zephyr/logging/log.h>
1212

13-
LOG_MODULE_REGISTER(zephyr_gpio_keys, CONFIG_INPUT_LOG_LEVEL);
14-
15-
#define DT_DRV_COMPAT zephyr_gpio_keys
13+
LOG_MODULE_REGISTER(gpio_keys, CONFIG_INPUT_LOG_LEVEL);
1614

1715
struct gpio_keys_callback {
1816
struct gpio_callback gpio_cb;
@@ -154,13 +152,18 @@ static int gpio_keys_init(const struct device *dev)
154152
return 0;
155153
}
156154

155+
#define GPIO_KEYS_CFG_CHECK(node_id) \
156+
BUILD_ASSERT(DT_NODE_HAS_PROP(node_id, zephyr_code), \
157+
"zephyr-code must be specified to use the input-gpio-keys driver");
158+
157159
#define GPIO_KEYS_CFG_DEF(node_id) \
158160
{ \
159161
.spec = GPIO_DT_SPEC_GET(node_id, gpios), \
160162
.zephyr_code = DT_PROP(node_id, zephyr_code), \
161163
}
162164

163165
#define GPIO_KEYS_INIT(i) \
166+
DT_INST_FOREACH_CHILD_STATUS_OKAY(i, GPIO_KEYS_CFG_CHECK); \
164167
static const struct gpio_keys_pin_config gpio_keys_pin_config_##i[] = { \
165168
DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(i, GPIO_KEYS_CFG_DEF, (,))}; \
166169
static struct gpio_keys_config gpio_keys_config_##i = { \
@@ -177,4 +180,9 @@ static int gpio_keys_init(const struct device *dev)
177180
&gpio_keys_config_##i, POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, \
178181
NULL);
179182

183+
#define DT_DRV_COMPAT gpio_keys
184+
DT_INST_FOREACH_STATUS_OKAY(GPIO_KEYS_INIT)
185+
186+
#undef DT_DRV_COMPAT
187+
#define DT_DRV_COMPAT zephyr_gpio_keys
180188
DT_INST_FOREACH_STATUS_OKAY(GPIO_KEYS_INIT)

dts/bindings/input/gpio-keys.yaml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
# Copyright (c) 2018, Linaro Limited
22
# SPDX-License-Identifier: Apache-2.0
33

4-
description: GPIO KEYS parent node
4+
description: |
5+
Zephyr Input GPIO KEYS parent node
6+
7+
This defines a group of buttons that can generate input events. Each button
8+
is defined in a child node of the gpio-keys node and defines a specific key
9+
code.
10+
11+
For example:
12+
13+
#include <zephyr/dt-bindings/input/input-event-codes.h>
14+
15+
/ {
16+
buttons {
17+
compatible = "gpio-keys";
18+
button_0 {
19+
gpios = <&gpio0 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
20+
zephyr,code = <INPUT_KEY_0>;
21+
};
22+
};
23+
};
24+
525
626
compatible: "gpio-keys"
727

@@ -26,5 +46,4 @@ child-binding:
2646
description: Descriptive name of the key
2747
zephyr,code:
2848
type: int
29-
default: 0
3049
description: Key code to emit.
Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,6 @@
11
# Copyright (c) 2022 Google LLC
22
# SPDX-License-Identifier: Apache-2.0
33

4-
description: |
5-
Zephyr Input GPIO KEYS parent node
6-
7-
This defines a group of buttons that can generate input events. Each button
8-
is defined in a child node of the zephyr,gpio-keys node and define a specific
9-
key code.
10-
11-
For example:
12-
13-
#include <zephyr/dt-bindings/input/input-event-codes.h>
14-
15-
/ {
16-
buttons {
17-
compatible = "zephyr,gpio-keys";
18-
button_0 {
19-
gpios = <&gpio0 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
20-
zephyr,code = <INPUT_KEY_0>;
21-
};
22-
};
23-
};
24-
254
compatible: "zephyr,gpio-keys"
265

276
include: [gpio-keys.yaml]
28-
29-
child-binding:
30-
properties:
31-
zephyr,code:
32-
required: true

0 commit comments

Comments
 (0)