LCD Driver, some teensy code, SDCard code, MBR/FAT32
This commit is contained in:
25
io/SoftSPI.h
25
io/SoftSPI.h
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user