Skip to content

Commit 53d765b

Browse files
committed
Update LittleVgl with upstream changes
1 parent ce22ba2 commit 53d765b

2 files changed

Lines changed: 107 additions & 208 deletions

File tree

sim/displayapp/LittleVgl.cpp

Lines changed: 90 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,67 @@
11
#include "displayapp/LittleVgl.h"
22
#include "displayapp/lv_pinetime_theme.h"
33

4-
//#include <FreeRTOS.h>
5-
//#include <task.h>
4+
#include <FreeRTOS.h>
5+
#include <task.h>
66
////#include <projdefs.h>
77
#include "drivers/Cst816s.h"
88
#include "drivers/St7789.h"
99

1010
using namespace Pinetime::Components;
1111

12-
//lv_style_t* LabelBigStyle = nullptr;
13-
//
14-
//static void disp_flush(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p) {
15-
// auto* lvgl = static_cast<LittleVgl*>(disp_drv->user_data);
16-
// lvgl->FlushDisplay(area, color_p);
17-
//}
18-
//
12+
lv_style_t* LabelBigStyle = nullptr;
13+
14+
static void disp_flush(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p) {
15+
auto* lvgl = static_cast<LittleVgl*>(disp_drv->user_data);
16+
lvgl->FlushDisplay(area, color_p);
17+
}
18+
19+
static void rounder(lv_disp_drv_t* disp_drv, lv_area_t* area) {
20+
auto* lvgl = static_cast<LittleVgl*>(disp_drv->user_data);
21+
if (lvgl->GetFullRefresh()) {
22+
area->x1 = 0;
23+
area->x2 = LV_HOR_RES - 1;
24+
area->y1 = 0;
25+
area->y2 = LV_VER_RES - 1;
26+
}
27+
}
28+
1929
bool touchpad_read(lv_indev_drv_t* indev_drv, lv_indev_data_t* data) {
2030
auto* lvgl = static_cast<LittleVgl*>(indev_drv->user_data);
2131
return lvgl->GetTouchPadInfo(data);
2232
}
2333

