summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2024-08-16 14:23:14 +0800
committersakumisu <[email protected]>2024-08-16 14:23:14 +0800
commit1efc29be5f60d685ebf1811dd0ddeae575015662 (patch)
tree060f1a9d971f7ca74f4f2e73e59896dcaa809a03
parent143a5ce3fd31156606c10221730b6fe2a977ee89 (diff)
feat(common): add usb_hexdump for test
-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 */