@@ -37,7 +37,15 @@ extern "C" {
3737
3838/* Private function prototypes -----------------------------------------------*/
3939#if __has_include ("lvgl.h")
40- void lvgl_displayFlushing (lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p);
40+ #include " mbed.h"
41+ void lvgl_displayFlushing (lv_display_t * display, const lv_area_t * area, unsigned char * px_map);
42+ static void inc_thd () {
43+ while (1 ) {
44+ lv_tick_inc (16 );
45+ delay (16 );
46+ }
47+ }
48+ static rtos::Thread lvgl_inc_thd;
4149#endif
4250
4351/* Functions -----------------------------------------------------------------*/
@@ -85,30 +93,27 @@ int Arduino_H7_Video::begin() {
8593 lv_init ();
8694
8795 /* Create a draw buffer */
88- static lv_disp_draw_buf_t draw_buf;
89- static lv_color_t * buf1;
90- buf1 = (lv_color_t *)malloc ((width () * height () / 10 ) * sizeof (lv_color_t )); /* Declare a buffer for 1/10 screen size */
96+ static lv_color_t * buf1 = (lv_color_t *)malloc ((width () * height () / 10 )); /* Declare a buffer for 1/10 screen size */
9197 if (buf1 == NULL ) {
9298 return 2 ; /* Insuff memory err */
9399 }
94- lv_disp_draw_buf_init (&draw_buf, buf1, NULL , width () * height () / 10 ); /* Initialize the display buffer. */
100+ static lv_color_t * buf2 = (lv_color_t *)malloc ((width () * height () / 10 )); /* Declare a buffer for 1/10 screen size */
101+ if (buf2 == NULL ) {
102+ return 2 ; /* Insuff memory err */
103+ }
95104
96- /* Initialize display features for LVGL library */
97- static lv_disp_drv_t disp_drv; /* Descriptor of a display driver */
98- lv_disp_drv_init (&disp_drv); /* Basic initialization */
99- disp_drv.flush_cb = lvgl_displayFlushing; /* Set your driver function */
100- disp_drv.draw_buf = &draw_buf; /* Assign the buffer to the display */
105+ lv_display_t *display;
101106 if (_rotated) {
102- disp_drv. hor_res = height (); /* Set the horizontal resolution of the display */
103- disp_drv. ver_res = width (); /* Set the vertical resolution of the display */
104- disp_drv. rotated = LV_DISP_ROT_270 ;
107+ display = lv_display_create ( height (), width ());
108+ lv_display_set_rotation ( display, LV_DISPLAY_ROTATION_270);
109+ // display->sw_rotate = 1 ;
105110 } else {
106- disp_drv.hor_res = width (); /* Set the horizontal resolution of the display */
107- disp_drv.ver_res = height (); /* Set the vertical resolution of the display */
108- disp_drv.rotated = LV_DISP_ROT_NONE;
111+ display = lv_display_create (width (), height ());
109112 }
110- disp_drv.sw_rotate = 1 ;
111- lv_disp_drv_register (&disp_drv); /* Finally register the driver */
113+ lv_display_set_buffers (display, buf1, NULL , width () * height () / 10 , LV_DISPLAY_RENDER_MODE_PARTIAL); /* Initialize the display buffer.*/
114+ lv_display_set_flush_cb (display, lvgl_displayFlushing);
115+
116+ lvgl_inc_thd.start (inc_thd);
112117 #endif
113118
114119 /* Configure SDRAM */
@@ -189,13 +194,29 @@ void Arduino_H7_Video::set(int x, int y, uint8_t r, uint8_t g, uint8_t b) {
189194#endif
190195
191196#if __has_include("lvgl.h")
192- void lvgl_displayFlushing (lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) {
197+ static uint8_t * dst = nullptr ;
198+ void lvgl_displayFlushing (lv_display_t * disp, const lv_area_t * area, unsigned char * px_map) {
193199 uint32_t width = lv_area_get_width (area);
194200 uint32_t height = lv_area_get_height (area);
195201 uint32_t offsetPos = (area->x1 + (dsi_getDisplayXSize () * area->y1 )) * sizeof (uint16_t );
196202
197- dsi_lcdDrawImage ((void *) color_p, (void *)(dsi_getActiveFrameBuffer () + offsetPos), width, height, DMA2D_INPUT_RGB565);
198- lv_disp_flush_ready (disp); /* Indicate you are ready with the flushing*/
203+ // TODO: find a smart way to tackle sw rotation
204+ /*
205+ if (lv_display_get_rotation(disp) != LV_DISPLAY_ROTATION_0) {
206+ if (dst != nullptr) {
207+ free(dst);
208+ }
209+ dst = (uint8_t*)malloc(width * height * 2);
210+ lv_draw_sw_rotate(px_map, dst, height, width,
211+ height * 2,
212+ width * 2,
213+ lv_display_get_rotation(disp), LV_COLOR_FORMAT_RGB565);
214+ px_map = dst;
215+ }
216+ */
217+
218+ dsi_lcdDrawImage ((void *) px_map, (void *)(dsi_getActiveFrameBuffer () + offsetPos), width, height, DMA2D_INPUT_RGB565);
219+ lv_display_flush_ready (disp); /* Indicate you are ready with the flushing*/
199220}
200221#endif
201222
0 commit comments