blob: a3cb57ab414d946e643240e05b9ec7ca11eee3df [file] [log] [blame]
// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <inttypes.h>
#include <assert.h>
#include <ftdi.h>
#include "ftdi_common.h"
#include "ftdiuart.h"
void usage(char *progname) {
printf("\n\n%s [switch args]\n", progname);
exit(-1);
}
int main(int argc, char **argv) {
int rv = 0;
struct ftdi_context fc;
struct fuart_context fuartc;
int args_consumed = 0;
struct ftdi_common_args fargs = {
// default for servo
.interface = INTERFACE_C,
.vendor_id = 0x0403,
.product_id = 0x6011,
.serialname = NULL,
// most used defaults
.speed = 115200,
.bits = BITS_8,
.parity = NONE,
.sbits = STOP_BIT_1,
};
if ((args_consumed = fcom_args(&fargs, argc, argv)) < 0) {
usage(argv[0]);
}
if (ftdi_init(&fc) < 0) {
ERROR_FTDI("Initializing ftdi context", &fc);
return 1;
}
if (fuart_init(&fuartc, &fc)) {
prn_fatal("fuart_init\n");
}
if (fuart_open(&fuartc, &fargs)) {
prn_fatal("fuart_open\n");
}
prn_info("ftdi uart connected to %s\n", fuartc.name);
while (1) {
if ((rv = fuart_wr_rd(&fuartc, 10000))) {
prn_error("fuart_wr_rd (%d)\n", rv);
break;
}
}
fuart_close(&fuartc);
return rv;
}