1 /*
2  * Copyright (c) 2022 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/ztest.h>
8 #include <zephyr/devicetree.h>
9 #include <zephyr/device.h>
10 #include <zephyr/drivers/spi.h>
11 #include <zephyr/logging/log.h>
12 
13 LOG_MODULE_REGISTER(test, CONFIG_LOG_DEFAULT_LEVEL);
14 
ZTEST(spi_dt_spec,test_dt_spec)15 ZTEST(spi_dt_spec, test_dt_spec)
16 {
17 	const struct spi_dt_spec spi_cs =
18 		SPI_DT_SPEC_GET(DT_NODELABEL(test_spi_dev_cs), 0, 0);
19 
20 	LOG_DBG("spi_cs.bus = %p", spi_cs.bus);
21 	LOG_DBG("spi_cs.config.cs.gpio.port = %p", spi_cs.config.cs.gpio.port);
22 	LOG_DBG("spi_cs.config.cs.gpio.pin = %u", spi_cs.config.cs.gpio.pin);
23 
24 	zassert_equal(spi_cs.bus, DEVICE_DT_GET(DT_NODELABEL(test_spi_cs)), "");
25 	zassert_true(spi_cs_is_gpio_dt(&spi_cs), "");
26 	zassert_equal(spi_cs.config.cs.gpio.port, DEVICE_DT_GET(DT_NODELABEL(test_gpio)), "");
27 	zassert_equal(spi_cs.config.cs.gpio.pin, 0x10, "");
28 
29 	const struct spi_dt_spec spi_no_cs =
30 		SPI_DT_SPEC_GET(DT_NODELABEL(test_spi_dev_no_cs), 0, 0);
31 
32 	LOG_DBG("spi_no_cs.bus = %p", spi_no_cs.bus);
33 	LOG_DBG("spi_no_cs.config.cs.gpio.port = %p", spi_no_cs.config.cs.gpio.port);
34 
35 	zassert_equal(spi_no_cs.bus, DEVICE_DT_GET(DT_NODELABEL(test_spi_no_cs)), "");
36 	zassert_false(spi_cs_is_gpio_dt(&spi_no_cs), "");
37 }
38 
39 ZTEST_SUITE(spi_dt_spec, NULL, NULL, NULL, NULL, NULL);
40