-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSPISlave_T4.h
55 lines (45 loc) · 1.34 KB
/
SPISlave_T4.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
#if !defined(_SPISlave_T4_H_)
#define _SPISlave_T4_H_
#include "Arduino.h"
#include "circular_buffer.h"
#include <SPI.h>
typedef enum SPI_BITS {
SPI_8_BITS = 8,
SPI_16_BITS = 16,
SPI_32_BITS = 32,
} SPI_BITS;
typedef void (*_SPI_ptr)();
#define SPISlave_T4_CLASS template<SPIClass* port = nullptr, SPI_BITS bits = SPI_8_BITS>
#define SPISlave_T4_FUNC template<SPIClass* port, SPI_BITS bits>
#define SPISlave_T4_OPT SPISlave_T4<port, bits>
extern SPIClass SPI;
class SPISlave_T4_Base {
public:
virtual void SLAVE_ISR();
};
//static SPISlave_T4_Base* _LPSPI1 = nullptr;
//static SPISlave_T4_Base* _LPSPI2 = nullptr;
//static SPISlave_T4_Base* _LPSPI3 = nullptr;
static SPISlave_T4_Base* _LPSPI4 = nullptr;
SPISlave_T4_CLASS class SPISlave_T4 : public SPISlave_T4_Base {
public:
SPISlave_T4();
void begin();
uint32_t transmitErrors();
void onReceive(_SPI_ptr handler) { _spihandler = handler; }
bool active();
bool available();
void sniffer(bool enable = 1);
void swapPins(bool enable = 1);
void pushr(uint32_t data);
uint32_t popr();
private:
_SPI_ptr _spihandler = nullptr;
void SLAVE_ISR();
int _portnum = 0;
uint32_t nvic_irq = 0;
uint32_t transmit_errors = 0;
bool sniffer_enabled = 0;
};
#include "SPISlave_T4.tpp"
#endif