mirror of https://github.com/EspoTek/Labrador.git
Started Debugging i2c
This commit is contained in:
parent
c96dd98c0f
commit
dde6d6ac42
|
@ -14,12 +14,14 @@ i2cDecoder::i2cDecoder(isoBuffer* sda_in, isoBuffer* scl_in, uint32_t clockRate)
|
|||
|
||||
void i2cDecoder::run()
|
||||
{
|
||||
qDebug() << "i2cDecoder::run()";
|
||||
while (serialDistance(sda) > SERIAL_DELAY * sda->sampleRate_bit)
|
||||
{
|
||||
updateBitValues();
|
||||
runStateMachine();
|
||||
serialPtr_bit += stepSize;
|
||||
currentStepIndex = (currentStepIndex + 1) % stepsPerBit;
|
||||
qDebug() << serialPtr_bit;
|
||||
currentStepIndex = (currentStepIndex + 1) % stepsPerBit;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +48,7 @@ void i2cDecoder::updateBitValues(){
|
|||
// Step size should be a multiple of the clock rate; we need >1 clock cycle resolution.
|
||||
void i2cDecoder::setStepSize(uint32_t clockRate, uint32_t multiplier)
|
||||
{
|
||||
stepSize = (double)((sda->sampleRate_bit)/clockRate)/(double)multiplier;
|
||||
stepSize = (double)((sda->sampleRate_bit)/clockRate)/(double)multiplier;
|
||||
stepsPerBit = multiplier;
|
||||
}
|
||||
|
||||
|
@ -54,6 +56,11 @@ void i2cDecoder::runStateMachine()
|
|||
{
|
||||
edge sdaEdge = edgeDetection(currentSdaValue, previousSdaValue);
|
||||
edge sclEdge = edgeDetection(currentSclValue, previousSclValue);
|
||||
|
||||
if (sdaEdge == edge::rising || sdaEdge == edge::falling)
|
||||
qDebug() << "sdaEdge";
|
||||
if (sclEdge == edge::rising || sclEdge == edge::falling)
|
||||
qDebug() << "sclEdge";
|
||||
|
||||
if ((sdaEdge == edge::rising) && (sclEdge == edge::falling)) // INVALID STATE TRANSITION
|
||||
{
|
||||
|
@ -94,8 +101,10 @@ edge i2cDecoder::edgeDetection(uint8_t current, uint8_t prev)
|
|||
return edge::held_low;
|
||||
if (current && !prev)
|
||||
return edge::rising;
|
||||
if (!current &&!prev)
|
||||
if (!current && prev)
|
||||
return edge::falling;
|
||||
|
||||
throw std::runtime_error("i2c Edge Detection critical failure");
|
||||
}
|
||||
|
||||
void i2cDecoder::decodeAddress(edge sdaEdge, edge sclEdge)
|
||||
|
@ -143,6 +152,7 @@ void i2cDecoder::startCondition()
|
|||
currentStepIndex = 0;
|
||||
address = 0x0000;
|
||||
state = transmissionState::address;
|
||||
qDebug() << "START";
|
||||
}
|
||||
|
||||
void i2cDecoder::stopCondition()
|
||||
|
@ -159,6 +169,7 @@ void i2cDecoder::stopCondition()
|
|||
state = transmissionState::idle;
|
||||
break;
|
||||
}
|
||||
qDebug() << "STOP";
|
||||
}
|
||||
|
||||
void i2cDecoder::dataByteCompleted(uint8_t byte, bool ACKed)
|
||||
|
|
|
@ -28,7 +28,6 @@ class i2cDecoder : public QObject
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit i2cDecoder(isoBuffer* sda_in, isoBuffer* scl_in, uint32_t clockRate);
|
||||
private:
|
||||
// misc
|
||||
isoBuffer* sda;
|
||||
isoBuffer* scl;
|
||||
|
@ -51,7 +50,7 @@ private:
|
|||
|
||||
// Member functions
|
||||
void updateBitValues();
|
||||
void setStepSize(uint32_t clockRate, uint32_t multiplier);
|
||||
void setStepSize(uint32_t clockRate, uint32_t multiplier);
|
||||
void runStateMachine();
|
||||
void run();
|
||||
int serialDistance(isoBuffer* buffer);
|
||||
|
|
|
@ -81,7 +81,7 @@ void isoDriver::timerTick(void){
|
|||
case 1:
|
||||
internalBuffer375_CH2->channel = 1;
|
||||
frameActionGeneric(1,2);
|
||||
if(serialDecodeEnabled_CH1){
|
||||
if(serialDecodeEnabled_CH1 && serialType == 0){
|
||||
internalBuffer375_CH2->serialManage(baudRate_CH1, 0);
|
||||
}
|
||||
break;
|
||||
|
@ -90,19 +90,21 @@ void isoDriver::timerTick(void){
|
|||
break;
|
||||
case 3:
|
||||
frameActionGeneric(2,0);
|
||||
if(serialDecodeEnabled_CH1){
|
||||
if(serialDecodeEnabled_CH1 && serialType == 0){
|
||||
internalBuffer375_CH1->serialManage(baudRate_CH1, 0);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
internalBuffer375_CH2->channel = 2;
|
||||
frameActionGeneric(2,2);
|
||||
if(serialDecodeEnabled_CH1){
|
||||
if(serialDecodeEnabled_CH1 && serialType == 0){
|
||||
internalBuffer375_CH1->serialManage(baudRate_CH1, 0);
|
||||
}
|
||||
if(serialDecodeEnabled_CH2){
|
||||
if(serialDecodeEnabled_CH2 && serialType == 0){
|
||||
internalBuffer375_CH2->serialManage(baudRate_CH2, 0);
|
||||
}
|
||||
if (serialDecodeEnabled_CH1 && serialType == 1)
|
||||
twoWire->run();
|
||||
break;
|
||||
case 5:
|
||||
break;
|
||||
|
@ -1456,5 +1458,13 @@ void isoDriver::setSerialType(unsigned char type)
|
|||
{
|
||||
serialType = type;
|
||||
qDebug() << "Serial Type changed to" << serialType;
|
||||
|
||||
if(serialType == 1)
|
||||
{
|
||||
if (twoWire)
|
||||
delete twoWire;
|
||||
twoWire = new i2c::i2cDecoder(internalBuffer375_CH1, internalBuffer375_CH2, i2cClockRate);
|
||||
twoWire->setStepSize(1000, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "genericusbdriver.h"
|
||||
#include "desktop_settings.h"
|
||||
#include "siprint.h"
|
||||
#include "i2cdecoder.h"
|
||||
|
||||
class isoBuffer;
|
||||
class isoBuffer_file;
|
||||
|
@ -114,6 +115,8 @@ private:
|
|||
double seriesResistance = 0;
|
||||
// Logic Analyser
|
||||
unsigned char serialType = 0;
|
||||
i2c::i2cDecoder* twoWire = nullptr;
|
||||
uint32_t i2cClockRate = 100000;
|
||||
//Generic Vars
|
||||
double windowAtPause = 0.01;
|
||||
QTimer* isoTimer = NULL, *slowTimer = NULL, *fileTimer = NULL;
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
/****************************************************************************
|
||||
** Resource object code
|
||||
**
|
||||
** Created by: The Resource Compiler for Qt version 5.10.1
|
||||
** Created by: The Resource Compiler for Qt version 5.11.1
|
||||
**
|
||||
** WARNING! All changes made in this file will be lost!
|
||||
*****************************************************************************/
|
||||
|
||||
static const unsigned char qt_resource_data[] = {
|
||||
// /home/esposch/Git/Labrador/Desktop_Interface/buffer_0.bmp
|
||||
// /home/esposch/git/labrador/Desktop_Interface/buffer_0.bmp
|
||||
0x0,0x0,0x0,0x8d,
|
||||
0x0,
|
||||
0x0,0x28,0xb6,0x78,0x9c,0xed,0xd0,0xb1,0xd,0xc2,0x30,0x0,0x45,0xc1,0xb0,0x45,
|
||||
|
@ -19,7 +19,7 @@ static const unsigned char qt_resource_data[] = {
|
|||
0xab,0x8f,0xd5,0xc7,0xea,0x63,0xf5,0xb1,0xfa,0x58,0x7d,0xac,0x3e,0x56,0x1f,0xab,
|
||||
0x8f,0xd5,0xc7,0xea,0x63,0xf5,0xb1,0xfa,0x58,0x7d,0xac,0x3e,0x56,0x1f,0xab,0x8f,
|
||||
0xd5,0xc7,0xea,0x63,0x73,0xf6,0xf9,0x2,0xf4,0x4,0x42,0xe7,
|
||||
// /home/esposch/Git/Labrador/Desktop_Interface/buffer_2.bmp
|
||||
// /home/esposch/git/labrador/Desktop_Interface/buffer_2.bmp
|
||||
0x0,0x0,0x0,0x7b,
|
||||
0x0,
|
||||
0x0,0x28,0xb6,0x78,0x9c,0xed,0xd0,0x31,0xd,0x80,0x30,0x14,0x45,0xd1,0xe2,0x82,
|
||||
|
@ -30,7 +30,7 @@ static const unsigned char qt_resource_data[] = {
|
|||
0x3e,0x99,0xf1,0xe1,0xc3,0x87,0xf,0x9f,0xcc,0xf8,0xf0,0xe1,0xc3,0x87,0x4f,0x66,
|
||||
0x7c,0xf8,0xf0,0xe1,0xc3,0x27,0x33,0x3e,0x7c,0xf8,0xf0,0xe1,0x93,0x19,0x1f,0x3e,
|
||||
0x7c,0xf8,0xf0,0x19,0x7b,0x1,0x6d,0x5a,0xf,0xce,
|
||||
// /home/esposch/Git/Labrador/Desktop_Interface/buffer_1.bmp
|
||||
// /home/esposch/git/labrador/Desktop_Interface/buffer_1.bmp
|
||||
0x0,0x0,0x0,0x97,
|
||||
0x0,
|
||||
0x0,0x28,0xb6,0x78,0x9c,0xed,0xd0,0xb1,0xd,0xc2,0x30,0x10,0x40,0xd1,0xb0,0x5,
|
||||
|
@ -79,13 +79,13 @@ static const unsigned char qt_resource_struct[] = {
|
|||
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
|
||||
// :/bitmap/buffer_2.bmp
|
||||
0x0,0x0,0x0,0x30,0x0,0x1,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x91,
|
||||
0x0,0x0,0x1,0x60,0x85,0xbd,0x6d,0xb,
|
||||
0x0,0x0,0x1,0x64,0xad,0x34,0xc4,0x61,
|
||||
// :/bitmap/buffer_0.bmp
|
||||
0x0,0x0,0x0,0x12,0x0,0x1,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,
|
||||
0x0,0x0,0x1,0x60,0x85,0xbd,0x6d,0xb,
|
||||
0x0,0x0,0x1,0x64,0xad,0x34,0xc4,0x61,
|
||||
// :/bitmap/buffer_1.bmp
|
||||
0x0,0x0,0x0,0x4e,0x0,0x1,0x0,0x0,0x0,0x1,0x0,0x0,0x1,0x10,
|
||||
0x0,0x0,0x1,0x60,0x85,0xbd,0x6d,0xb,
|
||||
0x0,0x0,0x1,0x64,0xad,0x34,0xc4,0x61,
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue