8000 fixed issue due to gc · mhepp63/lv_binding_micropython@9edca9f · GitHub
[go: up one dir, main page]

Skip to content

Commit 9edca9f

Browse files
prolombamirgon
authored andcommitted
fixed issue due to gc
1 parent eac861e commit 9edca9f

File tree

4 files changed

+35
-24
lines changed

4 files changed

+35
-24
lines changed

driver/stm32/STM32F7DISC/modrk043fn48h.c

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "softtimer.h"
44
#include <stdint.h>
55
#include <stdbool.h>
6+
#include <stdlib.h>
67
#include "../../../lvgl/lvgl.h"
78
#include "../../../lv_conf.h"
89
#include "../../include/common.h"
@@ -25,20 +26,27 @@ LTDC_HandleTypeDef *hltdc = NULL; // handle to LTDC, referenced in stm
2526
DMA2D_HandleTypeDef *hdma2d = NULL; // handle to DMA2D, referenced in stm32_it.c
2627
i2c_t *i2c_ts = NULL; // I2C handle for touchscreen
2728
struct _disp_drv_t *dma2d_disp_drv = NULL; // handle to display driver
28-
lv_color_t *fb = NULL; // framebuffer pointer
29+
lv_color_t *fb[2] = {NULL, NULL}; // framebuffer pointers
2930
uint32_t w = 0; // display width
3031
uint32_t h = 0; // display height
3132
volatile bool dma2d_pend = false; // flag of DMA2D pending operation
3233

3334
static bool config_ltdc(void);
3435
static bool config_dma2d(void);
3536

36-
STATIC mp_obj_t mp_rk043fn48h_bytearray(mp_obj_t n_obj) {
37-
size_t n = (size_t)mp_obj_get_int(n_obj);
38-
// allocation on extRAM with 1KB alignment
39-
void *p = m_malloc(n + 1024);
40-
p = (void*)((uint32_t)p + 1024 - (uint32_t)p % 1024);
41-
< 10000 span class=pl-k>return mp_obj_new_bytearray_by_ref(n, (void *)p);
37+
STATIC mp_obj_t mp_rk043fn48h_framebuffer(mp_obj_t n_obj) {
38+
int n = mp_obj_get_int(n_obj) -1;
39+
40+
if (n<0 || n>1){
41+
return mp_const_none;
42+
}
43+
44+
if(fb[n]==NULL){
45+
// allocation on extRAM with 1KB alignment to speed up LTDC burst access on AHB
46+
fb[n] = MP_STATE_PORT(rk043fn48h_fb[n]) = m_malloc(sizeof(lv_color_t) * w * h + 1024);
47+
fb[n] = (lv_color_t*)((uint32_t)fb[n] + 1024 - (uint32_t)fb[n] % 1024);
48+
}
49+
return mp_obj_new_bytearray_by_ref(sizeof(lv_color_t) * w * h , (void *)fb[n]);
4250
}
4351

4452
STATIC mp_obj_t mp_rk043fn48h_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
@@ -55,10 +63,9 @@ STATIC mp_obj_t mp_rk043fn48h_init(size_t n_args, const mp_obj_t *pos_args, mp_m
5563
w = args[ARG_w].u_int;
5664
h = args[ARG_h].u_int;
5765

58-
uint32_t p = (uint32_t)m_malloc(sizeof(lv_color_t) * w * h + 1024);
59-
fb = (lv_color_t *)(p + 1024 - p % 1024); //speeds up LTDC burst access on AHB
66+
mp_rk043fn48h_framebuffer(mp_obj_new_int(1));
6067

61-
if (fb == NULL) {
68+
if (fb[0] == NULL) {
6269
nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "Failed allocating frame buffer"));
6370
}
6471

@@ -91,8 +98,16 @@ STATIC mp_obj_t mp_rk043fn48h_deinit() {
9198
HAL_GPIO_WritePin(LCD_DISP_GPIO_PORT, LCD_DISP_PIN, GPIO_PIN_RESET);
9299
HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_RESET);
93100
hltdc = NULL;
94-
m_free(fb);
95-
fb = NULL;
101+
}
102+
103+
if(fb[0]!=NULL){
104+
m_free(MP_STATE_PORT(rk043fn48h_fb[0]));
105+
fb[0]=NULL;
106+
}
107+
108+
if(fb[1]!=NULL){
109+
m_free(MP_STATE_PORT(rk043fn48h_fb[1]));
110+
fb[1]=NULL;
96111
}
97112

98113
BSP_TS_DeInit();
@@ -115,7 +130,7 @@ STATIC void mp_rk043fn48h_flush(struct _disp_drv_t *disp_drv, const lv_area_t *a
115130
HAL_DMA2D_Init(hdma2d);
116131
HAL_DMA2D_Start_IT(hdma2d,
117132
(uint32_t)color_p,
118-
(uint32_t)(fb + area->x1 + area->y1 * w),
133+
(uint32_t)(fb[0] + area->x1 + area->y1 * w),
119134
lv_area_get_width(area),
120135
lv_area_get_height(area));
121136
}
@@ -188,7 +203,7 @@ STATIC bool mp_rk043fn48h_ts_read(struct _lv_indev_drv_t *indev_drv, lv_indev_da
188203

189204
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mp_rk043fn48h_init_obj, 0, mp_rk043fn48h_init);
190205
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_rk043fn48h_deinit_obj, mp_rk043fn48h_deinit);
191-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_rk043fn48h_bytearray_obj, mp_rk043fn48h_bytearray);
206+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_rk043fn48h_framebuffer_obj, mp_rk043fn48h_framebuffer);
192207
DEFINE_PTR_OBJ(mp_rk043fn48h_flush);
193208
DEFINE_PTR_OBJ(mp_rk043fn48h_gpu_blend);
194209
DEFINE_PTR_OBJ(mp_rk043fn48h_gpu_fill);
@@ -202,7 +217,7 @@ STATIC const mp_rom_map_elem_t rk043fn48h_globals_table[] = {
202217
{ MP_ROM_QSTR(MP_QSTR_gpu_blend), MP_ROM_PTR(&PTR_OBJ(mp_rk043fn48h_gpu_blend))},
203218
{ MP_ROM_QSTR(MP_QSTR_gpu_fill), MP_ROM_PTR(&PTR_OBJ(mp_rk043fn48h_gpu_fill))},
204219
{ MP_ROM_QSTR(MP_QSTR_ts_read), MP_ROM_PTR(&PTR_OBJ(mp_rk043fn48h_ts_read))},
205-
{ MP_ROM_QSTR(MP_QSTR_bytearray), MP_ROM_PTR(&PTR_OBJ(mp_rk043fn48h_bytearray))},
220+
{ MP_ROM_QSTR(MP_QSTR_framebuffer), MP_ROM_PTR(&PTR_OBJ(mp_rk043fn48h_framebuffer))},
206221
};
207222

208223
STATIC MP_DEFINE_CONST_DICT(
@@ -260,7 +275,7 @@ static bool config_ltdc(void) {
260275
#error "modrk043fn48h: LV_COLOR_DEPTH not supported"
261276
#endif
262277

263-
pLayerCfg.FBStartAdress = (uint32_t)fb;
278+
pLayerCfg.FBStartAdress = (uint32_t)fb[0];
264279
pLayerCfg.Alpha = 255;
265280
pLayerCfg.Alpha0 = 0;
266281
pLayerCfg.Backcolor.Blue = 0;

examples/advanced_demo.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,8 @@ def init_gui_stm32(self):
273273
tick = lvstm32.lvstm32()
274274
lcd.init(w=hres, h=vres)
275275
disp_buf1 = lv.disp_buf_t()
276-
buf1_1 = lcd.bytearray(hres * vres * lv.color_t.SIZE)
277-
buf1_2 = lcd.bytearray(hres * vres * lv.color_t.SIZE)
278-
# buf1_1 = bytearray(hres*10*lv.color_t.SIZE)
279-
# buf1_2 = bytearray(hres*10*lv.color_t.SIZE)
276+
buf1_1 = lcd.framebuffer(1)
277+
buf1_2 = lcd.framebuffer(2)
280278
lv.disp_buf_init(disp_buf1, buf1_1, buf1_2, len(buf1_1) // lv.color_t.SIZE)
281279
disp_drv = lv.disp_drv_t()
282280
lv.disp_drv_init(disp_drv)

examples/example1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ def init_gui_stm32(self):
7979
tick = lvstm32.lvstm32()
8080
lcd.init(w=hres, h=vres)
8181
disp_buf1 = lv.disp_buf_t()
82-
buf1_1 = lcd.bytearray(hres * vres * lv.color_t.SIZE)
83-
buf1_2 = lcd.bytearray(hres * vres * lv.color_t.SIZE)
82+
buf1_1 = lcd.framebuffer(1)
83+
buf1_2 = lcd.framebuffer(2)
8484
lv.disp_buf_init(disp_buf1, buf1_1, buf1_2, len(buf1_1) // lv.color_t.SIZE)
8585
disp_drv = lv.disp_drv_t()
8686
lv.disp_drv_init(disp_drv)

examples/example3.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
tick = lvstm32.lvstm32()
1111
lcd.init(w=hres, h=vres)
1212
disp_buf1 = lv.disp_buf_t()
13-
# buf1_1 = lcd.bytearray(hres*vres*lv.color_t.SIZE)
14-
# buf1_2 = lcd.bytearray(hres*vres*lv.color_t.SIZE)
1513
buf1_1 = bytearray(hres * 10 * lv.color_t.SIZE)
1614
buf1_2 = bytearray(hres * 10 * lv.color_t.SIZE)
1715
lv.disp_buf_init(disp_buf1, buf1_1, buf1_2, len(buf1_1) // lv.color_t.SIZE)

0 commit comments

Comments
 (0)
0