7#ifndef ZEPHYR_INCLUDE_INPUT_KBD_MATRIX_H_
8#define ZEPHYR_INCLUDE_INPUT_KBD_MATRIX_H_
26#define INPUT_KBD_MATRIX_COLUMN_DRIVE_NONE -1
29#define INPUT_KBD_MATRIX_COLUMN_DRIVE_ALL -2
32#define INPUT_KBD_MATRIX_SCAN_OCURRENCES 30U
35#if CONFIG_INPUT_KBD_MATRIX_16_BIT_ROW
37#define PRIkbdrow "04" PRIx16
40#define PRIkbdrow "02" PRIx8
43#if defined(CONFIG_INPUT_KBD_ACTUAL_KEY_MASK_DYNAMIC) || defined(__DOXYGEN__)
44#define INPUT_KBD_ACTUAL_KEY_MASK_CONST
66#define INPUT_KBD_ACTUAL_KEY_MASK_CONST const
70#define INPUT_KBD_MATRIX_ROW_BITS NUM_BITS(kbd_row_t)
132#define INPUT_KBD_MATRIX_DATA_NAME(node_id, name) \
133 _CONCAT(__input_kbd_matrix_, \
134 _CONCAT(name, DEVICE_DT_NAME_GET(node_id)))
140#define INPUT_KBD_MATRIX_DT_DEFINE_ROW_COL(node_id, _row_size, _col_size) \
141 BUILD_ASSERT(IN_RANGE(_row_size, 1, INPUT_KBD_MATRIX_ROW_BITS), "invalid row-size"); \
142 BUILD_ASSERT(IN_RANGE(_col_size, 1, UINT8_MAX), "invalid col-size"); \
143 IF_ENABLED(DT_NODE_HAS_PROP(node_id, actual_key_mask), ( \
144 BUILD_ASSERT(DT_PROP_LEN(node_id, actual_key_mask) == _col_size, \
145 "actual-key-mask size does not match the number of columns"); \
146 static INPUT_KBD_ACTUAL_KEY_MASK_CONST kbd_row_t \
147 INPUT_KBD_MATRIX_DATA_NAME(node_id, actual_key_mask)[_col_size] = \
148 DT_PROP(node_id, actual_key_mask); \
150 static kbd_row_t INPUT_KBD_MATRIX_DATA_NAME(node_id, stable_state)[_col_size]; \
151 static kbd_row_t INPUT_KBD_MATRIX_DATA_NAME(node_id, unstable_state)[_col_size]; \
152 static kbd_row_t INPUT_KBD_MATRIX_DATA_NAME(node_id, previous_state)[_col_size]; \
153 static kbd_row_t INPUT_KBD_MATRIX_DATA_NAME(node_id, new_state)[_col_size]; \
154 static uint8_t INPUT_KBD_MATRIX_DATA_NAME(node_id, scan_cycle_idx)[_row_size * _col_size];
159#define INPUT_KBD_MATRIX_DT_DEFINE(node_id) \
160 INPUT_KBD_MATRIX_DT_DEFINE_ROW_COL( \
161 node_id, DT_PROP(node_id, row_size), DT_PROP(node_id, col_size))
171#define INPUT_KBD_MATRIX_DT_INST_DEFINE_ROW_COL(inst, row_size, col_size) \
172 INPUT_KBD_MATRIX_DT_DEFINE_ROW_COL(DT_DRV_INST(inst), row_size, col_size)
179#define INPUT_KBD_MATRIX_DT_INST_DEFINE(inst) \
180 INPUT_KBD_MATRIX_DT_DEFINE(DT_DRV_INST(inst))
190#define INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT_ROW_COL(node_id, _api, _row_size, _col_size) \
193 .row_size = _row_size, \
194 .col_size = _col_size, \
195 .poll_period_us = DT_PROP(node_id, poll_period_ms) * USEC_PER_MSEC, \
196 .stable_poll_period_us = DT_PROP_OR(node_id, stable_poll_period_ms, \
197 DT_PROP(node_id, poll_period_ms)) * \
199 .poll_timeout_ms = DT_PROP(node_id, poll_timeout_ms), \
200 .debounce_down_us = DT_PROP(node_id, debounce_down_ms) * USEC_PER_MSEC, \
201 .debounce_up_us = DT_PROP(node_id, debounce_up_ms) * USEC_PER_MSEC, \
202 .settle_time_us = DT_PROP(node_id, settle_time_us), \
203 .ghostkey_check = !DT_PROP(node_id, no_ghostkey_check), \
204 IF_ENABLED(DT_NODE_HAS_PROP(node_id, actual_key_mask), ( \
205 .actual_key_mask = INPUT_KBD_MATRIX_DATA_NAME(node_id, actual_key_mask), \
208 .matrix_stable_state = INPUT_KBD_MATRIX_DATA_NAME(node_id, stable_state), \
209 .matrix_unstable_state = INPUT_KBD_MATRIX_DATA_NAME(node_id, unstable_state), \
210 .matrix_previous_state = INPUT_KBD_MATRIX_DATA_NAME(node_id, previous_state), \
211 .matrix_new_state = INPUT_KBD_MATRIX_DATA_NAME(node_id, new_state), \
212 .scan_cycle_idx = INPUT_KBD_MATRIX_DATA_NAME(node_id, scan_cycle_idx), \
221#define INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT(node_id, api) \
222 INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT_ROW_COL( \
223 node_id, api, DT_PROP(node_id, row_size), DT_PROP(node_id, col_size))
234#define INPUT_KBD_MATRIX_DT_INST_COMMON_CONFIG_INIT_ROW_COL(inst, api, row_size, col_size) \
235 INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT_ROW_COL(DT_DRV_INST(inst), api, row_size, col_size)
243#define INPUT_KBD_MATRIX_DT_INST_COMMON_CONFIG_INIT(inst, api) \
244 INPUT_KBD_MATRIX_DT_COMMON_CONFIG_INIT(DT_DRV_INST(inst), api)
257#ifdef CONFIG_PM_DEVICE
264 CONFIG_INPUT_KBD_MATRIX_THREAD_STACK_SIZE);
273#define INPUT_KBD_STRUCT_CHECK(config, data) \
274 BUILD_ASSERT(offsetof(config, common) == 0, \
275 "struct input_kbd_matrix_common_config must be placed first"); \
276 BUILD_ASSERT(offsetof(data, common) == 0, \
277 "struct input_kbd_matrix_common_data must be placed first")
289#if defined(CONFIG_INPUT_KBD_DRIVE_COLUMN_HOOK) || defined(__DOXYGEN__)
317#ifdef CONFIG_PM_DEVICE
327int input_kbd_matrix_pm_action(
const struct device *dev,
long atomic_t
Definition atomic_types.h:15
pm_device_action
Device PM actions.
Definition device.h:90
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:411
Thread Structure.
Definition thread.h:259
Variables needed for system clock.