fix i2c_manager conf checks

This commit is contained in:
hiruna 2023-05-26 22:27:08 +10:00
parent f8b0f34a59
commit 735b5df0ff

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; static const uint8_t ACK_CHECK_EN = 1;
#if defined (I2C_NUM_0) && defined (CONFIG_I2C_MANAGER_0_ENABLED) #if defined (CONFIG_I2C_MANAGER_0_ENABLED)
#define I2C_ZERO I2C_NUM_0 #define I2C_ZERO I2C_NUM_0
#if defined (CONFIG_I2C_MANAGER_0_PULLUPS) #if defined (CONFIG_I2C_MANAGER_0_PULLUPS)
#define I2C_MANAGER_0_PULLUPS true #define I2C_MANAGER_0_PULLUPS true
@ -66,12 +66,12 @@ static const uint8_t ACK_CHECK_EN = 1;
#define I2C_MANAGER_0_PULLUPS false #define I2C_MANAGER_0_PULLUPS false
#endif #endif
#define I2C_MANAGER_0_TIMEOUT ( CONFIG_I2C_MANAGER_0_TIMEOUT / portTICK_RATE_MS ) #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_RATE_MS ) #define I2C_MANAGER_0_LOCK_TIMEOUT ( CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT / portTICK_PERIOD_MS )
#endif #endif
#if defined (I2C_NUM_1) && defined (CONFIG_I2C_MANAGER_1_ENABLED) #if defined (CONFIG_I2C_MANAGER_1_ENABLED)
#define I2C_ONE I2C_NUM_1 #define I2C_ONE I2C_NUM_1
#if defined (CONFIG_I2C_MANAGER_1_PULLUPS) #if defined (CONFIG_I2C_MANAGER_1_PULLUPS)
#define I2C_MANAGER_1_PULLUPS true #define I2C_MANAGER_1_PULLUPS true
@ -79,8 +79,8 @@ static const uint8_t ACK_CHECK_EN = 1;
#define I2C_MANAGER_1_PULLUPS false #define I2C_MANAGER_1_PULLUPS false
#endif #endif
#define I2C_MANAGER_1_TIMEOUT ( CONFIG_I2C_MANAGER_1_TIMEOUT / portTICK_RATE_MS ) #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_RATE_MS ) #define I2C_MANAGER_1_LOCK_TIMEOUT ( CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT / portTICK_PERIOD_MS )
#endif #endif
#define ERROR_PORT(port, fail) { \ #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 " 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."); "to open it. See I2C Manager README for details.");
} else { } else {
ESP_LOGI(TAG, "Initialised port %d (SDA: %d, SCL: %d, speed: %d Hz.)", ESP_LOGI(TAG, "Initialised port %d (SDA: %d, SCL: %d, speed: %lu Hz.)",
port, conf.sda_io_num, conf.scl_io_num, conf.master.clk_speed); 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. // May seem weird, but init starts with a check if it's needed, no need for that check twice.
I2C_FN(_init)(port); I2C_FN(_init)(port);
ESP_LOGV(TAG, "Reading port %d, addr 0x%03x, reg 0x%04x", port, addr, reg); ESP_LOGV(TAG, "Reading port %d, addr 0x%03x, reg 0x%04lx", port, addr, reg);
TickType_t timeout = 0; TickType_t timeout = 0;
#if defined (I2C_ZERO) #if defined (I2C_ZERO)
@ -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. // May seem weird, but init starts with a check if it's needed, no need for that check twice.
I2C_FN(_init)(port); I2C_FN(_init)(port);
ESP_LOGV(TAG, "Writing port %d, addr 0x%03x, reg 0x%04x", port, addr, reg); ESP_LOGV(TAG, "Writing port %d, addr 0x%03x, reg 0x%04lx", port, addr, reg);
TickType_t timeout = 0; TickType_t timeout = 0;
#if defined (I2C_ZERO) #if defined (I2C_ZERO)
if (port == I2C_NUM_0) { if (port == I2C_NUM_0) {
timeout = (CONFIG_I2C_MANAGER_0_TIMEOUT) / portTICK_RATE_MS; timeout = (CONFIG_I2C_MANAGER_0_TIMEOUT) / portTICK_PERIOD_MS;
} }
#endif #endif
#if defined (I2C_ONE) #if defined (I2C_ONE)
if (port == I2C_NUM_1) { if (port == I2C_NUM_1) {
timeout = (CONFIG_I2C_MANAGER_1_TIMEOUT) / portTICK_RATE_MS; timeout = (CONFIG_I2C_MANAGER_1_TIMEOUT) / portTICK_PERIOD_MS;
} }
#endif #endif
@ -294,12 +294,12 @@ esp_err_t I2C_FN(_lock)(i2c_port_t port) {
TickType_t timeout; TickType_t timeout;
#if defined (I2C_ZERO) #if defined (I2C_ZERO)
if (port == I2C_NUM_0) { if (port == I2C_NUM_0) {
timeout = (CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT) / portTICK_RATE_MS; timeout = (CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT) / portTICK_PERIOD_MS;
} }
#endif #endif
#if defined (I2C_ONE) #if defined (I2C_ONE)
if (port == I2C_NUM_1) { if (port == I2C_NUM_1) {
timeout = (CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT) / portTICK_RATE_MS; timeout = (CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT) / portTICK_PERIOD_MS;
} }
#endif #endif