add usb debug level control and color display
This commit is contained in:
@@ -205,16 +205,65 @@
|
||||
|
||||
#define USB_DESC_SECTION __attribute__((section("usb_desc"))) __USED __ALIGNED(1)
|
||||
|
||||
#if 0
|
||||
#define USBD_LOG_INFO(a, ...) printf(a, ##__VA_ARGS__)
|
||||
#define USBD_LOG_DBG(a, ...) printf(a, ##__VA_ARGS__)
|
||||
#define USBD_LOG_WRN(a, ...) printf(a, ##__VA_ARGS__)
|
||||
#define USBD_LOG_ERR(a, ...) printf(a, ##__VA_ARGS__)
|
||||
/* DEBUG level */
|
||||
#define USB_DBG_ERROR 0
|
||||
#define USB_DBG_WARNING 1
|
||||
#define USB_DBG_INFO 2
|
||||
#define USB_DBG_LOG 3
|
||||
|
||||
#ifndef USB_DBG_LEVEL
|
||||
#define USB_DBG_LEVEL USB_DBG_INFO
|
||||
#endif
|
||||
|
||||
#ifndef USB_DBG_TAG
|
||||
#define USB_DBG_TAG "USB"
|
||||
#endif
|
||||
/*
|
||||
* The color for terminal (foreground)
|
||||
* BLACK 30
|
||||
* RED 31
|
||||
* GREEN 32
|
||||
* YELLOW 33
|
||||
* BLUE 34
|
||||
* PURPLE 35
|
||||
* CYAN 36
|
||||
* WHITE 37
|
||||
*/
|
||||
#define _USB_DBG_COLOR(n) printf("\033[" #n "m")
|
||||
#define _USB_DBG_LOG_HDR(lvl_name, color_n) \
|
||||
printf("\033[" #color_n "m[" lvl_name "/" USB_DBG_TAG "] ")
|
||||
#define _USB_DBG_LOG_X_END \
|
||||
printf("\033[0m")
|
||||
|
||||
#define usb_dbg_log_line(lvl, color_n, fmt, ...) \
|
||||
do { \
|
||||
_USB_DBG_LOG_HDR(lvl, color_n); \
|
||||
printf(fmt, ##__VA_ARGS__); \
|
||||
_USB_DBG_LOG_X_END; \
|
||||
} while (0)
|
||||
|
||||
#if (USB_DBG_LEVEL >= USB_DBG_LOG)
|
||||
#define USB_LOG_DBG(fmt, ...) usb_dbg_log_line("D", 0, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define USBD_LOG_INFO(a, ...) printf(a, ##__VA_ARGS__)
|
||||
#define USBD_LOG_DBG(a, ...)
|
||||
#define USBD_LOG_WRN(a, ...) printf(a, ##__VA_ARGS__)
|
||||
#define USBD_LOG_ERR(a, ...) printf(a, ##__VA_ARGS__)
|
||||
#define USB_LOG_DBG(...)
|
||||
#endif
|
||||
|
||||
#if (USB_DBG_LEVEL >= USB_DBG_INFO)
|
||||
#define USB_LOG_INFO(fmt, ...) usb_dbg_log_line("I", 32, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define USB_LOG_INFO(...)
|
||||
#endif
|
||||
|
||||
#if (USB_DBG_LEVEL >= USB_DBG_WARNING)
|
||||
#define USB_LOG_WRN(fmt, ...) usb_dbg_log_line("W", 33, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define USB_LOG_WRN(...)
|
||||
#endif
|
||||
|
||||
#if (USB_DBG_LEVEL >= USB_DBG_ERROR)
|
||||
#define USB_LOG_ERR(fmt, ...) usb_dbg_log_line("E", 31, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define USB_LOG_ERR(...)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user