Commit graph

57 commits

Author SHA1 Message Date
Fabio Baltieri 506ede0c59 input: kbd_matrix: fix a debouncing timing issue
Fix a debouncing timing unit mismatch when comparing us to ms.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-04 16:40:24 +00:00
Fabio Baltieri 76791cd708 input: kbd_matrix: add a input_kbd_matrix_drive_column_hook option
Add an option to call an application specific hook when setting the
column to scan. This makes it possible to handle application specific
quirks.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-29 18:18:09 +00:00
Fabio Baltieri ea887af0aa input: gpio_kbd_matrix: drop redundant gpio_kbd_matrix_set_detect_mode
This is called already as soon as the polling thread starts, so the call
in the gpio init function is harmless but redundant, drop it.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-22 11:44:48 +00:00
Fabio Baltieri 6cd72493ff input: gpio_kbd_matrix: add direct access support
When the matrix is connected to consecutive pins on the same port, it's
possible to read the whole row or set the whole column in a single
operation. For the column, this is only possible if the matrix is
configured for driving unselected column, as there's no API to configure
multiple pins at the same time at the moment.

This is more efficient than checking the pins individually, and it's
particularly useful if the row or columns are driven from a GPIO port
expander.

Add some code to detect the condition and enable it automatically as
long as the hw configuration supports it.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-22 10:34:40 +00:00
Fabio Baltieri 8ec1b5487e input: gpio_kbd_matrix: add column drive mode
Add an option to drive inactive columns to inactive state rather than
high impedance. This is useful if the matrix has isolation diodes for
every key, as it allows the matrix to stabilize faster and the API for
changing the pin value is more efficient than the one to change the pin
configuration.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-22 10:34:40 +00:00
Fabio Baltieri f9ed74e0d5 input: gpio_kbd_matrix: add 16 bit rows support
Add a Kconfig option to extend the row type to 16 bits, allowing the
library to handle a 16 row matrix.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-22 09:52:39 +01:00
Fabio Baltieri adcb2f580c input: gpio_kbd_matrix: define a type for the row data
Add a typedef for the row type rather than using uint8_t directly, this
allow supporting bigger matrix as an option by using a different type.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-22 09:52:39 +01:00
Fabio Baltieri 3452f9fa4e input: it8xxx2_kbd: drop unnecessary include
Drop the atomic.h included, this does not use any atomic anymore.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-17 08:25:27 +00:00
Fabio Baltieri 716281b5c9 input: kbd_matrix: move few assignment off the declaration area
Move a couple of automatic variable assignment off the declaration
block, leaves only structure aliases there, makes it a bit easier to
read.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-17 08:25:27 +00:00
Fabio Baltieri eaac842b82 input: kbd_matrix: move scan_cycles_idx increment
Move the scan_cycles_idx increment in input_kbd_matrix_update_state
as it's only used there, use a modulo operation rather than the if to
handle the index wrapping condition.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-17 08:25:27 +00:00
Fabio Baltieri 2cf9d32b29 input: kbd_matrix: use CLAMP instead of two ifs
Replace the wait_period_us clamping functions using a single CLAMP,
reposition the debug log as well.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-17 08:25:27 +00:00
Fabio Baltieri c639ab8e57 input: kbd_matrix: clean debug logs
Tweak a couple of debug log entries.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-17 08:25:27 +00:00
Fabio Baltieri 958cd4ff53 input: kbd_matrix,npcx: drop explicit LOG_LEVEL define
Use the LOG_MODULE_REGISTER argument instead.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-17 08:25:27 +00:00
Fabio Baltieri e87ded3f03 input: it8xxx2: use the generic keyboard code
Split the common keyboard scanning code out of the ITE specific driver
and use the generic code instead.

