From b5069f12642137263150bf274c0718f5ac89e6d3 Mon Sep 17 00:00:00 2001 From: Chris Esposito Date: Tue, 6 Nov 2018 10:36:04 +1100 Subject: [PATCH] Address gets sent to console along with r/w and ACK --- Desktop_Interface/i2cdecoder.cpp | 30 ++++++++++++++++++++++++++---- Desktop_Interface/i2cdecoder.h | 7 +++++-- Desktop_Interface/isodriver.cpp | 2 +- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Desktop_Interface/i2cdecoder.cpp b/Desktop_Interface/i2cdecoder.cpp index b75170fe..643e0c4a 100644 --- a/Desktop_Interface/i2cdecoder.cpp +++ b/Desktop_Interface/i2cdecoder.cpp @@ -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"; diff --git a/Desktop_Interface/i2cdecoder.h b/Desktop_Interface/i2cdecoder.h index 068881e8..af51f026 100644 --- a/Desktop_Interface/i2cdecoder.h +++ b/Desktop_Interface/i2cdecoder.h @@ -1,9 +1,11 @@ #ifndef I2CDECODER_H #define I2CDECODER_H -#include #include "isobuffer.h" #include "isobufferbuffer.h" + +#include +#include #include 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; diff --git a/Desktop_Interface/isodriver.cpp b/Desktop_Interface/isodriver.cpp index 48a59b72..4200e6a8 100644 --- a/Desktop_Interface/isodriver.cpp +++ b/Desktop_Interface/isodriver.cpp @@ -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); } }