-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdisplay_s3.c
171 lines (130 loc) · 4.54 KB
/
display_s3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* @file display_s3.c
* @author Lewis He (lewishe@outlook.com)
* @license MIT
* @copyright Copyright (c) 2024 Shenzhen Xinyuan Electronic Technology Co., Ltd
* @date 2024-01-08
*
*/
#include <sdkconfig.h>
#include "freertos/FreeRTOS.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_ops.h"
#include "esp_lcd_panel_vendor.h"
#include "esp_dma_utils.h"
#include "driver/gpio.h"
#include "esp_err.h"
#include "esp_log.h"
#include "product_pins.h"
#if CONFIG_LILYGO_T_DISPLAY_S3
#include "lvgl.h"
#define EXAMPLE_LCD_PIXEL_CLOCK_HZ (10 * 1000 * 1000)
static const char *TAG = "TFT";
static esp_lcd_panel_io_handle_t io_handle = NULL;
static esp_lcd_panel_handle_t panel_handle = NULL;
extern lv_disp_drv_t disp_drv;
lcd_cmd_t lcd_st7789v[] = {
{0x11, {0}, 0 | 0x80},
{0x3A, {0X05}, 1},
{0xB2, {0X0B, 0X0B, 0X00, 0X33, 0X33}, 5},
{0xB7, {0X75}, 1},
{0xBB, {0X28}, 1},
{0xC0, {0X2C}, 1},
{0xC2, {0X01}, 1},
{0xC3, {0X1F}, 1},
{0xC6, {0X13}, 1},
{0xD0, {0XA7}, 1},
{0xD0, {0XA4, 0XA1}, 2},
{0xD6, {0XA1}, 1},
{0xE0, {0XF0, 0X05, 0X0A, 0X06, 0X06, 0X03, 0X2B, 0X32, 0X43, 0X36, 0X11, 0X10, 0X2B, 0X32}, 14},
{0xE1, {0XF0, 0X08, 0X0C, 0X0B, 0X09, 0X24, 0X2B, 0X22, 0X43, 0X38, 0X15, 0X16, 0X2F, 0X37}, 14},
};
void display_push_colors(uint16_t x, uint16_t y, uint16_t width, uint16_t hight, uint16_t *data)
{
esp_lcd_panel_draw_bitmap(panel_handle, x, y, width, hight, data);
}
bool display_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_flush_ready(&disp_drv);
return false;
}
void display_init()
{
ESP_LOGI(TAG, "============T-Display-S3============");
gpio_config_t rd_gpio_config = {
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = 1ULL << BOARD_TFT_RD
};
ESP_ERROR_CHECK(gpio_config(&rd_gpio_config));
gpio_set_level(BOARD_TFT_RD, 1);
esp_lcd_i80_bus_handle_t i80_bus = NULL;
esp_lcd_i80_bus_config_t bus_config = {
.dc_gpio_num = BOARD_TFT_DC,
.wr_gpio_num = BOARD_TFT_WR,
.clk_src = LCD_CLK_SRC_DEFAULT,
.data_gpio_nums =
{
BOARD_TFT_DATA0,
BOARD_TFT_DATA1,
BOARD_TFT_DATA2,
BOARD_TFT_DATA3,
BOARD_TFT_DATA4,
BOARD_TFT_DATA5,
BOARD_TFT_DATA6,
BOARD_TFT_DATA7,
},
.bus_width = 8,
.max_transfer_bytes = AMOLED_WIDTH * 100 * sizeof(uint16_t),
.psram_trans_align = 64,
.sram_trans_align = 4
};
esp_lcd_new_i80_bus(&bus_config, &i80_bus);
esp_lcd_panel_io_i80_config_t io_config = {
.cs_gpio_num = BOARD_TFT_CS,
.pclk_hz = EXAMPLE_LCD_PIXEL_CLOCK_HZ,
.trans_queue_depth = 10,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
.dc_levels =
{
.dc_idle_level = 0,
.dc_cmd_level = 0,
.dc_dummy_level = 0,
.dc_data_level = 1,
},
.on_color_trans_done = display_notify_lvgl_flush_ready,
};
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));
esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = BOARD_TFT_RST,
.color_space = ESP_LCD_COLOR_SPACE_RGB,
.bits_per_pixel = 16,
.vendor_config = NULL
};
esp_lcd_new_panel_st7789(io_handle, &panel_config, &panel_handle);
esp_lcd_panel_reset(panel_handle);
esp_lcd_panel_init(panel_handle);
esp_lcd_panel_invert_color(panel_handle, true);
esp_lcd_panel_swap_xy(panel_handle, true);
//The screen faces you, and the USB is on the left
esp_lcd_panel_mirror(panel_handle, false, true);
//The screen faces you, the USB is to the right
// 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, 35);
for (uint8_t i = 0; i < (sizeof(lcd_st7789v) / sizeof(lcd_cmd_t)); i++) {
esp_lcd_panel_io_tx_param(io_handle, lcd_st7789v[i].addr, lcd_st7789v[i].param, lcd_st7789v[i].len & 0x7f);
if (lcd_st7789v[i].len & 0x80)
vTaskDelay(pdMS_TO_TICKS(120));
}
esp_lcd_panel_disp_on_off(panel_handle, true);
ESP_LOGI(TAG, "Turn on LCD backlight");
gpio_config_t bk_gpio_config = {
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = 1ULL << BOARD_TFT_BL
};
ESP_ERROR_CHECK(gpio_config(&bk_gpio_config));
gpio_set_level(BOARD_TFT_BL, 1);
}
#endif