FreeCalypso > hg > fc-usbser-tools
diff fteeprom/fteeprom-read.c @ 16:1d76deae1e74
fteeprom-read: convert to new local libs
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 07 Sep 2023 08:56:57 +0000 |
parents | 11b8a30333b3 |
children | bb1d0956b0a8 |
line wrap: on
line diff
--- a/fteeprom/fteeprom-read.c Thu Sep 07 08:11:12 2023 +0000 +++ b/fteeprom/fteeprom-read.c Thu Sep 07 08:56:57 2023 +0000 @@ -1,10 +1,20 @@ +/* + * This program connects to an FTDI chip via libusb and reads out its EEPROM. + * The present version has been converted to use our local libraries + * (libftmini and libuwrap) instead of libftdi - thus the external dependency + * is only libusb. + */ + #include <sys/types.h> #include <string.h> #include <strings.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> -#include <ftdi.h> +#include <usb.h> +#include "../libuwrap/find_dev.h" +#include "../libuwrap/open_close.h" +#include "../libftmini/eeprom_func.h" char *device_selector; unsigned eeprom_size = 64; @@ -39,22 +49,20 @@ main(argc, argv) char **argv; { - struct ftdi_context ftdi; + struct usb_device *dev; + usb_dev_handle *usbh; u_short word; unsigned n, col; process_cmdline(argc, argv); - ftdi_init(&ftdi); - if (ftdi_usb_open_string(&ftdi, device_selector) < 0) { - fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str); + dev = find_usbdev_by_desc_string(device_selector); + if (!dev) { + fprintf(stderr, "error: specified USB device not found\n"); exit(1); } + usbh = usbwrap_open_dev(dev, 1); for (n = 0; n < eeprom_size; n++) { - if (ftdi_read_eeprom_location(&ftdi, n, &word) < 0) { - fprintf(stderr, "EEPROM read error: %s\n", - ftdi.error_str); - exit(1); - } + word = ftmini_read_eeprom_loc(usbh, n); col = n & 7; if (col == 0) printf("%02X:", n * 2); @@ -62,6 +70,6 @@ if (col == 7) putchar('\n'); } - ftdi_usb_close(&ftdi); + usbwrap_close_dev(usbh); exit(0); }