1 /*
2 * Copyright (c) 2021 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/drivers/pinctrl.h>
8 #include <zephyr/ztest.h>
9
10 /* pin configuration for test device */
11 #define TEST_DEVICE DT_NODELABEL(test_device)
12 PINCTRL_DT_DEV_CONFIG_DECLARE(TEST_DEVICE);
13 static const struct pinctrl_dev_config *pcfg = PINCTRL_DT_DEV_CONFIG_GET(TEST_DEVICE);
14
ZTEST(pinctrl_nrf,test_dt_extract)15 ZTEST(pinctrl_nrf, test_dt_extract)
16 {
17 const struct pinctrl_state *scfg;
18
19 zassert_equal(pcfg->reg, 0x0U);
20 zassert_equal(pcfg->state_cnt, 1U);
21
22 scfg = &pcfg->states[0];
23
24 zassert_equal(scfg->id, PINCTRL_STATE_DEFAULT);
25 zassert_equal(scfg->pin_cnt, 7U);
26
27 zassert_equal(NRF_GET_FUN(scfg->pins[0]), NRF_FUN_UART_TX);
28 zassert_equal(NRF_GET_LP(scfg->pins[0]), NRF_LP_DISABLE);
29 zassert_equal(NRF_GET_DRIVE(scfg->pins[0]), NRF_DRIVE_S0S1);
30 zassert_equal(NRF_GET_PULL(scfg->pins[0]), NRF_PULL_NONE);
31 zassert_equal(NRF_GET_PIN(scfg->pins[0]), 1U);
32
33 zassert_equal(NRF_GET_FUN(scfg->pins[1]), NRF_FUN_UART_RTS);
34 zassert_equal(NRF_GET_LP(scfg->pins[1]), NRF_LP_DISABLE);
35 zassert_equal(NRF_GET_DRIVE(scfg->pins[1]), NRF_DRIVE_S0S1);
36 zassert_equal(NRF_GET_PULL(scfg->pins[1]), NRF_PULL_NONE);
37 zassert_equal(NRF_GET_PIN(scfg->pins[1]), 2U);
38
39 zassert_equal(NRF_GET_FUN(scfg->pins[2]), NRF_FUN_UART_RX);
40 zassert_equal(NRF_GET_PIN(scfg->pins[2]), NRF_PIN_DISCONNECTED);
41
42 zassert_equal(NRF_GET_FUN(scfg->pins[3]), NRF_FUN_UART_RX);
43 zassert_equal(NRF_GET_LP(scfg->pins[3]), NRF_LP_DISABLE);
44 zassert_equal(NRF_GET_DRIVE(scfg->pins[3]), NRF_DRIVE_H0S1);
45 zassert_equal(NRF_GET_PULL(scfg->pins[3]), NRF_PULL_NONE);
46 zassert_equal(NRF_GET_PIN(scfg->pins[3]), 3U);
47
48 zassert_equal(NRF_GET_FUN(scfg->pins[4]), NRF_FUN_UART_RX);
49 zassert_equal(NRF_GET_LP(scfg->pins[4]), NRF_LP_DISABLE);
50 zassert_equal(NRF_GET_DRIVE(scfg->pins[4]), NRF_DRIVE_S0S1);
51 zassert_equal(NRF_GET_PULL(scfg->pins[4]), NRF_PULL_UP);
52 zassert_equal(NRF_GET_PIN(scfg->pins[4]), 4U);
53
54 zassert_equal(NRF_GET_FUN(scfg->pins[5]), NRF_FUN_UART_RX);
55 zassert_equal(NRF_GET_LP(scfg->pins[5]), NRF_LP_DISABLE);
56 zassert_equal(NRF_GET_DRIVE(scfg->pins[5]), NRF_DRIVE_S0S1);
57 zassert_equal(NRF_GET_PULL(scfg->pins[5]), NRF_PULL_DOWN);
58 zassert_equal(NRF_GET_PIN(scfg->pins[5]), 5U);
59
60 zassert_equal(NRF_GET_FUN(scfg->pins[6]), NRF_FUN_UART_CTS);
61 zassert_equal(NRF_GET_LP(scfg->pins[6]), NRF_LP_ENABLE);
62 zassert_equal(NRF_GET_DRIVE(scfg->pins[6]), NRF_DRIVE_S0S1);
63 zassert_equal(NRF_GET_PULL(scfg->pins[6]), NRF_PULL_NONE);
64 zassert_equal(NRF_GET_PIN(scfg->pins[6]), 38U);
65 }
66
67 ZTEST_SUITE(pinctrl_nrf, NULL, NULL, NULL, NULL, NULL);
68