Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832-pinctrl.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@

i2c0_default: i2c0_default {
group1 {
psels = <NRF_PSEL(TWIM_SDA, 0, 26)>,
<NRF_PSEL(TWIM_SCL, 0, 27)>;
psels = <NRF_PSEL(TWIM_SDA, 0, 27)>,
<NRF_PSEL(TWIM_SCL, 0, 26)>;
};
};

i2c0_sleep: i2c0_sleep {
group1 {
psels = <NRF_PSEL(TWIM_SDA, 0, 26)>,
<NRF_PSEL(TWIM_SCL, 0, 27)>;
psels = <NRF_PSEL(TWIM_SDA, 0, 27)>,
<NRF_PSEL(TWIM_SCL, 0, 26)>;
low-power-enable;
};
};
Expand Down
60 changes: 58 additions & 2 deletions boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/dts-v1/;
#include <nordic/nrf52832_qfaa.dtsi>
#include <dt-bindings/input/input-event-codes.h>
#include "nrf52dk_nrf52832-pinctrl.dtsi"

/ {
Expand All @@ -22,6 +23,26 @@
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,keyboard-scan = &kscan_adapter;
};

kscan_adapter: kscan-adapter {
compatible = "zephyr,kscan-adapter";
input = <&ft5336>;
};

abs-to-rel {
compatible = "zephyr,input-abs-to-rel";
input = <&qdec>;
};

longpress {
compatible = "zephyr,input-longpress";
input = <&buttons>;
input-code = <INPUT_KEY_3>;
short-code = <INPUT_KEY_A>;
long-codes = <INPUT_KEY_B>, <INPUT_KEY_C>, <INPUT_KEY_D>;
long-delays-ms = <500>, <1000>, <2000>;
};

leds {
Expand Down Expand Up @@ -51,23 +72,27 @@
};
};

buttons {
compatible = "gpio-keys";
buttons: buttons {
compatible = "zephyr,gpio-keys";
button0: button_0 {
gpios = <&gpio0 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "Push button switch 0";
zephyr,code = <INPUT_KEY_0>;
};
button1: button_1 {
gpios = <&gpio0 14 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "Push button switch 1";
zephyr,code = <INPUT_KEY_1>;
};
button2: button_2 {
gpios = <&gpio0 15 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "Push button switch 2";
zephyr,code = <INPUT_KEY_2>;
};
button3: button_3 {
gpios = <&gpio0 16 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "Push button switch 3";
zephyr,code = <INPUT_KEY_3>;
};
};

Expand Down Expand Up @@ -128,6 +153,31 @@
watchdog0 = &wdt0;
};
};
&pinctrl {
qdec_default: qdec_default {
group1 {
psels = <NRF_PSEL(QDEC_A, 0, 29)>,
<NRF_PSEL(QDEC_B, 0, 31)>;
};
};

qdec_sleep: qdec_sleep {
group1 {
psels = <NRF_PSEL(QDEC_A, 0, 29)>,
<NRF_PSEL(QDEC_B, 0, 31)>;
low-power-enable;
};
};
};

&qdec {
status = "okay";
led-pre = <0>;
steps = <360>;
pinctrl-0 = <&qdec_default>;
pinctrl-1 = <&qdec_sleep>;
pinctrl-names = "default", "sleep";
};

&adc {
status = "okay";
Expand Down Expand Up @@ -156,6 +206,12 @@ arduino_i2c: &i2c0 {
pinctrl-0 = <&i2c0_default>;
pinctrl-1 = <&i2c0_sleep>;
pinctrl-names = "default", "sleep";

ft5336: ft5336@38 {
compatible = "focaltech,ft5336";
reg = <0x38>;
int-gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
};
};

&i2c1 {
Expand Down
1 change: 1 addition & 0 deletions doc/services/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ OS Services
file_system/index.rst
formatted_output.rst
ipc/index.rst
input/index.rst
logging/index.rst
tracing/index.rst
resource_management/index.rst
Expand Down
73 changes: 73 additions & 0 deletions doc/services/input/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
.. _input:

Input
#####

The input subsystem provides an API for dispatching input events from input
devices to the application.

Input Events
************

The subsystem is built around the :c:struct:`input_event` structure. An input
event represents a change in an individual event entity, for example the state
of a single button, or a movement in a single axis.

The :c:struct:`input_event` structure describes the specific event, and
includes a synchronization bit to indicate that the device reached a stable
state, for example when the events corresponding to multiple axes of a
multi-axis device have been reported.

Input Drivers
*************

An input device can report input events directly using any of the
:c:func:`input_report` functions, for example buttons or other on-off input
devices would use :c:func:`input_report_key`.

Complex devices may use a combination of multiple events, and set the ``sync``
bit once the output is stable.

The :c:func:`input_report` functions take a :c:struct:`device` pointer, which
is used to indicate which device reported the event and can be used by
subscribers to only receive events from a specific device. If there's no actual
device associated with the event, it can be set to ``NULL``, in which case only
subscribers with no device filter will receive the event.

Application API
***************

An application can register a callback using the
:c:func:`INPUT_LISTENER_CB_DEFINE` macro. If a device node is specified, the
callback is only invoked for events from the specific device, otherwise the
callback will receive all the events in the system. This is the only type of
filtering supported, any more complex filtering logic has to be implemented in
the callback itself.

The subsystem can operate synchronously or by using an event queue, depending
on the :kconfig:option:`CONFIG_INPUT_THREAD` option. If the input thread is
used, all the events are added to a queue and executed in a common ``input``
thread. If the thread is not used, the callback are invoked directly in the
input driver context.

The synchronous mode can be used in a simple application to keep a minimal
footprint, or in a complex application with an existing event model, where the
callback is just a wrapper to pipe back the event in a more complex application
specific event system.

Kscan Compatibility
*******************

Input devices generating X/Y/Touch events can be used in existing applications
based on the :ref:`kscan_api` API by defining a
:dtcompatible:`zephyr,kscan-adapter` node.

API Reference
*************

.. doxygengroup:: input_interface

Driver API Reference
********************

.. doxygengroup:: input_driver_interface
1 change: 1 addition & 0 deletions drivers/gpio/Kconfig.zephyr
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ config GPIO_KEYS_ZEPHYR
bool "Zephyr GPIO Keys"
default y
depends on DT_HAS_ZEPHYR_GPIO_KEYS_ENABLED
select INPUT
help
Enable support for Zephyr GPIO Keys.
14 changes: 7 additions & 7 deletions drivers/gpio/gpio_keys_zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
*/

#include <zephyr/device.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/input.h>
#include <zephyr/drivers/gpio_keys.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/input/input.h>

LOG_MODULE_REGISTER(zephyr_gpio_keys, CONFIG_GPIO_LOG_LEVEL);

Expand Down Expand Up @@ -61,7 +62,7 @@ static void gpio_keys_change_deferred(struct k_work *work)
pin_data->cb_data.pin_state = new_pressed;
LOG_DBG("Calling callback %s %d, code=%d", dev->name, new_pressed,
pin_cfg->zephyr_code);
data->callback(dev, &pin_data->cb_data, BIT(pin_cfg->spec.pin));
input_report_key(dev, pin_cfg->zephyr_code, new_pressed, true, K_FOREVER);
}
}

Expand Down Expand Up @@ -211,13 +212,12 @@ static int gpio_keys_init(const struct device *dev)
k_work_init_delayable(&data->pin_data[i].work, gpio_keys_change_deferred);
}

gpio_keys_zephyr_enable_interrupt(dev, NULL);

return 0;
}

static const struct gpio_keys_api gpio_keys_zephyr_api = {
.enable_interrupt = gpio_keys_zephyr_enable_interrupt,
.disable_interrupt = gpio_keys_zephyr_disable_interrupt,
.get_pin = gpio_keys_zephyr_get_pin,
static const struct input_driver_api gpio_keys_api = {
};

#define GPIO_KEYS_CFG_DEF(node_id) \
Expand All @@ -241,6 +241,6 @@ static const struct gpio_keys_api gpio_keys_zephyr_api = {
}; \
DEVICE_DT_INST_DEFINE(i, &gpio_keys_init, NULL, &gpio_keys_data_##i, \
&gpio_keys_config_##i, POST_KERNEL, CONFIG_GPIO_INIT_PRIORITY, \
&gpio_keys_zephyr_api);
&gpio_keys_api);

DT_INST_FOREACH_STATUS_OKAY(GPIO_KEYS_INIT)
1 change: 1 addition & 0 deletions drivers/kscan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ zephyr_library_sources_ifdef(CONFIG_KSCAN_HT16K33 kscan_ht16k33.c)
zephyr_library_sources_ifdef(CONFIG_KSCAN_CST816S kscan_cst816s.c)
zephyr_library_sources_ifdef(CONFIG_KSCAN_CAP1203 kscan_cap1203.c)
zephyr_library_sources_ifdef(CONFIG_KSCAN_NPCX kscan_npcx.c)
zephyr_library_sources_ifdef(CONFIG_KSCAN_ADAPTER kscan_adapter.c)

zephyr_library_sources_ifdef(CONFIG_USERSPACE kscan_handlers.c)
5 changes: 5 additions & 0 deletions drivers/kscan/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ config KSCAN_INIT_PRIORITY
help
Keyboard scan device driver initialization priority.

config KSCAN_ADAPTER
bool "Input subsystem to kscan adapter driver"
default y
depends on DT_HAS_ZEPHYR_KSCAN_ADAPTER_ENABLED

endif # KSCAN
1 change: 1 addition & 0 deletions drivers/kscan/Kconfig.ft5336
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ menuconfig KSCAN_FT5336
default y
depends on DT_HAS_FOCALTECH_FT5336_ENABLED
select I2C
select INPUT
help
Enable driver for multiple Focaltech capacitive touch panel
controllers. This driver should support FT5x06, FT5606, FT5x16,
Expand Down
Loading