Lines Matching +full:ascii +full:. +full:d

4  * Copyright (c) 2018 S.F.T. Inc.
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
13 * documentation and/or other materials provided with the distribution.
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * SUCH DAMAGE.
28 #include <sys/types.h>
29 #include <sys/ioccom.h>
30 #include <sys/spigenio.h>
31 #include <sys/sysctl.h>
33 #include <errno.h>
34 #include <fcntl.h>
35 #include <inttypes.h>
36 #include <limits.h>
37 #include <memory.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <string.h>
42 #include <unistd.h>
44 #define DEFAULT_DEVICE_NAME "/dev/spigen0.0"
59 * ASCII output when ASCII != 0 */
60 int ASCII; /* zero for binary input and output. member
61 * non-zero for ASCII input, 'binary'
85 * LSB array - reversebits[n] is the LSB value of n as an MSB. Use this array
131 " spi [-f device] [-d r|w|rw] [-m mode] [-s max-speed] [-c count]\n" in usage()
136 " -f specifies the device (default is spigen0.0)\n" in usage()
137 " -d specifies the operation (r, w, or rw; default is rw)\n" in usage()
140 " -c specifies the number of data bytes to transfer (default 0, i.e. none)\n" in usage()
146 " -A uses ASCII for input/output as 2-digit hex values\n" in usage()
151 "NOTE: setting the mode and/or speed is 'sticky'. Subsequent transactions\n" in usage()
152 " on that device will, by default, use the previously set values.\n" in usage()
173 opt.mode = -1; in main()
174 opt.speed = -1; in main()
175 opt.count = 0; in main()
176 opt.ASCII = 0; in main()
177 opt.binary = 0; in main()
178 opt.lsb = 0; in main()
179 opt.verbose = 0; in main()
180 opt.ncmd = 0; in main()
181 opt.pcmd = NULL; in main()
183 while (!err && (ch = getopt(argc, argv, "f:d:m:s:c:C:AbLvih")) != -1) { in main()
185 case 'd': in main()
218 opt.mode = (int)strtol(optarg, &pstr, 10); in main()
220 if (!pstr || *pstr || opt.mode < 0 || opt.mode > 3) { in main()
228 opt.speed = (int)strtol(optarg, &pstr, 10); in main()
230 if (!pstr || *pstr || opt.speed < 0) { in main()
238 opt.count = (int)strtol(optarg, &pstr, 10); in main()
248 if(opt.pcmd) /* specified more than once */ in main()
251 /* get malloc'd buffer or error */ in main()
259 opt.ASCII = 1; in main()
263 opt.binary = 1; in main()
267 opt.lsb = 1; in main()
271 opt.verbose++; in main()
291 (fdir == DIR_NONE && !finfo && opt.mode == -1 && opt.speed == -1 && opt.count == 0)) { in main()
301 if ((opt.count != 0 || opt.ncmd != 0) && fdir == DIR_NONE) { in main()
303 * count was specified, but direction was not. default is in main()
310 if (opt.count == 0) in main()
316 if (opt.count < 0 && fdir != DIR_READWRITE && fdir != DIR_WRITE) { in main()
317 fprintf(stderr, "Invalid length %d when not writing data\n", in main()
318 opt.count); in main()
332 fprintf(stderr, "Error - unable to open '%s', errno=%d\n", in main()
345 if (opt.mode != -1) { in main()
352 if (opt.speed != -1) { in main()
376 free(opt.pcmd); in main()
430 "Not enough memory to interpret command bytes, errno=%d\n", in interpret_command_bytes()
475 "Device mode: %d\n" in get_info()
476 "Device speed: %d\n", in get_info()
480 fprintf(stderr, "Unable to query info (err=%d), errno=%d\n", in get_info()
560 * read up to 'cbdata' bytes. If I get an EOF, do one of two things: in prep_write_buffer()
568 if (popt->ASCII) { in prep_write_buffer()
627 if (popt->ASCII) in prep_write_buffer()
628 fprintf(stderr, "ASCII input of %zd %s\n", cbread, in prep_write_buffer()
636 * if opt.count is negative, copy actual byte count to opt.count which does in prep_write_buffer()
637 * not include any of the 'command' bytes that are being sent. Can be zero. in prep_write_buffer()
653 * 'popt->ncmd' command bytes (if any). in prep_write_buffer()
655 * the code. in prep_write_buffer()
664 fprintf(stderr, "Writing %d %s to SPI device\n", in prep_write_buffer()
692 spi.st_command.iov_base = bufr; in _read_write()
693 spi.st_command.iov_len = cbrw; in _read_write()
696 * The remaining members for spi.st_data are zero - all bytes are in _read_write()
697 * 'command' for this. The driver doesn't really do anything different in _read_write()
699 * the transaction. in _read_write()
713 fprintf(stderr, "Error performing SPI transaction, errno=%d\n", in _read_write()
745 if (popt->binary || !popt->ASCII) { in _do_data_output()
747 fprintf(stderr, "Binary output of %d %s\n", icount, in _do_data_output()
754 fprintf(stderr, "ASCII output of %d %s\n", icount, in _do_data_output()
757 /* ASCII output */ in _do_data_output()
777 fprintf(stderr, "Error writing to stdout, errno=%d\n", errno); in _do_data_output()
780 "%d command %s and %d data %s read from SPI device\n", in _do_data_output()
904 fputs(" | 0 1 2 3 4 5 6 7 8 9 A B C D E F " in verbose_dump_buffer()
944 fputc('.', stderr); in verbose_dump_buffer()