summaryrefslogtreecommitdiff
path: root/tinyusb/common
diff options
context:
space:
mode:
Diffstat (limited to 'tinyusb/common')
-rw-r--r--tinyusb/common/common.h7
-rw-r--r--tinyusb/common/compiler/compiler_gcc.h12
2 files changed, 11 insertions, 8 deletions
diff --git a/tinyusb/common/common.h b/tinyusb/common/common.h
index 3ab530e6a..ecc7bf425 100644
--- a/tinyusb/common/common.h
+++ b/tinyusb/common/common.h
@@ -110,14 +110,15 @@
#define U32_TO_U8S_LE(u32) U32_B4_U8(u32), U32_B3_U8(u32), U32_B2_U8(u32), U32_B1_U8(u32)
//------------- Endian Conversion -------------//
-#define ENDIAN_BE(le32) \
- (uint32_t) ( ((le32 & 0xFF) << 24) | ((le32 & 0xFF00) << 8) | ((le32 >> 8) & 0xFF00) | ((le32 >> 24) & 0xFF) )
+#define ENDIAN_BE(u32) \
+ (uint32_t) ( (((u32) & 0xFF) << 24) | (((u32) & 0xFF00) << 8) | (((u32) >> 8) & 0xFF00) | (((u32) >> 24) & 0xFF) )
#define ENDIAN_BE16(le16) ((uint16_t) ((U16_LOW_U8(le16) << 8) | U16_HIGH_U8(le16)) )
-// TODO refractor to built-in function
+#ifndef __n2be_16
#define __n2be_16(u16) ((uint16_t) ((U16_LOW_U8(u16) << 8) | U16_HIGH_U8(u16)) )
#define __be2n_16(u16) __n2be_16(u16)
+#endif
//--------------------------------------------------------------------+
// INLINE FUNCTION
diff --git a/tinyusb/common/compiler/compiler_gcc.h b/tinyusb/common/compiler/compiler_gcc.h
index 1733fab02..188ae271d 100644
--- a/tinyusb/common/compiler/compiler_gcc.h
+++ b/tinyusb/common/compiler/compiler_gcc.h
@@ -130,12 +130,14 @@
* @{
*/
-//#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-// built-in function to convert 32-bit from native to Big Endian
-#define __be2n __builtin_bswap32
-#define __n2be __be2n
+// TODO mcu specific
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define __n2be(x) __REV(x) ///< built-in function to convert 32-bit from native to Big Endian
+#define __be2n(x) __n2be(x) ///< built-in function to convert 32-bit from Big Endian to native
-//#define __le2be_16 __builtin_bswap16
+#define __n2be_16(u16) ((uint16_t) __REV16(u16))
+#define __be2n_16(u16) __n2be_16(u16)
+#endif
/** @} */