-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcu_spi_magic.h
64 lines (53 loc) · 2.26 KB
/
mcu_spi_magic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef _mcu_spi_magic_
#define _mcu_spi_magic_
//#define write8(d) {Spi_Write(d);}
#define write8(d) Spi_Write(d)
#define read8(dst) { dst=Spi_Read();}
#define setWriteDir()
#define setReadDir()
#define RD_ACTIVE 0
#define RD_IDLE 0
#define WR_ACTIVE 0
#define WR_IDLE 0
#if defined(__AVR__)
#define CD_COMMAND *spicdPort &= spicdPinUnset
#define CD_DATA *spicdPort |= spicdPinSet
#define CS_ACTIVE *spicsPort &= spicsPinUnset
#define CS_IDLE *spicsPort |= spicsPinSet
#define MISO_STATE(x) { x = *spimisoPort&spimisoPinSet;}
#define MOSI_LOW *spimosiPort &= spimosiPinUnset
#define MOSI_HIGH *spimosiPort |= spimosiPinSet
#define CLK_LOW *spiclkPort &= spiclkPinUnset
#define CLK_HIGH *spiclkPort |= spiclkPinSet
#elif defined(ARDUINO_ARCH_ESP8266)
#define CD_COMMAND (digitalWrite(_cd,LOW))
#define CD_DATA (digitalWrite(_cd,HIGH))
#define CS_ACTIVE (digitalWrite(_cs,LOW))
#define CS_IDLE (digitalWrite(_cs,HIGH))
#define MISO_STATE(x) { x = digitalRead(_miso);}
#define MOSI_LOW (digitalWrite(_mosi,LOW))
#define MOSI_HIGH (digitalWrite(_mosi,HIGH))
#define CLK_LOW (digitalWrite(_clk,LOW))
#define CLK_HIGH (digitalWrite(_clk,HIGH))
#endif
#define WR_STROBE { }
#define RD_STROBE { }
//#define write16(d) { uint8_t h = (d)>>8, l = (d&0xFF); write8(h); write8(l); }
#define write16(d) write8(d>>8); write8(d)
#define read16(dst) { uint8_t hi; read8(hi); read8(dst); dst |= (hi << 8); }
//#define writeCmd8(x) { CD_COMMAND; write8(x); CD_DATA;}
#define writeCmd8(x) CD_COMMAND; write8(x)
//#define writeData8(x) { write8(x) }
#define writeData8(x) CD_DATA; write8(x)
//#define writeCmd16(x) { CD_COMMAND; write16(x); CD_DATA; }
//#define writeData16(x) { write16(x)}
#define writeCmd16(x) CD_COMMAND; write16(x)
#define writeData16(x) CD_DATA; write16(x)
//#define writeCmdData8(a, d) { CD_COMMAND; write8(a); CD_DATA; write8(d); }
//#define writeCmdData16(a, d) { \
//uint8_t hi, lo; \
// hi = (a) >> 8; lo = (a); CD_COMMAND; write8(hi); write8(lo); \
// hi = (d) >> 8; lo = (d); CD_DATA ; write8(hi); write8(lo); }
#define writeCmdData8(a, d) CD_COMMAND; write8(a); CD_DATA; write8(d)
#define writeCmdData16(a, d) CD_COMMAND; write8(a>>8); write8(a); CD_DATA; write8(d>>8); write8(d)
#endif // _mcu_spi_magic_