summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/usb_log.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/common/usb_log.h b/common/usb_log.h
index 923e8006..9a0146de 100644
--- a/common/usb_log.h
+++ b/common/usb_log.h
@@ -82,4 +82,31 @@ void usb_assert(const char *filename, int linenum);
usb_assert(__FILE__, __LINE__); \
} while (0)
+#define ___is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
+static inline void usb_hexdump(const void *ptr, uint32_t buflen)
+{
+ unsigned char *buf = (unsigned char *)ptr;
+ int i, j;
+
+ for (i = 0; i < buflen; i += 16) {
+ CONFIG_USB_PRINTF("%08X:", i);
+
+ for (j = 0; j < 16; j++)
+ if (i + j < buflen) {
+ if ((j % 8) == 0) {
+ CONFIG_USB_PRINTF(" ");
+ }
+
+ CONFIG_USB_PRINTF("%02X ", buf[i + j]);
+ } else
+ CONFIG_USB_PRINTF(" ");
+ CONFIG_USB_PRINTF(" ");
+
+ for (j = 0; j < 16; j++)
+ if (i + j < buflen)
+ CONFIG_USB_PRINTF("%c", ___is_print(buf[i + j]) ? buf[i + j] : '.');
+ CONFIG_USB_PRINTF("\n");
+ }
+}
+
#endif /* USB_LOG_H */