worked on RFID
worked on SPI refactoring/changes to reduce RAM section size (.text)
This commit is contained in:
43
Debug.h
43
Debug.h
@@ -3,19 +3,54 @@
|
||||
|
||||
#define DEBUG
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
extern "C" {
|
||||
#include "ets_sys.h"
|
||||
#include "c_types.h"
|
||||
#include "osapi.h"
|
||||
//#include "gpio.h"
|
||||
|
||||
//#include "os_type.h"
|
||||
//#include "user_config.h"
|
||||
#include "user_interface.h"
|
||||
//#include "wpa2_enterprise.h"
|
||||
//#include "inttypes.h"
|
||||
#include "mem.h"
|
||||
#include "espconn.h"
|
||||
|
||||
#include "ESP8266lib/c++.h"
|
||||
|
||||
#include "driver/uart.h"
|
||||
}
|
||||
|
||||
void hexdump(const uint8_t* buf, uint8_t len) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
os_printf("%02x ", buf[i]);
|
||||
}
|
||||
os_printf("\n");
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#define debug(str) os_printf(str)
|
||||
#define debugMod(module, str) os_printf("[%s] %s\n", module, str)
|
||||
#define debugMod1(module, str, val) os_printf("[%s] ", module); os_printf(str, val); os_printf("\n");
|
||||
#define IF_DEBUG(a) a
|
||||
#define debug(str) os_printf(str)
|
||||
#define debugMod(module, str) os_printf("[%s] %s\n", module, str)
|
||||
#define debugMod1(module, str, val) os_printf("[%s] ", module); os_printf(str, val); os_printf("\n");
|
||||
#define debugMod2(module, str, v1, v2) os_printf("[%s] ", module); os_printf(str, v1, v2); os_printf("\n");
|
||||
#define debugMod3(module, str, v1, v2, v3) os_printf("[%s] ", module); os_printf(str, v1, v2, v3); os_printf("\n");
|
||||
#define IF_DEBUG(a) a
|
||||
#define debugShow(buf, len) hexdump(buf,len)
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#define debug(module, str)
|
||||
#define debugMod(module, str)
|
||||
#define debugMod1(module, str, val)
|
||||
#define debugMod2(module, str, v1, v2)
|
||||
#define debugMod3(module, str, v1, v2, v3)
|
||||
#define IF_DEBUG(a)
|
||||
#define debugShow(a, b)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
166
io/SoftSPI.h
166
io/SoftSPI.h
@@ -24,7 +24,7 @@
|
||||
|
||||
#define SPI_FAST
|
||||
|
||||
class SoftSPI {
|
||||
namespace spi {
|
||||
|
||||
// MTDI GPIO12 MISO (DIN) D6
|
||||
// MTCK GPIO13 MOSI (DOUT) D7
|
||||
@@ -37,46 +37,102 @@ class SoftSPI {
|
||||
|
||||
// #define BIT(nr) (1 << 0)
|
||||
|
||||
public:
|
||||
//public:
|
||||
|
||||
SoftSPI() {
|
||||
// NOT CALLED!
|
||||
// CALL INIT() manually!
|
||||
// SoftSPI() {
|
||||
// // NOT CALLED!
|
||||
// // CALL INIT() manually!
|
||||
// }
|
||||
|
||||
// THINGS THAT SHOULD RUN FAST AND THUS BE KEPT IN RAM
|
||||
|
||||
static inline void csLo() { SPI_CS_LO; } // D8
|
||||
static inline void csHi() { SPI_CS_HI; } // D8
|
||||
|
||||
static inline void clkLo() { SPI_CLK_LO; } // D5
|
||||
static inline void clkHi() { SPI_CLK_HI; } // D5
|
||||
|
||||
static inline bool getMISO() {return SPI_MISO_READ;} // D6
|
||||
|
||||
#ifdef SPI_FAST
|
||||
static inline void wait() {
|
||||
__asm__ __volatile__("nop");
|
||||
}
|
||||
|
||||
void init() const {
|
||||
SPI_MISO_INPUT; SPI_MISO_NO_PULLUP; // D6: MISO
|
||||
SPI_MOSI_OUTPUT; // D7: MOSI
|
||||
SPI_CLK_OUTPUT; // D5: CLK
|
||||
SPI_CS_OUTPUT; // D8: CS
|
||||
static inline void waitLong() {
|
||||
os_delay_us(1);
|
||||
}
|
||||
#else
|
||||
static inline void wait() {
|
||||
os_delay_us(2);
|
||||
}
|
||||
static inline void waitLong() {
|
||||
os_delay_us(50);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void chipSelect() const {
|
||||
static void chipSelect() {
|
||||
clkLo();
|
||||
wait();
|
||||
csLo();
|
||||
waitLong();
|
||||
}
|
||||
|
||||
inline void chipDeselect() const {
|
||||
static void chipDeselect() {
|
||||
clkLo();
|
||||
wait();
|
||||
csHi();
|
||||
wait();
|
||||
|
||||
}
|
||||
|
||||
inline void csLo() const { SPI_CS_LO; } // D8
|
||||
inline void csHi() const { SPI_CS_HI; } // D8
|
||||
static inline uint8_t readWriteBit(const bool out) {
|
||||
if(out) {SPI_MOSI_HI;} else {SPI_MOSI_LO;}
|
||||
wait();
|
||||
clkHi();
|
||||
wait();
|
||||
const bool inp = getMISO();
|
||||
wait();
|
||||
clkLo();
|
||||
wait();
|
||||
return (inp) ? 1 : 0;
|
||||
}
|
||||
|
||||
inline void clkLo() const { SPI_CLK_LO; } // D5
|
||||
inline void clkHi() const { SPI_CLK_HI; } // D5
|
||||
/** write one bit to the bus */
|
||||
static inline void writeBit(const bool out) {
|
||||
if(out) {SPI_MOSI_HI;} else {SPI_MOSI_LO;}
|
||||
wait();
|
||||
clkHi();
|
||||
wait();
|
||||
clkLo();
|
||||
wait();
|
||||
}
|
||||
|
||||
inline bool getMISO() const {return SPI_MISO_READ;} // D6
|
||||
/** read one bit from the bus */
|
||||
static inline uint8_t readBit() {
|
||||
clkHi();
|
||||
wait();
|
||||
const bool val = getMISO();
|
||||
wait();
|
||||
clkLo();
|
||||
wait();
|
||||
return (val) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// THINGS THAT MAY RUN SLOWER FROM THE FLASH
|
||||
|
||||
|
||||
|
||||
static void ICACHE_FLASH_ATTR init() {
|
||||
SPI_MISO_INPUT; SPI_MISO_NO_PULLUP; // D6: MISO
|
||||
SPI_MOSI_OUTPUT; // D7: MOSI
|
||||
SPI_CLK_OUTPUT; // D5: CLK
|
||||
SPI_CS_OUTPUT; // D8: CS
|
||||
}
|
||||
|
||||
|
||||
/** read 16 bits */
|
||||
inline uint16_t readWord() const {
|
||||
static uint16_t ICACHE_FLASH_ATTR readWord() {
|
||||
return
|
||||
(readBit() << 15) |
|
||||
(readBit() << 14) |
|
||||
@@ -97,7 +153,7 @@ public:
|
||||
}
|
||||
|
||||
/** read 8 bits */
|
||||
inline uint8_t readByte() const {
|
||||
static uint8_t ICACHE_FLASH_ATTR readByte() {
|
||||
return
|
||||
(readBit() << 7) |
|
||||
(readBit() << 6) |
|
||||
@@ -109,7 +165,9 @@ public:
|
||||
(readBit() << 0);
|
||||
}
|
||||
|
||||
inline void writeWord(const uint16_t word) const {
|
||||
|
||||
|
||||
static void ICACHE_FLASH_ATTR writeWord(const uint16_t word) {
|
||||
writeBit(word & BIT(15));
|
||||
writeBit(word & BIT(14));
|
||||
writeBit(word & BIT(13));
|
||||
@@ -128,7 +186,7 @@ public:
|
||||
writeBit(word & BIT( 0));
|
||||
}
|
||||
|
||||
inline void writeByte(const uint8_t byte) const {
|
||||
static void ICACHE_FLASH_ATTR writeByte(const uint8_t byte) {
|
||||
writeBit(byte & BIT( 7));
|
||||
writeBit(byte & BIT( 6));
|
||||
writeBit(byte & BIT( 5));
|
||||
@@ -139,7 +197,7 @@ public:
|
||||
writeBit(byte & BIT( 0));
|
||||
}
|
||||
|
||||
inline uint16 readWriteWord(const uint16_t word) const {
|
||||
static uint16 ICACHE_FLASH_ATTR readWriteWord(const uint16_t word) {
|
||||
return
|
||||
(readWriteBit(word & BIT(15)) << 15) |
|
||||
(readWriteBit(word & BIT(14)) << 14) |
|
||||
@@ -159,7 +217,7 @@ public:
|
||||
(readWriteBit(word & BIT( 0)) << 0);
|
||||
}
|
||||
|
||||
inline uint8 readWriteByte(const uint8_t byte) const {
|
||||
static uint8 ICACHE_FLASH_ATTR readWriteByte(const uint8_t byte) {
|
||||
return
|
||||
(readWriteBit(byte & BIT( 7)) << 7) |
|
||||
(readWriteBit(byte & BIT( 6)) << 6) |
|
||||
@@ -171,62 +229,12 @@ public:
|
||||
(readWriteBit(byte & BIT( 0)) << 0);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
}
|
||||
|
||||
|
||||
inline uint8_t readWriteBit(const bool out) const {
|
||||
if(out) {SPI_MOSI_HI;} else {SPI_MOSI_LO;}
|
||||
wait();
|
||||
clkHi();
|
||||
wait();
|
||||
const bool inp = getMISO();
|
||||
wait();
|
||||
clkLo();
|
||||
wait();
|
||||
return (inp) ? 1 : 0;
|
||||
}
|
||||
// create an instance ONCE
|
||||
//SoftSPI spi;
|
||||
//using spi = SoftSPI;
|
||||
|
||||
/** write one bit to the bus */
|
||||
inline void writeBit(const bool out) const {
|
||||
if(out) {SPI_MOSI_HI;} else {SPI_MOSI_LO;}
|
||||
wait();
|
||||
clkHi();
|
||||
wait();
|
||||
clkLo();
|
||||
wait();
|
||||
}
|
||||
|
||||
/** read one bit from the bus */
|
||||
inline uint8_t readBit() const {
|
||||
clkHi();
|
||||
wait();
|
||||
const bool val = getMISO();
|
||||
wait();
|
||||
clkLo();
|
||||
wait();
|
||||
return (val) ? 1 : 0;
|
||||
}
|
||||
|
||||
#ifdef SPI_FAST
|
||||
inline void wait() const {
|
||||
__asm__ __volatile__("nop");
|
||||
}
|
||||
inline void waitLong() const {
|
||||
os_delay_us(1);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
inline void wait() const {
|
||||
os_delay_us(2);
|
||||
}
|
||||
inline void waitLong() const {
|
||||
os_delay_us(50);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif // SOFTSPI_H
|
||||
|
||||
Reference in New Issue
Block a user