43 lines
1003 B
C
43 lines
1003 B
C
#include <ftdi.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "ftdi_utils.h"
|
|
|
|
struct ftdi_context *ftdi;
|
|
|
|
int init_ftdi()
|
|
{
|
|
struct ftdi_version_info version;
|
|
uint8_t pins;
|
|
unsigned int chipid;
|
|
|
|
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);
|
|
|
|
int ret = ftdi_usb_open(ftdi, 0x0403, 0x6014);
|
|
if (ret < 0)
|
|
{
|
|
fprintf(stderr, "unable to open ftdi device: %d (%s)\n", ret, ftdi_get_error_string(ftdi));
|
|
ftdi_free(ftdi);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
// Enable bitbang mode
|
|
ftdi_set_bitmode(ftdi, 0xFF, BITMODE_BITBANG);
|
|
|
|
printf("ftdi_read_chipid: %d\n", ftdi_read_chipid(ftdi, &chipid));
|
|
printf("FTDI chipid: %X\n", chipid);
|
|
ftdi_read_pins(ftdi, &pins);
|
|
|
|
printf("Pins state: %X\n", pins);
|
|
|
|
return EXIT_SUCCESS;
|
|
} |