From e6535b546cfee0ff901899ac31d840da0ff564fd Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Tue, 20 Aug 2019 11:45:45 -0700 Subject: [PATCH] Add chip select and reset lines for TSC2101 --- src/emulator.c | 2 +- src/pxa260/pxa260_GPIO.c | 36 +++++++++++++++++++++++++++++++++++- src/tsc2101.c | 9 +++++++-- src/tsc2101.h | 2 +- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/emulator.c b/src/emulator.c index 36b2b4d..4bf661a 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -244,7 +244,7 @@ void emulatorSoftReset(void){ palmClockMultiplier = 1.00; pxa260Reset(); tps65010Reset(); - tsc2101Reset(); + tsc2101Reset(true); w86l488Reset(); sandboxReset(); } diff --git a/src/pxa260/pxa260_GPIO.c b/src/pxa260/pxa260_GPIO.c index 111f58c..8e2f3e0 100644 --- a/src/pxa260/pxa260_GPIO.c +++ b/src/pxa260/pxa260_GPIO.c @@ -1,7 +1,32 @@ #include "pxa260_GPIO.h" #include "pxa260_mem.h" +#include "../tsc2101.h" +#include "../emulator.h" +static void pxa260gpioOnOutputPinUpdated(Pxa260gpio* gpio, UInt8 gpioNum){ + //the pin value is not sent to this function because it is usually not needed and can be fetched with pxa260gpioGetState + + debugLog("PXA260 GPIO %d set:%d\n", gpioNum, pxa260gpioGetState(gpio, gpioNum)); + + switch(gpioNum){ + case 24: + //TSC2101 chip select + tsc2101SetChipSelect(!!pxa260gpioGetState(gpio, gpioNum)); + break; + + case 40: + //TSC2101 reset + if(pxa260gpioGetState(gpio, gpioNum) == PXA260_GPIO_LOW) + tsc2101Reset(false); + break; + + default: + //debugLog("Unimplimented PXA260 GPIO %d set:%d\n", gpioNum, pxa260gpioGetState(gpio, gpioNum)); + break; + } +} + static void pxa260gpioPrvRecalcValues(Pxa260gpio* gpio, UInt32 which){ UInt8 i; @@ -20,8 +45,17 @@ static void pxa260gpioPrvRecalcValues(Pxa260gpio* gpio, UInt32 which){ if (newVal != oldVal) { UInt32 wentHi = newVal &~ oldVal; UInt32 wentLo = oldVal &~ newVal; + UInt32 outputChanged = (wentHi | wentLo) & gpio->dirs[which]; gpio->detStatus[which] |= (wentHi & gpio->riseDet[which]) | (wentLo & gpio->fallDet[which]); + + if(outputChanged){ + UInt8 index; + + for(index = 0; index < 32; index++) + if(outputChanged & 1UL << index) + pxa260gpioOnOutputPinUpdated(gpio, which * 32 + index); + } } } @@ -106,7 +140,7 @@ Boolean pxa260gpioPrvMemAccessF(void* userData, UInt32 pa, UInt8 size, Boolean w case 25: case 26: gpio->AFRs[pa - 21] = val; - //pa = (pa - 21) / 2; + pa = (pa - 21) / 2; goto recalc; } diff --git a/src/tsc2101.c b/src/tsc2101.c index 2d245a0..6459f8f 100644 --- a/src/tsc2101.c +++ b/src/tsc2101.c @@ -74,7 +74,7 @@ static void tsc2101RegisterWrite(uint8_t page, uint8_t address, uint16_t value){ } } -void tsc2101Reset(void){ +void tsc2101Reset(bool isBoot){ memset(tsc2101Registers, 0x00, sizeof(tsc2101Registers)); tsc2101CurrentWord = 0x0000; tsc2101CurrentWordBitsRemaining = 16; @@ -82,7 +82,9 @@ void tsc2101Reset(void){ tsc2101CurrentRegister = 0; tsc2101CommandFinished = false; tsc2101Read = false; - tsc2101ChipSelect = true; + + if(isBoot) + tsc2101ChipSelect = true; //TODO: need to add all the registers here tsc2101Registers[TOUCH_CONTROL_STATUS] = 0x8000; @@ -111,6 +113,9 @@ void tsc2101SetChipSelect(bool value){ bool tsc2101ExchangeBit(bool bit){ bool output = true;//TODO: SPI return value is usualy true but this is unverified + if(tsc2101ChipSelect) + return true; + if(!tsc2101Read){ tsc2101CurrentWord <<= 1; tsc2101CurrentWord |= bit; diff --git a/src/tsc2101.h b/src/tsc2101.h index c841f8a..ccf51e3 100644 --- a/src/tsc2101.h +++ b/src/tsc2101.h @@ -4,7 +4,7 @@ #include #include -void tsc2101Reset(void); +void tsc2101Reset(bool isBoot); uint32_t tsc2101StateSize(void); void tsc2101SaveState(uint8_t* data); void tsc2101LoadState(uint8_t* data);