Welcome! Log In Create A New Profile

Advanced

Code does not find any usb devices

Posted by zezke 
Code does not find any usb devices
June 17, 2009 07:47PM
Well i was experimenting a bit with usb devices on the wii, but my code returns that there are zero devices present, despite the fact that my external hard drive is powered and connected and my usb microphone is connected. Am i doing anything wrong?

My code:
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define DEVLIST_MAXSIZE	8

static u32 *xfb;
static GXRModeObj *rmode;


void Initialise() {
	VIDEO_Init();
	WPAD_Init();
 
	rmode = VIDEO_GetPreferredMode(NULL);

	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
 
	VIDEO_Configure(rmode);
	VIDEO_SetNextFramebuffer(xfb);
	VIDEO_SetBlack(FALSE);
	VIDEO_Flush();
	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
}

void waitForButtonDown(int button){
	u16 buttonsDown;
	do {
		WPAD_ScanPads();
		buttonsDown = WPAD_ButtonsDown(0);
	} while(!(buttonsDown & button));
	printf("Button pressed\n");
}

int main() {
 
	Initialise();
	
	s32 test = USB_Initialize();
	printf("USB has been initialized: %d\n", test);
	printf("Press A to continue...\n\n");
	waitForButtonDown(WPAD_BUTTON_A);
	
	u8 n;
	u8* buffer;
	buffer = memalign(32, DEVLIST_MAXSIZE << 3);
	memset(buffer, 0, DEVLIST_MAXSIZE << 3);
	printf("DEVLIST_MAXSIZE: %x\n", (DEVLIST_MAXSIZE << 3));
	if(buffer != NULL){
		test = USB_GetDeviceList("/dev/usb/oh0",buffer,DEVLIST_MAXSIZE, 0, &n);
		printf("Getting usb device list: %d\n", test);
		printf("Found %d devices!\n",n);
	}
	else
		printf("Error: buffer is null.\n");
	printf("Press A to continue...\n\n");
	waitForButtonDown(WPAD_BUTTON_A);
	
	test = USB_Deinitialize();
	printf("USB has been deinitialized: %d\n", test);
	printf("Press B to continue...\n");
	waitForButtonDown(WPAD_BUTTON_B);
 
	printf("Exiting...\n");
	return 0;
}

For my usb related code i looked at this example
Re: Code does not find any usb devices
June 18, 2009 05:00AM
That's old code. There's at least one major bug with it, IOS expects MEM2 for USB stuff. So this is no good:
buffer = memalign(32, DEVLIST_MAXSIZE << 3);

You should take a look at usbstorage.c (and other usb code) in devkitpro svn, but one way is:

static s32 hId = -1;
buffer = iosAlloc(hId, DEVLIST_MAXSIZE << 3);

Also keep in mind that not all usb devices are detected. You can take a look at the usb2 support cios (202) and code for that, but it's still experimental.
Sorry, only registered users may post in this forum.

Click here to login