From 64513a24c48ae33650e07cefe842a73f7882b493 Mon Sep 17 00:00:00 2001 From: "C.S.M" Date: Tue, 17 Dec 2024 11:06:14 +0800 Subject: [PATCH] fix(i2c_slave): Support 10-bit address on esp32 --- components/hal/esp32/include/hal/i2c_ll.h | 4 ++-- components/soc/esp32/include/soc/Kconfig.soc_caps.in | 4 ++++ components/soc/esp32/include/soc/soc_caps.h | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/components/hal/esp32/include/hal/i2c_ll.h b/components/hal/esp32/include/hal/i2c_ll.h index 5149320673..1b4cf7039e 100644 --- a/components/hal/esp32/include/hal/i2c_ll.h +++ b/components/hal/esp32/include/hal/i2c_ll.h @@ -323,8 +323,8 @@ static inline void i2c_ll_set_slave_addr(i2c_dev_t *hw, uint16_t slave_addr, boo hw->slave_addr.en_10bit = addr_10bit_en; if (addr_10bit_en) { uint16_t addr_14_7 = (slave_addr & 0xff) << 7; - uint8_t addr_6_0 = ((slave_addr & 0x300) >> 8) || 0x78; - hw->slave_addr.addr = addr_14_7 || addr_6_0; + uint8_t addr_6_0 = ((slave_addr & 0x300) >> 8) | 0x78; + hw->slave_addr.addr = addr_14_7 | addr_6_0; } else { hw->slave_addr.addr = slave_addr; } diff --git a/components/soc/esp32/include/soc/Kconfig.soc_caps.in b/components/soc/esp32/include/soc/Kconfig.soc_caps.in index b6a3a58a88..becaf8af6c 100644 --- a/components/soc/esp32/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32/include/soc/Kconfig.soc_caps.in @@ -351,6 +351,10 @@ config SOC_I2C_SUPPORT_APB bool default y +config SOC_I2C_SUPPORT_10BIT_ADDR + bool + default y + config SOC_I2C_STOP_INDEPENDENT bool default y diff --git a/components/soc/esp32/include/soc/soc_caps.h b/components/soc/esp32/include/soc/soc_caps.h index 4d9aa8aded..648b750d1a 100644 --- a/components/soc/esp32/include/soc/soc_caps.h +++ b/components/soc/esp32/include/soc/soc_caps.h @@ -197,6 +197,7 @@ #define SOC_I2C_SUPPORT_SLAVE (1) #define SOC_I2C_SUPPORT_APB (1) +#define SOC_I2C_SUPPORT_10BIT_ADDR (1) // On ESP32, the stop bit should be independent, we can't put trans data and stop command together #define SOC_I2C_STOP_INDEPENDENT (1)