Page 1 of 1

Reading KEY_X, KEY_Y from timer interrupt

Posted: Mon Jan 12, 2009 7:03 am
by chukmunnlee
Hi, I'm using the latest version of libnds (1.3.1). I have setup a timer interrupt that fires every 1ms and what it does is to read the keypress. I'm having trouble reading X, Y and touch pad. I'm guessing that the timer interrupt is running on arm 9. Is there a way that I can emulate the old IPC structure? Can't change the way the keys are read because I'm porting an application.

TIA

Regards

Re: Reading KEY_X, KEY_Y from timer interrupt

Posted: Tue Jan 13, 2009 8:39 am
by chukmunnlee
This is what I want to do. In poll_keys(), I can only detect A, not X. TIA

Regards

#include <nds.h>
#include <stdio.h>

//Setup a timer to read the keys
void poll_keys(void) {
scanKeys();
u16 held = keysDown();

if (held & KEY_A)
iprintf("KEY_A\n");

if (held & KEY_X)
iprintf("KEY_X\n");
}

void init_timer(void) {

TIMER0_CR = 0;
TIMER0_DATA = (u16)TIMER_FREQ(1000);
TIMER0_CR = TIMER_ENABLE | TIMER_DIV_1 | TIMER_IRQ_REQ;
irqSet(IRQ_TIMER0, poll_keys);
irqEnable(IRQ_TIMER0);
}

//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------

consoleDemoInit();
init_timer();
while (1)
swiWaitForVBlank();
return 0;
}

Re: Reading KEY_X, KEY_Y from timer interrupt

Posted: Wed Jan 21, 2009 5:46 am
by WinterMute
Being honest, trying to poll the buttons at that speed is more than slightly ridiculous. What's the reasoning behind that?

Re: Reading KEY_X, KEY_Y from timer interrupt

Posted: Wed Jan 21, 2009 6:05 am
by chukmunnlee
That was actually an example. But I've manged to solve the problem. I found that you cannot call irqInit(). The reason is that this seems to disable the ARM7 interrupt for the touch, X and Y keys. After I remove the irqInit() the buttons worked.

Thanks