From 3994b245b9964eecc34d134343ba7dcc8f0da62a Mon Sep 17 00:00:00 2001 From: nopnop2002 Date: Sat, 7 Sep 2024 11:43:16 +0900 Subject: [PATCH] Added option to force legacy i2c driver --- README.md | 10 +++++++++- components/ssd1306/CMakeLists.txt | 6 +++++- components/ssd1306/Kconfig.projbuild | 7 +++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8c8cb8b..8cfc155 100644 --- a/README.md +++ b/README.md @@ -120,12 +120,20 @@ Therefore, the maximum i2c clock frequency is 400KHz. The i2c clock frequency used by this project is 400KHz. # I2C Port selection -![config-i2c-port](https://github.com/nopnop2002/esp-idf-ssd1306/assets/6020549/7a7de5ec-ef20-42ac-ba70-73ba74a762a7) +![config-i2c-port](https://github.com/user-attachments/assets/477bdf29-7492-4256-bc9e-e3ff363cddcc) The ESP32 XTENSA series has two I2C Ports. You can use these two ports freely. If you use this module at the same time as another I2C device using I2C port 0, you must change it to I2C port 1. +# Force legacy i2c driver +xtensa's ESP32 has two i2c buses: I2C_NUM_0/1. +I2C_NUM_0/1 are initialized independently, but legacy i2c drivers and new i2c drivers cannot be mixed. +If I2C_NUM_0 is initialized with the legacy i2c driver, I2C_NUM_1 must also be initialized with the legacy i2c driver. +If you use the SSD1306 at the same time as an I2C device that uses a legacy I2C driver, you must initialize the SSD1306 with the legacy I2C driver. +Enabling this will use the legacy i2c driver even after ESP-IDF V5.2. +![config-i2c-driver](https://github.com/user-attachments/assets/d07076d0-1c94-43d1-aa5a-aec810d2f7bc) + --- # SPI Clock speed diff --git a/components/ssd1306/CMakeLists.txt b/components/ssd1306/CMakeLists.txt index ea1cd62..b73951d 100644 --- a/components/ssd1306/CMakeLists.txt +++ b/components/ssd1306/CMakeLists.txt @@ -4,7 +4,11 @@ set(component_srcs "ssd1306.c" "ssd1306_spi.c") set(idf_version "${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}") if(idf_version VERSION_GREATER_EQUAL "5.2") - list(APPEND component_srcs "ssd1306_i2c_new.c") + if(CONFIG_LEGACY_DRIVER) + list(APPEND component_srcs "ssd1306_i2c_legacy.c") + else() + list(APPEND component_srcs "ssd1306_i2c_new.c") + endif() else() list(APPEND component_srcs "ssd1306_i2c_legacy.c") endif() diff --git a/components/ssd1306/Kconfig.projbuild b/components/ssd1306/Kconfig.projbuild index 0394575..9af6448 100644 --- a/components/ssd1306/Kconfig.projbuild +++ b/components/ssd1306/Kconfig.projbuild @@ -158,6 +158,13 @@ menu "SSD1306 Configuration" Use I2C_PORT_1. endchoice + config LEGACY_DRIVER + depends on I2C_INTERFACE + bool "Force legacy i2c driver" + default false + help + Force legacy i2c driver. + choice SPI_HOST depends on SPI_INTERFACE prompt "SPI peripheral that controls this bus"