Skip to content

Commit 66e3ce2

Browse files
leonardocavagnisfacchinm
authored andcommitted
add auto-detect of EDID mode for portenta H7+USB
1 parent 9cf2cb5 commit 66e3ce2

File tree

4 files changed

+83
-8
lines changed

4 files changed

+83
-8
lines changed

libraries/Arduino_H7_Video/src/Arduino_H7_Video.cpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#include "dsi.h"
1515
#include "st7701.h"
1616
#include "SDRAM.h"
17+
extern "C" {
1718
#include "video_modes.h"
19+
}
1820
#include "anx7625.h"
1921

2022
#if __has_include ("lvgl.h")
@@ -30,7 +32,29 @@ void lvgl_displayFlushing(lv_disp_drv_t * disp, const lv_area_t * area, lv_color
3032
Arduino_H7_Video::Arduino_H7_Video(int width, int heigth, DisplayShieldModel shield) :
3133
ArduinoGraphics(width, heigth) {
3234
_shield = shield;
33-
_landscape = (width >= heigth) ? true : false;
35+
36+
#if defined(ARDUINO_PORTENTA_H7_M7)
37+
if (_shield == NONE_SHIELD) {
38+
_edidMode = video_modes_get_edid(width, heigth);
39+
} else if (_shield == GIGA_DISPLAY_SHIELD) {
40+
_edidMode = EDID_MODE_480x800_60Hz;
41+
}
42+
#elif defined(ARDUINO_GIGA)
43+
_edidMode = EDID_MODE_480x800_60Hz;
44+
#endif
45+
46+
switch(_edidMode) {
47+
case EDID_MODE_640x480_60Hz ... EDID_MODE_800x600_59Hz:
48+
case EDID_MODE_1024x768_60Hz ... EDID_MODE_1920x1080_60Hz:
49+
_rotated = (width < heigth) ? true : false;
50+
break;
51+
case EDID_MODE_480x800_60Hz:
52+
_rotated = (width >= heigth) ? true : false;
53+
break;
54+
default:
55+
_rotated = false;
56+
break;
57+
}
3458
}
3559

3660
Arduino_H7_Video::~Arduino_H7_Video() {
@@ -61,20 +85,20 @@ int Arduino_H7_Video::begin() {
6185
anx7625_dp_get_edid(0, &recognized_edid);
6286

6387
//DSI Configuration
64-
anx7625_dp_start(0, &recognized_edid, EDID_MODE_720x480_60Hz);
88+
anx7625_dp_start(0, &recognized_edid, (enum edid_modes) _edidMode);
6589

6690
//Configure SDRAM
6791
SDRAM.begin(dsi_getFramebufferEnd());
6892
} else if (_shield == GIGA_DISPLAY_SHIELD) {
6993
//Init LCD Controller
70-
st7701_init(EDID_MODE_480x800_60Hz);
94+
st7701_init((enum edid_modes) _edidMode);
7195

7296
//Configure SDRAM
7397
SDRAM.begin();
7498
}
7599
#elif defined(ARDUINO_GIGA)
76100
//Init LCD Controller
77-
st7701_init(EDID_MODE_480x800_60Hz);
101+
st7701_init((enum edid_modes) _edidMode);
78102

79103
//Configure SDRAM
80104
SDRAM.begin();
@@ -101,7 +125,7 @@ int Arduino_H7_Video::begin() {
101125
lv_disp_drv_init(&disp_drv); /* Basic initialization */
102126
disp_drv.flush_cb = lvgl_displayFlushing; /* Set your driver function */
103127
disp_drv.draw_buf = &draw_buf; /* Assign the buffer to the display */
104-
if(_landscape) {
128+
if(_rotated) {
105129
disp_drv.hor_res = height(); /* Set the horizontal resolution of the display */
106130
disp_drv.ver_res = width(); /* Set the vertical resolution of the display */
107131
disp_drv.rotated = LV_DISP_ROT_270;
@@ -141,7 +165,7 @@ void Arduino_H7_Video::clear(){
141165
uint32_t bg = ArduinoGraphics::background();
142166
uint32_t x_size, y_size;
143167

144-
if(_landscape) {
168+
if(_rotated) {
145169
x_size = (height() <= dsi_getDisplayXSize())? height() : dsi_getDisplayXSize();
146170
y_size = (width() <= dsi_getDisplayYSize())? width() : dsi_getDisplayYSize();
147171
} else {
@@ -155,7 +179,7 @@ void Arduino_H7_Video::clear(){
155179
void Arduino_H7_Video::set(int x, int y, uint8_t r, uint8_t g, uint8_t b) {
156180
uint32_t x_rot, y_rot;
157181

158-
if (_landscape) {
182+
if (_rotated) {
159183
x_rot = ((height()-1) - y);
160184
y_rot = x;
161185

libraries/Arduino_H7_Video/src/Arduino_H7_Video.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class Arduino_H7_Video : public ArduinoGraphics {
4343
void attachLVGLTouchCb(void (*touch_cb)(void*,void*));
4444
private:
4545
DisplayShieldModel _shield;
46-
bool _landscape;
46+
bool _rotated;
47+
int _edidMode;
4748
};
4849

4950
#endif /* _ARDUINO_H7_VIDEO_H */

libraries/Arduino_H7_Video/src/video_modes.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,53 @@ struct envie_edid_mode envie_known_modes[NUM_KNOWN_MODES] = {
4949
.hactive = 1280, .hback_porch = 370, .hfront_porch = 110, .hsync_len = 40,
5050
.vactive = 720, .vback_porch = 30, .vfront_porch = 5, .vsync_len = 20,
5151
},
52+
[EDID_MODE_1920x1080_60Hz] = {
53+
.name = "1920x1080@60Hz", .pixel_clock = 148500, .refresh = 60,
54+
.hactive = 1920, .hback_porch = 280, .hfront_porch = 88, .hsync_len = 44,
55+
.vactive = 1080, .vback_porch = 45, .vfront_porch = 4, .vsync_len = 4,
56+
},
5257
};
5358

59+
/* Functions -----------------------------------------------------------------*/
60+
61+
enum edid_modes video_modes_get_edid(uint32_t h_check, uint32_t v_check) {
62+
int sum = 0;
63+
int sel_mode = -1;
64+
int sel_sum = 0;
65+
66+
for (int i = 0; i<NUM_KNOWN_MODES; i++) {
67+
if (h_check <= envie_known_modes[i].hactive && v_check <= envie_known_modes[i].vactive) {
68+
sum = ((int)envie_known_modes[i].hactive - h_check) +
69+
((int)envie_known_modes[i].vactive - v_check);
70+
} else {
71+
sum = -1;
72+
}
73+
74+
if (sum >= 0 && ((sel_mode == -1) || (sum < sel_sum))) {
75+
sel_mode = i;
76+
sel_sum = sum;
77+
}
78+
}
79+
80+
for (int i = 0; i<NUM_KNOWN_MODES; i++) {
81+
if (h_check <= envie_known_modes[i].vactive && v_check <= envie_known_modes[i].hactive) {
82+
sum = ((int)envie_known_modes[i].vactive - h_check) +
83+
((int)envie_known_modes[i].hactive - v_check);
84+
} else {
85+
sum = -1;
86+
}
87+
88+
if (sum >= 0 && ((sel_mode == -1) || (sum < sel_sum))) {
89+
sel_mode = i;
90+
sel_sum = sum;
91+
}
92+
}
93+
94+
if (sel_mode == -1) {
95+
sel_mode = EDID_MODE_1920x1080_60Hz;
96+
}
97+
98+
return sel_mode;
99+
}
100+
54101
/**** END OF FILE ****/

libraries/Arduino_H7_Video/src/video_modes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ struct envie_edid_mode {
3535
/* Exported variables --------------------------------------------------------*/
3636
extern struct envie_edid_mode envie_known_modes[];
3737

38+
/* Exported functions --------------------------------------------------------*/
39+
enum edid_modes video_modes_get_edid(uint32_t h_check, uint32_t v_check);
40+
3841
#endif /* _VIDEO_MODES_H */

0 commit comments

Comments
 (0)