2222#define ACK_VAL 0x0 // I2C ack value
2323#define NACK_VAL 0x1 // I2C nack value
2424
25- static xSemaphoreHandle i2c0_mux = NULL ;
26- static xSemaphoreHandle i2c1_mux = NULL ;
25+
26+ static SemaphoreHandle_t i2c0_mux = NULL ;
27+ static SemaphoreHandle_t i2c1_mux = NULL ;
28+
29+ static const char * TAG = "buses" ;
2730
2831esp_err_t start_buses () {
2932 // This function initializes the VSPI, HSPI and I2C buses of the ESP32
@@ -129,9 +132,9 @@ esp_err_t driver_i2c_read_bytes(int bus, uint8_t addr, uint8_t *value, size_t va
129132 res = i2c_master_stop (cmd );
130133 if (res != ESP_OK ) { i2c_cmd_link_delete (cmd ); return res ; }
131134
132- xSemaphoreHandle mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
135+ SemaphoreHandle_t mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
133136 if (xSemaphoreTake (mux , portMAX_DELAY ) != pdTRUE ) return ESP_ERR_TIMEOUT ; // Wait for I2C bus to become available
134- res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_RATE_MS );
137+ res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_PERIOD_MS );
135138 i2c_cmd_link_delete (cmd );
136139 xSemaphoreGive (mux );
137140 return res ;
@@ -158,9 +161,9 @@ esp_err_t driver_i2c_read_reg(int bus, uint8_t addr, uint8_t reg, uint8_t *value
158161 res = i2c_master_stop (cmd );
159162 if (res != ESP_OK ) { i2c_cmd_link_delete (cmd ); return res ; }
160163
161- xSemaphoreHandle mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
164+ SemaphoreHandle_t mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
162165 if (xSemaphoreTake (mux , portMAX_DELAY ) != pdTRUE ) return ESP_ERR_TIMEOUT ; // Wait for I2C bus to become available
163- res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_RATE_MS );
166+ res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_PERIOD_MS );
164167 i2c_cmd_link_delete (cmd );
165168 xSemaphoreGive (mux );
166169 return res ;
@@ -179,9 +182,9 @@ esp_err_t driver_i2c_read_event(int bus, uint8_t addr, uint8_t *buf) {
179182 res = i2c_master_stop (cmd );
180183 if (res != ESP_OK ) { i2c_cmd_link_delete (cmd ); return res ; }
181184
182- xSemaphoreHandle mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
185+ SemaphoreHandle_t mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
183186 if (xSemaphoreTake (mux , portMAX_DELAY ) != pdTRUE ) return ESP_ERR_TIMEOUT ; // Wait for I2C bus to become available
184- res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_RATE_MS );
187+ res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_PERIOD_MS );
185188 i2c_cmd_link_delete (cmd );
186189 xSemaphoreGive (mux );
187190 return res ;
@@ -198,9 +201,9 @@ esp_err_t driver_i2c_write_byte(int bus, uint8_t addr, uint8_t value) {
198201 res = i2c_master_stop (cmd );
199202 if (res != ESP_OK ) { i2c_cmd_link_delete (cmd ); return res ; }
200203
201- xSemaphoreHandle mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
204+ SemaphoreHandle_t mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
202205 if (xSemaphoreTake (mux , portMAX_DELAY ) != pdTRUE ) return ESP_ERR_TIMEOUT ; // Wait for I2C bus to become available
203- res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_RATE_MS );
206+ res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_PERIOD_MS );
204207 i2c_cmd_link_delete (cmd );
205208 xSemaphoreGive (mux );
206209 return res ;
@@ -219,9 +222,9 @@ esp_err_t driver_i2c_write_reg(int bus, uint8_t addr, uint8_t reg, uint8_t value
219222 res = i2c_master_stop (cmd );
220223 if (res != ESP_OK ) { i2c_cmd_link_delete (cmd ); return res ; }
221224
222- xSemaphoreHandle mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
225+ SemaphoreHandle_t mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
223226 if (xSemaphoreTake (mux , portMAX_DELAY ) != pdTRUE ) return ESP_ERR_TIMEOUT ; // Wait for I2C bus to become available
224- res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_RATE_MS );
227+ res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_PERIOD_MS );
225228 i2c_cmd_link_delete (cmd );
226229 xSemaphoreGive (mux );
227230 return res ;
@@ -242,9 +245,9 @@ esp_err_t driver_i2c_write_reg_n(int bus, uint8_t addr, uint8_t reg, uint8_t *va
242245 res = i2c_master_stop (cmd );
243246 if (res != ESP_OK ) { i2c_cmd_link_delete (cmd ); return res ; }
244247
245- xSemaphoreHandle mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
248+ SemaphoreHandle_t mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
246249 if (xSemaphoreTake (mux , portMAX_DELAY ) != pdTRUE ) return ESP_ERR_TIMEOUT ; // Wait for I2C bus to become available
247- res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_RATE_MS );
250+ res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_PERIOD_MS );
248251 i2c_cmd_link_delete (cmd );
249252 xSemaphoreGive (mux );
250253 return res ;
@@ -263,9 +266,9 @@ esp_err_t driver_i2c_write_buffer(int bus, uint8_t addr, const uint8_t* buffer,
263266 res = i2c_master_stop (cmd );
264267 if (res != ESP_OK ) { i2c_cmd_link_delete (cmd ); return res ; }
265268
266- xSemaphoreHandle mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
269+ SemaphoreHandle_t mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
267270 if (xSemaphoreTake (mux , portMAX_DELAY ) != pdTRUE ) return ESP_ERR_TIMEOUT ; // Wait for I2C bus to become available
268- res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_RATE_MS );
271+ res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_PERIOD_MS );
269272 i2c_cmd_link_delete (cmd );
270273 xSemaphoreGive (mux );
271274 return res ;
@@ -286,9 +289,9 @@ esp_err_t driver_i2c_write_buffer_reg(int bus, uint8_t addr, uint8_t reg, const
286289 res = i2c_master_stop (cmd );
287290 if (res != ESP_OK ) { i2c_cmd_link_delete (cmd ); return res ; }
288291
289- xSemaphoreHandle mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
292+ SemaphoreHandle_t mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
290293 if (xSemaphoreTake (mux , portMAX_DELAY ) != pdTRUE ) return ESP_ERR_TIMEOUT ; // Wait for I2C bus to become available
291- res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_RATE_MS );
294+ res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_PERIOD_MS );
292295 i2c_cmd_link_delete (cmd );
293296 xSemaphoreGive (mux );
294297 return res ;
@@ -313,9 +316,9 @@ esp_err_t driver_i2c_write_reg32(int bus, uint8_t addr, uint8_t reg, uint32_t va
313316 res = i2c_master_stop (cmd );
314317 if (res != ESP_OK ) { i2c_cmd_link_delete (cmd ); return res ; }
315318
316- xSemaphoreHandle mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
319+ SemaphoreHandle_t mux = (bus == I2C_NUM_1 ) ? i2c1_mux : i2c0_mux ;
317320 if (xSemaphoreTake (mux , portMAX_DELAY ) != pdTRUE ) return ESP_ERR_TIMEOUT ; // Wait for I2C bus to become available
318- res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_RATE_MS );
321+ res = i2c_master_cmd_begin (bus , cmd , 1000 / portTICK_PERIOD_MS );
319322 i2c_cmd_link_delete (cmd );
320323 xSemaphoreGive (mux );
321324 return res ;
0 commit comments