From 49148e76706e5e24c2ba7f6ccc1d7ec4736ab2f3 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 3 Mar 2021 15:24:13 +0000 Subject: support cheap chinese blue pill boards, make usb dfu compatible with dfuse --- app/i2c_bb.c | 70 +++++++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 36 deletions(-) (limited to 'app/i2c_bb.c') diff --git a/app/i2c_bb.c b/app/i2c_bb.c index f392b5e..cfa6742 100644 --- a/app/i2c_bb.c +++ b/app/i2c_bb.c @@ -106,57 +106,54 @@ static void i2c_bb_sm (int od, int d, int oc, int c) } // Check for STOP - if (oc && c && !od && d) { + if (oc && c && !od && d) state = ST_LOST; - } switch (state) { case ST_LOST: i2c_bb_sda (1); i2c_bb_scl (1); break; + case ST_ADDRESS_7...ST_ADDRESS_0: - if (! (!oc && c)) { + if (! (!oc && c)) break; - } //rising scl of a7...a0 sr = (sr << 1) | !!d; if (state == ST_ADDRESS_0) { - if ( (sr & ~I2C_READ) == OUR_ADDRESS) { + if ((sr & ~I2C_READ) == OUR_ADDRESS) { state++; rnw = d; - } else { + } else state = ST_LOST; - } - } else { + } else state++; - } break; + case ST_ADDRESS_ACK: - if (! (oc && !c)) { + if (! (oc && !c)) break; - } //falling scl of a0 i2c_bb_sda (0); - if (rnw) { + if (rnw) state++; - } else { + + else state = ST_PREP_REG_7; - } break; + case ST_OUT_7: - if (! (oc && !c)) { + if (! (oc && !c)) break; - } //falling scl of ack i2c_bb_sda (1); @@ -168,32 +165,32 @@ static void i2c_bb_sm (int od, int d, int oc, int c) i2c_bb_scl (1); state++; break; + case ST_OUT_6...ST_OUT_0: - if (! (oc && !c)) { + if (! (oc && !c)) break; - } //falling scl of d6...d0 i2c_bb_sda (sr & 0x80); sr <<= 1; state++; break; + case ST_PREP_OUT_ACK: - if (! (oc && !c)) { + if (! (oc && !c)) break; - } //falling scl of d0 i2c_bb_sda (1); state++; break; + case ST_OUT_ACK: - if (! (!oc && c)) { + if (! (!oc && c)) break; - } //rising scl of ack @@ -207,74 +204,74 @@ static void i2c_bb_sm (int od, int d, int oc, int c) } break; + case ST_PREP_REG_7: - if (! (oc && !c)) { + if (! (oc && !c)) break; - } //falling scl of ack i2c_bb_sda (1); sr = 0; state++; break; + case ST_REG_7...ST_REG_0: - if (! (!oc && c)) { + if (! (!oc && c)) break; - } //rising scl of r7..r0 sr = (sr << 1) | !!d; state++; break; + case ST_REG_ACK: - if (! (oc && !c)) { + if (! (oc && !c)) break; - } //falling scl of r0 reg = sr; i2c_bb_sda (0); state = ST_PREP_IN_7; break; + case ST_PREP_IN_7: - if (! (oc && !c)) { + if (! (oc && !c)) break; - } //falling scl of ack i2c_bb_sda (1); sr = 0; state++; break; + case ST_IN_7...ST_IN_0: - if (! (!oc && c)) { + if (! (!oc && c)) break; - } //rising scl of i7..i0 sr = (sr << 1) | !!d; state++; break; + case ST_IN_ACK: - if (! (oc && !c)) { + if (! (oc && !c)) break; - } //falling scl of i0 i2c_bb_sda (0); state++; break; + case ST_REG_WRITE: - if (! (oc && !c)) { + if (! (oc && !c)) break; - } //falling scl of ack i2c_bb_sda (1); @@ -286,6 +283,7 @@ static void i2c_bb_sm (int od, int d, int oc, int c) sr = 0; state = ST_IN_7; break; + default: state = ST_LOST; } -- cgit v1.2.3