@@ -37,8 +37,20 @@ extern "C" {
3737
3838/* Private function prototypes -----------------------------------------------*/
3939#if __has_include ("lvgl.h")
40+ #include " mbed.h"
41+ #if (LVGL_VERSION_MAJOR == 9)
42+ void lvgl_displayFlushing (lv_display_t * display, const lv_area_t * area, unsigned char * px_map);
43+ static void inc_thd () {
44+ while (1 ) {
45+ lv_tick_inc (16 );
46+ delay (16 );
47+ }
48+ }
49+ static rtos::Thread lvgl_inc_thd;
50+ #else
4051void lvgl_displayFlushing (lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p);
4152#endif
53+ #endif
4254
4355/* Functions -----------------------------------------------------------------*/
4456Arduino_H7_Video::Arduino_H7_Video (int width, int height, H7DisplayShield &shield)
@@ -84,9 +96,36 @@ int Arduino_H7_Video::begin() {
8496 /* Initiliaze LVGL library */
8597 lv_init ();
8698
99+
100+ #if (LVGL_VERSION_MAJOR == 9)
87101 /* Create a draw buffer */
102+ static lv_color_t * buf1 = (lv_color_t *)malloc ((width () * height () / 10 )); /* Declare a buffer for 1/10 screen size */
103+ if (buf1 == NULL ) {
104+ return 2 ; /* Insuff memory err */
105+ }
106+ static lv_color_t * buf2 = (lv_color_t *)malloc ((width () * height () / 10 )); /* Declare a buffer for 1/10 screen size */
107+ if (buf2 == NULL ) {
108+ return 2 ; /* Insuff memory err */
109+ }
110+
111+ lv_display_t *display;
112+ if (_rotated) {
113+ display = lv_display_create (height (), width ());
114+ lv_display_set_rotation (display, LV_DISPLAY_ROTATION_270);
115+ // display->sw_rotate = 1;
116+ } else {
117+ display = lv_display_create (width (), height ());
118+ }
119+ lv_display_set_buffers (display, buf1, NULL , width () * height () / 10 , LV_DISPLAY_RENDER_MODE_PARTIAL); /* Initialize the display buffer.*/
120+ lv_display_set_flush_cb (display, lvgl_displayFlushing);
121+
122+ lvgl_inc_thd.start (inc_thd);
123+
124+ #else // LVGL_VERSION_MAJOR
125+
126+ /* Create a draw buffer */
88127 static lv_disp_draw_buf_t draw_buf;
89- static lv_color_t * buf1;
128+ static lv_color_t * buf1;
90129 buf1 = (lv_color_t *)malloc ((width () * height () / 10 ) * sizeof (lv_color_t )); /* Declare a buffer for 1/10 screen size */
91130 if (buf1 == NULL ) {
92131 return 2 ; /* Insuff memory err */
@@ -109,6 +148,8 @@ int Arduino_H7_Video::begin() {
109148 }
110149 disp_drv.sw_rotate = 1 ;
111150 lv_disp_drv_register (&disp_drv); /* Finally register the driver */
151+
152+ #endif
112153 #endif
113154
114155 /* Configure SDRAM */
@@ -189,6 +230,42 @@ void Arduino_H7_Video::set(int x, int y, uint8_t r, uint8_t g, uint8_t b) {
189230#endif
190231
191232#if __has_include("lvgl.h")
233+ #if (LVGL_VERSION_MAJOR == 9)
234+ static uint8_t * rotated_buf = nullptr ;
235+ void lvgl_displayFlushing (lv_display_t * disp, const lv_area_t * area, unsigned char * px_map) {
236+ uint32_t w = lv_area_get_width (area);
237+ uint32_t h = lv_area_get_height (area);
238+ lv_area_t * area_in_use = (lv_area_t *)area;
239+
240+ // TODO: find a smart way to tackle sw rotation
241+ lv_display_rotation_t rotation = lv_display_get_rotation (disp);
242+ lv_area_t rotated_area;
243+ if (rotation != LV_DISPLAY_ROTATION_0) {
244+ rotated_buf = (uint8_t *)realloc (rotated_buf, w * h * 4 );
245+ lv_color_format_t cf = lv_display_get_color_format (disp);
246+ lv_draw_sw_rotate (px_map, rotated_buf,
247+ w, h, lv_draw_buf_width_to_stride (w, cf),
248+ lv_draw_buf_width_to_stride (h, cf),
249+ LV_DISPLAY_ROTATION_90, cf);
250+ rotated_area.x1 = lv_display_get_vertical_resolution (disp) - area->y2 - 1 ;
251+ rotated_area.y1 = area->x1 ;
252+ // rotated_area.y2 = dsi_getDisplayYSize() - area->x1 - 1;
253+ rotated_area.x2 = rotated_area.x1 + h - 1 ;
254+ rotated_area.y2 = rotated_area.y1 + w + 1 ;
255+
256+ area_in_use = &rotated_area;
257+ px_map = rotated_buf;
258+ auto temp = w;
259+ w = h;
260+ h = temp;
261+ }
262+
263+ uint32_t offsetPos = (area_in_use->x1 + (dsi_getDisplayXSize () * area_in_use->y1 )) * sizeof (uint16_t );
264+
265+ dsi_lcdDrawImage ((void *) px_map, (void *)(dsi_getActiveFrameBuffer () + offsetPos), w, h, DMA2D_INPUT_RGB565);
266+ lv_display_flush_ready (disp); /* Indicate you are ready with the flushing*/
267+ }
268+ #else
192269void lvgl_displayFlushing (lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) {
193270 uint32_t width = lv_area_get_width (area);
194271 uint32_t height = lv_area_get_height (area);
@@ -198,5 +275,6 @@ void lvgl_displayFlushing(lv_disp_drv_t * disp, const lv_area_t * area, lv_color
198275 lv_disp_flush_ready (disp); /* Indicate you are ready with the flushing*/
199276}
200277#endif
278+ #endif
201279
202280/* *** END OF FILE ****/
0 commit comments