Skip to content

Commit 2a8e3fe

Browse files
committed
tests: gpio_basic_api: Convert test to use DEVICE_DT_GET
Move to use DEVICE_DT_GET instead of device_get_binding as we work on phasing out use of DTS 'label' property. Signed-off-by: Kumar Gala <[email protected]>
1 parent 1f82e32 commit 2a8e3fe

File tree

5 files changed

+26
-28
lines changed

5 files changed

+26
-28
lines changed

tests/drivers/gpio/gpio_basic_api/src/main.c

+11-15
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ static void board_setup(void)
2121
{
2222
#if DT_NODE_HAS_STATUS(DT_INST(0, test_gpio_basic_api), okay)
2323
/* PIN_IN and PIN_OUT must be on same controller. */
24-
if (strcmp(DT_GPIO_LABEL(DT_INST(0, test_gpio_basic_api), out_gpios),
25-
DT_GPIO_LABEL(DT_INST(0, test_gpio_basic_api), in_gpios)) != 0) {
24+
const struct device *in_dev = DEVICE_DT_GET(DEV_OUT);
25+
const struct device *out_dev = DEVICE_DT_GET(DEV_IN);
26+
27+
if (in_dev != out_dev) {
2628
printk("FATAL: output controller %s != input controller %s\n",
27-
DT_GPIO_LABEL(DT_INST(0, test_gpio_basic_api), out_gpios),
28-
DT_GPIO_LABEL(DT_INST(0, test_gpio_basic_api), in_gpios));
29+
out_dev->name, in_dev->name);
2930
k_panic();
3031
}
3132
#endif
@@ -37,12 +38,6 @@ static void board_setup(void)
3738
* selected as test pins in device tree.
3839
*/
3940

40-
if (strcmp(DEV_NAME, "GPIO_5") != 0) {
41-
printk("FATAL: controller set in DTS %s != controller %s\n",
42-
DEV_NAME, "GPIO_5");
43-
k_panic();
44-
}
45-
4641
if (PIN_IN != 15) {
4742
printk("FATAL: input pin set in DTS %d != %d\n", PIN_IN, 15);
4843
k_panic();
@@ -87,16 +82,17 @@ static void board_setup(void)
8782
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) |
8883
IOMUXC_SW_PAD_CTL_PAD_DSE(6));
8984
#elif defined(CONFIG_BOARD_RV32M1_VEGA)
90-
const char *pmx_name = DT_LABEL(DT_NODELABEL(porta));
91-
const struct device *pmx = device_get_binding(pmx_name);
85+
const struct device *pmx = DEVICE_DT_GET(DT_NODELABEL(porta));
86+
87+
zassert_true(device_is_ready(pmx), "pinmux dev is not ready");
9288

9389
pinmux_pin_set(pmx, PIN_OUT, PORT_PCR_MUX(kPORT_MuxAsGpio));
9490
pinmux_pin_set(pmx, PIN_IN, PORT_PCR_MUX(kPORT_MuxAsGpio));
9591
#elif defined(CONFIG_GPIO_EMUL)
9692
extern struct gpio_callback gpio_emul_callback;
97-
const struct device *dev = device_get_binding(DEV_NAME);
98-
zassert_not_equal(dev, NULL,
99-
"Device not found");
93+
const struct device *dev = DEVICE_DT_GET(DEV);
94+
95+
zassert_true(device_is_ready(dev), "GPIO dev is not ready");
10096
int rc = gpio_add_callback(dev, &gpio_emul_callback);
10197
__ASSERT(rc == 0, "gpio_add_callback() failed: %d", rc);
10298
#endif

tests/drivers/gpio/gpio_basic_api/src/test_callback_manage.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static void trigger_callback(const struct device *dev, int enable_cb)
8383

