FreeCalypso > hg > fc-usbser-tools
changeset 60:ae8075bcc029
cp2102-read-baudtab program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 11 Sep 2023 20:47:52 +0000 |
parents | 672c7adc8bc9 |
children | 7941a5e06d6a |
files | .hgignore cp2102/Makefile cp2102/read_baudtab.c |
diffstat | 3 files changed, 50 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Mon Sep 11 20:38:51 2023 +0000 +++ b/.hgignore Mon Sep 11 20:47:52 2023 +0000 @@ -3,6 +3,7 @@ \.[oa]$ ^cp2102/cp2102-decode-baudtab$ +^cp2102/cp2102-read-baudtab$ ^cp2102/cp2102-read-eeprom$ ^cp2102/cp2102-read-partno$ ^cp2102/file_rw_test$
--- a/cp2102/Makefile Mon Sep 11 20:38:51 2023 +0000 +++ b/cp2102/Makefile Mon Sep 11 20:47:52 2023 +0000 @@ -1,6 +1,7 @@ CC= gcc CFLAGS= -O2 -PROGS= cp2102-decode-baudtab cp2102-read-eeprom cp2102-read-partno +PROGS= cp2102-decode-baudtab cp2102-read-baudtab cp2102-read-eeprom \ + cp2102-read-partno NOINST= file_rw_test LIBS= ../libuwrap/libuwrap.a @@ -9,6 +10,7 @@ INSTBIN=${INSTALL_PREFIX}/bin DECODE_BAUDTAB_OBJS= decode_baudtab.o decode_baudtab_main.o intel_hex_in.o +READ_BAUDTAB_OBJS= decode_baudtab.o read_baudtab.o read_eeprom.o READ_EEPROM_OBJS= intel_hex_out.o read_eeprom.o read_eeprom_main.o RW_TEST_OBJS= intel_hex_in.o intel_hex_out.o file_rw_test.o @@ -17,6 +19,9 @@ cp2102-decode-baudtab: ${DECODE_BAUDTAB_OBJS} ${CC} ${CFLAGS} -o $@ ${DECODE_BAUDTAB_OBJS} +cp2102-read-baudtab: ${READ_BAUDTAB_OBJS} ${LIBS} + ${CC} ${CFLAGS} -o $@ ${READ_BAUDTAB_OBJS} ${LIBS} -lusb + cp2102-read-eeprom: ${READ_EEPROM_OBJS} ${LIBS} ${CC} ${CFLAGS} -o $@ ${READ_EEPROM_OBJS} ${LIBS} -lusb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cp2102/read_baudtab.c Mon Sep 11 20:47:52 2023 +0000 @@ -0,0 +1,43 @@ +/* + * This program locates a CP2102 device via libusb, reads its internal + * 1024-byte EEPROM, decodes the baud rate table portion thereof + * and prints the decoded table. + */ + +#include <sys/types.h> +#include <string.h> +#include <strings.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <usb.h> +#include "../libuwrap/find_dev.h" +#include "cp210x_defs.h" + +u_char eeprom[SIZE_EEPROM]; + +main(argc, argv) + char **argv; +{ + struct usb_device *dev; + usb_dev_handle *usbh; + + if (argc != 2) { + fprintf(stderr, "usage: %s device-selector\n", argv[0]); + exit(1); + } + dev = find_usbdev_by_desc_string(argv[1]); + if (!dev) { + fprintf(stderr, "error: specified USB device not found\n"); + exit(1); + } + usbh = usb_open(dev); + if (!usbh) { + fprintf(stderr, "error: usb_open() failed\n"); + exit(1); + } + read_eeprom(usbh); + usb_close(usbh); + decode_baud_table(stdout); + exit(0); +}