This is the documentation for the latest (main) development branch of Zephyr. If you are looking for the documentation of previous releases, use the drop-down menu on the left and select the desired version.

KSCAN

Overview

The kscan driver (keyboard scan matrix) is used for detecting a key press in a connected matrix keyboard or any device with buttons such as joysticks. Typically, matrix keyboards are implemented using a two-dimensional configuration in order to sense several keys. This allows interfacing to many keys through fewer physical pins. Keyboard matrix drivers read the rows while applying power through the columns one at a time with the purpose of detecting key events. There is no correlation between the physical and electrical layout of keys. For, example, the physical layout may be one array of 16 or fewer keys, which may be electrically connected to a 4 x 4 array. In addition, key values are defined by a keymap provided by the keyboard manufacturer.

Configuration Options

Related configuration options:

API Reference

group kscan_interface

KSCAN APIs.

Typedefs

typedef void (*kscan_callback_t)(const struct device *dev, uint32_t row, uint32_t column, bool pressed)

Keyboard scan callback called when user press/release a key on a matrix keyboard.

Parameters
  • dev – Pointer to the device structure for the driver instance.

  • row – Describes row change.

  • column – Describes column change.

  • pressed – Describes the kind of key event.

Functions

int kscan_config(const struct device *dev, kscan_callback_t callback)

Configure a Keyboard scan instance.

Parameters
  • dev – Pointer to the device structure for the driver instance.

  • callback – called when keyboard devices reply to to a keyboard event such as key pressed/released.

Returns

  • 0 – If successful.

  • Negative – errno code if failure.

int kscan_enable_callback(const struct device *dev)

Enables callback.

Parameters
  • dev – Pointer to the device structure for the driver instance.

Returns

  • 0 – If successful.

  • Negative – errno code if failure.

int kscan_disable_callback(const struct device *dev)

Disables callback.

Parameters
  • dev – Pointer to the device structure for the driver instance.

Returns

  • 0 – If successful.

  • Negative – errno code if failure.