8484
static int test_callback_add_remove(void)
8585
{
86-
const struct device *dev = device_get_binding(DEV_NAME);
86+
const struct device *dev = DEVICE_DT_GET(DEV);
8787

8888
/* SetUp: initialize environment */
8989
int rc = init_callback(dev, callback_1, callback_2);
@@ -132,7 +132,7 @@ static int test_callback_add_remove(void)
132132
static int test_callback_self_remove(void)
133133
{
134134
int res = TC_FAIL;
135-
const struct device *dev = device_get_binding(DEV_NAME);
135+
const struct device *dev = DEVICE_DT_GET(DEV);
136136

137137
/* SetUp: initialize environment */
138138
int rc = init_callback(dev, callback_1, callback_remove_self);
@@ -184,7 +184,7 @@ static int test_callback_self_remove(void)
184184

185185
static int test_callback_enable_disable(void)
186186
{
187-
const struct device *dev = device_get_binding(DEV_NAME);
187+
const struct device *dev = DEVICE_DT_GET(DEV);
188188

189189
/* SetUp: initialize environment */
190190
int rc = init_callback(dev, callback_1, callback_2);

tests/drivers/gpio/gpio_basic_api/src/test_callback_trigger.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void callback(const struct device *dev,
3333

3434
static int test_callback(int mode)
3535
{
36-
const struct device *dev = device_get_binding(DEV_NAME);
36+
const struct device *dev = DEVICE_DT_GET(DEV);
3737
struct drv_data *drv_data = &data;
3838

3939
gpio_pin_interrupt_configure(dev, PIN_IN, GPIO_INT_DISABLE);

tests/drivers/gpio/gpio_basic_api/src/test_gpio.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@
2121
* If this is not present devices that have gpio-0, gpio-1, or gpio-2
2222
* aliases are supported for build-only tests.
2323
*/
24-
#define DEV_NAME DT_GPIO_LABEL(DT_INST(0, test_gpio_basic_api), out_gpios)
24+
#define DEV_OUT DT_GPIO_CTLR(DT_INST(0, test_gpio_basic_api), out_gpios)
25+
#define DEV_IN DT_GPIO_CTLR(DT_INST(0, test_gpio_basic_api), in_gpios)
26+
#define DEV DEV_OUT /* DEV_OUT should equal DEV_IN, we test for this */
2527
#define PIN_OUT DT_GPIO_PIN(DT_INST(0, test_gpio_basic_api), out_gpios)
2628
#define PIN_IN DT_GPIO_PIN(DT_INST(0, test_gpio_basic_api), in_gpios)
2729

2830
#elif DT_NODE_HAS_STATUS(DT_ALIAS(gpio_0), okay)
29-
#define DEV_NAME DT_LABEL(DT_ALIAS(gpio_0))
31+
#define DEV DT_GPIO_CTLR(DT_ALIAS(gpio_0))
3032
#elif DT_NODE_HAS_STATUS(DT_ALIAS(gpio_1), okay)
31-
#define DEV_NAME DT_LABEL(DT_ALIAS(gpio_1))
33+
#define DEV DT_GPIO_CTLR(DT_ALIAS(gpio_1))
3234
#elif DT_NODE_HAS_STATUS(DT_ALIAS(gpio_3), okay)
33-
#define DEV_NAME DT_LABEL(DT_ALIAS(gpio_3))
35+
#define DEV DT_GPIO_CTLR(DT_ALIAS(gpio_3))
3436
#else
3537
#error Unsupported board
3638
#endif

tests/drivers/gpio/gpio_basic_api/src/test_gpio_port.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ static int setup(void)
6969
int rc;
7070
gpio_port_value_t v1;
7171

72-
TC_PRINT("Validate device %s\n", DEV_NAME);
73-
dev = device_get_binding(DEV_NAME);
74-
zassert_not_equal(dev, NULL,
75-
"Device not found");
72+
const struct device *dev = DEVICE_DT_GET(DEV);
7673

77-
TC_PRINT("Check %s output %d connected to input %d\n", DEV_NAME,
74+
TC_PRINT("Validate device %s\n", dev->name);
75+
zassert_true(device_is_ready(dev), "GPIO dev is not ready");
76+
77+
TC_PRINT("Check %s output %d connected to input %d\n", dev->name,
7878
PIN_OUT, PIN_IN);
7979

8080
rc = gpio_pin_configure(dev, PIN_IN, GPIO_INPUT);

0 commit comments

Comments
 (0)