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>
This commit is contained in:
Fabio Baltieri 2023-12-11 16:11:12 +00:00 committed by Fabio Baltieri
commit 4307882dd1
5 changed files with 95 additions and 3 deletions

View file

@ -27,6 +27,13 @@ config INPUT_KBD_MATRIX_16_BIT_ROW
Use a 16 bit type for the internal structure, allow using a matrix
with up to 16 rows if the driver supports it.
config INPUT_KBD_ACTUAL_KEY_MASK_DYNAMIC
bool "Allow runtime changes to the actual key mask"
help
If enabled, the actual key mask data is stored in RAM, and a
input_kbd_matrix_actual_key_mask_set() function is available to
change the content at runtime.
config INPUT_SHELL_KBD_MATRIX_STATE
bool "Input kbd_matrix_state shell command"
depends on INPUT_SHELL

View file

@ -323,3 +323,19 @@ int input_kbd_matrix_common_init(const struct device *dev)
return 0;
}
#if CONFIG_INPUT_KBD_ACTUAL_KEY_MASK_DYNAMIC
int input_kbd_matrix_actual_key_mask_set(const struct device *dev,
uint8_t row, uint8_t col, bool enabled)
{
const struct input_kbd_matrix_common_config *cfg = dev->config;
if (row >= cfg->row_size || col >= cfg->col_size) {
return -EINVAL;
}
WRITE_BIT(cfg->actual_key_mask[col], row, enabled);
return 0;
}
#endif