@@ -38,6 +38,7 @@ extern "C" {
3838/* Private function prototypes -----------------------------------------------*/
3939#if __has_include ("lvgl.h")
4040#include " mbed.h"
41+ #if (LVGL_VERSION_MAJOR == 9)
4142void lvgl_displayFlushing (lv_display_t * display, const lv_area_t * area, unsigned char * px_map);
4243static void inc_thd () {
4344 while (1 ) {
@@ -46,6 +47,9 @@ static void inc_thd() {
4647 }
4748}
4849static rtos::Thread lvgl_inc_thd;
50+ #else
51+ void lvgl_displayFlushing (lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p);
52+ #endif
4953#endif
5054
5155/* Functions -----------------------------------------------------------------*/
@@ -92,6 +96,8 @@ int Arduino_H7_Video::begin() {
9296 /* Initiliaze LVGL library */
9397 lv_init ();
9498
99+
100+ #if (LVGL_VERSION_MAJOR == 9)
95101 /* Create a draw buffer */
96102 static lv_color_t * buf1 = (lv_color_t *)malloc ((width () * height () / 10 )); /* Declare a buffer for 1/10 screen size */
97103 if (buf1 == NULL ) {
@@ -114,6 +120,36 @@ int Arduino_H7_Video::begin() {
114120 lv_display_set_flush_cb (display, lvgl_displayFlushing);
115121
116122 lvgl_inc_thd.start (inc_thd);
123+
124+ #else // LVGL_VERSION_MAJOR
125+
126+ /* Create a draw buffer */
127+ static lv_disp_draw_buf_t draw_buf;
128+ static lv_color_t * buf1;
129+ buf1 = (lv_color_t *)malloc ((width () * height () / 10 ) * sizeof (lv_color_t )); /* Declare a buffer for 1/10 screen size */
130+ if (buf1 == NULL ) {
131+ return 2 ; /* Insuff memory err */
132+ }
133+ lv_disp_draw_buf_init (&draw_buf, buf1, NULL , width () * height () / 10 ); /* Initialize the display buffer. */
134+
135+ /* Initialize display features for LVGL library */
136+ static lv_disp_drv_t disp_drv; /* Descriptor of a display driver */
137+ lv_disp_drv_init (&disp_drv); /* Basic initialization */
138+ disp_drv.flush_cb = lvgl_displayFlushing; /* Set your driver function */
139+ disp_drv.draw_buf = &draw_buf; /* Assign the buffer to the display */
140+ if (_rotated) {
141+ disp_drv.hor_res = height (); /* Set the horizontal resolution of the display */
142+ disp_drv.ver_res = width (); /* Set the vertical resolution of the display */
143+ disp_drv.rotated = LV_DISP_ROT_270;
144+ } else {
145+ disp_drv.hor_res = width (); /* Set the horizontal resolution of the display */
146+ disp_drv.ver_res = height (); /* Set the vertical resolution of the display */
147+ disp_drv.rotated = LV_DISP_ROT_NONE;
148+ }
149+ disp_drv.sw_rotate = 1 ;
150+ lv_disp_drv_register (&disp_drv); /* Finally register the driver */
151+
152+ #endif
117153 #endif
118154
119155 /* Configure SDRAM */
@@ -194,6 +230,7 @@ void Arduino_H7_Video::set(int x, int y, uint8_t r, uint8_t g, uint8_t b) {
194230#endif
195231
196232#if __has_include("lvgl.h")
233+ #if (LVGL_VERSION_MAJOR == 9)
197234static uint8_t * rotated_buf = nullptr ;
198235void lvgl_displayFlushing (lv_display_t * disp, const lv_area_t * area, unsigned char * px_map) {
199236 uint32_t w = lv_area_get_width (area);
@@ -228,6 +265,16 @@ void lvgl_displayFlushing(lv_display_t * disp, const lv_area_t * area, unsigned
228265 dsi_lcdDrawImage ((void *) px_map, (void *)(dsi_getActiveFrameBuffer () + offsetPos), w, h, DMA2D_INPUT_RGB565);
229266 lv_display_flush_ready (disp); /* Indicate you are ready with the flushing*/
230267}
268+ #else
269+ void lvgl_displayFlushing (lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) {
270+ uint32_t width = lv_area_get_width (area);
271+ uint32_t height = lv_area_get_height (area);
272+ uint32_t offsetPos = (area->x1 + (dsi_getDisplayXSize () * area->y1 )) * sizeof (uint16_t );
273+
274+ dsi_lcdDrawImage ((void *) color_p, (void *)(dsi_getActiveFrameBuffer () + offsetPos), width, height, DMA2D_INPUT_RGB565);
275+ lv_disp_flush_ready (disp); /* Indicate you are ready with the flushing*/
276+ }
277+ #endif
231278#endif
232279
233280/* *** END OF FILE ****/
0 commit comments