FreeCalypso > hg > freecalypso-hwlab
comparison lcdtest/testmain.c @ 27:4b7cac119fb5
lcdtest: added our own local exitcodes.h header
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 27 May 2018 21:49:46 +0000 |
parents | 225556110fa6 |
children | de3d3cfcbb35 |
comparison
equal
deleted
inserted
replaced
26:225556110fa6 | 27:4b7cac119fb5 |
---|---|
1 #include <sys/types.h> | 1 #include <sys/types.h> |
2 #include <stdio.h> | 2 #include <stdio.h> |
3 #include <stdlib.h> | 3 #include <stdlib.h> |
4 #include <unistd.h> | 4 #include <unistd.h> |
5 #include <ftdi.h> | 5 #include <ftdi.h> |
6 #include "exitcodes.h" | |
6 | 7 |
7 char *device_serial; | 8 char *device_serial; |
8 struct ftdi_context ftdi; | 9 struct ftdi_context ftdi; |
9 | 10 |
10 process_cmdline(argc, argv) | 11 process_cmdline(argc, argv) |
18 case 'd': | 19 case 'd': |
19 device_serial = optarg; | 20 device_serial = optarg; |
20 continue; | 21 continue; |
21 default: | 22 default: |
22 /* error msg already printed */ | 23 /* error msg already printed */ |
23 exit(1); | 24 exit(ERROR_USAGE); |
24 } | 25 } |
25 } | 26 } |
26 switch (argc - optind) { | 27 switch (argc - optind) { |
27 case 0: | 28 case 0: |
28 break; | 29 break; |
29 case 1: | 30 case 1: |
30 if (chdir(argv[optind]) < 0) { | 31 if (chdir(argv[optind]) < 0) { |
31 perror(argv[optind]); | 32 perror(argv[optind]); |
32 exit(1); | 33 exit(ERROR_UNIX); |
33 } | 34 } |
34 break; | 35 break; |
35 default: | 36 default: |
36 fprintf(stderr, "usage: %s [options] [chdir]\n", argv[0]); | 37 fprintf(stderr, "usage: %s [options] [chdir]\n", argv[0]); |
37 exit(1); | 38 exit(ERROR_USAGE); |
38 } | 39 } |
39 } | 40 } |
40 | 41 |
41 main(argc, argv) | 42 main(argc, argv) |
42 char **argv; | 43 char **argv; |
45 | 46 |
46 process_cmdline(argc, argv); | 47 process_cmdline(argc, argv); |
47 ftdi_init(&ftdi); | 48 ftdi_init(&ftdi); |
48 if (ftdi_usb_open_desc(&ftdi, 0x0403, 0x7157, 0, device_serial) < 0) { | 49 if (ftdi_usb_open_desc(&ftdi, 0x0403, 0x7157, 0, device_serial) < 0) { |
49 fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str); | 50 fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str); |
50 exit(1); | 51 exit(ERROR_FTDI); |
51 } | 52 } |
52 if (ftdi_set_bitmode(&ftdi, 0, BITMODE_MCU) < 0) { | 53 if (ftdi_set_bitmode(&ftdi, 0, BITMODE_MCU) < 0) { |
53 fprintf(stderr, "unable to enter MCU mode: %s\n", | 54 fprintf(stderr, "unable to enter MCU mode: %s\n", |
54 ftdi.error_str); | 55 ftdi.error_str); |
55 exit(1); | 56 exit(ERROR_FTDI); |
56 } | 57 } |
57 for (;;) { | 58 for (;;) { |
58 if (isatty(0)) { | 59 if (isatty(0)) { |
59 fputs("lcdtest> ", stdout); | 60 fputs("lcdtest> ", stdout); |
60 fflush(stdout); | 61 fflush(stdout); |