LCD Driver, some teensy code, SDCard code, MBR/FAT32

This commit is contained in:
2021-02-11 20:08:25 +01:00
parent 3babe3f1ef
commit faf6e55bc5
19 changed files with 1679 additions and 25 deletions

View File

@@ -184,15 +184,19 @@
public:
static void setOutput(uint8_t pin) {pinMode(pin, OUTPUT);}
static inline void setOutput(uint8_t pin) {pinMode(pin, OUTPUT);}
static void setInput(uint8_t pin) {pinMode(pin, INPUT);}
static inline void setInput(uint8_t pin) {pinMode(pin, INPUT);}
static void clear(uint8_t pin) {digitalWriteFast(pin, 0);}
static inline void clear(uint8_t pin) {digitalWriteFast(pin, 0);}
static inline void set(uint8_t pin) {digitalWriteFast(pin, 1);}
static inline void setOrClear(uint8_t pin, uint8_t val) {digitalWriteFast(pin, val);}
static inline uint8_t get(uint8_t pin) {return digitalReadFast(pin);}
static void set(uint8_t pin) {digitalWriteFast(pin, 1);}
static uint8_t get(uint8_t pin) {return digitalReadFast(pin);}
};

View File

@@ -57,7 +57,7 @@ private:
// DEVICE specific options
memset(&devcfg, 0, sizeof(devcfg));
devcfg.clock_speed_hz = 20 * 1000 * 1000; // IMPORTANT!
devcfg.clock_speed_hz = 30 * 1000 * 1000; // IMPORTANT!
devcfg.mode = 0;
devcfg.spics_io_num = -1;//PIN_NUM_CS; // currently not used
devcfg.queue_size = 2;

View File

@@ -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

View File

@@ -6,13 +6,18 @@
#include "../Debug.h"
#pragma GCC push_options
#pragma GCC optimize ("O2")
#pragma GCC optimize ("O3")
template <int PIN_MISO, int PIN_MOSI, int PIN_CLK, bool fast> class SoftSPI {
// NOTE: the last template argument has changed from "bool fast" to "int slowdown" where 0 is now fastest!
template <int PIN_MISO, int PIN_MOSI, int PIN_CLK, int SLOWDOWN> class SoftSPI {
static constexpr const char* NAME = "softSPI";
#ifndef BIT
#define BIT(x) (1<<x)
#endif
public:
/** ctor */
@@ -21,6 +26,7 @@ public:
}
private:
void init() {
debugMod3(NAME, "init() MISO:%d MOSI:%d CLK:%d", PIN_MISO, PIN_MOSI, PIN_CLK);
if (PIN_MISO) {MyGPIO::setInput(PIN_MISO);}
@@ -30,16 +36,15 @@ private:
private:
static inline void wait() {
if (!fast) {
for (int i = 0; i < 8; ++i) {
__asm__ __volatile__("nop");
}
for (int i = 0; i < SLOWDOWN; ++i) {
__asm__ __volatile__("nop");
}
}
inline void clkLo() { MyGPIO::clear(PIN_CLK); }
inline void clkHi() { MyGPIO::set(PIN_CLK); }
static inline void clkLo() { MyGPIO::clear(PIN_CLK); }
static inline void clkHi() { MyGPIO::set(PIN_CLK); }
/** write one bit to the bus */
inline void writeBit(const bool out) {
@@ -52,7 +57,7 @@ private:
}
/** read one bit from the bus */
inline uint8_t readBit() {
static inline uint8_t readBit() {
clkHi();
wait();
const bool val = MyGPIO::get(PIN_MISO);
@@ -62,7 +67,7 @@ private:
return (val) ? 1 : 0;
}
inline uint8_t readWriteBit(const bool out) {
static inline uint8_t readWriteBit(const bool out) {
if(out) {MyGPIO::set(PIN_MOSI);} else {MyGPIO::clear(PIN_MOSI);}
wait();
clkHi();