From 3c1b0ca7eacb260878f260d684f9f2b53e08b198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Tue, 17 Aug 2021 11:31:42 +0200 Subject: [PATCH] =?UTF-8?q?main:=20replace=20I=C2=B2C=20library=20with=20s?= =?UTF-8?q?oftware=20implementation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/main.c b/main.c index 68a1b80..e2bc7bd 100644 --- a/main.c +++ b/main.c @@ -8,7 +8,7 @@ #include "stm8s.h" #include "main.h" -#include "i2c_master.h" +#include "softi2c_master.h" #include "eeprom_blockprog.h" // blink RUN LED to show error @@ -180,7 +180,7 @@ static bool save_edid(void) // return if succeeded static bool read_edid(void) { - if (!i2c_master_setup(5)) { + if (!softi2c_master_setup(10)) { puts("I²C setup failed"); return false; } @@ -191,12 +191,9 @@ static bool read_edid(void) uint8_t data[I2C_EEPROM_PAGE_SIZE]; // data from page bool same = false; // if the data read is the same while (!same) { // read until the data is the same - const enum i2c_master_rc rc = i2c_master_address_read(I2C_SLAVE, false, address, ARRAY_LENGTH(address), data, ARRAY_LENGTH(data)); // read I²C EEPROM data - if (I2C_MASTER_RC_NONE != rc) { - puts("I²C read failed ("); - putc('0' + rc); - putc(')'); - i2c_master_reset(); // try to clear any I²C issue + const bool rc = softi2c_master_address_read(I2C_SLAVE, address, ARRAY_LENGTH(address), data, ARRAY_LENGTH(data)); // read I²C EEPROM data + if (!rc) { + puts("I²C read failed"); return false; } // check if the data is the same and copy it to EDID @@ -209,7 +206,7 @@ static bool read_edid(void) } } } - i2c_master_release(); // release I²C again + softi2c_master_release(); // release I²C again return true; } @@ -218,7 +215,7 @@ static bool read_edid(void) // return if succeeded static bool write_edid(void) { - if (!i2c_master_setup(5)) { + if (!softi2c_master_setup(10)) { puts("I²C setup failed"); return false; } @@ -226,19 +223,14 @@ static bool write_edid(void) const uint16_t length = edid_length(); for (uint16_t i = 0; i < length; i += I2C_EEPROM_PAGE_SIZE) { const uint8_t address[] = {i}; - const enum i2c_master_rc rc = i2c_master_address_write(I2C_SLAVE, false, address, ARRAY_LENGTH(address), &edid[i], I2C_EEPROM_PAGE_SIZE); // write I²C EEPROM page - if (I2C_MASTER_RC_NONE != rc) { - puts("I²C write failed ("); - putc('0' + rc); - putc(')'); - if (I2C_MASTER_RC_BUS_ERROR == rc) { - i2c_master_reset(); // try to clear any I²C issue - } + const bool rc = softi2c_master_address_write(I2C_SLAVE, address, ARRAY_LENGTH(address), &edid[i], I2C_EEPROM_PAGE_SIZE); // write I²C EEPROM page + if (!rc) { + puts("I²C write failed"); return false; } wait_10us((5 + 1) * 100); // wait 5 ms for the page write to complete } - i2c_master_release(); // release I²C again + softi2c_master_release(); // release I²C again return true; }