mirror of https://github.com/EspoTek/Labrador.git
more i2 skeleton
This commit is contained in:
parent
4c61a0a327
commit
634a046097
|
@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue