Commit | Line | Data |
---|---|---|
ad397a4b TJ |
1 | /* This program is distributed under the GPL, version 2 */ |
2 | ||
3 | #include <stdio.h> | |
4 | #include <unistd.h> | |
5 | #include <ftdi.h> | |
6 | ||
7 | int main(int argc, char **argv) | |
8 | { | |
9 | struct ftdi_context ftdic; | |
10 | int f,i; | |
898c34dd | 11 | char buf[1]; |
ad397a4b TJ |
12 | |
13 | ftdi_init(&ftdic); | |
14 | ||
15 | f = ftdi_usb_open(&ftdic, 0x0403, 0x6001); | |
16 | ||
17 | if(f < 0 && f != -5) { | |
18 | fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(&ftdic)); | |
19 | exit(-1); | |
20 | } | |
21 | ||
22 | printf("ftdi open succeeded: %d\n",f); | |
23 | ||
24 | printf("enabling bitbang mode\n"); | |
25 | ftdi_enable_bitbang(&ftdic, 0xFF); | |
26 | ||
ad397a4b TJ |
27 | sleep(3); |
28 | ||
29 | buf[0] = 0x0; | |
30 | printf("turning everything on\n"); | |
31 | f = ftdi_write_data(&ftdic, buf, 1); | |
32 | if(f < 0) { | |
33 | fprintf(stderr,"write failed for 0x%x, error %d (%s)\n",buf[0],f, ftdi_get_error_string(&ftdic)); | |
34 | } | |
35 | ||
36 | sleep(3); | |
37 | ||
38 | buf[0] = 0xFF; | |
39 | printf("turning everything off\n"); | |
40 | f = ftdi_write_data(&ftdic, buf, 1); | |
41 | if(f < 0) { | |
42 | fprintf(stderr,"write failed for 0x%x, error %d (%s)\n",buf[0],f, ftdi_get_error_string(&ftdic)); | |
43 | } | |
44 | ||
45 | sleep(3); | |
46 | ||
47 | for(i = 0; i < 32; i++) { | |
48 | buf[0] = 0 | (0xFF ^ 1 << (i % 8)); | |
49 | if( i > 0 && (i % 8) == 0) { | |
50 | printf("\n"); | |
51 | } | |
52 | printf("%02hhx ",buf[0]); | |
53 | fflush(stdout); | |
54 | f = ftdi_write_data(&ftdic, buf, 1); | |
55 | if(f < 0) { | |
56 | fprintf(stderr,"write failed for 0x%x, error %d (%s)\n",buf[0],f, ftdi_get_error_string(&ftdic)); | |
57 | } | |
58 | sleep(1); | |
59 | } | |
60 | ||
61 | printf("\n"); | |
62 | ||
63 | printf("disabling bitbang mode\n"); | |
64 | ftdi_disable_bitbang(&ftdic); | |
65 | ||
66 | ftdi_usb_close(&ftdic); | |
67 | ftdi_deinit(&ftdic); | |
68 | } |