improve I²C master debugging
This commit is contained in:
parent
5be8874b3c
commit
03e6875a94
28
main.c
28
main.c
|
@ -51,7 +51,11 @@ void putc(char c)
|
||||||
// don't wait until the transmission is complete
|
// don't wait until the transmission is complete
|
||||||
}
|
}
|
||||||
|
|
||||||
void puts(const char* s)
|
// enable/disable UART debug
|
||||||
|
//#define puts(X) {}
|
||||||
|
#define puts(X) puts_uart(X)
|
||||||
|
|
||||||
|
void puts_uart(const char* s)
|
||||||
{
|
{
|
||||||
if (NULL == s) {
|
if (NULL == s) {
|
||||||
return;
|
return;
|
||||||
|
@ -296,32 +300,41 @@ we will only be able to provide 1 extension block since we can only respond to o
|
||||||
} else {
|
} else {
|
||||||
IWDG_KR = IWDG_KR_KEY_REFRESH; // reset watchdog
|
IWDG_KR = IWDG_KR_KEY_REFRESH; // reset watchdog
|
||||||
puts("reading sink EDID: ");
|
puts("reading sink EDID: ");
|
||||||
softi2c_master_setup(100); // start the I²C master to talk to sink
|
uint8_t i2c_rc = 1; // if the complete read succeeded
|
||||||
bool i2c_success = false; // if the complete read succeeded
|
if (!softi2c_master_setup(1)) { // start the I²C master to talk to sink
|
||||||
|
i2c_rc = 2;
|
||||||
|
goto i2c_end;
|
||||||
|
}
|
||||||
if (!softi2c_master_start()) { // start transaction
|
if (!softi2c_master_start()) { // start transaction
|
||||||
|
i2c_rc = 3;
|
||||||
goto i2c_end;
|
goto i2c_end;
|
||||||
}
|
}
|
||||||
if (!softi2c_master_select_slave(0x50, true)) { // select EDID
|
if (!softi2c_master_select_slave(0x50, true)) { // select EDID
|
||||||
|
i2c_rc = 4;
|
||||||
goto i2c_end;
|
goto i2c_end;
|
||||||
}
|
}
|
||||||
const uint8_t edid_addr = 0x00; // EDID address to read
|
const uint8_t edid_addr = 0x00; // EDID address to read
|
||||||
if (!softi2c_master_write(&edid_addr, 1)) { // write address to read
|
if (!softi2c_master_write(&edid_addr, 1)) { // write address to read
|
||||||
|
i2c_rc = 5;
|
||||||
goto i2c_end;
|
goto i2c_end;
|
||||||
}
|
}
|
||||||
if (!softi2c_master_start()) { // re-start transaction
|
if (!softi2c_master_start()) { // re-start transaction
|
||||||
|
i2c_rc = 6;
|
||||||
goto i2c_end;
|
goto i2c_end;
|
||||||
}
|
}
|
||||||
if (!softi2c_master_select_slave(0x50, false)) { // re-select EDID
|
if (!softi2c_master_select_slave(0x50, false)) { // re-select EDID
|
||||||
|
i2c_rc = 7;
|
||||||
goto i2c_end;
|
goto i2c_end;
|
||||||
}
|
}
|
||||||
uint8_t edid_sink[256]; // buffer for sink EDID
|
uint8_t edid_sink[256]; // buffer for sink EDID
|
||||||
if (!softi2c_master_read(edid_sink, ARRAY_LENGTH(edid_sink))) { // read EDID
|
if (!softi2c_master_read(edid_sink, ARRAY_LENGTH(edid_sink))) { // read EDID
|
||||||
|
i2c_rc = 8;
|
||||||
goto i2c_end;
|
goto i2c_end;
|
||||||
}
|
}
|
||||||
i2c_success = true; // complete read succeeded
|
i2c_rc = 0; // complete read succeeded
|
||||||
i2c_end:
|
i2c_end:
|
||||||
softi2c_master_stop();
|
softi2c_master_stop();
|
||||||
if (i2c_success) {
|
if (0 == i2c_rc) {
|
||||||
puts("success\r\n");
|
puts("success\r\n");
|
||||||
const uint16_t edid_len = edid_length(edid_sink); // get length
|
const uint16_t edid_len = edid_length(edid_sink); // get length
|
||||||
if (edid_len) { // EDID is valid
|
if (edid_len) { // EDID is valid
|
||||||
|
@ -394,7 +407,10 @@ level pulse on the Hot Plug Detect pin. This pulse shall be at least 100 msec.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
puts("fail\r\n");
|
LED_PORT->ODR.reg &= ~LED_PIN; // switch LED on to indicate I²C read fail
|
||||||
|
puts("fail (rc=");
|
||||||
|
putc('0' + i2c_rc);
|
||||||
|
puts(")\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue