summaryrefslogtreecommitdiffstats
path: root/tmk_core/protocol/arm_atsam/usb
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/protocol/arm_atsam/usb')
-rw-r--r--tmk_core/protocol/arm_atsam/usb/compiler.h934
-rw-r--r--tmk_core/protocol/arm_atsam/usb/conf_usb.h73
-rw-r--r--tmk_core/protocol/arm_atsam/usb/main_usb.c74
-rw-r--r--tmk_core/protocol/arm_atsam/usb/status_codes.h98
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udc.c651
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udc.h26
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udc_desc.h29
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udd.h40
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udi.h96
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udi_cdc.c857
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udi_cdc.h58
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udi_cdc_conf.h16
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udi_device_conf.h654
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udi_device_epsize.h21
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udi_hid.c82
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udi_hid.h4
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c789
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.h48
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udi_hid_kbd_conf.h2
-rw-r--r--tmk_core/protocol/arm_atsam/usb/udi_hid_kbd_desc.c108
-rw-r--r--tmk_core/protocol/arm_atsam/usb/ui.c39
-rw-r--r--tmk_core/protocol/arm_atsam/usb/ui.h2
-rw-r--r--tmk_core/protocol/arm_atsam/usb/usb.c345
-rw-r--r--tmk_core/protocol/arm_atsam/usb/usb.h110
-rw-r--r--tmk_core/protocol/arm_atsam/usb/usb2422.c366
-rw-r--r--tmk_core/protocol/arm_atsam/usb/usb2422.h384
-rw-r--r--tmk_core/protocol/arm_atsam/usb/usb_atmel.h181
-rw-r--r--tmk_core/protocol/arm_atsam/usb/usb_device_udd.c386
-rw-r--r--tmk_core/protocol/arm_atsam/usb/usb_main.h51
-rw-r--r--tmk_core/protocol/arm_atsam/usb/usb_protocol.h252
-rw-r--r--tmk_core/protocol/arm_atsam/usb/usb_protocol_cdc.h215
-rw-r--r--tmk_core/protocol/arm_atsam/usb/usb_protocol_hid.h383
-rw-r--r--tmk_core/protocol/arm_atsam/usb/usb_util.c54
-rw-r--r--tmk_core/protocol/arm_atsam/usb/usb_util.h3
34 files changed, 3200 insertions, 4231 deletions
diff --git a/tmk_core/protocol/arm_atsam/usb/compiler.h b/tmk_core/protocol/arm_atsam/usb/compiler.h
index b2ccfd73ed..6ba2322340 100644
--- a/tmk_core/protocol/arm_atsam/usb/compiler.h
+++ b/tmk_core/protocol/arm_atsam/usb/compiler.h
@@ -43,7 +43,7 @@
*/
#ifndef UTILS_COMPILER_H_INCLUDED
-#define UTILS_COMPILER_H_INCLUDED
+# define UTILS_COMPILER_H_INCLUDED
/**
* \defgroup group_sam0_utils Compiler abstraction layer and code utilities
@@ -54,38 +54,38 @@
* @{
*/
-#if (defined __ICCARM__)
-# include <intrinsics.h>
-#endif
+# if (defined __ICCARM__)
+# include <intrinsics.h>
+# endif
-#include <stddef.h>
+# include <stddef.h>
//#include <parts.h>
//#include <status_codes.h>
//#include <preprocessor.h>
//#include <io.h>
-#ifndef __ASSEMBLY__
+# ifndef __ASSEMBLY__
-#include <stdio.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdlib.h>
+# include <stdio.h>
+# include <stdbool.h>
+# include <stdint.h>
+# include <stdlib.h>
/**
* \def UNUSED
* \brief Marking \a v as a unused parameter or value.
*/
-#define UNUSED(v) (void)(v)
+# define UNUSED(v) (void)(v)
/**
* \def barrier
* \brief Memory barrier
*/
-#ifdef __GNUC__
-# define barrier() asm volatile("" ::: "memory")
-#else
-# define barrier() asm ("")
-#endif
+# ifdef __GNUC__
+# define barrier() asm volatile("" ::: "memory")
+# else
+# define barrier() asm("")
+# endif
/**
* \brief Emit the compiler pragma \a arg.
@@ -93,38 +93,37 @@
* \param[in] arg The pragma directive as it would appear after \e \#pragma
* (i.e. not stringified).
*/
-#define COMPILER_PRAGMA(arg) _Pragma(#arg)
+# define COMPILER_PRAGMA(arg) _Pragma(# arg)
/**
* \def COMPILER_PACK_SET(alignment)
* \brief Set maximum alignment for subsequent struct and union definitions to \a alignment.
*/
-#define COMPILER_PACK_SET(alignment) COMPILER_PRAGMA(pack(alignment))
+# define COMPILER_PACK_SET(alignment) COMPILER_PRAGMA(pack(alignment))
/**
* \def COMPILER_PACK_RESET()
* \brief Set default alignment for subsequent struct and union definitions.
*/
-#define COMPILER_PACK_RESET() COMPILER_PRAGMA(pack())
-
+# define COMPILER_PACK_RESET() COMPILER_PRAGMA(pack())
/**
* \brief Set aligned boundary.
*/
-#if (defined __GNUC__) || (defined __CC_ARM)
-# define COMPILER_ALIGNED(a) __attribute__((__aligned__(a)))
-#elif (defined __ICCARM__)
-# define COMPILER_ALIGNED(a) COMPILER_PRAGMA(data_alignment = a)
-#endif
+# if (defined __GNUC__) || (defined __CC_ARM)
+# define COMPILER_ALIGNED(a) __attribute__((__aligned__(a)))
+# elif (defined __ICCARM__)
+# define COMPILER_ALIGNED(a) COMPILER_PRAGMA(data_alignment = a)
+# endif
/**
* \brief Set word-aligned boundary.
*/
-#if (defined __GNUC__) || defined(__CC_ARM)
-#define COMPILER_WORD_ALIGNED __attribute__((__aligned__(4)))
-#elif (defined __ICCARM__)
-#define COMPILER_WORD_ALIGNED COMPILER_PRAGMA(data_alignment = 4)
-#endif
+# if (defined __GNUC__) || defined(__CC_ARM)
+# define COMPILER_WORD_ALIGNED __attribute__((__aligned__(4)))
+# elif (defined __ICCARM__)
+# define COMPILER_WORD_ALIGNED COMPILER_PRAGMA(data_alignment = 4)
+# endif
/**
* \def __always_inline
@@ -134,15 +133,15 @@
* heuristics and inline the function no matter how big it thinks it
* becomes.
*/
-#if !defined(__always_inline)
-#if defined(__CC_ARM)
-# define __always_inline __forceinline
-#elif (defined __GNUC__)
-# define __always_inline __attribute__((__always_inline__))
-#elif (defined __ICCARM__)
-# define __always_inline _Pragma("inline=forced")
-#endif
-#endif
+# if !defined(__always_inline)
+# if defined(__CC_ARM)
+# define __always_inline __forceinline
+# elif (defined __GNUC__)
+# define __always_inline __attribute__((__always_inline__))
+# elif (defined __ICCARM__)
+# define __always_inline _Pragma("inline=forced")
+# endif
+# endif
/**
* \def __no_inline
@@ -152,14 +151,13 @@
* heuristics and not inline the function no matter how small it thinks it
* becomes.
*/
-#if defined(__CC_ARM)
-# define __no_inline __attribute__((noinline))
-#elif (defined __GNUC__)
-# define __no_inline __attribute__((noinline))
-#elif (defined __ICCARM__)
-# define __no_inline _Pragma("inline=never")
-#endif
-
+# if defined(__CC_ARM)
+# define __no_inline __attribute__((noinline))
+# elif (defined __GNUC__)
+# define __no_inline __attribute__((noinline))
+# elif (defined __ICCARM__)
+# define __no_inline _Pragma("inline=never")
+# endif
/** \brief This macro is used to test fatal errors.
*
@@ -170,212 +168,201 @@
*
* \param[in] expr Expression to evaluate and supposed to be nonzero.
*/
-#if defined(_ASSERT_ENABLE_)
-# if defined(TEST_SUITE_DEFINE_ASSERT_MACRO)
-# include "unit_test/suite.h"
-# else
-# undef TEST_SUITE_DEFINE_ASSERT_MACRO
-# define Assert(expr) \
- {\
- if (!(expr)) asm("BKPT #0");\
- }
-# endif
-#else
-# define Assert(expr) ((void) 0)
-#endif
+# if defined(_ASSERT_ENABLE_)
+# if defined(TEST_SUITE_DEFINE_ASSERT_MACRO)
+# include "unit_test/suite.h"
+# else
+# undef TEST_SUITE_DEFINE_ASSERT_MACRO
+# define Assert(expr) \
+ { \
+ if (!(expr)) asm("BKPT #0"); \
+ }
+# endif
+# else
+# define Assert(expr) ((void)0)
+# endif
/* Define WEAK attribute */
-#if defined ( __CC_ARM )
-# define WEAK __attribute__ ((weak))
-#elif defined ( __ICCARM__ )
-# define WEAK __weak
-#elif defined ( __GNUC__ )
-# define WEAK __attribute__ ((weak))
-#endif
+# if defined(__CC_ARM)
+# define WEAK __attribute__((weak))
+# elif defined(__ICCARM__)
+# define WEAK __weak
+# elif defined(__GNUC__)
+# define WEAK __attribute__((weak))
+# endif
/* Define NO_INIT attribute */
-#if defined ( __CC_ARM )
-# define NO_INIT __attribute__((zero_init))
-#elif defined ( __ICCARM__ )
-# define NO_INIT __no_init
-#elif defined ( __GNUC__ )
-# define NO_INIT __attribute__((section(".no_init")))
-#endif
+# if defined(__CC_ARM)
+# define NO_INIT __attribute__((zero_init))
+# elif defined(__ICCARM__)
+# define NO_INIT __no_init
+# elif defined(__GNUC__)
+# define NO_INIT __attribute__((section(".no_init")))
+# endif
//#include "interrupt.h"
/** \name Usual Types
* @{ */
-#ifndef __cplusplus
-# if !defined(__bool_true_false_are_defined)
-typedef unsigned char bool;
-# endif
-#endif
-typedef uint16_t le16_t;
-typedef uint16_t be16_t;
-typedef uint32_t le32_t;
-typedef uint32_t be32_t;
-typedef uint32_t iram_size_t;
+# ifndef __cplusplus
+# if !defined(__bool_true_false_are_defined)
+typedef unsigned char bool;
+# endif
+# endif
+typedef uint16_t le16_t;
+typedef uint16_t be16_t;
+typedef uint32_t le32_t;
+typedef uint32_t be32_t;
+typedef uint32_t iram_size_t;
/** @} */
/** \name Aliasing Aggregate Types
* @{ */
/** 16-bit union. */
-typedef union
-{
- int16_t s16;
- uint16_t u16;
- int8_t s8[2];
- uint8_t u8[2];
+typedef union {
+ int16_t s16;
+ uint16_t u16;
+ int8_t s8[2];
+ uint8_t u8[2];
} Union16;
/** 32-bit union. */
-typedef union
-{
- int32_t s32;
- uint32_t u32;
- int16_t s16[2];
- uint16_t u16[2];
- int8_t s8[4];
- uint8_t u8[4];
+typedef union {
+ int32_t s32;
+ uint32_t u32;
+ int16_t s16[2];
+ uint16_t u16[2];
+ int8_t s8[4];
+ uint8_t u8[4];
} Union32;
/** 64-bit union. */
-typedef union
-{
- int64_t s64;
- uint64_t u64;
- int32_t s32[2];
- uint32_t u32[2];
- int16_t s16[4];
- uint16_t u16[4];
- int8_t s8[8];
- uint8_t u8[8];
+typedef union {
+ int64_t s64;
+ uint64_t u64;
+ int32_t s32[2];
+ uint32_t u32[2];
+ int16_t s16[4];
+ uint16_t u16[4];
+ int8_t s8[8];
+ uint8_t u8[8];
} Union64;
/** Union of pointers to 64-, 32-, 16- and 8-bit unsigned integers. */
-typedef union
-{
- int64_t *s64ptr;
- uint64_t *u64ptr;
- int32_t *s32ptr;
- uint32_t *u32ptr;
- int16_t *s16ptr;
- uint16_t *u16ptr;
- int8_t *s8ptr;
- uint8_t *u8ptr;
+typedef union {
+ int64_t * s64ptr;
+ uint64_t *u64ptr;
+ int32_t * s32ptr;
+ uint32_t *u32ptr;
+ int16_t * s16ptr;
+ uint16_t *u16ptr;
+ int8_t * s8ptr;
+ uint8_t * u8ptr;
} UnionPtr;
/** Union of pointers to volatile 64-, 32-, 16- and 8-bit unsigned integers. */
-typedef union
-{
- volatile int64_t *s64ptr;
- volatile uint64_t *u64ptr;
- volatile int32_t *s32ptr;
- volatile uint32_t *u32ptr;
- volatile int16_t *s16ptr;
- volatile uint16_t *u16ptr;
- volatile int8_t *s8ptr;
- volatile uint8_t *u8ptr;
+typedef union {
+ volatile int64_t * s64ptr;
+ volatile uint64_t *u64ptr;
+ volatile int32_t * s32ptr;
+ volatile uint32_t *u32ptr;
+ volatile int16_t * s16ptr;
+ volatile uint16_t *u16ptr;
+ volatile int8_t * s8ptr;
+ volatile uint8_t * u8ptr;
} UnionVPtr;
/** Union of pointers to constant 64-, 32-, 16- and 8-bit unsigned integers. */
-typedef union
-{
- const int64_t *s64ptr;
- const uint64_t *u64ptr;
- const int32_t *s32ptr;
- const uint32_t *u32ptr;
- const int16_t *s16ptr;
- const uint16_t *u16ptr;
- const int8_t *s8ptr;
- const uint8_t *u8ptr;
+typedef union {
+ const int64_t * s64ptr;
+ const uint64_t *u64ptr;
+ const int32_t * s32ptr;
+ const uint32_t *u32ptr;
+ const int16_t * s16ptr;
+ const uint16_t *u16ptr;
+ const int8_t * s8ptr;
+ const uint8_t * u8ptr;
} UnionCPtr;
/** Union of pointers to constant volatile 64-, 32-, 16- and 8-bit unsigned integers. */
-typedef union
-{
- const volatile int64_t *s64ptr;
- const volatile uint64_t *u64ptr;
- const volatile int32_t *s32ptr;
- const volatile uint32_t *u32ptr;
- const volatile int16_t *s16ptr;
- const volatile uint16_t *u16ptr;
- const volatile int8_t *s8ptr;
- const volatile uint8_t *u8ptr;
+typedef union {
+ const volatile int64_t * s64ptr;
+ const volatile uint64_t *u64ptr;
+ const volatile int32_t * s32ptr;
+ const volatile uint32_t *u32ptr;
+ const volatile int16_t * s16ptr;
+ const volatile uint16_t *u16ptr;
+ const volatile int8_t * s8ptr;
+ const volatile uint8_t * u8ptr;
} UnionCVPtr;
/** Structure of pointers to 64-, 32-, 16- and 8-bit unsigned integers. */
-typedef struct
-{
- int64_t *s64ptr;
- uint64_t *u64ptr;
- int32_t *s32ptr;
- uint32_t *u32ptr;
- int16_t *s16ptr;
- uint16_t *u16ptr;
- int8_t *s8ptr;
- uint8_t *u8ptr;
+typedef struct {
+ int64_t * s64ptr;
+ uint64_t *u64ptr;
+ int32_t * s32ptr;
+ uint32_t *u32ptr;
+ int16_t * s16ptr;
+ uint16_t *u16ptr;
+ int8_t * s8ptr;
+ uint8_t * u8ptr;
} StructPtr;
/** Structure of pointers to volatile 64-, 32-, 16- and 8-bit unsigned integers. */
-typedef struct
-{
- volatile int64_t *s64ptr;
- volatile uint64_t *u64ptr;
- volatile int32_t *s32ptr;
- volatile uint32_t *u32ptr;
- volatile int16_t *s16ptr;
- volatile uint16_t *u16ptr;
- volatile int8_t *s8ptr;
- volatile uint8_t *u8ptr;
+typedef struct {
+ volatile int64_t * s64ptr;
+ volatile uint64_t *u64ptr;
+ volatile int32_t * s32ptr;
+ volatile uint32_t *u32ptr;
+ volatile int16_t * s16ptr;
+ volatile uint16_t *u16ptr;
+ volatile int8_t * s8ptr;
+ volatile uint8_t * u8ptr;
} StructVPtr;
/** Structure of pointers to constant 64-, 32-, 16- and 8-bit unsigned integers. */
-typedef struct
-{
- const int64_t *s64ptr;
- const uint64_t *u64ptr;
- const int32_t *s32ptr;
- const uint32_t *u32ptr;
- const int16_t *s16ptr;
- const uint16_t *u16ptr;
- const int8_t *s8ptr;
- const uint8_t *u8ptr;
+typedef struct {
+ const int64_t * s64ptr;
+ const uint64_t *u64ptr;
+ const int32_t * s32ptr;
+ const uint32_t *u32ptr;
+ const int16_t * s16ptr;
+ const uint16_t *u16ptr;
+ const int8_t * s8ptr;
+ const uint8_t * u8ptr;
} StructCPtr;
/** Structure of pointers to constant volatile 64-, 32-, 16- and 8-bit unsigned integers. */
-typedef struct
-{
- const volatile int64_t *s64ptr;
- const volatile uint64_t *u64ptr;
- const volatile int32_t *s32ptr;
- const volatile uint32_t *u32ptr;
- const volatile int16_t *s16ptr;
- const volatile uint16_t *u16ptr;
- const volatile int8_t *s8ptr;
- const volatile uint8_t *u8ptr;
+typedef struct {
+ const volatile int64_t * s64ptr;
+ const volatile uint64_t *u64ptr;
+ const volatile int32_t * s32ptr;
+ const volatile uint32_t *u32ptr;
+ const volatile int16_t * s16ptr;
+ const volatile uint16_t *u16ptr;
+ const volatile int8_t * s8ptr;
+ const volatile uint8_t * u8ptr;
} StructCVPtr;
/** @} */
-#endif /* #ifndef __ASSEMBLY__ */
+# endif /* #ifndef __ASSEMBLY__ */
/** \name Usual Constants
* @{ */
-//kmod #define DISABLE 0
-//kmod #define ENABLE 1
-
-#ifndef __cplusplus
-# if !defined(__bool_true_false_are_defined)
-# define false 0
-# define true 1
-# endif
-#endif
+// kmod #define DISABLE 0
+// kmod #define ENABLE 1
+
+# ifndef __cplusplus
+# if !defined(__bool_true_false_are_defined)
+# define false 0
+# define true 1
+# endif
+# endif
/** @} */
-#ifndef __ASSEMBLY__
+# ifndef __ASSEMBLY__
/** \name Optimization Control
* @{ */
@@ -384,17 +371,17 @@ typedef struct
* \def likely(exp)
* \brief The expression \a exp is likely to be true
*/
-#if !defined(likely) || defined(__DOXYGEN__)
-# define likely(exp) (exp)
-#endif
+# if !defined(likely) || defined(__DOXYGEN__)
+# define likely(exp) (exp)
+# endif
/**
* \def unlikely(exp)
* \brief The expression \a exp is unlikely to be true
*/
-#if !defined(unlikely) || defined(__DOXYGEN__)
-# define unlikely(exp) (exp)
-#endif
+# if !defined(unlikely) || defined(__DOXYGEN__)
+# define unlikely(exp) (exp)
+# endif
/**
* \def is_constant(exp)
@@ -404,11 +391,11 @@ typedef struct
*
* \return true if \a exp is constant, false otherwise.
*/
-#if (defined __GNUC__) || (defined __CC_ARM)
-# define is_constant(exp) __builtin_constant_p(exp)
-#else
-# define is_constant(exp) (0)
-#endif
+# if (defined __GNUC__) || (defined __CC_ARM)
+# define is_constant(exp) __builtin_constant_p(exp)
+# else
+# define is_constant(exp) (0)
+# endif
/** @} */
@@ -422,7 +409,7 @@ typedef struct
*
* \return Read bits.
*/
-#define Rd_bits( value, mask) ((value) & (mask))
+# define Rd_bits(value, mask) ((value) & (mask))
/** \brief Writes the bits of a C lvalue specified by a given bit-mask.
*
@@ -432,8 +419,7 @@ typedef struct
*
* \return Resulting value with written bits.
*/
-#define Wr_bits(lvalue, mask, bits) ((lvalue) = ((lvalue) & ~(mask)) |\
- ((bits ) & (mask)))
+# define Wr_bits(lvalue, mask, bits) ((lvalue) = ((lvalue) & ~(mask)) | ((bits) & (mask)))
/** \brief Tests the bits of a value specified by a given bit-mask.
*
@@ -442,7 +428,7 @@ typedef struct
*
* \return \c 1 if at least one of the tested bits is set, else \c 0.
*/
-#define Tst_bits( value, mask) (Rd_bits(value, mask) != 0)
+# define Tst_bits(value, mask) (Rd_bits(value, mask) != 0)
/** \brief Clears the bits of a C lvalue specified by a given bit-mask.
*
@@ -451,7 +437,7 @@ typedef struct
*
* \return Resulting value with cleared bits.
*/
-#define Clr_bits(lvalue, mask) ((lvalue) &= ~(mask))
+# define Clr_bits(lvalue, mask) ((lvalue) &= ~(mask))
/** \brief Sets the bits of a C lvalue specified by a given bit-mask.
*
@@ -460,7 +446,7 @@ typedef struct
*
* \return Resulting value with set bits.
*/
-#define Set_bits(lvalue, mask) ((lvalue) |= (mask))
+# define Set_bits(lvalue, mask) ((lvalue) |= (mask))
/** \brief Toggles the bits of a C lvalue specified by a given bit-mask.
*
@@ -469,7 +455,7 @@ typedef struct
*
* \return Resulting value with toggled bits.
*/
-#define Tgl_bits(lvalue, mask) ((lvalue) ^= (mask))
+# define Tgl_bits(lvalue, mask) ((lvalue) ^= (mask))
/** \brief Reads the bit-field of a value specified by a given bit-mask.
*
@@ -478,7 +464,7 @@ typedef struct
*
* \return Read bit-field.
*/
-#define Rd_bitfield( value, mask) (Rd_bits( value, mask) >> ctz(mask))
+# define Rd_bitfield(value, mask) (Rd_bits(value, mask) >> ctz(mask))
/** \brief Writes the bit-field of a C lvalue specified by a given bit-mask.
*
@@ -488,11 +474,10 @@ typedef struct
*
* \return Resulting value with written bit-field.
*/
-#define Wr_bitfield(lvalue, mask, bitfield) (Wr_bits(lvalue, mask, (uint32_t)(bitfield) << ctz(mask)))
+# define Wr_bitfield(lvalue, mask, bitfield) (Wr_bits(lvalue, mask, (uint32_t)(bitfield) << ctz(mask)))
/** @} */
-
/** \name Zero-Bit Counting
*
* Under GCC, __builtin_clz and __builtin_ctz behave like macros when
@@ -513,43 +498,11 @@ typedef struct
*
* \return The count of leading zero bits in \a u.
*/
-#if (defined __GNUC__) || (defined __CC_ARM)
-# define clz(u) ((u) ? __builtin_clz(u) : 32)
-#else
-# define clz(u) (((u) == 0) ? 32 : \
- ((u) & (1ul << 31)) ? 0 : \
- ((u) & (1ul << 30)) ? 1 : \
- ((u) & (1ul << 29)) ? 2 : \
- ((u) & (1ul << 28)) ? 3 : \
- ((u) & (1ul << 27)) ? 4 : \
- ((u) & (1ul << 26)) ? 5 : \
- ((u) & (1ul << 25)) ? 6 : \
- ((u) & (1ul << 24)) ? 7 : \
- ((u) & (1ul << 23)) ? 8 : \
- ((u) & (1ul << 22)) ? 9 : \
- ((u) & (1ul << 21)) ? 10 : \
- ((u) & (1ul << 20)) ? 11 : \
- ((u) & (1ul << 19)) ? 12 : \
- ((u) & (1ul << 18)) ? 13 : \
- ((u) & (1ul << 17)) ? 14 : \
- ((u) & (1ul << 16)) ? 15 : \
- ((u) & (1ul << 15)) ? 16 : \
- ((u) & (1ul << 14)) ? 17 : \
- ((u) & (1ul << 13)) ? 18 : \
- ((u) & (1ul << 12)) ? 19 : \
- ((u) & (1ul << 11)) ? 20 : \
- ((u) & (1ul << 10)) ? 21 : \
- ((u) & (1ul << 9)) ? 22 : \
- ((u) & (1ul << 8)) ? 23 : \
- ((u) & (1ul << 7)) ? 24 : \
- ((u) & (1ul << 6)) ? 25 : \
- ((u) & (1ul << 5)) ? 26 : \
- ((u) & (1ul << 4)) ? 27 : \
- ((u) & (1ul << 3)) ? 28 : \
- ((u) & (1ul << 2)) ? 29 : \
- ((u) & (1ul << 1)) ? 30 : \
- 31)
-#endif
+# if (defined __GNUC__) || (defined __CC_ARM)
+# define clz(u) ((u) ? __builtin_clz(u) : 32)
+# else
+# define clz(u) (((u) == 0) ? 32 : ((u) & (1ul << 31)) ? 0 : ((u) & (1ul << 30)) ? 1 : ((u) & (1ul << 29)) ? 2 : ((u) & (1ul << 28)) ? 3 : ((u) & (1ul << 27)) ? 4 : ((u) & (1ul << 26)) ? 5 : ((u) & (1ul << 25)) ? 6 : ((u) & (1ul << 24)) ? 7 : ((u) & (1ul << 23)) ? 8 : ((u) & (1ul << 22)) ? 9 : ((u) & (1ul << 21)) ? 10 : ((u) & (1ul << 20)) ? 11 : ((u) & (1ul << 19)) ? 12 : ((u) & (1ul << 18)) ? 13 : ((u) & (1ul << 17)) ? 14 : ((u) & (1ul << 16)) ? 15 : ((u) & (1ul << 15)) ? 16 : ((u) & (1ul << 14)) ? 17 : ((u) & (1ul << 13)) ? 18 : ((u) & (1ul << 12)) ? 19 : ((u) & (1ul << 11)) ? 20 : ((u) & (1ul << 10)) ? 21 : ((u) & (1ul << 9)) ? 22 : ((u) & (1ul << 8)) ? 23 : ((u) & (1ul << 7)) ? 24 : ((u) & (1ul << 6)) ? 25 : ((u) & (1ul << 5)) ? 26 : ((u) & (1ul << 4)) ? 27 : ((u) & (1ul << 3)) ? 28 : ((u) & (1ul << 2)) ? 29 : ((u) & (1ul << 1)) ? 30 : 31)
+# endif
/** \brief Counts the trailing zero bits of the given value considered as a 32-bit integer.
*
@@ -557,47 +510,14 @@ typedef struct
*
* \return The count of trailing zero bits in \a u.
*/
-#if (defined __GNUC__) || (defined __CC_ARM)
-# define ctz(u) ((u) ? __builtin_ctz(u) : 32)
-#else
-# define ctz(u) ((u) & (1ul << 0) ? 0 : \
- (u) & (1ul << 1) ? 1 : \
- (u) & (1ul << 2) ? 2 : \
- (u) & (1ul << 3) ? 3 : \
- (u) & (1ul << 4) ? 4 : \
- (u) & (1ul << 5) ? 5 : \
- (u) & (1ul << 6) ? 6 : \
- (u) & (1ul << 7) ? 7 : \
- (u) & (1ul << 8) ? 8 : \
- (u) & (1ul << 9) ? 9 : \
- (u) & (1ul << 10) ? 10 : \
- (u) & (1ul << 11) ? 11 : \
- (u) & (1ul << 12) ? 12 : \
- (u) & (1ul << 13) ? 13 : \
- (u) & (1ul << 14) ? 14 : \
- (u) & (1ul << 15) ? 15 : \
- (u) & (1ul << 16) ? 16 : \
- (u) & (1ul << 17) ? 17 : \
- (u) & (1ul << 18) ? 18 : \
- (u) & (1ul << 19) ? 19 : \
- (u) & (1ul << 20) ? 20 : \
- (u) & (1ul << 21) ? 21 : \
- (u) & (1ul << 22) ? 22 : \
- (u) & (1ul << 23) ? 23 : \
- (u) & (1ul << 24) ? 24 : \
- (u) & (1ul << 25) ? 25 : \
- (u) & (1ul << 26) ? 26 : \
- (u) & (1ul << 27) ? 27 : \
- (u) & (1ul << 28) ? 28 : \
- (u) & (1ul << 29) ? 29 : \
- (u) & (1ul << 30) ? 30 : \
- (u) & (1ul << 31) ? 31 : \
- 32)
-#endif
+# if (defined __GNUC__) || (defined __CC_ARM)
+# define ctz(u) ((u) ? __builtin_ctz(u) : 32)
+# else
+# define ctz(u) ((u) & (1ul << 0) ? 0 : (u) & (1ul << 1) ? 1 : (u) & (1ul << 2) ? 2 : (u) & (1ul << 3) ? 3 : (u) & (1ul << 4) ? 4 : (u) & (1ul << 5) ? 5 : (u) & (1ul << 6) ? 6 : (u) & (1ul << 7) ? 7 : (u) & (1ul << 8) ? 8 : (u) & (1ul << 9) ? 9 : (u) & (1ul << 10) ? 10 : (u) & (1ul << 11) ? 11 : (u) & (1ul << 12) ? 12 : (u) & (1ul << 13) ? 13 : (u) & (1ul << 14) ? 14 : (u) & (1ul << 15) ? 15 : (u) & (1ul << 16) ? 16 : (u) & (1ul << 17) ? 17 : (u) & (1ul << 18) ? 18 : (u) & (1ul << 19) ? 19 : (u) & (1ul << 20) ? 20 : (u) & (1ul << 21) ? 21 : (u) & (1ul << 22) ? 22 : (u) & (1ul << 23) ? 23 : (u) & (1ul << 24) ? 24 : (u) & (1ul << 25) ? 25 : (u) & (1ul << 26) ? 26 : (u) & (1ul << 27) ? 27 : (u) & (1ul << 28) ? 28 : (u) & (1ul << 29) ? 29 : (u) & (1ul << 30) ? 30 : (u) & (1ul << 31) ? 31 : 32)
+# endif
/** @} */
-
/** \name Bit Reversing
* @{ */
@@ -607,7 +527,7 @@ typedef struct
*
* \return Value resulting from \a u8 with reversed bits.
*/
-#define bit_reverse8(u8) ((U8)(bit_reverse32((U8)(u8)) >> 24))
+# define bit_reverse8(u8) ((U8)(bit_reverse32((U8)(u8)) >> 24))
/** \brief Reverses the bits of \a u16.
*
@@ -615,7 +535,7 @@ typedef struct
*
* \return Value resulting from \a u16 with reversed bits.
*/
-#define bit_reverse16(u16) ((uint16_t)(bit_reverse32((uint16_t)(u16)) >> 16))
+# define bit_reverse16(u16) ((uint16_t)(bit_reverse32((uint16_t)(u16)) >> 16))
/** \brief Reverses the bits of \a u32.
*
@@ -623,7 +543,7 @@ typedef struct
*
* \return Value resulting from \a u32 with reversed bits.
*/
-#define bit_reverse32(u32) __RBIT(u32)
+# define bit_reverse32(u32) __RBIT(u32)
/** \brief Reverses the bits of \a u64.
*
@@ -631,12 +551,10 @@ typedef struct
*
* \return Value resulting from \a u64 with reversed bits.
*/
-#define bit_reverse64(u64) ((uint64_t)(((uint64_t)bit_reverse32((uint64_t)(u64) >> 32)) |\
- ((uint64_t)bit_reverse32((uint64_t)(u64)) << 32)))
+# define bit_reverse64(u64) ((uint64_t)(((uint64_t)bit_reverse32((uint64_t)(u64) >> 32)) | ((uint64_t)bit_reverse32((uint64_t)(u64)) << 32)))
/** @} */
-
/** \name Alignment
* @{ */
@@ -647,7 +565,7 @@ typedef struct
*
* \return \c 1 if the number \a val is aligned with the \a n boundary, else \c 0.
*/
-#define Test_align(val, n) (!Tst_bits( val, (n) - 1 ) )
+# define Test_align(val, n) (!Tst_bits(val, (n)-1))
/** \brief Gets alignment of the number \a val with respect to the \a n boundary.
*
@@ -656,7 +574,7 @@ typedef struct
*
* \return Alignment of the number \a val with respect to the \a n boundary.
*/
-#define Get_align(val, n) ( Rd_bits( val, (n) - 1 ) )