|
1 | 1 | /* |
2 | | - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD |
| 2 | + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Unlicense OR CC0-1.0 |
5 | 5 | */ |
|
19 | 19 |
|
20 | 20 | #if SOC_I2C_SLAVE_CAN_GET_STRETCH_CAUSE |
21 | 21 |
|
| 22 | +TEST_CASE("I2C peripheral allocate slave all", "[i2c]") |
| 23 | +{ |
| 24 | + i2c_slave_dev_handle_t dev_handle[SOC_HP_I2C_NUM]; |
| 25 | + for (int i = 0; i < SOC_HP_I2C_NUM; i++) { |
| 26 | + i2c_slave_config_t i2c_slv_config_1 = { |
| 27 | + .clk_source = I2C_CLK_SRC_DEFAULT, |
| 28 | + .i2c_port = -1, |
| 29 | + .scl_io_num = I2C_SLAVE_SCL_IO, |
| 30 | + .sda_io_num = I2C_SLAVE_SDA_IO, |
| 31 | + .slave_addr = ESP_SLAVE_ADDR, |
| 32 | + .send_buf_depth = DATA_LENGTH, |
| 33 | + .receive_buf_depth = DATA_LENGTH, |
| 34 | + .flags.enable_internal_pullup = true, |
| 35 | + }; |
| 36 | + |
| 37 | + TEST_ESP_OK(i2c_new_slave_device(&i2c_slv_config_1, &dev_handle[i])); |
| 38 | + } |
| 39 | + i2c_slave_config_t i2c_slv_config_1 = { |
| 40 | + .clk_source = I2C_CLK_SRC_DEFAULT, |
| 41 | + .i2c_port = -1, |
| 42 | + .scl_io_num = I2C_SLAVE_SCL_IO, |
| 43 | + .sda_io_num = I2C_SLAVE_SDA_IO, |
| 44 | + .slave_addr = ESP_SLAVE_ADDR, |
| 45 | + .send_buf_depth = DATA_LENGTH, |
| 46 | + .receive_buf_depth = DATA_LENGTH, |
| 47 | + .flags.enable_internal_pullup = true, |
| 48 | + }; |
| 49 | + i2c_slave_dev_handle_t dev_handle_2; |
| 50 | + |
| 51 | + TEST_ESP_ERR(ESP_ERR_NOT_FOUND, i2c_new_slave_device(&i2c_slv_config_1, &dev_handle_2)); |
| 52 | + |
| 53 | + for (int i = 0; i < SOC_HP_I2C_NUM; i++) { |
| 54 | + TEST_ESP_OK(i2c_del_slave_device(dev_handle[i])); |
| 55 | + } |
| 56 | + |
| 57 | + // Get another one |
| 58 | + |
| 59 | + TEST_ESP_OK(i2c_new_slave_device(&i2c_slv_config_1, &dev_handle_2)); |
| 60 | + TEST_ESP_OK(i2c_del_slave_device(dev_handle_2)); |
| 61 | +} |
| 62 | + |
22 | 63 | static QueueHandle_t event_queue; |
23 | 64 | static uint8_t *temp_data; |
24 | 65 | static size_t temp_len = 0; |
@@ -92,7 +133,7 @@ static void i2c_slave_read_test_v2(void) |
92 | 133 | unity_wait_for_signal("master write"); |
93 | 134 |
|
94 | 135 | i2c_slave_event_t evt; |
95 | | - if (xQueueReceive(event_queue, &evt, 1) == pdTRUE) { |
| 136 | + if (xQueueReceive(event_queue, &evt, portMAX_DELAY) == pdTRUE) { |
96 | 137 | if (evt == I2C_SLAVE_EVT_RX) { |
97 | 138 | disp_buf(temp_data, temp_len); |
98 | 139 | printf("length is %x\n", temp_len); |
@@ -296,7 +337,6 @@ static void i2c_master_write_test_with_customize_api(void) |
296 | 337 |
|
297 | 338 | TEST_ESP_OK(i2c_del_master_bus(bus_handle)); |
298 | 339 | } |
299 | | - |
300 | 340 | TEST_CASE_MULTIPLE_DEVICES("I2C master write slave with customize api", "[i2c][test_env=generic_multi_device][timeout=150]", i2c_master_write_test_with_customize_api, i2c_slave_read_test_v2); |
301 | 341 |
|
302 | 342 | #endif // SOC_I2C_SLAVE_CAN_GET_STRETCH_CAUSE |
0 commit comments