@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: CC0-1.0
|
||||
*/
|
||||
|
||||
#include "hw_init.h"
|
||||
|
||||
#if CONFIG_EXAMPLE_LCD_INTERFACE_MIPI_DSI
|
||||
|
||||
#include "esp_ldo_regulator.h"
|
||||
#include "esp_lcd_mipi_dsi.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "esp_lcd_ek79007.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
static const char *TAG = "hw_lcd_init";
|
||||
|
||||
#define HW_LDO_MIPI_CHAN (3)
|
||||
#define HW_LDO_MIPI_VOLTAGE_MV (2500)
|
||||
#define HW_LCD_BIT_PER_PIXEL (16)
|
||||
#define HW_MIPI_DPI_PX_FORMAT (LCD_COLOR_PIXEL_FORMAT_RGB565)
|
||||
#define HW_PIN_NUM_LCD_RST (27)
|
||||
|
||||
static esp_lcd_dsi_bus_handle_t s_mipi_dsi_bus;
|
||||
static esp_lcd_panel_io_handle_t s_mipi_dbi_io;
|
||||
static esp_lcd_panel_handle_t s_panel_handle;
|
||||
|
||||
static void lcd_ldo_power_on(void)
|
||||
{
|
||||
esp_ldo_channel_handle_t ldo_mipi_phy = NULL;
|
||||
esp_ldo_channel_config_t ldo_mipi_phy_config = {
|
||||
.chan_id = HW_LDO_MIPI_CHAN,
|
||||
.voltage_mv = HW_LDO_MIPI_VOLTAGE_MV,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_ldo_acquire_channel(&ldo_mipi_phy_config, &ldo_mipi_phy));
|
||||
}
|
||||
|
||||
esp_err_t hw_lcd_init(esp_lcd_panel_handle_t *panel_handle, esp_lcd_panel_io_handle_t *io_handle, esp_lv_adapter_tear_avoid_mode_t tear_avoid_mode, esp_lv_adapter_rotation_t rotation)
|
||||
{
|
||||
lcd_ldo_power_on();
|
||||
|
||||
ESP_LOGD(TAG, "Install LCD driver");
|
||||
esp_lcd_dsi_bus_config_t bus_config = EK79007_PANEL_BUS_DSI_2CH_CONFIG();
|
||||
ESP_ERROR_CHECK(esp_lcd_new_dsi_bus(&bus_config, &s_mipi_dsi_bus));
|
||||
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
esp_lcd_dbi_io_config_t dbi_config = EK79007_PANEL_IO_DBI_CONFIG();
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_dbi(s_mipi_dsi_bus, &dbi_config, &s_mipi_dbi_io));
|
||||
|
||||
ESP_LOGI(TAG, "Install LCD driver of ek79007");
|
||||
esp_lcd_dpi_panel_config_t dpi_config = EK79007_1024_600_PANEL_60HZ_CONFIG(HW_MIPI_DPI_PX_FORMAT);
|
||||
dpi_config.num_fbs = esp_lv_adapter_get_required_frame_buffer_count(tear_avoid_mode, rotation);
|
||||
ek79007_vendor_config_t vendor_config = {
|
||||
.mipi_config = {
|
||||
.dsi_bus = s_mipi_dsi_bus,
|
||||
.dpi_config = &dpi_config,
|
||||
},
|
||||
};
|
||||
const esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = HW_PIN_NUM_LCD_RST,
|
||||
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
|
||||
.bits_per_pixel = HW_LCD_BIT_PER_PIXEL,
|
||||
.vendor_config = &vendor_config,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_ek79007(s_mipi_dbi_io, &panel_config, &s_panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_reset(s_panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_init(s_panel_handle));
|
||||
|
||||
*panel_handle = s_panel_handle;
|
||||
if (io_handle) {
|
||||
*io_handle = s_mipi_dbi_io;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,314 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: CC0-1.0
|
||||
*/
|
||||
|
||||
#include "esp_system.h"
|
||||
#include "esp_lcd_st77916.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "hw_init.h"
|
||||
#include "helpers/lcd_orientation_helper.h"
|
||||
|
||||
#if CONFIG_EXAMPLE_LCD_INTERFACE_QSPI
|
||||
|
||||
static const char *TAG = "hw_lcd_init";
|
||||
|
||||
#define HW_PIN_NUM_BK_LIGHT (GPIO_NUM_44)
|
||||
#define HW_LCD_BK_LIGHT_ON_LEVEL (1)
|
||||
#define HW_LCD_BASE_SWAP_XY (false)
|
||||
#define HW_LCD_BASE_MIRROR_X (false)
|
||||
#define HW_LCD_BASE_MIRROR_Y (false)
|
||||
|
||||
#define HW_LCD_DATA3 (GPIO_NUM_12)
|
||||
#define HW_LCD_DATA2 (GPIO_NUM_11)
|
||||
#define HW_LCD_DATA1 (GPIO_NUM_13)
|
||||
#define HW_LCD_DATA0 (GPIO_NUM_46)
|
||||
#define HW_LCD_PCLK (GPIO_NUM_18)
|
||||
#define HW_LCD_CS (GPIO_NUM_14)
|
||||
#define HW_LCD_DC (GPIO_NUM_45)
|
||||
#define HW_LCD_RST (GPIO_NUM_47)
|
||||
#define HW_LCD_POWER_OFF (GPIO_NUM_9)
|
||||
|
||||
#define HW_LCD_PIXEL_CLOCK_HZ (80 * 1000 * 1000)
|
||||
#define HW_LCD_COLOR_SPACE (LCD_RGB_ELEMENT_ORDER_RGB)
|
||||
#define HW_LCD_BITS_PER_PIXEL (16)
|
||||
#define HW_LCD_CMD_BITS (32)
|
||||
#define HW_LCD_PARAM_BITS (8)
|
||||
#define HW_LCD_MAX_TRANSFER_SZ (HW_LCD_H_RES * HW_LCD_V_RES * 2)
|
||||
|
||||
static esp_lcd_panel_io_handle_t s_panel_io_handle;
|
||||
static esp_lcd_panel_handle_t s_panel_handle;
|
||||
|
||||
static const st77916_lcd_init_cmd_t st77916_qspi_init[] = {
|
||||
{0xF0, (uint8_t []){0x28}, 1, 0},
|
||||
{0xF2, (uint8_t []){0x28}, 1, 0},
|
||||
{0x73, (uint8_t []){0xF0}, 1, 0},
|
||||
{0x7C, (uint8_t []){0xD1}, 1, 0},
|
||||
{0x83, (uint8_t []){0xE0}, 1, 0},
|
||||
{0x84, (uint8_t []){0x61}, 1, 0},
|
||||
{0xF2, (uint8_t []){0x82}, 1, 0},
|
||||
{0xF0, (uint8_t []){0x00}, 1, 0},
|
||||
{0xF0, (uint8_t []){0x01}, 1, 0},
|
||||
{0xF1, (uint8_t []){0x01}, 1, 0},
|
||||
{0xB0, (uint8_t []){0x56}, 1, 0},
|
||||
{0xB1, (uint8_t []){0x4D}, 1, 0},
|
||||
{0xB2, (uint8_t []){0x24}, 1, 0},
|
||||
{0xB4, (uint8_t []){0x87}, 1, 0},
|
||||
{0xB5, (uint8_t []){0x44}, 1, 0},
|
||||
{0xB6, (uint8_t []){0x8B}, 1, 0},
|
||||
{0xB7, (uint8_t []){0x40}, 1, 0},
|
||||
{0xB8, (uint8_t []){0x86}, 1, 0},
|
||||
{0xBA, (uint8_t []){0x00}, 1, 0},
|
||||
{0xBB, (uint8_t []){0x08}, 1, 0},
|
||||
{0xBC, (uint8_t []){0x08}, 1, 0},
|
||||
{0xBD, (uint8_t []){0x00}, 1, 0},
|
||||
{0xC0, (uint8_t []){0x80}, 1, 0},
|
||||
{0xC1, (uint8_t []){0x10}, 1, 0},
|
||||
{0xC2, (uint8_t []){0x37}, 1, 0},
|
||||
{0xC3, (uint8_t []){0x80}, 1, 0},
|
||||
{0xC4, (uint8_t []){0x10}, 1, 0},
|
||||
{0xC5, (uint8_t []){0x37}, 1, 0},
|
||||
{0xC6, (uint8_t []){0xA9}, 1, 0},
|
||||
{0xC7, (uint8_t []){0x41}, 1, 0},
|
||||
{0xC8, (uint8_t []){0x01}, 1, 0},
|
||||
{0xC9, (uint8_t []){0xA9}, 1, 0},
|
||||
{0xCA, (uint8_t []){0x41}, 1, 0},
|
||||
{0xCB, (uint8_t []){0x01}, 1, 0},
|
||||
{0xD0, (uint8_t []){0x91}, 1, 0},
|
||||
{0xD1, (uint8_t []){0x68}, 1, 0},
|
||||
{0xD2, (uint8_t []){0x68}, 1, 0},
|
||||
{0xF5, (uint8_t []){0x00, 0xA5}, 2, 0},
|
||||
{0xDD, (uint8_t []){0x4F}, 1, 0},
|
||||
{0xDE, (uint8_t []){0x4F}, 1, 0},
|
||||
{0xF1, (uint8_t []){0x10}, 1, 0},
|
||||
{0xF0, (uint8_t []){0x00}, 1, 0},
|
||||
{0xF0, (uint8_t []){0x02}, 1, 0},
|
||||
{0xE0, (uint8_t []){0xF0, 0x0A, 0x10, 0x09, 0x09, 0x36, 0x35, 0x33, 0x4A, 0x29, 0x15, 0x15, 0x2E, 0x34}, 14, 0},
|
||||
{0xE1, (uint8_t []){0xF0, 0x0A, 0x0F, 0x08, 0x08, 0x05, 0x34, 0x33, 0x4A, 0x39, 0x15, 0x15, 0x2D, 0x33}, 14, 0},
|
||||
{0xF0, (uint8_t []){0x10}, 1, 0},
|
||||
{0xF3, (uint8_t []){0x10}, 1, 0},
|
||||
{0xE0, (uint8_t []){0x07}, 1, 0},
|
||||
{0xE1, (uint8_t []){0x00}, 1, 0},
|
||||
{0xE2, (uint8_t []){0x00}, 1, 0},
|
||||
{0xE3, (uint8_t []){0x00}, 1, 0},
|
||||
{0xE4, (uint8_t []){0xE0}, 1, 0},
|
||||
{0xE5, (uint8_t []){0x06}, 1, 0},
|
||||
{0xE6, (uint8_t []){0x21}, 1, 0},
|
||||
{0xE7, (uint8_t []){0x01}, 1, 0},
|
||||
{0xE8, (uint8_t []){0x05}, 1, 0},
|
||||
{0xE9, (uint8_t []){0x02}, 1, 0},
|
||||
{0xEA, (uint8_t []){0xDA}, 1, 0},
|
||||
{0xEB, (uint8_t []){0x00}, 1, 0},
|
||||
{0xEC, (uint8_t []){0x00}, 1, 0},
|
||||
{0xED, (uint8_t []){0x0F}, 1, 0},
|
||||
{0xEE, (uint8_t []){0x00}, 1, 0},
|
||||
{0xEF, (uint8_t []){0x00}, 1, 0},
|
||||
{0xF8, (uint8_t []){0x00}, 1, 0},
|
||||
{0xF9, (uint8_t []){0x00}, 1, 0},
|
||||
{0xFA, (uint8_t []){0x00}, 1, 0},
|
||||
{0xFB, (uint8_t []){0x00}, 1, 0},
|
||||
{0xFC, (uint8_t []){0x00}, 1, 0},
|
||||
{0xFD, (uint8_t []){0x00}, 1, 0},
|
||||
{0xFE, (uint8_t []){0x00}, 1, 0},
|
||||
{0xFF, (uint8_t []){0x00}, 1, 0},
|
||||
{0x60, (uint8_t []){0x40}, 1, 0},
|
||||
{0x61, (uint8_t []){0x04}, 1, 0},
|
||||
{0x62, (uint8_t []){0x00}, 1, 0},
|
||||
{0x63, (uint8_t []){0x42}, 1, 0},
|
||||
{0x64, (uint8_t []){0xD9}, 1, 0},
|
||||
{0x65, (uint8_t []){0x00}, 1, 0},
|
||||
{0x66, (uint8_t []){0x00}, 1, 0},
|
||||
{0x67, (uint8_t []){0x00}, 1, 0},
|
||||
{0x68, (uint8_t []){0x00}, 1, 0},
|
||||
{0x69, (uint8_t []){0x00}, 1, 0},
|
||||
{0x6A, (uint8_t []){0x00}, 1, 0},
|
||||
{0x6B, (uint8_t []){0x00}, 1, 0},
|
||||
{0x70, (uint8_t []){0x40}, 1, 0},
|
||||
{0x71, (uint8_t []){0x03}, 1, 0},
|
||||
{0x72, (uint8_t []){0x00}, 1, 0},
|
||||
{0x73, (uint8_t []){0x42}, 1, 0},
|
||||
{0x74, (uint8_t []){0xD8}, 1, 0},
|
||||
{0x75, (uint8_t []){0x00}, 1, 0},
|
||||
{0x76, (uint8_t []){0x00}, 1, 0},
|
||||
{0x77, (uint8_t []){0x00}, 1, 0},
|
||||
{0x78, (uint8_t []){0x00}, 1, 0},
|
||||
{0x79, (uint8_t []){0x00}, 1, 0},
|
||||
{0x7A, (uint8_t []){0x00}, 1, 0},
|
||||
{0x7B, (uint8_t []){0x00}, 1, 0},
|
||||
{0x80, (uint8_t []){0x48}, 1, 0},
|
||||
{0x81, (uint8_t []){0x00}, 1, 0},
|
||||
{0x82, (uint8_t []){0x06}, 1, 0},
|
||||
{0x83, (uint8_t []){0x02}, 1, 0},
|
||||
{0x84, (uint8_t []){0xD6}, 1, 0},
|
||||
{0x85, (uint8_t []){0x04}, 1, 0},
|
||||
{0x86, (uint8_t []){0x00}, 1, 0},
|
||||
{0x87, (uint8_t []){0x00}, 1, 0},
|
||||
{0x88, (uint8_t []){0x48}, 1, 0},
|
||||
{0x89, (uint8_t []){0x00}, 1, 0},
|
||||
{0x8A, (uint8_t []){0x08}, 1, 0},
|
||||
{0x8B, (uint8_t []){0x02}, 1, 0},
|
||||
{0x8C, (uint8_t []){0xD8}, 1, 0},
|
||||
{0x8D, (uint8_t []){0x04}, 1, 0},
|
||||
{0x8E, (uint8_t []){0x00}, 1, 0},
|
||||
{0x8F, (uint8_t []){0x00}, 1, 0},
|
||||
{0x90, (uint8_t []){0x48}, 1, 0},
|
||||
{0x91, (uint8_t []){0x00}, 1, 0},
|
||||
{0x92, (uint8_t []){0x0A}, 1, 0},
|
||||
{0x93, (uint8_t []){0x02}, 1, 0},
|
||||
{0x94, (uint8_t []){0xDA}, 1, 0},
|
||||
{0x95, (uint8_t []){0x04}, 1, 0},
|
||||
{0x96, (uint8_t []){0x00}, 1, 0},
|
||||
{0x97, (uint8_t []){0x00}, 1, 0},
|
||||
{0x98, (uint8_t []){0x48}, 1, 0},
|
||||
{0x99, (uint8_t []){0x00}, 1, 0},
|
||||
{0x9A, (uint8_t []){0x0C}, 1, 0},
|
||||
{0x9B, (uint8_t []){0x02}, 1, 0},
|
||||
{0x9C, (uint8_t []){0xDC}, 1, 0},
|
||||
{0x9D, (uint8_t []){0x04}, 1, 0},
|
||||
{0x9E, (uint8_t []){0x00}, 1, 0},
|
||||
{0x9F, (uint8_t []){0x00}, 1, 0},
|
||||
{0xA0, (uint8_t []){0x48}, 1, 0},
|
||||
{0xA1, (uint8_t []){0x00}, 1, 0},
|
||||
{0xA2, (uint8_t []){0x05}, 1, 0},
|
||||
{0xA3, (uint8_t []){0x02}, 1, 0},
|
||||
{0xA4, (uint8_t []){0xD5}, 1, 0},
|
||||
{0xA5, (uint8_t []){0x04}, 1, 0},
|
||||
{0xA6, (uint8_t []){0x00}, 1, 0},
|
||||
{0xA7, (uint8_t []){0x00}, 1, 0},
|
||||
{0xA8, (uint8_t []){0x48}, 1, 0},
|
||||
{0xA9, (uint8_t []){0x00}, 1, 0},
|
||||
{0xAA, (uint8_t []){0x07}, 1, 0},
|
||||
{0xAB, (uint8_t []){0x02}, 1, 0},
|
||||
{0xAC, (uint8_t []){0xD7}, 1, 0},
|
||||
{0xAD, (uint8_t []){0x04}, 1, 0},
|
||||
{0xAE, (uint8_t []){0x00}, 1, 0},
|
||||
{0xAF, (uint8_t []){0x00}, 1, 0},
|
||||
{0xB0, (uint8_t []){0x48}, 1, 0},
|
||||
{0xB1, (uint8_t []){0x00}, 1, 0},
|
||||
{0xB2, (uint8_t []){0x09}, 1, 0},
|
||||
{0xB3, (uint8_t []){0x02}, 1, 0},
|
||||
{0xB4, (uint8_t []){0xD9}, 1, 0},
|
||||
{0xB5, (uint8_t []){0x04}, 1, 0},
|
||||
{0xB6, (uint8_t []){0x00}, 1, 0},
|
||||
{0xB7, (uint8_t []){0x00}, 1, 0},
|
||||
{0xB8, (uint8_t []){0x48}, 1, 0},
|
||||
{0xB9, (uint8_t []){0x00}, 1, 0},
|
||||
{0xBA, (uint8_t []){0x0B}, 1, 0},
|
||||
{0xBB, (uint8_t []){0x02}, 1, 0},
|
||||
{0xBC, (uint8_t []){0xDB}, 1, 0},
|
||||
{0xBD, (uint8_t []){0x04}, 1, 0},
|
||||
{0xBE, (uint8_t []){0x00}, 1, 0},
|
||||
{0xBF, (uint8_t []){0x00}, 1, 0},
|
||||
{0xC0, (uint8_t []){0x10}, 1, 0},
|
||||
{0xC1, (uint8_t []){0x47}, 1, 0},
|
||||
{0xC2, (uint8_t []){0x56}, 1, 0},
|
||||
{0xC3, (uint8_t []){0x65}, 1, 0},
|
||||
{0xC4, (uint8_t []){0x74}, 1, 0},
|
||||
{0xC5, (uint8_t []){0x88}, 1, 0},
|
||||
{0xC6, (uint8_t []){0x99}, 1, 0},
|
||||
{0xC7, (uint8_t []){0x01}, 1, 0},
|
||||
{0xC8, (uint8_t []){0xBB}, 1, 0},
|
||||
{0xC9, (uint8_t []){0xAA}, 1, 0},
|
||||
{0xD0, (uint8_t []){0x10}, 1, 0},
|
||||
{0xD1, (uint8_t []){0x47}, 1, 0},
|
||||
{0xD2, (uint8_t []){0x56}, 1, 0},
|
||||
{0xD3, (uint8_t []){0x65}, 1, 0},
|
||||
{0xD4, (uint8_t []){0x74}, 1, 0},
|
||||
{0xD5, (uint8_t []){0x88}, 1, 0},
|
||||
{0xD6, (uint8_t []){0x99}, 1, 0},
|
||||
{0xD7, (uint8_t []){0x01}, 1, 0},
|
||||
{0xD8, (uint8_t []){0xBB}, 1, 0},
|
||||
{0xD9, (uint8_t []){0xAA}, 1, 0},
|
||||
{0xF3, (uint8_t []){0x01}, 1, 0},
|
||||
{0xF0, (uint8_t []){0x00}, 1, 0},
|
||||
{0x21, (uint8_t []){}, 0, 0},
|
||||
{0x11, (uint8_t []){}, 0, 0},
|
||||
{0x00, (uint8_t []){}, 0, 120},
|
||||
};
|
||||
|
||||
esp_err_t hw_lcd_init(esp_lcd_panel_handle_t *panel_handle, esp_lcd_panel_io_handle_t *io_handle, esp_lv_adapter_tear_avoid_mode_t tear_avoid_mode, esp_lv_adapter_rotation_t rotation)
|
||||
{
|
||||
ESP_LOGD(TAG, "Initialize QSPI bus");
|
||||
const spi_bus_config_t buscfg = {
|
||||
.sclk_io_num = HW_LCD_PCLK,
|
||||
.data0_io_num = HW_LCD_DATA0,
|
||||
.data1_io_num = HW_LCD_DATA1,
|
||||
.data2_io_num = HW_LCD_DATA2,
|
||||
.data3_io_num = HW_LCD_DATA3,
|
||||
.max_transfer_sz = HW_LCD_MAX_TRANSFER_SZ,
|
||||
.flags = SPICOMMON_BUSFLAG_QUAD,
|
||||
};
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||
|
||||
ESP_LOGD(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_spi_config_t io_config = {
|
||||
.dc_gpio_num = HW_LCD_DC,
|
||||
.cs_gpio_num = HW_LCD_CS,
|
||||
.pclk_hz = HW_LCD_PIXEL_CLOCK_HZ,
|
||||
.lcd_cmd_bits = HW_LCD_CMD_BITS,
|
||||
.lcd_param_bits = HW_LCD_PARAM_BITS,
|
||||
.spi_mode = 0,
|
||||
.trans_queue_depth = 1,
|
||||
.flags = {
|
||||
.quad_mode = 1,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)SPI2_HOST, &io_config, &s_panel_io_handle));
|
||||
|
||||
ESP_LOGD(TAG, "Power on LCD");
|
||||
gpio_config_t power_gpio_config = {
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pin_bit_mask = 1ULL << HW_LCD_POWER_OFF
|
||||
};
|
||||
ESP_ERROR_CHECK(gpio_config(&power_gpio_config));
|
||||
gpio_set_level(HW_LCD_POWER_OFF, 0);
|
||||
|
||||
ESP_LOGD(TAG, "Install LCD driver");
|
||||
const st77916_vendor_config_t vendor_config = {
|
||||
.init_cmds = st77916_qspi_init,
|
||||
.init_cmds_size = sizeof(st77916_qspi_init) / sizeof(st77916_lcd_init_cmd_t),
|
||||
.flags = {
|
||||
.use_qspi_interface = 1,
|
||||
},
|
||||
};
|
||||
esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = HW_LCD_RST,
|
||||
.rgb_ele_order = HW_LCD_COLOR_SPACE,
|
||||
.bits_per_pixel = HW_LCD_BITS_PER_PIXEL,
|
||||
.vendor_config = (void *) &vendor_config,
|
||||
.flags = {
|
||||
.reset_active_high = true,
|
||||
},
|
||||
};
|
||||
|
||||
ESP_LOGI(TAG, "Install st77916 panel driver");
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_st77916(s_panel_io_handle, (const esp_lcd_panel_dev_config_t *)&panel_config, &s_panel_handle));
|
||||
|
||||
esp_lcd_panel_reset(s_panel_handle);
|
||||
esp_lcd_panel_init(s_panel_handle);
|
||||
|
||||
bool swap_xy = false;
|
||||
bool mirror_x = false;
|
||||
bool mirror_y = false;
|
||||
lcd_get_orientation_flags(HW_LCD_BASE_SWAP_XY, HW_LCD_BASE_MIRROR_X, HW_LCD_BASE_MIRROR_Y,
|
||||
rotation, &swap_xy, &mirror_x, &mirror_y);
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(s_panel_handle, swap_xy));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_mirror(s_panel_handle, mirror_x, mirror_y));
|
||||
esp_lcd_panel_disp_on_off(s_panel_handle, true);
|
||||
|
||||
*io_handle = s_panel_io_handle;
|
||||
*panel_handle = s_panel_handle;
|
||||
|
||||
gpio_config_t bk_gpio_config = {
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pin_bit_mask = 1ULL << HW_PIN_NUM_BK_LIGHT
|
||||
};
|
||||
ESP_ERROR_CHECK(gpio_config(&bk_gpio_config));
|
||||
ESP_LOGI(TAG, "Turning on LCD backlight");
|
||||
gpio_set_level(HW_PIN_NUM_BK_LIGHT, HW_LCD_BK_LIGHT_ON_LEVEL);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: CC0-1.0
|
||||
*/
|
||||
|
||||
#include "hw_init.h"
|
||||
|
||||
#if CONFIG_EXAMPLE_LCD_INTERFACE_RGB
|
||||
|
||||
#include "esp_lcd_panel_rgb.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
static const char *TAG = "hw_lcd_init";
|
||||
|
||||
#define HW_LCD_PIXEL_CLOCK_HZ (18 * 1000 * 1000)
|
||||
#define HW_LCD_HSYNC (40)
|
||||
#define HW_LCD_HBP (40)
|
||||
#define HW_LCD_HFP (48)
|
||||
#define HW_LCD_VSYNC (23)
|
||||
#define HW_LCD_VBP (32)
|
||||
#define HW_LCD_VFP (13)
|
||||
|
||||
#define HW_LCD_RGB_VSYNC (GPIO_NUM_3)
|
||||
#define HW_LCD_RGB_HSYNC (GPIO_NUM_46)
|
||||
#define HW_LCD_RGB_DE (GPIO_NUM_17)
|
||||
#define HW_LCD_RGB_PCLK (GPIO_NUM_9)
|
||||
#define HW_LCD_RGB_DISP (GPIO_NUM_NC)
|
||||
#define HW_LCD_RGB_DATA0 (GPIO_NUM_10)
|
||||
#define HW_LCD_RGB_DATA1 (GPIO_NUM_11)
|
||||
#define HW_LCD_RGB_DATA2 (GPIO_NUM_12)
|
||||
#define HW_LCD_RGB_DATA3 (GPIO_NUM_13)
|
||||
#define HW_LCD_RGB_DATA4 (GPIO_NUM_14)
|
||||
#define HW_LCD_RGB_DATA5 (GPIO_NUM_21)
|
||||
#define HW_LCD_RGB_DATA6 (GPIO_NUM_8)
|
||||
#define HW_LCD_RGB_DATA7 (GPIO_NUM_18)
|
||||
#define HW_LCD_RGB_DATA8 (GPIO_NUM_45)
|
||||
#define HW_LCD_RGB_DATA9 (GPIO_NUM_38)
|
||||
#define HW_LCD_RGB_DATA10 (GPIO_NUM_39)
|
||||
#define HW_LCD_RGB_DATA11 (GPIO_NUM_40)
|
||||
#define HW_LCD_RGB_DATA12 (GPIO_NUM_41)
|
||||
#define HW_LCD_RGB_DATA13 (GPIO_NUM_42)
|
||||
#define HW_LCD_RGB_DATA14 (GPIO_NUM_2)
|
||||
#define HW_LCD_RGB_DATA15 (GPIO_NUM_1)
|
||||
|
||||
#define HW_LCD_DATA_WIDTH (16)
|
||||
#define HW_LCD_BIT_PER_PIXEL (16)
|
||||
#define HW_LCD_BOUNCE_BUFFER_HEIGHT (20)
|
||||
|
||||
static esp_lcd_panel_handle_t s_panel_handle;
|
||||
|
||||
esp_err_t hw_lcd_init(esp_lcd_panel_handle_t *panel_handle, esp_lcd_panel_io_handle_t *io_handle, esp_lv_adapter_tear_avoid_mode_t tear_avoid_mode, esp_lv_adapter_rotation_t rotation)
|
||||
{
|
||||
ESP_LOGI(TAG, "Initialize RGB panel");
|
||||
esp_lcd_rgb_panel_config_t panel_conf = {
|
||||
.clk_src = LCD_CLK_SRC_DEFAULT,
|
||||
.dma_burst_size = 64,
|
||||
.data_width = HW_LCD_DATA_WIDTH,
|
||||
.bits_per_pixel = HW_LCD_BIT_PER_PIXEL,
|
||||
.de_gpio_num = HW_LCD_RGB_DE,
|
||||
.pclk_gpio_num = HW_LCD_RGB_PCLK,
|
||||
.vsync_gpio_num = HW_LCD_RGB_VSYNC,
|
||||
.hsync_gpio_num = HW_LCD_RGB_HSYNC,
|
||||
.disp_gpio_num = HW_LCD_RGB_DISP,
|
||||
.data_gpio_nums = {
|
||||
HW_LCD_RGB_DATA0,
|
||||
HW_LCD_RGB_DATA1,
|
||||
HW_LCD_RGB_DATA2,
|
||||
HW_LCD_RGB_DATA3,
|
||||
HW_LCD_RGB_DATA4,
|
||||
HW_LCD_RGB_DATA5,
|
||||
HW_LCD_RGB_DATA6,
|
||||
HW_LCD_RGB_DATA7,
|
||||
HW_LCD_RGB_DATA8,
|
||||
HW_LCD_RGB_DATA9,
|
||||
HW_LCD_RGB_DATA10,
|
||||
HW_LCD_RGB_DATA11,
|
||||
HW_LCD_RGB_DATA12,
|
||||
HW_LCD_RGB_DATA13,
|
||||
HW_LCD_RGB_DATA14,
|
||||
HW_LCD_RGB_DATA15,
|
||||
},
|
||||
.timings = {
|
||||
.pclk_hz = HW_LCD_PIXEL_CLOCK_HZ,
|
||||
.h_res = HW_LCD_H_RES,
|
||||
.v_res = HW_LCD_V_RES,
|
||||
.hsync_back_porch = HW_LCD_HBP,
|
||||
.hsync_front_porch = HW_LCD_HFP,
|
||||
.hsync_pulse_width = HW_LCD_HSYNC,
|
||||
.vsync_back_porch = HW_LCD_VBP,
|
||||
.vsync_front_porch = HW_LCD_VFP,
|
||||
.vsync_pulse_width = HW_LCD_VSYNC,
|
||||
.flags = {
|
||||
.pclk_active_neg = true,
|
||||
},
|
||||
},
|
||||
.flags.fb_in_psram = 1,
|
||||
.num_fbs = esp_lv_adapter_get_required_frame_buffer_count(tear_avoid_mode, rotation),
|
||||
.bounce_buffer_size_px = HW_LCD_H_RES * HW_LCD_BOUNCE_BUFFER_HEIGHT,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_lcd_new_rgb_panel(&panel_conf, &s_panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_reset(s_panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_init(s_panel_handle));
|
||||
|
||||
*panel_handle = s_panel_handle;
|
||||
if (io_handle) {
|
||||
*io_handle = NULL;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: CC0-1.0
|
||||
*/
|
||||
|
||||
#include "esp_system.h"
|
||||
#include "esp_lcd_ili9341.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "hw_init.h"
|
||||
#include "helpers/lcd_orientation_helper.h"
|
||||
|
||||
#if CONFIG_EXAMPLE_LCD_INTERFACE_SPI_WITH_PSRAM
|
||||
|
||||
static const char *TAG = "hw_lcd_init";
|
||||
|
||||
#define HW_PIN_NUM_BK_LIGHT (GPIO_NUM_47)
|
||||
#define HW_LCD_BK_LIGHT_ON_LEVEL (1)
|
||||
#define HW_LCD_BASE_SWAP_XY (false)
|
||||
#define HW_LCD_BASE_MIRROR_X (true)
|
||||
#define HW_LCD_BASE_MIRROR_Y (true)
|
||||
|
||||
#define HW_LCD_DATA0 (GPIO_NUM_6)
|
||||
#define HW_LCD_PCLK (GPIO_NUM_7)
|
||||
#define HW_LCD_CS (GPIO_NUM_5)
|
||||
#define HW_LCD_DC (GPIO_NUM_4)
|
||||
#define HW_LCD_RST (GPIO_NUM_48)
|
||||
|
||||
#define HW_LCD_PIXEL_CLOCK_HZ (40 * 1000 * 1000)
|
||||
#define HW_LCD_COLOR_SPACE (LCD_RGB_ELEMENT_ORDER_RGB)
|
||||
#define HW_LCD_BITS_PER_PIXEL (16)
|
||||
#define HW_LCD_CMD_BITS (8)
|
||||
#define HW_LCD_PARAM_BITS (8)
|
||||
#define HW_LCD_MAX_TRANSFER_SZ (HW_LCD_H_RES * HW_LCD_V_RES * 2)
|
||||
|
||||
static esp_lcd_panel_io_handle_t s_panel_io_handle;
|
||||
static esp_lcd_panel_handle_t s_panel_handle;
|
||||
|
||||
static const ili9341_lcd_init_cmd_t vendor_specific_init_default[] = {
|
||||
{0xC8, (uint8_t []){0xFF, 0x93, 0x42}, 3, 0},
|
||||
{0xC0, (uint8_t []){0x0E, 0x0E}, 2, 0},
|
||||
{0xC5, (uint8_t []){0xD0}, 1, 0},
|
||||
{0xC1, (uint8_t []){0x02}, 1, 0},
|
||||
{0xB4, (uint8_t []){0x02}, 1, 0},
|
||||
{0xE0, (uint8_t []){0x00, 0x03, 0x08, 0x06, 0x13, 0x09, 0x39, 0x39, 0x48, 0x02, 0x0a, 0x08, 0x17, 0x17, 0x0F}, 15, 0},
|
||||
{0xE1, (uint8_t []){0x00, 0x28, 0x29, 0x01, 0x0d, 0x03, 0x3f, 0x33, 0x52, 0x04, 0x0f, 0x0e, 0x37, 0x38, 0x0F}, 15, 0},
|
||||
{0xB1, (uint8_t []){00, 0x1B}, 2, 0},
|
||||
{0x36, (uint8_t []){0x08}, 1, 0},
|
||||
{0x3A, (uint8_t []){0x55}, 1, 0},
|
||||
{0xB7, (uint8_t []){0x06}, 1, 0},
|
||||
{0x11, (uint8_t []){0}, 0x80, 0},
|
||||
{0x29, (uint8_t []){0}, 0x80, 0},
|
||||
{0, (uint8_t []){0}, 0xff, 0},
|
||||
};
|
||||
|
||||
esp_err_t hw_lcd_init(esp_lcd_panel_handle_t *panel_handle, esp_lcd_panel_io_handle_t *io_handle, esp_lv_adapter_tear_avoid_mode_t tear_avoid_mode, esp_lv_adapter_rotation_t rotation)
|
||||
{
|
||||
ESP_LOGD(TAG, "Initialize SPI bus");
|
||||
const spi_bus_config_t buscfg = {
|
||||
.sclk_io_num = HW_LCD_PCLK,
|
||||
.mosi_io_num = HW_LCD_DATA0,
|
||||
.miso_io_num = GPIO_NUM_NC,
|
||||
.quadwp_io_num = GPIO_NUM_NC,
|
||||
.quadhd_io_num = GPIO_NUM_NC,
|
||||
.max_transfer_sz = HW_LCD_MAX_TRANSFER_SZ,
|
||||
};
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||
|
||||
ESP_LOGD(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_spi_config_t io_config = {
|
||||
.dc_gpio_num = HW_LCD_DC,
|
||||
.cs_gpio_num = HW_LCD_CS,
|
||||
.pclk_hz = HW_LCD_PIXEL_CLOCK_HZ,
|
||||
.lcd_cmd_bits = HW_LCD_CMD_BITS,
|
||||
.lcd_param_bits = HW_LCD_PARAM_BITS,
|
||||
.spi_mode = 0,
|
||||
.trans_queue_depth = 1,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)SPI2_HOST, &io_config, &s_panel_io_handle));
|
||||
|
||||
ESP_LOGD(TAG, "Install LCD driver");
|
||||
const ili9341_vendor_config_t vendor_config = {
|
||||
.init_cmds = vendor_specific_init_default,
|
||||
.init_cmds_size = sizeof(vendor_specific_init_default) / sizeof(vendor_specific_init_default[0]),
|
||||
};
|
||||
esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = HW_LCD_RST,
|
||||
.flags.reset_active_high = true,
|
||||
.rgb_ele_order = HW_LCD_COLOR_SPACE,
|
||||
.bits_per_pixel = HW_LCD_BITS_PER_PIXEL,
|
||||
.vendor_config = (void *) &vendor_config,
|
||||
};
|
||||
|
||||
ESP_LOGI(TAG, "Install ili9341 panel driver");
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_ili9341(s_panel_io_handle, (const esp_lcd_panel_dev_config_t *)&panel_config, &s_panel_handle));
|
||||
|
||||
esp_lcd_panel_reset(s_panel_handle);
|
||||
esp_lcd_panel_init(s_panel_handle);
|
||||
|
||||
bool swap_xy = false;
|
||||
bool mirror_x = true;
|
||||
bool mirror_y = true;
|
||||
lcd_get_orientation_flags(HW_LCD_BASE_SWAP_XY, HW_LCD_BASE_MIRROR_X, HW_LCD_BASE_MIRROR_Y,
|
||||
rotation, &swap_xy, &mirror_x, &mirror_y);
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(s_panel_handle, swap_xy));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_mirror(s_panel_handle, mirror_x, mirror_y));
|
||||
esp_lcd_panel_disp_on_off(s_panel_handle, true);
|
||||
|
||||
*io_handle = s_panel_io_handle;
|
||||
*panel_handle = s_panel_handle;
|
||||
|
||||
gpio_config_t bk_gpio_config = {
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pin_bit_mask = 1ULL << HW_PIN_NUM_BK_LIGHT
|
||||
};
|
||||
ESP_ERROR_CHECK(gpio_config(&bk_gpio_config));
|
||||
ESP_LOGI(TAG, "Turning on LCD backlight");
|
||||
gpio_set_level(HW_PIN_NUM_BK_LIGHT, HW_LCD_BK_LIGHT_ON_LEVEL);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: CC0-1.0
|
||||
*/
|
||||
|
||||
#include "esp_system.h"
|
||||
#include "esp_lcd_gc9a01.h"
|
||||
#include "hw_init.h"
|
||||
#include "helpers/lcd_orientation_helper.h"
|
||||
|
||||
#if CONFIG_EXAMPLE_LCD_INTERFACE_SPI_WITHOUT_PSRAM
|
||||
|
||||
static const char *TAG = "hw_lcd_init";
|
||||
|
||||
#define HW_LCD_BASE_SWAP_XY (false)
|
||||
#define HW_LCD_BASE_MIRROR_X (true)
|
||||
#define HW_LCD_BASE_MIRROR_Y (false)
|
||||
|
||||
#define HW_LCD_DATA0 (GPIO_NUM_0)
|
||||
#define HW_LCD_PCLK (GPIO_NUM_1)
|
||||
#define HW_LCD_CS (GPIO_NUM_7)
|
||||
#define HW_LCD_DC (GPIO_NUM_2)
|
||||
#define HW_LCD_RST (GPIO_NUM_NC)
|
||||
|
||||
#define HW_LCD_PIXEL_CLOCK_HZ (80 * 1000 * 1000)
|
||||
#define HW_LCD_COLOR_SPACE (LCD_RGB_ELEMENT_ORDER_BGR)
|
||||
#define HW_LCD_BITS_PER_PIXEL (16)
|
||||
#define HW_LCD_CMD_BITS (8)
|
||||
#define HW_LCD_PARAM_BITS (8)
|
||||
#define HW_LCD_MAX_TRANSFER_SZ (HW_LCD_H_RES * 80 * 2)
|
||||
|
||||
static esp_lcd_panel_io_handle_t s_panel_io_handle;
|
||||
static esp_lcd_panel_handle_t s_panel_handle;
|
||||
|
||||
esp_err_t hw_lcd_init(esp_lcd_panel_handle_t *panel_handle, esp_lcd_panel_io_handle_t *io_handle, esp_lv_adapter_tear_avoid_mode_t tear_avoid_mode, esp_lv_adapter_rotation_t rotation)
|
||||
{
|
||||
ESP_LOGD(TAG, "Initialize SPI bus");
|
||||
const spi_bus_config_t buscfg = {
|
||||
.sclk_io_num = HW_LCD_PCLK,
|
||||
.mosi_io_num = HW_LCD_DATA0,
|
||||
.miso_io_num = GPIO_NUM_NC,
|
||||
.quadwp_io_num = GPIO_NUM_NC,
|
||||
.quadhd_io_num = GPIO_NUM_NC,
|
||||
.max_transfer_sz = HW_LCD_MAX_TRANSFER_SZ,
|
||||
};
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||
|
||||
ESP_LOGD(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_spi_config_t io_config = {
|
||||
.dc_gpio_num = HW_LCD_DC,
|
||||
.cs_gpio_num = HW_LCD_CS,
|
||||
.pclk_hz = HW_LCD_PIXEL_CLOCK_HZ,
|
||||
.lcd_cmd_bits = HW_LCD_CMD_BITS,
|
||||
.lcd_param_bits = HW_LCD_PARAM_BITS,
|
||||
.spi_mode = 0,
|
||||
.trans_queue_depth = 10,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)SPI2_HOST, &io_config, &s_panel_io_handle));
|
||||
|
||||
ESP_LOGD(TAG, "Install LCD driver");
|
||||
esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = HW_LCD_RST,
|
||||
.rgb_ele_order = HW_LCD_COLOR_SPACE,
|
||||
.bits_per_pixel = HW_LCD_BITS_PER_PIXEL,
|
||||
};
|
||||
|
||||
ESP_LOGI(TAG, "Install gc9a01 panel driver");
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_gc9a01(s_panel_io_handle, &panel_config, &s_panel_handle));
|
||||
|
||||
esp_lcd_panel_reset(s_panel_handle);
|
||||
esp_lcd_panel_init(s_panel_handle);
|
||||
|
||||
bool swap_xy = false;
|
||||
bool mirror_x = true;
|
||||
bool mirror_y = false;
|
||||
lcd_get_orientation_flags(HW_LCD_BASE_SWAP_XY, HW_LCD_BASE_MIRROR_X, HW_LCD_BASE_MIRROR_Y,
|
||||
rotation, &swap_xy, &mirror_x, &mirror_y);
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(s_panel_handle, swap_xy));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_mirror(s_panel_handle, mirror_x, mirror_y));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_invert_color(s_panel_handle, true));
|
||||
esp_lcd_panel_disp_on_off(s_panel_handle, true);
|
||||
|
||||
*io_handle = s_panel_io_handle;
|
||||
*panel_handle = s_panel_handle;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user