Skip to content

Commit b78ce7e

Browse files
dasGringuenbroonie
authored andcommitted
spi: spidev_test: Cleaned hexadecimal dump
Signed-off-by: Adrian Remonda <adrianremonda@gmail.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent c517d83 commit b78ce7e

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

‎Documentation/spi/spidev_test.c‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <unistd.h>
1616
#include <stdio.h>
1717
#include <stdlib.h>
18+
#include <string.h>
1819
#include <getopt.h>
1920
#include <fcntl.h>
2021
#include <sys/ioctl.h>
@@ -35,6 +36,33 @@ static uint8_t bits = 8;
3536
static uint32_t speed = 500000;
3637
static uint16_t delay;
3738

39+
static void hex_dump(const void *src, size_t length, size_t line_size, char *prefix)
40+
{
41+
int i = 0;
42+
const unsigned char *address = src;
43+
const unsigned char *line = address;
44+
unsigned char c;
45+
46+
printf("%s | ", prefix);
47+
while (length-- > 0) {
48+
printf("%02X ", *address++);
49+
if (!(++i % line_size) || (length == 0 && i % line_size)) {
50+
if (length == 0) {
51+
while (i++ % line_size)
52+
printf("__ ");
53+
}
54+
printf(" | "); /* right close */
55+
while (line < address) {
56+
c = *line++;
57+
printf("%c", (c < 33 || c == 255) ? 0x2E : c);
58+
}
59+
printf("\n");
60+
if (length > 0)
61+
printf("%s | ", prefix);
62+
}
63+
}
64+
}
65+
3866
static void transfer(int fd)
3967
{
4068
int ret;
@@ -76,12 +104,7 @@ static void transfer(int fd)
76104
if (ret < 1)
77105
pabort("can't send spi message");
78106

79-
for (ret = 0; ret < ARRAY_SIZE(tx); ret++) {
80-
if (!(ret % 6))
81-
puts("");
82-
printf("%.2X ", rx[ret]);
83-
}
84-
puts("");
107+
hex_dump(rx, ARRAY_SIZE(rx), 32, "RX");
85108
}
86109

87110
static void print_usage(const char *prog)

0 commit comments

Comments
 (0)