From d4b9997d435909f806a72d227e4b0d94bb2ecc67 Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Tue, 13 Aug 2019 17:39:57 -0700 Subject: [PATCH] Add TSC2101 protocol handler --- qtBuildSystem/Mu/debugviewer.cpp | 9 ++- qtBuildSystem/Mu/debugviewer.h | 3 +- qtBuildSystem/Mu/debugviewer.ui | 120 +++++++++++++++++-------------- src/pxa260/pxa260Ssp.c | 2 - src/tps65010.c | 14 ++-- src/tsc2101.c | 77 +++++++++++++++++++- src/tsc2101.h | 8 +++ 7 files changed, 163 insertions(+), 70 deletions(-) diff --git a/qtBuildSystem/Mu/debugviewer.cpp b/qtBuildSystem/Mu/debugviewer.cpp index 97865f8..58d8131 100644 --- a/qtBuildSystem/Mu/debugviewer.cpp +++ b/qtBuildSystem/Mu/debugviewer.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "mainwindow.h" #include "emuwrapper.h" @@ -108,7 +109,7 @@ void DebugViewer::on_debug32Bit_clicked(){ debugRadioButtonHandler(); } -void DebugViewer::on_debugDump_clicked(){ +void DebugViewer::on_debugDumpToFile_clicked(){ QString fileBuffer; QFile fileOut(((MainWindow*)parentWidget())->settings->value("resourceDirectory", "").toString() + "/debugDumps/" + ui->debugFilePath->text()); @@ -124,6 +125,12 @@ void DebugViewer::on_debugDump_clicked(){ } } +void DebugViewer::on_debugDumpToTerminal_clicked(){ + for(int index = 0; index < ui->debugValueList->count(); index++) + printf("%s\n", ui->debugValueList->item(index)->text().toStdString().c_str()); + fflush(stdout); +} + void DebugViewer::on_debugShowRegisters_clicked(){ EmuWrapper& emu = ((MainWindow*)parentWidget())->emu; diff --git a/qtBuildSystem/Mu/debugviewer.h b/qtBuildSystem/Mu/debugviewer.h index d9c4e13..d37cb74 100644 --- a/qtBuildSystem/Mu/debugviewer.h +++ b/qtBuildSystem/Mu/debugviewer.h @@ -28,7 +28,8 @@ private slots: void on_debug16Bit_clicked(); void on_debug32Bit_clicked(); - void on_debugDump_clicked(); + void on_debugDumpToFile_clicked(); + void on_debugDumpToTerminal_clicked(); void on_debugShowRegisters_clicked(); void on_debugShowDebugLogs_clicked(); void on_debugEraseDebugLogs_clicked(); diff --git a/qtBuildSystem/Mu/debugviewer.ui b/qtBuildSystem/Mu/debugviewer.ui index 396bdcb..6631a45 100644 --- a/qtBuildSystem/Mu/debugviewer.ui +++ b/qtBuildSystem/Mu/debugviewer.ui @@ -45,6 +45,16 @@ + + + + 8bit + + + + + + @@ -52,6 +62,34 @@ + + + + File Path + + + + + + + Address + + + + + + + Length + + + + + + + 32bit + + + @@ -62,26 +100,6 @@ - - - - - - - 32bit - - - - - - - Dump To File - - - false - - - @@ -89,37 +107,6 @@ - - - - Length - - - - - - - 8bit - - - - - - - Erase Debug Logs - - - false - - - - - - - File Path - - - @@ -130,10 +117,33 @@ - - - - Address + + + + Dump To File + + + false + + + + + + + Erase Debug Logs + + + false + + + + + + + Dump To Terminal + + + false diff --git a/src/pxa260/pxa260Ssp.c b/src/pxa260/pxa260Ssp.c index 5c1f03a..c7d461b 100644 --- a/src/pxa260/pxa260Ssp.c +++ b/src/pxa260/pxa260Ssp.c @@ -140,8 +140,6 @@ uint32_t pxa260SspReadWord(uint32_t address){ uint8_t tfl = pxa260SspTxFifoEntrys(); uint16_t value = 0x0000; - debugLog("Unimplimented PXA260 SSP SSSR read\n"); - if(rfl == 0) rfl = 0xF; else diff --git a/src/tps65010.c b/src/tps65010.c index ac4f83f..8eb91ea 100644 --- a/src/tps65010.c +++ b/src/tps65010.c @@ -90,15 +90,13 @@ uint8_t tps65010I2cExchange(uint8_t i2cBus){ } tps65010CurrentI2cByte |= (i2cBus == I2C_1); - if(tps65010CurrentI2cByteBitsRemaining > 0){ - if(tps65010State == I2C_SENDING){ - if(tps65010SelectedRegister < 0x11) - newI2cBus = (tps65010Registers[tps65010SelectedRegister] && 1 << (tps65010CurrentI2cByteBitsRemaining - 1)) ? I2C_1 : I2C_0; - else - newI2cBus = 0x00; - } - tps65010CurrentI2cByteBitsRemaining--; + if(tps65010State == I2C_SENDING){ + if(tps65010SelectedRegister < 0x11) + newI2cBus = (tps65010Registers[tps65010SelectedRegister] && 1 << (tps65010CurrentI2cByteBitsRemaining - 1)) ? I2C_1 : I2C_0; + else + newI2cBus = I2C_0; } + tps65010CurrentI2cByteBitsRemaining--; if(tps65010CurrentI2cByteBitsRemaining == 0){ //process data from byte diff --git a/src/tsc2101.c b/src/tsc2101.c index c450776..12502b4 100644 --- a/src/tsc2101.c +++ b/src/tsc2101.c @@ -4,8 +4,29 @@ #include "emulator.h" -void tsc2101Reset(void){ +uint16_t tsc2101CurrentWord; +uint8_t tsc2101CurrentWordBitsRemaining; +uint8_t tsc2101CurrentPage; +uint8_t tsc2101CurrentRegister; +bool tsc2101CommandFinished; +bool tsc2101Read; + +static uint16_t tsc2101RegisterRead(uint8_t page, uint8_t address){ + debugLog("Unimplemented TSC2101 register read, page:0x%01X, address:0x%02X\n", page, address); +} + +static void tsc2101RegisterWrite(uint8_t page, uint8_t address, uint16_t value){ + debugLog("Unimplemented TSC2101 register write, page:0x%01X, address:0x%02X, value:0x%04X\n", page, address, value); +} + +void tsc2101Reset(void){ + tsc2101CurrentWord = 0x0000; + tsc2101CurrentWordBitsRemaining = 16; + tsc2101CurrentPage = 0; + tsc2101CurrentRegister = 0; + tsc2101CommandFinished = false; + tsc2101Read = false; } uint32_t tsc2101StateSize(void){ @@ -20,6 +41,56 @@ void tsc2101LoadState(uint8_t* data){ } -bool tsc2101ExchangeBit(bool bit){ - debugLog("Unimplemented TSC2101 transfer:%d\n", bit); +void tsc2101SetChipSelect(bool value){ + tsc2101CurrentWordBitsRemaining = 16; + tsc2101Read = false; +} + +bool tsc2101ExchangeBit(bool bit){ + bool output = true;//TODO: SPI return value is usualy true but this is unverified + + if(!tsc2101Read){ + tsc2101CurrentWord <<= 1; + tsc2101CurrentWord |= bit; + } + else{ + output = !!(tsc2101CurrentWord & 0x8000); + tsc2101CurrentWord <<= 1; + } + tsc2101CurrentWordBitsRemaining--; + + if(tsc2101CurrentWordBitsRemaining == 0){ + if(!tsc2101CommandFinished){ + //write command word + tsc2101CurrentPage = tsc2101CurrentWord >> 11 & 0x000F; + tsc2101CurrentRegister = tsc2101CurrentWord >> 5 & 0x003F; + tsc2101Read = !!(tsc2101CurrentWord & 0x8000); + if(tsc2101Read){ + //add first data word + tsc2101CurrentWord = tsc2101RegisterRead(tsc2101CurrentPage, tsc2101CurrentRegister); + tsc2101CurrentRegister++; + } + } + else if(!tsc2101Read){ + //write data word + if(tsc2101CurrentRegister < 0x40){ + tsc2101RegisterWrite(tsc2101CurrentPage, tsc2101CurrentRegister, tsc2101CurrentWord); + tsc2101CurrentRegister++; + } + } + else{ + //read data word + if(tsc2101CurrentRegister < 0x40){ + tsc2101CurrentWord = tsc2101RegisterRead(tsc2101CurrentPage, tsc2101CurrentRegister); + tsc2101CurrentRegister++; + } + else{ + tsc2101CurrentWord = 0xFFFF; + } + } + + tsc2101CurrentWordBitsRemaining = 16; + } + + return output; } diff --git a/src/tsc2101.h b/src/tsc2101.h index 5a73104..394b916 100644 --- a/src/tsc2101.h +++ b/src/tsc2101.h @@ -4,11 +4,19 @@ #include #include +extern uint16_t tsc2101CurrentWord; +extern uint8_t tsc2101CurrentWordBitsRemaining; +extern uint8_t tsc2101CurrentPage; +extern uint8_t tsc2101CurrentRegister; +extern bool tsc2101CommandFinished; +extern bool tsc2101Read; + void tsc2101Reset(void); uint32_t tsc2101StateSize(void); void tsc2101SaveState(uint8_t* data); void tsc2101LoadState(uint8_t* data); +void tsc2101SetChipSelect(bool value); bool tsc2101ExchangeBit(bool bit); #endif