summaryrefslogtreecommitdiff
path: root/util/prog.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2022-09-23 20:20:38 +0200
committerUros Majstorovic <majstor@majstor.org>2022-09-23 20:20:38 +0200
commitf30abc1f75f483ffe78d92d5109b6c1d700925a3 (patch)
treeede5f6a35200f5bfe95d4fdea5cb41ac66e6a0fc /util/prog.c
parent522a419a4139db2023e97e1a9ff2774011f069c9 (diff)
added x230x programming and switching utility; fe310 flash utility;
Diffstat (limited to 'util/prog.c')
-rw-r--r--util/prog.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/util/prog.c b/util/prog.c
new file mode 100644
index 0000000..0227682
--- /dev/null
+++ b/util/prog.c
@@ -0,0 +1,79 @@
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <ftdi.h>
+
+#define FTDI_MAX_EEPROM_SIZE 256
+
+int main(int argc, char *argv[]) {
+ int ret;
+ int val;
+ struct ftdi_context *ftdi;
+ struct ftdi_version_info version;
+ unsigned char buf[FTDI_MAX_EEPROM_SIZE];
+
+ if ((ftdi = ftdi_new()) == 0) {
+ fprintf(stderr, "ftdi_new failed\n");
+ return EXIT_FAILURE;
+ }
+
+ version = ftdi_get_library_version();
+ printf("Initialized libftdi %s (major: %d, minor: %d, micro: %d, snapshot ver: %s)\n",
+ version.version_str, version.major, version.minor, version.micro,
+ version.snapshot_str);
+
+ if ((ret = ftdi_usb_open(ftdi, 0x0403, 0x6015)) < 0) {
+ fprintf(stderr, "Unable to open ftdi device: %d (%s)\n", ret, ftdi_get_error_string(ftdi));
+ ftdi_free(ftdi);
+ return EXIT_FAILURE;
+ }
+
+ ret = ftdi_read_eeprom(ftdi);
+ if (ret < 0) goto ftdi_fin;
+
+ ret = ftdi_eeprom_decode(ftdi, 1);
+ if (ret < 0) goto ftdi_fin;
+
+ ftdi_get_eeprom_value(ftdi, SELF_POWERED, &val);
+ printf("POWER: %x\n", val);
+ ftdi_get_eeprom_value(ftdi, CBUS_FUNCTION_0, &val);
+ printf("CBUS0: %d\n", val);
+ ftdi_get_eeprom_value(ftdi, CBUS_FUNCTION_1, &val);
+ printf("CBUS1: %d\n", val);
+ ftdi_get_eeprom_value(ftdi, CBUS_FUNCTION_2, &val);
+ printf("CBUS2: %d\n", val);
+ ftdi_get_eeprom_value(ftdi, CBUS_FUNCTION_3, &val);
+ printf("CBUS3: %d\n", val);
+
+ ftdi_set_eeprom_value(ftdi, SELF_POWERED, 1);
+ ftdi_set_eeprom_value(ftdi, CBUS_FUNCTION_0, CBUSX_PWREN);
+ ftdi_set_eeprom_value(ftdi, CBUS_FUNCTION_1, CBUSX_IOMODE);
+ /* next rev hw
+ ftdi_set_eeprom_value(ftdi, CBUS_FUNCTION_3, CBUSX_VBUS_SENSE);
+ */
+ ftdi_set_eeprom_value(ftdi, CBUS_FUNCTION_2, CBUSX_TRISTATE);
+ ftdi_set_eeprom_value(ftdi, CBUS_FUNCTION_3, CBUSX_TRISTATE);
+
+ ret = ftdi_eeprom_build(ftdi);
+ if (ret < 0) goto ftdi_fin;
+
+ ret = ftdi_get_eeprom_buf(ftdi, buf, FTDI_MAX_EEPROM_SIZE);
+ if (ret < 0) goto ftdi_fin;
+
+ printf("MISC: %x\n", *buf);
+
+ if ((argc > 1) && (strcmp(argv[1], "do") == 0)) {
+ ret = ftdi_write_eeprom(ftdi);
+ if (ret < 0) goto ftdi_fin;
+ }
+
+ ret = ftdi_usb_close(ftdi);
+
+ftdi_fin:
+ if (ret < 0) {
+ fprintf(stderr, "ERR: %d (%s)\n", ret, ftdi_get_error_string(ftdi));
+ }
+ ftdi_free(ftdi);
+
+ return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+}