Merge branch 'bugfix/i2c_port_unsigned' into 'master'

I2C: i2c_port_t type is now an enumeration

Closes IDFGH-7433

See merge request espressif/esp-idf!18230
This commit is contained in:
Omar Chebib
2022-08-25 17:25:51 +08:00
8 changed files with 63 additions and 30 deletions
+11 -1
View File
@@ -105,6 +105,14 @@ static const char *I2C_TAG = "i2c";
#define I2C_CLOCK_INVALID (-1)
/**
* I2C bus are defined in the header files, let's check that the values are correct
*/
#if SOC_I2C_NUM >= 2
_Static_assert(I2C_NUM_1 == 1, "I2C_NUM_1 must be equal to 1");
#endif // SOC_I2C_NUM >= 2
_Static_assert(I2C_NUM_MAX == SOC_I2C_NUM, "I2C_NUM_MAX must be equal to SOC_I2C_NUM");
typedef struct {
i2c_hw_cmd_t hw_cmd;
union {
@@ -193,7 +201,9 @@ typedef struct
static i2c_context_t i2c_context[I2C_NUM_MAX] = {
I2C_CONTEX_INIT_DEF(I2C_NUM_0),
#if I2C_NUM_MAX > 1
/* Now that I2C_NUM_MAX is part of an enum (i2c_port_t), we cannot use
* it anomore in the preprocessor! */
#if SOC_I2C_NUM > 1
I2C_CONTEX_INIT_DEF(I2C_NUM_1),
#endif
};
-6
View File
@@ -24,12 +24,6 @@ extern "C" {
#define I2C_APB_CLK_FREQ APB_CLK_FREQ /*!< I2C source clock is APB clock, 80MHz */
#define I2C_NUM_MAX (SOC_I2C_NUM) /*!< I2C port max */
#define I2C_NUM_0 (0) /*!< I2C port 0 */
#if SOC_I2C_NUM >= 2
#define I2C_NUM_1 (1) /*!< I2C port 1 */
#endif
// I2C clk flags for users to use, can be expanded in the future.
#define I2C_SCLK_SRC_FLAG_FOR_NOMAL (0) /*!< Any one clock source that is available for the specified frequency may be choosen*/
#define I2C_SCLK_SRC_FLAG_AWARE_DFS (1 << 0) /*!< For REF tick clock, it won't change with APB.*/
+2 -2
View File
@@ -152,7 +152,7 @@ void i2c_hal_disable_slave_rx_it(i2c_hal_context_t *hal)
i2c_ll_slave_disable_rx_it(hal->dev);
}
void i2c_hal_slave_init(i2c_hal_context_t *hal, int i2c_num)
void i2c_hal_slave_init(i2c_hal_context_t *hal, i2c_port_t i2c_num)
{
i2c_ll_slave_init(hal->dev);
//Use fifo mode
@@ -183,7 +183,7 @@ void i2c_hal_master_fsm_rst(i2c_hal_context_t *hal)
i2c_ll_master_fsm_rst(hal->dev);
}
void i2c_hal_master_init(i2c_hal_context_t *hal, int i2c_num)
void i2c_hal_master_init(i2c_hal_context_t *hal, i2c_port_t i2c_num)
{
hal->version = i2c_ll_get_hw_version(hal->dev);
i2c_ll_master_init(hal->dev);
+7 -1
View File
@@ -18,7 +18,13 @@ extern "C" {
/**
* @brief I2C port number, can be I2C_NUM_0 ~ (I2C_NUM_MAX-1).
*/
typedef int i2c_port_t;
typedef enum {
I2C_NUM_0 = 0, /*!< I2C port 0 */
#if SOC_I2C_NUM >= 2
I2C_NUM_1, /*!< I2C port 1 */
#endif
I2C_NUM_MAX, /*!< I2C port max */
} i2c_port_t;
typedef enum{
#if SOC_I2C_SUPPORT_SLAVE