52 lines
1.0 KiB
C++
52 lines
1.0 KiB
C++
#ifndef TCS_BUS_H_
|
|
#define TCS_BUS_H_ 1
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
|
|
class TcsBus {
|
|
public:
|
|
struct EventData_t;
|
|
typedef struct EventData_t {
|
|
void (*func)(const EventData_t* evt);
|
|
const uint8_t* bits;
|
|
size_t bitCount;
|
|
} EventData_t;
|
|
|
|
TcsBus(int sendPin, int receivePin);
|
|
void begin();
|
|
void end();
|
|
void TimeBase();
|
|
void RegisterDefaultRxEvent(EventData_t* evt);
|
|
void RegisterEvent(const EventData_t* evt);
|
|
void UnRegisterEvent(const EventData_t* evt);
|
|
|
|
bool StartTransmit(EventData_t* evt);
|
|
|
|
private:
|
|
void EnterWaitIdle();
|
|
void ReceiveBit(uint8_t currentBit);
|
|
void TransmitBit();
|
|
void WaitIdle();
|
|
int sendPin;
|
|
int receivePin;
|
|
|
|
enum class SamplingState
|
|
{
|
|
IDLE = 0,
|
|
RECEIVE = 1,
|
|
TRANSMIT = 2,
|
|
WAIT_IDLE = 3,
|
|
};
|
|
|
|
SamplingState state;
|
|
uint8_t rxBits[256];
|
|
uint16_t currentBitIndex;
|
|
uint8_t oversamplingStep;
|
|
uint8_t oversamplingSum;
|
|
std::vector<const EventData_t*> events;
|
|
EventData_t* defaultRxEvent;
|
|
EventData_t* txEvent;
|
|
};
|
|
|
|
#endif //TCS_BUS_H_
|