source i2c_manager files from https://github.com/ropg/i2c_manager master

This commit is contained in:
hiruna 2023-05-27 13:00:33 +10:00
parent 785b7d5c28
commit 8f72cfaa94
3 changed files with 171 additions and 173 deletions

View file

@ -6,10 +6,8 @@ menu "I2C Port 0"
if I2C_MANAGER_0_ENABLED
config I2C_MANAGER_0_SDA
int "SDA (GPIO pin)"
default 0
config I2C_MANAGER_0_SCL
int "SCL (GPIO pin)"
default 0
config I2C_MANAGER_0_FREQ_HZ
int "Frequency (Hz)"
default 400000

View file

@ -58,7 +58,7 @@ static SemaphoreHandle_t* I2C_FN(_mutex) = &I2C_FN(_local_mutex)[0];
static const uint8_t ACK_CHECK_EN = 1;
#if defined (CONFIG_I2C_MANAGER_0_ENABLED)
#if defined (I2C_NUM_0) && defined (CONFIG_I2C_MANAGER_0_ENABLED)
#define I2C_ZERO I2C_NUM_0
#if defined (CONFIG_I2C_MANAGER_0_PULLUPS)
#define I2C_MANAGER_0_PULLUPS true
@ -66,12 +66,12 @@ static const uint8_t ACK_CHECK_EN = 1;
#define I2C_MANAGER_0_PULLUPS false
#endif
#define I2C_MANAGER_0_TIMEOUT ( CONFIG_I2C_MANAGER_0_TIMEOUT / portTICK_PERIOD_MS )
#define I2C_MANAGER_0_LOCK_TIMEOUT ( CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT / portTICK_PERIOD_MS )
#define I2C_MANAGER_0_TIMEOUT ( pdMS_TO_TICKS( CONFIG_I2C_MANAGER_0_TIMEOUT ) )
#define I2C_MANAGER_0_LOCK_TIMEOUT ( ( pdMS_TO_TICKS( CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT ) )
#endif
#if defined (CONFIG_I2C_MANAGER_1_ENABLED)
#if defined (I2C_NUM_1) && defined (CONFIG_I2C_MANAGER_1_ENABLED)
#define I2C_ONE I2C_NUM_1
#if defined (CONFIG_I2C_MANAGER_1_PULLUPS)
#define I2C_MANAGER_1_PULLUPS true
@ -79,8 +79,8 @@ static const uint8_t ACK_CHECK_EN = 1;
#define I2C_MANAGER_1_PULLUPS false
#endif
#define I2C_MANAGER_1_TIMEOUT ( CONFIG_I2C_MANAGER_1_TIMEOUT / portTICK_PERIOD_MS )
#define I2C_MANAGER_1_LOCK_TIMEOUT ( CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT / portTICK_PERIOD_MS )
#define I2C_MANAGER_1_TIMEOUT ( pdMS_TO_TICKS( CONFIG_I2C_MANAGER_1_TIMEOUT ) )
#define I2C_MANAGER_1_LOCK_TIMEOUT ( pdMS_TO_TICKS( CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT ) )
#endif
#define ERROR_PORT(port, fail) { \
@ -168,7 +168,7 @@ esp_err_t I2C_FN(_init)(i2c_port_t port) {
ESP_LOGW(TAG, "If it was already open, we'll use it with whatever settings were used "
"to open it. See I2C Manager README for details.");
} else {
ESP_LOGI(TAG, "Initialised port %d (SDA: %d, SCL: %d, speed: %lu Hz.)",
ESP_LOGI(TAG, "Initialised port %d (SDA: %d, SCL: %d, speed: %d Hz.)",
port, conf.sda_io_num, conf.scl_io_num, conf.master.clk_speed);
}
@ -186,7 +186,7 @@ esp_err_t I2C_FN(_read)(i2c_port_t port, uint16_t addr, uint32_t reg, uint8_t *b
// May seem weird, but init starts with a check if it's needed, no need for that check twice.
I2C_FN(_init)(port);
ESP_LOGV(TAG, "Reading port %d, addr 0x%03x, reg 0x%04lx", port, addr, reg);
ESP_LOGV(TAG, "Reading port %d, addr 0x%03x, reg 0x%04x", port, addr, reg);
TickType_t timeout = 0;
#if defined (I2C_ZERO)
@ -222,7 +222,7 @@ esp_err_t I2C_FN(_read)(i2c_port_t port, uint16_t addr, uint32_t reg, uint8_t *b
}
if (result != ESP_OK) {
ESP_LOGW(TAG, "Error: %d", result);
ESP_LOGD(TAG, "Error: %d", result);
}
ESP_LOG_BUFFER_HEX_LEVEL(TAG, buffer, size, ESP_LOG_VERBOSE);
@ -239,17 +239,17 @@ esp_err_t I2C_FN(_write)(i2c_port_t port, uint16_t addr, uint32_t reg, const uin
// May seem weird, but init starts with a check if it's needed, no need for that check twice.
I2C_FN(_init)(port);
ESP_LOGV(TAG, "Writing port %d, addr 0x%03x, reg 0x%04lx", port, addr, reg);
ESP_LOGV(TAG, "Writing port %d, addr 0x%03x, reg 0x%04x", port, addr, reg);
TickType_t timeout = 0;
#if defined (I2C_ZERO)
if (port == I2C_NUM_0) {
timeout = (CONFIG_I2C_MANAGER_0_TIMEOUT) / portTICK_PERIOD_MS;
timeout = pdMS_TO_TICKS( CONFIG_I2C_MANAGER_0_TIMEOUT );
}
#endif
#if defined (I2C_ONE)
if (port == I2C_NUM_1) {
timeout = (CONFIG_I2C_MANAGER_1_TIMEOUT) / portTICK_PERIOD_MS;
timeout = pdMS_TO_TICKS( CONFIG_I2C_MANAGER_1_TIMEOUT );
}
#endif
@ -271,7 +271,7 @@ esp_err_t I2C_FN(_write)(i2c_port_t port, uint16_t addr, uint32_t reg, const uin
}
if (result != ESP_OK) {
ESP_LOGW(TAG, "Error: %d", result);
ESP_LOGD(TAG, "Error: %d", result);
}
ESP_LOG_BUFFER_HEX_LEVEL(TAG, buffer, size, ESP_LOG_VERBOSE);
@ -294,12 +294,12 @@ esp_err_t I2C_FN(_lock)(i2c_port_t port) {
TickType_t timeout;
#if defined (I2C_ZERO)
if (port == I2C_NUM_0) {
timeout = (CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT) / portTICK_PERIOD_MS;
timeout = pdMS_TO_TICKS( CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT );
}
#endif
#if defined (I2C_ONE)
if (port == I2C_NUM_1) {
timeout = (CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT) / portTICK_PERIOD_MS;
timeout = pdMS_TO_TICKS( CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT );
}
#endif