#ifndef __LUFA_ENDIANNESS_H__\r
#define __LUFA_ENDIANNESS_H__\r
\r
+ /* Enable C linkage for C++ Compilers: */\r
+ #if defined(__cplusplus)\r
+ extern "C" {\r
+ #endif\r
+\r
/* Preprocessor Checks: */\r
#if !defined(__INCLUDE_FROM_COMMON_H)\r
#error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.\r
*\r
* \ingroup Group_ByteSwapping\r
*\r
- * \param[in] x 16-bit value whose byte ordering is to be swapped.\r
+ * \param[in] x 16-bit value whose byte ordering is to be swapped.\r
*\r
* \return Input value with the byte ordering reversed.\r
*/\r
- #define SWAPENDIAN_16(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))\r
+ #define SWAPENDIAN_16(x) (uint16_t)((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))\r
\r
/** Swaps the byte ordering of a 32-bit value at compile-time. Do not use this macro for swapping byte orderings\r
* of dynamic values computed at runtime- use \ref SwapEndian_32() instead. The result of this macro can be used\r
*\r
* \ingroup Group_ByteSwapping\r
*\r
- * \param[in] x 32-bit value whose byte ordering is to be swapped.\r
+ * \param[in] x 32-bit value whose byte ordering is to be swapped.\r
*\r
* \return Input value with the byte ordering reversed.\r
*/\r
- #define SWAPENDIAN_32(x) ((((x) & 0xFF000000UL) >> 24UL) | (((x) & 0x00FF0000UL) >> 8UL) | \\r
- (((x) & 0x0000FF00UL) << 8UL) | (((x) & 0x000000FFUL) << 24UL))\r
+ #define SWAPENDIAN_32(x) (uint32_t)((((x) & 0xFF000000UL) >> 24UL) | (((x) & 0x00FF0000UL) >> 8UL) | \\r
+ (((x) & 0x0000FF00UL) << 8UL) | (((x) & 0x000000FFUL) << 24UL))\r
\r
#if defined(ARCH_BIG_ENDIAN) && !defined(le16_to_cpu)\r
#define le16_to_cpu(x) SwapEndian_16(x)\r
*\r
* \ingroup Group_ByteSwapping\r
*\r
- * \param[in,out] Data Pointer to a number containing an even number of bytes to be reversed.\r
- * \param[in] Bytes Length of the data in bytes.\r
+ * \param[in,out] Data Pointer to a number containing an even number of bytes to be reversed.\r
+ * \param[in] Length Length of the data in bytes.\r
*/\r
- static inline void SwapEndian_n(void* Data,\r
- uint8_t Bytes) ATTR_NON_NULL_PTR_ARG(1);\r
- static inline void SwapEndian_n(void* Data,\r
- uint8_t Bytes)\r
+ static inline void SwapEndian_n(void* const Data,\r
+ uint8_t Length) ATTR_NON_NULL_PTR_ARG(1);\r
+ static inline void SwapEndian_n(void* const Data,\r
+ uint8_t Length)\r
{\r
uint8_t* CurrDataPos = (uint8_t*)Data;\r
\r
- while (Bytes > 1)\r
+ while (Length > 1)\r
{\r
uint8_t Temp = *CurrDataPos;\r
- *CurrDataPos = *(CurrDataPos + Bytes - 1);\r
- *(CurrDataPos + Bytes - 1) = Temp;\r
+ *CurrDataPos = *(CurrDataPos + Length - 1);\r
+ *(CurrDataPos + Length - 1) = Temp;\r
\r
CurrDataPos++;\r
- Bytes -= 2;\r
+ Length -= 2;\r
}\r
}\r
\r
+ /* Disable C linkage for C++ Compilers: */\r
+ #if defined(__cplusplus)\r
+ }\r
+ #endif\r
+\r
#endif\r
\r
/** @} */\r