2434
LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Drivers::Cst816S& touchPanel)
25-
: lcd {lcd}, touchPanel {touchPanel}, previousClick {0, 0} {
26-
35+
: lcd {lcd}, touchPanel {touchPanel} {
2736
}
2837

2938
void LittleVgl::Init() {
3039
// lv_init();
31-
// InitDisplay();
3240
// InitTheme();
41+
// InitDisplay();
3342
InitTouchpad();
3443
}
3544

36-
//void LittleVgl::InitDisplay() {
37-
// lv_disp_draw_buf_init(&disp_buf_2, buf2_1, buf2_2, LV_HOR_RES_MAX * 4); /*Initialize the display buffer*/
38-
// lv_disp_drv_init(&disp_drv); /*Basic initialization*/
39-
//
40-
// /*Set up the functions to access to your display*/
41-
//
42-
// /*Set the resolution of the display*/
43-
// disp_drv.hor_res = 240;
44-
// disp_drv.ver_res = 240;
45-
//
46-
// /*Used to copy the buffer's content to the display*/
47-
// disp_drv.flush_cb = disp_flush;
48-
// /*Set a display buffer*/
49-
// disp_drv.draw_buf = &disp_buf_2;
50-
// disp_drv.user_data = this;
51-
//
52-
// /*Finally register the driver*/
53-
// lv_disp_drv_register(&disp_drv);
54-
//}
45+
void LittleVgl::InitDisplay() {
46+
lv_disp_buf_init(&disp_buf_2, buf2_1, buf2_2, LV_HOR_RES_MAX * 4); /*Initialize the display buffer*/
47+
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
48+
49+
/*Set up the functions to access to your display*/
50+
51+
/*Set the resolution of the display*/
52+
disp_drv.hor_res = 240;
53+
disp_drv.ver_res = 240;
54+
55+
/*Used to copy the buffer's content to the display*/
56+
disp_drv.flush_cb = disp_flush;
57+
/*Set a display buffer*/
58+
disp_drv.buffer = &disp_buf_2;
59+
disp_drv.user_data = this;
60+
disp_drv.rounder_cb = rounder;
61+
62+
/*Finally register the driver*/
63+
lv_disp_drv_register(&disp_drv);
64+
}
5565

5666
void LittleVgl::InitTouchpad() {
5767
lv_indev_drv_t indev_drv;
@@ -67,171 +77,30 @@ void LittleVgl::SetFullRefresh(FullRefreshDirections direction) {
6777
if (scrollDirection == FullRefreshDirections::None) {
6878
scrollDirection = direction;
6979
if (scrollDirection == FullRefreshDirections::Down) {
70-
lv_disp_set_rotation(lv_disp_get_default(), LV_DISP_ROT_NONE);
80+
lv_disp_set_direction(lv_disp_get_default(), 1);
7181
} else if (scrollDirection == FullRefreshDirections::Right) {
72-
lv_disp_set_rotation(lv_disp_get_default(), LV_DISP_ROT_NONE);
82+
lv_disp_set_direction(lv_disp_get_default(), 2);
7383
} else if (scrollDirection == FullRefreshDirections::Left) {
74-
lv_disp_set_rotation(lv_disp_get_default(), LV_DISP_ROT_NONE);
84+
lv_disp_set_direction(lv_disp_get_default(), 3);
7585
} else if (scrollDirection == FullRefreshDirections::RightAnim) {
76-
lv_disp_set_rotation(lv_disp_get_default(), LV_DISP_ROT_NONE);
86+
lv_disp_set_direction(lv_disp_get_default(), 5);
7787
} else if (scrollDirection == FullRefreshDirections::LeftAnim) {
78-
lv_disp_set_rotation(lv_disp_get_default(), LV_DISP_ROT_NONE);
88+
lv_disp_set_direction(lv_disp_get_default(), 4);
7989
}
8090
}
91+
fullRefresh = true;
8192
}
82-
//
83-
//
84-
//void LittleVgl::DisplayDownScroll(){
85-
// // We are controlling the drawing process, disable lvgl timers
86-
// lv_timer_enable(false);
87-
//
88-
// // For each segment, draw the full width, 4 lines at a time starting from the bottom
89-
// // TODO: Should probably calculate this from the size of the draw buffer
90-
// int16_t height = 4;
91-
// int16_t width = 240;
92-
// int16_t y2 = 240;
93-
// int16_t y1 = 240 - height;
94-
//
95-
// lv_area_t area;
96-
// area.x1 = 0;
97-
// area.x2 = width;
98-
//
99-
// // Start from the bottom and create a 4 line high box
100-
// for (y1 = 240 - height; y1 >= 0; y1 -= height) {
101-
// y2 = y1 + height - 1;
102-
//
103-
// // If the box has reached the end of the visible line on the lcd controller...
104-
// if (y2 == visibleNbLines - 1) {
105-
// // move past the non visible lines
106-
// writeOffset += (totalNbLines - visibleNbLines);
107-
// // and wrap around to the start of address space
108-
// writeOffset %= totalNbLines;
109-
// }
110-
// // Set new box
111-
// area.y1 = y1;
112-
// area.y2 = y2;
113-
//
114-
// // Scroll as we draw
115-
// uint16_t toScroll = height;
116-
// if (scrollOffset >= toScroll)
117-
// scrollOffset -= toScroll;
118-
// else { // now we need to wrap the scroll address
119-
// toScroll -= scrollOffset;
120-
// scrollOffset = totalNbLines - toScroll;
121-
// }
122-
// lcd.VerticalScrollStartAddress(scrollOffset);
123-
//
124-
// lv_disp_t* disp = lv_disp_get_default();
125-
// // Clear invalid area list / tells lvgl that nothing on the screen needs to be updated
126-
// _lv_inv_area(disp, nullptr);
127-
// // invalidate only the segment we want to update in this portion of the animation
128-
// _lv_inv_area(disp, &area);
129-
// // cancel any current flushes in the display driver
130-
// // Since we've stopped timers, it will be waiting forever if there is currently a flush
131-
// lv_disp_flush_ready(disp->driver);
132-
// lv_refr_now(disp);
133-
// }
134-
// // Done! clear flags and enable timers
135-
// scrollDirection = FullRefreshDirections::None;
136-
// animating = false;
137-
// lv_timer_enable(true);
138-
//}
139-
//
140-
//void LittleVgl::DisplayHorizAnim() {
141-
// lv_timer_enable(false);
142-
//
143-
// int16_t height, width, x1, x2;
144-
// lv_area_t area;
145-
//
146-
// height = 240;
147-
// width = 4;
148-
// int16_t (*NextStep)(int16_t, int16_t){};
149-
// bool (*CheckEnd)(int16_t){};
150-
//
151-
// area.y1=0;
152-
// area.y2=height;
153-
//
154-
// if (scrollDirection == FullRefreshDirections::RightAnim) {
155-
// x1 = 0;
156-
//
157-
// CheckEnd = [](int16_t x) -> bool {
158-
// return (x < LV_HOR_RES_MAX);
159-
// };
160-
// NextStep = [](int16_t x, int16_t width) -> int16_t {
161-
// auto newx = x + width * 2;
162-
// if (newx < 240) {return newx;};
163-
// return (newx < 240 + width) ? (newx - 240 + width) : newx;
164-
// };
165-
//
166-
// } else if (scrollDirection == FullRefreshDirections::LeftAnim) {
167-
// x1 = 240 - width;
168-
//
169-
// CheckEnd = [](int16_t x) -> bool {
170-
// return (x >= 0);
171-
// };
172-
// NextStep = [](int16_t x, int16_t width) -> int16_t {
173-
// auto newx = x - width * 2;
174-
// if (newx >= 0) {return newx;}
175-
// return (newx >= 0 - width) ? (newx + 240 - width) : newx;
176-
// };
177-
//
178-
// } else {
179-
// // Not set for a horizontal animation!
180-
// lv_timer_enable(true);
181-
// return;
182-
// }
183-
//
184-
// for (; CheckEnd(x1); x1 = NextStep(x1, width)) {
185-
// x2 = x1 + width-1;
186-
//
187-
// if (area.y2 == visibleNbLines - 1) {
188-
// writeOffset += (totalNbLines - visibleNbLines);
189-
// writeOffset %= totalNbLines;
190-
// }
191-
// area.x1 = x1;
192-
// area.x2 = x2;
193-
//
194-
// lv_disp_t* disp = lv_disp_get_default();
195-
// _lv_inv_area(disp, nullptr);
196-
// _lv_inv_area(disp, &area);
197-
// lv_disp_flush_ready(disp->driver);
198-
// lv_refr_now(disp);
199-
// }
200-
// scrollDirection = FullRefreshDirections::None;
201-
// animating = false;
202-
// lv_timer_enable(true);
203-
//}
204-
//
205-
//void LittleVgl::FlushDisplayManually() {
206-
// switch(scrollDirection){
207-
// case FullRefreshDirections::Down:
208-
// DisplayDownScroll();
209-
// break;
210-
// case FullRefreshDirections::RightAnim:
211-
// case FullRefreshDirections::LeftAnim:
212-
// DisplayHorizAnim();
213-
// break;
214-
// default:
215-
// break;
216-
// }
217-
//}
218-
//
93+
21994
void LittleVgl::FlushDisplay(const lv_area_t* area, lv_color_t* color_p) {
22095
// uint16_t y1, y2, width, height = 0;
22196
//
22297
// ulTaskNotifyTake(pdTRUE, 200);
223-
// // NOtification is still needed (even if there is a mutex on SPI) because of the DataCommand pin
224-
// // which cannot be set/clear during a transfert.
225-
//
226-
// if (!animating && (scrollDirection == FullRefreshDirections::Down ||
227-
// scrollDirection == FullRefreshDirections::RightAnim ||
228-
// scrollDirection == FullRefreshDirections::LeftAnim)){
229-
// animating = true;
230-
// FlushDisplayManually();
231-
// return;
232-
// }
98+
// // Notification is still needed (even if there is a mutex on SPI) because of the DataCommand pin
99+
// // which cannot be set/clear during a transfer.
233100
//
234-
// if ((scrollDirection == FullRefreshDirections::Up) && (area->y1 == 0)) {
101+
// if ((scrollDirection == LittleVgl::FullRefreshDirections::Down) && (area->y2 == visibleNbLines - 1)) {
102+
// writeOffset = ((writeOffset + totalNbLines) - visibleNbLines) % totalNbLines;
103+
// } else if ((scrollDirection == FullRefreshDirections::Up) && (area->y1 == 0)) {
235104
// writeOffset = (writeOffset + visibleNbLines) % totalNbLines;
236105
// }
237106
//
@@ -241,13 +110,34 @@ void LittleVgl::FlushDisplay(const lv_area_t* area, lv_color_t* color_p) {
241110
// width = (area->x2 - area->x1) + 1;
242111
// height = (area->y2 - area->y1) + 1;
243112
//
244-
// if (scrollDirection == FullRefreshDirections::Up) {
113+
// if (scrollDirection == LittleVgl::FullRefreshDirections::Down) {
114+
//
115+
// if (area->y2 < visibleNbLines - 1) {
116+
// uint16_t toScroll = 0;
117+
// if (area->y1 == 0) {
118+
// toScroll = height * 2;
119+
// scrollDirection = FullRefreshDirections::None;
120+
// lv_disp_set_direction(lv_disp_get_default(), 0);
121+
// } else {
122+
// toScroll = height;
123+
// }
124+
//
125+
// if (scrollOffset >= toScroll)
126+
// scrollOffset -= toScroll;
127+
// else {
128+
// toScroll -= scrollOffset;
129+
// scrollOffset = (totalNbLines) -toScroll;
130+
// }
131+
// lcd.VerticalScrollStartAddress(scrollOffset);
132+
// }
133+
//
134+
// } else if (scrollDirection == FullRefreshDirections::Up) {
245135
//
246136
// if (area->y1 > 0) {
247137
// if (area->y2 == visibleNbLines - 1) {
248138
// scrollOffset += (height * 2);
249139
// scrollDirection = FullRefreshDirections::None;
250-
//// lv_disp_set_rotation(lv_disp_get_default(), LV_DISP_ROT_NONE);
140+
// lv_disp_set_direction(lv_disp_get_default(), 0);
251141
// } else {
252142
// scrollOffset += height;
253143
// }
@@ -257,12 +147,12 @@ void LittleVgl::FlushDisplay(const lv_area_t* area, lv_color_t* color_p) {
257147
// } else if (scrollDirection == FullRefreshDirections::Left or scrollDirection == FullRefreshDirections::LeftAnim) {
258148
// if (area->x2 == visibleNbLines - 1) {
259149
// scrollDirection = FullRefreshDirections::None;
260-
//// lv_disp_set_rotation(lv_disp_get_default(), LV_DISP_ROT_NONE);
150+
// lv_disp_set_direction(lv_disp_get_default(), 0);
261151
// }
262152
// } else if (scrollDirection == FullRefreshDirections::Right or scrollDirection == FullRefreshDirections::RightAnim) {
263153
// if (area->x1 == 0) {
264154
// scrollDirection = FullRefreshDirections::None;
265-
//// lv_disp_set_rotation(lv_disp_get_default(), LV_DISP_ROT_NONE);
155+
// lv_disp_set_direction(lv_disp_get_default(), 0);
266156
// }
267157
// }
268158
//
@@ -319,9 +209,15 @@ bool LittleVgl::GetTouchPadInfo(lv_indev_data_t* ptr) {
319209
return false;
320210
}
321211

322-
//void LittleVgl::InitTheme() {
323-
// if (!lv_pinetime_theme_is_inited()) {
324-
// lv_theme_t* th = lv_pinetime_theme_init(lv_disp_get_default(), lv_color_white(), lv_color_hex(0xC0C0C0), &jetbrains_mono_bold_20);
325-
// lv_disp_set_theme(lv_disp_get_default(), th);
326-
// }
327-
//}
212+
void LittleVgl::InitTheme() {
213+
214+
lv_theme_t* th = lv_pinetime_theme_init(LV_COLOR_WHITE,
215+
LV_COLOR_SILVER,
216+
0,
217+
&jetbrains_mono_bold_20,
218+
&jetbrains_mono_bold_20,
219+
&jetbrains_mono_bold_20,
220+
&jetbrains_mono_bold_20);
221+
222+
lv_theme_set_act(th);
223+
}

0 commit comments

Comments
 (0)