From 3bbffa65a13826515eb8384d72e25fad9910a544 Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Tue, 19 Jun 2018 14:38:49 -0700 Subject: [PATCH] Can now run with or without the bootloader in the Qt port Also clean up ads7846 functions --- qtBuildSystem/Mu/emuwrapper.cpp | 6 +++++- src/ads7846.c | 31 +++++++++++++++++------------- src/ads7846.h | 4 ++-- src/hardwareRegistersAccessors.c.h | 4 ++-- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/qtBuildSystem/Mu/emuwrapper.cpp b/qtBuildSystem/Mu/emuwrapper.cpp index 654f878..0328444 100644 --- a/qtBuildSystem/Mu/emuwrapper.cpp +++ b/qtBuildSystem/Mu/emuwrapper.cpp @@ -129,7 +129,7 @@ uint32_t EmuWrapper::init(QString romPath, QString bootloaderPath, uint32_t feat return EMU_ERROR_INVALID_PARAMETER; } - if(bootloaderPath != ""){ + if(bootloaderPath != "" && bootloaderFile.exists()){ if(bootloaderFile.open(QFile::ReadOnly)){ bootloaderData = bootloaderFile.readAll(); bootloaderFile.close(); @@ -141,6 +141,10 @@ uint32_t EmuWrapper::init(QString romPath, QString bootloaderPath, uint32_t feat return EMU_ERROR_INVALID_PARAMETER; } } + else{ + bootloaderBuff.data = NULL; + bootloaderBuff.size = 0; + } error = emulatorInit(romBuff, bootloaderBuff, features); if(error == EMU_ERROR_NONE){ diff --git a/src/ads7846.c b/src/ads7846.c index 30fcfe9..32dfb26 100644 --- a/src/ads7846.c +++ b/src/ads7846.c @@ -10,21 +10,29 @@ bool ads7846PenIrqEnabled; uint16_t ads7846OutputValue; -void ads7846SendBit(bool bit){ +static inline bool ads7846GetAdcBit(){ + //a new control byte can be sent while receiving data + //this is valid behavior as long as the start of the last control byte was 16 or more clock cycles ago + bool bit = ads7846OutputValue & 0x8000; + ads7846OutputValue <<= 1; + return bit; +} + +bool ads7846ExchangeBit(bool bitIn){ if(ads7846BitsToNextControl > 0) ads7846BitsToNextControl--; if(ads7846BitsToNextControl == 0){ //check for control bit - if(bit){ + if(bitIn){ ads7846ControlByte = 0x01; ads7846BitsToNextControl = 16; } - return; + return ads7846GetAdcBit(); } else if(ads7846BitsToNextControl < 8){ ads7846ControlByte <<= 1; - ads7846ControlByte |= bit; + ads7846ControlByte |= bitIn; } if(ads7846BitsToNextControl == 7){ @@ -103,17 +111,14 @@ void ads7846SendBit(bool bit){ } } } + + return ads7846GetAdcBit(); } -bool ads7846RecieveBit(){ - bool bit; - - //a new control byte can be sent while receiving data - //this is valid behavior as long as there has been 16 clock cycles since the start of the last control byte - - bit = ads7846OutputValue & 0x8000; - ads7846OutputValue <<= 1; - return bit; +bool ads7846Busy(){ + if(ads7846BitsToNextControl == 8) + return true; + return false; } void ads7846Reset(){ diff --git a/src/ads7846.h b/src/ads7846.h index 3daf20f..f0b5d99 100644 --- a/src/ads7846.h +++ b/src/ads7846.h @@ -7,7 +7,7 @@ extern uint8_t ads7846ControlByte; extern bool ads7846PenIrqEnabled; extern uint16_t ads7846OutputValue; -void ads7846SendBit(bool bit); -bool ads7846RecieveBit(); +bool ads7846ExchangeBit(bool bitIn); +bool ads7846Busy(); void ads7846Reset(); diff --git a/src/hardwareRegistersAccessors.c.h b/src/hardwareRegistersAccessors.c.h index fb7536b..400ec94 100644 --- a/src/hardwareRegistersAccessors.c.h +++ b/src/hardwareRegistersAccessors.c.h @@ -250,9 +250,9 @@ static inline void setSpiCont2(uint16_t value){ for(uint8_t bits = 0; bits < bitCount; bits++){ //the Palm m515 seems to invert received bits - ads7846SendBit(spi2Data & 0x8000); + bool newBit = ads7846ExchangeBit(spi2Data & 0x8000); spi2Data <<= 1; - spi2Data |= !ads7846RecieveBit(); + spi2Data |= !newBit; } registerArrayWrite16(SPIDATA2, spi2Data);