main: check writter EDID

This commit is contained in:
King Kévin 2021-08-17 08:57:48 +02:00
parent ae158d3098
commit e34fec4221
1 changed files with 36 additions and 2 deletions

38
main.c
View File

@ -372,8 +372,42 @@ void main(void)
}
} else { // button pressed > 3s
run_led_on(); // indicate we started
if (edid_valid) {
led_error = !write_edid(); // write EDID to I²C EEPROM
if (edid_valid) { // the current EDID we have is valid and is ready to be written
led_error = true; // error indication will be cleared if everything succeeded
puts("writing I²C EDID: ");
if (write_edid()) { // write EDID to I²C EEPROM succeeded
puts("OK\r\n");
const uint16_t target_length = edid_length(); // remember the length of the EDID we programmed
puts("reading back EDID: ");
if (read_edid()) { // read EDID back from I²C
puts("OK\r\n");
if (edid_length() == target_length) { // ensure the EDID length between what we programmed and read is the same
puts("verifying EDID: ");
bool identical_edid = true; // to find out if EDID is identical
for (uint16_t i = 0; i < target_length; i++) { // compare EDID
if (edid[i] != *(uint8_t*)(EEPROM_ADDR + i)) { // ensure the data is the same
identical_edid = false; // EDID is not identical
break; // stop comparing
}
}
if (identical_edid) { // EDID has been successfully programmed
puts("OK\r\n");
led_error = false; // no error happened
} else {
puts("failed (wrong data)\r\n");
}
} else {
puts("failed (not length)\r\n");
}
} else {
puts("\r\n"); // error should have been printed
}
puts("reloading EEPROM EDID\r\n");
load_edid(); // re-load EDID from EEPROM after it has been overwritten from the read
edid_valid = (0 != edid_length()); // verify if EDID is valid (should be as before
} else {
puts("\r\n"); // error should have been printed
}
} else {
puts("\r\n"); // error should have been printed
led_error = true; // we can't program an invalid EDID