Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Keyboard Matrix API

Keyboard Matrix API. More...

Data Structures

struct  input_kbd_matrix_api
 Keyboard matrix internal APIs. More...
 
struct  input_kbd_matrix_common_config
 Common keyboard matrix config. More...
 
struct  input_kbd_matrix_common_data
 Common keyboard matrix data. More...
 

Macros

#define INPUT_KBD_MATRIX_COLUMN_DRIVE_NONE   -1
 Special drive_column argument for not driving any column.
 
#define INPUT_KBD_MATRIX_COLUMN_DRIVE_ALL   -2
 Special drive_column argument for driving all the columns.
 
#define INPUT_KBD_MATRIX_SCAN_OCURRENCES   30U
 Number of tracked scan cycles.
 
#define PRIkbdrow   "02" PRIx8
 
#define INPUT_KBD_ACTUAL_KEY_MASK_CONST
 
#define INPUT_KBD_MATRIX_ROW_BITS   NUM_BITS(kbd_row_t)
 Maximum number of rows.
 
#define INPUT_KBD_MATRIX_DATA_NAME(node_id, name)
 
#define INPUT_KBD_MATRIX_DT_DEFINE_ROW_COL(node_id, _row_size, _col_size)
 Defines the common keyboard matrix support data from devicetree, specify row and col count.
 
#define INPUT_KBD_MATRIX_DT_DEFINE(node_id)
 Defines the common keyboard matrix support data from devicetree.
 
#define INPUT_KBD_MATRIX_DT_INST_DEFINE_ROW_COL(inst, row_size, col_size)    INPUT_KBD_MATRIX_DT_DEFINE_ROW_COL(DT_DRV_INST(inst), row_size, col_size)
 Defines the common keyboard matrix support data from devicetree instance, specify row and col count.
 
#define INPUT_KBD_MATRIX_DT_INST_DEFINE(inst)    INPUT_KBD_MATRIX_DT_DEFINE(DT_DRV_INST(inst))
 Defines the common keyboard matrix support data from devicetree instance.
 
#define INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT_ROW_COL(node_id, _api, _row_size, _col_size)
 Initialize common keyboard matrix config from devicetree, specify row and col count.
 
#define INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT(node_id, api)
 Initialize common keyboard matrix config from devicetree.
 
#define INPUT_KBD_MATRIX_DT_INST_COMMON_CONFIG_INIT_ROW_COL(inst, api, row_size, col_size)    INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT_ROW_COL(DT_DRV_INST(inst), api, row_size, col_size)
 Initialize common keyboard matrix config from devicetree instance, specify row and col count.
 
#define INPUT_KBD_MATRIX_DT_INST_COMMON_CONFIG_INIT(inst, api)    INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT(DT_DRV_INST(inst), api)
 Initialize common keyboard matrix config from devicetree instance.
 
#define INPUT_KBD_STRUCT_CHECK(config, data)
 Validate the offset of the common data structures.
 

Typedefs

typedef uint8_t kbd_row_t
 Row entry data type.
 

Functions

int input_kbd_matrix_actual_key_mask_set (const struct device *dev, uint8_t row, uint8_t col, bool enabled)
 Enables or disables a specific row, column combination in the actual key mask.
 
void input_kbd_matrix_poll_start (const struct device *dev)
 Start scanning the keyboard matrix.
 
void input_kbd_matrix_drive_column_hook (const struct device *dev, int col)
 Drive column hook.
 
int input_kbd_matrix_common_init (const struct device *dev)
 Common function to initialize a keyboard matrix device at init time.
 

Detailed Description

Keyboard Matrix API.

Macro Definition Documentation

◆ INPUT_KBD_ACTUAL_KEY_MASK_CONST

#define INPUT_KBD_ACTUAL_KEY_MASK_CONST

◆ INPUT_KBD_MATRIX_COLUMN_DRIVE_ALL

#define INPUT_KBD_MATRIX_COLUMN_DRIVE_ALL   -2

#include <zephyr/input/input_kbd_matrix.h>

Special drive_column argument for driving all the columns.

