Skip to content

Commit

Permalink
input: gpio_kbd_matrix: add column drive mode
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
fabiobaltieri committed Nov 22, 2023
1 parent 45a5ced commit 8ec1b54
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 10 additions & 2 deletions drivers/input/input_gpio_kbd_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct gpio_kbd_matrix_config {
const struct gpio_dt_spec *col_gpio;
struct gpio_callback *gpio_cb;
gpio_callback_handler_t handler;
bool col_drive_inactive;
};

struct gpio_kbd_matrix_data {
Expand Down Expand Up @@ -53,7 +54,9 @@ static void gpio_kbd_matrix_drive_column(const struct device *dev, int col)
const struct gpio_dt_spec *gpio = &cfg->col_gpio[i];

if ((data->last_col_state ^ state) & BIT(i)) {
if (state & BIT(i)) {
if (cfg->col_drive_inactive) {
gpio_pin_set_dt(gpio, state & BIT(i));
} else if (state & BIT(i)) {
gpio_pin_configure_dt(gpio, GPIO_OUTPUT_ACTIVE);
} else {
gpio_pin_configure_dt(gpio, GPIO_INPUT);
Expand Down Expand Up @@ -114,7 +117,11 @@ static int gpio_kbd_matrix_init(const struct device *dev)
return -ENODEV;
}

ret = gpio_pin_configure_dt(gpio, GPIO_INPUT);
if (cfg->col_drive_inactive) {
ret = gpio_pin_configure_dt(gpio, GPIO_OUTPUT_INACTIVE);
} else {
ret = gpio_pin_configure_dt(gpio, GPIO_INPUT);
}
if (ret != 0) {
LOG_ERR("Pin %d configuration failed: %d", i, ret);
return ret;
Expand Down Expand Up @@ -186,6 +193,7 @@ static const struct input_kbd_matrix_api gpio_kbd_matrix_api = {
.col_gpio = gpio_kbd_matrix_col_gpio_##n, \
.gpio_cb = gpio_kbd_matrix_gpio_cb_##n, \
.handler = gpio_kbd_matrix_cb_##n, \
.col_drive_inactive = DT_INST_PROP(n, col_drive_inactive), \
}; \
\
static struct gpio_kbd_matrix_data gpio_kbd_matrix_data_##n; \
Expand Down
11 changes: 9 additions & 2 deletions dts/bindings/input/gpio-kbd-matrix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,12 @@ properties:
required: true
description: |
GPIO for the keyboard matrix columns, supports up to 32 different GPIOs.
The pins will be driven according to the GPIO_ACTIVE_HIGH or
GPIO_ACTIVE_LOW flags when selected, high impedance when not selected.
When unselected, this pin will be either driven to inactive state or
configured to high impedance (input) depending on the col-drive-inactive
property.
col-drive-inactive:
type: boolean
description: |
If enabled, unselected column GPIOs will be driven to inactive state.
Default to configure unselected column GPIOs to high impedance.

0 comments on commit 8ec1b54

Please sign in to comment.