Skip to content

Commit d9e1757

Browse files
Merge pull request #1015 from dmazzella/patch-1
Arduino_H7_Video: handling errors at initialization time
2 parents f9744ff + 0255e38 commit d9e1757

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

libraries/Arduino_H7_Video/src/Arduino_H7_Video.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ int Arduino_H7_Video::begin() {
9595
#endif
9696

9797
/* Video controller/bridge init */
98-
_shield->init(_edidMode);
98+
int err_code = _shield->init(_edidMode);
99+
if (err_code < 0) {
100+
return 3; /* Video controller fail init */
101+
}
99102

100103
#if __has_include("lvgl.h")
101104
/* Initiliaze LVGL library */

libraries/Arduino_H7_Video/src/H7DisplayShield.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,22 @@ int USBCVideoClass::init(int edidmode) {
3131
}
3232

3333
//Checking HDMI plug event
34-
anx7625_wait_hpd_event(0);
34+
err_code = anx7625_wait_hpd_event(0);
35+
if(err_code < 0) {
36+
return err_code;
37+
}
3538

3639
//Read EDID
37-
anx7625_dp_get_edid(0, &recognized_edid);
40+
err_code = anx7625_dp_get_edid(0, &recognized_edid);
41+
if(err_code < 0) {
42+
return err_code;
43+
}
3844

3945
//DSI Configuration
40-
anx7625_dp_start(0, &recognized_edid, (enum edid_modes) edidmode);
46+
err_code = anx7625_dp_start(0, &recognized_edid, (enum edid_modes) edidmode);
47+
if(err_code < 0) {
48+
return err_code;
49+
}
4150

4251
return 0;
4352
}

libraries/Arduino_H7_Video/src/anx7625.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -520,15 +520,21 @@ int anx7625_init(uint8_t bus) {
520520
return 0;
521521
}
522522

523-
void anx7625_wait_hpd_event(uint8_t bus) {
523+
int anx7625_wait_hpd_event(uint8_t bus) {
524524
ANXINFO("Waiting for HDMI hot plug event...\n");
525-
526-
while (1) {
525+
526+
int retry_hpd_change = 10000;
527+
while (--retry_hpd_change) {
527528
mdelay(10);
528529
int detected = anx7625_hpd_change_detect(bus);
529-
if (detected == 1)
530-
break;
530+
if (detected < 0)
531+
return -1;
532+
if (detected > 0)
533+
return 0;
531534
}
535+
536+
ANXERROR("Timed out to detect HPD change on bus %d.\n", bus);
537+
return -1;
532538
}
533539

534540
int anx7625_get_cc_status(uint8_t bus, uint8_t *cc_status) {

libraries/Arduino_H7_Video/src/anx7625.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern "C" {
2020
int anx7625_dp_start(uint8_t bus, const struct edid *edid, enum edid_modes mode = EDID_MODE_AUTO);
2121
int anx7625_dp_get_edid(uint8_t bus, struct edid *out);
2222
int anx7625_init(uint8_t bus);
23-
void anx7625_wait_hpd_event(uint8_t bus);
23+
int anx7625_wait_hpd_event(uint8_t bus);
2424
int anx7625_get_cc_status(uint8_t bus, uint8_t *cc_status);
2525
int anx7625_read_system_status(uint8_t bus, uint8_t *sys_status);
2626
bool anx7625_is_power_provider(uint8_t bus);

0 commit comments

Comments
 (0)