@@ -30,20 +30,13 @@ void lvgl_displayFlushing(lv_disp_drv_t * disp, const lv_area_t * area, lv_color
3030Arduino_H7_Video::Arduino_H7_Video (int width, int heigth, DisplayShieldModel shield) :
3131 ArduinoGraphics(width, heigth) {
3232 _shield = shield;
33+ _landscape = (width >= heigth) ? true : false ;
3334}
3435
3536Arduino_H7_Video::~Arduino_H7_Video () {
3637}
3738
3839int Arduino_H7_Video::begin () {
39- int ret = 0 ;
40-
41- ret = begin (true );
42-
43- return ret;
44- }
45-
46- int Arduino_H7_Video::begin (bool landscape) {
4740 if (!ArduinoGraphics::begin ()) {
4841 return 0 ;
4942 }
@@ -89,8 +82,6 @@ int Arduino_H7_Video::begin(bool landscape) {
8982 #error Board not compatible with this library
9083 #endif
9184
92- _landscape = landscape;
93-
9485 dsi_lcdClear (0 );
9586
9687 #if __has_include("lvgl.h")
@@ -106,13 +97,19 @@ int Arduino_H7_Video::begin(bool landscape) {
10697 lv_disp_draw_buf_init (&draw_buf, buf1, NULL , width () * height () / 10 ); /* Initialize the display buffer. */
10798
10899 /* Initialize display features for LVGL library */
109- static lv_disp_drv_t disp_drv; /* Descriptor of a display driver */
110- lv_disp_drv_init (&disp_drv); /* Basic initialization */
111- disp_drv.flush_cb = lvgl_displayFlushing; /* Set your driver function */
112- disp_drv.draw_buf = &draw_buf; /* Assign the buffer to the display */
113- disp_drv.hor_res = width (); /* Set the horizontal resolution of the display */
114- disp_drv.ver_res = height (); /* Set the vertical resolution of the display */
115- disp_drv.rotated = (_landscape) ? LV_DISP_ROT_270 : LV_DISP_ROT_NONE;
100+ static lv_disp_drv_t disp_drv; /* Descriptor of a display driver */
101+ lv_disp_drv_init (&disp_drv); /* Basic initialization */
102+ disp_drv.flush_cb = lvgl_displayFlushing; /* Set your driver function */
103+ disp_drv.draw_buf = &draw_buf; /* Assign the buffer to the display */
104+ if (_landscape) {
105+ disp_drv.hor_res = height (); /* Set the horizontal resolution of the display */
106+ disp_drv.ver_res = width (); /* Set the vertical resolution of the display */
107+ disp_drv.rotated = LV_DISP_ROT_270;
108+ } else {
109+ disp_drv.hor_res = width (); /* Set the horizontal resolution of the display */
110+ disp_drv.ver_res = height (); /* Set the vertical resolution of the display */
111+ disp_drv.rotated = LV_DISP_ROT_NONE;
112+ }
116113 disp_drv.sw_rotate = 1 ;
117114 lv_disp_drv_register (&disp_drv); /* Finally register the driver */
118115 #endif
@@ -142,29 +139,48 @@ void Arduino_H7_Video::endDraw() {
142139
143140void Arduino_H7_Video::clear (){
144141 uint32_t bg = ArduinoGraphics::background ();
145- dsi_lcdClear (bg);
142+ uint32_t x_size, y_size;
143+
144+ if (_landscape) {
145+ x_size = (height () <= dsi_getDisplayXSize ())? height () : dsi_getDisplayXSize ();
146+ y_size = (width () <= dsi_getDisplayYSize ())? width () : dsi_getDisplayYSize ();
147+ } else {
148+ x_size = (width () <= dsi_getDisplayXSize ())? width () : dsi_getDisplayXSize ();
149+ y_size = (height () <= dsi_getDisplayYSize ())? height () : dsi_getDisplayYSize ();
150+ }
151+
152+ dsi_lcdFillArea ((void *)(dsi_getCurrentFrameBuffer ()), x_size, y_size, bg);
146153}
147154
148155void Arduino_H7_Video::set (int x, int y, uint8_t r, uint8_t g, uint8_t b) {
149156 uint32_t x_rot, y_rot;
150157
151158 if (_landscape) {
152- x_rot = ((width ()-1 ) - y);
159+ x_rot = ((height ()-1 ) - y);
153160 y_rot = x;
161+
162+ if (x_rot >= height () || y_rot >= width ())
163+ return ;
154164 } else {
155165 x_rot = x;
156166 y_rot = y;
167+
168+ if (x_rot >= width () || y_rot >= height ())
169+ return ;
157170 }
158171
172+ if (x_rot >= dsi_getDisplayXSize () || y_rot >= dsi_getDisplayYSize ())
173+ return ;
174+
159175 uint32_t color = (uint32_t )((uint32_t )(r << 16 ) | (uint32_t )(g << 8 ) | (uint32_t )(b << 0 ));
160- dsi_lcdFillArea ((void *)(dsi_getCurrentFrameBuffer () + ((x_rot + (width () * y_rot)) * sizeof (uint16_t ))), 1 , 1 , color);
176+ dsi_lcdFillArea ((void *)(dsi_getCurrentFrameBuffer () + ((x_rot + (dsi_getDisplayXSize () * y_rot)) * sizeof (uint16_t ))), 1 , 1 , color);
161177}
162178
163179#if __has_include("lvgl.h")
164180void lvgl_displayFlushing (lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) {
165181 uint32_t width = lv_area_get_width (area);
166182 uint32_t height = lv_area_get_height (area);
167- uint32_t offsetPos = (area->x1 + (disp-> hor_res * area->y1 )) * sizeof (uint16_t );
183+ uint32_t offsetPos = (area->x1 + (dsi_getDisplayXSize () * area->y1 )) * sizeof (uint16_t );
168184
169185 dsi_lcdDrawImage ((void *) color_p, (void *)(dsi_getCurrentFrameBuffer () + offsetPos), width, height, DMA2D_INPUT_RGB565);
170186 lv_disp_flush_ready (disp); /* Indicate you are ready with the flushing*/
0 commit comments