| 1 | /* simple.c |
| 2 | |
| 3 | Simple libftdi usage example |
| 4 | |
| 5 | This program is distributed under the GPL, version 2 |
| 6 | */ |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <ftdi.h>cxx . . $ `<file>/src/ftdi.h`/ |
| 11 | |
| 12 | int maincxx . . $ main(b126dc7c1de90089).(void) |
| 13 | { |
| 14 | int ret; |
| 15 | struct ftdi_contextcxx . . $ ftdi_context# *ftdi; |
| 16 | struct ftdi_version_infocxx . . $ ftdi_version_info# version; |
| 17 | if ((ftdi = ftdi_newcxx . . $ ftdi_new(207ff50971a1b30).()) == 0) |
| 18 | { |
| 19 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "ftdi_new failed\n"); |
| 20 | return EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:96:9`!; |
| 21 | } |
| 22 | |
| 23 | version = ftdi_get_library_versioncxx . . $ ftdi_get_library_version(6888b1066d7f1a1b).(); |
| 24 | printfcxx . . $ printf(581fddd72a8db8fc).("Initialized libftdi %s (major: %d, minor: %d, micro: %d, snapshot ver: %s)\n", |
| 25 | version.version_strcxx . . $ ftdi_version_info#version_str., version.majorcxx . . $ ftdi_version_info#major., version.minorcxx . . $ ftdi_version_info#minor., version.microcxx . . $ ftdi_version_info#micro., |
| 26 | version.snapshot_strcxx . . $ ftdi_version_info#snapshot_str.); |
| 27 | |
| 28 | if ((ret = ftdi_usb_opencxx . . $ ftdi_usb_open(cfc3cf95535913f).(ftdi, 0x0403, 0x6001)) < 0) |
| 29 | { |
| 30 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "unable to open ftdi device: %d (%s)\n", ret, ftdi_get_error_stringcxx . . $ ftdi_get_error_string(318567b992c3484e).(ftdi)); |
| 31 | ftdi_freecxx . . $ ftdi_free(a4aec54891bac95c).(ftdi); |
| 32 | return EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:96:9`!; |
| 33 | } |
| 34 | |
| 35 | // Read out FTDIChip-ID of R type chips |
| 36 | if (ftdi->typecxx . . $ ftdi_context#type. == TYPE_Rcxx . . $ TYPE_R.) |
| 37 | { |
| 38 | unsigned int chipid; |
| 39 | printfcxx . . $ printf(581fddd72a8db8fc).("ftdi_read_chipid: %d\n", ftdi_read_chipidcxx . . $ ftdi_read_chipid(5bf1e244060ec5e4).(ftdi, &chipid)); |
| 40 | printfcxx . . $ printf(581fddd72a8db8fc).("FTDI chipid: %X\n", chipid); |
| 41 | } |
| 42 | |
| 43 | if ((ret = ftdi_usb_closecxx . . $ ftdi_usb_close(e7991dd2c21df3a2).(ftdi)) < 0) |
| 44 | { |
| 45 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "unable to close ftdi device: %d (%s)\n", ret, ftdi_get_error_stringcxx . . $ ftdi_get_error_string(318567b992c3484e).(ftdi)); |
| 46 | ftdi_freecxx . . $ ftdi_free(a4aec54891bac95c).(ftdi); |
| 47 | return EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:96:9`!; |
| 48 | } |
| 49 | |
| 50 | ftdi_freecxx . . $ ftdi_free(a4aec54891bac95c).(ftdi); |
| 51 | |
| 52 | return EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:97:9`!; |
| 53 | } |