Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions components/i2cdev/.eil.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
name: i2cdev
description: ESP-IDF I2C master thread-safe utilities
version: 1.5.0
version: 2.0.0
groups:
- common
code_owners:
Expand All @@ -26,4 +25,4 @@ targets:
license: MIT
copyrights:
- name: UncleRus
year: 2018
year: 2018
42 changes: 34 additions & 8 deletions components/i2cdev/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
if(${IDF_TARGET} STREQUAL esp8266)
set(req esp8266 freertos esp_idf_lib_helpers)
# ESP-IDF CMake component for i2cdev library
set(req driver freertos esp_idf_lib_helpers)

# ESP-IDF version detection for automatic driver selection
# Check for manual override via Kconfig
if(CONFIG_I2CDEV_USE_LEGACY_DRIVER)
set(USE_LEGACY_DRIVER TRUE)
message(STATUS "i2cdev: Manual override - using legacy driver (CONFIG_I2CDEV_USE_LEGACY_DRIVER=y)")
elseif(NOT DEFINED IDF_VERSION_MAJOR)
# In case older ESP-IDF versions that don't define IDF_VERSION_MAJOR
set(USE_LEGACY_DRIVER TRUE)
message(STATUS "i2cdev: IDF_VERSION_MAJOR not defined, using legacy driver")
elseif(IDF_VERSION_MAJOR LESS 5)
set(USE_LEGACY_DRIVER TRUE)
message(STATUS "i2cdev: ESP-IDF v${IDF_VERSION_MAJOR}.x detected, using legacy driver")
elseif(IDF_VERSION_MAJOR EQUAL 5 AND IDF_VERSION_MINOR LESS 3)
set(USE_LEGACY_DRIVER TRUE)
message(STATUS "i2cdev: ESP-IDF v${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR} detected, using legacy driver")
else()
set(req driver freertos esp_idf_lib_helpers)
set(USE_LEGACY_DRIVER FALSE)
message(STATUS "i2cdev: ESP-IDF v${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR} detected, using new i2c_master driver")
endif()

idf_component_register(
SRCS i2cdev.c
INCLUDE_DIRS .
REQUIRES ${req}
)
# Conditionally set the source file based on version detection or Kconfig override
if(USE_LEGACY_DRIVER)
set(SRCS "i2cdev_legacy.c")
message(STATUS "i2cdev: Compiling with legacy I2C driver (i2cdev_legacy.c)")
else()
set(SRCS "i2cdev.c")
message(STATUS "i2cdev: Compiling with new I2C master driver (i2cdev.c)")
endif()

# Register the component
idf_component_register(SRCS ${SRCS}
INCLUDE_DIRS "."
REQUIRES ${req})

52 changes: 50 additions & 2 deletions components/i2cdev/Kconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,52 @@
menu "I2C"
menu "I2C Device Library"

config I2CDEV_USE_LEGACY_DRIVER
bool "Use Legacy I2C Driver API"
default n
help
Select this option to use the older ESP-IDF I2C driver API (driver/i2c.h)
instead of the newer driver API (driver/i2c_master.h).

This is automatically determined by the build system based on your ESP-IDF version.
For ESP-IDF versions prior to v5.3, the legacy driver will be used automatically.
You can manually override this setting if needed.

config I2CDEV_AUTO_ENABLE_PULLUPS
bool "Automatically enable internal I2C pullups when not configured"
default n
depends on !IDF_TARGET_ESP8266
help
When enabled, internal pullup resistors are automatically enabled
when both sda_pullup_en and scl_pullup_en are false (default state).

Useful for development and prototyping. Disable for production
systems with external pullups to avoid interference.

Considerations:
- May increase power consumption slightly
- Could interfere with carefully tuned external pullups
- Not recommended for battery-powered applications

Note: This option only affects the modern i2cdev driver (ESP32 family).
Legacy driver behavior is unchanged for compatibility.

config I2CDEV_DEFAULT_SDA_PIN
int "Default I2C SDA pin"
default 21
help
Default SDA pin for I2C devices.

config I2CDEV_DEFAULT_SCL_PIN
int "Default I2C SCL pin"
default 22
help
Default SCL pin for I2C devices.

config I2CDEV_MAX_DEVICES_PER_PORT
int "Maximum number of devices per I2C port"
default 8
help
Maximum number of devices that can be registered on a single I2C port.

config I2CDEV_TIMEOUT
int "I2C transaction timeout, milliseconds"
Expand All @@ -13,5 +61,5 @@ config I2CDEV_NOLOCK
drivers will become non-thread safe.
Use this option if you need to access your I2C devices
from interrupt handlers.

endmenu
22 changes: 22 additions & 0 deletions components/i2cdev/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@ COMPONENT_ADD_INCLUDEDIRS = .

ifdef CONFIG_IDF_TARGET_ESP8266
COMPONENT_DEPENDS = esp8266 freertos esp_idf_lib_helpers
# ESP8266 RTOS SDK auto-detects all .c files, so use COMPONENT_OBJS to override
# This prevents both i2cdev.c and i2cdev_legacy.c from being compiled
COMPONENT_OBJS := i2cdev_legacy.o
COMPONENT_SRCDIRS := .
else
COMPONENT_DEPENDS = driver freertos esp_idf_lib_helpers
# For ESP32 family, check for manual override first
ifdef CONFIG_I2CDEV_USE_LEGACY_DRIVER
COMPONENT_SRCS = i2cdev_legacy.c
else
# Check if version variables are available, fallback to legacy if not
ifdef IDF_VERSION_MAJOR
ifeq ($(shell test $(IDF_VERSION_MAJOR) -lt 5 && echo 1),1)
COMPONENT_SRCS = i2cdev_legacy.c
else ifeq ($(shell test $(IDF_VERSION_MAJOR) -eq 5 -a $(IDF_VERSION_MINOR) -lt 3 && echo 1),1)
COMPONENT_SRCS = i2cdev_legacy.c
else
COMPONENT_SRCS = i2cdev.c
endif
else
# Version variables not available - fallback to legacy driver for safety
COMPONENT_SRCS = i2cdev_legacy.c
endif
endif
endif
Loading
Loading