Commit graph

95 commits

Author SHA1 Message Date
Fabio Baltieri 8b9464089c input: add a pmw3610 driver
Add a driver for the Pixart PMW3610 mouse sensor device.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-03-06 13:34:16 +01:00
Fabio Baltieri 7d676c2331 input: pat912x: add a bunch of settings
Add devicetree based settings for resolution, axis inversion and sleep
mode enable. Keep the resolution setting in its own function so it can
be called by the application again in runtime if needed.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-03-04 22:10:58 +01:00
Fabio Baltieri ad9f2c599b input: kbd_matrix: skip column with empty mask
The active key mask can be used for supporting multiple keyboard layouts
with a single firmware. A possible use case is to support keyboard with
or without a numpad, in which case an entire set of columns may be
missing. Add a check to detect this condition and skip scanning that
column entirely if no keys are defined in it.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-03-04 14:09:08 +01:00
Fabio Baltieri 3538335f5a input: add a pat912x driver
Add an initial input driver for the PixArt PAT9125EL, just core
functionalities for now, will add more configuration properties at a
later stage.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-02-29 11:53:20 +00:00
Chen Xingyu d181607f4e drivers: input: Implement driver for ADC keys
This commit introduces a driver for ADC keys, a common circuit design where
keys are connected to an ADC input via a resistor ladder.

Signed-off-by: Chen Xingyu <hi@xingrz.me>
2024-02-26 11:35:19 +00:00
Joel Guittet 415cb65e3f drivers: input: cst816s: add alternative chip id
The CST816S chip ID have an alternative value. It seems that this
field represents in fact a version number of controller. Fix by adding
the new chip ID.

Signed-off-by: Joel Guittet <joelguittet@gmail.com>
2024-02-05 14:49:33 +01:00
Fabio Baltieri 01be4aff40 input: gpio_qdec: add power management support
Add power management support to the gpio-qdec driver.

This is a bit complicated by the fact that the driver has two modes of
operation and the interrupt, timer and idle work ineract with each
other.

The suspend sequence is:
- set the suspended bit (inhibits the poll timer so that it does not
  resubmit the idle work)
- cancel the idle work (so that it does not schedule and re-set the
  interrupt or timers)
- disable interrupts (if used)
- stop the sampling timer
- disconnect the pins

The resume sequence is more or less the opposite.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-02-02 12:43:12 +01:00
Fabio Baltieri 1dd2307b3f input: gpio_qdec: add optical encoder support
Change the gpio_qdec driver to support optical encoders.

Add a property to use for defining an arbitrary number of GPIOs for the
sensing devices (typically infrared LEDs, but could also be the
biasing for the phototransistor), and one for adding a delay between
turning those on and reading the pin status.

The infrared LEDs typically consume a non negligible amount of power, so
there's also a new idle-poll-time-us property that enables two possible
modes of operation:

- if idle-poll-time-us is zero (default) the LEDs are enabled all the
  time and the driver enters polling mode using the GPIO interrupt as
  with mechanical encoders. This is usable for mains powered devices and
  has the lowest overhead on the CPU.

- if idle-poll-time-us is non zero, then the driver polls the encoder
  all the time, turning on the LEDs just before reading the state and
  shutting them off immediately after, but when the encoder is idle it
  switches the polling rate to idle-poll-time-us to save power, and only
  polls at sample-time-us when some movement is detected.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-01-23 09:45:57 -05:00
Fabio Baltieri 91ee5c4db2 input: gpio_qdec: rename gpio to ab_gpio
Rename gpio to ab_gpio, this is in preparation for adding another gpio
pointer.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-01-23 09:45:57 -05:00
Fabio Baltieri e5974b2aac input: gpio_keys: implement polling mode support
Some MCU have limitations with GPIO interrupts. Add a polling mode to
the gpio-keys driver to support those cases.

This required a bit of a refactoring of the driver data structure to add
a instance wide data, and move the pin specific pointer in the config
structure.

For polling, reuse the button 0 delayed work so we minimize the resource
waste, the two work handler functions are only referenced when used so
at least those are discarded automatically if no instance needs them.