◆ INPUT_KBD_MATRIX_COLUMN_DRIVE_NONE

#define INPUT_KBD_MATRIX_COLUMN_DRIVE_NONE   -1

#include <zephyr/input/input_kbd_matrix.h>

Special drive_column argument for not driving any column.

◆ INPUT_KBD_MATRIX_DATA_NAME

#define INPUT_KBD_MATRIX_DATA_NAME (   node_id,
  name 
)

#include <zephyr/input/input_kbd_matrix.h>

Value:
_CONCAT(__input_kbd_matrix_, \
_CONCAT(name, DEVICE_DT_NAME_GET(node_id)))
#define DEVICE_DT_NAME_GET(node_id)
The name of the global device object for node_id.
Definition: device.h:228

◆ INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT

#define INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT (   node_id,
  api 
)

#include <zephyr/input/input_kbd_matrix.h>

Value:
node_id, api, DT_PROP(node_id, row_size), DT_PROP(node_id, col_size))
#define DT_PROP(node_id, prop)
Get a devicetree property value.
Definition: devicetree.h:636
#define INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT_ROW_COL(node_id, _api, _row_size, _col_size)
Initialize common keyboard matrix config from devicetree, specify row and col count.
Definition: input_kbd_matrix.h:187

Initialize common keyboard matrix config from devicetree.

Parameters
node_idThe devicetree node identifier.
apiPointer to a input_kbd_matrix_api structure.

◆ INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT_ROW_COL

#define INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT_ROW_COL (   node_id,
  _api,
  _row_size,
  _col_size 
)

#include <zephyr/input/input_kbd_matrix.h>

Value:
{ \
.api = _api, \
.row_size = _row_size, \
.col_size = _col_size, \
.poll_period_us = DT_PROP(node_id, poll_period_ms) * USEC_PER_MSEC, \
.poll_timeout_ms = DT_PROP(node_id, poll_timeout_ms), \
.debounce_down_us = DT_PROP(node_id, debounce_down_ms) * USEC_PER_MSEC, \
.debounce_up_us = DT_PROP(node_id, debounce_up_ms) * USEC_PER_MSEC, \
.settle_time_us = DT_PROP(node_id, settle_time_us), \
.ghostkey_check = !DT_PROP(node_id, no_ghostkey_check), \
IF_ENABLED(DT_NODE_HAS_PROP(node_id, actual_key_mask), ( \
.actual_key_mask = INPUT_KBD_MATRIX_DATA_NAME(node_id, actual_key_mask), \
)) \
\
.matrix_stable_state = INPUT_KBD_MATRIX_DATA_NAME(node_id, stable_state), \
.matrix_unstable_state = INPUT_KBD_MATRIX_DATA_NAME(node_id, unstable_state), \
.matrix_previous_state = INPUT_KBD_MATRIX_DATA_NAME(node_id, previous_state), \
.matrix_new_state = INPUT_KBD_MATRIX_DATA_NAME(node_id, new_state), \
.scan_cycle_idx = INPUT_KBD_MATRIX_DATA_NAME(node_id, scan_cycle_idx), \
}
#define USEC_PER_MSEC
number of microseconds per millisecond
Definition: sys_clock.h:89
#define DT_NODE_HAS_PROP(node_id, prop)
Does a devicetree node have a property?
Definition: devicetree.h:3307
#define INPUT_KBD_MATRIX_DATA_NAME(node_id, name)
Definition: input_kbd_matrix.h:129

Initialize common keyboard matrix config from devicetree, specify row and col count.

Parameters
node_idThe devicetree node identifier.
_apiPointer to a input_kbd_matrix_api structure.
_row_sizeThe matrix row count.
_col_sizeThe matrix column count.

◆ INPUT_KBD_MATRIX_DT_DEFINE

#define INPUT_KBD_MATRIX_DT_DEFINE (   node_id)

#include <zephyr/input/input_kbd_matrix.h>

Value:
node_id, DT_PROP(node_id, row_size), DT_PROP(node_id, col_size))
#define INPUT_KBD_MATRIX_DT_DEFINE_ROW_COL(node_id, _row_size, _col_size)
Defines the common keyboard matrix support data from devicetree, specify row and col count.
Definition: input_kbd_matrix.h:137

