Line 7:
Line 7:
* For Linux : [http://www.intra2net.com/de/produkte/opensource/ftdi/ API] [http://www.intra2net.com/de/produkte/opensource/ftdi/documentation/group__libftdi.html 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]
−
+
==Hardware==
−
I have started a Linux application, all seems ok, except the ftdi_read_data that always return 0 :/
+
The usb gecko is a two step converter to convert EXI<->serial<->usb. It is a fancy serial port. All the fun is provided by software. No, the EXI interrupt is not possible to trigger from the PC.
−
For those who interested this page can be a base to make a usable application.
−
−
<source lang="c">
−
#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");
−
}
−
−
−
−
//--------------------------- Set RX/TX size buffer --------------------------------------
−
if((ret = ftdi_read_data_set_chunksize(&ftdic,65536)) < 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,65536)) < 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);
−
−
}
−
</source>
−
[[Category:Homebrew]]