Skip to content

Commit 9cf2cb5

Browse files
leonardocavagnisfacchinm
authored andcommitted
auto manage of landscape and portrait mode in Arduino_H7_Video library
1 parent 454c852 commit 9cf2cb5

File tree

7 files changed

+57
-32
lines changed

7 files changed

+57
-32
lines changed

libraries/Arduino_H7_Video/examples/ArduinoLogo/ArduinoLogo.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
INCBIN(test, "/home/user/Downloads/test.bin");
1717
*/
1818

19-
Arduino_H7_Video Display(480, 800, GIGA_DISPLAY_SHIELD);
19+
Arduino_H7_Video Display(800, 480, GIGA_DISPLAY_SHIELD);
2020
//Arduino_H7_Video Display(720, 480);
2121

2222
void setup() {
2323
Display.begin();
2424

2525
Image img_arduinologo(ENCODING_RGB16, (uint8_t *) texture_raw, 300, 300);
2626
Display.beginDraw();
27-
Display.image(img_arduinologo, (Display.height() - img_arduinologo.width())/2, (Display.width() - img_arduinologo.height())/2);
27+
Display.image(img_arduinologo, (Display.width() - img_arduinologo.width())/2, (Display.height() - img_arduinologo.height())/2);
2828
Display.endDraw();
2929
}
3030

libraries/Arduino_H7_Video/examples/ArduinoLogoDrawing/ArduinoLogoDrawing.ino

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "Arduino_H7_Video.h"
99

10-
Arduino_H7_Video Display(480, 800, GIGA_DISPLAY_SHIELD);
10+
Arduino_H7_Video Display(800, 480, GIGA_DISPLAY_SHIELD);
1111
//Arduino_H7_Video Display(720, 480);
1212

1313
void setup() {
@@ -17,19 +17,19 @@ void setup() {
1717
Display.background(255, 255, 255);
1818
Display.clear();
1919
Display.fill(0x008184);
20-
Display.circle(Display.height()/2, Display.width()/2, 300);
20+
Display.circle(Display.width()/2, Display.height()/2, 300);
2121
Display.stroke(255, 255, 255);
2222
Display.noFill();
2323
for (int i=0; i<30; i++) {
24-
Display.circle((Display.height()/2)-55+5, Display.width()/2, 110-i);
25-
Display.circle((Display.height()/2)+55-5, Display.width()/2, 110-i);
24+
Display.circle((Display.width()/2)-55+5, Display.height()/2, 110-i);
25+
Display.circle((Display.width()/2)+55-5, Display.height()/2, 110-i);
2626
}
2727
Display.fill(255, 255, 255);
28-
Display.rect((Display.height()/2)-55-16+5, (Display.width()/2)-5, 32, 10);
28+
Display.rect((Display.width()/2)-55-16+5, (Display.height()/2)-5, 32, 10);
2929
Display.fill(255, 255, 255);
30-
Display.rect((Display.height()/2)+55-16-5, (Display.width()/2)-5, 32, 10);
30+
Display.rect((Display.width()/2)+55-16-5, (Display.height()/2)-5, 32, 10);
3131
Display.fill(255, 255, 255);
32-
Display.rect((Display.height()/2)+55-5-5, (Display.width()/2)-16, 10, 32);
32+
Display.rect((Display.width()/2)+55-5-5, (Display.height()/2)-16, 10, 32);
3333
Display.endDraw();
3434
}
3535

libraries/Arduino_H7_Video/examples/LVGLDemo/LVGLDemo.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "lvgl.h"
1212
#include "giga_touch.h"
1313

14-
Arduino_H7_Video Display(480, 800, GIGA_DISPLAY_SHIELD);
14+
Arduino_H7_Video Display(800, 480, GIGA_DISPLAY_SHIELD);
1515
//Arduino_H7_Video Display(720, 480);
1616

1717
//@TODO: Complete demo with 4 main features

libraries/Arduino_H7_Video/src/Arduino_H7_Video.cpp

+37-21
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,13 @@ void lvgl_displayFlushing(lv_disp_drv_t * disp, const lv_area_t * area, lv_color
3030
Arduino_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

3536
Arduino_H7_Video::~Arduino_H7_Video() {
3637
}
3738

3839
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) {
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

143140
void 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

148155
void 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")
164180
void 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*/

libraries/Arduino_H7_Video/src/Arduino_H7_Video.h

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class Arduino_H7_Video : public ArduinoGraphics {
3131
virtual ~Arduino_H7_Video();
3232

3333
int begin();
34-
int begin(bool landscape);
3534
void end();
3635

3736
void clear();

libraries/Arduino_H7_Video/src/dsi.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,14 @@ uint32_t dsi_getCurrentFrameBuffer() {
333333
return pend_buffer ? FB_ADDRESS_0 : FB_ADDRESS_1;
334334
}
335335

336+
uint32_t dsi_getDisplayXSize(){
337+
return lcd_x_size;
338+
}
339+
340+
uint32_t dsi_getDisplayYSize(){
341+
return lcd_y_size;
342+
}
343+
336344
void dsi_layerInit(uint16_t LayerIndex, uint32_t FB_Address) {
337345
LTDC_LayerCfgTypeDef Layercfg;
338346

libraries/Arduino_H7_Video/src/dsi.h

+2
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ void dsi_configueCLUT(uint32_t* clut);
3939
uint32_t dsi_getNextFrameBuffer(void);
4040
uint32_t dsi_getCurrentFrameBuffer(void);
4141
uint32_t dsi_getFramebufferEnd(void);
42+
uint32_t dsi_getDisplayXSize(void);
43+
uint32_t dsi_getDisplayYSize(void);
4244

4345
#endif /* _DSI_H */

0 commit comments

Comments
 (0)