#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.
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]
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]