- if (type == MEMORY_SIZE_8K)
- return 8*1024;
- else if (type == MEMORY_SIZE_64K)
- return 64*1024;
- else if (type == MEMORY_SIZE_128K)
- return 128*1024;
- else if (type == MEMORY_SIZE_512K)
- return 512*1024;
- else
- return 0;
-}
-
-struct sigrok_device_instance *zp_open_device(int device_index)
-{
- struct sigrok_device_instance *sdi;
- libusb_device **devlist;
- struct libusb_device_descriptor des;
- int err, i, j;
-
- if(!(sdi = get_sigrok_device_instance(device_instances, device_index)))
- return NULL;
-
- libusb_get_device_list(usb_context, &devlist);
- if(sdi->status == ST_INACTIVE) {
- /* find the device by vendor, product, bus and address */
- libusb_get_device_list(usb_context, &devlist);
- for(i = 0; devlist[i]; i++) {
- if( (err = libusb_get_device_descriptor(devlist[i], &des)) ) {
- g_warning("failed to get device descriptor: %d", err);
- continue;
- }
-
- if(des.idVendor == USB_VENDOR) {
- if(libusb_get_bus_number(devlist[i]) == sdi->usb->bus &&
- libusb_get_device_address(devlist[i]) == sdi->usb->address) {
- for (j = 0; j < sizeof(zeroplus_models) / sizeof(zeroplus_models[0]); j++) {
- if (des.idProduct == zeroplus_models[j].pid) {
- g_message("Found PID=%04X (%s)", des.idProduct, zeroplus_models[j].model_name);
- num_channels = zeroplus_models[j].channels;
- memory_size = zeroplus_models[j].sample_depth * 1024;
- break;
- }
- }
- if (num_channels == 0) {
- g_warning("Unknown ZeroPlus device %04X", des.idProduct);
- continue;
- }
- /* found it */
- if( !(err = libusb_open(devlist[i], &(sdi->usb->devhdl))) ) {
- sdi->status = ST_ACTIVE;
- g_message("opened device %d on %d.%d interface %d", sdi->index,
- sdi->usb->bus, sdi->usb->address, USB_INTERFACE);
- }
- else {
- g_warning("failed to open device: %d", err);
- sdi = NULL;
- }
- }
- }
- }
- }
- else {
- /* status must be ST_ACTIVE, i.e. already in use... */
- sdi = NULL;
- }
- libusb_free_device_list(devlist, 1);
-
- if(sdi && sdi->status != ST_ACTIVE)
- sdi = NULL;
-
- return sdi;
-}
-
-
-static void close_device(struct sigrok_device_instance *sdi)
-{
-
- if(sdi->usb->devhdl)
- {
- g_message("closing device %d on %d.%d interface %d", sdi->index, sdi->usb->bus,
- sdi->usb->address, USB_INTERFACE);
- libusb_release_interface(sdi->usb->devhdl, USB_INTERFACE);
- libusb_close(sdi->usb->devhdl);
- sdi->usb->devhdl = NULL;
- sdi->status = ST_INACTIVE;
- }
-