50 lines
1.1 KiB
C++

#if !defined(_SPI2Slave_T4_H_)
#define _SPI2Slave_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 SPI2Slave_T4_CLASS template<SPIClass* port = nullptr, SPI_BITS bits = SPI_8_BITS>
#define SPI2Slave_T4_FUNC template<SPIClass* port, SPI_BITS bits>
#define SPI2Slave_T4_OPT SPI2Slave_T4<port, bits>
extern SPIClass SPI;
class SPI2Slave_T4_Base {
public:
virtual void SLAVE_ISR();
};
static SPI2Slave_T4_Base* _LPSPI1 = nullptr;
SPI2Slave_T4_CLASS class SPI2Slave_T4 : public SPI2Slave_T4_Base {
public:
SPI2Slave_T4();
void begin();
uint32_t transmitErrors();
void onReceive(_SPI_ptr handler) { _spihandler = handler; }
bool active();
bool available();
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;
};
#include "SPI2Slave_T4.tpp"
#endif