Labrador/Desktop_Interface/i2cdecoder.h

79 lines
1.5 KiB
C
Raw Normal View History

2018-07-24 00:21:21 +01:00
#ifndef I2CDECODER_H
#define I2CDECODER_H
#include "isobuffer.h"
2018-11-05 23:15:48 +00:00
#include "isobufferbuffer.h"
#include <QObject>
#include <QTimer>
2018-11-05 23:15:48 +00:00
#include <mutex>
2018-07-24 00:21:21 +01:00
2018-08-08 00:19:30 +01:00
namespace i2c
{
enum class transmissionState: uint8_t
{
unknown,
2018-08-08 00:19:30 +01:00
idle,
address,
data
};
enum class edge: uint8_t
{
rising,
falling,
held_high,
held_low
};
2018-11-05 22:50:36 +00:00
constexpr uint8_t addressBitStreamLength = 9;
2018-11-05 23:46:47 +00:00
constexpr uint8_t dataBitStreamLength = 9;
constexpr uint32_t I2C_BUFFER_LENGTH = 4096;
2018-11-05 22:50:36 +00:00
2018-07-24 00:21:21 +01:00
class i2cDecoder : public QObject
{
Q_OBJECT
public:
explicit i2cDecoder(isoBuffer* sda_in, isoBuffer* scl_in, QPlainTextEdit* console_in);
// misc
2018-07-24 00:21:21 +01:00
isoBuffer* sda;
isoBuffer* scl;
2018-11-05 23:15:48 +00:00
QPlainTextEdit* console;
isoBufferBuffer* serialBuffer = nullptr;
std::mutex mutex;
QTimer *updateTimer;
// State vars
2018-08-14 08:40:55 +01:00
uint8_t currentSdaValue = 0;
uint8_t previousSdaValue = 0;
uint8_t currentSclValue = 0;
uint8_t previousSclValue = 0;
2018-11-03 23:47:25 +00:00
uint64_t serialPtr_bit = 0;
transmissionState state = transmissionState::unknown;
2018-11-05 23:15:48 +00:00
bool consoleStateInvalid;
2018-08-08 09:35:26 +01:00
// Data Transmission
2018-08-14 08:40:55 +01:00
uint8_t currentBitIndex = 0;
2018-11-05 23:46:47 +00:00
uint16_t currentBitStream;
2018-08-08 09:35:26 +01:00
// Member functions
2018-07-31 00:05:58 +01:00
void updateBitValues();
2018-08-02 09:27:09 +01:00
void runStateMachine();
void run();
int serialDistance(isoBuffer* buffer);
2018-08-08 00:19:30 +01:00
edge edgeDetection(uint8_t current, uint8_t prev);
2018-08-08 09:35:26 +01:00
void decodeAddress(edge sdaEdge, edge sclEdge);
void decodeData(edge sdaEdge, edge sclEdge);
2018-08-08 09:58:41 +01:00
void startCondition();
void stopCondition();
2018-11-03 23:47:25 +00:00
void reset();
2018-07-24 00:21:21 +01:00
signals:
public slots:
2018-11-05 23:15:48 +00:00
void updateConsole();
2018-07-24 00:21:21 +01:00
};
2018-08-08 00:19:30 +01:00
} // Namespace i2c
2018-07-24 00:21:21 +01:00
#endif // UARTSTYLEDECODER_H