Skip to content

Commit

Permalink
Fix build issues on esp32-idf v5
Browse files Browse the repository at this point in the history
* Remove I2C_MASTER_NUM definition when the module doesn't have 2 I2C, such as esp32-c3
* Remove HSPI_HOST macro deprecated for newer chips
* Replace deprecated portTICK_RATE_MS with pdMS_TO_TICKS
  • Loading branch information
r12f authored Feb 20, 2023
1 parent 5553dd3 commit 3d11835
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions include/u8g2_esp32_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@

#define U8G2_ESP32_HAL_UNDEFINED GPIO_NUM_NC

#if SOC_I2C_NUM > 1
#define I2C_MASTER_NUM I2C_NUM_1 // I2C port number for master dev
#else
#define I2C_MASTER_NUM I2C_NUM_0 // I2C port number for master dev
#endif

#define I2C_MASTER_TX_BUF_DISABLE 0 // I2C master do not need buffer
#define I2C_MASTER_RX_BUF_DISABLE 0 // I2C master do not need buffer
#define I2C_MASTER_FREQ_HZ 50000 // I2C master clock frequency
Expand Down
8 changes: 5 additions & 3 deletions src/u8g2_esp32_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ static spi_device_handle_t handle_spi; // SPI handle.
static i2c_cmd_handle_t handle_i2c; // I2C handle.
static u8g2_esp32_hal_t u8g2_esp32_hal; // HAL state data.

#define HOST SPI2_HOST

#undef ESP_ERROR_CHECK
#define ESP_ERROR_CHECK(x) \
do { \
Expand Down Expand Up @@ -65,7 +67,7 @@ uint8_t u8g2_esp32_spi_byte_cb(u8x8_t* u8x8,
bus_config.quadwp_io_num = GPIO_NUM_NC; // Not used
bus_config.quadhd_io_num = GPIO_NUM_NC; // Not used
// ESP_LOGI(TAG, "... Initializing bus.");
ESP_ERROR_CHECK(spi_bus_initialize(HSPI_HOST, &bus_config, 1));
ESP_ERROR_CHECK(spi_bus_initialize(HOST, &bus_config, 1));

spi_device_interface_config_t dev_config;
dev_config.address_bits = 0;
Expand All @@ -82,7 +84,7 @@ uint8_t u8g2_esp32_spi_byte_cb(u8x8_t* u8x8,
dev_config.pre_cb = NULL;
dev_config.post_cb = NULL;
// ESP_LOGI(TAG, "... Adding device bus.");
ESP_ERROR_CHECK(spi_bus_add_device(HSPI_HOST, &dev_config, &handle_spi));
ESP_ERROR_CHECK(spi_bus_add_device(HOST, &dev_config, &handle_spi));

break;
}
Expand Down Expand Up @@ -176,7 +178,7 @@ uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t* u8x8,
ESP_LOGD(TAG, "End I2C transfer.");
ESP_ERROR_CHECK(i2c_master_stop(handle_i2c));
ESP_ERROR_CHECK(i2c_master_cmd_begin(I2C_MASTER_NUM, handle_i2c,
I2C_TIMEOUT_MS / portTICK_RATE_MS));
pdMS_TO_TICKS(I2C_TIMEOUT_MS)));
i2c_cmd_link_delete(handle_i2c);
break;
}
Expand Down

0 comments on commit 3d11835

Please sign in to comment.