Fix a bug in the PM structure instantiation as well.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-01-10 18:21:49 +00:00
Jonathan Hamberg 9c1a45cc00 posix: Fix name collision with __bswap
__bswap_ in zephyr/sys/byteorder.h conflicts with __bswap_ in host's
byteswap.h. byteswap.h from host compiler used in posix_native_64 boards
causes a compilation issue.

This commit renames __bswap_ to BSWAP_ to prevent collision.

Before this commit a compilation error can be created by adding #include
<byteswap.h> to samples/net/sockets/echo/src/socket_echo.c

This does not change external API to byteorder.h, but does change
internal implementation which some other source files depend on.

Replaced manual byteswap operations in devmem_service.c with APIs from
byteorder.h which automatically converts to CPU endianess when necessary.

Fixes #44324

Signed-off-by: Jonathan Hamberg <jonathanhamberg@gmail.com>
2024-01-10 18:13:44 +00:00
Fabio Baltieri bd8cee8683 drivers: input: add an analog-axis driver
Add an input driver to read data from an analog device, such as a
thumbstick, connected to an ADC channel, and report it as an input
device.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-01-10 15:05:35 +01:00
Fabio Baltieri 8ca40e5ebf drivers: input: depend on multithreading on drivers using a thread
These all require threads support to function, add a "depends on
MULTITHREADING" accordingly.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-01-09 11:27:44 +00:00
Fabio Baltieri bba517fa14 input: tweak actual-key-mask description
Tweak the actual-key-mask description, apply some leftover feedback from
the prevoius PR.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-01-08 10:23:53 +01:00
Fabio Baltieri 2a99432695 input: kbd_matrix: fail gracefully if changing an undefined key mask
Add a check to input_kbd_matrix_actual_key_mask_set() to return an error
if trying to change a key mask but the device does not define a keymask
in the first place.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-01-04 18:40:10 +00:00
Fabio Baltieri 4307882dd1 input: kbd_matrix: add actual key mask runtime control
Add an option to enable a input_kbd_matrix_actual_key_mask_set API to
enable or disable keys dynamically in the mask. This can be useful if
the exact key mask is determined in runtime and the device is using a
single firmware for multiple matrix configurations.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-27 16:50:21 +00:00
Fabio Baltieri 66a06d955a input: use K_KERNEL_STACK_SIZEOF to set the thread stack size
Use K_KERNEL_STACK_SIZEOF instead of the config directly to set the
stack size in k_thread_create() calls.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-23 09:59:28 +00:00
Fabio Baltieri c0e6629b7b input: npcx_kbd: setup the interrupt to falling edge only
The driver works on active low signals only, change the interrupt
configuration to trigger on falling edges only.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-20 18:07:43 +00:00
Fabio Baltieri 0442fe3bbf input: npcx_kbd: clear pending interrupts before reenabling detection
The driver right now re-enters polling mode a couple times after the
matrix has been detected as stable as the key interrupt is still pending
and fires again once detection is reenabled.

Clear pending WUI interrupts before reenabling key press detection to
avoid that.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-19 10:57:38 +00:00
Fabio Baltieri ecce235322 input: kbd_matrix: fix possible race condition
Fix a possible race condition in the keyboard matrix library where a key
would get pressed between the last read and reenabling the (edge
sensitive) interrupt and the even would be lost.

The window for this to happen is very narrow and had to artificially add
a sleep to reproduce it.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-18 12:25:19 +01:00
Fabio Baltieri ffbd0397dd input: gpio_kbd_matrix: use edge-to-active interrupt
Change the interrupt setup from both edge to edge to active. Edge to
active is all was needed anyway and it makes this compatible with gpio
controller that only support single edge interrupt.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-18 12:25:19 +01:00
Fabio Baltieri f9313b1745 input: add a linux-evdev device
Add a device driver to read events from a Linux evdev device node and
inject them back as Zephyr input events.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-18 12:23:59 +01:00
Fabio Baltieri 38d5c0a8ac input: kbd_matrix: make the thread priority configurable
Add a config entry for the keyboard matrix thread priority. This
changes the current default, but that was pretty much an arbitrary numbe
anyay and the exact one should be picked the application so it should be
alright to do so.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-18 09:27:53 +01:00
Fabio Baltieri cc5cef8179 input: gpio_keys: add power management support
Add power management support to the gpio keys driver. When in suspend,
disable all the button gpios and interrupts.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-18 09:27:42 +01:00
Fabio Baltieri c0b103bfb1 input: ft5336: add suspend and resume support
Add power management support to ft5336. The chip can go to hibernate and
reduce power consumption to a minimum, the only way to wake it up though
is by pulsing the reset or wake signal. Only reset is implemented in the
driver right now so only allow this functionality if the reset pin is
defined.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-15 11:32:56 +00:00
Marcio Ribeiro 8cb870f7de driver: input: espressif touch_sensor
Espressif touch sensor driver implemented.

