summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2022-06-04 21:07:47 +0800
committersakumisu <[email protected]>2022-06-04 21:07:47 +0800
commitad17e1f40fb4e3482d5f572f45ffac8a47f908b2 (patch)
tree4fa8c14e6c9ee70a01130557b4545ffee84e710c
parent9a857e60bad8fed4dac693bffbff3074e4a986a1 (diff)
move log macros into usb_log.h,adjust header file inclusion order
-rw-r--r--common/usb_log.h87
-rw-r--r--common/usb_util.h90
-rw-r--r--core/usbd_core.h11
-rw-r--r--core/usbh_core.h11
-rw-r--r--usb_config.h11
5 files changed, 118 insertions, 92 deletions
diff --git a/common/usb_log.h b/common/usb_log.h
new file mode 100644
index 00000000..1471caae
--- /dev/null
+++ b/common/usb_log.h
@@ -0,0 +1,87 @@
+#ifndef _USB_LOG_H
+#define _USB_LOG_H
+
+#include <stdio.h>
+
+/* DEBUG level */
+#define USB_DBG_ERROR 0
+#define USB_DBG_WARNING 1
+#define USB_DBG_INFO 2
+#define USB_DBG_LOG 3
+
+#ifndef CONFIG_USB_DBG_LEVEL
+#define CONFIG_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
+ */
+#ifndef CONFIG_USB_PRINTF
+#define CONFIG_USB_PRINTF printf
+#endif
+
+#ifdef CONFIG_USB_PRINTF_COLOR_ENABLE
+#define _USB_DBG_COLOR(n) CONFIG_USB_PRINTF("\033[" #n "m")
+#define _USB_DBG_LOG_HDR(lvl_name, color_n) \
+ CONFIG_USB_PRINTF("\033[" #color_n "m[" lvl_name "/" USB_DBG_TAG "] ")
+#define _USB_DBG_LOG_X_END \
+ CONFIG_USB_PRINTF("\033[0m")
+#else
+#define _USB_DBG_COLOR(n)
+#define _USB_DBG_LOG_HDR(lvl_name, color_n) \
+ CONFIG_USB_PRINTF("[" lvl_name "/" USB_DBG_TAG "] ")
+#define _USB_DBG_LOG_X_END
+#endif
+
+#define usb_dbg_log_line(lvl, color_n, fmt, ...) \
+ do { \
+ _USB_DBG_LOG_HDR(lvl, color_n); \
+ CONFIG_USB_PRINTF(fmt, ##__VA_ARGS__); \
+ _USB_DBG_LOG_X_END; \
+ } while (0)
+
+#if (CONFIG_USB_DBG_LEVEL >= USB_DBG_LOG)
+#define USB_LOG_DBG(fmt, ...) usb_dbg_log_line("D", 0, fmt, ##__VA_ARGS__)
+#else
+#define USB_LOG_DBG(...)
+#endif
+
+#if (CONFIG_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 (CONFIG_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 (CONFIG_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
+
+#define USB_LOG_RAW CONFIG_USB_PRINTF
+
+void usb_assert(const char *filename, int linenum);
+#define USB_ASSERT(f) \
+ do { \
+ if (!(f)) \
+ usb_assert(__FILE__, __LINE__); \
+ } while (0)
+
+#endif
diff --git a/common/usb_util.h b/common/usb_util.h
index 6f0d7a25..4a7fbb83 100644
--- a/common/usb_util.h
+++ b/common/usb_util.h
@@ -23,15 +23,6 @@
#ifndef _USB_UTIL_H
#define _USB_UTIL_H
-#include <stdbool.h>
-#include <string.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "usb_errno.h"
-#include "usb_list.h"
-#include "usb_mem.h"
-
#if defined(__CC_ARM)
#ifndef __USED
#define __USED __attribute__((used))
@@ -250,85 +241,4 @@
#define USB_DESC_SECTION __attribute__((section("usb_desc"))) __USED __ALIGNED(1)
-/* DEBUG level */
-#define USB_DBG_ERROR 0
-#define USB_DBG_WARNING 1
-#define USB_DBG_INFO 2
-#define USB_DBG_LOG 3
-
-#ifndef CONFIG_USB_DBG_LEVEL
-#define CONFIG_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
- */
-#ifndef CONFIG_USB_PRINTF
-#define CONFIG_USB_PRINTF printf
-#endif
-
-#ifdef CONFIG_USB_PRINTF_COLOR_ENABLE
-#define _USB_DBG_COLOR(n) CONFIG_USB_PRINTF("\033[" #n "m")
-#define _USB_DBG_LOG_HDR(lvl_name, color_n) \
- CONFIG_USB_PRINTF("\033[" #color_n "m[" lvl_name "/" USB_DBG_TAG "] ")
-#define _USB_DBG_LOG_X_END \
- CONFIG_USB_PRINTF("\033[0m")
-#else
-#define _USB_DBG_COLOR(n)
-#define _USB_DBG_LOG_HDR(lvl_name, color_n) \
- CONFIG_USB_PRINTF("[" lvl_name "/" USB_DBG_TAG "] ")
-#define _USB_DBG_LOG_X_END
-#endif
-
-#define usb_dbg_log_line(lvl, color_n, fmt, ...) \
- do { \
- _USB_DBG_LOG_HDR(lvl, color_n); \
- CONFIG_USB_PRINTF(fmt, ##__VA_ARGS__); \
- _USB_DBG_LOG_X_END; \
- } while (0)
-
-#if (CONFIG_USB_DBG_LEVEL >= USB_DBG_LOG)
-#define USB_LOG_DBG(fmt, ...) usb_dbg_log_line("D", 0, fmt, ##__VA_ARGS__)
-#else
-#define USB_LOG_DBG(...)
-#endif
-
-#if (CONFIG_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 (CONFIG_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 (CONFIG_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
-
-#define USB_LOG_RAW CONFIG_USB_PRINTF
-
-void usb_assert(const char *filename, int linenum);
-#define USB_ASSERT(f) \
- do { \
- if (!(f)) \
- usb_assert(__FILE__, __LINE__); \
- } while (0)
-
#endif
diff --git a/core/usbd_core.h b/core/usbd_core.h
index 61afdb3f..fff92504 100644
--- a/core/usbd_core.h
+++ b/core/usbd_core.h
@@ -26,10 +26,19 @@
extern "C" {
#endif
+#include <stdbool.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "usb_config.h"
#include "usb_util.h"
+#include "usb_errno.h"
#include "usb_def.h"
+#include "usb_list.h"
+#include "usb_mem.h"
+#include "usb_log.h"
#include "usb_dc.h"
-#include "usb_config.h"
enum usbd_event_type {
/** USB error reported by the controller */
diff --git a/core/usbh_core.h b/core/usbh_core.h
index 8338c695..b4d867a3 100644
--- a/core/usbh_core.h
+++ b/core/usbh_core.h
@@ -22,13 +22,22 @@
#ifndef _USBH_CORE_H
#define _USBH_CORE_H
+#include <stdbool.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "usb_config.h"
#include "usb_util.h"
+#include "usb_errno.h"
#include "usb_def.h"
+#include "usb_list.h"
+#include "usb_mem.h"
+#include "usb_log.h"
#include "usb_hc.h"
#include "usb_osal.h"
#include "usb_workq.h"
#include "usbh_hub.h"
-#include "usb_config.h"
#ifdef __cplusplus
extern "C" {
diff --git a/usb_config.h b/usb_config.h
index e619e6ce..39c77df6 100644
--- a/usb_config.h
+++ b/usb_config.h
@@ -1,6 +1,17 @@
#ifndef _USB_CONFIG_H
#define _USB_CONFIG_H
+/* USB common Configuration */
+#ifndef CONFIG_USB_DBG_LEVEL
+#define CONFIG_USB_DBG_LEVEL USB_DBG_INFO
+#endif
+
+#ifndef CONFIG_USB_PRINTF
+#define CONFIG_USB_PRINTF printf
+#endif
+
+#define CONFIG_USB_PRINTF_COLOR_ENABLE
+
/* USB DEVICE Configuration */
/* core */
#ifndef CONFIG_USBDEV_REQUEST_BUFFER_LEN