Matrix keypad driver for row/column keypads. More...

Detailed Description

Matrix keypad driver for row/column keypads.

Files

file  matrix_keypad.h
 
file  matrix_keypad_params.h
 Default configuration.
 

Data Structures

struct  matrix_keypad_params_t
 Device initialization parameters. More...
 
struct  matrix_keypad_t
 Device descriptor for the driver. More...
 

Macros

#define CONFIG_MATRIX_KEYPAD_NUM_ROWS   2
 Maximum number of rows.
 
#define CONFIG_MATRIX_KEYPAD_NUM_COLUMNS   2
 Maximum number of columns.
 
#define CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_BEGIN   0xC0
 Debounce pattern high to low bits. More...
 
#define CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_END   0x7
 Debounce pattern low to high bits. More...
 
#define CONFIG_MATRIX_KEYPAD_ROWS_USE_OPEN_DRAIN   0
 Use open drain GPIO mode.
 
#define MATRIX_KEYPAD_ROWS_GPIO_MODE   GPIO_OUT
 GPIO mode used for the row GPIOs.
 
#define MATRIX_KEYPAD_DEBOUNCE_MASK    (CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_BEGIN | CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_END)
 Debounce pattern mask.
 

Typedefs

typedef uint8_t matrix_keypad_state_row_t
 Type definition for a full row (all columns) state, variable width depending on the number of columns.
 
typedef void(* matrix_keypad_cb_t) (void *arg, size_t row, size_t column, bool state)
 Callback for key state changes. More...
 

Functions

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. More...
 
size_t matrix_keypad_scan (matrix_keypad_t *dev)
 Scan through the keypad matrix. More...
 

Macro Definition Documentation

◆ CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_BEGIN

#define CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_BEGIN   0xC0

Debounce pattern high to low bits.

This pattern should consist of bits set on the most significant bits of the value. The number of bits set determines the number of scans the key must be in the current state before a change is processed.

Definition at line 84 of file matrix_keypad.h.

◆ CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_END

#define CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_END   0x7

Debounce pattern low to high bits.

This pattern should consist of bits set on the least significant bits of the value. The number of bits set determines the number of scans the key must be in the next state before a change is processed.

Definition at line 95 of file matrix_keypad.h.

Typedef Documentation

◆ matrix_keypad_cb_t

typedef void(* matrix_keypad_cb_t) (void *arg, size_t row, size_t column, bool state)

Callback for key state changes.

Parameters
argcallback context
rowRow that changed
columnColumn that changed
stateNew state of the key, 1 = pressed, 0 = released

Definition at line 165 of file matrix_keypad.h.

Function Documentation

◆ matrix_keypad_init()

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.

Parameters
[in,out]devDevice descriptor of the driver
[in]paramsInitialization parameters
[in]callbackCallback to call on state changes
[in]argContext argument for the callback
Returns
0 on success

◆ matrix_keypad_scan()

size_t matrix_keypad_scan ( matrix_keypad_t dev)

Scan through the keypad matrix.

This updates the state of the device descriptor, calling matrix_keypad_cb_t when a key press or release has been detected

Parameters
[in,out]devDevice descriptor of the driver
Returns
Number of keys that changed state