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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>