GP32 Usb Communication


Torlus

Still Fresh
Joined
Feb 16, 2004
Messages
17
Hi,

I've done an implementation of Forth for GBA, called PandaForth (see here), and I'd like to port it to GP32.

One of the features of PandaForth for GBA is the ability to code directly on hardware thru a multiboot cable.

For GP32, it seems easier, as it supports USB. I tried to play a bit with some code for USB found on this site, but at the moment I haven't be able to get USB communication work in both ways (I have been able to send data from GP32 to PC, but not the other way).

If anyone has some code (for PC and GP32) of bi-directional USB communcation, it would help me a lot :)
 
Here's how you do the gp32 side (think I found this code on darkfaders site). I did have some linux code for the pc side, but I can't find it now.

Code:
GPN_DESC usb_desc;
GPN_COMM usb_comm;
#define PACKET_SIZE  256

//////////////////////////////////////////////////////////////////////////////
// read                                                                     //
//////////////////////////////////////////////////////////////////////////////
static int usb_read(char *buf, int size)
{
	int done = usb_comm.comm_recv(buf, size);
	/*int done = 0;
	while (done < size)
	{
  int done1 = usb_comm.comm_recv(((char *)buf) + done, size - done);
  if (done1 <= 0) GpThreadSleep(0);
  done += done1;
	}
	//int done = size;
	*/
	return done;
}

//////////////////////////////////////////////////////////////////////////////
// write                                                                    //
//////////////////////////////////////////////////////////////////////////////
static int usb_write(const char *buf, int size)
{
	int done = size;
	done = usb_comm.comm_send((void *)buf, size);
	/*int done = 0;
	while (1)
	{
  int done1 = usb_comm.comm_send(((char *)buf) + done, size - done);
  if (!done1) GpThreadSleep(0);
  done += done1;
	}*/
	return done;
}

//////////////////////////////////////////////////////////////////////////////
// OpenUSB                                                                  //
//////////////////////////////////////////////////////////////////////////////
int OpenUSB()
{
  //	debugInteface->read = read;
  //	debugInteface->write = write;

	//if (!GpUSBLineCheck()) return -1;

	usb_desc.port_kind = COMM_USB_D;
	usb_desc.tr_mode = 1;	// 1=bulk
	usb_desc.tr_buf_size = PACKET_SIZE * 8;
	usb_desc.sz_pkt = PACKET_SIZE;
	usb_desc.isr_comm_ram = 0;
	if (GpCommCreate(&usb_desc, &usb_comm)) return -1;

	return 0;
}

//////////////////////////////////////////////////////////////////////////////
// CloseUSB                                                                 //
//////////////////////////////////////////////////////////////////////////////
void CloseUSB()
{
	GpCommDelete(&usb_desc);
}
 
hmm most of this code is commented out :)
And the remaining part is just plain calls to "comm_*" functions...
Anyway, my mistake probably comes from the PC side, so Linux code for this will be useful. ;)
 
the_Diabologic posted on Mar 13 2005 at 02:00 PM said:
nifty, but wouldn't it be enough at first to have the interpreter read the stuff from a file?
Well I could do this for sure, but that's not the point... It would be by far less funny this way :)
 
Last edited by a moderator:
Ok I have found a solution. For those who might be interested, see the GP32 section of my site (about PandaForth).
 
Back
Top