root / branches / rbom / code / projects / colonet / testing / ftdi_test / ftdi_test.c @ 1390
History | View | Annotate | Download (1.36 KB)
1 | 13 | emarinel | /* ftdi test
|
---|---|---|---|
2 | * Simple program to test the ftdi drivers with the dongle
|
||
3 | */
|
||
4 | |||
5 | #include <stdio.h> |
||
6 | #include <unistd.h> |
||
7 | #include <usb.h> |
||
8 | #include <ftdi.h> |
||
9 | |||
10 | int main(int argc, char **argv) |
||
11 | { |
||
12 | struct ftdi_context ftdic;
|
||
13 | int f,i;
|
||
14 | |||
15 | ftdi_init(&ftdic); |
||
16 | |||
17 | f = ftdi_usb_open(&ftdic, 0x0403, 0x6001); |
||
18 | |||
19 | if(f < 0 && f != -5) { |
||
20 | fprintf(stderr, "unable to open ftdi device: %d\n",f);
|
||
21 | exit(-1);
|
||
22 | } |
||
23 | |||
24 | printf("ftdi open succeeded: %d\n",f);
|
||
25 | |||
26 | printf("enabling bitbang mode\n");
|
||
27 | ftdi_enable_bitbang(&ftdic, 0xFF);
|
||
28 | |||
29 | char buf[1]; |
||
30 | |||
31 | sleep(3);
|
||
32 | |||
33 | buf[0] = 0x0; |
||
34 | printf("turning everything on\n");
|
||
35 | f = ftdi_write_data(&ftdic, buf, 1);
|
||
36 | if(f < 0) { |
||
37 | fprintf(stderr,"write failed for 0x%x, error %d\n",buf[0],f); |
||
38 | } |
||
39 | |||
40 | sleep(3);
|
||
41 | |||
42 | buf[0] = 0xFF; |
||
43 | printf("turning everything off\n");
|
||
44 | f = ftdi_write_data(&ftdic, buf, 1);
|
||
45 | if(f < 0) { |
||
46 | fprintf(stderr,"write failed for 0x%x, error %d\n",buf[0],f); |
||
47 | } |
||
48 | |||
49 | sleep(3);
|
||
50 | |||
51 | for(i = 0; i < 32; i++) { |
||
52 | buf[0] = 0 | (0xFF ^ 1 << (i % 8)); |
||
53 | if( i > 0 && (i % 8) == 0) { |
||
54 | printf("\n");
|
||
55 | } |
||
56 | printf("%02hhx ",buf[0]); |
||
57 | fflush(stdout); |
||
58 | f = ftdi_write_data(&ftdic, buf, 1);
|
||
59 | if(f < 0) { |
||
60 | fprintf(stderr,"write failed for 0x%x, error %d\n",buf[0],f); |
||
61 | } |
||
62 | sleep(1);
|
||
63 | } |
||
64 | |||
65 | printf("\n");
|
||
66 | |||
67 | printf("disabling bitbang mode\n");
|
||
68 | ftdi_disable_bitbang(&ftdic); |
||
69 | |||
70 | ftdi_usb_close(&ftdic); |
||
71 | ftdi_deinit(&ftdic); |
||
72 | } |