Defines the common keyboard matrix support data from devicetree.

◆ INPUT_KBD_MATRIX_DT_DEFINE_ROW_COL

#define INPUT_KBD_MATRIX_DT_DEFINE_ROW_COL (   node_id,
  _row_size,
  _col_size 
)

#include <zephyr/input/input_kbd_matrix.h>

Value:
BUILD_ASSERT(IN_RANGE(_row_size, 1, INPUT_KBD_MATRIX_ROW_BITS), "invalid row-size"); \
BUILD_ASSERT(IN_RANGE(_col_size, 1, UINT8_MAX), "invalid col-size"); \
IF_ENABLED(DT_NODE_HAS_PROP(node_id, actual_key_mask), ( \
BUILD_ASSERT(DT_PROP_LEN(node_id, actual_key_mask) == _col_size, \
"actual-key-mask size does not match the number of columns"); \
INPUT_KBD_MATRIX_DATA_NAME(node_id, actual_key_mask)[_col_size] = \
DT_PROP(node_id, actual_key_mask); \
)) \
static kbd_row_t INPUT_KBD_MATRIX_DATA_NAME(node_id, stable_state)[_col_size]; \
static kbd_row_t INPUT_KBD_MATRIX_DATA_NAME(node_id, unstable_state)[_col_size]; \
static kbd_row_t INPUT_KBD_MATRIX_DATA_NAME(node_id, previous_state)[_col_size]; \
static kbd_row_t INPUT_KBD_MATRIX_DATA_NAME(node_id, new_state)[_col_size]; \
static uint8_t INPUT_KBD_MATRIX_DATA_NAME(node_id, scan_cycle_idx)[_row_size * _col_size];
#define DT_PROP_LEN(node_id, prop)
Get a property's logical length.
Definition: devicetree.h:670
uint8_t kbd_row_t
Row entry data type.
Definition: input_kbd_matrix.h:37
#define INPUT_KBD_MATRIX_ROW_BITS
Maximum number of rows.
Definition: input_kbd_matrix.h:68
#define INPUT_KBD_ACTUAL_KEY_MASK_CONST
Definition: input_kbd_matrix.h:42
#define IN_RANGE(val, min, max)
Checks if a value is within range.
Definition: util.h:422
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
#define UINT8_MAX
Definition: stdint.h:27

Defines the common keyboard matrix support data from devicetree, specify row and col count.

◆ INPUT_KBD_MATRIX_DT_INST_COMMON_CONFIG_INIT

#define INPUT_KBD_MATRIX_DT_INST_COMMON_CONFIG_INIT (   inst,
  api 
)     INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT(DT_DRV_INST(inst), api)

#include <zephyr/input/input_kbd_matrix.h>

Initialize common keyboard matrix config from devicetree instance.

Parameters
instInstance.
apiPointer to a input_kbd_matrix_api structure.

◆ INPUT_KBD_MATRIX_DT_INST_COMMON_CONFIG_INIT_ROW_COL

#define INPUT_KBD_MATRIX_DT_INST_COMMON_CONFIG_INIT_ROW_COL (   inst,
  api,
  row_size,
  col_size 
)     INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT_ROW_COL(DT_DRV_INST(inst), api, row_size, col_size)

#include <zephyr/input/input_kbd_matrix.h>

Initialize common keyboard matrix config from devicetree instance, specify row and col count.

Parameters
instInstance.
apiPointer to a input_kbd_matrix_api structure.
row_sizeThe matrix row count.
col_sizeThe matrix column count.

◆ INPUT_KBD_MATRIX_DT_INST_DEFINE

#define INPUT_KBD_MATRIX_DT_INST_DEFINE (   inst)     INPUT_KBD_MATRIX_DT_DEFINE(DT_DRV_INST(inst))

#include <zephyr/input/input_kbd_matrix.h>

Defines the common keyboard matrix support data from devicetree instance.

Parameters
instInstance.

◆ INPUT_KBD_MATRIX_DT_INST_DEFINE_ROW_COL