Note that this changes few timing defaults, the change is not
significant though so I suspect there's no difference in practice.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-16 17:54:00 +01:00
Fabio Baltieri a089fa241f input: npcx: drop the input_ prefix from the internal functions
Drop the input_ prefix fromthe internal functions. Trying to unify the
input drivers to use the same style for function naming, this makes it a
bit more compact and makes it easier to distinguish the common keyboard
structures and functions from the driver ones.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-16 09:30:34 +01:00
Fabio Baltieri 256bc860cf input: add a gpio based keyboard matrix driver
Add a GPIO based keyboard matrix driver using the generic keyboard
matrix code.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-15 11:41:25 +01:00
Fabio Baltieri be5cb7af7c input: kbd_matrix: move the header to the project wide include directory
Move the input_kbd_matrix.h header out of drivers/ and into include/,
this allows external drivers to use it and doxygen to pick it up.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-15 11:41:25 +01:00
Fabio Baltieri 297c41031b doc: input: add a input_kbd_matrix group, fix few missing doc entries
Add a input_kbd_matrix doxygen group and add this to the other Input
APIs page, add few missing argument documentation entries.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-15 11:41:25 +01:00
Fabio Baltieri 0c00b6e0ab input: kbd_matrix: make the api field a pointer
The API field of input_kbd_matrix_common_config should have been a
pointer from the start, clang-16 caught this with a compiler warning.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-15 11:41:25 +01:00
Fabio Baltieri 15e92d5e5c input: kbd: make row and col size optional add extra macro
Change the row-count and col-count to be optional in the generic
binding, add a second pair of macro to allow the implementation to
specify the numbers from a different property.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-15 11:41:25 +01:00
Fabio Baltieri 9439c816e9 input: split npcx generic keyboard code into input_kbd_matrix.c
Move all the generic code from the Nuvoton NPCX keyboard scanning driver
into input_kbd_matrix.c. While doing that convert few configs into
devicetree properties and tweak few other things to enable the generic
code to support multiple instances.

This is limited to 8 rows for now, and that's fine for all the current
in-tree drivers, the limit could be removed down the road but this
should be fine for now, added few generic build checks to make sure a
driver does not go over the limit, as well and some more implementation
specific checks.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-13 09:45:28 +01:00
Fabio Baltieri 3003cc1938 input: keep CMakeLists and Kconfig sorted
Add zephyr-keep-sorted tags to CMakeLists and Kconfig in input.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-13 09:41:05 +01:00
Fabio Baltieri 7a3a6d0c03 input: convert ite_it8xxx2_kbd driver from kscan to input
Convert the ITE keyboard scanning driver from kscan to input, add the
corresponding kscan compatibility node to the current board, build test
only.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-10 16:30:37 +00:00
Fabio Baltieri 0e3d0e9b15 input: gt911: fix reset control polarity
This chip uses an active low reset, so the correct behavior here is to
define the pin as ACTIVE_LOW, using GPIO_OUTPUT_ACTIVE to assert the
reset and set to 0 to deassert.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-06 08:50:33 +00:00
Fabio Baltieri 05ab1c5f77 input: ft5336: fix reset control polarity
This chip uses an active low reset, so the correct behavior here is to
define the pin as ACTIVE_LOW, using GPIO_OUTPUT_ACTIVE to assert the
reset and set to 0 to deassert.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-06 08:50:33 +00:00
Fabio Baltieri 9b488103ae input: cst816s: simplify the reset code
The current code deasserts the reset, just to re-assert it immediately.
Just initialize with OUTPUT_ACTIVE, delay and then de-assert.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-06 08:50:33 +00:00
Fabio Baltieri d3d484c473 input: add some initial keyboard matrix library stubs
We currently have three keyboard scanning drivers in the code base
(npcx, it8xxx2 and mchp_xec, last two yet to be converted to input).
These have been largely copy pasted from each other and share a lot of
the same structure and code.

This PR lays a foundation to start decoupling feature from those drivers
into a common code base, and it is heavily inspired by the current
regulator common data/config one.

Feature wise this only moves the thread struct, stack and initialization
to the common code and declares the thread callback as the only API, but
the intent is to move as much code as possible in there an only abstract
device specific callbacks in the api structures.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-10-31 09:00:27 +01:00
Benedikt Schmidt a03f1010b8 drivers: fix thread function signatures
Fix thread function signatures to avoid stack corruption on thread exit.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2023-10-30 12:24:34 +01:00
Brunon Blok bf830ba780 drivers: input: add driver for stmpe811 i2c touch controller
This commit adds STMPE811 I2C touch controller driver.

Signed-off-by: Brunon Blok <bblok@internships.antmicro.com>
Signed-off-by: Mateusz Sierszulski <msierszulski@antmicro.com>
2023-09-22 09:29:56 +02:00
Mario Paja d72b79256c driver: input: gt911: Fix to properly handle touch events on esp32
This fix properly ignores a multitouch event on esp32 board

Signed-off-by: Mario Paja <mariopaja@hotmail.com>
2023-08-30 22:21:14 +02:00
Nick Ward 2d65acca3a drivers: gpio: use gpio_is_ready_dt helper function
Update `struct gpio_dt_spec` use with gpio_is_ready_dt()

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2023-08-28 08:48:35 -05:00
Fabio Baltieri 2401743c21 input: gpio_keys: fix CONTAINER_OF declaration
Fix CONTAINER_OF usage in gpio_keys_interrupt, this should go first to
struct gpio_keys_callback and then to struct gpio_keys_pin_data. It
happens to work right now because cb_data is the first field.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-28 10:12:21 +02:00
Fabio Baltieri ec71be5d9d drivers,subsys: fix few missing k_work_delayable_from_work
Fix few instances of delayable work handlers using the k_work pointer
directly in a CONTAINER_OF pointing to a k_work_delayable.

