ESP32S3+ILI9225+8位并口220*176分辨率运行LVGL例程

2024-01-03 10:51:10

LVGL测试1

?一、前言

? ? ? ? 屏幕ILI9225,实际可能是ST7775,两者兼容,指令一样。

? ? ? ? 支持8位或16并口。

? ? ? ? 分辨率:220*176,RGB565

二、源码

main.c

#include <stdio.h>
#include "lvgl_gui.h"

void app_main(void)
{
    xTaskCreatePinnedToCore(guiTask, "guiTask", 1024 * 6, NULL, 5, NULL, 1);
}

lvgl_gui.h

#pragma once

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "freertos/semphr.h"
#include "esp_timer.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_vendor.h"
#include "esp_lcd_panel_ops.h"
#include "driver/gpio.h"
#include "esp_err.h"
#include "esp_log.h"
#include "lvgl.h"
#include "driver/ledc.h"


#include "demos/lv_demos.h"

// PCLK frequency can't go too high as the limitation of PSRAM bandwidth
#define LCD_PIXEL_CLOCK_HZ (20 * 1000 * 1000)

#define LCD_BK_LIGHT_ON_LEVEL 1
#define LCD_BK_LIGHT_OFF_LEVEL !LCD_BK_LIGHT_ON_LEVEL

#define PIN_NUM_DATA0 13
#define PIN_NUM_DATA1 14
#define PIN_NUM_DATA2 21
#define PIN_NUM_DATA3 47
#define PIN_NUM_DATA4 48
#define PIN_NUM_DATA5 45
#define PIN_NUM_DATA6 8
#define PIN_NUM_DATA7 7

#define PIN_NUM_PCLK 4
#define PIN_NUM_RD 3
#define PIN_NUM_CS 6
#define PIN_NUM_DC 5
#define PIN_NUM_RST 2
#define PIN_NUM_BK_LIGHT 1

// The pixel number in horizontal and vertical
#define LCD_H_RES 176
#define LCD_V_RES 220
// Bit number used to represent command and parameter
#define LCD_CMD_BITS 8
#define LCD_PARAM_BITS 8

#define LVGL_TICK_PERIOD_MS 2

// Supported alignment: 16, 32, 64. A higher alignment can enables higher burst transfer size, thus a higher i80 bus throughput.
#define PSRAM_DATA_ALIGNMENT 64

void guiTask(void *pvParameter);

lvgl_gui.c

#include "lvgl_gui.h"

static const char *TAG = "lvgl_gui";

extern EventGroupHandle_t s_gui_event_group;
SemaphoreHandle_t xGuiSemaphore;

static lv_img_dsc_t IMG1 = {
    .header.cf = LV_IMG_CF_RAW,
    .header.always_zero = 0,
    .header.reserved = 0,
    .header.w = 0,
    .header.h = 0,
    .data_size = 0,
    .data = NULL,
};

extern esp_err_t esp_lcd_new_panel_ili9225(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config, esp_lcd_panel_handle_t *ret_panel);

static bool notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx)
{
    lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx;
    lv_disp_flush_ready(disp_driver);
    return false;
}

static void lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map)
{
    esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)drv->user_data;
    int offsetx1 = area->x1;
    int offsetx2 = area->x2;
    int offsety1 = area->y1;
    int offsety2 = area->y2;
    // copy a buffer's content to a specific area of the display
    esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_map);
    lv_disp_flush_ready(drv);
}

static void increase_lvgl_tick(void *arg)
{
    /* Tell LVGL how many milliseconds has elapsed */
    lv_tick_inc(LVGL_TICK_PERIOD_MS);
}

static void backlight_ledc_init(void)
{
    // Prepare and then apply the LEDC PWM timer configuration
    ledc_timer_config_t ledc_timer = {
        .speed_mode = LEDC_LOW_SPEED_MODE,
        .timer_num = LEDC_TIMER_0,
        .duty_resolution = LEDC_TIMER_13_BIT,
        .freq_hz = 5000, // Set output frequency at 5 kHz
        .clk_cfg = LEDC_AUTO_CLK};
    ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));

    // Prepare and then apply the LEDC PWM channel configuration
    ledc_channel_config_t ledc_channel = {
        .speed_mode = LEDC_LOW_SPEED_MODE,
        .channel = LEDC_CHANNEL_0,
        .timer_sel = LEDC_TIMER_0,
        .intr_type = LEDC_INTR_DISABLE,
        .gpio_num = PIN_NUM_BK_LIGHT,
        .duty = 0, // Set duty to 0%
        .hpoint = 0};
    ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
}

