FreeCalypso > hg > freecalypso-hwlab
diff lcdtest/main.c @ 12:5eaf832d57d0
lcdtest program started, skeleton compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 06 Apr 2018 06:15:11 +0000 |
parents | |
children | 4194b6744890 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lcdtest/main.c Fri Apr 06 06:15:11 2018 +0000 @@ -0,0 +1,53 @@ +#include <sys/types.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <ftdi.h> + +char *device_selector = "i:0x0403:0x6010"; +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_selector = optarg; + continue; + default: + /* error msg already printed */ + exit(1); + } + } +} + +main(argc, argv) + char **argv; +{ + char command[512]; + + process_cmdline(argc, argv); + ftdi_init(&ftdi); + if (ftdi_usb_open_string(&ftdi, device_selector) < 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); + } +}