tcs_toroeffner/source/TcsBus.h

52 lines
1.0 KiB
C
Raw Permalink Normal View History

#ifndef TCS_BUS_H_
#define TCS_BUS_H_ 1
#include <cstdint>
2022-11-14 07:55:41 +00:00
#include <vector>
class TcsBus {
public:
2022-11-14 07:55:41 +00:00
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();
2022-11-14 07:55:41 +00:00
void end();
void TimeBase();
2022-11-14 07:55:41 +00:00
void RegisterDefaultRxEvent(EventData_t* evt);
void RegisterEvent(const EventData_t* evt);
void UnRegisterEvent(const EventData_t* evt);
bool StartTransmit(EventData_t* evt);
private:
2022-11-14 07:55:41 +00:00
void EnterWaitIdle();
void ReceiveBit(uint8_t currentBit);
void TransmitBit();
void WaitIdle();
int sendPin;
int receivePin;
enum class SamplingState
{
IDLE = 0,
RECEIVE = 1,
TRANSMIT = 2,
2022-11-14 07:55:41 +00:00
WAIT_IDLE = 3,
};
SamplingState state;
2022-11-14 07:55:41 +00:00
uint8_t rxBits[256];
uint16_t currentBitIndex;
uint8_t oversamplingStep;
2022-11-14 07:55:41 +00:00
uint8_t oversamplingSum;
std::vector<const EventData_t*> events;
EventData_t* defaultRxEvent;
EventData_t* txEvent;
};
#endif //TCS_BUS_H_