mirror of https://github.com/EspoTek/Labrador.git
i2c decoder no longer tries to read invalid buffer region
This commit is contained in:
parent
d65b647ab4
commit
0f00af0c08
|
@ -7,7 +7,8 @@ static const uint32_t kClockMultiplier = 10;
|
|||
i2cDecoder::i2cDecoder(isoBuffer* sda_in, isoBuffer* scl_in, uint32_t clockRate) :
|
||||
QObject(nullptr),
|
||||
sda(sda_in),
|
||||
scl(scl_in)
|
||||
scl(scl_in),
|
||||
serialPtr_bit(sda->back * 8)
|
||||
{
|
||||
setStepSize(clockRate, kClockMultiplier);
|
||||
}
|
||||
|
@ -20,7 +21,10 @@ void i2cDecoder::run()
|
|||
updateBitValues();
|
||||
runStateMachine();
|
||||
serialPtr_bit += stepSize;
|
||||
qDebug() << serialPtr_bit;
|
||||
if (serialPtr_bit > (sda->bufferEnd * 8)){
|
||||
serialPtr_bit -= (sda->bufferEnd * 8);
|
||||
}
|
||||
// qDebug () << serialPtr_bit;
|
||||
currentStepIndex = (currentStepIndex + 1) % stepsPerBit;
|
||||
}
|
||||
}
|
||||
|
@ -36,13 +40,14 @@ int i2cDecoder::serialDistance(isoBuffer* buffer)
|
|||
}
|
||||
|
||||
void i2cDecoder::updateBitValues(){
|
||||
previousSdaValue = currentSdaValue;
|
||||
previousSclValue = currentSclValue;
|
||||
|
||||
int coord_byte = serialPtr_bit/8;
|
||||
int coord_bit = serialPtr_bit - (8*coord_byte);
|
||||
unsigned char dataByteSda = sda->buffer[coord_byte];
|
||||
unsigned char dataByteScl = scl->buffer[coord_byte];
|
||||
unsigned char mask = (1 << coord_bit);
|
||||
previousSdaValue = currentSdaValue;
|
||||
previousSclValue = currentSclValue;
|
||||
currentSdaValue = dataByteSda & mask;
|
||||
currentSclValue = dataByteScl & mask;
|
||||
}
|
||||
|
@ -64,11 +69,15 @@ void i2cDecoder::runStateMachine()
|
|||
// if (sclEdge == edge::rising || sclEdge == edge::falling)
|
||||
// qDebug() << "sclEdge";
|
||||
|
||||
qDebug() << "sdaEdge" << (uint8_t)sdaEdge << "sclEdge" << (uint8_t)sclEdge;
|
||||
// qDebug() << "sdaEdge" << (uint8_t)sdaEdge << "sclEdge" << (uint8_t)sclEdge;
|
||||
|
||||
if ((sdaEdge == edge::rising) && (sclEdge == edge::falling)) // INVALID STATE TRANSITION
|
||||
{
|
||||
state = transmissionState::unknown;
|
||||
qDebug() << "Dumping I2C state and aborting...";
|
||||
for (uint8_t i=0; i < 32; i++)
|
||||
qDebug("%x\t%x", sda->buffer[serialPtr_bit/8 - i] & 0xFF, scl->buffer[serialPtr_bit/8 - i] & 0xFF);
|
||||
throw std::runtime_error("unknown i2c transmission state");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -168,9 +177,11 @@ void i2cDecoder::stopCondition()
|
|||
currentStepIndex = 0;
|
||||
state = transmissionState::data;
|
||||
currentDataByte = 0;
|
||||
qDebug() << "Address =" << address;
|
||||
break;
|
||||
case transmissionState::data:
|
||||
state = transmissionState::idle;
|
||||
qDebug() << "Data =" << currentDataByte;
|
||||
break;
|
||||
}
|
||||
qDebug() << "I2C STOP";
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
uint8_t previousSdaValue = 0;
|
||||
uint8_t currentSclValue = 0;
|
||||
uint8_t previousSclValue = 0;
|
||||
uint64_t serialPtr_bit = 0;
|
||||
uint64_t serialPtr_bit;
|
||||
transmissionState state = transmissionState::unknown;
|
||||
|
||||
// Data Transmission
|
||||
|
|
Loading…
Reference in New Issue