|
74 | 74 | #include <driver/i2c_master.h> |
75 | 75 | #endif |
76 | 76 |
|
| 77 | +#ifndef CONFIG_SOC_I2C_SUPPORTED |
| 78 | + #error "It appears I2C is not supported. Please check sdkconfig." |
| 79 | +#endif |
| 80 | + |
77 | 81 | /* GPIO number used for I2C master clock */ |
78 | 82 | #ifdef CONFIG_I2C_MASTER_SCL |
79 | 83 | /* Yellow wire Clock */ |
80 | | - #define I2C_MASTER_SCL_IO CONFIG_I2C_MASTER_SCL |
| 84 | + #define I2C_MASTER_SCL_IO CONFIG_I2C_MASTER_SCL |
81 | 85 | #else |
82 | 86 | /* There should have been a Kconfig.projbuild file in the ./main |
83 | 87 | * directory to set I2C parameters in the sdkconfig project file. */ |
|
87 | 91 | /* GPIO number used for I2C master data */ |
88 | 92 | #ifdef CONFIG_I2C_MASTER_SDA |
89 | 93 | /* Orange wire */ |
90 | | - #define I2C_MASTER_SDA_IO CONFIG_I2C_MASTER_SDA |
| 94 | + #define I2C_MASTER_SDA_IO CONFIG_I2C_MASTER_SDA |
91 | 95 | #else |
92 | 96 | /* There should have been a Kconfig.projbuild file in the ./main |
93 | 97 | * directory to set I2C parameters in the sdkconfig project file. */ |
|
96 | 100 |
|
97 | 101 | /* I2C master i2c port number, |
98 | 102 | * the number of i2c peripheral interfaces available will depend on the chip */ |
99 | | -#define I2C_MASTER_NUM 0 |
| 103 | +#ifndef I2C_MASTER_NUM |
| 104 | + #define I2C_MASTER_NUM 0 |
| 105 | +#endif |
100 | 106 |
|
101 | 107 | /* I2C master clock frequency |
102 | 108 | * Typically, an I2C slave device has a 7-bit address or 10-bit address. |
@@ -184,11 +190,19 @@ static esp_err_t esp_i2c_master_init(void) |
184 | 190 | int i2c_master_port = I2C_MASTER_NUM; |
185 | 191 | esp_err_t ret = ESP_OK; |
186 | 192 |
|
| 193 | + /* I2C port number, can be I2C_NUM_0 ~ (I2C_NUM_MAX-1). */ |
| 194 | + if (I2C_MASTER_NUM >= I2C_NUM_MAX) { |
| 195 | + ESP_LOGW(TAG, "Warning: I2C_MASTER_NUM value %d exceeds (I2C_NUM_MAX-1)" |
| 196 | + " %d ", I2C_MASTER_NUM, I2C_NUM_MAX); |
| 197 | + } |
187 | 198 | ESP_LOGI(TAG, "esp_i2c_master_init"); |
188 | 199 | ESP_LOGI(TAG, "I2C_MASTER_FREQ_HZ = %d", (int)I2C_MASTER_FREQ_HZ); |
189 | 200 | ESP_LOGI(TAG, "I2C_READ_WAIT_TICKS = %d", (int)I2C_READ_WAIT_TICKS); |
190 | 201 | ESP_LOGI(TAG, "I2C_WRITE_WAIT_TICKS = %d", (int)I2C_WRITE_WAIT_TICKS); |
191 | 202 | ESP_LOGI(TAG, "I2C_MASTER_TIMEOUT_MS = %d", (int)I2C_MASTER_TIMEOUT_MS); |
| 203 | + ESP_LOGI(TAG, "I2C_MASTER_NUM = %d", (int)I2C_MASTER_NUM); |
| 204 | + ESP_LOGI(TAG, "I2C_MASTER_SCL_IO = %d", (int)I2C_MASTER_SCL_IO); |
| 205 | + ESP_LOGI(TAG, "I2C_MASTER_SDA_IO = %d", (int)I2C_MASTER_SDA_IO); |
192 | 206 |
|
193 | 207 | conf.mode = I2C_MODE_MASTER; |
194 | 208 | conf.sda_io_num = I2C_MASTER_SDA_IO; |
|
0 commit comments