Address gets sent to console along with r/w and ACK

This commit is contained in:
Chris Esposito 2018-11-06 10:36:04 +11:00
parent b19900e9a0
commit b5069f1264
3 changed files with 32 additions and 7 deletions

View File

@ -2,12 +2,18 @@
using namespace i2c;
i2cDecoder::i2cDecoder(isoBuffer* sda_in, isoBuffer* scl_in) :
QObject(nullptr),
sda(sda_in),
scl(scl_in)
i2cDecoder::i2cDecoder(isoBuffer* sda_in, isoBuffer* scl_in, QPlainTextEdit* console_in)
: QObject(nullptr)
, sda(sda_in)
, scl(scl_in)
, console(console_in)
{
serialBuffer = new isoBufferBuffer(I2C_BUFFER_LENGTH);
updateTimer = new QTimer();
updateTimer->setTimerType(Qt::PreciseTimer);
updateTimer->start(CONSOLE_UPDATE_TIMER_PERIOD);
connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateConsole()));
}
void i2cDecoder::reset()
@ -151,6 +157,20 @@ void i2cDecoder::decodeAddress(edge sdaEdge, edge sclEdge)
if (currentBitIndex == addressBitStreamLength)
{
qDebug() << "Finished Address Decode";
if (addressBitStream & 0b0000000000000010)
serialBuffer->add("READ ");
else
serialBuffer->add("WRITE ");
char addressStr[8];
sprintf(addressStr, "0x%02x ", (addressBitStream & 0b0000000111111100) >> 2);
serialBuffer->add(addressStr);
if (addressBitStream & 0b0000000000000001)
serialBuffer->add("(NACK)");
consoleStateInvalid = true;
}
}
@ -190,10 +210,12 @@ void i2cDecoder::stopCondition()
currentBitIndex = 0;
state = transmissionState::data;
currentDataByte = 0;
serialBuffer->add('\n');
break;
case transmissionState::data:
state = transmissionState::idle;
qDebug() << "Data =" << currentDataByte;
serialBuffer->add('\n');
break;
}
qDebug() << "I2C STOP";

View File

@ -1,9 +1,11 @@
#ifndef I2CDECODER_H
#define I2CDECODER_H
#include <QObject>
#include "isobuffer.h"
#include "isobufferbuffer.h"
#include <QObject>
#include <QTimer>
#include <mutex>
namespace i2c
@ -32,13 +34,14 @@ class i2cDecoder : public QObject
{
Q_OBJECT
public:
explicit i2cDecoder(isoBuffer* sda_in, isoBuffer* scl_in);
explicit i2cDecoder(isoBuffer* sda_in, isoBuffer* scl_in, QPlainTextEdit* console_in);
// misc
isoBuffer* sda;
isoBuffer* scl;
QPlainTextEdit* console;
isoBufferBuffer* serialBuffer = nullptr;
std::mutex mutex;
QTimer *updateTimer;
// State vars
uint8_t currentSdaValue = 0;

View File

@ -1549,7 +1549,7 @@ void isoDriver::setSerialType(unsigned char type)
{
if (twoWire)
delete twoWire;
twoWire = new i2c::i2cDecoder(internalBuffer375_CH1, internalBuffer375_CH2);
twoWire = new i2c::i2cDecoder(internalBuffer375_CH1, internalBuffer375_CH2, internalBuffer375_CH1->console1);
}
}