This is harmless since the k_work is the first element in
k_work_delayable, but using k_work_delayable_from_work is the right way
of handling it.

Change a couple of explicit CONTAINER_OF doing the same work as the
macro in the process.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-28 10:12:21 +02:00
Fabio Baltieri 19290e465d input: gpio_keys: drop struct gpio_keys_data
Drop the data data structure and use the pin data one directly, also add
a missing const qualifier in the main conf data structure, both save few
bytes of RAM on some platforms.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-21 16:08:42 +02:00
Fabio Baltieri 35e3bfcdef drivers: input: drop the zephyr,gpio-keys binding
This is now redundant and `gpio-keys` can be used instead.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-07 11:26:26 +02:00
Fabio Baltieri 2b489fd1f2 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>
2023-08-07 11:26:26 +02:00
Fabio Baltieri 937116aef9 drivers: input: add missing GPIO_KEYS GPIO dependency
Add a missing dependency between GPIO_KEYS and GPIO.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-07 11:26:26 +02:00
Fabian Blatz e1e4fcc701 input: remove cap1203 kscan-like state report
Previously the driver was retrofitted to the kscan api, handling it as a
input device with one row and three columns. With the move to the input
subsystem each input can have its proper input code instead.

Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
2023-07-25 11:25:51 +02:00
Fabian Blatz 1d56b8e2aa input: convert cap1203 from kscan
Convert the CAP1203 driver to the input subsystem, add to build_all tests.

Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
2023-07-25 11:25:51 +02:00
Nicolas Pitre 531aa5786d drivers: move to timepoint API
Remove sys_clock_timeout_end_calc() usage.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-07-25 09:12:26 +02:00
Daniel DeGrasse 066c40bbb0 drivers: input: ft5336: Add support for reset GPIO and FT3267 IC
Add support for resetting controller at boot, and update FT5336
documentation to indicate that the FT3267 IC is also supported by this
driver.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2023-07-25 09:08:59 +02:00
Paul He 278563ed45 drivers: input: gt911: fix error 'ret' undeclared
When CONFIG_INPUT_GT911_INTERRUPT is set to 'y', it will get this
undeclared error, now fix it.

Signed-off-by: Paul He <pawpawhe@gmail.com>
2023-07-20 20:52:19 +00:00
Fabio Baltieri d95c12848d drivers: input: add few missing gpio_add_callback return check
Add few missing check on gpio_add_callback and gpio_add_callback_dt
calls, fixes a coverity warning.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-07-19 09:18:38 +00:00
Daniel DeGrasse 5862b38e99 drivers: input: gt911: enable fallback to alternate address
GT911 IC uses the INT pin to select the correct I2C address during
reset. However, some boards may not route this pin (or may only support
receiving inputs on it). This results in the I2C address selected by the
GT911 IC being arbitrary based on the state of the (floating) INT pin.

To resolve this, introduce an `alt-addr` property for this device. When
set, the INT pin will not be pulled low. Instead, the I2C address will be
probed at runtime, starting with the devicetree address and falling back to
`alt-addr`.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2023-07-18 18:49:13 +00:00
Fabian Blatz 723421b231 input: convert cst816s from kscan
Convert the cst816s capacitive touch screen driver to the input subsystem.

Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
2023-07-18 08:55:26 -05:00
Fabio Baltieri 04e0e458c8 input: convert gt911 from kscan
Convert the GT911 driver to the input subsystem, fix the existing boards
to work in the default config.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-07-13 14:24:50 +00:00
Alberto Escolar Piedras 78ff21e1e1 input SDL: Split in top and bottom
Split the SDL input driver in a top and bottom
to enable using it with embedded libCs.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-07-06 16:04:15 +02:00
Fabio Baltieri 9065c2d156 input: convert xpt2046 from kscan
Convert the XPT2046 driver to the input subsystem, change the api,
remove the callback and enable logic.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-06-27 12:17:06 +00:00
Fabio Baltieri 2790106c33 input: add a gpio qdec input driver
Add a GPIO based quadrature decoder driver that reports relative axes
movements using the input subsystem.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-06-22 10:46:15 +02:00
Fabio Baltieri cda5b175fa input: check for gpio_add_callback error codes.
Add two error code check for gpio_add_callback functions to avoid
triggering a coverity warning.

Drop a redundant initialization in the process.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-06-01 06:33:27 -04:00