From 634a046097bce24b21346b12494146009b6938a3 Mon Sep 17 00:00:00 2001 From: Chris Esposito Date: Thu, 2 Aug 2018 18:27:09 +1000 Subject: [PATCH] more i2 skeleton --- Desktop_Interface/i2cdecoder.cpp | 24 +++++++++++++++++++++--- Desktop_Interface/i2cdecoder.h | 11 +++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Desktop_Interface/i2cdecoder.cpp b/Desktop_Interface/i2cdecoder.cpp index 8f6d649c..f31abe6e 100644 --- a/Desktop_Interface/i2cdecoder.cpp +++ b/Desktop_Interface/i2cdecoder.cpp @@ -1,21 +1,27 @@ #include "i2cdecoder.h" -i2cDecoder::i2cDecoder(isoBuffer* sda_in, isoBuffer* scl_in) : QObject(nullptr) +i2cDecoder::i2cDecoder(isoBuffer* sda_in, isoBuffer* scl_in, uint32_t clockRate) : QObject(nullptr) { sda = sda_in; scl = scl_in; + setStepSize(clockRate); } void i2cDecoder::run() { - + while (serialDistance(sda) > SERIAL_DELAY * sda->sampleRate_bit) + { + updateBitValues(); + runStateMachine(); + serialPtr_bit += stepSize; + } } int i2cDecoder::serialDistance(isoBuffer* buffer) { int back_bit = buffer->back * 8; int bufferEnd_bit = buffer->bufferEnd * 8; - if(back_bit >= serialPtr_bit) + if (back_bit >= serialPtr_bit) return back_bit - serialPtr_bit; else return bufferEnd_bit - serialPtr_bit + back_bit; @@ -30,3 +36,15 @@ void i2cDecoder::updateBitValues(){ currentSdaValue = dataByteSda & mask; currentSclValue = dataByteScl & mask; } + +void i2cDecoder::setStepSize(uint32_t clockRate) +{ + stepSize = (double)((sda->sampleRate_bit)/clockRate)/2.0; + if (stepSize > (SERIAL_DELAY * sda->sampleRate_bit)/2) + stepSize = SERIAL_DELAY * sda->sampleRate_bit / 2; +} + +void i2cDecoder::runStateMachine() +{ + +} diff --git a/Desktop_Interface/i2cdecoder.h b/Desktop_Interface/i2cdecoder.h index 3c27bf6d..6f46166b 100644 --- a/Desktop_Interface/i2cdecoder.h +++ b/Desktop_Interface/i2cdecoder.h @@ -8,16 +8,19 @@ class i2cDecoder : public QObject { Q_OBJECT public: - explicit i2cDecoder(isoBuffer* sda_in, isoBuffer* scl_in); - void run(); - int serialDistance(isoBuffer* buffer); + explicit i2cDecoder(isoBuffer* sda_in, isoBuffer* scl_in, uint32_t clockRate); private: isoBuffer* sda; isoBuffer* scl; uint8_t currentSdaValue; uint8_t currentSclValue; - int serialPtr_bit = 0; + uint64_t serialPtr_bit = 0; void updateBitValues(); + uint32_t stepSize; + void setStepSize(uint32_t clockRate); + void runStateMachine(); + void run(); + int serialDistance(isoBuffer* buffer); signals: public slots: };