diff --git a/main.c b/main.c index f83649c..1e87483 100644 --- a/main.c +++ b/main.c @@ -8,6 +8,7 @@ #include "stm8s.h" #include "main.h" +#include "softi2c_master.h" #define EEPROM_ADDR 0x4000 // EEPROM start address // LED pin (sink for on) @@ -185,9 +186,48 @@ level pulse on the Hot Plug Detect pin. This pulse shall be at least 100 msec. } rim(); // re-enable interrupts + // even if we don't pull up HPD ourself, we should be able to respond to I²C within 20 ms + puts("I²C ready\r\n"); + + // read sink EDID + if (!i2c_fwd) { // ensure we are the only master on the I²C sink lines + IWDG_KR = IWDG_KR_KEY_REFRESH; // reset watchdog + puts("reading sink EDID: "); + softi2c_master_setup(100); // start the I²C master to talk to sink + bool i2c_success = false; // if the complete read succeeded + if (!softi2c_master_start()) { // start transaction + goto i2c_end; + } + if (!softi2c_master_select_slave(0x50, true)) { // select EDID + goto i2c_end; + } + const uint8_t edid_addr = 0x00; // EDID address to read + if (!softi2c_master_write(&edid_addr, 1)) { // write address to read + goto i2c_end; + } + if (!softi2c_master_start()) { // re-start transaction + goto i2c_end; + } + if (!softi2c_master_select_slave(0x50, false)) { // re-select EDID + goto i2c_end; + } + uint8_t edid_sink[256]; // buffer for sink EDID + if (!softi2c_master_read(edid_sink, ARRAY_LENGTH(edid_sink))) { // read EDID + goto i2c_end; + } + i2c_success = true; // complete read succeeded +i2c_end: + softi2c_master_stop(); + if (i2c_success) { + puts("success\r\n"); + } else { + puts("fail\r\n"); + } + } + bool action = false; // if an action has been performed LED_PORT->ODR.reg &= ~LED_PIN; // switch LED on to indicate we are ready - puts("ready\r\n"); + puts("loop\r\n"); while (true) { IWDG_KR = IWDG_KR_KEY_REFRESH; // reset watchdog if (i2c_transaction_new) { // an I²C transaction started