//find_cypress.c 	scans the USB busses to find an
//cypress FX2   68013
//

//             (C) Marko Cebokli S57UUU  jul 2007
//             GNU/GPL licence:  www.gnu.org/licences/licences.html#GPL

//compile:  gcc -lusb find_cypress.c -o find_cypress

#include <stdio.h>
#include <usb.h>

int main()
{
struct usb_bus *p,*cbus;
struct usb_device *q;
struct usb_device *current_device;
usb_dev_handle *current_handle;
int er[5];

usb_init();
er[0]=usb_find_busses();
er[1]=usb_find_devices();

p=usb_busses;
current_device=NULL;
while(p!=NULL)			//find the CY7C68013
	{
	printf("\nUSB bus %s",p->dirname);
	q=p->devices;
	while(q!=NULL)
		{
		printf("\n	device: %s     ",q->filename);
		printf("vendor=%4x ",q->descriptor.idVendor);
		printf("product=%4x",q->descriptor.idProduct);
		if ((q->descriptor.idVendor==0x4b4)&&(q->descriptor.idProduct==0x8613))
			{
			current_device=q;
			cbus=p;
			}
		q=q->next;
		}
	p=p->next;
	}
fflush(stdout);

if (current_device==NULL)
	{
	printf("\n\nCould not find an (unconfigured) CY7C68013 device!\n\n");
	exit(EXIT_FAILURE);
	}
else
	{
	printf("\n\nFound an unconfigured CY7C68013 device ");
	printf("on bus %s as device %s",cbus->dirname,current_device->filename);
	}

printf("\n\n");fflush(stdout);

return 0;
}
