Loading...
Searching...
No Matches
matrix_keypad.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Koen Zandberg
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
52#ifndef MATRIX_KEYPAD_H
53#define MATRIX_KEYPAD_H
54
55#include <stdint.h>
56#include <stdbool.h>
57#include "periph/gpio.h"
58
59#ifdef __cplusplus
60extern "C" {
61#endif
62
66#ifndef CONFIG_MATRIX_KEYPAD_NUM_ROWS
67#define CONFIG_MATRIX_KEYPAD_NUM_ROWS 2
68#endif
69
73#ifndef CONFIG_MATRIX_KEYPAD_NUM_COLUMNS
74#define CONFIG_MATRIX_KEYPAD_NUM_COLUMNS 2
75#endif
76
84#ifndef CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_BEGIN
85#define CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_BEGIN 0xC0
86#endif
87
95#ifndef CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_END
96#define CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_END 0x7
97#endif
98
102#ifndef CONFIG_MATRIX_KEYPAD_ROWS_USE_OPEN_DRAIN
103#define CONFIG_MATRIX_KEYPAD_ROWS_USE_OPEN_DRAIN 0
104#endif
105
109#if CONFIG_MATRIX_KEYPAD_ROWS_USE_OPEN_DRAIN
110#define MATRIX_KEYPAD_ROWS_GPIO_MODE GPIO_OD_PU
111#else
112#define MATRIX_KEYPAD_ROWS_GPIO_MODE GPIO_OUT
113#endif
114
118#define MATRIX_KEYPAD_DEBOUNCE_MASK \
119 (CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_BEGIN | CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_END)
120
125#if CONFIG_MATRIX_KEYPAD_NUM_COLUMNS <= 8
127#elif CONFIG_MATRIX_KEYPAD_NUM_COLUMNS <= 16
128typedef uint16_t matrix_keypad_state_row_t;
129#elif CONFIG_MATRIX_KEYPAD_NUM_COLUMNS <= 32
130typedef uint32_t matrix_keypad_state_row_t;
131#elif CONFIG_MATRIX_KEYPAD_NUM_COLUMNS <= 64
132typedef uint64_t matrix_keypad_state_row_t;
133#else
134#error Too many columns on matrix keypad.
135#endif
136
157
166typedef void (*matrix_keypad_cb_t)(void *arg, size_t row, size_t column, bool state);
167
197
209 const matrix_keypad_params_t *params,
210 matrix_keypad_cb_t callback,
211 void *arg);
212
224#ifdef __cplusplus
225}
226#endif
227
228#endif /* MATRIX_KEYPAD_H */
Low-level GPIO peripheral driver interface definitions.
void(* matrix_keypad_cb_t)(void *arg, size_t row, size_t column, bool state)
Callback for key state changes.
uint8_t matrix_keypad_state_row_t
Type definition for a full row (all columns) state, variable width depending on the number of columns...
#define CONFIG_MATRIX_KEYPAD_NUM_ROWS
Maximum number of rows.
size_t matrix_keypad_scan(matrix_keypad_t *dev)
Scan through the keypad matrix.
int matrix_keypad_init(matrix_keypad_t *dev, const matrix_keypad_params_t *params, matrix_keypad_cb_t callback, void *arg)
Initialize the given device.
#define CONFIG_MATRIX_KEYPAD_NUM_COLUMNS
Maximum number of columns.
Device initialization parameters.
uint32_t row2col_delay
Delay in microseconds between configuring the row gpio and reading out the column.
Device descriptor for the driver.
matrix_keypad_cb_t callback
Callback called when a key changes state.
void * arg
callback context
const matrix_keypad_params_t * params
Device initialization parameters.