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); |
ad397a4b TJ |
25 | if(f < 0 && f != -5) { |
26 | fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(&ftdic)); | |
27 | exit(-1); | |
28 | } | |
08cb09bf | 29 | printf("ftdi open succeeded(channel 1): %d\n",f); |
ad397a4b | 30 | |
08cb09bf | 31 | printf("enabling bitbang mode(channel 1)\n"); |
ad397a4b TJ |
32 | ftdi_enable_bitbang(&ftdic, 0xFF); |
33 | ||
08cb09bf TJ |
34 | // Init 2. channel |
35 | ftdi_init(&ftdic2); | |
36 | ftdi_set_interface(&ftdic2, INTERFACE_B); | |
ad397a4b | 37 | f = ftdi_usb_open(&ftdic2, 0x0403, 0x6001); |
ad397a4b | 38 | if(f < 0 && f != -5) { |
08cb09bf | 39 | fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(&ftdic2)); |
ad397a4b TJ |
40 | exit(-1); |
41 | } | |
08cb09bf | 42 | printf("ftdi open succeeded(channel 2): %d\n",f); |
ad397a4b | 43 | |
08cb09bf | 44 | printf("enabling bitbang mode (channel 2)\n"); |
ad397a4b TJ |
45 | ftdi_enable_bitbang(&ftdic2, 0xFF); |
46 | ||
08cb09bf TJ |
47 | // Write data |
48 | printf("startloop\n"); | |
49 | for(i = 0; i < 23; i++) { | |
50 | buf[0] = 0x1; | |
51 | printf("porta: %02i: 0x%02x \n",i,buf[0]); | |
52 | f = ftdi_write_data(&ftdic, buf, 1); | |
53 | if(f < 0) | |
54 | fprintf(stderr,"write failed on channel 1 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(&ftdic)); | |
55 | sleep(1); | |
ad397a4b | 56 | |
08cb09bf TJ |
57 | buf[0] = 0x2; |
58 | printf("porta: %02i: 0x%02x \n",i,buf[0]); | |
59 | f = ftdi_write_data(&ftdic, buf, 1); | |
60 | if(f < 0) | |
61 | fprintf(stderr,"write failed on channel 1 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(&ftdic)); | |
62 | sleep(1); | |
ad397a4b | 63 | |
08cb09bf TJ |
64 | buf[0] = 0x1; |
65 | printf("portb: %02i: 0x%02x \n",i,buf[0]); | |
66 | f = ftdi_write_data(&ftdic2, buf, 1); | |
67 | if(f < 0) | |
68 | fprintf(stderr,"write failed on channel 2 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(&ftdic2)); | |
69 | sleep(1); | |
ad397a4b | 70 | |
08cb09bf TJ |
71 | buf[0] = 0x2; |
72 | printf("portb: %02i: 0x%02x \n",i,buf[0]); | |
73 | f = ftdi_write_data(&ftdic2, buf, 1); | |
74 | if(f < 0) | |
75 | fprintf(stderr,"write failed on channel 2 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(&ftdic2)); | |
ad397a4b TJ |
76 | sleep(1); |
77 | } | |
ad397a4b TJ |
78 | printf("\n"); |
79 | ||
08cb09bf | 80 | printf("disabling bitbang mode(channel 1)\n"); |
ad397a4b | 81 | ftdi_disable_bitbang(&ftdic); |
ad397a4b TJ |
82 | ftdi_usb_close(&ftdic); |
83 | ftdi_deinit(&ftdic); | |
08cb09bf TJ |
84 | |
85 | printf("disabling bitbang mode(channel 2)\n"); | |
86 | ftdi_disable_bitbang(&ftdic2); | |
87 | ftdi_usb_close(&ftdic2); | |
88 | ftdi_deinit(&ftdic2); | |
ad397a4b | 89 | } |