void guiTask(void *pvParameter)
{
    xGuiSemaphore = xSemaphoreCreateMutex();
    static lv_disp_draw_buf_t disp_buf; // contains internal graphic buffer(s) called draw buffer(s)
    static lv_disp_drv_t disp_drv;      // contains callback functions

    ESP_LOGI(TAG, "Turn off LCD backlight");
    // gpio_set_direction(PIN_NUM_BK_LIGHT, GPIO_MODE_OUTPUT);
    // gpio_set_level(PIN_NUM_BK_LIGHT, LCD_BK_LIGHT_OFF_LEVEL);
    gpio_set_direction(PIN_NUM_RD, GPIO_MODE_OUTPUT);
    gpio_set_level(PIN_NUM_RD, 1);

    backlight_ledc_init();

    ESP_LOGI(TAG, "Initialize Intel 8080 bus");
    esp_lcd_i80_bus_handle_t i80_bus = NULL;
    esp_lcd_i80_bus_config_t bus_config = {
        .clk_src = LCD_CLK_SRC_DEFAULT,
        .dc_gpio_num = PIN_NUM_DC,
        .wr_gpio_num = PIN_NUM_PCLK,
        .data_gpio_nums = {
            PIN_NUM_DATA0,
            PIN_NUM_DATA1,
            PIN_NUM_DATA2,
            PIN_NUM_DATA3,
            PIN_NUM_DATA4,
            PIN_NUM_DATA5,
            PIN_NUM_DATA6,
            PIN_NUM_DATA7,
        },
        .bus_width = 8,
        .max_transfer_bytes = LCD_V_RES * 220 * sizeof(uint16_t),
        .psram_trans_align = PSRAM_DATA_ALIGNMENT,
        .sram_trans_align = 4,
    };
    ESP_ERROR_CHECK(esp_lcd_new_i80_bus(&bus_config, &i80_bus));
    esp_lcd_panel_io_handle_t io_handle = NULL;
    esp_lcd_panel_io_i80_config_t io_config = {
        .cs_gpio_num = PIN_NUM_CS,
        .pclk_hz = LCD_PIXEL_CLOCK_HZ,
        .trans_queue_depth = 10,
        .dc_levels = {
            .dc_idle_level = 0,
            .dc_cmd_level = 0,
            .dc_dummy_level = 0,
            .dc_data_level = 1,
        },
        .on_color_trans_done = notify_lvgl_flush_ready,
        .user_ctx = &disp_drv,
        .lcd_cmd_bits = LCD_CMD_BITS,
        .lcd_param_bits = LCD_PARAM_BITS,
        .flags.swap_color_bytes = true,
    };
    ESP_ERROR_CHECK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));

    esp_lcd_panel_handle_t panel_handle = NULL;

    ESP_LOGI(TAG, "Install LCD driver of ili9225");
    esp_lcd_panel_dev_config_t panel_config = {
        .reset_gpio_num = PIN_NUM_RST,
        .color_space = ESP_LCD_COLOR_SPACE_RGB,
        .bits_per_pixel = 16,
    };
    ESP_ERROR_CHECK(esp_lcd_new_panel_ili9225(io_handle, &panel_config, &panel_handle));

    esp_lcd_panel_reset(panel_handle);
    esp_lcd_panel_init(panel_handle);

    // Set inversion, x/y coordinate order, x/y mirror according to your LCD module spec
    // esp_lcd_panel_invert_color(panel_handle, false);
    esp_lcd_panel_swap_xy(panel_handle, true);
    esp_lcd_panel_mirror(panel_handle, true, false);

    // the gap is LCD panel specific, even panels with the same driver IC, can have different gap value
    // esp_lcd_panel_set_gap(panel_handle, 0, 20);

    // user can flush pre-defined pattern to the screen before we turn on the screen or backlight
    ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));

    ESP_LOGI(TAG, "Initialize LVGL library");
    lv_init();
    // alloc draw buffers used by LVGL
    // it's recommended to choose the size of the draw buffer(s) to be at least 1/10 screen sized
    lv_color_t *buf1 = NULL;
    lv_color_t *buf2 = NULL;
    // buf1 = heap_caps_aligned_alloc(PSRAM_DATA_ALIGNMENT, LCD_H_RES * 480 * sizeof(lv_color_t), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
    // buf2 = heap_caps_aligned_alloc(PSRAM_DATA_ALIGNMENT, LCD_H_RES * 480 * sizeof(lv_color_t), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);

    buf1 = heap_caps_malloc(LCD_V_RES * 50 * sizeof(lv_color_t), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
    buf2 = heap_caps_malloc(LCD_V_RES * 50 * sizeof(lv_color_t), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);

    assert(buf1);
    assert(buf2);
    ESP_LOGI(TAG, "buf1@%p, buf2@%p", buf1, buf2);
    // initialize LVGL draw buffers
    lv_disp_draw_buf_init(&disp_buf, buf1, buf2, LCD_V_RES * 50);

    ESP_LOGI(TAG, "Register display driver to LVGL");
    lv_disp_drv_init(&disp_drv);
    disp_drv.hor_res = LCD_H_RES;
    disp_drv.ver_res = LCD_V_RES;
    disp_drv.flush_cb = lvgl_flush_cb;
    disp_drv.draw_buf = &disp_buf;
    disp_drv.user_data = panel_handle;
    // lv_disp_t *disp = lv_disp_drv_register(&disp_drv);
    lv_disp_drv_register(&disp_drv);

    ESP_LOGI(TAG, "Install LVGL tick timer");
    // Tick interface for LVGL (using esp_timer to generate 2ms periodic event)
    const esp_timer_create_args_t lvgl_tick_timer_args = {
        .callback = &increase_lvgl_tick,
        .name = "lvgl_tick"};
    esp_timer_handle_t lvgl_tick_timer = NULL;
    ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer));
    ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer, LVGL_TICK_PERIOD_MS * 1000));

    ESP_LOGI(TAG, "Turn on LCD backlight");
    // gpio_set_level(PIN_NUM_BK_LIGHT, LCD_BK_LIGHT_ON_LEVEL);
    ESP_ERROR_CHECK(ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 8191));
    // Update duty to apply the new value
    ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0));


    lv_demo_benchmark_set_max_speed(true);
    lv_demo_benchmark();

    ESP_LOGI(TAG, "Display LVGL animation");



    while (1)
    {
        vTaskDelay(pdMS_TO_TICKS(10));
        if (pdTRUE == xSemaphoreTake(xGuiSemaphore, portMAX_DELAY))
        {
            lv_timer_handler();
            xSemaphoreGive(xGuiSemaphore);
        }
    }
    free(buf1);
    free(buf2);
    vTaskDelete(NULL);
}

