1 /*
2 * Copyright (c) 2021 Teslabs Engineering S.L.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6 #include <zephyr/drivers/pinctrl.h>
7 #include <zephyr/ztest.h>
8
9 /* pin configuration for test device */
10 #define TEST_DEVICE DT_NODELABEL(test_device)
11 PINCTRL_DT_DEV_CONFIG_DECLARE(TEST_DEVICE);
12 static const struct pinctrl_dev_config *pcfg = PINCTRL_DT_DEV_CONFIG_GET(TEST_DEVICE);
13
ZTEST(pinctrl_gd32,test_dt_extract)14 ZTEST(pinctrl_gd32, test_dt_extract)
15 {
16 const struct pinctrl_state *scfg;
17 pinctrl_soc_pin_t pin;
18
19 zassert_equal(pcfg->state_cnt, 1U);
20
21 scfg = &pcfg->states[0];
22
23 zassert_equal(scfg->id, PINCTRL_STATE_DEFAULT);
24 zassert_equal(scfg->pin_cnt, 12U);
25
26 pin = scfg->pins[0];
27 zassert_equal(GD32_PORT_GET(pin), 0);
28 zassert_equal(GD32_PIN_GET(pin), 0);
29 zassert_equal(GD32_AF_GET(pin), GD32_AF0);
30 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_NONE);
31 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
32 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_2MHZ);
33
34 pin = scfg->pins[1];
35 zassert_equal(GD32_PORT_GET(pin), 1);
36 zassert_equal(GD32_PIN_GET(pin), 1);
37 zassert_equal(GD32_AF_GET(pin), GD32_AF1);
38 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_NONE);
39 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
40 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_2MHZ);
41
42 pin = scfg->pins[2];
43 zassert_equal(GD32_PORT_GET(pin), 2);
44 zassert_equal(GD32_PIN_GET(pin), 2);
45 zassert_equal(GD32_AF_GET(pin), GD32_AF2);
46 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_NONE);
47 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
48 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_2MHZ);
49
50 pin = scfg->pins[3];
51 zassert_equal(GD32_PORT_GET(pin), 0);
52 zassert_equal(GD32_PIN_GET(pin), 3);
53 zassert_equal(GD32_AF_GET(pin), GD32_AF3);
54 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_NONE);
55 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_OD);
56 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_2MHZ);
57
58 pin = scfg->pins[4];
59 zassert_equal(GD32_PORT_GET(pin), 1);
60 zassert_equal(GD32_PIN_GET(pin), 4);
61 zassert_equal(GD32_AF_GET(pin), GD32_AF4);
62 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_NONE);
63 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
64 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_2MHZ);
65
66 pin = scfg->pins[5];
67 zassert_equal(GD32_PORT_GET(pin), 2);
68 zassert_equal(GD32_PIN_GET(pin), 5);
69 zassert_equal(GD32_AF_GET(pin), GD32_AF5);
70 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_PULLUP);
71 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
72 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_2MHZ);
73
74 pin = scfg->pins[6];
75 zassert_equal(GD32_PORT_GET(pin), 0);
76 zassert_equal(GD32_PIN_GET(pin), 6);
77 zassert_equal(GD32_AF_GET(pin), GD32_AF6);
78 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_PULLDOWN);
79 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
80 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_2MHZ);
81
82 pin = scfg->pins[7];
83 zassert_equal(GD32_PORT_GET(pin), 1);
84 zassert_equal(GD32_PIN_GET(pin), 7);
85 zassert_equal(GD32_AF_GET(pin), GD32_AF7);
86 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_NONE);
87 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
88 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_2MHZ);
89
90 pin = scfg->pins[8];
91 zassert_equal(GD32_PORT_GET(pin), 2);
92 zassert_equal(GD32_PIN_GET(pin), 8);
93 zassert_equal(GD32_AF_GET(pin), GD32_AF8);
94 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_NONE);
95 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
96 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_25MHZ);
97
98 pin = scfg->pins[9];
99 zassert_equal(GD32_PORT_GET(pin), 0);
100 zassert_equal(GD32_PIN_GET(pin), 9);
101 zassert_equal(GD32_AF_GET(pin), GD32_AF9);
102 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_NONE);
103 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
104 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_50MHZ);
105
106 pin = scfg->pins[10];
107 zassert_equal(GD32_PORT_GET(pin), 1);
108 zassert_equal(GD32_PIN_GET(pin), 10);
109 zassert_equal(GD32_AF_GET(pin), GD32_AF10);
110 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_NONE);
111 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
112 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_MAX);
113
114 pin = scfg->pins[11];
115 zassert_equal(GD32_PORT_GET(pin), 2);
116 zassert_equal(GD32_PIN_GET(pin), 11);
117 zassert_equal(GD32_AF_GET(pin), GD32_ANALOG);
118 zassert_equal(GD32_PUPD_GET(pin), GD32_PUPD_NONE);
119 zassert_equal(GD32_OTYPE_GET(pin), GD32_OTYPE_PP);
120 zassert_equal(GD32_OSPEED_GET(pin), GD32_OSPEED_2MHZ);
121 }
122
123 ZTEST_SUITE(pinctrl_gd32, NULL, NULL, NULL, NULL, NULL);
124