summaryrefslogtreecommitdiff
path: root/common/usb_util.h
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2021-11-26 23:41:59 +0800
committersakumisu <[email protected]>2021-11-29 10:32:05 +0800
commit636b30c3d8a11b7cfede7b1e8dd58549aa8e4ffd (patch)
tree7a41849e323645f26df3057507f48136a1b35c02 /common/usb_util.h
parent89f8d74fb82c3af2a67938941421077f499ed5c5 (diff)
refactor usb class structure
Diffstat (limited to 'common/usb_util.h')
-rw-r--r--common/usb_util.h129
1 files changed, 100 insertions, 29 deletions
diff --git a/common/usb_util.h b/common/usb_util.h
index d3d575e5..4c2f6743 100644
--- a/common/usb_util.h
+++ b/common/usb_util.h
@@ -1,42 +1,108 @@
#ifndef _USB_UTIL_H
#define _USB_UTIL_H
-#include "stdbool.h"
-#include "string.h"
-#include "stdint.h"
-#include "stdio.h"
-#include "stdlib.h"
+#include <stdbool.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
#include "usb_slist.h"
-#ifndef __packed
-#define __packed __attribute__((__packed__))
+#if defined(__CC_ARM)
+#ifndef __USED
+#define __USED __attribute__((used))
#endif
-#ifndef __aligned
-#define __aligned(x) __attribute__((__aligned__(x)))
+#ifndef __WEAK
+#define __WEAK __attribute__((weak))
#endif
-#define __may_alias __attribute__((__may_alias__))
-#ifndef __printf_like
-#define __printf_like(f, a) __attribute__((format(printf, f, a)))
+#ifndef __PACKED
+#define __PACKED __attribute__((packed))
+#endif
+#ifndef __PACKED_STRUCT
+#define __PACKED_STRUCT __packed struct
+#endif
+#ifndef __PACKED_UNION
+#define __PACKED_UNION __packed union
+#endif
+#ifndef __ALIGNED
+#define __ALIGNED(x) __attribute__((aligned(x)))
+#endif
+#elif defined(__GNUC__)
+#ifndef __USED
+#define __USED __attribute__((used))
+#endif
+#ifndef __WEAK
+#define __WEAK __attribute__((weak))
+#endif
+#ifndef __PACKED
+#define __PACKED __attribute__((packed, aligned(1)))
+#endif
+#ifndef __PACKED_STRUCT
+#define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
+#endif
+#ifndef __PACKED_UNION
+#define __PACKED_UNION union __attribute__((packed, aligned(1)))
+#endif
+#ifndef __ALIGNED
+#define __ALIGNED(x) __attribute__((aligned(x)))
+#endif
+#elif defined(__ICCARM__)
+#ifndef __USED
+#if __ICCARM_V8
+#define __USED __attribute__((used))
+#else
+#define __USED _Pragma("__root")
#endif
-#define __used __attribute__((__used__))
-#ifndef __deprecated
-#define __deprecated __attribute__((deprecated))
#endif
-#define ARG_UNUSED(x) (void)(x)
-// #define likely(x) __builtin_expect((bool)!!(x), true)
-// #define unlikely(x) __builtin_expect((bool)!!(x), false)
+#ifndef __WEAK
+#if __ICCARM_V8
+#define __WEAK __attribute__((weak))
+#else
+#define __WEAK _Pragma("__weak")
+#endif
+#endif
-#define popcount(x) __builtin_popcount(x)
+#ifndef __PACKED
+#if __ICCARM_V8
+#define __PACKED __attribute__((packed, aligned(1)))
+#else
+/* Needs IAR language extensions */
+#define __PACKED __packed
+#endif
+#endif
-#ifndef __no_optimization
-#define __no_optimization __attribute__((optimize("-O0")))
+#ifndef __PACKED_STRUCT
+#if __ICCARM_V8
+#define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
+#else
+/* Needs IAR language extensions */
+#define __PACKED_STRUCT __packed struct
+#endif
+#endif
+
+#ifndef __PACKED_UNION
+#if __ICCARM_V8
+#define __PACKED_UNION union __attribute__((packed, aligned(1)))
+#else
+/* Needs IAR language extensions */
+#define __PACKED_UNION __packed union
+#endif
+#endif
+
+#ifndef __ALIGNED
+#if __ICCARM_V8
+#define __ALIGNED(x) __attribute__((aligned(x)))
+#elif (__VER__ >= 7080000)
+/* Needs IAR language extensions */
+#define __ALIGNED(x) __attribute__((aligned(x)))
+#else
+#warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored.
+#define __ALIGNED(x)
+#endif
#endif
-#ifndef __weak
-#define __weak __attribute__((__weak__))
#endif
-#define __unused __attribute__((__unused__))
#ifndef __ALIGN_BEGIN
#define __ALIGN_BEGIN
@@ -45,6 +111,10 @@
#define __ALIGN_END __attribute__((aligned(4)))
#endif
+#ifndef ARG_UNUSED
+#define ARG_UNUSED(x) (void)(x)
+#endif
+
#ifndef LO_BYTE
#define LO_BYTE(x) ((uint8_t)(x & 0x00FF))
#endif
@@ -133,12 +203,13 @@
#define WBVAL(x) (x & 0xFF), ((x >> 8) & 0xFF)
#define DBVAL(x) (x & 0xFF), ((x >> 8) & 0xFF), ((x >> 16) & 0xFF), ((x >> 24) & 0xFF)
-#define USB_DESC_SECTION __attribute__((section("usb_desc"))) __used __aligned(1)
+#define USB_DESC_SECTION __attribute__((section("usb_desc"))) __USED __ALIGNED(1)
#if 0
-#define USBD_LOG_WRN(a, ...) printf(a, ##__VA_ARGS__)
-#define USBD_LOG_DBG(a, ...) printf(a, ##__VA_ARGS__)
-#define USBD_LOG_ERR(a, ...) printf(a, ##__VA_ARGS__)
+#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__)
#else
#define USBD_LOG_INFO(a, ...) printf(a, ##__VA_ARGS__)
#define USBD_LOG_DBG(a, ...)
@@ -146,4 +217,4 @@
#define USBD_LOG_ERR(a, ...) printf(a, ##__VA_ARGS__)
#endif
-#endif \ No newline at end of file
+#endif