#define INPUT_KBD_MATRIX_DT_INST_DEFINE_ROW_COL (   inst,
  row_size,
  col_size 
)     INPUT_KBD_MATRIX_DT_DEFINE_ROW_COL(DT_DRV_INST(inst), row_size, col_size)

#include <zephyr/input/input_kbd_matrix.h>

Defines the common keyboard matrix support data from devicetree instance, specify row and col count.

Parameters
instInstance.
row_sizeThe matrix row count.
col_sizeThe matrix column count.

◆ INPUT_KBD_MATRIX_ROW_BITS

#define INPUT_KBD_MATRIX_ROW_BITS   NUM_BITS(kbd_row_t)

#include <zephyr/input/input_kbd_matrix.h>

Maximum number of rows.

◆ INPUT_KBD_MATRIX_SCAN_OCURRENCES

#define INPUT_KBD_MATRIX_SCAN_OCURRENCES   30U

#include <zephyr/input/input_kbd_matrix.h>

Number of tracked scan cycles.

◆ INPUT_KBD_STRUCT_CHECK

#define INPUT_KBD_STRUCT_CHECK (   config,
  data 
)

#include <zephyr/input/input_kbd_matrix.h>

Value:
BUILD_ASSERT(offsetof(config, common) == 0, \
"struct input_kbd_matrix_common_config must be placed first"); \
BUILD_ASSERT(offsetof(data, common) == 0, \
"struct input_kbd_matrix_common_data must be placed first")

Validate the offset of the common data structures.

Parameters
configName of the config structure.
dataName of the data structure.

◆ PRIkbdrow

#define PRIkbdrow   "02" PRIx8

Typedef Documentation

◆ kbd_row_t

typedef uint8_t kbd_row_t

#include <zephyr/input/input_kbd_matrix.h>

Row entry data type.

Function Documentation

◆ input_kbd_matrix_actual_key_mask_set()

int input_kbd_matrix_actual_key_mask_set ( const struct device dev,
uint8_t  row,
uint8_t  col,
bool  enabled 
)

#include <zephyr/input/input_kbd_matrix.h>

Enables or disables a specific row, column combination in the actual key mask.

This allows enabling or disabling spcific row, column combination in the actual key mask in runtime. It can be useful if some of the keys are not present in some configuration, and the specific configuration is determined in runtime. Requires CONFIG_INPUT_KBD_ACTUAL_KEY_MASK_DYNAMIC to be enabled.

Parameters
devPointer to the keyboard matrix device.
rowThe matrix row to enable or disable.
colThe matrix column to enable or disable.
enabledWhether the specificied row, col has to be enabled or disabled.
Return values
0If the change is successful.
-errnoNegative errno if row or col are out of range for the device.

◆ input_kbd_matrix_common_init()

int input_kbd_matrix_common_init ( const struct device dev)

#include <zephyr/input/input_kbd_matrix.h>

Common function to initialize a keyboard matrix device at init time.

This function must be called at the end of the device init function.

Parameters
devKeyboard matrix device instance.
Return values
0If initialized successfully.
-errnoNegative errno in case of failure.

◆ input_kbd_matrix_drive_column_hook()

void input_kbd_matrix_drive_column_hook ( const struct device dev,
int  col 
)

#include <zephyr/input/input_kbd_matrix.h>

Drive column hook.

This can be implemented by the application to handle column selection quirks. Called after the driver specific drive_column function. Requires CONFIG_INPUT_KBD_DRIVE_COLUMN_HOOK to be enabled.

Parameters
devKeyboard matrix device instance.
colThe column to drive, or INPUT_KBD_MATRIX_COLUMN_DRIVE_NONE or INPUT_KBD_MATRIX_COLUMN_DRIVE_ALL.

◆ input_kbd_matrix_poll_start()

void input_kbd_matrix_poll_start ( const struct device dev)

#include <zephyr/input/input_kbd_matrix.h>

Start scanning the keyboard matrix.

Starts the keyboard matrix scanning cycle, this should be called in reaction of a press event, after the device has been put in detect mode.

Parameters
devKeyboard matrix device instance.