LCD Driver, some teensy code, SDCard code, MBR/FAT32
This commit is contained in:
14
io/SoftI2C.h
14
io/SoftI2C.h
@@ -24,7 +24,7 @@ template <int PIN_SDA, int PIN_SCL, bool fast> class SoftI2C {
|
||||
inline void sclHi() {MyGPIO::set(PIN_SCL);}
|
||||
inline void sclLo() {MyGPIO::clear(PIN_SCL);}
|
||||
|
||||
inline void waitLong() {
|
||||
void waitLong() {
|
||||
if (fast) {
|
||||
for (uint8_t i = 0; i < 128; ++i) {
|
||||
__asm__ __volatile__("nop");
|
||||
@@ -36,7 +36,7 @@ template <int PIN_SDA, int PIN_SCL, bool fast> class SoftI2C {
|
||||
}
|
||||
}
|
||||
|
||||
inline void waitShort() {
|
||||
void waitShort() {
|
||||
if (fast) {
|
||||
for (uint8_t i = 0; i < 16; ++i) {
|
||||
__asm__ __volatile__("nop");
|
||||
@@ -114,13 +114,13 @@ public:
|
||||
|
||||
|
||||
// write one byte to the bus and check slave's ACK/NACK
|
||||
bool IN_FLASH writeByteAndCheck(const uint8_t byte) {
|
||||
bool writeByteAndCheck(const uint8_t byte) {
|
||||
_writeByte(byte);
|
||||
return _readAck();
|
||||
}
|
||||
|
||||
// write several bytes to the bus and check slave's ACK/NACK
|
||||
bool IN_FLASH writeBytesAndCheck(const uint8_t* src, uint8_t len) {
|
||||
bool writeBytesAndCheck(const uint8_t* src, uint8_t len) {
|
||||
while(len) {
|
||||
const bool ok = writeByteAndCheck(*src);
|
||||
if (!ok) {return false;}
|
||||
@@ -157,7 +157,7 @@ public:
|
||||
debugMod1(NAME, "found %d", i)
|
||||
}
|
||||
waitLong();
|
||||
if (i%16 == 0) {vTaskDelay(100 / portTICK_PERIOD_MS);}
|
||||
if (i%16 == 0) {delay(10);}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,9 +242,10 @@ private:
|
||||
sclHi(); // clock pulse and read
|
||||
waitShort();
|
||||
const uint8_t val = sdaRead();
|
||||
waitShort();
|
||||
sclLo();
|
||||
waitShort();
|
||||
return val;
|
||||
return val ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -267,6 +268,7 @@ private:
|
||||
|
||||
inline bool _readAck() {
|
||||
sdaDirIn(); // switch to input mode
|
||||
waitShort();
|
||||
const uint8_t res = _readBit();
|
||||
//printf("%d\n", res);
|
||||
return res == 0; // ACK when input pulled low
|
||||
|
||||
Reference in New Issue
Block a user