Ejemplo n.º 1
0
int cyusb_open_exact(unsigned short vid, unsigned short pid)
{
	int r;
	cyusb_handle *h = NULL;
	
	r = libusb_init(NULL);
	if (r) {
	      printf("Error in initializing libusb library...\n");
	      return -1;
	}
	h = libusb_open_device_with_vid_pid(NULL, vid, pid);
	if ( !h ) {
	   printf("Device not found\n");
	   return -2;
	}
	cydev[0].dev     = libusb_get_device(h);
	cydev[0].handle  = h;
  	cydev[nid].vid     = cyusb_getvendor(h);
	cydev[nid].pid     = cyusb_getproduct(h);
	cydev[nid].is_open = 1;
	cydev[nid].busnum  = cyusb_get_busnumber(h);
	cydev[nid].devaddr = cyusb_get_devaddr(h);
	nid = 1;
	return 1;
}
Ejemplo n.º 2
0
int SPI_DOWNLOAD_THREAD::get_fx3_prog_handle()
{
    char *progfile_p, *tmp;
    cyusb_handle *handle;
    int i, j, r;
    struct stat filestat;
#if 0
    r = check_fx3_flashprog(h);
    if ( r == 0 )
        //return 0;
    tmp = getenv("CYUSB_ROOT");
    if (tmp != NULL) {
        i = strlen(tmp);
        progfile_p = (char *)malloc(i + 32);
        strcpy(progfile_p, tmp);
        strcat(progfile_p, "/fx3_images/cyfxflashprog.img");
    }
    else {
        progfile_p = (char *)malloc (32);
        strcpy (progfile_p, "fx3_images/cyfxflashprog.img");
    }

    r = stat(progfile_p, &filestat);
    if ( r != 0 ) {
        printf("Failed to find cyfxflashprog.img file\n");
        //return -1;
    }
#endif
    r = fx3_usbboot_download( qPrintable(QString("/home/linux/app/cyfxflashprog.img")));
   // free (progfile_p);
    if ( r != 0 ) {
        printf("Failed to download flash prog utility\n");
        return -1;
    }

    // Now wait for the flash programmer to enumerate, and get a handle to it.
    for ( j = 0; j < GETHANDLE_TIMEOUT; j++ ) {
        sleep (1);
        for ( i = 0; i < num_devices_detected; i++ ) {
            handle = cyusb_gethandle(i);
            if ( cyusb_getvendor(handle) == FLASHPROG_VID ) {
                r = check_fx3_flashprog(handle);
                if ( r == 0 ) {
                    h = handle;
                    return 0;
                }
            }
        }
    }

    printf("Failed to get handle to flash programmer\n");
    return -2;
}
Ejemplo n.º 3
0
int HostIO_CyUSB::OpenEx(CameraID cID)
{
	int		numDevs;
	USHORT	VID;
	USHORT	PID;
	bool	bFoundDevice = false;

	m_log->Write(2, _T("OpenEx name: %s"), cID.SerialToOpen.c_str());
	
	numDevs = cyusb_open();

	for (int i = 0; i < (int)numDevs; i++) 
	{
		h = cyusb_gethandle(i);
		VID = cyusb_getvendor(h);
		PID = cyusb_getproduct(h);

		std::string SerialNum = std::string("None");
		GetSerialNumber(SerialNum);
		std::string SerialToOpen = SerialNum;
		
		std::string Desc = std::string("None");
		GetDesc(Desc);

		m_log->Write(2, _T("Dev %d:"), i);
		m_log->Write(2, _T(" SerialNumber=%s"), SerialNum.c_str());
		m_log->Write(2, _T(" Description=%s"), Desc.c_str());

		if (VID == QSICyVID && PID == QSICyPID && SerialNum == cID.SerialToOpen )
		{
			m_log->Write(2, _T("USB Open found QSI Cy device at index: %d, Serial: %s, Description: %s"), 
							i, SerialNum.c_str(), Desc.c_str());
			bFoundDevice = true;
			break;
		}
	}
	
	if (bFoundDevice && cyusb_kernel_driver_active(h, 0) == 0 && cyusb_claim_interface(h, 0) == 0)
	{
		SetTimeouts(READ_TIMEOUT, WRITE_TIMEOUT);		
	}
	else
	{
		m_log->Write(2, "No devices matched");
	}

	m_log->Write(2, _T("OpenEx Done."));

	return bFoundDevice ? ALL_OK : ERR_USB_OpenFailed;
}
Ejemplo n.º 4
0
int HostIO_CyUSB::ListDevices(std::vector<CameraID> & vID )
{
	int		numDevs;
	USHORT	VID;
	USHORT	PID;

	m_log->Write(2, _T("ListDevices started."));
	numDevs = cyusb_open();

	for (int i = 0; i < (int)numDevs; i++) 
	{
		h = cyusb_gethandle(i);
		VID = cyusb_getvendor(h);
		PID = cyusb_getproduct(h);

		std::string SerialNum = std::string("None");
		GetSerialNumber(SerialNum);
		std::string SerialToOpen = SerialNum;
		
		std::string Desc = std::string("None");
		GetDesc(Desc);
		
		m_log->Write(2, _T("Dev %d:"), i);
		m_log->Write(2, _T(" SerialNumber=%s"), SerialNum.c_str());
		m_log->Write(2, _T(" Description=%s"), Desc.c_str());

		if (VID == QSICyVID && PID == QSICyPID && !SerialNum.empty() )
		{
			m_log->Write(2, 
			             _T("USB ListDevices found QSI Cy device at index: %d, Serial: %s, Description: %s"), 
						 i, 
			             SerialNum.c_str(), 
			             Desc.c_str()
			             );
			CameraID id(SerialNum, SerialToOpen, Desc, VID, PID, CameraID::CP_CyUSB);
			vID.push_back(id);
		}
	}
	
	cyusb_close();
	
	m_log->Write(2, _T("USB ListDevices Done. Number of devices found: %d"), numDevs);
	return S_OK;
}
Ejemplo n.º 5
0
static int renumerate(void)
{
	cyusb_device *dev = NULL;
	cyusb_handle *handle = NULL;
	int found = 0;
	int i;
	int r;

	numdev = libusb_get_device_list(NULL, &list);
	if ( numdev < 0 ) {
	   printf("Library: Error in enumerating devices...\n");
	   return -4;
	}

	nid = 0;

	for ( i = 0; i < numdev; ++i ) {
		cyusb_device *tdev = list[i];
		if ( device_is_of_interest(tdev) ) {
		   cydev[nid].dev = tdev;
		   r = libusb_open(tdev, &cydev[nid].handle);
		   if ( r ) {
		      printf("Error in opening device\n");
		      return -5;
		   }
		   else handle = cydev[nid].handle;
		   cydev[nid].vid     = cyusb_getvendor(handle);
		   cydev[nid].pid     = cyusb_getproduct(handle);
		   cydev[nid].is_open = 1;
		   cydev[nid].busnum  = cyusb_get_busnumber(handle);
		   cydev[nid].devaddr = cyusb_get_devaddr(handle);
		   ++nid;
		}
	}
	return nid;
}
int main(int argc, char **argv)
{
	int r;
	char user_input = 'n';
	pthread_t tid1, tid2;

	program_name = argv[0];
	
	while ( (next_option = getopt_long(argc, argv, short_options, 
					   long_options, NULL) ) != -1 ) {
		switch ( next_option ) {
			case 'h': /* -h or --help  */
				  print_usage(stdout, 0);
			case 'v': /* -v or --version */
				  printf("%s (Ver 1.0)\n",program_name);
				  printf("Copyright (C) 2012 Cypress Semiconductors Inc. / ATR-LABS\n");
				  exit(0);
			case 't': /* -t or --timeout  */
				  timeout_provided = 1;
				  timeout = atoi(optarg);
				  break;
			case '?': /* Invalid option */
				  print_usage(stdout, 1);
			default : /* Something else, unexpected */
				  abort();
		}
	} 

	validate_inputs();

	r = cyusb_open();
	if ( r < 0 ) {
	   printf("Error opening library\n");
	   return -1;
	}
	else if ( r == 0 ) {
		printf("No device found\n");
		return 0;
	}
	if ( r > 1 ) {
		printf("More than 1 devices of interest found. Disconnect unwanted devices\n");
		return 0;
	}
	h1 = cyusb_gethandle(0);
	if ( cyusb_getvendor(h1) != 0x04b4 ) {
	  	printf("Cypress chipset not detected\n");
		cyusb_close();
	  	return 0;
	}
	r = cyusb_kernel_driver_active(h1, 0);
	if ( r != 0 ) {
	   printf("kernel driver active. Exitting\n");
	   cyusb_close();
	   return 0;
	}
	r = cyusb_claim_interface(h1, 0);
	if ( r != 0 ) {
	   printf("Error in claiming interface\n");
	   cyusb_close();
	   return 0;
	}
	else printf("Successfully claimed interface\n");
	r = pthread_create(&tid1, NULL, reader, NULL);
	r = pthread_create(&tid2, NULL, writer, NULL);
	while ( 1) {
		pause();
	}
	cyusb_close();
	return 0;
}
Ejemplo n.º 7
0
/* Get the handle to the FX3 flash programmer device, if found. */
static int
get_fx3_prog_handle (
		cyusb_handle **h)
{
	char *progfile_p, *tmp;
	cyusb_handle *handle;
	int i, j, r;
	struct stat filestat;

	handle = *h;
	r = check_fx3_flashprog (handle);
	if (r == 0)
		return 0;

	printf ("Info: Trying to download flash programmer to RAM\n");

	tmp = getenv ("CYUSB_ROOT");
	if (tmp != NULL) {
		i = strlen (tmp);
		progfile_p = (char *)malloc (i + 32);
		strcpy (progfile_p, tmp);
		strcat (progfile_p, "/fx3_images/cyfxflashprog.img");
	}
	else {
		progfile_p = (char *)malloc (32);
		strcpy (progfile_p, "fx3_images/cyfxflashprog.img");
	}

	r = stat (progfile_p, &filestat);
	if (r != 0) {
		fprintf (stderr, "Error: Failed to find cyfxflashprog.img file\n");
		return -1;
	}

	r = fx3_usbboot_download (handle, progfile_p);
	free (progfile_p);
	if (r != 0) {
		fprintf (stderr, "Error: Failed to download flash prog utility\n");
		return -1;
	}

	cyusb_close ();
	*h = NULL;

	// Now wait for the flash programmer to enumerate, and get a handle to it.
	for (j = 0; j < GETHANDLE_TIMEOUT; j++) {
		sleep (1);
		r = cyusb_open ();
		if (r > 0) {
			for (i = 0; i < r; i++) {
				handle = cyusb_gethandle (i);
				if (cyusb_getvendor (handle) == FLASHPROG_VID) {
					r = check_fx3_flashprog (handle);
					if (r == 0) {
						printf ("Info: Got handle to FX3 flash programmer\n");
						*h = handle;
						return 0;
					}
				}
			}
			cyusb_close ();
		}
	}

	fprintf (stderr, "Error: Failed to get handle to flash programmer\n");
	return -2;
}