Changes

Jump to navigation Jump to search
5,226 bytes added ,  02:03, 22 February 2008
New page: To code computer side usbgecko application you need : * For Win32 : [http://www.ftdichip.com/Drivers/D2XX.htm API] [http://www.ftdichip.com/Documents/ProgramGuides/D2XXPG34.pdf DOC] * F...
To code computer side usbgecko application you need :

* For Win32 : [http://www.ftdichip.com/Drivers/D2XX.htm API] [http://www.ftdichip.com/Documents/ProgramGuides/D2XXPG34.pdf DOC]

* For Linux : [http://www.intra2net.com/de/produkte/opensource/ftdi/ API] [http://www.intra2net.com/de/produkte/opensource/ftdi/documentation/group__libftdi.html DOC]



I have started a linux application, all seems ok, except the ftdi_read_data that always return 0 :/
For those who interrested this page can be a base to make a usable application.

#include <stdio.h>
#include <sys/types.h>
#include <ftdi.h>

//-------------------------- Globals ----------------------------------
int32_t status;
int ret;
int32_t TxSent;
int32_t RxSent;

struct ftdi_context ftdic;

int cmd_readmem = 0x04;
//-------------------------- Function Prototypes ----------------------------------
void gecko_opendevice();




int main(int argc, char **argv)
{
void* plop;
unsigned char responseback = 0;

ftdi_init(&ftdic);


printf("-----------------------------------\n");
printf("- NoNameNo's UsbGecko Linux Tools -\n");
printf("-----------------------------------\n\n");

gecko_opendevice();
printf("Connecting to Wii.\n");
printf("%x\n",gecko_writebyte(&cmd_readmem,1));
printf("%x\n",gecko_readbyte(&responseback, 1));
ftdi_usb_close(&ftdic);
ftdi_deinit(&ftdic);

return EXIT_SUCCESS;
}
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
int gecko_readbyte(unsigned char* lpBuffer, int dwBytesToRead)
{
status = ftdi_read_data(&ftdic, lpBuffer, dwBytesToRead);

if (status > 0){
if(status != dwBytesToRead){
return 2;
}
}
else{
printf("[Error] UsbGecko Reading Device\n");
//ftdi_usb_close(&ftdic);
//ftdi_deinit(&ftdic);
return status;
}

return 1;
}

//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
int gecko_writebyte(unsigned char* lpBuffer, int dwBytesToWrite)
{
status = ftdi_write_data(&ftdic, lpBuffer, dwBytesToWrite);

if (status > 0){
if(status != dwBytesToWrite){
return 2;
}
}
else{
printf("[Error] UsbGecko Writing Device\n");
ftdi_usb_close(&ftdic);
ftdi_deinit(&ftdic);
return 0;
}

return 1;
}



//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
void gecko_opendevice()
{
//---------------------------open device --------------------------------------
if((ret = ftdi_usb_open(&ftdic, 0x0403, 0x6001)) < 0) {
printf("[Error] UsbGecko NOT Detected\n");
exit(0);
}
else{
printf("[OK] UsbGecko Detected\n");
}


//---------------------------Reset device --------------------------------------
if((ret = ftdi_usb_reset(&ftdic)) < 0) {
printf("[Error] UsbGecko Reseting Device \n");
ftdi_usb_close(&ftdic);
ftdi_deinit(&ftdic);
exit(0);
}
else{
printf("[OK] UsbGecko Reseted\n");
}


//---------------------------SetTimeOut to 2000 --------------------------------------
ftdic.usb_read_timeout=2000;
ftdic.usb_write_timeout=2000;
printf("[OK] UsbGecko Setted 2 sec timout\n");

//---------------------------Purging RX/TX buffers --------------------------------------
if((ret = ftdi_usb_purge_buffers(&ftdic)) < 0) {
printf("[Error] UsbGecko Purging Buffer \n");
ftdi_usb_close(&ftdic);
ftdi_deinit(&ftdic);
exit(0);
}
else{
printf("[OK] UsbGecko Purged RX/TX buffers\n");
}


//---------------------------SetTimeOut to 2000 --------------------------------------
if((ret = ftdi_read_data_set_chunksize(&ftdic,2000)) < 0) {
printf("[Error] UsbGecko Setting RX time out \n");
ftdi_usb_close(&ftdic);
ftdi_deinit(&ftdic);
exit(0);
}
else{
printf("[OK] UsbGecko Setted RX Timeout\n");
}


//--------------------------- Set RX/TX size buffer --------------------------------------
if((ret = ftdi_read_data_set_chunksize(&ftdic,2000)) < 0) {
printf("[Error] UsbGecko Setting RX buffer size\n");
ftdi_usb_close(&ftdic);
ftdi_deinit(&ftdic);
exit(0);
}
else{
printf("[OK] UsbGecko Setted RX Buffer Size\n");
}
if((ret = ftdi_write_data_set_chunksize(&ftdic,2000)) < 0) {
printf("[Error] UsbGecko Setting TX Buffer size\n");
ftdi_usb_close(&ftdic);
ftdi_deinit(&ftdic);
exit(0);
}
else{
printf("[OK] UsbGecko Setted TX Buffer Size\n");
}


//---------------------------Required ??? --------------------------------------
sleep(1);

}
121

edits

Navigation menu