# have all needed files, that a GNU package needs
AUTOMAKE_OPTIONS = foreign 1.4
-SUBDIRS = src doc
+SUBDIRS = src examples doc
EXTRA_DIST = libftdi.spec COPYING.LIB README ChangeLog libftdi-config.in
AC_INIT(configure.in)
AM_CONFIG_HEADER(config.h)
-AM_INIT_AUTOMAKE(libftdi, 0.7)
+AM_INIT_AUTOMAKE(libftdi, 0.8)
AC_LANG_C
AC_PROG_CC
AM_CONDITIONAL(HAVE_DOXYGEN, test -n $DOXYGEN);
AC_OUTPUT([libftdi-config],[chmod a+x libftdi-config])
-AC_OUTPUT(Makefile src/Makefile doc/Doxyfile doc/Makefile libftdi.pc)
+AC_OUTPUT(Makefile src/Makefile examples/Makefile doc/Doxyfile doc/Makefile libftdi.pc)
# alphabetically by member name. If set to NO the members will appear in
# declaration order.
-SORT_MEMBER_DOCS = YES
+SORT_MEMBER_DOCS = NO
# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the
# brief documentation of file, namespace and class members alphabetically
# directories that contain example code fragments that are included (see
# the \include command).
-EXAMPLE_PATH =
+EXAMPLE_PATH = ../examples
# If the value of the EXAMPLE_PATH tag contains directories, you can use the
# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
all: $(MANUALS)
-html/index.html: ../src/*.c ../src/*.h
+html/index.html: ../src/*.c ../src/*.h ../examples/*.c
$(DOXYGEN)
--- /dev/null
+METASOURCES = AUTO
+INCLUDES = -I$(top_srcdir)/src
+LDADD = $(top_builddir)/src/libftdi.la
+
+bin_PROGRAMS = simple \
+ bitbang \
+ bitbang2 \
+ bitbang_ft2232
+
+simple_SOURCES = simple.c
+bitbang_SOURCES = bitbang.c
+bitbang2_SOURCES = bitbang2.c
+bitbang_ft2232_SOURCES = bitbang_ft2232.c
--- /dev/null
+/* This program is distributed under the GPL, version 2 */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <ftdi.h>
+
+int main(int argc, char **argv)
+{
+ struct ftdi_context ftdic;
+ int f,i;
+
+ ftdi_init(&ftdic);
+
+ f = ftdi_usb_open(&ftdic, 0x0403, 0x6001);
+
+ if(f < 0 && f != -5) {
+ fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(&ftdic));
+ exit(-1);
+ }
+
+ printf("ftdi open succeeded: %d\n",f);
+
+ printf("enabling bitbang mode\n");
+ ftdi_enable_bitbang(&ftdic, 0xFF);
+
+ char buf[1];
+
+ sleep(3);
+
+ buf[0] = 0x0;
+ printf("turning everything on\n");
+ f = ftdi_write_data(&ftdic, buf, 1);
+ if(f < 0) {
+ fprintf(stderr,"write failed for 0x%x, error %d (%s)\n",buf[0],f, ftdi_get_error_string(&ftdic));
+ }
+
+ sleep(3);
+
+ buf[0] = 0xFF;
+ printf("turning everything off\n");
+ f = ftdi_write_data(&ftdic, buf, 1);
+ if(f < 0) {
+ fprintf(stderr,"write failed for 0x%x, error %d (%s)\n",buf[0],f, ftdi_get_error_string(&ftdic));
+ }
+
+ sleep(3);
+
+ for(i = 0; i < 32; i++) {
+ buf[0] = 0 | (0xFF ^ 1 << (i % 8));
+ if( i > 0 && (i % 8) == 0) {
+ printf("\n");
+ }
+ printf("%02hhx ",buf[0]);
+ fflush(stdout);
+ f = ftdi_write_data(&ftdic, buf, 1);
+ if(f < 0) {
+ fprintf(stderr,"write failed for 0x%x, error %d (%s)\n",buf[0],f, ftdi_get_error_string(&ftdic));
+ }
+ sleep(1);
+ }
+
+ printf("\n");
+
+ printf("disabling bitbang mode\n");
+ ftdi_disable_bitbang(&ftdic);
+
+ ftdi_usb_close(&ftdic);
+ ftdi_deinit(&ftdic);
+}
--- /dev/null
+/* ftdi_out.c
+ *
+ * Output a (stream of) byte(s) in bitbang mode to the
+ * ftdi245 chip that is (hopefully) attached.
+ *
+ * We have a little board that has a FT245BM chip and
+ * the 8 outputs are connected to several different
+ * things that we can turn on and off with this program.
+ *
+ * If you have an idea about hardware that can easily
+ * interface onto an FTDI chip, I'd like to collect
+ * ideas. If I find it worthwhile to make, I'll consider
+ * making it, I'll even send you a prototype (against
+ * cost-of-material) if you want.
+ *
+ * At "harddisk-recovery.nl" they have a little board that
+ * controls the power to two harddrives and two fans.
+ *
+ * -- REW R.E.Wolff@BitWizard.nl
+ *
+ *
+ *
+ * This program was based on libftdi_example_bitbang2232.c
+ * which doesn't carry an author or attribution header.
+ *
+ *
+ * This program is distributed under the GPL, version 2.
+ * Millions copies of the GPL float around the internet.
+ */
+
+
+#include <stdio.h>
+#include <unistd.h>
+#include <ftdi.h>
+
+void ftdi_fatal (struct ftdi_context *ftdi, char *str)
+{
+ fprintf (stderr, "%s: %s\n",
+ str, ftdi_get_error_string (ftdi));
+ exit (1);
+}
+
+int main(int argc, char **argv)
+{
+ struct ftdi_context ftdic;
+ int i, t;
+ unsigned char data;
+ int delay = 100000; /* 100 thousand microseconds: 1 tenth of a second */
+
+ while ((t = getopt (argc, argv, "d:")) != -1) {
+ switch (t) {
+ case 'd':
+ delay = atoi (optarg);
+ break;
+ }
+ }
+
+ ftdi_init(&ftdic);
+
+ if (ftdi_usb_open(&ftdic, 0x0403, 0x6001) < 0)
+ ftdi_fatal (&ftdic, "Can't open ftdi device");
+
+ if (ftdi_enable_bitbang(&ftdic, 0xFF) < 0)
+ ftdi_fatal (&ftdic, "Can't enable bitbang");
+
+ for (i=optind; i < argc ; i++) {
+ sscanf (argv[i], "%x", &t);
+ data = t;
+ if(ftdi_write_data(&ftdic, &data, 1) < 0) {
+ fprintf(stderr,"write failed for 0x%x: %s\n",
+ data, ftdi_get_error_string(&ftdic));
+ }
+ usleep(delay);
+ }
+
+ ftdi_usb_close(&ftdic);
+ ftdi_deinit(&ftdic);
+ exit (0);
+}
--- /dev/null
+/* This program is distributed under the GPL, version 2 */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <ftdi.h>
+
+int main(int argc, char **argv)
+{
+ struct ftdi_context ftdic,ftdic2;
+ int f,i;
+
+ ftdi_init(&ftdic);
+
+ f = ftdi_usb_open(&ftdic, 0x0403, 0x6001);
+
+ if(f < 0 && f != -5) {
+ fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(&ftdic));
+ exit(-1);
+ }
+
+ printf("ftdi open succeeded: %d\n",f);
+
+ printf("enabling bitbang mode\n");
+ ftdi_enable_bitbang(&ftdic, 0xFF);
+
+ ftdic2.interface=1;
+ ftdic2.index=1;
+ ftdic2.out_ep=0x83;
+ ftdic2.in_ep=0x4;
+
+ f = ftdi_usb_open(&ftdic2, 0x0403, 0x6001);
+
+ if(f < 0 && f != -5) {
+ fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(&ftdic));
+ exit(-1);
+ }
+
+ printf("ftdi open succeeded: %d\n",f);
+
+ printf("enabling bitbang mode\n");
+ ftdi_enable_bitbang(&ftdic2, 0xFF);
+
+
+ char buf[1];
+
+ sleep(3);
+
+ buf[0] = 0x0;
+ printf("turning everything on\n");
+ f = ftdi_write_data(&ftdic, buf, 1);
+ if(f < 0) {
+ fprintf(stderr,"write failed for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(&ftdic));
+ }
+
+ sleep(3);
+
+ buf[0] = 0xFF;
+ printf("turning everything off\n");
+ f = ftdi_write_data(&ftdic, buf, 1);
+ if(f < 0) {
+ fprintf(stderr,"write failed for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(&ftdic));
+ }
+
+ sleep(3);
+
+ for(i = 0; i < 32; i++) {
+ buf[0] = 0 | (0xFF ^ 1 << (i % 8));
+ if( i > 0 && (i % 8) == 0) {
+ printf("\n");
+ }
+ printf("%02hhx ",buf[0]);
+ fflush(stdout);
+ f = ftdi_write_data(&ftdic, buf, 1);
+ if(f < 0) {
+ fprintf(stderr,"write failed for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(&ftdic));
+ }
+ sleep(1);
+ }
+
+ printf("\n");
+
+ printf("disabling bitbang mode\n");
+ ftdi_disable_bitbang(&ftdic);
+
+ ftdi_usb_close(&ftdic);
+ ftdi_deinit(&ftdic);
+}
--- /dev/null
+#include <stdio.h>
+#include <ftdi.h>
+
+int main(int argc, char **argv)
+{
+ int ret;
+ struct ftdi_context ftdic;
+ ftdi_init(&ftdic);
+
+ if((ret = ftdi_usb_open(&ftdic, 0x0403, 0x6001)) < 0) {
+ fprintf(stderr, "unable to open ftdi device: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
+ return EXIT_FAILURE;
+ }
+
+ ftdi_usb_close(&ftdic);
+ ftdi_deinit(&ftdic);
+
+ return EXIT_SUCCESS;
+}
/**
\mainpage libftdi API documentation
- Library to talk to FTDI chips. See http://www.ftdichip.com
-
- The latest versions of libftdi is available at
+ Library to talk to FTDI chips. You find the latest versions of libftdi at
http://www.intra2net.com/de/produkte/opensource/ftdi/
+ The library is easy to use. Have a look at this short example:
+ \include simple.c
+
+ More examples can be found in the "examples" directory.
*/
/** \addtogroup libftdi */
/* @{ */