Skip to content

Commit

Permalink
Fixed the problem that the operation of TwoWire suddenly became stran…
Browse files Browse the repository at this point in the history
…ge when using it together with Arduino TwoWire on ESP32S3
  • Loading branch information
lovyan03 committed Jul 25, 2024
1 parent 5e32d57 commit f38076b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lgfx/v1/platforms/esp32/Bus_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Original Source:

/// ESP32-S3をターゲットにした際にREG_SPI_BASEが定義されていなかったので応急処置 ;
#if defined ( CONFIG_IDF_TARGET_ESP32S3 )
#if ( ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 0) )
#if !defined( REG_SPI_BASE )
#define REG_SPI_BASE(i) (DR_REG_SPI1_BASE + (((i)>1) ? (((i)* 0x1000) + 0x20000) : (((~(i)) & 1)* 0x1000 )))
#endif
#elif defined ( CONFIG_IDF_TARGET_ESP32 ) || !defined ( CONFIG_IDF_TARGET )
Expand Down
14 changes: 9 additions & 5 deletions src/lgfx/v1/platforms/esp32/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ namespace lgfx
if (fifo_reg == &reg[i]) { continue; }
reg[i] = _reg_store[i];
}
updateDev(dev);
}

void setPins(i2c_dev_t* dev, gpio_num_t scl, gpio_num_t sda)
Expand Down Expand Up @@ -862,10 +863,6 @@ namespace lgfx
gpio_set_direction(scl_io, GPIO_MODE_OUTPUT_OD);
delayMicroseconds(I2C_CLR_BUS_HALF_PERIOD_US);

auto mod = getPeriphModule(i2c_port);
// ESP-IDF環境でperiph_module_disableを使うと、後でenableできなくなる問題が起きたためコメントアウト;
//periph_module_disable(mod);

// SDAがHIGHになるまでSTOP送出を繰り返す。;
int i = 0;
do
Expand All @@ -879,9 +876,10 @@ namespace lgfx
gpio_set_level(sda_io, 1);
delayMicroseconds(I2C_CLR_BUS_HALF_PERIOD_US);
} while (!gpio_get_level(sda_io) && (i++ < I2C_CLR_BUS_SCL_NUM));
periph_module_enable(mod);

#if !defined (CONFIG_IDF_TARGET_ESP32C3)
/// ESP32C3で periph_module_reset を使用すると以後通信不能になる問題が起きたため分岐;
auto mod = getPeriphModule(i2c_port);
periph_module_reset(mod);
#endif
i2c_set_pin((i2c_port_t)i2c_port, sda_io, scl_io, gpio_pullup_t::GPIO_PULLUP_ENABLE, gpio_pullup_t::GPIO_PULLUP_ENABLE, I2C_MODE_MASTER);
Expand Down Expand Up @@ -1005,6 +1003,9 @@ namespace lgfx
#endif
#endif
#endif
#else
auto mod = getPeriphModule(i2c_port);
periph_module_disable(mod);
#endif
if ((int)i2c_context[i2c_port].pin_scl >= 0)
{
Expand Down Expand Up @@ -1074,6 +1075,9 @@ namespace lgfx
#else
twowire->begin((int)i2c_context[i2c_port].pin_sda, (int)i2c_context[i2c_port].pin_scl);
#endif
#else
auto mod = getPeriphModule(i2c_port);
periph_module_enable(mod);
#endif

i2c_context[i2c_port].initialized = true;
Expand Down

0 comments on commit f38076b

Please sign in to comment.