Reading KEY_X, KEY_Y from timer interrupt

Post Reply
chukmunnlee
Posts: 7
Joined: Wed Aug 13, 2008 2:56 am

Reading KEY_X, KEY_Y from timer interrupt

Post by chukmunnlee » Mon Jan 12, 2009 7:03 am

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

chukmunnlee
Posts: 7
Joined: Wed Aug 13, 2008 2:56 am

Re: Reading KEY_X, KEY_Y from timer interrupt

Post by chukmunnlee » Tue Jan 13, 2009 8:39 am

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;
}

WinterMute
Site Admin
Posts: 2003
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Reading KEY_X, KEY_Y from timer interrupt

Post by WinterMute » Wed Jan 21, 2009 5:46 am

Being honest, trying to poll the buttons at that speed is more than slightly ridiculous. What's the reasoning behind that?
Help keep devkitPro toolchains free, Donate today

Personal Blog

chukmunnlee
Posts: 7
Joined: Wed Aug 13, 2008 2:56 am

Re: Reading KEY_X, KEY_Y from timer interrupt

Post by chukmunnlee » Wed Jan 21, 2009 6:05 am

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest