Commit | Line | Data |
---|---|---|
08cb09bf TJ |
1 | /* bitbang_ft2232.c |
2 | ||
3 | Output some flickering in bitbang mode to the FT2232 | |
4 | ||
5 | Thanks to max@koeln.ccc.de for fixing and extending | |
6 | the example for the second channel. | |
7 | ||
8 | This program is distributed under the GPL, version 2 | |
9 | */ | |
ad397a4b TJ |
10 | |
11 | #include <stdio.h> | |
12 | #include <unistd.h> | |
13 | #include <ftdi.h> | |
14 | ||
15 | int main(int argc, char **argv) | |
16 | { | |
08cb09bf TJ |
17 | struct ftdi_context ftdic, ftdic2; |
18 | char buf[1]; | |
ad397a4b TJ |
19 | int f,i; |
20 | ||
08cb09bf | 21 | // Init 1. channel |
ad397a4b | 22 | ftdi_init(&ftdic); |
08cb09bf | 23 | ftdi_set_interface(&ftdic, INTERFACE_A); |
ad397a4b | 24 | f = ftdi_usb_open(&ftdic, 0x0403, 0x6001); |
22d12cda TJ |
25 | if (f < 0 && f != -5) |
26 | { | |
ad397a4b TJ |
27 | fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(&ftdic)); |
28 | exit(-1); | |
29 | } | |
08cb09bf | 30 | printf("ftdi open succeeded(channel 1): %d\n",f); |
ad397a4b | 31 | |
08cb09bf | 32 | printf("enabling bitbang mode(channel 1)\n"); |
ad397a4b TJ |
33 | ftdi_enable_bitbang(&ftdic, 0xFF); |
34 | ||
08cb09bf TJ |
35 | // Init 2. channel |
36 | ftdi_init(&ftdic2); | |
37 | ftdi_set_interface(&ftdic2, INTERFACE_B); | |
ad397a4b | 38 | f = ftdi_usb_open(&ftdic2, 0x0403, 0x6001); |
22d12cda TJ |
39 | if (f < 0 && f != -5) |
40 | { | |
08cb09bf | 41 | fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(&ftdic2)); |
ad397a4b TJ |
42 | exit(-1); |
43 | } | |
08cb09bf | 44 | printf("ftdi open succeeded(channel 2): %d\n",f); |
ad397a4b | 45 | |
08cb09bf | 46 | printf("enabling bitbang mode (channel 2)\n"); |
ad397a4b TJ |
47 | ftdi_enable_bitbang(&ftdic2, 0xFF); |
48 | ||
08cb09bf TJ |
49 | // Write data |
50 | printf("startloop\n"); | |
22d12cda TJ |
51 | for (i = 0; i < 23; i++) |
52 | { | |
08cb09bf TJ |
53 | buf[0] = 0x1; |
54 | printf("porta: %02i: 0x%02x \n",i,buf[0]); | |
55 | f = ftdi_write_data(&ftdic, buf, 1); | |
22d12cda | 56 | if (f < 0) |
08cb09bf TJ |
57 | fprintf(stderr,"write failed on channel 1 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(&ftdic)); |
58 | sleep(1); | |
ad397a4b | 59 | |
08cb09bf TJ |
60 | buf[0] = 0x2; |
61 | printf("porta: %02i: 0x%02x \n",i,buf[0]); | |
62 | f = ftdi_write_data(&ftdic, buf, 1); | |
22d12cda | 63 | if (f < 0) |
08cb09bf TJ |
64 | fprintf(stderr,"write failed on channel 1 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(&ftdic)); |
65 | sleep(1); | |
ad397a4b | 66 | |
08cb09bf TJ |
67 | buf[0] = 0x1; |
68 | printf("portb: %02i: 0x%02x \n",i,buf[0]); | |
69 | f = ftdi_write_data(&ftdic2, buf, 1); | |
22d12cda | 70 | if (f < 0) |
08cb09bf TJ |
71 | fprintf(stderr,"write failed on channel 2 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(&ftdic2)); |
72 | sleep(1); | |
ad397a4b | 73 | |
08cb09bf TJ |
74 | buf[0] = 0x2; |
75 | printf("portb: %02i: 0x%02x \n",i,buf[0]); | |
76 | f = ftdi_write_data(&ftdic2, buf, 1); | |
22d12cda | 77 | if (f < 0) |
08cb09bf | 78 | fprintf(stderr,"write failed on channel 2 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(&ftdic2)); |
ad397a4b TJ |
79 | sleep(1); |
80 | } | |
ad397a4b TJ |
81 | printf("\n"); |
82 | ||
08cb09bf | 83 | printf("disabling bitbang mode(channel 1)\n"); |
ad397a4b | 84 | ftdi_disable_bitbang(&ftdic); |
ad397a4b TJ |
85 | ftdi_usb_close(&ftdic); |
86 | ftdi_deinit(&ftdic); | |
08cb09bf TJ |
87 | |
88 | printf("disabling bitbang mode(channel 2)\n"); | |
89 | ftdi_disable_bitbang(&ftdic2); | |
90 | ftdi_usb_close(&ftdic2); | |
91 | ftdi_deinit(&ftdic2); | |
ad397a4b | 92 | } |