|
16 | 16 |
|
17 | 17 | #include <zephyr/drivers/i2c.h>
|
18 | 18 | #include <zephyr/drivers/i2c/target/eeprom.h>
|
| 19 | +#include <zephyr/drivers/gpio.h> |
19 | 20 |
|
20 | 21 | #include <zephyr/ztest.h>
|
21 | 22 |
|
@@ -166,6 +167,62 @@ static int run_program_read(const struct device *i2c, uint8_t addr,
|
166 | 167 | return 0;
|
167 | 168 | }
|
168 | 169 |
|
| 170 | +ZTEST(i2c_eeprom_target, test_deinit) |
| 171 | +{ |
| 172 | + const struct device *const i2c_0 = DEVICE_DT_GET(DT_BUS(NODE_EP0)); |
| 173 | + const struct device *const i2c_1 = DEVICE_DT_GET(DT_BUS(NODE_EP1)); |
| 174 | + const struct gpio_dt_spec sda_pin_0 = |
| 175 | + GPIO_DT_SPEC_GET_OR(DT_PATH(zephyr_user), sda0_gpios, {}); |
| 176 | + const struct gpio_dt_spec scl_pin_0 = |
| 177 | + GPIO_DT_SPEC_GET_OR(DT_PATH(zephyr_user), scl0_gpios, {}); |
| 178 | + const struct gpio_dt_spec sda_pin_1 = |
| 179 | + GPIO_DT_SPEC_GET_OR(DT_PATH(zephyr_user), sda1_gpios, {}); |
| 180 | + const struct gpio_dt_spec scl_pin_1 = |
| 181 | + GPIO_DT_SPEC_GET_OR(DT_PATH(zephyr_user), scl1_gpios, {}); |
| 182 | + int ret; |
| 183 | + |
| 184 | + if (i2c_0 == i2c_1) { |
| 185 | + TC_PRINT(" gpio loopback required for test\n"); |
| 186 | + ztest_test_skip(); |
| 187 | + } |
| 188 | + |
| 189 | + if (scl_pin_0.port == NULL || sda_pin_0.port == NULL || |
| 190 | + scl_pin_1.port == NULL || sda_pin_1.port == NULL) { |
| 191 | + TC_PRINT(" bus gpios not specified in zephyr,path\n"); |
| 192 | + ztest_test_skip(); |
| 193 | + } |
| 194 | + |
| 195 | + ret = device_deinit(i2c_0); |
| 196 | + if (ret == -ENOTSUP) { |
| 197 | + TC_PRINT(" device deinit not supported\n"); |
| 198 | + ztest_test_skip(); |
| 199 | + } |
| 200 | + |
| 201 | + zassert_ok(ret); |
| 202 | + |
| 203 | + ret = device_deinit(i2c_1); |
| 204 | + if (ret == -ENOTSUP) { |
| 205 | + TC_PRINT(" device deinit not supported\n"); |
| 206 | + zassert_ok(device_init(i2c_0)); |
| 207 | + ztest_test_skip(); |
| 208 | + } |
| 209 | + |
| 210 | + zassert_ok(gpio_pin_configure_dt(&sda_pin_0, GPIO_INPUT)); |
| 211 | + zassert_ok(gpio_pin_configure_dt(&sda_pin_1, GPIO_OUTPUT_INACTIVE)); |
| 212 | + zassert_ok(gpio_pin_configure_dt(&scl_pin_0, GPIO_INPUT)); |
| 213 | + zassert_ok(gpio_pin_configure_dt(&scl_pin_1, GPIO_OUTPUT_INACTIVE)); |
| 214 | + zassert_equal(gpio_pin_get_dt(&sda_pin_0), 0); |
| 215 | + zassert_equal(gpio_pin_get_dt(&scl_pin_0), 0); |
| 216 | + zassert_ok(gpio_pin_set_dt(&sda_pin_1, 1)); |
| 217 | + zassert_ok(gpio_pin_set_dt(&scl_pin_1, 1)); |
| 218 | + zassert_equal(gpio_pin_get_dt(&sda_pin_0), 1); |
| 219 | + zassert_equal(gpio_pin_get_dt(&scl_pin_0), 1); |
| 220 | + zassert_ok(gpio_pin_configure_dt(&sda_pin_1, GPIO_INPUT)); |
| 221 | + zassert_ok(gpio_pin_configure_dt(&scl_pin_1, GPIO_INPUT)); |
| 222 | + zassert_ok(device_init(i2c_0)); |
| 223 | + zassert_ok(device_init(i2c_1)); |
| 224 | +} |
| 225 | + |
169 | 226 | ZTEST(i2c_eeprom_target, test_eeprom_target)
|
170 | 227 | {
|
171 | 228 | const struct device *const eeprom_0 = DEVICE_DT_GET(NODE_EP0);
|
|
0 commit comments