|
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 | ******************** |
@@ -806,6 +808,35 @@ ZTEST(spi_loopback, test_spi_concurrent_transfer_different_spec) |
806 | 808 | test_spi_concurrent_transfer_helper(specs); |
807 | 809 | } |
808 | 810 |
|
| 811 | +ZTEST(spi_loopback, test_spi_deinit) |
| 812 | +{ |
| 813 | + struct spi_dt_spec *spec = loopback_specs[0]; |
| 814 | + const struct device *dev = spec->bus; |
| 815 | + int ret; |
| 816 | + |
| 817 | + if (miso_pin.port == NULL || mosi_pin.port == NULL) { |
| 818 | + TC_PRINT(" zephyr,user miso-gpios or mosi-gpios are not defined\n"); |
| 819 | + ztest_test_skip(); |
| 820 | + } |
| 821 | + |
| 822 | + ret = device_deinit(dev); |
| 823 | + if (ret == -ENOTSUP) { |
| 824 | + TC_PRINT(" device deinit not supported\n"); |
| 825 | + ztest_test_skip(); |
| 826 | + } |
| 827 | + |
| 828 | + zassert_ok(ret); |
| 829 | + zassert_ok(gpio_pin_configure_dt(&miso_pin, GPIO_INPUT)); |
| 830 | + zassert_ok(gpio_pin_configure_dt(&mosi_pin, GPIO_OUTPUT_INACTIVE)); |
| 831 | + zassert_equal(gpio_pin_get_dt(&miso_pin), 0); |
| 832 | + zassert_ok(gpio_pin_set_dt(&mosi_pin, 1)); |
| 833 | + zassert_equal(gpio_pin_get_dt(&miso_pin), 1); |
| 834 | + zassert_ok(gpio_pin_set_dt(&mosi_pin, 0)); |
| 835 | + zassert_equal(gpio_pin_get_dt(&miso_pin), 0); |
| 836 | + zassert_ok(gpio_pin_configure_dt(&mosi_pin, GPIO_INPUT)); |
| 837 | + zassert_ok(device_init(dev)); |
| 838 | +} |
| 839 | + |
809 | 840 | #if (CONFIG_SPI_ASYNC) |
810 | 841 | static struct k_poll_signal async_sig = K_POLL_SIGNAL_INITIALIZER(async_sig); |
811 | 842 | static struct k_poll_event async_evt = |
|
0 commit comments