# HG changeset patch # User Mychaela Falconia # Date 1694465272 0 # Node ID ae8075bcc02907f0a4c212af93f9ce066e7ad4aa # Parent 672c7adc8bc9142fd2887bd031ff5c8e3c27b60a cp2102-read-baudtab program written, compiles diff -r 672c7adc8bc9 -r ae8075bcc029 .hgignore --- 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$ diff -r 672c7adc8bc9 -r ae8075bcc029 cp2102/Makefile --- 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 diff -r 672c7adc8bc9 -r ae8075bcc029 cp2102/read_baudtab.c --- /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 +#include +#include +#include +#include +#include +#include +#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); +}