-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLvgl.ino
175 lines (142 loc) · 4.84 KB
/
Lvgl.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
164
165
166
167
168
169
170
171
172
173
174
175
/*
* @Description: Lvgl Template
* @Author: LILYGO_L
* @Date: 2024-09-05 09:07:21
* @LastEditTime: 2025-01-02 16:38:22
* @License: GPL 3.0
*/
#include "custom.h"
#include "lvgl.h"
#include "gui_guider.h"
#include "events_init.h"
#include "Arduino_GFX_Library.h"
#include "Arduino_DriveBus_Library.h"
#include "pin_config.h"
static lv_disp_draw_buf_t draw_buf;
static lv_disp_drv_t disp_drv;
Arduino_DataBus *bus = new Arduino_ESP32QSPI(
LCD_CS /* CS */, LCD_SCLK /* SCK */, LCD_SDIO0 /* SDIO0 */, LCD_SDIO1 /* SDIO1 */,
LCD_SDIO2 /* SDIO2 */, LCD_SDIO3 /* SDIO3 */);
Arduino_GFX *gfx = new Arduino_CO5300(bus, LCD_RST /* RST */,
0 /* rotation */, false /* IPS */, LCD_WIDTH, LCD_HEIGHT,
20 /* col offset 1 */, 0 /* row offset 1 */, 0 /* col_offset2 */, 0 /* row_offset2 */);
std::shared_ptr<Arduino_IIC_DriveBus> IIC_Bus =
std::make_shared<Arduino_HWIIC>(IIC_SDA, IIC_SCL, &Wire);
void Arduino_IIC_Touch_Interrupt(void);
std::unique_ptr<Arduino_IIC> FT3168(new Arduino_FT3x68(IIC_Bus, FT3168_DEVICE_ADDRESS,
TP_RST, TP_INT, Arduino_IIC_Touch_Interrupt));
void Arduino_IIC_Touch_Interrupt(void)
{
FT3168->IIC_Interrupt_Flag = true;
}
lv_ui guider_ui;
/* 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 (FT3168->IIC_Interrupt_Flag == true)
{
FT3168->IIC_Interrupt_Flag = false;
int32_t touch_x = FT3168->IIC_Read_Device_Value(FT3168->Arduino_IIC_Touch::Value_Information::TOUCH_COORDINATE_X);
int32_t touch_y = FT3168->IIC_Read_Device_Value(FT3168->Arduino_IIC_Touch::Value_Information::TOUCH_COORDINATE_Y);
uint8_t fingers_number = FT3168->IIC_Read_Device_Value(FT3168->Arduino_IIC_Touch::Value_Information::TOUCH_FINGER_NUMBER);
if (fingers_number > 0)
{
data->state = LV_INDEV_STATE_PR;
/*Set the coordinates*/
data->point.x = touch_x;
data->point.y = touch_y;
// Serial.print("Data x ");
// Serial.printf("%d\n", x[0]);
// Serial.print("Data y ");
// Serial.printf("%d\n", y[0]);
}
else
{
data->state = LV_INDEV_STATE_REL;
}
}
}
void my_rounder_cb(lv_disp_drv_t *disp_drv, lv_area_t *area)
{
if (area->x1 % 2 != 0)
area->x1 += 1;
if (area->y1 % 2 != 0)
area->y1 += 1;
uint32_t w = (area->x2 - area->x1 + 1);
uint32_t h = (area->y2 - area->y1 + 1);
if (w % 2 != 0)
area->x2 -= 1;
if (h % 2 != 0)
area->y2 -= 1;
}
void lvgl_initialization(void)
{
lv_init();
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 = LCD_WIDTH;
disp_drv.ver_res = LCD_HEIGHT;
disp_drv.flush_cb = my_disp_flush;
disp_drv.rounder_cb = my_rounder_cb;
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_EN, OUTPUT);
digitalWrite(LCD_EN, HIGH);
if (FT3168->begin() == false)
{
Serial.println("FT3168 initialization fail");
delay(2000);
}
else
{
Serial.println("FT3168 initialization successfully");
}
gfx->begin();
gfx->fillScreen(BLACK);
lvgl_initialization();
setup_ui(&guider_ui);
events_init(&guider_ui);
for (int i = 0; i <= 255; i++)
{
gfx->Display_Brightness(i);
delay(3);
}
}
void loop()
{
lv_timer_handler(); /* let the GUI do its work */
delay(5);
}