Try to implement exact timing on SPI2

This commit is contained in:
meepingsnesroms
2018-05-28 13:50:05 -07:00
parent d1909985f7
commit e2a4f7e2ea
9 changed files with 5147 additions and 22 deletions

View File

@@ -20,6 +20,22 @@ SPI Start Chunk(sent once on boot):
5 5 bit receive, continued from last command, 0x0014
Palm OS reads from the touchscreen SPI in 5 accesses:
SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:16(printed 1 times)
SPI2 transfer, before:0xE01B, after:0x00FF(printed 1 times)
SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:3(printed 1 times)
SPI2 transfer, before:0x0004, after:0x0026(printed 1 times)
SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:5(printed 1 times)
SPI2 transfer, before:0x001D, after:0x03BF(printed 1 times)
SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:12(printed 1 times)
SPI2 transfer, before:0x0E1C, after:0xCE00(printed 1 times)
SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:16(printed 1 times)
SPI2 transfer, before:0xE01C, after:0xFEFF(printed 1 times)
resync event?{
16 0xE01B
3 only sends 0s, delay or receive, 0x0004

View File

@@ -31,8 +31,8 @@ macx {
}
CONFIG(debug, debug|release){
DEFINES += EMU_DEBUG EMU_CUSTOM_DEBUG_LOG_HANDLER
# DEFINES += EMU_LOG_REGISTER_ACCESS_UNKNOWN EMU_OPCODE_LEVEL_DEBUG EMU_LOG_APIS
DEFINES += EMU_DEBUG EMU_CUSTOM_DEBUG_LOG_HANDLER EMU_LOG_REGISTER_ACCESS_UNKNOWN
# DEFINES += EMU_OPCODE_LEVEL_DEBUG EMU_LOG_APIS
}
QMAKE_CFLAGS += -std=c99

View File

@@ -4,27 +4,30 @@
#include "portability.h"
uint8_t ads7846InputBitsLeft;
uint8_t ads7846BitsToNextControl;//bits before starting a new control byte
uint8_t ads7846ControlByte;
bool ads7846PenIrqEnabled;
uint16_t ads7846OutputValue;
void ads7846SendBit(bool bit){
//check for control bit
if(ads7846InputBitsLeft == 0){
if(ads7846BitsToNextControl > 0)
ads7846BitsToNextControl--;
if(ads7846BitsToNextControl == 0){
//check for control bit
if(bit){
ads7846ControlByte = 0x01;
ads7846InputBitsLeft = 7;
ads7846BitsToNextControl = 16;
}
return;
}
else if(ads7846BitsToNextControl < 8){
ads7846ControlByte <<= 1;
ads7846ControlByte |= bit;
}
ads7846ControlByte <<= 1;
ads7846ControlByte |= bit;
ads7846InputBitsLeft--;
if(ads7846InputBitsLeft == 0){
if(ads7846BitsToNextControl == 7){
//control byte finished, get output value
double value;
double rangeMax;
@@ -48,6 +51,7 @@ void ads7846SendBit(bool bit){
value = palmInput.touchscreenY;
else
value = 160;
debugLog("Accessed ADS7846 Touchscreen y.\n");
break;
case 0x20:
@@ -70,6 +74,7 @@ void ads7846SendBit(bool bit){
value = palmInput.touchscreenX;
else
value = 160;
debugLog("Accessed ADS7846 Touchscreen x.\n");
break;
case 0x60:
@@ -85,7 +90,7 @@ void ads7846SendBit(bool bit){
break;
}
//check if ADC is on, if not do nothing
//check if ADC is on, if not do nothing, PENIRQ is handled in refreshInputState() in hardwareRegisters.c
if(powerSave != 0x02){
if(mode){
//8 bit conversion
@@ -97,9 +102,6 @@ void ads7846SendBit(bool bit){
ads7846OutputValue = value / rangeMax * 0x0FFF;
ads7846OutputValue <<= 4;//move to output position
}
//theres a 1 bit delay after the control byte before the data
//ads7846OutputValue >>= 1;
}
}
}
@@ -108,7 +110,7 @@ bool ads7846RecieveBit(){
bool bit;
//a new control byte can be sent while receiving data
//this is valid behavior as long as there is only 5 clock cycles/bits of data of the previous transfer remaining
//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;
@@ -118,6 +120,6 @@ bool ads7846RecieveBit(){
void ads7846Reset(){
ads7846OutputValue = 0x0000;
ads7846ControlByte = 0x00;
ads7846PenIrqEnabled = false;
ads7846InputBitsLeft = 0;
ads7846PenIrqEnabled = true;
ads7846BitsToNextControl = 0;
}

View File

@@ -2,7 +2,7 @@
#include <stdbool.h>
extern uint8_t ads7846InputBitsLeft;
extern uint8_t ads7846BitsToNextControl;
extern uint8_t ads7846ControlByte;
extern bool ads7846PenIrqEnabled;
extern uint16_t ads7846OutputValue;

View File

@@ -524,7 +524,7 @@ void emulatorSaveState(uint8_t* data){
offset += sizeof(uint8_t);
//ADS7846
writeStateValueUint8(data + offset, ads7846InputBitsLeft);
writeStateValueUint8(data + offset, ads7846BitsToNextControl);
offset += sizeof(uint8_t);
writeStateValueUint8(data + offset, ads7846ControlByte);
offset += sizeof(uint8_t);
@@ -667,7 +667,7 @@ void emulatorLoadState(uint8_t* data){
offset += sizeof(uint8_t);
//ADS7846
ads7846InputBitsLeft = readStateValueUint8(data + offset);
ads7846BitsToNextControl = readStateValueUint8(data + offset);
offset += sizeof(uint8_t);
ads7846ControlByte = readStateValueUint8(data + offset);
offset += sizeof(uint8_t);

View File

@@ -357,13 +357,16 @@ uint8_t getHwRegister8(uint32_t address){
#endif
switch(address){
/*
case PBDATA:
//read outputs as is and inputs as true, floating pins are high
return (registerArrayRead8(PBDATA) & registerArrayRead8(PBDIR)) | ~registerArrayRead8(PBDIR);
*/
case PDDATA:
return getPortDValue();
/*
case PEDATA:
//read outputs as is and inputs as true, floating pins are high
return (registerArrayRead8(PEDATA) & registerArrayRead8(PEDIR)) | ~registerArrayRead8(PEDIR);
@@ -379,6 +382,7 @@ uint8_t getHwRegister8(uint32_t address){
case PJDATA:
//read outputs as is and inputs as true, floating pins are high
return (registerArrayRead8(PJDATA) & registerArrayRead8(PJDIR)) | ~registerArrayRead8(PJDIR);
*/
case PKDATA:
return getPortKValue();
@@ -653,11 +657,13 @@ void setHwRegister8(uint32_t address, uint8_t value){
case PKPUEN:
//port data value, nothing attached to port
/*
case PCDATA:
case PDDATA:
case PEDATA:
case PFDATA:
case PJDATA:
*/
//misc port config
case PDKBEN:

5100
tests/touchGpioLog.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -29,6 +29,7 @@ may need to trigger an interrupt if a IMR masked interrupt becomes unmasked and
touch interrupt seems to not use IRQ5
When SPICLK2, SPITXD or SPIRXD on port e is disabled ADS7846 functions should respond approptatly(not transmitting or receiving or blocking both for the clock)
port g data bit 2 may need to be 0 to access ADS7846
REFREQ clock frequency in RTCCTL should slow down the RTC when enabled
Debug tools:
missing icons