@@ -30,20 +30,13 @@ void lvgl_displayFlushing(lv_disp_drv_t * disp, const lv_area_t * area, lv_color
30
30
Arduino_H7_Video::Arduino_H7_Video (int width, int heigth, DisplayShieldModel shield) :
31
31
ArduinoGraphics(width, heigth) {
32
32
_shield = shield;
33
+ _landscape = (width >= heigth) ? true : false ;
33
34
}
34
35
35
36
Arduino_H7_Video::~Arduino_H7_Video () {
36
37
}
37
38
38
39
int 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) {
47
40
if (!ArduinoGraphics::begin ()) {
48
41
return 0 ;
49
42
}
@@ -89,8 +82,6 @@ int Arduino_H7_Video::begin(bool landscape) {
89
82
#error Board not compatible with this library
90
83
#endif
91
84
92
- _landscape = landscape;
93
-
94
85
dsi_lcdClear (0 );
95
86
96
87
#if __has_include("lvgl.h")
@@ -106,13 +97,19 @@ int Arduino_H7_Video::begin(bool landscape) {
106
97
lv_disp_draw_buf_init (&draw_buf, buf1, NULL , width () * height () / 10 ); /* Initialize the display buffer. */
107
98
108
99
/* 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
+ }
116
113
disp_drv.sw_rotate = 1 ;
117
114
lv_disp_drv_register (&disp_drv); /* Finally register the driver */
118
115
#endif
@@ -142,29 +139,48 @@ void Arduino_H7_Video::endDraw() {
142
139
143
140
void Arduino_H7_Video::clear (){
144
141
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);
146
153
}
147
154
148
155
void Arduino_H7_Video::set (int x, int y, uint8_t r, uint8_t g, uint8_t b) {
149
156
uint32_t x_rot, y_rot;
150
157
151
158
if (_landscape) {
152
- x_rot = ((width ()-1 ) - y);
159
+ x_rot = ((height ()-1 ) - y);
153
160
y_rot = x;
161
+
162
+ if (x_rot >= height () || y_rot >= width ())
163
+ return ;
154
164
} else {
155
165
x_rot = x;
156
166
y_rot = y;
167
+
168
+ if (x_rot >= width () || y_rot >= height ())
169
+ return ;
157
170
}
158
171
172
+ if (x_rot >= dsi_getDisplayXSize () || y_rot >= dsi_getDisplayYSize ())
173
+ return ;
174
+
159
175
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);
161
177
}
162
178
163
179
#if __has_include("lvgl.h")
164
180
void lvgl_displayFlushing (lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) {
165
181
uint32_t width = lv_area_get_width (area);
166
182
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 );
168
184
169
185
dsi_lcdDrawImage ((void *) color_p, (void *)(dsi_getCurrentFrameBuffer () + offsetPos), width, height, DMA2D_INPUT_RGB565);
170
186
lv_disp_flush_ready (disp); /* Indicate you are ready with the flushing*/
0 commit comments