Partially implement TSC2101 buffer

This commit is contained in:
meepingsnesroms
2019-08-24 12:56:18 -07:00
parent afa5b13d14
commit 5af248eaef
2 changed files with 41 additions and 4 deletions

View File

@@ -39,6 +39,9 @@ electrical noise on lines(conversions probably should have +-20 added to values)
in the edge case that SPICLK2 is disabled while using ADS7846 and a 1 was the last bit shifted out 0s will still be shifted in
need to to verify behavior of differential mode bit
TSC2101:
values of AUX1 and AUX2 are unknown an need to be tested, emulation has issues with the USB port shortly after and it would make sense that since the T3 has the same connector as the m515 AUX1 is the device type resistor in the bottom connector
SD Card:
block specific write protect bits don't work
IRQ2 may actually be attached to the SD Card data out pin, triggering an interrupt when a 0 is received to process the return data

View File

@@ -37,13 +37,17 @@ enum{
TOUCH_CONTROL_AUX2_MAX,
TOUCH_CONTROL_AUX2_MIN,
TOUCH_CONTROL_MEASUREMENT_CONFIGURATION,
TOUCH_CONTROL_PROGRAMMABLE_DELAY
TOUCH_CONTROL_PROGRAMMABLE_DELAY,
//TOUCH_CONTROL_RESERVED_X...
//TODO: add audio control registers
BUFFER_START = TSC2101_REG_LOCATION(3, 0),
BUFFER_END = TSC2101_REG_LOCATION(3, 63)
};
static uint16_t tsc2101Registers[0x100];
static uint8_t tsc2101BufferReadPosition;
static uint8_t tsc2101BufferWritePosition;
static uint16_t tsc2101CurrentWord;
static uint8_t tsc2101CurrentWordBitsRemaining;
static uint8_t tsc2101CurrentPage;
@@ -53,6 +57,31 @@ static bool tsc2101Read;
static bool tsc2101ChipSelect;
static uint8_t tsc2101BufferFifoEntrys(void){
//check for wraparound
if(tsc2101BufferWritePosition < tsc2101BufferReadPosition)
return tsc2101BufferWritePosition + 17 - tsc2101BufferReadPosition;
return tsc2101BufferWritePosition - tsc2101BufferReadPosition;
}
static uint16_t tsc2101BufferFifoRead(void){
if(tsc2101BufferFifoEntrys() > 0)
tsc2101BufferReadPosition = (tsc2101BufferReadPosition + 1) % 65;
return tsc2101Registers[BUFFER_START + tsc2101BufferReadPosition];
}
static void tsc2101BufferFifoWrite(uint16_t value){
if(tsc2101BufferFifoEntrys() < 64)
tsc2101BufferWritePosition = (tsc2101BufferWritePosition + 1) % 65;
else
debugLog("tsc2101 buffer FIFO overflowed\n");
tsc2101Registers[BUFFER_START + tsc2101BufferWritePosition] = value;
}
static void tsc2101BufferFifoFlush(void){
tsc2101BufferReadPosition = tsc2101BufferWritePosition;
}
static uint16_t tsc2101GetAnalogMask(void){
const uint16_t masks[4] = {0xFFF, 0xFF0, 0xFFC, 0xFFF};
@@ -108,7 +137,6 @@ static void tsc2101ResetRegisters(void){
//TODO: need to add all the registers here
tsc2101Registers[TOUCH_CONTROL_STATUS] = 0x8000;
//tsc2101Registers[TOUCH_CONTROL_BUFFER_MODE] = 0x0200;//TODO: return buffer emupt flag based on real buffer size
tsc2101Registers[TOUCH_CONTROL_REFERENCE] = 0x0002;
tsc2101RefreshInterrupt();
@@ -126,9 +154,13 @@ static uint16_t tsc2101RegisterRead(uint8_t page, uint8_t address){
debugLog("TSC2101 read status register\n");
return tsc2101Registers[TOUCH_CONTROL_STATUS] | 0x0FDE;
case TOUCH_CONTROL_BUFFER_MODE:
return tsc2101Registers[TOUCH_CONTROL_BUFFER_MODE] | (tsc2101BufferFifoEntrys() == 64) << 10 | (tsc2101BufferFifoEntrys() == 0) << 9;
case TOUCH_CONTROL_RESET_CONTROL_REGISTER:
return 0xFFFF;
//TOUCH_DATA_* registers are scaned, the values get copyed to the register when the result is generated
case TOUCH_DATA_X:
case TOUCH_DATA_Y:
case TOUCH_DATA_Z1:
@@ -138,8 +170,8 @@ static uint16_t tsc2101RegisterRead(uint8_t page, uint8_t address){
case TOUCH_DATA_AUX2:
case TOUCH_DATA_TEMP1:
case TOUCH_DATA_TEMP2:
debugLog("Unimplemented TSC2101 analog port read:%d\n", combinedRegisterNumber);
return 0x0000;
//simple read, no actions needed
return tsc2101Registers[combinedRegisterNumber];
default:
debugLog("Unimplemented TSC2101 register read, page:0x%01X, address:0x%02X\n", page, address);
@@ -212,6 +244,8 @@ static void tsc2101RegisterWrite(uint8_t page, uint8_t address, uint16_t value){
}
void tsc2101Reset(bool isBoot){
tsc2101BufferReadPosition = 0;
tsc2101BufferWritePosition = 0;
tsc2101CurrentWord = 0x0000;
tsc2101CurrentWordBitsRemaining = 16;
tsc2101CurrentPage = 0;