static uint32_t mode;
static uint8_t bits = 8;
static char *input_file;
+static char *output_file;
static uint32_t speed = 500000;
static uint16_t delay;
static int verbose;
static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len)
{
int ret;
-
+ int out_fd;
struct spi_ioc_transfer tr = {
.tx_buf = (unsigned long)tx,
.rx_buf = (unsigned long)rx,
if (verbose)
hex_dump(tx, len, 32, "TX");
- hex_dump(rx, len, 32, "RX");
+
+ if (output_file) {
+ out_fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ if (out_fd < 0)
+ pabort("could not open output file");
+
+ ret = write(out_fd, rx, len);
+ if (ret != len)
+ pabort("not all bytes written to utput file");
+
+ close(out_fd);
+ }
+
+ if (verbose || !output_file)
+ hex_dump(rx, len, 32, "RX");
}
static void print_usage(const char *prog)
" -d --delay delay (usec)\n"
" -b --bpw bits per word \n"
" -i --input input data from a file (e.g. \"test.bin\")\n"
+ " -o --output output data to a file (e.g. \"results.bin\")\n"
" -l --loop loopback\n"
" -H --cpha clock phase\n"
" -O --cpol clock polarity\n"
{ "delay", 1, 0, 'd' },
{ "bpw", 1, 0, 'b' },
{ "input", 1, 0, 'i' },
+ { "output", 1, 0, 'o' },
{ "loop", 0, 0, 'l' },
{ "cpha", 0, 0, 'H' },
{ "cpol", 0, 0, 'O' },
};
int c;
- c = getopt_long(argc, argv, "D:s:d:b:i:lHOLC3NR24p:v",
+ c = getopt_long(argc, argv, "D:s:d:b:i:o:lHOLC3NR24p:v",
lopts, NULL);
if (c == -1)
case 'i':
input_file = optarg;
break;
+ case 'o':
+ output_file = optarg;
+ break;
case 'l':
mode |= SPI_LOOP;
break;