| 1 | /* bitbang_ft2232.c |
| 2 | |
| 3 | Output some flickering in bitbang mode to the FT2232 |
| 4 | |
| 5 | Thanks to [email protected] for fixing and extending |
| 6 | the example for the second channel. |
| 7 | |
| 8 | This program is distributed under the GPL, version 2 |
| 9 | */ |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <unistd.h> |
| 14 | #include <ftdi.h>cxx . . $ `<file>/src/ftdi.h`/ |
| 15 | |
| 16 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) |
| 17 | { |
| 18 | struct ftdi_contextcxx . . $ ftdi_context# *ftdi, *ftdi2; |
| 19 | unsigned char buf[1]; |
| 20 | int f,i; |
| 21 | |
| 22 | // Init 1. channel |
| 23 | if ((ftdi = ftdi_newcxx . . $ ftdi_new(207ff50971a1b30).()) == 0) |
| 24 | { |
| 25 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "ftdi_new failed\n"); |
| 26 | return EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:96:9`!; |
| 27 | } |
| 28 | |
| 29 | ftdi_set_interfacecxx . . $ ftdi_set_interface(73d9956508f3a98f).(ftdi, INTERFACE_Acxx . . $ INTERFACE_A.); |
| 30 | f = ftdi_usb_opencxx . . $ ftdi_usb_open(cfc3cf95535913f).(ftdi, 0x0403, 0x6001); |
| 31 | if (f < 0 && f != -5) |
| 32 | { |
| 33 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_stringcxx . . $ ftdi_get_error_string(318567b992c3484e).(ftdi)); |
| 34 | ftdi_freecxx . . $ ftdi_free(a4aec54891bac95c).(ftdi); |
| 35 | exitcxx . . $ exit(3ca292c338df9bb3).(-1); |
| 36 | } |
| 37 | printfcxx . . $ printf(581fddd72a8db8fc).("ftdi open succeeded(channel 1): %d\n",f); |
| 38 | |
| 39 | printfcxx . . $ printf(581fddd72a8db8fc).("enabling bitbang mode(channel 1)\n"); |
| 40 | ftdi_set_bitmodecxx . . $ ftdi_set_bitmode(fd17119b3c08153d).(ftdi, 0xFF, BITMODE_BITBANGcxx . . $ BITMODE_BITBANG.); |
| 41 | |
| 42 | // Init 2. channel |
| 43 | if ((ftdi2 = ftdi_newcxx . . $ ftdi_new(207ff50971a1b30).()) == 0) |
| 44 | { |
| 45 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "ftdi_new failed\n"); |
| 46 | return EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:96:9`!; |
| 47 | } |
| 48 | ftdi_set_interfacecxx . . $ ftdi_set_interface(73d9956508f3a98f).(ftdi2, INTERFACE_Bcxx . . $ INTERFACE_B.); |
| 49 | f = ftdi_usb_opencxx . . $ ftdi_usb_open(cfc3cf95535913f).(ftdi2, 0x0403, 0x6001); |
| 50 | if (f < 0 && f != -5) |
| 51 | { |
| 52 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_stringcxx . . $ ftdi_get_error_string(318567b992c3484e).(ftdi2)); |
| 53 | ftdi_freecxx . . $ ftdi_free(a4aec54891bac95c).(ftdi2); |
| 54 | exitcxx . . $ exit(3ca292c338df9bb3).(-1); |
| 55 | } |
| 56 | printfcxx . . $ printf(581fddd72a8db8fc).("ftdi open succeeded(channel 2): %d\n",f); |
| 57 | |
| 58 | printfcxx . . $ printf(581fddd72a8db8fc).("enabling bitbang mode (channel 2)\n"); |
| 59 | ftdi_set_bitmodecxx . . $ ftdi_set_bitmode(fd17119b3c08153d).(ftdi2, 0xFF, BITMODE_BITBANGcxx . . $ BITMODE_BITBANG.); |
| 60 | |
| 61 | // Write data |
| 62 | printfcxx . . $ printf(581fddd72a8db8fc).("startloop\n"); |
| 63 | for (i = 0; i < 23; i++) |
| 64 | { |
| 65 | buf[0] = 0x1; |
| 66 | printfcxx . . $ printf(581fddd72a8db8fc).("porta: %02i: 0x%02x \n",i,buf[0]); |
| 67 | f = ftdi_write_datacxx . . $ ftdi_write_data(8bb9860f18916ed8).(ftdi, buf, 1); |
| 68 | if (f < 0) |
| 69 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"write failed on channel 1 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_stringcxx . . $ ftdi_get_error_string(318567b992c3484e).(ftdi)); |
| 70 | usleepcxx . . $ usleep(4c679297bf94b9eb).(1 * 1000000); |
| 71 | |
| 72 | buf[0] = 0x2; |
| 73 | printfcxx . . $ printf(581fddd72a8db8fc).("porta: %02i: 0x%02x \n",i,buf[0]); |
| 74 | f = ftdi_write_datacxx . . $ ftdi_write_data(8bb9860f18916ed8).(ftdi, buf, 1); |
| 75 | if (f < 0) |
| 76 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"write failed on channel 1 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_stringcxx . . $ ftdi_get_error_string(318567b992c3484e).(ftdi)); |
| 77 | usleepcxx . . $ usleep(4c679297bf94b9eb).(1 * 1000000); |
| 78 | |
| 79 | buf[0] = 0x1; |
| 80 | printfcxx . . $ printf(581fddd72a8db8fc).("portb: %02i: 0x%02x \n",i,buf[0]); |
| 81 | f = ftdi_write_datacxx . . $ ftdi_write_data(8bb9860f18916ed8).(ftdi2, buf, 1); |
| 82 | if (f < 0) |
| 83 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"write failed on channel 2 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_stringcxx . . $ ftdi_get_error_string(318567b992c3484e).(ftdi2)); |
| 84 | usleepcxx . . $ usleep(4c679297bf94b9eb).(1 * 1000000); |
| 85 | |
| 86 | buf[0] = 0x2; |
| 87 | printfcxx . . $ printf(581fddd72a8db8fc).("portb: %02i: 0x%02x \n",i,buf[0]); |
| 88 | f = ftdi_write_datacxx . . $ ftdi_write_data(8bb9860f18916ed8).(ftdi2, buf, 1); |
| 89 | if (f < 0) |
| 90 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"write failed on channel 2 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_stringcxx . . $ ftdi_get_error_string(318567b992c3484e).(ftdi2)); |
| 91 | usleepcxx . . $ usleep(4c679297bf94b9eb).(1 * 1000000); |
| 92 | } |
| 93 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 94 | |
| 95 | printfcxx . . $ printf(581fddd72a8db8fc).("disabling bitbang mode(channel 1)\n"); |
| 96 | ftdi_disable_bitbangcxx . . $ ftdi_disable_bitbang(e7991dd2c21df3a2).(ftdi); |
| 97 | ftdi_usb_closecxx . . $ ftdi_usb_close(e7991dd2c21df3a2).(ftdi); |
| 98 | ftdi_freecxx . . $ ftdi_free(a4aec54891bac95c).(ftdi); |
| 99 | |
| 100 | printfcxx . . $ printf(581fddd72a8db8fc).("disabling bitbang mode(channel 2)\n"); |
| 101 | ftdi_disable_bitbangcxx . . $ ftdi_disable_bitbang(e7991dd2c21df3a2).(ftdi2); |
| 102 | ftdi_usb_closecxx . . $ ftdi_usb_close(e7991dd2c21df3a2).(ftdi2); |
| 103 | ftdi_freecxx . . $ ftdi_free(a4aec54891bac95c).(ftdi2); |
| 104 | |
| 105 | return 0; |
| 106 | } |