Skip to content

Commit dde8e53

Browse files
committed
fix(i2c_bus): soft i2c allows access to all registers and avoids Kconfig conflicts
1 parent 19e72db commit dde8e53

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

components/i2c_bus/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# ChangeLog
22

3+
## V1.4.1 - 2025-8-14
4+
5+
### Bug Fix:
6+
7+
- Soft i2c supports removing the restriction on ``NULL_I2C_MEM_ADDR``, allowing users to refer to all eligible register addresses.
8+
- Modify the `ESP_IDF_VERSION` naming in Kconfig to avoid conflicts with other components.
9+
310
## v1.4.0 - 2025-3-13
411

512
### Enhancements:

components/i2c_bus/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
menu "Bus Options"
22

33
menu "I2C Bus Options"
4-
config ESP_IDF_VERSION
4+
config ESP_IDF_VERSION_FOR_I2C
55
string
66
option env="ESP_IDF_VERSION"
77

@@ -22,7 +22,7 @@ menu "Bus Options"
2222
config I2C_BUS_BACKWARD_CONFIG
2323
bool "Enable backward compatibility for the I2C driver (force use of the old i2c_driver above v5.3)"
2424
default n
25-
depends on ESP_IDF_VERSION >= 5.3
25+
depends on ESP_IDF_VERSION_FOR_I2C >= 5.3
2626
help
2727
Enable this option for backward compatibility with the old I2C driver
2828

components/i2c_bus/i2c_bus_soft.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,14 @@ esp_err_t i2c_master_soft_bus_write_reg8(i2c_master_soft_bus_handle_t bus_handle
110110

111111
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_wait_ack(bus_handle), TAG, "No ACK for device address");
112112

113+
#if !CONFIG_I2C_BUS_REMOVE_NULL_MEM_ADDR
113114
if (mem_address != NULL_I2C_MEM_ADDR) {
115+
#endif
114116
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_write_byte(bus_handle, mem_address), TAG, "Failed to write memory address");
115117
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_wait_ack(bus_handle), TAG, "No ACK for device address");
118+
#if !CONFIG_I2C_BUS_REMOVE_NULL_MEM_ADDR
116119
}
117-
120+
#endif
118121
// Write data
119122
for (size_t i = 0; i < data_len; i++) {
120123
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_write_byte(bus_handle, data[i]), TAG, "Failed to write data byte");
@@ -136,12 +139,16 @@ esp_err_t i2c_master_soft_bus_write_reg16(i2c_master_soft_bus_handle_t bus_handl
136139
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_write_byte(bus_handle, address_byte), TAG, "Failed to write device address");
137140
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_wait_ack(bus_handle), TAG, "No ACK for device address");
138141

142+
#if !CONFIG_I2C_BUS_REMOVE_NULL_MEM_ADDR
139143
if (mem_address != NULL_I2C_MEM_16BIT_ADDR) {
144+
#endif
140145
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_write_byte(bus_handle, (uint8_t)((mem_address >> 8) & 0x00FF)), TAG, "Failed to write memory address");
141146
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_wait_ack(bus_handle), TAG, "No ACK for mem address");
142147
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_write_byte(bus_handle, (uint8_t)(mem_address & 0x00FF)), TAG, "Failed to write memory address");
143148
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_wait_ack(bus_handle), TAG, "No ACK for mem address");
149+
#if !CONFIG_I2C_BUS_REMOVE_NULL_MEM_ADDR
144150
}
151+
#endif
145152

146153
// Write data
147154
for (size_t i = 0; i < data_len; i++) {
@@ -159,7 +166,9 @@ esp_err_t i2c_master_soft_bus_read_reg8(i2c_master_soft_bus_handle_t bus_handle,
159166
ESP_RETURN_ON_FALSE(bus_handle, ESP_ERR_INVALID_ARG, TAG, "Invalid I2C bus handle");
160167

161168
// Send memory address
169+
#if !CONFIG_I2C_BUS_REMOVE_NULL_MEM_ADDR
162170
if (mem_address != NULL_I2C_MEM_ADDR) {
171+
#endif
163172
// Generate START condition
164173
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_start(bus_handle), TAG, "Failed to initiate start signal");
165174

@@ -169,7 +178,9 @@ esp_err_t i2c_master_soft_bus_read_reg8(i2c_master_soft_bus_handle_t bus_handle,
169178
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_wait_ack(bus_handle), TAG, "No ACK for device address");
170179
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_write_byte(bus_handle, mem_address), TAG, "Failed to write memory address");
171180
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_wait_ack(bus_handle), TAG, "No ACK for mem address");
181+
#if !CONFIG_I2C_BUS_REMOVE_NULL_MEM_ADDR
172182
}
183+
#endif
173184

174185
// Generate RESTART condition
175186
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_start(bus_handle), TAG, "Failed to initiate repeated start signal");
@@ -198,7 +209,9 @@ esp_err_t i2c_master_soft_bus_read_reg16(i2c_master_soft_bus_handle_t bus_handle
198209
ESP_RETURN_ON_FALSE(bus_handle, ESP_ERR_INVALID_ARG, TAG, "Invalid I2C bus handle");
199210

200211
// Send memory address
212+
#if !CONFIG_I2C_BUS_REMOVE_NULL_MEM_ADDR
201213
if (mem_address != NULL_I2C_MEM_16BIT_ADDR) {
214+
#endif
202215
// Generate START condition
203216
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_start(bus_handle), TAG, "Failed to initiate start signal");
204217

@@ -210,7 +223,9 @@ esp_err_t i2c_master_soft_bus_read_reg16(i2c_master_soft_bus_handle_t bus_handle
210223
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_wait_ack(bus_handle), TAG, "No ACK for mem address");
211224
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_write_byte(bus_handle, (uint8_t)(mem_address & 0x00FF)), TAG, "Failed to write memory address");
212225
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_wait_ack(bus_handle), TAG, "No ACK for mem address");
226+
#if !CONFIG_I2C_BUS_REMOVE_NULL_MEM_ADDR
213227
}
228+
#endif
214229

215230
// Generate RESTART condition
216231
ESP_RETURN_ON_ERROR(i2c_master_soft_bus_start(bus_handle), TAG, "Failed to initiate repeated start signal");

components/i2c_bus/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "1.4.0"
1+
version: "1.4.1"
22
description: The I2C Bus Driver supports both hardware and software I2C.
33
url: https://github.com/espressif/esp-iot-solution/tree/master/components/i2c_bus
44
repository: https://github.com/espressif/esp-iot-solution.git
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# For IDF 5.0
2+
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
3+
CONFIG_FREERTOS_HZ=1000
4+
CONFIG_ESP_TASK_WDT_EN=n
5+
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096
6+
7+
# For IDF4.4
8+
CONFIG_ESP32S2_DEFAULT_CPU_FREQ_240=y
9+
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
10+
CONFIG_ESP_TASK_WDT=n

0 commit comments

Comments
 (0)