|
16 | 16 | #include <zephyr/ztest.h>
|
17 | 17 | #include <zephyr/drivers/spi.h>
|
18 | 18 | #include <zephyr/pm/device_runtime.h>
|
| 19 | +#include <zephyr/drivers/gpio.h> |
19 | 20 | #include <zephyr/kernel.h>
|
20 | 21 | #include <stdio.h>
|
21 | 22 | #include <stdarg.h>
|
@@ -56,7 +57,8 @@ static int spec_idx;
|
56 | 57 | */
|
57 | 58 | struct spi_dt_spec spec_copies[5];
|
58 | 59 |
|
59 |
| - |
| 60 | +const struct gpio_dt_spec miso_pin = GPIO_DT_SPEC_GET_OR(DT_PATH(zephyr_user), miso_gpios, {}); |
| 61 | +const struct gpio_dt_spec mosi_pin = GPIO_DT_SPEC_GET_OR(DT_PATH(zephyr_user), mosi_gpios, {}); |
60 | 62 |
|
61 | 63 | /*
|
62 | 64 | ********************
|
@@ -831,6 +833,35 @@ ZTEST(spi_loopback, test_spi_concurrent_transfer_different_spec)
|
831 | 833 | test_spi_concurrent_transfer_helper(specs);
|
832 | 834 | }
|
833 | 835 |
|
| 836 | +ZTEST(spi_loopback, test_spi_deinit) |
| 837 | +{ |
| 838 | + struct spi_dt_spec *spec = loopback_specs[0]; |
| 839 | + const struct device *dev = spec->bus; |
| 840 | + int ret; |
| 841 | + |
| 842 | + if (miso_pin.port == NULL || mosi_pin.port == NULL) { |
| 843 | + TC_PRINT(" zephyr,user miso-gpios or mosi-gpios are not defined\n"); |
| 844 | + ztest_test_skip(); |
| 845 | + } |
| 846 | + |
| 847 | + ret = device_deinit(dev); |
| 848 | + if (ret == -ENOTSUP) { |
| 849 | + TC_PRINT(" device deinit not supported\n"); |
| 850 | + ztest_test_skip(); |
| 851 | + } |
| 852 | + |
| 853 | + zassert_ok(ret); |
| 854 | + zassert_ok(gpio_pin_configure_dt(&miso_pin, GPIO_INPUT)); |
| 855 | + zassert_ok(gpio_pin_configure_dt(&mosi_pin, GPIO_OUTPUT_INACTIVE)); |
| 856 | + zassert_equal(gpio_pin_get_dt(&miso_pin), 0); |
| 857 | + zassert_ok(gpio_pin_set_dt(&mosi_pin, 1)); |
| 858 | + zassert_equal(gpio_pin_get_dt(&miso_pin), 1); |
| 859 | + zassert_ok(gpio_pin_set_dt(&mosi_pin, 0)); |
| 860 | + zassert_equal(gpio_pin_get_dt(&miso_pin), 0); |
| 861 | + zassert_ok(gpio_pin_configure_dt(&mosi_pin, GPIO_INPUT)); |
| 862 | + zassert_ok(device_init(dev)); |
| 863 | +} |
| 864 | + |
834 | 865 | #if (CONFIG_SPI_ASYNC)
|
835 | 866 | static struct k_poll_signal async_sig = K_POLL_SIGNAL_INITIALIZER(async_sig);
|
836 | 867 | static struct k_poll_event async_evt =
|
|
0 commit comments