@@ -237,4 +237,56 @@ static void slave_write_buffer_test_v2(void)
237237
238238TEST_CASE_MULTIPLE_DEVICES ("I2C master read slave test" , "[i2c][test_env=generic_multi_device][timeout=150]" , master_read_slave_test_v2 , slave_write_buffer_test_v2 );
239239
240+ static void i2c_master_write_test_with_customize_api (void )
241+ {
242+ uint8_t data_wr [DATA_LENGTH ] = { 0 };
243+ int i ;
244+
245+ i2c_master_bus_config_t i2c_mst_config = {
246+ .clk_source = I2C_CLK_SRC_DEFAULT ,
247+ .i2c_port = TEST_I2C_PORT ,
248+ .scl_io_num = I2C_MASTER_SCL_IO ,
249+ .sda_io_num = I2C_MASTER_SDA_IO ,
250+ .flags .enable_internal_pullup = true,
251+ };
252+ i2c_master_bus_handle_t bus_handle ;
253+
254+ TEST_ESP_OK (i2c_new_master_bus (& i2c_mst_config , & bus_handle ));
255+
256+ i2c_device_config_t dev_cfg = {
257+ .dev_addr_length = I2C_ADDR_BIT_LEN_7 ,
258+ .device_address = I2C_DEVICE_ADDRESS_NOT_USED ,
259+ .scl_speed_hz = 100000 ,
260+ };
261+
262+ i2c_master_dev_handle_t dev_handle ;
263+ TEST_ESP_OK (i2c_master_bus_add_device (bus_handle , & dev_cfg , & dev_handle ));
264+
265+ unity_wait_for_signal ("i2c slave init finish" );
266+
267+ unity_send_signal ("master write" );
268+ for (i = 0 ; i < DATA_LENGTH ; i ++ ) {
269+ data_wr [i ] = i ;
270+ }
271+
272+ disp_buf (data_wr , i );
273+
274+ uint8_t address = (ESP_SLAVE_ADDR << 1 | 0 );
275+
276+ i2c_operation_job_t i2c_ops [] = {
277+ { .command = I2C_MASTER_CMD_START },
278+ { .command = I2C_MASTER_CMD_WRITE , .write = { .ack_check = true, .data = (uint8_t * ) & address , .total_bytes = 1 } },
279+ { .command = I2C_MASTER_CMD_WRITE , .write = { .ack_check = true, .data = (uint8_t * ) data_wr , .total_bytes = DATA_LENGTH } },
280+ { .command = I2C_MASTER_CMD_STOP },
281+ };
282+
283+ TEST_ESP_OK (i2c_master_execute_defined_operations (dev_handle , i2c_ops , sizeof (i2c_ops ) / sizeof (i2c_operation_job_t ), -1 ));
284+ unity_wait_for_signal ("ready to delete" );
285+ TEST_ESP_OK (i2c_master_bus_rm_device (dev_handle ));
286+
287+ TEST_ESP_OK (i2c_del_master_bus (bus_handle ));
288+ }
289+
290+ 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 );
291+
240292#endif // SOC_I2C_SLAVE_CAN_GET_STRETCH_CAUSE
0 commit comments