Skip to content

Commit eb04ef9

Browse files
committed
test: added gpio_kpp test implementation.
added gpio_kpp test implementation. Signed-off-by: Qiang Zhang <[email protected]>
1 parent 3681bd8 commit eb04ef9

File tree

6 files changed

+175
-0
lines changed

6 files changed

+175
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
6+
project(input_kpp)
7+
8+
target_include_directories(app PRIVATE ${ZEPHYR_BASE}/drivers/input)
9+
10+
FILE(GLOB app_sources src/*.c)
11+
target_sources(app PRIVATE ${app_sources})
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
aliases {
9+
kpp = &kpp;
10+
};
11+
};
12+
13+
&pinctrl {
14+
kpp_default: kpp_default {
15+
group0 {
16+
pinmux = <
17+
&iomuxc_gpio_sd_b1_00_kpp_row7
18+
&iomuxc_gpio_sd_b1_01_kpp_col7
19+
&iomuxc_gpio_sd_b1_02_kpp_row6
20+
&iomuxc_gpio_sd_b1_03_kpp_col6
21+
>;
22+
drive-strength = "high";
23+
bias-pull-up;
24+
slew-rate = "fast";
25+
};
26+
};
27+
};
28+
29+
&kpp {
30+
pinctrl-0 = <&kpp_default>;
31+
pinctrl-names = "default";
32+
status = "okay";
33+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
aliases {
9+
kpp = &kpp;
10+
};
11+
};
12+
13+
&pinctrl {
14+
kpp_default: kpp_default {
15+
group0 {
16+
pinmux = <
17+
&iomuxc_gpio_sd_b1_00_kpp_row7
18+
&iomuxc_gpio_sd_b1_01_kpp_col7
19+
&iomuxc_gpio_sd_b1_02_kpp_row6
20+
&iomuxc_gpio_sd_b1_03_kpp_col6
21+
>;
22+
drive-strength = "high";
23+
bias-pull-up;
24+
slew-rate = "fast";
25+
};
26+
};
27+
};
28+
29+
&kpp {
30+
pinctrl-0 = <&kpp_default>;
31+
pinctrl-names = "default";
32+
status = "okay";
33+
};

tests/drivers/input/gpio_kpp/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_ZTEST=y
2+
CONFIG_INPUT=y
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) 2024 Arif Balik <[email protected]>
3+
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/device.h>
8+
#include <zephyr/input/input.h>
9+
#include <zephyr/input/input_kpp.h>
10+
#include <zephyr/kernel.h>
11+
#include <zephyr/sys/util.h>
12+
#include <zephyr/ztest.h>
13+
14+
#include <soc.h>
15+
#include <autoconf.h>
16+
#include <inttypes.h>
17+
#include <zephyr/drivers/gpio.h>
18+
19+
#if DT_NODE_HAS_STATUS_OKAY(DT_ALIAS(kpp))
20+
#define KPP_NODE DT_ALIAS(kpp)
21+
#else
22+
#error "Could not find an KPP compatible device in DT"
23+
#endif
24+
25+
#define TEST_KPP_ACTIVE_COLUMROWS (0xFF)
26+
27+
#define WAIT_FOR_IDLE_TIMEOUT_US (5 * USEC_PER_SEC)
28+
29+
ZTEST_SUITE(kpp_scan, NULL, NULL, NULL, NULL, NULL);
30+
31+
volatile bool g_kpp_interrupt;
32+
uint8_t read_keys[INPUT_KPP_COLUMNNUM_MAX] = {0};
33+
34+
static const struct device *test_dev = DEVICE_DT_GET(KPP_NODE);
35+
36+
static void kpp_scan_wait_for_idle(void)
37+
{
38+
k_busy_wait(1000);
39+
40+
if (!g_kpp_interrupt) {
41+
zassert_true((!g_kpp_interrupt), "timeout waiting for idle state");
42+
}
43+
}
44+
45+
static void kpp_scan_data_check(uint8_t *data)
46+
{
47+
int row_data_mask;
48+
49+
for (int i = 0; i < INPUT_KPP_COLUMNNUM_MAX; i++) {
50+
if (data[i] != 0) {
51+
row_data_mask = data[i];
52+
for (int j = 0; j < INPUT_KPP_ROWNUM_MAX; j++) {
53+
if ((row_data_mask & (1 << j)) == 0) {
54+
continue;
55+
}
56+
TC_PRINT("Key pressed at row %d, column %d", j, i);
57+
}
58+
}
59+
}
60+
61+
}
62+
63+
static void kpp_cb(const struct device *dev)
64+
{
65+
input_kpp_scan(dev, &read_keys[0]);
66+
g_kpp_interrupt = true;
67+
}
68+
69+
ZTEST(kpp_scan, test_kpp_keypress_interrupt)
70+
{
71+
input_kpp_set_callback(test_dev, kpp_cb);
72+
input_kpp_config(test_dev, TEST_KPP_ACTIVE_COLUMROWS,
73+
TEST_KPP_ACTIVE_COLUMROWS, KPP_EVENT_KEY_DPRESS);
74+
75+
kpp_scan_wait_for_idle();
76+
zexpect_true(g_kpp_interrupt);
77+
g_kpp_interrupt = false;
78+
79+
kpp_scan_data_check(&read_keys[0]);
80+
}
81+
82+
ZTEST(kpp_scan, test_kppkeyrelease_interrupt)
83+
{
84+
input_kpp_set_callback(test_dev, kpp_cb);
85+
input_kpp_config(test_dev, TEST_KPP_ACTIVE_COLUMROWS,
86+
TEST_KPP_ACTIVE_COLUMROWS, KPP_EVENT_KEY_RELEASE);
87+
88+
kpp_scan_wait_for_idle();
89+
zexpect_true(g_kpp_interrupt);
90+
g_kpp_interrupt = false;
91+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tests:
2+
drivers.input.kpp_scan:
3+
tags: drivers input kpp
4+
filter: dt_compat_enabled("nxp,mcux-kpp")
5+
depends_on: kpp

0 commit comments

Comments
 (0)