| 1 | /* This program is distributed under the GPL, version 2 */cxx . . $ `<file>/examples/bitbang.c`/ |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <unistd.h> |
| 6 | #include <ftdi.h>cxx . . $ `<file>/src/ftdi.h`/ |
| 7 | |
| 8 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) |
| 9 | { |
| 10 | struct ftdi_contextcxx . . $ ftdi_context# *ftdi; |
| 11 | int f,i; |
| 12 | unsigned char buf[1]; |
| 13 | int retval = 0; |
| 14 | |
| 15 | if ((ftdi = ftdi_newcxx . . $ ftdi_new(207ff50971a1b30).()) == 0) |
| 16 | { |
| 17 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "ftdi_new failed\n"); |
| 18 | return EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:96:9`!; |
| 19 | } |
| 20 | |
| 21 | f = ftdi_usb_opencxx . . $ ftdi_usb_open(cfc3cf95535913f).(ftdi, 0x0403, 0x6001); |
| 22 | |
| 23 | if (f < 0 && f != -5) |
| 24 | { |
| 25 | 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)); |
| 26 | retval = 1; |
| 27 | goto done; |
| 28 | } |
| 29 | |
| 30 | printfcxx . . $ printf(581fddd72a8db8fc).("ftdi open succeeded: %d\n",f); |
| 31 | |
| 32 | printfcxx . . $ printf(581fddd72a8db8fc).("enabling bitbang mode\n"); |
| 33 | ftdi_set_bitmodecxx . . $ ftdi_set_bitmode(fd17119b3c08153d).(ftdi, 0xFF, BITMODE_BITBANGcxx . . $ BITMODE_BITBANG.); |
| 34 | |
| 35 | usleepcxx . . $ usleep(4c679297bf94b9eb).(3 * 1000000); |
| 36 | |
| 37 | buf[0] = 0x0; |
| 38 | printfcxx . . $ printf(581fddd72a8db8fc).("turning everything on\n"); |
| 39 | f = ftdi_write_datacxx . . $ ftdi_write_data(8bb9860f18916ed8).(ftdi, buf, 1); |
| 40 | if (f < 0) |
| 41 | { |
| 42 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"write failed for 0x%x, error %d (%s)\n",buf[0],f, ftdi_get_error_stringcxx . . $ ftdi_get_error_string(318567b992c3484e).(ftdi)); |
| 43 | } |
| 44 | |
| 45 | usleepcxx . . $ usleep(4c679297bf94b9eb).(3 * 1000000); |
| 46 | |
| 47 | buf[0] = 0xFF; |
| 48 | printfcxx . . $ printf(581fddd72a8db8fc).("turning everything off\n"); |
| 49 | f = ftdi_write_datacxx . . $ ftdi_write_data(8bb9860f18916ed8).(ftdi, buf, 1); |
| 50 | if (f < 0) |
| 51 | { |
| 52 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"write failed for 0x%x, error %d (%s)\n",buf[0],f, ftdi_get_error_stringcxx . . $ ftdi_get_error_string(318567b992c3484e).(ftdi)); |
| 53 | } |
| 54 | |
| 55 | usleepcxx . . $ usleep(4c679297bf94b9eb).(3 * 1000000); |
| 56 | |
| 57 | for (i = 0; i < 32; i++) |
| 58 | { |
| 59 | buf[0] = 0 | (0xFF ^ 1 << (i % 8)); |
| 60 | if ( i > 0 && (i % 8) == 0) |
| 61 | { |
| 62 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 63 | } |
| 64 | printfcxx . . $ printf(581fddd72a8db8fc).("%02hhx ",buf[0]); |
| 65 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!); |
| 66 | f = ftdi_write_datacxx . . $ ftdi_write_data(8bb9860f18916ed8).(ftdi, buf, 1); |
| 67 | if (f < 0) |
| 68 | { |
| 69 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"write failed for 0x%x, error %d (%s)\n",buf[0],f, ftdi_get_error_stringcxx . . $ ftdi_get_error_string(318567b992c3484e).(ftdi)); |
| 70 | } |
| 71 | usleepcxx . . $ usleep(4c679297bf94b9eb).(1 * 1000000); |
| 72 | } |
| 73 | |
| 74 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 75 | |
| 76 | printfcxx . . $ printf(581fddd72a8db8fc).("disabling bitbang mode\n"); |
| 77 | ftdi_disable_bitbangcxx . . $ ftdi_disable_bitbang(e7991dd2c21df3a2).(ftdi); |
| 78 | |
| 79 | ftdi_usb_closecxx . . $ ftdi_usb_close(e7991dd2c21df3a2).(ftdi); |
| 80 | done: |
| 81 | ftdi_freecxx . . $ ftdi_free(a4aec54891bac95c).(ftdi); |
| 82 | |
| 83 | return retval; |
| 84 | } |