mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-03 10:30:58 +02:00
refactor(i2c_lcd): test app in cxx environment
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -22,17 +22,17 @@ typedef uint32_t esp_lcd_i2c_bus_handle_t; /*!< Type of LCD I
|
|||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t dev_addr; /*!< I2C device address */
|
uint32_t dev_addr; /*!< I2C device address */
|
||||||
|
uint32_t scl_speed_hz; /*!< I2C LCD SCL frequency (hz) */
|
||||||
|
size_t control_phase_bytes; /*!< I2C LCD panel will encode control information (e.g. D/C selection) into control phase, in several bytes */
|
||||||
|
uint8_t dc_bit_offset; /*!< Offset of the D/C selection bit in control phase */
|
||||||
|
int lcd_cmd_bits; /*!< Bit-width of LCD command */
|
||||||
|
int lcd_param_bits; /*!< Bit-width of LCD parameter */
|
||||||
esp_lcd_panel_io_color_trans_done_cb_t on_color_trans_done; /*!< Callback invoked when color data transfer has finished */
|
esp_lcd_panel_io_color_trans_done_cb_t on_color_trans_done; /*!< Callback invoked when color data transfer has finished */
|
||||||
void *user_ctx; /*!< User private data, passed directly to on_color_trans_done's user_ctx */
|
void *user_ctx; /*!< User private data, passed directly to on_color_trans_done's user_ctx */
|
||||||
size_t control_phase_bytes; /*!< I2C LCD panel will encode control information (e.g. D/C selection) into control phase, in several bytes */
|
|
||||||
unsigned int dc_bit_offset; /*!< Offset of the D/C selection bit in control phase */
|
|
||||||
int lcd_cmd_bits; /*!< Bit-width of LCD command */
|
|
||||||
int lcd_param_bits; /*!< Bit-width of LCD parameter */
|
|
||||||
struct {
|
struct {
|
||||||
unsigned int dc_low_on_data: 1; /*!< If this flag is enabled, DC line = 0 means transfer data, DC line = 1 means transfer command; vice versa */
|
unsigned int dc_low_on_data: 1; /*!< If this flag is enabled, DC line = 0 means transfer data, DC line = 1 means transfer command; vice versa */
|
||||||
unsigned int disable_control_phase: 1; /*!< If this flag is enabled, the control phase isn't used */
|
unsigned int disable_control_phase: 1; /*!< If this flag is enabled, the control phase isn't used */
|
||||||
} flags; /*!< Extra flags to fine-tune the I2C device */
|
} flags; /*!< Extra flags to fine-tune the I2C device */
|
||||||
uint32_t scl_speed_hz; /*!< I2C LCD SCL frequency (hz) */
|
|
||||||
} esp_lcd_panel_io_i2c_config_t;
|
} esp_lcd_panel_io_i2c_config_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
set(srcs "test_app_main.c"
|
set(srcs "test_app_main.c"
|
||||||
"test_i2c_lcd_panel.c")
|
"test_i2c_lcd_panel.cpp")
|
||||||
|
|
||||||
# In order for the cases defined by `TEST_CASE` to be linked into the final elf,
|
# In order for the cases defined by `TEST_CASE` to be linked into the final elf,
|
||||||
# the component can be registered as WHOLE_ARCHIVE
|
# the component can be registered as WHOLE_ARCHIVE
|
||||||
|
@@ -12,8 +12,8 @@ extern "C" {
|
|||||||
#define TEST_LCD_H_RES 128
|
#define TEST_LCD_H_RES 128
|
||||||
#define TEST_LCD_V_RES 64
|
#define TEST_LCD_V_RES 64
|
||||||
|
|
||||||
#define TEST_I2C_SDA_GPIO 0
|
#define TEST_I2C_SDA_GPIO GPIO_NUM_0
|
||||||
#define TEST_I2C_SCL_GPIO 2
|
#define TEST_I2C_SCL_GPIO GPIO_NUM_2
|
||||||
|
|
||||||
#define TEST_I2C_HOST_ID 0
|
#define TEST_I2C_HOST_ID 0
|
||||||
|
|
||||||
|
@@ -27,13 +27,20 @@ TEST_CASE("lcd_panel_with_i2c_interface_(ssd1306)", "[lcd]")
|
|||||||
};
|
};
|
||||||
|
|
||||||
i2c_master_bus_config_t i2c_bus_conf = {
|
i2c_master_bus_config_t i2c_bus_conf = {
|
||||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
.i2c_port = -1, // automatically select a free I2C port
|
||||||
.sda_io_num = TEST_I2C_SDA_GPIO,
|
.sda_io_num = TEST_I2C_SDA_GPIO,
|
||||||
.scl_io_num = TEST_I2C_SCL_GPIO,
|
.scl_io_num = TEST_I2C_SCL_GPIO,
|
||||||
.i2c_port = -1,
|
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||||
|
.glitch_ignore_cnt = 4,
|
||||||
|
.intr_priority = 0,
|
||||||
|
.trans_queue_depth = 0, // no tx queue, transmit using blocking mode
|
||||||
|
.flags = {
|
||||||
|
.enable_internal_pullup = true,
|
||||||
|
.allow_pd = false,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
i2c_master_bus_handle_t bus_handle;
|
i2c_master_bus_handle_t bus_handle = NULL;
|
||||||
TEST_ESP_OK(i2c_new_master_bus(&i2c_bus_conf, &bus_handle));
|
TEST_ESP_OK(i2c_new_master_bus(&i2c_bus_conf, &bus_handle));
|
||||||
|
|
||||||
esp_lcd_panel_io_handle_t io_handle = NULL;
|
esp_lcd_panel_io_handle_t io_handle = NULL;
|
||||||
@@ -44,14 +51,26 @@ TEST_CASE("lcd_panel_with_i2c_interface_(ssd1306)", "[lcd]")
|
|||||||
.dc_bit_offset = 6, // According to SSD1306 datasheet
|
.dc_bit_offset = 6, // According to SSD1306 datasheet
|
||||||
.lcd_cmd_bits = 8, // According to SSD1306 datasheet
|
.lcd_cmd_bits = 8, // According to SSD1306 datasheet
|
||||||
.lcd_param_bits = 8, // According to SSD1306 datasheet
|
.lcd_param_bits = 8, // According to SSD1306 datasheet
|
||||||
|
.on_color_trans_done = NULL,
|
||||||
|
.user_ctx = NULL,
|
||||||
|
.flags = {
|
||||||
|
.dc_low_on_data = false, // According to SSD1306 datasheet, DC=0 means command, DC=1 means data
|
||||||
|
.disable_control_phase = false, // Control phase is used
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_ESP_OK(esp_lcd_new_panel_io_i2c(bus_handle, &io_config, &io_handle));
|
TEST_ESP_OK(esp_lcd_new_panel_io_i2c(bus_handle, &io_config, &io_handle));
|
||||||
|
|
||||||
esp_lcd_panel_handle_t panel_handle = NULL;
|
esp_lcd_panel_handle_t panel_handle = NULL;
|
||||||
esp_lcd_panel_dev_config_t panel_config = {
|
esp_lcd_panel_dev_config_t panel_config = {
|
||||||
.bits_per_pixel = 1,
|
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_BGR, // SSD1306 is monochrome, so RGB order doesn't matter
|
||||||
.reset_gpio_num = -1,
|
.data_endian = LCD_RGB_DATA_ENDIAN_LITTLE,
|
||||||
|
.bits_per_pixel = 1, // SSD1306 is monochrome, so 1 bit per pixel
|
||||||
|
.reset_gpio_num = GPIO_NUM_NC,
|
||||||
|
.vendor_config = NULL,
|
||||||
|
.flags = {
|
||||||
|
.reset_active_high = false, // SSD1306 reset is active low
|
||||||
|
}
|
||||||
};
|
};
|
||||||
TEST_ESP_OK(esp_lcd_new_panel_ssd1306(io_handle, &panel_config, &panel_handle));
|
TEST_ESP_OK(esp_lcd_new_panel_ssd1306(io_handle, &panel_config, &panel_handle));
|
||||||
TEST_ESP_OK(esp_lcd_panel_reset(panel_handle));
|
TEST_ESP_OK(esp_lcd_panel_reset(panel_handle));
|
@@ -3,10 +3,6 @@ set(srcs cxx_build_test_main.cpp
|
|||||||
test_cxx_standard.cpp
|
test_cxx_standard.cpp
|
||||||
test_sdmmc_sdspi_init.cpp)
|
test_sdmmc_sdspi_init.cpp)
|
||||||
|
|
||||||
if(CONFIG_SOC_I2C_SUPPORTED)
|
|
||||||
list(APPEND srcs test_i2c_lcd.cpp)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(CONFIG_SOC_I2S_SUPPORTED)
|
if(CONFIG_SOC_I2S_SUPPORTED)
|
||||||
list(APPEND srcs test_i2s.cpp)
|
list(APPEND srcs test_i2s.cpp)
|
||||||
endif()
|
endif()
|
||||||
@@ -17,5 +13,4 @@ endif()
|
|||||||
|
|
||||||
idf_component_register(SRCS "${srcs}"
|
idf_component_register(SRCS "${srcs}"
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
PRIV_REQUIRES driver esp_lcd esp_driver_i2s
|
PRIV_REQUIRES driver esp_driver_i2s)
|
||||||
REQUIRES soc)
|
|
||||||
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* 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,
|
|
||||||
.color_space = ESP_LCD_COLOR_SPACE_MONOCHROME,
|
|
||||||
.data_endian = LCD_RGB_DATA_ENDIAN_LITTLE,
|
|
||||||
.bits_per_pixel = 16,
|
|
||||||
.flags = {
|
|
||||||
.reset_active_high = false,
|
|
||||||
},
|
|
||||||
.vendor_config = NULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
const esp_lcd_panel_dev_config_t panel_config1 = {
|
|
||||||
.reset_gpio_num = 0,
|
|
||||||
.color_space = ESP_LCD_COLOR_SPACE_BGR,
|
|
||||||
.data_endian = LCD_RGB_DATA_ENDIAN_LITTLE,
|
|
||||||
.bits_per_pixel = 16,
|
|
||||||
.flags = {
|
|
||||||
.reset_active_high = false,
|
|
||||||
},
|
|
||||||
.vendor_config = NULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
const esp_lcd_panel_dev_config_t panel_config2 = {
|
|
||||||
.reset_gpio_num = 0,
|
|
||||||
.rgb_endian = LCD_RGB_ENDIAN_BGR,
|
|
||||||
.data_endian = LCD_RGB_DATA_ENDIAN_LITTLE,
|
|
||||||
.bits_per_pixel = 16,
|
|
||||||
.flags = {
|
|
||||||
.reset_active_high = false,
|
|
||||||
},
|
|
||||||
.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,
|
|
||||||
.allow_pd = false,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
Reference in New Issue
Block a user