gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Reading in touch coordinates by myself

#173195 - sylvestersteele - Fri Mar 26, 2010 5:35 am

Hi,

I want to read in the touch coordinates by myself instead of using the libnds API.

I looked up how libnds does it- and pretty much copy pasted that code into my main function. Unfortunately it doesn't work. Following is the code- any help would be appreciated.

Code:


#define    REG_SPICNT   (*(vuint16*)0x040001C0)
#define    SPI_ENABLE   BIT(15)
#define    SPI_BAUD_2MHz   1
#define    SPI_DEVICE_TOUCH   (2 << 8)
#define    SPI_CONTINUOUS   BIT(11)
#define    REG_SPIDATA   (*(vuint16*)0x040001C2)
#define    TSC_MEASURE_X   0xD0
#define    SPI_BUSY   BIT(7)

void SerialWaitBusy(){
    
       while (REG_SPICNT & SPI_BUSY)
         printf ("\nWaiting...");
                swiDelay(1);

}



   uint32 oldIME;
uint16 result, result2;
int ctr=0;
 consoleDemoInit();
   printf("      Hello DS dev'rs\n");
   printf("     \x1b[32mwww.devkitpro.org\n");
   printf("   \x1b[32;1mwww.drunkencoders.com\x1b[39m");
   

   while(1) {

    oldIME = REG_IME;
   REG_IME = 0;
   SerialWaitBusy();

   // Write the command and wait for it to complete
   REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz |  SPI_DEVICE_TOUCH | SPI_CONTINUOUS; //0x8A01;
   REG_SPIDATA = TSC_MEASURE_X;
   SerialWaitBusy();

   
   REG_SPIDATA = 0;
   SerialWaitBusy();
   result = REG_SPIDATA;

   
   REG_SPICNT = SPI_ENABLE | 0x201;
   REG_SPIDATA = 0;
   SerialWaitBusy();

   result2 = REG_SPIDATA >>3;

   REG_IME = oldIME;


      printf ("\nPosition: %d", (((result & 0x7F) << 5) | result2));
   
   
      swiWaitForVBlank();
   }



I took that from the arm7/touch.c uint16 touchRead(uint32 command) function. The program runs but...

1- I noticed that if I printf the busy bit immediately after the REG_SPICNT = SPI_ENABLE | SPI_BAUD_2MHz | SPI_DEVICE_TOUCH | SPI_CONTINUOUS; //0x8A01; EG_SPIDATA = TSC_MEASURE_X; statements it is never set to busy.

2- Even when I touch the screen it does not return the touched coordinates.

Thanks,
Sylvester[/code]

#173196 - sylvestersteele - Fri Mar 26, 2010 5:44 am

Correction

Code:
int main(){

   uint32 oldIME;
uint16 result, result2;
.
.
.
.

}

#173200 - wintermute - Fri Mar 26, 2010 10:27 am

devkitPro is a vendor, not a library, I corrected your post accordingly.

The touch screen is only accessible from arm7 code, you can't read it directly from the arm9.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#173202 - vuurrobin - Fri Mar 26, 2010 10:30 am

sylvestersteele wrote:

I want to read in the touch coordinates by myself instead of using the libnds API.


why do you want to do that?
_________________
my blog:
http://vuurrobin.100webcustomers.com/

#173204 - sylvestersteele - Fri Mar 26, 2010 4:49 pm

So- the code runs by default on arm9- but I now need to get it to run on the arm7. How do I do that?


Also- Does only the arm9 have access to the screen? If so then I need to run the display code on arm9 and the touch screen reading code on arm7. How do I do that?

Thanks,
Sylvester

#173208 - elhobbs - Fri Mar 26, 2010 6:46 pm

sylvestersteele wrote:
Also- Does only the arm9 have access to the screen? If so then I need to run the display code on arm9 and the touch screen reading code on arm7. How do I do that?

Thanks,
Sylvester
if you have to ask the question then you are better off using libnds.

#173211 - fincs - Fri Mar 26, 2010 9:52 pm

sylvestersteele wrote:

I want to read in the touch coordinates by myself instead of using the libnds API.


What's so wrong with libnds that several people want to reimplement the wheel?