fixed some issue with SoftI2C not working (missing delay)

added code for a waveshare eInk
refactored some old code to match with the new SoftI2C
This commit is contained in:
2020-10-18 10:49:59 +02:00
parent 9c94faa24d
commit ac74587ee7
7 changed files with 426 additions and 44 deletions

View File

@@ -15,6 +15,7 @@ template <int PIN_SDA, int PIN_SCL, bool fast> class SoftI2C {
inline void sdaDirIn() {MyGPIO::setInput(PIN_SDA);}
inline void sclDirOut() {MyGPIO::setOutput(PIN_SCL);}
inline void sclDirIn() {MyGPIO::setInput(PIN_SCL);}
inline void sdaHi() {MyGPIO::set(PIN_SDA);}
inline void sdaLo() {MyGPIO::clear(PIN_SDA);}
@@ -29,7 +30,7 @@ template <int PIN_SDA, int PIN_SCL, bool fast> class SoftI2C {
__asm__ __volatile__("nop");
}
} else {
for (uint16_t i = 0; i < 1024; ++i) {
for (uint16_t i = 0; i < 2048; ++i) {
__asm__ __volatile__("nop");
}
}
@@ -92,7 +93,8 @@ public:
waitLong();
sdaHi();
sdaDirIn(); // free the bus
sdaDirIn(); // free the bus
sclDirIn(); // TESTING. free the bus
waitLong();
@@ -147,6 +149,17 @@ public:
stop();
return ok;
}
inline void queryAll() {
debugMod(NAME, "queryAll()")
for (uint8_t i = 0; i < 128; ++i) {
if (query(i)) {
debugMod1(NAME, "found %d", i)
}
waitLong();
if (i%16 == 0) {vTaskDelay(100 / portTICK_PERIOD_MS);}
}
}
@@ -166,14 +179,14 @@ public:
// select register(s) to read
ok = startWrite(addr);
if (!ok) {debugMod(NAME, "failed start write(1)"); return false;}
if (!ok) {debugMod(NAME, "failed start read(1)"); return false;}
ok = writeByteAndCheck(reg);
if (!ok) {debugMod(NAME, "failed select register"); return false;}
stop();
// read register(s)
ok = startRead(addr);
if (!ok) {debugMod(NAME, "failed start write(2)"); return false;}
if (!ok) {debugMod(NAME, "failed start read(2)"); return false;}
readBytes(dst, len);
stop();
@@ -215,6 +228,7 @@ private:
inline void _writeBit(const bool out) {
//sdaDirOut(); // switch to output mode
if(out) {sdaHi();} else {sdaLo();} // apply data
waitShort(); // wait for data to settle. IMPORTANT!
sclHi(); // clock pulse
waitShort();
sclLo();
@@ -254,6 +268,7 @@ private:
inline bool _readAck() {
sdaDirIn(); // switch to input mode
const uint8_t res = _readBit();
//printf("%d\n", res);
return res == 0; // ACK when input pulled low
}

View File

@@ -5,8 +5,6 @@
#include "../Platforms.h"
#include "../Debug.h"
#pragma GCC push_options
#pragma GCC optimize ("O2")