Skip to content

Commit 9eb66f3

Browse files
committed
feat(i2c): Add method to access the I2C bus handle
1 parent b709a78 commit 9eb66f3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

cores/esp32/esp32-hal-i2c-ng.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ static bool i2cDetachBus(void *bus_i2c_num) {
5656
return true;
5757
}
5858

59+
void * i2cBusHandle(uint8_t i2c_num) {
60+
if (i2c_num >= SOC_I2C_NUM) {
61+
return NULL;
62+
}
63+
return bus[i2c_num].bus_handle;
64+
}
65+
5966
bool i2cIsInit(uint8_t i2c_num) {
6067
if (i2c_num >= SOC_I2C_NUM) {
6168
return false;

cores/esp32/esp32-hal-i2c.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "soc/soc_caps.h"
2121
#if SOC_I2C_SUPPORTED
22+
#include "esp_idf_version.h"
2223

2324
#ifdef __cplusplus
2425
extern "C" {
@@ -39,6 +40,10 @@ esp_err_t i2cWriteReadNonStop(
3940
);
4041
bool i2cIsInit(uint8_t i2c_num);
4142

43+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
44+
void * i2cBusHandle(uint8_t i2c_num);
45+
#endif
46+
4247
#ifdef __cplusplus
4348
}
4449
#endif

0 commit comments

Comments
 (0)