fix(i2c_lcd): using function overloading to keep esp_lcd_new_panel_io_i2c

becuase _Generic is not available in C++

Closes https://github.com/espressif/esp-idf/issues/14037
This commit is contained in:
morris 2024-06-21 11:04:15 +08:00
parent 8d8d8cbf18
commit fe2b23b93a
2 changed files with 77 additions and 3 deletions

View File

@ -67,6 +67,43 @@ esp_err_t esp_lcd_new_panel_io_i2c_v1(uint32_t bus, const esp_lcd_panel_io_i2c_c
*/
esp_err_t esp_lcd_new_panel_io_i2c_v2(i2c_master_bus_handle_t bus, const esp_lcd_panel_io_i2c_config_t *io_config, esp_lcd_panel_io_handle_t *ret_io);
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
/**
* @brief Create LCD panel IO handle
*
* @param[in] bus I2C bus ID, indicates which I2C port to use
* @param[in] io_config IO configuration, for I2C interface
* @param[out] ret_io Returned IO handle
* @return
* - ESP_ERR_INVALID_ARG if parameter is invalid
* - ESP_ERR_NO_MEM if out of memory
* - ESP_OK on success
*/
static inline void esp_lcd_new_panel_io_i2c(uint32_t bus, const esp_lcd_panel_io_i2c_config_t *io_config, esp_lcd_panel_io_handle_t *ret_io)
{
esp_lcd_new_panel_io_i2c_v1(bus, io_config, ret_io);
}
/**
* @brief Create LCD panel IO handle
*
* @param[in] bus I2C bus handle, returned from `i2c_new_master_bus`
* @param[in] io_config IO configuration, for I2C interface
* @param[out] ret_io Returned IO handle
* @return
* - ESP_ERR_INVALID_ARG if parameter is invalid
* - ESP_ERR_NO_MEM if out of memory
* - ESP_OK on success
*/
static inline void esp_lcd_new_panel_io_i2c(i2c_master_bus_handle_t bus, const esp_lcd_panel_io_i2c_config_t *io_config, esp_lcd_panel_io_handle_t *ret_io)
{
esp_lcd_new_panel_io_i2c_v2(bus, io_config, ret_io);
}
#else
/**
* @brief Create LCD panel IO handle
*
@ -80,8 +117,6 @@ esp_err_t esp_lcd_new_panel_io_i2c_v2(i2c_master_bus_handle_t bus, const esp_lcd
*/
#define esp_lcd_new_panel_io_i2c(bus, io_config, ret_io) _Generic((bus), \
i2c_master_bus_handle_t : esp_lcd_new_panel_io_i2c_v2, \
default : esp_lcd_new_panel_io_i2c_v1) (bus, io_config, ret_io) \
default : esp_lcd_new_panel_io_i2c_v1) (bus, io_config, ret_io)
#ifdef __cplusplus
}
#endif

View File

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include "esp_lcd_panel_vendor.h"
#include "esp_lcd_panel_io.h"
#include "driver/i2c_master.h"
const esp_lcd_panel_dev_config_t panel_config0 = {
.reset_gpio_num = 0,
@ -37,3 +39,40 @@ const esp_lcd_panel_dev_config_t panel_config2 = {
},
.vendor_config = NULL,
};
void test_i2c_lcd_apis(void)
{
i2c_master_bus_config_t i2c_bus_conf = {
.i2c_port = -1,
.sda_io_num = GPIO_NUM_0,
.scl_io_num = GPIO_NUM_2,
.clk_source = I2C_CLK_SRC_DEFAULT,
.glitch_ignore_cnt = 0,
.intr_priority = 1,
.trans_queue_depth = 4,
.flags = {
.enable_internal_pullup = true,
}
};
i2c_master_bus_handle_t bus_handle;
i2c_new_master_bus(&i2c_bus_conf, &bus_handle);
esp_lcd_panel_io_handle_t io_handle = NULL;
esp_lcd_panel_io_i2c_config_t io_config = {
.dev_addr = 0x3c,
.on_color_trans_done = NULL,
.user_ctx = NULL,
.control_phase_bytes = 1,
.dc_bit_offset = 6,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
.flags = {
.dc_low_on_data = false,
.disable_control_phase = false,
},
.scl_speed_hz = 10 * 1000,
};
esp_lcd_new_panel_io_i2c(bus_handle, &io_config, &io_handle);
}