Signed-off-by: Marcio Ribeiro <marcio.ribeiro@espressif.com>
2023-12-11 18:31:38 +01:00
Fabio Baltieri e4796521f2 input: kbd_matrix: add an kbd_matrix_state shell command
Add a "input kbd_matrix_state" shell command. This prints the state of
a keyboard matrix in a much more compact representation than the normal
input event dump, but also keeps track of any key seen during the
execution and reports that on the "off" command. The output can be used
to help setting the actual-key-mask property.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-08 20:16:39 +00:00
Fabio Baltieri bc849c7078 input: kbd_matrix: add print helper define
Add a print helper define for the keyboard matrix row paired with the
row typedef.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-08 20:16:39 +00:00
Fabio Baltieri f69641f7d2 input: gpio_kbd_matrix: do not enable interrupt if there's no callbacks
Change the gpio_kbd_matrix_set_detect_mode to skip setting gpio
interrupts if we don't have callbacks configured. This is the case if
the driver is running in poll or scan mode.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-08 01:07:15 +00:00
Fabio Baltieri c161253287 drivers: input: fix few types
Fix few wrong types in various input drivers.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-06 09:25:49 +00:00
Fabio Baltieri 808c0f1f78 input: kbd_matrix: add actual-key-mask support
Add an optional actual-key-mask property to filter out key combinations
that are not implemented in the actual keyboard matrix.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-06 09:16:45 +00:00
Fabio Baltieri 9080007ef9 input: gpio_keys: drop the pin filter from the callback
The bit check field is redundant since the callback struct is masked to
a single pin already. Drop it, simplify the code a bit.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-05 16:22:10 -06:00
Fabio Baltieri f6917bca14 input: gpio_keys: interrupt configure cleanup
Use the same ret variable name as the rest of the file, drop a redundant
mask, use gpio_pin_interrupt_configure_dt.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-05 16:22:10 -06:00
Fabio Baltieri 07bf0f95fe input: gpio_keys: drop zephyr_code from the callback struct
It's not really used from here, guess it was a leftover.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-05 16:22:10 -06:00
Fabio Baltieri 3862c227d4 input: gpio_kbd_matrix: add poll and scan mode support
Add a poll and scan mode for the driver. If any of these are set, the
driver does not use the GPIO interrupts to detect when the matrix has to
switch to polling mode. Instead, it keeps polling it all the time,
either by enabling all the columns and poll the rows for activity, or
just keep scanning all the time.

Poll mode is useful if the specific SoC used does not support GPIO
interrupt on all the row GPIOs at the same time, scan mode if it does
not even support selecting all the columns at the same time.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-04 16:40:35 +00:00
Fabio Baltieri 56d73a8b0c input: kbd_matrix: always poll if poll_timeout_ms is 0
Tweak the polling mode so that the driver never exit polling mode if
poll_timeout_ms is 0. This is useful if the specific driver does not
support idle mode.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-04 16:40:35 +00:00
Fabio Baltieri f4bf74e402 input: kbd_matrix: clear unstable state correctly on release
The state variable to tracking the unstable state of a key is currently
being cleared based on the bit value, which means that on release it's
not being cleared at all. Fix that by clearing using the bit mask
instead.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-04 16:40:24 +00:00
Fabio Baltieri 71e5c66ea4 input: kbd_matrix: fix a typing issue for a cycle counter
scan_clk_cycle is used to store values from k_cycle_get_32(), it very
much needs to be a uint32_t.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-12-04 16:40:24 +00:00
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