Skip to content

Commit 71c4377

Browse files
committed
Merge branch 'feat/i2c_slave_v2_v5.4' into 'release/v5.4'
feat(i2c_slave): Add new i2c slave driver --version two with great stretch handling (backport v5.4) See merge request espressif/esp-idf!34907
2 parents 41ce4c9 + 32adbe7 commit 71c4377

File tree

39 files changed

+2145
-318
lines changed

39 files changed

+2145
-318
lines changed

components/esp_driver_i2c/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ if(CONFIG_SOC_I2C_SUPPORTED)
1010
"i2c_common.c"
1111
)
1212
if(CONFIG_SOC_I2C_SUPPORT_SLAVE)
13-
list(APPEND srcs "i2c_slave.c")
13+
if(CONFIG_I2C_ENABLE_SLAVE_DRIVER_VERSION_2)
14+
list(APPEND srcs "i2c_slave_v2.c")
15+
else()
16+
list(APPEND srcs "i2c_slave.c")
17+
endif()
1418
endif()
1519

1620
endif()

components/esp_driver_i2c/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@ menu "ESP-Driver:I2C Configurations"
1717

1818
note: This cannot be used in the I2C legacy driver.
1919

20+
config I2C_ENABLE_SLAVE_DRIVER_VERSION_2
21+
bool "Enable I2C slave driver version 2"
22+
default n
23+
help
24+
I2C slave version 2 solves some existing known issues. Such as write/read workflow, stretch handling, etc.
25+
2026
endmenu # I2C Configurations

components/esp_driver_i2c/i2c_private.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "driver/i2c_slave.h"
2020
#include "esp_private/periph_ctrl.h"
2121
#include "esp_pm.h"
22+
#include "sdkconfig.h"
2223

2324
#ifdef __cplusplus
2425
extern "C" {
@@ -196,6 +197,8 @@ typedef struct {
196197
uint32_t rcv_fifo_cnt; // receive fifo count.
197198
} i2c_slave_receive_t;
198199

200+
#if !CONFIG_I2C_ENABLE_SLAVE_DRIVER_VERSION_2
201+
199202
struct i2c_slave_dev_t {
200203
i2c_bus_t *base; // bus base class
201204
SemaphoreHandle_t slv_rx_mux; // Mutex for slave rx direction
@@ -213,6 +216,22 @@ struct i2c_slave_dev_t {
213216
uint32_t already_receive_len; // Data length already received in ISR.
214217
};
215218

219+
#else // CONFIG_I2C_ENABLE_SLAVE_DRIVER_VERSION_2
220+
221+
struct i2c_slave_dev_t {
222+
i2c_bus_t *base; // bus base class
223+
SemaphoreHandle_t operation_mux; // Mux for i2c slave operation
224+
i2c_slave_request_callback_t request_callback; // i2c slave request callback
225+
i2c_slave_received_callback_t receive_callback; // i2c_slave receive callback
226+
void *user_ctx; // Callback user context
227+
RingbufHandle_t rx_ring_buf; // receive ringbuffer
228+
RingbufHandle_t tx_ring_buf; // transmit ringbuffer
229+
uint32_t rx_data_count; // receive data count
230+
i2c_slave_receive_t receive_desc; // slave receive descriptor
231+
};
232+
233+
#endif // CONFIG_I2C_ENABLE_SLAVE_DRIVER_VERSION_2
234+
216235
/**
217236
* @brief Acquire I2C bus handle
218237
*

0 commit comments

Comments
 (0)