Debian Codegraph @

examples/bitbang2.c

raw symbols SCIP
1 /* ftdi_out.c
2 *
3 * Output a (stream of) byte(s) in bitbang mode to the
4 * ftdi245 chip that is (hopefully) attached.
5 *
6 * We have a little board that has a FT245BM chip and
7 * the 8 outputs are connected to several different
8 * things that we can turn on and off with this program.
9 *
10 * If you have an idea about hardware that can easily
11 * interface onto an FTDI chip, I'd like to collect
12 * ideas. If I find it worthwhile to make, I'll consider
13 * making it, I'll even send you a prototype (against
14 * cost-of-material) if you want.
15 *
16 * At "harddisk-recovery.nl" they have a little board that
17 * controls the power to two harddrives and two fans.
18 *
19 * -- REW [email protected]
20 *
21 *
22 *
23 * This program was based on libftdi_example_bitbang2232.c
24 * which doesn't carry an author or attribution header.
25 *
26 *
27 * This program is distributed under the GPL, version 2.
28 * Millions copies of the GPL float around the internet.
29 */
30
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <ftdi.h>cxx . . $ `<file>/src/ftdi.h`/
36
37 void ftdi_fatalcxx . . $ ftdi_fatal(280a46e282bb4216). (struct ftdi_contextcxx . . $ ftdi_context# *ftdi, char *str)
38 {
39 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: %s\n",
40 str, ftdi_get_error_stringcxx . . $ ftdi_get_error_string(318567b992c3484e). (ftdi));
41 ftdi_freecxx . . $ ftdi_free(a4aec54891bac95c).(ftdi);
42 exitcxx . . $ exit(3ca292c338df9bb3). (1);
43 }
44
45 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv)
46 {
47 struct ftdi_contextcxx . . $ ftdi_context# *ftdi;
48 int i, t;
49 unsigned char data;
50 int delay = 100000; /* 100 thousand microseconds: 1 tenth of a second */
51
52 while ((t = getoptcxx . . $ getopt(2483c31ff9bab884). (argc, argv, "d:")) != -1)
53 {
54 switch (t)
55 {
56 case 'd':
57 delay = atoicxx . . $ atoi(5c4306d8553b3696). (optargcxx . . $ optarg.);
58 break;
59 }
60 }
61
62 if ((ftdi = ftdi_newcxx . . $ ftdi_new(207ff50971a1b30).()) == 0)
63 {
64 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "ftdi_bew failed\n");
65 return EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:96:9`!;
66 }
67
68 if (ftdi_usb_opencxx . . $ ftdi_usb_open(cfc3cf95535913f).(ftdi, 0x0403, 0x6001) < 0)
69 ftdi_fatalcxx . . $ ftdi_fatal(280a46e282bb4216). (ftdi, "Can't open ftdi device");
70
71 if (ftdi_set_bitmodecxx . . $ ftdi_set_bitmode(fd17119b3c08153d).(ftdi, 0xFF, BITMODE_BITBANGcxx . . $ BITMODE_BITBANG.) < 0)
72 ftdi_fatalcxx . . $ ftdi_fatal(280a46e282bb4216). (ftdi, "Can't enable bitbang");
73
74 for (i=optindcxx . . $ optind.; i < argc ; i++)
75 {
76 sscanfcxx . . $ sscanf(5e8a2c12db2ea735). (argv[i], "%x", &t);
77 data = t;
78 if (ftdi_write_datacxx . . $ ftdi_write_data(8bb9860f18916ed8).(ftdi, &data, 1) < 0)
79 {
80 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"write failed for 0x%x: %s\n",
81 data, ftdi_get_error_stringcxx . . $ ftdi_get_error_string(318567b992c3484e).(ftdi));
82 }
83 usleepcxx . . $ usleep(4c679297bf94b9eb).(delay);
84 }
85
86 ftdi_usb_closecxx . . $ ftdi_usb_close(e7991dd2c21df3a2).(ftdi);
87 ftdi_freecxx . . $ ftdi_free(a4aec54891bac95c).(ftdi);
88 exitcxx . . $ exit(3ca292c338df9bb3). (0);
89 }