esp_lcd_panel_ili9225.c

/*
 * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdlib.h>
#include <sys/cdefs.h>
#include "sdkconfig.h"


#if CONFIG_LCD_ENABLE_DEBUG_LOG
// The local log level must be defined before including esp_log.h
// Set the maximum log level for this source file
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
#endif
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_lcd_panel_interface.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_vendor.h"
#include "esp_lcd_panel_ops.h"
#include "esp_lcd_panel_commands.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "esp_check.h"
#include "esp_log.h"

static const char *TAG = "lcd_panel.ili9225";

static esp_err_t panel_ili9225_del(esp_lcd_panel_t *panel);
static esp_err_t panel_ili9225_reset(esp_lcd_panel_t *panel);
static esp_err_t panel_ili9225_init(esp_lcd_panel_t *panel);
static esp_err_t panel_ili9225_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, int x_end, int y_end, const void *color_data);
static esp_err_t panel_ili9225_invert_color(esp_lcd_panel_t *panel, bool invert_color_data);
static esp_err_t panel_ili9225_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y);
static esp_err_t panel_ili9225_swap_xy(esp_lcd_panel_t *panel, bool swap_axes);
static esp_err_t panel_ili9225_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap);
static esp_err_t panel_ili9225_disp_on_off(esp_lcd_panel_t *panel, bool off);

typedef struct
{
    esp_lcd_panel_t base;
    esp_lcd_panel_io_handle_t io;
    int reset_gpio_num;
    bool reset_level;
    int x_gap;
    int y_gap;
    unsigned int bits_per_pixel;
    uint8_t madctl_val; // save current value of LCD_CMD_MADCTL register
    uint8_t colmod_cal; // save surrent value of LCD_CMD_COLMOD register
} ili9225_panel_t;

esp_err_t esp_lcd_new_panel_ili9225(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config, esp_lcd_panel_handle_t *ret_panel)
{
#if CONFIG_LCD_ENABLE_DEBUG_LOG
    esp_log_level_set(TAG, ESP_LOG_DEBUG);
#endif
    esp_err_t ret = ESP_OK;
    ili9225_panel_t *ili9225 = NULL;
    ESP_GOTO_ON_FALSE(io && panel_dev_config && ret_panel, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument");
    ili9225 = calloc(1, sizeof(ili9225_panel_t));
    ESP_GOTO_ON_FALSE(ili9225, ESP_ERR_NO_MEM, err, TAG, "no mem for ili9225 panel");

    if (panel_dev_config->reset_gpio_num >= 0)
    {
        gpio_config_t io_conf = {
            .mode = GPIO_MODE_OUTPUT,
            .pin_bit_mask = 1ULL << panel_dev_config->reset_gpio_num,
        };
        ESP_GOTO_ON_ERROR(gpio_config(&io_conf), err, TAG, "configure GPIO for RST line failed");
    }

    switch (panel_dev_config->color_space)
    {
    case ESP_LCD_COLOR_SPACE_RGB:
        ili9225->madctl_val = 0;
        break;
    case ESP_LCD_COLOR_SPACE_BGR:
        ili9225->madctl_val |= LCD_CMD_BGR_BIT;
        break;
    default:
        ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported color space");
        break;
    }

    switch (panel_dev_config->bits_per_pixel)
    {
    case 16:
        ili9225->colmod_cal = 0x55;
        break;
    case 18:
        ili9225->colmod_cal = 0x66;
        break;
    default:
        ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported pixel width");
        break;
    }

    ili9225->io = io;
    ili9225->bits_per_pixel = panel_dev_config->bits_per_pixel;
    ili9225->reset_gpio_num = panel_dev_config->reset_gpio_num;
    ili9225->reset_level = panel_dev_config->flags.reset_active_high;
    ili9225->base.del = panel_ili9225_del;
    ili9225->base.reset = panel_ili9225_reset;
    ili9225->base.init = panel_ili9225_init;
    ili9225->base.draw_bitmap = panel_ili9225_draw_bitmap;
    ili9225->base.invert_color = panel_ili9225_invert_color;
    ili9225->base.set_gap = panel_ili9225_set_gap;
    ili9225->base.mirror = panel_ili9225_mirror;
    ili9225->base.swap_xy = panel_ili9225_swap_xy;
    ili9225->base.disp_on_off = panel_ili9225_disp_on_off;
    *ret_panel = &(ili9225->base);
    ESP_LOGD(TAG, "new ili9225 panel @%p", ili9225);

    return ESP_OK;

err:
    if (ili9225)
    {
        if (panel_dev_config->reset_gpio_num >= 0)
        {
            gpio_reset_pin(panel_dev_config->reset_gpio_num);
        }
        free(ili9225);
    }
    return ret;
}

static esp_err_t panel_ili9225_del(esp_lcd_panel_t *panel)
{
    ili9225_panel_t *ili9225 = __containerof(panel, ili9225_panel_t, base);

    if (ili9225->reset_gpio_num >= 0)
    {
        gpio_reset_pin(ili9225->reset_gpio_num);
    }
    ESP_LOGD(TAG, "del ili9225 panel @%p", ili9225);
    free(ili9225);
    return ESP_OK;
}

static esp_err_t panel_ili9225_reset(esp_lcd_panel_t *panel)
{
    ili9225_panel_t *ili9225 = __containerof(panel, ili9225_panel_t, base);
    esp_lcd_panel_io_handle_t io = ili9225->io;

    // perform hardware reset
    if (ili9225->reset_gpio_num >= 0)
    {
        gpio_set_level(ili9225->reset_gpio_num, ili9225->reset_level);
        vTaskDelay(pdMS_TO_TICKS(10));
        gpio_set_level(ili9225->reset_gpio_num, !ili9225->reset_level);
        vTaskDelay(pdMS_TO_TICKS(10));
    }
    else
    { // perform software reset
        esp_lcd_panel_io_tx_param(io, LCD_CMD_SWRESET, NULL, 0);
        vTaskDelay(pdMS_TO_TICKS(20)); // spec, wait at least 5m before sending new command
    }

    return ESP_OK;
}

static esp_err_t panel_ili9225_init(esp_lcd_panel_t *panel)
{
    ili9225_panel_t *ili9225 = __containerof(panel, ili9225_panel_t, base);
    esp_lcd_panel_io_handle_t io = ili9225->io;
    // Init LCD
    ESP_LOGI("ili9225", "panel_ili9225_init");

    esp_lcd_panel_io_tx_param(io, 0x10, (uint8_t[]) { 0 }, 1); //
    esp_lcd_panel_io_tx_param(io, 0x11, (uint8_t[]) { 0 }, 1); //
	esp_lcd_panel_io_tx_param(io, 0x12, (uint8_t[]) { 0 }, 1); //
	esp_lcd_panel_io_tx_param(io, 0x13, (uint8_t[]) { 0 }, 1); //
	esp_lcd_panel_io_tx_param(io, 0x14, (uint8_t[]) { 0 }, 1); //
	vTaskDelay(40/portTICK_PERIOD_MS);

	esp_lcd_panel_io_tx_param(io, 0x11, (uint8_t[]) { 0x00,0x18 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x12, (uint8_t[]) { 0x61,0x21 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x13, (uint8_t[]) { 0x0,0x06F }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x14, (uint8_t[]) { 0x49,0x5F }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x10, (uint8_t[]) { 0x80,0x00 }, 2); //
	vTaskDelay(10/portTICK_PERIOD_MS);
	esp_lcd_panel_io_tx_param(io, 0x11, (uint8_t[]) { 0x10,0x3b }, 2); //
	vTaskDelay(50/portTICK_PERIOD_MS);

	esp_lcd_panel_io_tx_param(io, 0x01, (uint8_t[]) { 0x02,0x1c }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x02, (uint8_t[]) { 0x01,0x00 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x03, (uint8_t[]) { 0x10,0x30 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x07, (uint8_t[]) { 0x00,0x00 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x08, (uint8_t[]) { 0x08,0x08 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x0b, (uint8_t[]) { 0x11,0x00 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x0c, (uint8_t[]) { 0x00,0x00 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x0f, (uint8_t[]) { 0x0D,0x01 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x15, (uint8_t[]) { 0x00,0x20 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x20, (uint8_t[]) { 0x00,0x00 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x21, (uint8_t[]) { 0x00,0x00 }, 2); //

	esp_lcd_panel_io_tx_param(io, 0x30, (uint8_t[]) { 0x00,0x00 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x31, (uint8_t[]) { 0x00,0xDB }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x32, (uint8_t[]) { 0x00,0x00 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x33, (uint8_t[]) { 0x00,0x00 }, 2); //

	esp_lcd_panel_io_tx_param(io, 0x34, (uint8_t[]) { 0x00,0xDB }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x35, (uint8_t[]) { 0x00,0x00 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x36, (uint8_t[]) { 0x00,0xAF }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x37, (uint8_t[]) { 0x00,0x00 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x38, (uint8_t[]) { 0x00,0xDB }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x39, (uint8_t[]) { 0x00,0x00 }, 2); //

	esp_lcd_panel_io_tx_param(io, 0x50, (uint8_t[]) { 0x00,0x00 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x51, (uint8_t[]) { 0x08,0x08 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x52, (uint8_t[]) { 0x08,0x0A }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x53, (uint8_t[]) { 0x00,0x0A }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x54, (uint8_t[]) { 0x0A,0x08 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x55, (uint8_t[]) { 0x08,0x08 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x56, (uint8_t[]) { 0x00,0x00 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x57, (uint8_t[]) { 0xA0,0x00 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x58, (uint8_t[]) { 0x07,0x10 }, 2); //
	esp_lcd_panel_io_tx_param(io, 0x59, (uint8_t[]) { 0x07,0x10 }, 2); //

	esp_lcd_panel_io_tx_param(io, 0x07, (uint8_t[]) { 0x00,0x12 }, 2); //
	vTaskDelay(50/portTICK_PERIOD_MS);
	esp_lcd_panel_io_tx_param(io, 0x07, (uint8_t[]) { 0x10,0x17 }, 2); //
    esp_lcd_panel_io_tx_param(io, 0x22, NULL , 0); //

 
    return ESP_OK;
}

static esp_err_t panel_ili9225_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, int x_end, int y_end, const void *color_data)
{
    ili9225_panel_t *ili9225 = __containerof(panel, ili9225_panel_t, base);
    assert((x_start < x_end) && (y_start < y_end) && "start position must be smaller than end position");
    esp_lcd_panel_io_handle_t io = ili9225->io;

    x_start += ili9225->x_gap;
    x_end += ili9225->x_gap;
    y_start += ili9225->y_gap;
    y_end += ili9225->y_gap;

    size_t len = (x_end - x_start)* ili9225->bits_per_pixel / 8;
    for(uint16_t _y=y_start;_y<=y_end;_y++){
        esp_lcd_panel_io_tx_param(io, 0x20,(uint8_t[]){(x_start >> 8) & 0xFF,x_start & 0xFF},2);
        esp_lcd_panel_io_tx_param(io, 0x21,(uint8_t[]){(_y>>8)&0xFF,_y&0xFF},2);

        esp_lcd_panel_io_tx_color(io, 0x22, color_data+len*(_y-y_start), len);
	}

    return ESP_OK;
}

static esp_err_t panel_ili9225_invert_color(esp_lcd_panel_t *panel, bool invert_color_data)
{
    ili9225_panel_t *ili9225 = __containerof(panel, ili9225_panel_t, base);
    esp_lcd_panel_io_handle_t io = ili9225->io;
    int command = 0;
    if (invert_color_data)
    {
        command = LCD_CMD_INVON;
    }
    else
    {
        command = LCD_CMD_INVOFF;
    }
    esp_lcd_panel_io_tx_param(io, command, NULL, 0);
    return ESP_OK;
}

static esp_err_t panel_ili9225_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y)
{
    ili9225_panel_t *ili9225 = __containerof(panel, ili9225_panel_t, base);
    esp_lcd_panel_io_handle_t io = ili9225->io;
    if (mirror_x)
    {
        ili9225->madctl_val |= LCD_CMD_MX_BIT;
    }
    else
    {
        ili9225->madctl_val &= ~LCD_CMD_MX_BIT;
    }
    if (mirror_y)
    {
        ili9225->madctl_val |= LCD_CMD_MY_BIT;
    }
    else
    {
        ili9225->madctl_val &= ~LCD_CMD_MY_BIT;
    }
    esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]){ili9225->madctl_val}, 1);
    return ESP_OK;
}

static esp_err_t panel_ili9225_swap_xy(esp_lcd_panel_t *panel, bool swap_axes)
{
    ili9225_panel_t *ili9225 = __containerof(panel, ili9225_panel_t, base);
    esp_lcd_panel_io_handle_t io = ili9225->io;
    if (swap_axes)
    {
        ili9225->madctl_val |= LCD_CMD_MV_BIT;
    }
    else
    {
        ili9225->madctl_val &= ~LCD_CMD_MV_BIT;
    }
    esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]){ili9225->madctl_val}, 1);
    return ESP_OK;
}

static esp_err_t panel_ili9225_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap)
{
    ili9225_panel_t *ili9225 = __containerof(panel, ili9225_panel_t, base);
    ili9225->x_gap = x_gap;
    ili9225->y_gap = y_gap;
    return ESP_OK;
}

static esp_err_t panel_ili9225_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
{
    ili9225_panel_t *ili9225 = __containerof(panel, ili9225_panel_t, base);
    esp_lcd_panel_io_handle_t io = ili9225->io;
    int command = 0;
    if (on_off)
    {
        command = LCD_CMD_DISPON;
    }
    else
    {
        command = LCD_CMD_DISPOFF;
    }
    esp_lcd_panel_io_tx_param(io, command, NULL, 0);
    return ESP_OK;
}

?为了支持小屏幕尺寸,lvgl\src\hal\lv_hal_disp.c需要修改:

? ? driver->hor_res ? ? ? ? ?= 176;//320;

? ? driver->ver_res ? ? ? ? ?= 220;//240;

void lv_disp_drv_init(lv_disp_drv_t * driver)
{
    lv_memset_00(driver, sizeof(lv_disp_drv_t));

    driver->hor_res          = 176;//320;
    driver->ver_res          = 220;//240;
    driver->physical_hor_res = -1;
    driver->physical_ver_res = -1;
    driver->offset_x         = 0;
    driver->offset_y         = 0;
    driver->antialiasing     = LV_COLOR_DEPTH > 8 ? 1 : 0;
    driver->screen_transp    = 0;
    driver->dpi              = LV_DPI_DEF;
    driver->color_chroma_key = LV_COLOR_CHROMA_KEY;

三、说明

待续

四、总结

待续

文章来源:https://blog.csdn.net/weixin_44067125/article/details/135354519
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。