FreeCalypso > hg > freecalypso-hwlab
view lcdtest/testmain.c @ 106:66f04193a906
fc-simtool: pb-dump: forgot newline at the end of record
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 25 Jan 2021 06:03:58 +0000 |
parents | de3d3cfcbb35 |
children |
line wrap: on
line source
#include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <ftdi.h> #include "exitcodes.h" char *device_serial; struct ftdi_context ftdi; process_cmdline(argc, argv) char **argv; { int c; extern int optind; extern char *optarg; while ((c = getopt(argc, argv, "d:")) != EOF) { switch (c) { case 'd': device_serial = optarg; continue; default: /* error msg already printed */ exit(ERROR_USAGE); } } switch (argc - optind) { case 0: break; case 1: if (chdir(argv[optind]) < 0) { perror(argv[optind]); exit(ERROR_UNIX); } break; default: fprintf(stderr, "usage: %s [options] [chdir]\n", argv[0]); exit(ERROR_USAGE); } } 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(ERROR_FTDI); } if (ftdi_set_bitmode(&ftdi, 0, BITMODE_MCU) < 0) { fprintf(stderr, "unable to enter MCU mode: %s\n", ftdi.error_str); exit(ERROR_FTDI); } for (;;) { if (isatty(0)) { fputs("lcdtest> ", stdout); fflush(stdout); } if (!fgets(command, sizeof command, stdin)) exit(0); dispatch_cmd(command); } }