-
-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathmain.cpp
92 lines (74 loc) · 2.26 KB
/
main.cpp
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
#define LGFX_AUTODETECT
#include <LGFX_AUTODETECT.hpp>
#include <lv_demo.h>
#include <lvgl.h>
/*Change to your screen resolution*/
static const uint16_t screenWidth = 320;
static const uint16_t screenHeight = 240;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[2][ screenWidth * 10 ];
LGFX gfx;
/* Display flushing */
void my_disp_flush( lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p )
{
if (gfx.getStartCount() == 0)
{ // Processing if not yet started
gfx.startWrite();
}
gfx.pushImageDMA( area->x1
, area->y1
, area->x2 - area->x1 + 1
, area->y2 - area->y1 + 1
, ( lgfx::swap565_t* )&color_p->full);
lv_disp_flush_ready( disp );
}
void sd_access_sample( void )
{
if (gfx.getStartCount() > 0)
{ // Free the bus before accessing the SD card
gfx.endWrite();
}
// Something to manipulate the SD card.
auto file = SD.open("/file");
file.close();
}
/*Read the touchpad*/
void my_touchpad_read( lv_indev_drv_t * indev_driver, lv_indev_data_t * data )
{
uint16_t touchX, touchY;
data->state = LV_INDEV_STATE_REL;
if( gfx.getTouch( &touchX, &touchY ) )
{
data->state = LV_INDEV_STATE_PR;
/*Set the coordinates*/
data->point.x = touchX;
data->point.y = touchY;
}
}
void setup()
{
gfx.begin();
lv_init();
lv_disp_draw_buf_init( &draw_buf, buf[0], buf[1], screenWidth * 10 );
/*Initialize the display*/
static lv_disp_drv_t disp_drv;
lv_disp_drv_init( &disp_drv );
/*Change the following line to your display resolution*/
disp_drv.hor_res = screenWidth;
disp_drv.ver_res = screenHeight;
disp_drv.flush_cb = my_disp_flush;
disp_drv.draw_buf = &draw_buf;
lv_disp_drv_register( &disp_drv );
/*Initialize the 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 );
lv_demo_benchmark();
}
void loop()
{
lv_timer_handler(); /* let the GUI do its work */
delay(1);
}