FreeCalypso > hg > freecalypso-hwlab
diff lcdtest/testmain.c @ 26:225556110fa6
lcdtest: beginning of reorg for adding lcdphone program
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 27 May 2018 21:36:07 +0000 |
parents | lcdtest/main.c@2127e6fdeab2 |
children | 4b7cac119fb5 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lcdtest/testmain.c Sun May 27 21:36:07 2018 +0000 @@ -0,0 +1,66 @@ +#include <sys/types.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <ftdi.h> + +char *device_serial; +struct ftdi_context ftdi; + +process_cmdline(argc, argv) + char **argv; +{ + int c; + extern char *optarg; + + while ((c = getopt(argc, argv, "d:")) != EOF) { + switch (c) { + case 'd': + device_serial = optarg; + continue; + default: + /* error msg already printed */ + exit(1); + } + } + switch (argc - optind) { + case 0: + break; + case 1: + if (chdir(argv[optind]) < 0) { + perror(argv[optind]); + exit(1); + } + break; + default: + fprintf(stderr, "usage: %s [options] [chdir]\n", argv[0]); + exit(1); + } +} + +main(argc, argv) + char **argv; +{ + char command[512]; + + process_cmdline(argc, argv); + ftdi_init(&ftdi); + if (ftdi_usb_open_desc(&ftdi, 0x0403, 0x7157, 0, device_serial) < 0) { + fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str); + exit(1); + } + if (ftdi_set_bitmode(&ftdi, 0, BITMODE_MCU) < 0) { + fprintf(stderr, "unable to enter MCU mode: %s\n", + ftdi.error_str); + exit(1); + } + for (;;) { + if (isatty(0)) { + fputs("lcdtest> ", stdout); + fflush(stdout); + } + if (!fgets(command, sizeof command, stdin)) + exit(0); + dispatch_cmd(command); + } +}