FreeCalypso > hg > fc-usbser-tools
changeset 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 | e1629a7c8ae3 |
children | 2e21b551b971 |
files | fteeprom/Makefile fteeprom/fteeprom-read.c |
diffstat | 2 files changed, 22 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/fteeprom/Makefile Thu Sep 07 08:11:12 2023 +0000 +++ b/fteeprom/Makefile Thu Sep 07 08:56:57 2023 +0000 @@ -2,6 +2,7 @@ CFLAGS= -O2 PROGS= ftee-gen2232c ftee-gen2232h ftee-gen232r ftee-mkblank fteeprom-erase \ fteeprom-prog fteeprom-read +LIBS= ../libftmini/libftmini.a ../libuwrap/libuwrap.a INSTALL_PREFIX= /opt/freecalypso @@ -27,8 +28,8 @@ fteeprom-prog: fteeprom-prog.c ${CC} ${CFLAGS} -o $@ $@.c -lftdi -fteeprom-read: fteeprom-read.c - ${CC} ${CFLAGS} -o $@ $@.c -lftdi +fteeprom-read: fteeprom-read.o ${LIBS} + ${CC} ${CFLAGS} -o $@ $@.o ${LIBS} -lusb install: mkdir -p ${INSTBIN}
--- 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); }