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
Reading KEY_X, KEY_Y from timer interrupt
-
- Posts: 7
- Joined: Wed Aug 13, 2008 2:56 am
Re: Reading KEY_X, KEY_Y from timer interrupt
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;
}
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;
}
-
- Site Admin
- Posts: 2003
- Joined: Tue Aug 09, 2005 3:21 am
- Location: UK
- Contact:
Re: Reading KEY_X, KEY_Y from timer interrupt
Being honest, trying to poll the buttons at that speed is more than slightly ridiculous. What's the reasoning behind that?
-
- Posts: 7
- Joined: Wed Aug 13, 2008 2:56 am
Re: Reading KEY_X, KEY_Y from timer interrupt
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
Thanks
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 7 guests