Products > Programming

updating fx2pipe to work with libusb-1.0

(1/4) > >>

NiHaoMike:
The Cypress FX2 is a cheap and very versatile high speed interface for USB 2.0. The program fx2pipe makes it easy to use.
https://www.triplespark.net/elec/periph/USB-FX2/software/fx2pipe.html
The problem is that it was built for libusb-0.1 while nowadays libusb-1.0 is used. Therefore, it doesn't work on a modern OS.

--- Code: ---mike@DX79SI /bulk/mike/downloads/fx2pipe-0.8/fx2pipe $ ./fx2pipe -i -0 -8 -ifclk=48o
Firmware config: 0x12 0xe3 0xe0 0x0c 0x12
IO loop running...
Downloading firmware [builtin]...
fx2pipe: wwusb.cc:129: WWUSBDevice::ErrorCode WWUSBDevice::_DoConnect(usb_device*): Assertion `dev_handle_to_dev(udh)==udev' failed.
Aborted

--- End code ---
The culprit is in the file wwusb.cc:

--- Code: ---// Totally evil and fragile extraction of file descriptor from
// guts of libusb.  They don't install usbi.h, which is what we'd need
// to do this nicely.
//
// FIXME if everything breaks someday in the future, look here...
static inline int fd_from_usb_dev_handle(usb_dev_handle *udh)
{
return( *((int*)udh) );
}

// This function is from SSRP: Actually, we don't need it any more.
// Danger, big, fragile KLUDGE.  The problem is that we want to be
// able to get from a usb_dev_handle back to a usb_device, and the
// right way to do this is buried in a non-installed include file.
static inline struct usb_device *dev_handle_to_dev(usb_dev_handle *udh)
{
struct usb_dev_handle_kludge {
int fd;
struct usb_bus *bus;
struct usb_device *device;
};

return(((struct usb_dev_handle_kludge *) udh)->device);
}

--- End code ---
As seen from https://github.com/libusb/libusb/blob/master/libusb/libusbi.h the internals of the device handle has changed considerably:

--- Code: ---struct libusb_device {
/* lock protects refcnt, everything else is finalized at initialization
* time */
usbi_mutex_t lock;
int refcnt;

struct libusb_context *ctx;
struct libusb_device *parent_dev;

uint8_t bus_number;
uint8_t port_number;
uint8_t device_address;
enum libusb_speed speed;

struct list_head list;
unsigned long session_data;

struct libusb_device_descriptor device_descriptor;
int attached;
};

struct libusb_device_handle {
/* lock protects claimed_interfaces */
usbi_mutex_t lock;
unsigned long claimed_interfaces;

struct list_head list;
struct libusb_device *dev;
int auto_detach_kernel_driver;
};

--- End code ---
The problem is that I do not see anything that corresponds to the file descriptor, unless it got renamed or is embedded into another struct. Anyone with libusb programming experience able to help out?

ataradov:
The simple port will not work. They use FD to pass it to the poll(). And libusb1.0 does the same thing internally, you can't combine the two, since if more than one poll() waits on the FD, only one will wake up at random.

The code is quite a mess. It would seriously be easier to just rewrite it from scratch.

magic:
There was a thread about it recently. Just install libusb-0.1 :D

This program doesn't really use libusb, only initally to discover and open the device. And the libusb API for that has changed AFAIK so even that won't work anymore. You would have to rewrite the whole wwusb thing.

ebclr:
According to the original developer libusb has a lower performance, and was intentionally avoided

magic:
IIRC,

His beef with libusb was that it couldn't queue multiple buffers and left the hardware idle while the software was receiving one buffer and submitting another one. This has since then been fixed in the exact version of libusb which this program doesn't work with.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod