1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 00:09:46 +01:00

matrix_keypad: use gpio_is_valid

Bit of future proofing this module and use gpio_is_valid instead of
GPIO_UNDEF everywhere
This commit is contained in:
Koen Zandberg 2023-01-17 11:03:01 +01:00
parent b5af66cdd8
commit 21ac46c89d
No known key found for this signature in database
GPG Key ID: BA1718B37D79F51C

View File

@ -39,7 +39,7 @@ static void _setup_columns(matrix_keypad_t *dev)
{
for (size_t i = 0; i < CONFIG_MATRIX_KEYPAD_NUM_COLUMNS; i++) {
gpio_t column = dev->params->columns[i];
if (column != GPIO_UNDEF) {
if (gpio_is_valid(column)) {
gpio_init(column, GPIO_IN_PU);
}
}
@ -49,7 +49,7 @@ static void _setup_rows(matrix_keypad_t *dev)
{
for (size_t i = 0; i < CONFIG_MATRIX_KEYPAD_NUM_ROWS; i++) {
gpio_t row = dev->params->rows[i];
if (row != GPIO_UNDEF) {
if (gpio_is_valid(row)) {
gpio_init(row, MATRIX_KEYPAD_ROWS_GPIO_MODE); /* Open drain to ensure rows don't conflict */
gpio_set(row);
}
@ -107,7 +107,7 @@ size_t matrix_keypad_scan(matrix_keypad_t *dev)
for (size_t i = 0; i < CONFIG_MATRIX_KEYPAD_NUM_ROWS; i++) {
gpio_t row = dev->params->rows[i];
if (row == GPIO_UNDEF) {
if (!gpio_is_valid(row)) {
continue;
}
@ -122,7 +122,7 @@ size_t matrix_keypad_scan(matrix_keypad_t *dev)
/* Scan columns */
for (size_t j = 0; j < CONFIG_MATRIX_KEYPAD_NUM_COLUMNS; j++) {
gpio_t column = dev->params->columns[j];
if (column == GPIO_UNDEF) {
if (!gpio_is_valid(column)) {
continue;
}
bool status = !gpio_read(column);