Skip to content

Commit 3624077

Browse files
kisvegaborfacchinm
authored andcommitted
lvgl: improve GPU
1 parent ac08ec0 commit 3624077

File tree

2 files changed

+32
-42
lines changed

2 files changed

+32
-42
lines changed

examples/Portenta_lvgl/Portenta_lvgl.ino

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ static lv_disp_drv_t disp_drv;
1313
/* Display flushing */
1414
static void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
1515
{
16-
uint32_t w = lv_area_get_width(area);
17-
uint32_t h = lv_area_get_height(area);
1816

19-
#if 1
20-
// SCB_InvalidateICache();
21-
22-
// SCB_CleanInvalidateDCache();
17+
#if ARDUINO_PORTENTA_H7_M7
18+
SCB_CleanInvalidateDCache();
19+
SCB_InvalidateICache();
20+
#endif
2321

2422
DMA2D_HandleTypeDef * dma2d = stm32_get_DMA2D();
2523

2624
lv_color_t * pDst = (lv_color_t*)fb;
2725
pDst += area->y1 * lcd_x_size + area->x1;
2826

27+
uint32_t w = lv_area_get_width(area);
28+
uint32_t h = lv_area_get_height(area);
2929
/*##-1- Configure the DMA2D Mode, Color Mode and output offset #############*/
3030
dma2d->Init.Mode = DMA2D_M2M;
3131
dma2d->Init.ColorMode = DMA2D_OUTPUT_RGB565;
@@ -45,31 +45,26 @@ static void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t
4545
dma2d->LayerCfg[1].AlphaInverted = DMA2D_REGULAR_ALPHA; /* No ForeGround Alpha inversion */
4646

4747
/* DMA2D Initialization */
48-
if(HAL_DMA2D_Init(dma2d) == HAL_OK) {
49-
if(HAL_DMA2D_ConfigLayer(dma2d, 1) == HAL_OK) {
50-
HAL_DMA2D_Start(dma2d, (uint32_t)color_p, (uint32_t)pDst, w, h);
51-
HAL_DMA2D_PollForTransfer(dma2d, 1000);
48+
if (HAL_DMA2D_Init(dma2d) == HAL_OK) {
49+
if (HAL_DMA2D_ConfigLayer(dma2d, 1) == HAL_OK) {
50+
HAL_DMA2D_Start(dma2d, (uint32_t)color_p, (uint32_t)pDst, w, h);
51+
HAL_DMA2D_PollForTransfer(dma2d, 1000);
5252
}
5353
}
54-
#else
55-
//NO GPU
56-
int32_t y;
57-
for(y = area->y1; y <= area->y2; y++) {
58-
memcpy(&fb[y * lcd_x_size + area->x1], color_p, w * sizeof(lv_color_t));
59-
color_p += w;
60-
}
61-
#endif
62-
lv_disp_flush_ready(disp); /* tell lvgl that flushing is done */
54+
55+
lv_disp_flush_ready(disp); /* tell lvgl that flushing is done */
6356
}
6457

6558

6659
/* If your MCU has hardware accelerator (GPU) then you can use it to blend to memories using opacity
67-
* It can be used only in buffered mode (LV_VDB_SIZE != 0 in lv_conf.h)*/
60+
It can be used only in buffered mode (LV_VDB_SIZE != 0 in lv_conf.h)*/
6861
static void gpu_blend(lv_disp_drv_t * disp_drv, lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa)
6962
{
70-
71-
// SCB_CleanInvalidateDCache();
72-
63+
64+
#if ARDUINO_PORTENTA_H7_M7
65+
SCB_CleanInvalidateDCache();
66+
#endif
67+
7368
DMA2D_HandleTypeDef * dma2d = stm32_get_DMA2D();
7469

7570
dma2d->Instance = DMA2D;
@@ -87,24 +82,25 @@ static void gpu_blend(lv_disp_drv_t * disp_drv, lv_color_t * dest, const lv_colo
8782
dma2d->LayerCfg[0].AlphaMode = DMA2D_NO_MODIF_ALPHA;
8883
dma2d->LayerCfg[0].InputColorMode = DMA2D_INPUT_RGB565;
8984
dma2d->LayerCfg[0].InputOffset = 0;
90-
85+
9186
/* DMA2D Initialization */
9287
if (HAL_DMA2D_Init(dma2d) == HAL_OK) {
9388
if (HAL_DMA2D_ConfigLayer(dma2d, 0) == HAL_OK && HAL_DMA2D_ConfigLayer(dma2d, 1) == HAL_OK) {
94-
HAL_DMA2D_BlendingStart(dma2d, (uint32_t) src, (uint32_t) dest, (uint32_t) dest, length, 1);
95-
HAL_DMA2D_PollForTransfer(dma2d, 1000);
89+
HAL_DMA2D_BlendingStart(dma2d, (uint32_t) src, (uint32_t) dest, (uint32_t) dest, length, 1);
90+
HAL_DMA2D_PollForTransfer(dma2d, 1000);
9691
}
9792
}
9893
}
9994

10095
/* If your MCU has hardware accelerator (GPU) then you can use it to fill a memory with a color */
10196
static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
102-
const lv_area_t * fill_area, lv_color_t color)
97+
const lv_area_t * fill_area, lv_color_t color)
10398
{
104-
// SCB_CleanInvalidateDCache();
105-
106-
DMA2D_HandleTypeDef * dma2d = stm32_get_DMA2D();
99+
#if ARDUINO_PORTENTA_H7_M7
100+
SCB_CleanInvalidateDCache();
101+
#endif
107102

103+
DMA2D_HandleTypeDef * dma2d = stm32_get_DMA2D();
108104

109105
lv_color_t * destination = dest_buf + (dest_width * fill_area->y1 + fill_area->x1);
110106

@@ -120,7 +116,7 @@ static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t
120116
if (HAL_DMA2D_Init(dma2d) == HAL_OK) {
121117
if (HAL_DMA2D_ConfigLayer(dma2d, 1) == HAL_OK) {
122118
lv_coord_t h = lv_area_get_height(fill_area);
123-
if(HAL_DMA2D_BlendingStart(dma2d, lv_color_to32(color), (uint32_t)destination, (uint32_t)destination, w, h) == HAL_OK) {
119+
if (HAL_DMA2D_BlendingStart(dma2d, lv_color_to32(color), (uint32_t)destination, (uint32_t)destination, w, h) == HAL_OK) {
124120
HAL_DMA2D_PollForTransfer(dma2d, 1000);
125121
}
126122
}
@@ -157,11 +153,11 @@ void setup() {
157153
anx7625_dp_start(0, &recognized_edid, EDID_MODE_720x480_60Hz);
158154
SDRAM.begin(getFramebufferEnd());
159155

160-
lv_init();
161-
156+
lv_init();
157+
162158
lcd_x_size = stm32_getXSize();
163159
lcd_y_size = stm32_getYSize();
164-
160+
165161
fb = (uint16_t *)getNextFrameBuffer();
166162
getNextFrameBuffer();
167163

@@ -182,14 +178,11 @@ void setup() {
182178
//lv_label_set_text(label, "Hello Arduino! Dev-7,0");
183179
//lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
184180

185-
lv_demo_widgets();
181+
lv_demo_widgets();
186182

187183
}
188184

189185
void loop() {
190-
uint32_t t1 = millis();
191186
lv_task_handler();
192187
delay(3);
193-
uint32_t t2 = millis();
194-
lv_tick_inc(t2-t1);
195188
}

examples/Portenta_lvgl/lv_demo_widgets.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,7 @@ static void controls_create(lv_obj_t * parent)
139139
lv_textarea_set_cursor_hidden(ta, true);
140140
lv_textarea_set_text_align(ta, LV_LABEL_ALIGN_CENTER);
141141
lv_obj_set_event_cb(ta, lv_ta_event_cb);
142-
143-
lv_theme_apply(ta, LV_THEME_TEXTAREA_ONELINE);
144-
142+
145143
ta = lv_textarea_create(h, ta);
146144
lv_textarea_set_pwd_mode(ta, true);
147145
lv_textarea_set_placeholder_text(ta, "Password");
@@ -410,4 +408,3 @@ static void tab_changer_task_cb(lv_task_t * task)
410408

411409
lv_tabview_set_tab_act(tv, act, LV_ANIM_ON);
412410
}
413-

0 commit comments

Comments
 (0)