-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLvgl_benchmark.ino
163 lines (133 loc) · 4.88 KB
/
Lvgl_benchmark.ino
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
156
157
158
159
160
161
162
163
/*
* @Description: LVGL
* @Author: LILYGO_L
* @Date: 2023-09-22 11:59:37
* @LastEditTime: 2024-09-11 09:50:25
* @License: GPL 3.0
*/
// #define TOUCH_MODULES_GT911
// #define TOUCH_MODULES_CST_SELF
#define TOUCH_MODULES_CST_MUTUAL
// #define TOUCH_MODULES_ZTW622
// #define TOUCH_MODULES_L58
// #define TOUCH_MODULES_FT3267
// #define TOUCH_MODULES_FT5x06
#include "lvgl.h"
#include "Arduino_GFX_Library.h"
#include "pin_config.h"
#include "lv_demo_benchmark.h"
#include "TouchLib.h"
volatile bool Touch_Int_Flag = false;
TouchLib touch(Wire, TOUCH_SDA, TOUCH_SCL, CST3240_ADDRESS);
Arduino_DataBus *bus = new Arduino_XL9535SWSPI(IIC_SDA /* SDA */, IIC_SCL /* SCL */, -1 /* XL PWD */,
XL95X5_CS /* XL CS */, XL95X5_SCLK /* XL SCK */, XL95X5_MOSI /* XL MOSI */);
Arduino_ESP32RGBPanel *rgbpanel = new Arduino_ESP32RGBPanel(
-1 /* DE */, LCD_VSYNC /* VSYNC */, LCD_HSYNC /* HSYNC */, LCD_PCLK /* PCLK */,
LCD_B0 /* B0 */, LCD_B1 /* B1 */, LCD_B2 /* B2 */, LCD_B3 /* B3 */, LCD_B4 /* B4 */,
LCD_G0 /* G0 */, LCD_G1 /* G1 */, LCD_G2 /* G2 */, LCD_G3 /* G3 */, LCD_G4 /* G4 */, LCD_G5 /* G5 */,
LCD_R0 /* R0 */, LCD_R1 /* R1 */, LCD_R2 /* R2 */, LCD_R3 /* R3 */, LCD_R4 /* R4 */,
1 /* hsync_polarity */, 20 /* hsync_front_porch */, 2 /* hsync_pulse_width */, 0 /* hsync_back_porch */,
1 /* vsync_polarity */, 30 /* vsync_front_porch */, 8 /* vsync_pulse_width */, 1 /* vsync_back_porch */,
10 /* pclk_active_neg */, 6000000L /* prefer_speed */, false /* useBigEndian */,
0 /* de_idle_high*/, 0 /* pclk_idle_high */);
Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
LCD_WIDTH /* width */, LCD_HEIGHT /* height */, rgbpanel, 0 /* rotation */, true /* auto_flush */,
bus, -1 /* RST */, st7701_type9_init_operations, sizeof(st7701_type9_init_operations));
static lv_disp_draw_buf_t draw_buf;
static lv_disp_drv_t disp_drv;
/* Display flushing */
void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
uint32_t w = (area->x2 - area->x1 + 1);
uint32_t h = (area->y2 - area->y1 + 1);
#if (LV_COLOR_16_SWAP != 0)
gfx->draw16bitBeRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
#else
gfx->draw16bitRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
#endif
lv_disp_flush_ready(disp);
}
/*Read the touchpad*/
void my_touchpad_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
{
if (Touch_Int_Flag == true)
{
touch.read();
TP_Point t = touch.getPoint(0);
if ((touch.getPointNum() == 1) && (t.pressure > 0) && (t.state != 0))
{
data->state = LV_INDEV_STATE_PR;
/*Set the coordinates*/
data->point.x = t.x;
data->point.y = t.y;
// Serial.printf("Touch X: %d Y: %d", t.x, t.y);
// Serial.printf("Static: %d", t.state);
// Serial.printf("Pressure: %d", t.pressure);
}
Touch_Int_Flag = false;
}
else
{
data->state = LV_INDEV_STATE_REL;
}
}
void lvgl_initialization(void)
{
lv_init();
uint32_t screen_width = gfx->width();
uint32_t screen_height = gfx->height();
// 使用PSRAM分配内存
lv_color_t *buf_1 = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * LCD_WIDTH * 40, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
lv_color_t *buf_2 = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * LCD_WIDTH * 40, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
while ((!buf_1) || (!buf_2))
{
Serial.println("LVGL disp_draw_buf allocate failed!");
delay(1000);
}
lv_disp_draw_buf_init(&draw_buf, buf_1, buf_2, LCD_WIDTH * 40);
/* Initialize the display */
lv_disp_drv_init(&disp_drv);
/* Change the following line to your display resolution */
disp_drv.hor_res = screen_width;
disp_drv.ver_res = screen_height;
disp_drv.flush_cb = my_disp_flush;
disp_drv.draw_buf = &draw_buf;
disp_drv.full_refresh = 1; // 双缓冲全像素刷新
lv_disp_drv_register(&disp_drv);
/*Initialize the (dummy) input device driver*/
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = my_touchpad_read;
lv_indev_drv_register(&indev_drv);
}
void setup()
{
Serial.begin(115200);
Serial.println("Ciallo");
pinMode(LCD_BL, OUTPUT);
digitalWrite(LCD_BL, HIGH);
attachInterrupt(
TOUCH_INT,
[]
{
Touch_Int_Flag = true;
// Serial.println("get_int");
},
FALLING);
Wire.begin(IIC_SDA, IIC_SCL);
gfx->begin();
gfx->fillScreen(BLACK);
gfx->XL_digitalWrite(TOUCH_RST, LOW);
delay(200);
gfx->XL_digitalWrite(TOUCH_RST, HIGH);
delay(200);
touch.init();
lvgl_initialization();
lv_demo_benchmark();
}
void loop()
{
lv_timer_handler(); /* let the GUI do its work */
delay(5);
}