/* Copyright (C) 2016 Herbert Poetzl ** ** This program is free software: you can redistribute it and/or ** modify it under the terms of the GNU General Public License ** as published by the Free Software Foundation, either version ** 2 of the License, or (at your option) any later version. */ #include #include #include #include #include #include int main(int argc, char *argv[]) { struct ftdi_context *ctx; struct ftdi_device_list *list; struct libusb_device *fdev = NULL; int res, ret=0; ctx = ftdi_new(); if (!ctx) { printf("ERROR: ftdi_new()\n"); ret = 1; goto err_ctx; } res = ftdi_set_interface(ctx, INTERFACE_A); if (res < 0) { printf("ERROR: ftdi_set_interface() = %d\n", res); ret = 2; goto err_intf; } res = ftdi_usb_find_all(ctx, &list, 0x0403, 0x6014); if (res < 0) { printf("ERROR: ftdi_usb_find_all() = %d\n", res); ret = 3; goto err_list; } else { unsigned cnt = res; struct ftdi_device_list *this = list; for (int i=0; inext; struct libusb_device *dev = this->dev; res = ftdi_usb_get_strings(ctx, dev, mnf, sizeof(mnf), dsc, sizeof(dsc), ser, sizeof(ser)); if (res < 0) { printf("ERROR: ftdi_usb_get_strings() = %d\n", res); } else { printf("[%d] %s - %s - %s\n", i, mnf, dsc, ser); } fdev = dev; this = next; } } res = ftdi_usb_open_dev(ctx, fdev); if (res < 0) { printf("ERROR: ftdi_usb_open_dev() = %d\n", res); ret = 4; goto err_fdev; } res = ftdi_usb_reset(ctx); // USB transfer sizes // Event/error characters // Timeouts // Latency timer // Flow control res = ftdi_set_bitmode(ctx, 0, BITMODE_RESET); res = ftdi_set_bitmode(ctx, 0, BITMODE_MPSSE); unsigned char buf[3] = { 0 }; unsigned char gpioh = atoi(argv[2]); unsigned char trish = atoi(argv[1]); int len = 0; buf[len++] = SET_BITS_HIGH; buf[len++] = gpioh; buf[len++] = trish; res = ftdi_write_data(ctx, buf, len); if (res < 0) { printf("ERROR: ftdi_write_data() = %d\n", res); ret = 5; goto err_fdev; } err_fdev: ftdi_list_free(&list); err_list: err_intf: ftdi_free(ctx); err_ctx: exit(ret); }