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 > want to use slot 2 GPIO

#171972 - hounjini - Tue Jan 05, 2010 3:46 pm

Hi

I'm trying to make slot2 digital input / ouput.
I read this page(http://nocash.emubase.de/gbatek.htm#gbacartioportgpio)
,and trying to make it working.

Here is my code.

Code:

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

#define REG_DIRECTION (*(vuint16*)0x080000C6)
#define REG_DATA (*(vuint16*)0x080000C4)
#define REG_CONTROL (*(uint16*)0x80000C8)

volatile int frame = 0;
void Vblank() {
    frame++;
}

bool output(void) {
    sysSetCartOwner(true);
    REG_CONTROL = REG_CONTROL & 0x0000;
    REG_CONTROL = REG_CONTROL | 0x0001;
    REG_DIRECTION = REG_DIRECTION & 0x0000;
    REG_DIRECTION = REG_DIRECTION | 0x000F;
    REG_DATA = REG_DATA & 0x0000;
    REG_DATA = REG_DATA | 0x000C;
}


int main(void) {
   touchPosition touchXY;
   irqSet(IRQ_VBLANK, Vblank);
   consoleDemoInit();
   iprintf("      Hello DS dev'rs\n");
   iprintf("     \x1b[32mwww.devkitpro.org\n");
   iprintf("   \x1b[32;1mwww.drunkencoders.com\x1b[39m");
    output();
   while(1) {
      swiWaitForVBlank();
      touchRead(&touchXY);
      iprintf("\x1b[10;0HFrame = %d",frame);
      iprintf("\x1b[16;0HTouch x = %04X, %04X\n", touchXY.rawx, touchXY.px);
      iprintf("Touch y = %04X, %04X\n", touchXY.rawy, touchXY.py);
   }
   return 0;
}


simple hello world code with output(void) function for setting register.
hardware : attached data lines to all slot2 pins and test with led.

thank you for reading my post.
Happy new year!

#172077 - Diddl - Wed Jan 13, 2010 11:04 am

I want do same and look with interest to your project.