Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Cannot modify header information - headers already sent by (output started at /usr/share/web/joat/webshare/ds/index.php:1101) in /usr/share/web/joat/webshare/ds/index.php on line 885
NDSTech Wiki : Touch Screen browse
Misc /
Touch Screen

Menu

Getting Started

System Information

Misc

It's a TI TSC2046 controller, hooked up to the ARM7 SPI port. News at 9.

Command Format:

bitnamedescription
7SStart bit
6..4A2..A0Channel select
3Mode12 bit/8 bit conversion mode
2SER/DFRread type
1..0PD1..PD0power-down mode

Power down mode:

PD1PD0/PENIRQDescription
00EnabledPower-down between conversions
01DisabledVoltage reference off, ADC on
10EnabledVoltage reference on, ADC off
11DisabledDevice always powered. Voltage reference on, ADC on

/PENIRQ is wired to bit 6 of R2_CR

The DS has wired an external VREF of 3.3 V to the TSC, instead of using the internal 2.5 VREF. This impacts the temperature calculations below, and converting any reading into an actual voltage.

Useful commands:

ConstantValueNotes
TSC_MEASURE_TEMP10x84Measures temperature diode 1
TSC_MEASURE_Y0x94Measures Y position
TSC_MEASURE_BATTERY0xA4Does not work on DS, VBAT is grounded
TSC_MEASURE_Z10xB4Measures cross-panel position 1
TSC_MEASURE_Z20xC4Measures cross-panel position 2
TSC_MEASURE_X0xD4Measures X position
TSC_MEASURE_AUX0xE4Measures ?, its non-zero, but I don't know what
TSC_MEASURE_TEMP20xF4Measures temperature diode 2

A 12-bit measurment cycle consists of 3 SPI byte transfers:

  • The first transfer sends the command and returns no meaningful data.
  • The second transfer returns 0 measurement(11)..measurment(5)
  • The third transfer returns measurment(4..0) 000

Thus, pseudocode for measuring a TSC input is:

 
BlockingWriteSPI(command);
data = BlockingWriteSPI(0);
data = (data << 5) | (BlockingWriteSPI(0) >> 3);

Temperature calculation:

Temperature diode two has a 91 times larger current, and the absolute temperature can be calculated based on the measurements of the two sensors. I'll present a fixed point algorithm for computing the temperature in degrees C (see the TSC 2046 datasheet for the original equation).

temperature(deg C) = 8490 * (V_I91 - V_I1) - 273*4096; (in 20.12 fixed point)

Reading from the touchscreen controller (SPI)

 
uint16 touchRead(uint32 command) {
  uint16 result;
  while (SERIAL_CR & SERIAL_BUSY) swiDelay(1);

  // Write the command and wait for it to complete
  SERIAL_CR = SERIAL_ENABLE | 0x800 | 0x201;
  SERIAL_DATA = command;
  while (SERIAL_CR & SERIAL_BUSY) swiDelay(1);

  // Write the second command and clock in part of the data
  SERIAL_DATA = 0;
  while (SERIAL_CR & SERIAL_BUSY) swiDelay(1);
  result = SERIAL_DATA;

  // Clock in the rest of the data (last transfer)
  SERIAL_CR = SERIAL_ENABLE | 0x201;
  SERIAL_DATA = 0;
  while (SERIAL_CR & SERIAL_BUSY) swiDelay(1);

  // Return the result
  return ((result & 0x7F) << 5) | (SERIAL_DATA >> 3);
}

Todo: figure out what bit 11, bit 9, and bit 0 are doing (bit 0 is probably the CR select, since the firmware reads have this bit cleared)

Position calculation

 
#define SCREEN_WIDTH   256
#define SCREEN_HEIGHT   192

// those are pixel positions of the two points you click when calibrating
#define TOUCH_CNTRL_X1   (*(vu8*)0x027FFCDC)
#define TOUCH_CNTRL_Y1   (*(vu8*)0x027FFCDD)
#define TOUCH_CNTRL_X2   (*(vu8*)0x027FFCE2)
#define TOUCH_CNTRL_Y2   (*(vu8*)0x027FFCE3)

// those are the corresponding touchscreen values:
#define TOUCH_CAL_X1   (*(vu16*)0x027FFCD8)
#define TOUCH_CAL_Y1   (*(vu16*)0x027FFCDA)
#define TOUCH_CAL_X2   (*(vu16*)0x027FFCDE)
#define TOUCH_CAL_Y2   (*(vu16*)0x027FFCE0)

// linear mapping can be used to go from touchscreen position to pixel position

// precalculate some values
static int16 TOUCH_WIDTH  = TOUCH_CAL_X2 - TOUCH_CAL_X1;
static int16 TOUCH_HEIGHT = TOUCH_CAL_Y2 - TOUCH_CAL_Y1;
static int16 CNTRL_WIDTH  = TOUCH_CNTRL_X2 - TOUCH_CNTRL_X1;
static int16 CNTRL_HEIGHT = TOUCH_CNTRL_Y2 - TOUCH_CNTRL_Y1;


// reading pixel position:
int16 x = (IPC->touchX - (int16) TOUCH_CAL_X1) * CNTRL_WIDTH  / TOUCH_WIDTH  + (int16) TOUCH_CNTRL_X1;
int16 y = (IPC->touchY - (int16) TOUCH_CAL_Y1) * CNTRL_HEIGHT / TOUCH_HEIGHT + (int16) TOUCH_CNTRL_Y1;

Recent Changes (All) | Edit SideBar

Page last modified on October 16, 2005, at 04:27 AM
Edit Page | Page History
Everything done on this project is for the sole purpose of writing interoperable software under Sect. 1201 (f) Reverse Engineering exception of the DMCA.
This site is not affiliated with Nintendo in any manner. Nintendo DS © 2004 Nintendo. TM and ® are trademarks of Nintendo.
Powered by PmWiki