Skip to content

Commit fe2b23b

Browse files
committed
fix(i2c_lcd): using function overloading to keep esp_lcd_new_panel_io_i2c
becuase _Generic is not available in C++ Closes espressif#14037
1 parent 8d8d8cb commit fe2b23b

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

components/esp_lcd/include/esp_lcd_io_i2c.h

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,43 @@ esp_err_t esp_lcd_new_panel_io_i2c_v1(uint32_t bus, const esp_lcd_panel_io_i2c_c
6767
*/
6868
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);
6969

70+
#ifdef __cplusplus
71+
}
72+
#endif
73+
74+
#ifdef __cplusplus
75+
/**
76+
* @brief Create LCD panel IO handle
77+
*
78+
* @param[in] bus I2C bus ID, indicates which I2C port to use
79+
* @param[in] io_config IO configuration, for I2C interface
80+
* @param[out] ret_io Returned IO handle
81+
* @return
82+
* - ESP_ERR_INVALID_ARG if parameter is invalid
83+
* - ESP_ERR_NO_MEM if out of memory
84+
* - ESP_OK on success
85+
*/
86+
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)
87+
{
88+
esp_lcd_new_panel_io_i2c_v1(bus, io_config, ret_io);
89+
}
90+
91+
/**
92+
* @brief Create LCD panel IO handle
93+
*
94+
* @param[in] bus I2C bus handle, returned from `i2c_new_master_bus`
95+
* @param[in] io_config IO configuration, for I2C interface
96+
* @param[out] ret_io Returned IO handle
97+
* @return
98+
* - ESP_ERR_INVALID_ARG if parameter is invalid
99+
* - ESP_ERR_NO_MEM if out of memory
100+
* - ESP_OK on success
101+
*/
102+
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)
103+
{
104+
esp_lcd_new_panel_io_i2c_v2(bus, io_config, ret_io);
105+
}
106+
#else
70107
/**
71108
* @brief Create LCD panel IO handle
72109
*
@@ -80,8 +117,6 @@ esp_err_t esp_lcd_new_panel_io_i2c_v2(i2c_master_bus_handle_t bus, const esp_lcd
80117
*/
81118
#define esp_lcd_new_panel_io_i2c(bus, io_config, ret_io) _Generic((bus), \
82119
i2c_master_bus_handle_t : esp_lcd_new_panel_io_i2c_v2, \
83-
default : esp_lcd_new_panel_io_i2c_v1) (bus, io_config, ret_io) \
120+
default : esp_lcd_new_panel_io_i2c_v1) (bus, io_config, ret_io)
84121

85-
#ifdef __cplusplus
86-
}
87122
#endif

tools/test_apps/system/cxx_build_test/main/test_i2c_lcd.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
66
#include "esp_lcd_panel_vendor.h"
7+
#include "esp_lcd_panel_io.h"
8+
#include "driver/i2c_master.h"
79

810
const esp_lcd_panel_dev_config_t panel_config0 = {
911
.reset_gpio_num = 0,
@@ -37,3 +39,40 @@ const esp_lcd_panel_dev_config_t panel_config2 = {
3739
},
3840
.vendor_config = NULL,
3941
};
42+
43+
void test_i2c_lcd_apis(void)
44+
{
45+
i2c_master_bus_config_t i2c_bus_conf = {
46+
.i2c_port = -1,
47+
.sda_io_num = GPIO_NUM_0,
48+
.scl_io_num = GPIO_NUM_2,
49+
.clk_source = I2C_CLK_SRC_DEFAULT,
50+
.glitch_ignore_cnt = 0,
51+
.intr_priority = 1,
52+
.trans_queue_depth = 4,
53+
.flags = {
54+
.enable_internal_pullup = true,
55+
}
56+
};
57+
58+
i2c_master_bus_handle_t bus_handle;
59+
i2c_new_master_bus(&i2c_bus_conf, &bus_handle);
60+
61+
esp_lcd_panel_io_handle_t io_handle = NULL;
62+
esp_lcd_panel_io_i2c_config_t io_config = {
63+
.dev_addr = 0x3c,
64+
.on_color_trans_done = NULL,
65+
.user_ctx = NULL,
66+
.control_phase_bytes = 1,
67+
.dc_bit_offset = 6,
68+
.lcd_cmd_bits = 8,
69+
.lcd_param_bits = 8,
70+
.flags = {
71+
.dc_low_on_data = false,
72+
.disable_control_phase = false,
73+
},
74+
.scl_speed_hz = 10 * 1000,
75+
};
76+
77+
esp_lcd_new_panel_io_i2c(bus_handle, &io_config, &io_handle);
78+
}

0 commit comments

Comments
 (0)