@@ -312,29 +312,27 @@ static esp_err_t s_hp_i2c_pins_config(i2c_bus_handle_t handle)
312312 int port_id = handle -> port_num ;
313313
314314 // SDA pin configurations
315- gpio_config_t sda_conf = {
316- .intr_type = GPIO_INTR_DISABLE ,
317- .mode = GPIO_MODE_INPUT_OUTPUT_OD ,
318- .pull_down_en = false,
319- .pull_up_en = handle -> pull_up_enable ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE ,
320- .pin_bit_mask = 1ULL << handle -> sda_num ,
321- };
322315 ESP_RETURN_ON_ERROR (gpio_set_level (handle -> sda_num , 1 ), TAG , "i2c sda pin set level failed" );
323- ESP_RETURN_ON_ERROR (gpio_config (& sda_conf ), TAG , "config GPIO failed" );
316+ gpio_input_enable (handle -> sda_num );
317+ gpio_od_enable (handle -> sda_num );
318+ if (handle -> pull_up_enable ) {
319+ gpio_pullup_en (handle -> sda_num );
320+ } else {
321+ gpio_pullup_dis (handle -> sda_num );
322+ }
324323 gpio_func_sel (handle -> sda_num , PIN_FUNC_GPIO );
325324 esp_rom_gpio_connect_out_signal (handle -> sda_num , i2c_periph_signal [port_id ].sda_out_sig , 0 , 0 );
326325 esp_rom_gpio_connect_in_signal (handle -> sda_num , i2c_periph_signal [port_id ].sda_in_sig , 0 );
327326
328327 // SCL pin configurations
329- gpio_config_t scl_conf = {
330- .intr_type = GPIO_INTR_DISABLE ,
331- .mode = GPIO_MODE_INPUT_OUTPUT_OD ,
332- .pull_down_en = false,
333- .pull_up_en = handle -> pull_up_enable ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE ,
334- .pin_bit_mask = 1ULL << handle -> scl_num ,
335- };
336328 ESP_RETURN_ON_ERROR (gpio_set_level (handle -> scl_num , 1 ), TAG , "i2c scl pin set level failed" );
337- ESP_RETURN_ON_ERROR (gpio_config (& scl_conf ), TAG , "config GPIO failed" );
329+ gpio_input_enable (handle -> scl_num );
330+ gpio_od_enable (handle -> scl_num );
331+ if (handle -> pull_up_enable ) {
332+ gpio_pullup_en (handle -> scl_num );
333+ } else {
334+ gpio_pullup_dis (handle -> scl_num );
335+ }
338336 gpio_func_sel (handle -> scl_num , PIN_FUNC_GPIO );
339337 esp_rom_gpio_connect_out_signal (handle -> scl_num , i2c_periph_signal [port_id ].scl_out_sig , 0 , 0 );
340338 esp_rom_gpio_connect_in_signal (handle -> scl_num , i2c_periph_signal [port_id ].scl_in_sig , 0 );
@@ -406,3 +404,28 @@ esp_err_t i2c_common_set_pins(i2c_bus_handle_t handle)
406404
407405 return ret ;
408406}
407+
408+ esp_err_t i2c_common_deinit_pins (i2c_bus_handle_t handle )
409+ {
410+ int port_id = handle -> port_num ;
411+
412+ if (handle -> is_lp_i2c == false) {
413+ ESP_RETURN_ON_ERROR (gpio_output_disable (handle -> sda_num ), TAG , "disable i2c pins failed" );
414+ esp_rom_gpio_connect_in_signal (GPIO_MATRIX_CONST_ZERO_INPUT , i2c_periph_signal [port_id ].sda_in_sig , 0 );
415+
416+ ESP_RETURN_ON_ERROR (gpio_output_disable (handle -> scl_num ), TAG , "disable i2c pins failed" );
417+ esp_rom_gpio_connect_in_signal (GPIO_MATRIX_CONST_ZERO_INPUT , i2c_periph_signal [port_id ].scl_in_sig , 0 );
418+ }
419+ #if SOC_LP_I2C_SUPPORTED
420+ else {
421+ ESP_RETURN_ON_ERROR (rtc_gpio_deinit (handle -> sda_num ), TAG , "deinit rtc gpio failed" );
422+ ESP_RETURN_ON_ERROR (rtc_gpio_deinit (handle -> scl_num ), TAG , "deinit rtc gpio failed" );
423+ #if SOC_LP_GPIO_MATRIX_SUPPORTED
424+ lp_gpio_connect_in_signal (GPIO_MATRIX_CONST_ZERO_INPUT , i2c_periph_signal [port_id ].scl_in_sig , 0 );
425+ lp_gpio_connect_in_signal (GPIO_MATRIX_CONST_ZERO_INPUT , i2c_periph_signal [port_id ].sda_in_sig , 0 );
426+ #endif
427+ }
428+ #endif
429+
430+ return ESP_OK ;
431+ }
0 commit comments