summaryrefslogtreecommitdiff
path: root/protocol/lufa/LUFA-120730/LUFA/Common
diff options
context:
space:
mode:
Diffstat (limited to 'protocol/lufa/LUFA-120730/LUFA/Common')
-rw-r--r--protocol/lufa/LUFA-120730/LUFA/Common/ArchitectureSpecific.h177
-rw-r--r--protocol/lufa/LUFA-120730/LUFA/Common/Architectures.h84
-rw-r--r--protocol/lufa/LUFA-120730/LUFA/Common/Attributes.h150
-rw-r--r--protocol/lufa/LUFA-120730/LUFA/Common/BoardTypes.h231
-rw-r--r--protocol/lufa/LUFA-120730/LUFA/Common/Common.h381
-rw-r--r--protocol/lufa/LUFA-120730/LUFA/Common/CompilerSpecific.h97
-rw-r--r--protocol/lufa/LUFA-120730/LUFA/Common/Endianness.h489
7 files changed, 1609 insertions, 0 deletions
diff --git a/protocol/lufa/LUFA-120730/LUFA/Common/ArchitectureSpecific.h b/protocol/lufa/LUFA-120730/LUFA/Common/ArchitectureSpecific.h
new file mode 100644
index 0000000000..1e09edf29b
--- /dev/null
+++ b/protocol/lufa/LUFA-120730/LUFA/Common/ArchitectureSpecific.h
@@ -0,0 +1,177 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ * \brief Architecture specific definitions relating to specific processor architectures.
+ *
+ * \copydetails Group_ArchitectureSpecific
+ *
+ * \note Do not include this file directly, rather include the Common.h header file instead to gain this file's
+ * functionality.
+ */
+
+/** \ingroup Group_Common
+ * \defgroup Group_ArchitectureSpecific Architecture Specific Definitions
+ * \brief Architecture specific definitions relating to specific processor architectures.
+ *
+ * Architecture specific macros, functions and other definitions, which relate to specific architectures. This
+ * definitions may or may not be available in some form on other architectures, and thus should be protected by
+ * preprocessor checks in portable code to prevent compile errors.
+ *
+ * @{
+ */
+
+#ifndef __LUFA_ARCHSPEC_H__
+#define __LUFA_ARCHSPEC_H__
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_COMMON_H)
+ #error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
+ #endif
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Macros: */
+ #if (ARCH == ARCH_AVR8) || (ARCH == ARCH_XMEGA) || defined(__DOXYGEN__)
+ #if (ARCH == ARCH_AVR8) || defined(__DOXYGEN__)
+ /** Re-enables the AVR's JTAG bus in software, until a system reset. This will re-enable JTAG debugging
+ * interface after is has been disabled in software via \ref JTAG_DISABLE().
+ *
+ * \note This macro is not available for all architectures.
+ */
+ #define JTAG_ENABLE() MACROS{ \
+ __asm__ __volatile__ ( \
+ "in __tmp_reg__,__SREG__" "\n\t" \
+ "cli" "\n\t" \
+ "out %1, %0" "\n\t" \
+ "out __SREG__, __tmp_reg__" "\n\t" \
+ "out %1, %0" "\n\t" \
+ : \
+ : "r" (MCUCR & ~(1 << JTD)), \
+ "M" (_SFR_IO_ADDR(MCUCR)) \
+ : "r0"); \
+ }MACROE
+
+ /** Disables the AVR's JTAG bus in software, until a system reset. This will override the current JTAG
+ * status as set by the JTAGEN fuse, disabling JTAG debugging and reverting the JTAG pins back to GPIO
+ * mode.
+ *
+ * \note This macro is not available for all architectures.
+ */
+ #define JTAG_DISABLE() MACROS{ \
+ __asm__ __volatile__ ( \
+ "in __tmp_reg__,__SREG__" "\n\t" \
+ "cli" "\n\t" \
+ "out %1, %0" "\n\t" \
+ "out __SREG__, __tmp_reg__" "\n\t" \
+ "out %1, %0" "\n\t" \
+ : \
+ : "r" (MCUCR | (1 << JTD)), \
+ "M" (_SFR_IO_ADDR(MCUCR)) \
+ : "r0"); \
+ }MACROE
+ #endif
+
+ /** Defines a volatile \c NOP statement which cannot be optimized out by the compiler, and thus can always
+ * be set as a breakpoint in the resulting code. Useful for debugging purposes, where the optimizer
+ * removes/reorders code to the point where break points cannot reliably be set.
+ *
+ * \note This macro is not available for all architectures.
+ */
+ #define JTAG_DEBUG_POINT() __asm__ __volatile__ ("nop" ::)
+
+ /** Defines an explicit JTAG break point in the resulting binary via the assembly \c BREAK statement. When
+ * a JTAG is used, this causes the program execution to halt when reached until manually resumed.
+ *
+ * \note This macro is not available for all architectures.
+ */
+ #define JTAG_DEBUG_BREAK() __asm__ __volatile__ ("break" ::)
+
+ /** Macro for testing condition "x" and breaking via \ref JTAG_DEBUG_BREAK() if the condition is false.
+ *
+ * \note This macro is not available for all architectures.
+ *
+ * \param[in] Condition Condition that will be evaluated.
+ */
+ #define JTAG_ASSERT(Condition) MACROS{ if (!(Condition)) { JTAG_DEBUG_BREAK(); } }MACROE
+
+ /** Macro for testing condition \c "x" and writing debug data to the stdout stream if \c false. The stdout stream
+ * must be pre-initialized before this macro is run and linked to an output device, such as the microcontroller's
+ * USART peripheral.
+ *
+ * The output takes the form "{FILENAME}: Function {FUNCTION NAME}, Line {LINE NUMBER}: Assertion {Condition} failed."
+ *
+ * \note This macro is not available for all architectures.
+ *
+ * \param[in] Condition Condition that will be evaluated,
+ */
+ #define STDOUT_ASSERT(Condition) MACROS{ if (!(x)) { \
+ printf_P(PSTR("%s: Function \"%s\", Line %d: " \
+ "Assertion \"%s\" failed.\r\n"), \
+ __FILE__, __func__, __LINE__, #Condition); } }MACROE
+
+ #if !defined(pgm_read_ptr) || defined(__DOXYGEN__)
+ /** Reads a pointer out of PROGMEM space on the AVR8 architecture. This is currently a wrapper for the
+ * avr-libc \c pgm_read_ptr() macro with a \c void* cast, so that its value can be assigned directly
+ * to a pointer variable or used in pointer arithmetic without further casting in C. In a future
+ * avr-libc distribution this will be part of the standard API and will be implemented in a more formal
+ * manner.
+ *
+ * \note This macro is not available for all architectures.
+ *
+ * \param[in] Address Address of the pointer to read.
+ *
+ * \return Pointer retrieved from PROGMEM space.
+ */
+ #define pgm_read_ptr(Address) (void*)pgm_read_word(Address)
+ #endif
+ #elif (ARCH == ARCH_UC3)
+ #define JTAG_DEBUG_POINT() __asm__ __volatile__ ("nop" ::)
+ #define JTAG_DEBUG_BREAK() __asm__ __volatile__ ("breakpoint" ::)
+ #define JTAG_ASSERT(Condition) MACROS{ if (!(Condition)) { JTAG_DEBUG_BREAK(); } }MACROE
+ #define STDOUT_ASSERT(Condition) MACROS{ if (!(x)) { \
+ printf("%s: Function \"%s\", Line %d: " \
+ "Assertion \"%s\" failed.\r\n"), \
+ __FILE__, __func__, __LINE__, #Condition); } }MACROE
+ #endif
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
+
diff --git a/protocol/lufa/LUFA-120730/LUFA/Common/Architectures.h b/protocol/lufa/LUFA-120730/LUFA/Common/Architectures.h
new file mode 100644
index 0000000000..8941f7c0c7
--- /dev/null
+++ b/protocol/lufa/LUFA-120730/LUFA/Common/Architectures.h
@@ -0,0 +1,84 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ * \brief Supported library architecture defines.
+ *
+ * \copydetails Group_Architectures
+ *
+ * \note Do not include this file directly, rather include the Common.h header file instead to gain this file's
+ * functionality.
+ */
+
+/** \ingroup Group_Common
+ * \defgroup Group_Architectures Hardware Architectures
+ * \brief Supported library architecture defines.
+ *
+ * Architecture macros for selecting the desired target microcontroller architecture. One of these values should be
+ * defined as the value of \c ARCH in the user project makefile via the \c -D compiler switch to GCC, to select the
+ * target architecture.
+ *
+ * The selected architecture should remain consistent with the makefile \c ARCH value, which is used to select the
+ * underlying driver source files for each architecture.
+ *
+ * @{
+ */
+
+#ifndef __LUFA_ARCHITECTURES_H__
+#define __LUFA_ARCHITECTURES_H__
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_COMMON_H)
+ #error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Macros: */
+ /** Selects the Atmel 8-bit AVR (AT90USB* and ATMEGA*U* chips) architecture. */
+ #define ARCH_AVR8 0
+
+ /** Selects the Atmel 32-bit UC3 AVR (AT32UC3* chips) architecture. */
+ #define ARCH_UC3 1
+
+ /** Selects the Atmel XMEGA AVR (ATXMEGA*U chips) architecture. */
+ #define ARCH_XMEGA 2
+
+ #if !defined(__DOXYGEN__)
+ #define ARCH_ ARCH_AVR8
+
+ #if !defined(ARCH)
+ #define ARCH ARCH_AVR8
+ #endif
+ #endif
+
+#endif
+
+/** @} */
+
diff --git a/protocol/lufa/LUFA-120730/LUFA/Common/Attributes.h b/protocol/lufa/LUFA-120730/LUFA/Common/Attributes.h
new file mode 100644
index 0000000000..fce75d0ed2
--- /dev/null
+++ b/protocol/lufa/LUFA-120730/LUFA/Common/Attributes.h
@@ -0,0 +1,150 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ * \brief Special function/variable attribute macros.
+ *
+ * \copydetails Group_FuncVarAttributes
+ *
+ * \note Do not include this file directly, rather include the Common.h header file instead to gain this file's
+ * functionality.
+ */
+
+/** \ingroup Group_Common
+ * \defgroup Group_FuncVarAttributes Function/Variable Attributes
+ * \brief Special function/variable attribute macros.
+ *
+ * This module contains macros for applying specific attributes to functions and variables to control various
+ * optimizer and code generation features of the compiler. Attributes may be placed in the function prototype
+ * or variable declaration in any order, and multiple attributes can be specified for a single item via a space
+ * separated list.
+ *
+ * On incompatible versions of GCC or on other compilers, these macros evaluate to nothing unless they are
+ * critical to the code's function and thus must throw a compile error when used.
+ *
+ * @{
+ */
+
+#ifndef __LUFA_ATTR_H__
+#define __LUFA_ATTR_H__
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_COMMON_H)
+ #error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Macros: */
+ #if (__GNUC__ >= 3) || defined(__DOXYGEN__)
+ /** Indicates to the compiler that the function can not ever return, so that any stack restoring or
+ * return code may be omitted by the compiler in the resulting binary.
+ */
+ #define ATTR_NO_RETURN __attribute__ ((noreturn))
+
+ /** Indicates that the function returns a value which should not be ignored by the user code. When
+ * applied, any ignored return value from calling the function will produce a compiler warning.
+ */
+ #define ATTR_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
+
+ /** Indicates that the specified parameters of the function are pointers which should never be \c NULL.
+ * When applied as a 1-based comma separated list the compiler will emit a warning if the specified
+ * parameters are known at compiler time to be \c NULL at the point of calling the function.
+ */
+ #define ATTR_NON_NULL_PTR_ARG(...) __attribute__ ((nonnull (__VA_ARGS__)))
+
+ /** Removes any preamble or postamble from the function. When used, the function will not have any
+ * register or stack saving code. This should be used with caution, and when used the programmer
+ * is responsible for maintaining stack and register integrity.
+ */
+ #define ATTR_NAKED __attribute__ ((naked))
+
+ /** Prevents the compiler from considering a specified function for in-lining. When applied, the given
+ * function will not be in-lined under any circumstances.
+ */
+ #define ATTR_NO_INLINE __attribute__ ((noinline))
+
+ /** Forces the compiler to inline the specified function. When applied, the given function will be
+ * in-lined under all circumstances.
+ */
+ #define ATTR_ALWAYS_INLINE __attribute__ ((always_inline))
+
+ /** Indicates that the specified function is pure, in that it has no side-effects other than global
+ * or parameter variable access.
+ */
+ #define ATTR_PURE __attribute__ ((pure))
+
+ /** Indicates that the specified function is constant, in that it has no side effects other than
+ * parameter access.
+ */
+ #define ATTR_CONST __attribute__ ((const))
+
+ /** Marks a given function as deprecated, which produces a warning if the function is called. */
+ #define ATTR_DEPRECATED __attribute__ ((deprecated))
+
+ /** Marks a function as a weak reference, which can be overridden by other functions with an
+ * identical name (in which case the weak reference is discarded at link time).
+ */
+ #define ATTR_WEAK __attribute__ ((weak))
+ #endif
+
+ /** Forces the compiler to not automatically zero the given global variable on startup, so that the
+ * current RAM contents is retained. Under most conditions this value will be random due to the
+ * behavior of volatile memory once power is removed, but may be used in some specific circumstances,
+ * like the passing of values back after a system watchdog reset.
+ */
+ #define ATTR_NO_INIT __attribute__ ((section (".noinit")))
+
+ /** Places the function in one of the initialization sections, which execute before the main function
+ * of the application. Refer to the avr-libc manual for more information on the initialization sections.
+ *
+ * \param[in] SectionIndex Initialization section number where the function should be placed.
+ */
+ #define ATTR_INIT_SECTION(SectionIndex) __attribute__ ((used, naked, section (".init" #SectionIndex )))
+
+ /** Marks a function as an alias for another function.
+ *
+ * \param[in] Func Name of the function which the given function name should alias.
+ */
+ #define ATTR_ALIAS(Func) __attribute__ ((alias( #Func )))
+
+ /** Marks a variable or struct element for packing into the smallest space available, omitting any
+ * alignment bytes usually added between fields to optimize field accesses.
+ */
+ #define ATTR_PACKED __attribute__ ((packed))
+
+ /** Indicates the minimum alignment in bytes for a variable or struct element.
+ *
+ * \param[in] Bytes Minimum number of bytes the item should be aligned to.
+ */
+ #define ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes)))
+#endif
+
+/** @} */
+
diff --git a/protocol/lufa/LUFA-120730/LUFA/Common/BoardTypes.h b/protocol/lufa/LUFA-120730/LUFA/Common/BoardTypes.h
new file mode 100644
index 0000000000..4c152dab29
--- /dev/null
+++ b/protocol/lufa/LUFA-120730/LUFA/Common/BoardTypes.h
@@ -0,0 +1,231 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ * \brief Supported pre-made board hardware defines.
+ *
+ * \copydetails Group_BoardTypes
+ *
+ * \note Do not include this file directly, rather include the Common.h header file instead to gain this file's
+ * functionality.
+ */
+
+/** \ingroup Group_Common
+ * \defgroup Group_BoardTypes Board Types
+ * \brief Supported pre-made board hardware defines.
+ *
+ * Board macros for indicating the chosen physical board hardware to the library. These macros should be used when
+ * defining the \c BOARD token to the chosen hardware via the \c -D switch in the project makefile. If a custom
+ * board is used, the \ref BOARD_NONE or \ref BOARD_USER values should be selected.
+ *
+ * @{
+ */
+
+#ifndef __LUFA_BOARDTYPES_H__
+#define __LUFA_BOARDTYPES_H__
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_COMMON_H)
+ #error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Macros: */
+ /** Selects the user-defined board drivers, which should be placed in the user project's folder
+ * under a directory named \c /Board/. Each board driver should be named identically to the LUFA
+ * master board driver (i.e., driver in the \c LUFA/Drivers/Board directory) so that the library
+ * can correctly identify it.
+ */
+ #define BOARD_USER 0
+
+ /** Disables board drivers when operation will not be adversely affected (e.g. LEDs) - use of board drivers
+ * such as the Joystick driver, where the removal would adversely affect the code's operation is still disallowed. */
+ #define BOARD_NONE 1
+
+ /** Selects the USBKEY specific board drivers, including Temperature, Button, Dataflash, Joystick and LED drivers. */
+ #define BOARD_USBKEY 2
+
+ /** Selects the STK525 specific board drivers, including Temperature, Button, Dataflash, Joystick and LED drivers. */
+ #define BOARD_STK525 3
+
+ /** Selects the STK526 specific board drivers, including Temperature, Button, Dataflash, Joystick and LED drivers. */
+ #define BOARD_STK526 4
+
+ /** Selects the RZUSBSTICK specific board drivers, including the driver for the boards LEDs. */
+ #define BOARD_RZUSBSTICK 5
+
+ /** Selects the ATAVRUSBRF01 specific board drivers, including the driver for the board LEDs. */
+ #define BOARD_ATAVRUSBRF01 6
+
+ /** Selects the BUMBLEB specific board drivers, using the officially recommended peripheral layout. */
+ #define BOARD_BUMBLEB 7
+
+ /** Selects the XPLAIN (Revision 2 or newer) specific board drivers, including LED and Dataflash drivers. */
+ #define BOARD_XPLAIN 8
+
+ /** Selects the XPLAIN (Revision 1) specific board drivers, including LED and Dataflash drivers. */
+ #define BOARD_XPLAIN_REV1 9
+
+ /** Selects the EVK527 specific board drivers, including Temperature, Button, Dataflash, Joystick and LED drivers. */
+ #define BOARD_EVK527 10
+
+ /** Selects the Teensy version 1.x specific board drivers, including the driver for the board LEDs. */
+ #define BOARD_TEENSY 11
+
+ /** Selects the USBTINY MKII specific board drivers, including the Button and LEDs drivers. */
+ #define BOARD_USBTINYMKII 12
+
+ /** Selects the Benito specific board drivers, including the Button and LEDs drivers. */
+ #define BOARD_BENITO 13
+
+ /** Selects the JM-DB-U2 specific board drivers, including the Button and LEDs drivers. */
+ #define BOARD_JMDBU2 14
+
+ /** Selects the Olimex AVR-USB-162 specific board drivers, including the Button and LEDs drivers. */
+ #define BOARD_OLIMEX162 15
+
+ /** Selects the UDIP specific board drivers, including the Button and LEDs drivers. */
+ #define BOARD_UDIP 16
+
+ /** Selects the BUI specific board drivers, including the driver for the board LEDs. */
+ #define BOARD_BUI 17
+
+ /** Selects the Arduino Uno specific board drivers, including the driver for the board LEDs. */
+ #define BOARD_UNO 18
+
+ /** Selects the Busware CUL V3 specific board drivers, including the Button and LEDs drivers. */
+ #define BOARD_CULV3 19
+
+ /** Selects the Blackcat USB JTAG specific board drivers, including the driver for the board LEDs. */
+ #define BOARD_BLACKCAT 20
+
+ /** Selects the Maximus specific board drivers, including the driver for the board LEDs. */
+ #define BOARD_MAXIMUS 21
+
+ /** Selects the Minimus specific board drivers, including the Button and LEDs drivers. */
+ #define BOARD_MINIMUS 22
+
+ /** Selects the Adafruit U4 specific board drivers, including the Button driver. */
+ #define BOARD_ADAFRUITU4 23
+
+ /** Selects the Microsin AVR-USB162 specific board drivers, including the Button and LEDs drivers. */
+ #define BOARD_MICROSIN162 24
+
+ /** Selects the Kernel Concepts USBFOO specific board drivers, including the Button and LEDs drivers. */
+ #define BOARD_USBFOO 25
+
+ /** Selects the Sparkfun ATMEGA8U2 specific board drivers, including the driver for the board LEDs. */
+ #define BOARD_SPARKFUN8U2 26
+
+ /** Selects the Atmel EVK1101 specific board drivers, including the Button, Joystick and LED drivers. */
+ #define BOARD_EVK1101 27
+
+ /** Selects the Busware TUL specific board drivers, including the Button and LED drivers. */
+ #define BOARD_TUL 28
+
+ /** Selects the Atmel EVK1100 specific board drivers, including the Button, Joystick and LED drivers. */
+ #define BOARD_EVK1100 29
+
+ /** Selects the Atmel EVK1104 specific board drivers, including the Button and LED drivers. */
+ #define BOARD_EVK1104 30
+
+ /** Selects the Atmel XMEGA A3BU Xplained specific board drivers, including Dataflash, Button and LED drivers. */
+ #define BOARD_A3BU_XPLAINED 31
+
+ /** Selects the Teensy version 2.x specific board drivers, including the driver for the board LEDs. */
+ #define BOARD_TEENSY2 32
+
+ /** Selects the USB2AX version 1 and 2 specific board drivers, including the Button and LEDs drivers. */
+ #define BOARD_USB2AX 33
+
+ /** Selects the USB2AX version 3 specific board drivers, including the Button and LEDs drivers. */
+ #define BOARD_USB2AX_V3 34
+
+ /** Selects the Micropendous 32U2 specific board drivers, including the Button and LED drivers. */
+ #define BOARD_MICROPENDOUS_32U2 35
+
+ /** Selects the Micropendous A specific board drivers, including the driver for the board Button. */
+ #define BOARD_MICROPENDOUS_A 36
+
+ /** Selects the Micropendous 1 specific board drivers, including the driver for the board Button. */
+ #define BOARD_MICROPENDOUS_1 37
+
+ /** Selects the Micropendous 2 specific board drivers, including the driver for the board Button. */
+ #define BOARD_MICROPENDOUS_2 38
+
+ /** Selects the Micropendous 3 specific board drivers, including the driver for the board Button. */
+ #define BOARD_MICROPENDOUS_3 39
+
+ /** Selects the Micropendous 4 specific board drivers, including the driver for the board Button. */
+ #define BOARD_MICROPENDOUS_4 40
+
+ /** Selects the Micropendous DIP specific board drivers, including the driver for the board Button. */
+ #define BOARD_MICROPENDOUS_DIP 41
+
+ /** Selects the Micropendous (Arduino-like) revision 1 specific board drivers, including the Button and LED drivers. */
+ #define BOARD_MICROPENDOUS_REV1 42
+
+ /** Selects the Micropendous (Arduino-like) revision 2 specific board drivers, including the Button and LED drivers. */
+ #define BOARD_MICROPENDOUS_REV2 43
+
+ /** Selects the XMEGA B1 Xplained specific board drivers, including the Button and LED drivers. */
+ #define BOARD_B1_XPLAINED 44
+
+ /** Selects the Bitwizard Multio specific board drivers, including the driver for the board LEDs. */
+ #define BOARD_MULTIO 45
+
+ /** Selects the Bitwizard Big-Multio specific board drivers, including the driver for the board LEDs. */
+ #define BOARD_BIGMULTIO 46
+
+ /** Selects the DorkbotPDX Duce specific board drivers, including the driver for the board LEDs. */
+ #define BOARD_DUCE 47
+
+ /** Selects the Olimex AVR-USB-32U4 specific board drivers, including the Button and LED drivers. */
+ #define BOARD_OLIMEX32U4 48
+
+ /** Selects the Olimex AVR-USB-T32U4 specific board drivers, including the Button and LED drivers. */
+ #define BOARD_OLIMEXT32U4 49
+
+ /** Selects the Olimex AVR-ISP-MK2 specific board drivers, including the Button and LED drivers. */
+ #define BOARD_OLIMEXISPMK2 50
+
+
+ #if !defined(__DOXYGEN__)
+ #define BOARD_ BOARD_NONE
+
+ #if !defined(BOARD)
+ #define BOARD BOARD_NONE
+ #endif
+ #endif
+
+#endif
+
+/** @} */
+
diff --git a/protocol/lufa/LUFA-120730/LUFA/Common/Common.h b/protocol/lufa/LUFA-120730/LUFA/Common/Common.h
new file mode 100644
index 0000000000..cf1f49b9da
--- /dev/null
+++ b/protocol/lufa/LUFA-120730/LUFA/Common/Common.h
@@ -0,0 +1,381 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \dir
+ * \brief Common library header files.
+ *
+ * This folder contains header files which are common to all parts of the LUFA library. They may be used freely in
+ * user applications.
+ */
+
+/** \file
+ * \brief Common library convenience headers, macros and functions.
+ *
+ * \copydetails Group_Common
+ */
+
+/** \defgroup Group_Common Common Utility Headers - LUFA/Drivers/Common/Common.h
+ * \brief Common library convenience headers, macros and functions.
+ *
+ * Common utility headers containing macros, functions, enums and types which are common to all
+ * aspects of the library.
+ *
+ * @{
+ */
+
+/** \defgroup Group_GlobalInt Global Interrupt Macros
+ * \brief Convenience macros for the management of interrupts globally within the device.
+ *
+ * Macros and functions to create and control global interrupts within the device.
+ */
+
+#ifndef __LUFA_COMMON_H__
+#define __LUFA_COMMON_H__
+
+ /* Macros: */
+ #define __INCLUDE_FROM_COMMON_H
+
+ /* Includes: */
+ #include <stdint.h>
+ #include <stdbool.h>
+ #include <string.h>
+ #include <stddef.h>
+
+ #include "Architectures.h"
+ #include "BoardTypes.h"
+ #include "ArchitectureSpecific.h"
+ #include "CompilerSpecific.h"
+ #include "Attributes.h"
+
+ #if defined(USE_LUFA_CONFIG_HEADER)
+ #include "LUFAConfig.h"
+ #endif
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Architecture specific utility includes: */
+ #if defined(__DOXYGEN__)
+ /** Type define for an unsigned integer the same width as the selected architecture's machine register.
+ * This is distinct from the non-specific standard int data type, whose width is machine dependant but
+ * which may not reflect the actual machine register width on some targets (e.g. AVR8).
+ */
+ typedef MACHINE_REG_t uint_reg_t;
+ #elif (ARCH == ARCH_AVR8)
+ #include <avr/io.h>
+ #include <avr/interrupt.h>
+ #include <avr/pgmspace.h>
+ #include <avr/eeprom.h>
+ #include <avr/boot.h>
+ #include <math.h>
+ #include <util/delay.h>
+
+ typedef uint8_t uint_reg_t;
+
+ #define ARCH_HAS_EEPROM_ADDRESS_SPACE
+ #define ARCH_HAS_FLASH_ADDRESS_SPACE
+ #define ARCH_HAS_MULTI_ADDRESS_SPACE
+ #define ARCH_LITTLE_ENDIAN
+
+ #include "Endianness.h"
+ #elif (ARCH == ARCH_UC3)
+ #include <avr32/io.h>
+ #include <math.h>
+
+ // === TODO: Find abstracted way to handle these ===
+ #define PROGMEM
+ #define pgm_read_byte(x) *x
+ #define memcmp_P(...) memcmp(__VA_ARGS__)
+ #define memcpy_P(...) memcpy(__VA_ARGS__)
+ // =================================================
+
+ typedef uint32_t uint_reg_t;
+
+ #define ARCH_BIG_ENDIAN
+
+ #include "Endianness.h"
+ #elif (ARCH == ARCH_XMEGA)
+ #include <avr/io.h>
+ #include <avr/interrupt.h>
+ #include <avr/pgmspace.h>
+ #include <avr/eeprom.h>
+ #include <math.h>
+ #include <util/delay.h>
+
+ typedef uint8_t uint_reg_t;
+
+ #define ARCH_HAS_EEPROM_ADDRESS_SPACE
+ #define ARCH_HAS_FLASH_ADDRESS_SPACE
+ #define ARCH_HAS_MULTI_ADDRESS_SPACE
+ #define ARCH_LITTLE_ENDIAN
+
+ #include "Endianness.h"
+ #else
+ #error Unknown device architecture specified.
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Macros: */
+ /** Macro for encasing other multi-statement macros. This should be used along with an opening brace
+ * before the start of any multi-statement macro, so that the macros contents as a whole are treated
+ * as a discrete block and not as a list of separate statements which may cause problems when used as
+ * a block (such as inline \c if statements).
+ */
+ #define MACROS do
+
+ /** Macro for encasing other multi-statement macros. This should be used along with a preceding closing
+ * brace at the end of any multi-statement macro, so that the macros contents as a whole are treated
+ * as a discrete block and not as a list of separate statements which may cause problems when used as
+ * a block (such as inline \c if statements).
+ */
+ #define MACROE while (0)
+
+ /** Convenience macro to determine the larger of two values.
+ *
+ * \attention This macro should only be used with operands that do not have side effects from being evaluated
+ * multiple times.
+ *
+ * \param[in] x First value to compare
+ * \param[in] y First value to compare
+ *
+ * \return The larger of the two input parameters
+ */
+ #if !defined(MAX) || defined(__DOXYGEN__)
+ #define MAX(x, y) (((x) > (y)) ? (x) : (y))
+ #endif
+
+ /** Convenience macro to determine the smaller of two values.
+ *
+ * \attention This macro should only be used with operands that do not have side effects from being evaluated
+ * multiple times.
+ *
+ * \param[in] x First value to compare
+ * \param[in] y First value to compare
+ *
+ * \return The smaller of the two input parameters
+ */
+ #if !defined(MIN) || defined(__DOXYGEN__)
+ #define MIN(x, y) (((x) < (y)) ? (x) : (y))
+ #endif
+
+ #if !defined(STRINGIFY) || defined(__DOXYGEN__)
+ /** Converts the given input into a string, via the C Preprocessor. This macro puts literal quotation
+ * marks around the input, converting the source into a string literal.
+ *
+ * \param[in] x Input to convert into a string literal.
+ *
+ * \return String version of the input.
+ */
+ #define STRINGIFY(x) #x
+
+ /** Converts the given input into a string after macro expansion, via the C Preprocessor. This macro puts
+ * literal quotation marks around the expanded input, converting the source into a string literal.
+ *
+ * \param[in] x Input to expand and convert into a string literal.
+ *
+ * \return String version of the expanded input.
+ */
+ #define STRINGIFY_EXPANDED(x) STRINGIFY(x)
+ #endif
+
+ #if !defined(ISR) || defined(__DOXYGEN__)
+ /** Macro for the definition of interrupt service routines, so that the compiler can insert the required
+ * prologue and epilogue code to properly manage the interrupt routine without affecting the main thread's
+ * state with unintentional side-effects.
+ *
+ * Interrupt handlers written using this macro may still need to be registered with the microcontroller's
+ * Interrupt Controller (if present) before they will properly handle incoming interrupt events.
+ *
+ * \note This macro is only supplied on some architectures, where the standard library does not include a valid
+ * definition. If an existing definition exists, the alternative definition here will be ignored.
+ *
+ * \ingroup Group_GlobalInt
+ *
+ * \param[in] Name Unique name of the interrupt service routine.
+ */
+ #define ISR(Name, ...) void Name (void) __attribute__((__interrupt__)) __VA_ARGS__; void Name (void)
+ #endif
+
+ /* Inline Functions: */
+ /** Function to reverse the individual bits in a byte - i.e. bit 7 is moved to bit 0, bit 6 to bit 1,
+ * etc.
+ *
+ * \param[in] Byte Byte of data whose bits are to be reversed.
+ *
+ * \return Input data with the individual bits reversed (mirrored).
+ */
+ static inline uint8_t BitReverse(uint8_t Byte) ATTR_WARN_UNUSED_RESULT ATTR_CONST;
+ static inline uint8_t BitReverse(uint8_t Byte)
+ {
+ Byte = (((Byte & 0xF0) >> 4) | ((Byte & 0x0F) << 4));
+ Byte = (((Byte & 0xCC) >> 2) | ((Byte & 0x33) << 2));
+ Byte = (((Byte & 0xAA) >> 1) | ((Byte & 0x55) << 1));
+
+ return Byte;
+ }
+
+ /** Function to perform a blocking delay for a specified number of milliseconds. The actual delay will be
+ * at a minimum the specified number of milliseconds, however due to loop overhead and internal calculations
+ * may be slightly higher.
+ *
+ * \param[in] Milliseconds Number of milliseconds to delay
+ */
+ static inline void Delay_MS(uint16_t Milliseconds) ATTR_ALWAYS_INLINE;
+ static inline void Delay_MS(uint16_t Milliseconds)
+ {
+ #if (ARCH == ARCH_AVR8)
+ if (GCC_IS_COMPILE_CONST(Milliseconds))
+ {
+ _delay_ms(Milliseconds);
+ }
+ else
+ {
+ while (Milliseconds--)
+ _delay_ms(1);
+ }
+ #elif (ARCH == ARCH_UC3)
+ while (Milliseconds--)
+ {
+ __builtin_mtsr(AVR32_COUNT, 0);
+ while ((uint32_t)__builtin_mfsr(AVR32_COUNT) < (F_CPU / 1000));
+ }
+ #elif (ARCH == ARCH_XMEGA)
+ if (GCC_IS_COMPILE_CONST(Milliseconds))
+ {
+ _delay_ms(Milliseconds);
+ }
+ else
+ {
+ while (Milliseconds--)
+ _delay_ms(1);
+ }
+ #endif
+ }
+
+ /** Retrieves a mask which contains the current state of the global interrupts for the device. This
+ * value can be stored before altering the global interrupt enable state, before restoring the
+ * flag(s) back to their previous values after a critical section using \ref SetGlobalInterruptMask().
+ *
+ * \ingroup Group_GlobalInt
+ *
+ * \return Mask containing the current Global Interrupt Enable Mask bit(s).
+ */
+ static inline uint_reg_t GetGlobalInterruptMask(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
+ static inline uint_reg_t GetGlobalInterruptMask(void)
+ {
+ GCC_MEMORY_BARRIER();
+
+ #if (ARCH == ARCH_AVR8)
+ return SREG;
+ #elif (ARCH == ARCH_UC3)
+ return __builtin_mfsr(AVR32_SR);
+ #elif (ARCH == ARCH_XMEGA)
+ return SREG;
+ #endif
+ }
+
+ /** Sets the global interrupt enable state of the microcontroller to the mask passed into the function.
+ * This can be combined with \ref GetGlobalInterruptMask() to save and restore the Global Interrupt Enable
+ * Mask bit(s) of the device after a critical section has completed.
+ *
+ * \ingroup Group_GlobalInt
+ *
+ * \param[in] GlobalIntState Global Interrupt Enable Mask value to use
+ */
+ static inline void SetGlobalInterruptMask(const uint_reg_t GlobalIntState) ATTR_ALWAYS_INLINE;
+ static inline void SetGlobalInterruptMask(const uint_reg_t GlobalIntState)
+ {
+ GCC_MEMORY_BARRIER();
+
+ #if (ARCH == ARCH_AVR8)
+ SREG = GlobalIntState;
+ #elif (ARCH == ARCH_UC3)
+ if (GlobalIntState & AVR32_SR_GM)
+ __builtin_ssrf(AVR32_SR_GM_OFFSET);
+ else
+ __builtin_csrf(AVR32_SR_GM_OFFSET);
+ #elif (ARCH == ARCH_XMEGA)
+ SREG = GlobalIntState;
+ #endif
+
+ GCC_MEMORY_BARRIER();
+ }
+
+ /** Enables global interrupt handling for the device, allowing interrupts to be handled.
+ *
+ * \ingroup Group_GlobalInt
+ */
+ static inline void GlobalInterruptEnable(void) ATTR_ALWAYS_INLINE;
+ static inline void GlobalInterruptEnable(void)
+ {
+ GCC_MEMORY_BARRIER();
+
+ #if (ARCH == ARCH_AVR8)
+ sei();
+ #elif (ARCH == ARCH_UC3)
+ __builtin_csrf(AVR32_SR_GM_OFFSET);
+ #elif (ARCH == ARCH_XMEGA)
+ sei();
+ #endif
+
+ GCC_MEMORY_BARRIER();
+ }
+
+ /** Disabled global interrupt handling for the device, preventing interrupts from being handled.
+ *
+ * \ingroup Group_GlobalInt
+ */
+ static inline void GlobalInterruptDisable(void) ATTR_ALWAYS_INLINE;
+ static inline void GlobalInterruptDisable(void)
+ {
+ GCC_MEMORY_BARRIER();
+
+ #if (ARCH == ARCH_AVR8)
+ cli();
+ #elif (ARCH == ARCH_UC3)
+ __builtin_ssrf(AVR32_SR_GM_OFFSET);
+ #elif (ARCH == ARCH_XMEGA)
+ cli();
+ #endif
+
+ GCC_MEMORY_BARRIER();
+ }
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
+
diff --git a/protocol/lufa/LUFA-120730/LUFA/Common/CompilerSpecific.h b/protocol/lufa/LUFA-120730/LUFA/Common/CompilerSpecific.h
new file mode 100644
index 0000000000..22afe940b3
--- /dev/null
+++ b/protocol/lufa/LUFA-120730/LUFA/Common/CompilerSpecific.h
@@ -0,0 +1,97 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ * \brief Compiler specific definitions for code optimization and correctness.
+ *
+ * \copydetails Group_CompilerSpecific
+ *
+ * \note Do not include this file directly, rather include the Common.h header file instead to gain this file's
+ * functionality.
+ */
+
+/** \ingroup Group_Common
+ * \defgroup Group_CompilerSpecific Compiler Specific Definitions
+ * \brief Compiler specific definitions for code optimization and correctness.
+ *
+ * Compiler specific definitions to expose certain compiler features which may increase the level of code optimization
+ * for a specific compiler, or correct certain issues that may be present such as memory barriers for use in conjunction
+ * with atomic variable access.
+ *
+ * Where possible, on alternative compilers, these macros will either have no effect, or default to returning a sane value
+ * so that they can be used in existing code without the need for extra compiler checks in the user application code.
+ *
+ * @{
+ */
+
+#ifndef __LUFA_COMPILERSPEC_H__
+#define __LUFA_COMPILERSPEC_H__
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_COMMON_H)
+ #error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Macros: */
+ #if defined(__GNUC__) || defined(__DOXYGEN__)
+ /** Forces GCC to use pointer indirection (via the device's pointer register pairs) when accessing the given
+ * struct pointer. In some cases GCC will emit non-optimal assembly code when accessing a structure through
+ * a pointer, resulting in a larger binary. When this macro is used on a (non \c const) structure pointer before
+ * use, it will force GCC to use pointer indirection on the elements rather than direct store and load
+ * instructions.
+ *
+ * \param[in, out] StructPtr Pointer to a structure which is to be forced into indirect access mode.
+ */
+ #define GCC_FORCE_POINTER_ACCESS(StructPtr) __asm__ __volatile__("" : "=b" (StructPtr) : "0" (StructPtr))
+
+ /** Forces GCC to create a memory barrier, ensuring that memory accesses are not reordered past the barrier point.
+ * This can be used before ordering-critical operations, to ensure that the compiler does not re-order the resulting
+ * assembly output in an unexpected manner on sections of code that are ordering-specific.
+ */
+ #define GCC_MEMORY_BARRIER() __asm__ __volatile__("" ::: "memory");
+
+ /** Determines if the specified value can be determined at compile-time to be a constant value when compiling under GCC.
+ *
+ * \param[in] x Value to check compile-time constantness of.
+ *
+ * \return Boolean true if the given value is known to be a compile time constant, false otherwise.
+ */
+ #define GCC_IS_COMPILE_CONST(x) __builtin_constant_p(x)
+ #else
+ #define GCC_FORCE_POINTER_ACCESS(StructPtr)
+ #define GCC_MEMORY_BARRIER()
+ #define GCC_IS_COMPILE_CONST(x) 0
+ #endif
+
+#endif
+
+/** @} */
+
diff --git a/protocol/lufa/LUFA-120730/LUFA/Common/Endianness.h b/protocol/lufa/LUFA-120730/LUFA/Common/Endianness.h
new file mode 100644
index 0000000000..d0812e4e3b
--- /dev/null
+++ b/protocol/lufa/LUFA-120730/LUFA/Common/Endianness.h
@@ -0,0 +1,489 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ * \brief Endianness and Byte Ordering macros and functions.
+ *
+ * \copydetails Group_Endianness
+ */
+
+/** \ingroup Group_Endianness
+ * \defgroup Group_ByteSwapping Byte Reordering
+ * \brief Macros and functions for forced byte reordering.
+ */
+
+/** \ingroup Group_Endianness
+ * \defgroup Group_EndianConversion Endianness Conversion
+ * \brief Macros and functions for automatic endianness conversion.
+ */
+
+/** \ingroup Group_Common
+ * \defgroup Group_Endianness Endianness and Byte Ordering
+ * \brief Convenience macros and functions relating to byte (re-)ordering
+ *
+ * Common library convenience macros and functions relating to byte (re-)ordering.
+ *
+ * @{
+ */
+
+#ifndef __LUFA_ENDIANNESS_H__
+#define __LUFA_ENDIANNESS_H__
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_COMMON_H)
+ #error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
+ #endif
+
+ #if !(defined(ARCH_BIG_ENDIAN) || defined(ARCH_LITTLE_ENDIAN))
+ #error ARCH_BIG_ENDIAN or ARCH_LITTLE_ENDIAN not set for the specified architecture.
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Macros: */
+ /** Swaps the byte ordering of a 16-bit value at compile-time. Do not use this macro for swapping byte orderings
+ * of dynamic values computed at runtime, use \ref SwapEndian_16() instead. The result of this macro can be used
+ * inside struct or other variable initializers outside of a function, something that is not possible with the
+ * inline function variant.
+ *
+ * \ingroup Group_ByteSwapping
+ *
+ * \param[in] x 16-bit value whose byte ordering is to be swapped.
+ *
+ * \return Input value with the byte ordering reversed.
+ */
+ #define SWAPENDIAN_16(x) (uint16_t)((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
+
+ /** Swaps the byte ordering of a 32-bit value at compile-time. Do not use this macro for swapping byte orderings
+ * of dynamic values computed at runtime- use \ref SwapEndian_32() instead. The result of this macro can be used
+ * inside struct or other variable initializers outside of a function, something that is not possible with the
+ * inline function variant.
+ *
+ * \ingroup Group_ByteSwapping
+ *
+ * \param[in] x 32-bit value whose byte ordering is to be swapped.
+ *
+ * \return Input value with the byte ordering reversed.
+ */
+ #define SWAPENDIAN_32(x) (uint32_t)((((x) & 0xFF000000UL) >> 24UL) | (((x) & 0x00FF0000UL) >> 8UL) | \
+ (((x) & 0x0000FF00UL) << 8UL) | (((x) & 0x000000FFUL) << 24UL))
+
+ #if defined(ARCH_BIG_ENDIAN) && !defined(le16_to_cpu)
+ #define le16_to_cpu(x) SwapEndian_16(x)
+ #define le32_to_cpu(x) SwapEndian_32(x)
+ #define be16_to_cpu(x) (x)
+ #define be32_to_cpu(x) (x)
+ #define cpu_to_le16(x) SwapEndian_16(x)
+ #define cpu_to_le32(x) SwapEndian_32(x)
+ #define cpu_to_be16(x) (x)
+ #define cpu_to_be32(x) (x)
+ #define LE16_TO_CPU(x) SWAPENDIAN_16(x)
+ #define LE32_TO_CPU(x) SWAPENDIAN_32(x)
+ #define BE16_TO_CPU(x) (x)
+ #define BE32_TO_CPU(x) (x)
+ #define CPU_TO_LE16(x) SWAPENDIAN_16(x)
+ #define CPU_TO_LE32(x) SWAPENDIAN_32(x)
+ #define CPU_TO_BE16(x) (x)
+ #define CPU_TO_BE32(x) (x)
+ #elif !defined(le16_to_cpu)
+ /** \name Run-time endianness conversion */
+ //@{
+
+ /** Performs a conversion between a Little Endian encoded 16-bit piece of data and the
+ * Endianness of the currently selected CPU architecture.
+ *
+ * On little endian architectures, this macro does nothing.
+ *
+ * \note This macro is designed for run-time conversion of data - for compile-time endianness
+ * conversion, use \ref LE16_TO_CPU instead.
+ *
+ * \ingroup Group_EndianConversion
+ *
+ * \param[in] x Data to perform the endianness conversion on.
+ *
+ * \return Endian corrected version of the input value.
+ */
+ #define le16_to_cpu(x) (x)
+
+ /** Performs a conversion between a Little Endian encoded 32-bit piece of data and the
+ * Endianness of the currently selected CPU architecture.
+ *
+ * On little endian architectures, this macro does nothing.
+ *
+ * \note This macro is designed for run-time conversion of data - for compile-time endianness
+ * conversion, use \ref LE32_TO_CPU instead.
+ *
+ * \ingroup Group_EndianConversion
+ *
+ * \param[in] x Data to perform the endianness conversion on.
+ *
+ * \return Endian corrected version of the input value.
+ */
+ #define le32_to_cpu(x) (x)
+
+ /** Performs a conversion between a Big Endian encoded 16-bit piece of data and the
+ * Endianness of the currently selected CPU architecture.
+ *
+ * On big endian architectures, this macro does nothing.
+ *
+ * \note This macro is designed for run-time conversion of data - for compile-time endianness
+ * conversion, use \ref BE16_TO_CPU instead.
+ *
+ * \ingroup Group_EndianConversion
+ *
+ * \param[in] x Data to perform the endianness conversion on.
+ *
+ * \return Endian corrected version of the input value.
+ */
+ #define be16_to_cpu(x) SwapEndian_16(x)
+
+ /** Performs a conversion between a Big Endian encoded 32-bit piece of data and the
+ * Endianness of the currently selected CPU architecture.
+ *
+ * On big endian architectures, this macro does nothing.
+ *
+ * \note This macro is designed for run-time conversion of data - for compile-time endianness
+ * conversion, use \ref BE32_TO_CPU instead.
+ *
+ * \ingroup Group_EndianConversion
+ *
+ * \param[in] x Data to perform the endianness conversion on.
+ *
+ * \return Endian corrected version of the input value.
+ */
+ #define be32_to_cpu(x) SwapEndian_32(x)
+
+ /** Performs a conversion on a natively encoded 16-bit piece of data to ensure that it
+ * is in Little Endian format regardless of the currently selected CPU architecture.
+ *
+ * On little endian architectures, this macro does nothing.
+ *
+ * \note This macro is designed for run-time conversion of data - for compile-time endianness
+ * conversion, use \ref CPU_TO_LE16 instead.
+ *
+ * \ingroup Group_EndianConversion
+ *
+ * \param[in] x Data to perform the endianness conversion on.
+ *
+ * \return Endian corrected version of the input value.
+ */
+ #define cpu_to_le16(x) (x)
+
+ /** Performs a conversion on a natively encoded 32-bit piece of data to ensure that it
+ * is in Little Endian format regardless of the currently selected CPU architecture.
+ *
+ * On little endian architectures, this macro does nothing.
+ *
+ * \note This macro is designed for run-time conversion of data - for compile-time endianness
+ * conversion, use \ref CPU_TO_LE32 instead.
+ *
+ * \ingroup Group_EndianConversion
+ *
+ * \param[in] x Data to perform the endianness conversion on.
+ *
+ * \return Endian corrected version of the input value.
+ */
+ #define cpu_to_le32(x) (x)
+
+ /** Performs a conversion on a natively encoded 16-bit piece of data to ensure that it
+ * is in Big Endian format regardless of the currently selected CPU architecture.
+ *
+ * On big endian architectures, this macro does nothing.
+ *
+ * \note This macro is designed for run-time conversion of data - for compile-time endianness
+ * conversion, use \ref CPU_TO_BE16 instead.
+ *
+ * \ingroup Group_EndianConversion
+ *
+ * \param[in] x Data to perform the endianness conversion on.
+ *
+ * \return Endian corrected version of the input value.
+ */
+ #define cpu_to_be16(x) SwapEndian_16(x)
+
+ /** Performs a conversion on a natively encoded 32-bit piece of data to ensure that it
+ * is in Big Endian format regardless of the currently selected CPU architecture.
+ *
+ * On big endian architectures, this macro does nothing.
+ *
+ * \note This macro is designed for run-time conversion of data - for compile-time endianness
+ * conversion, use \ref CPU_TO_BE32 instead.
+ *
+ * \ingroup Group_EndianConversion
+ *
+ * \param[in] x Data to perform the endianness conversion on.
+ *
+ * \return Endian corrected version of the input value.
+ */
+ #define cpu_to_be32(x) SwapEndian_32(x)
+
+ //@}
+
+ /** \name Compile-time endianness conversion */
+ //@{
+
+ /** Performs a conversion between a Little Endian encoded 16-bit piece of data and the
+ * Endianness of the currently selected CPU architecture.
+ *
+ * On little endian architectures, this macro does nothing.
+ *
+ * \note This macro is designed for compile-time conversion of data - for run time endianness
+ * conversion, use \ref le16_to_cpu instead.
+ *
+ * \ingroup Group_EndianConversion
+ *
+ * \param[in] x Data to perform the endianness conversion on.
+ *
+ * \return Endian corrected version of the input value.
+ */
+ #define LE16_TO_CPU(x) (x)
+
+ /** Performs a conversion between a Little Endian encoded 32-bit piece of data and the
+ * Endianness of the currently selected CPU architecture.
+ *
+ * On little endian architectures, this macro does nothing.
+ *
+ * \note This macro is designed for compile-time conversion of data - for run time endianness
+ * conversion, use \ref le32_to_cpu instead.
+ *
+ * \ingroup Group_EndianConversion
+ *
+ * \param[in] x Data to perform the endianness conversion on.
+ *
+ * \return Endian corrected version of the input value.
+ */
+ #define LE32_TO_CPU(x) (x)
+
+ /** Performs a conversion between a Big Endian encoded 16-bit piece of data and the
+ * Endianness of the currently selected CPU architecture.
+ *
+ * On big endian architectures, this macro does nothing.
+ *
+ * \note This macro is designed for compile-time conversion of data - for run-time endianness
+ * conversion, use \ref be16_to_cpu instead.
+ *
+ * \ingroup Group_EndianConversion
+ *
+ * \param[in] x Data to perform the endianness conversion on.
+ *
+ * \return Endian corrected version of the input value.
+ */
+ #define BE16_TO_CPU(x) SWAPENDIAN_16(x)
+
+ /** Performs a conversion between a Big Endian encoded 32-bit piece of data and the
+ * Endianness of the currently selected CPU architecture.
+ *
+ * On big endian architectures, this macro does nothing.
+ *
+ * \note This macro is designed for compile-time conversion of data - for run-time endianness
+ * conversion, use \ref be32_to_cpu instead.
+ *
+ * \ingroup Group_EndianConversion
+ *
+ * \param[in] x Data to perform the endianness conversion on.
+ *
+ * \return Endian corrected version of the input value.
+ */
+ #define BE32_TO_CPU(x) SWAPENDIAN_32(x)
+
+ /** Performs a conversion on a natively encoded 16-bit piece of data to ensure that it
+ * is in Little Endian format regardless of the currently selected CPU architecture.
+ *
+ * On little endian architectures, this macro does nothing.
+ *
+ * \note This macro is designed for compile-time conversion of data - for run-time endianness
+ * conversion, use \ref cpu_to_le16 instead.
+ *
+ * \ingroup Group_EndianConversion
+ *
+ * \param[in] x Data to perform the endianness conversion on.
+ *
+ * \return Endian corrected version of the input value.
+ */
+ #define CPU_TO_LE16(x) (x)
+
+ /** Performs a conversion on a natively encoded 32-bit piece of data to ensure that it
+ * is in Little Endian format regardless of the currently selected CPU architecture.
+ *
+ * On little endian architectures, this macro does nothing.
+ *
+ * \note This macro is designed for compile-time conversion of data - for run-time endianness
+ * conversion, use \ref cpu_to_le32 instead.
+ *
+ * \ingroup Group_EndianConversion
+ *
+ * \param[in] x Data to perform the endianness conversion on.
+ *
+ * \return Endian corrected version of the input value.
+ */
+ #define CPU_TO_LE32(x) (x)
+
+ /** Performs a conversion on a natively encoded 16-bit piece of data to ensure that it
+ * is in Big Endian format regardless of the currently selected CPU architecture.
+ *
+ * On big endian architectures, this macro does nothing.
+ *
+ * \note This macro is designed for compile-time conversion of data - for run-time endianness
+ * conversion, use \ref cpu_to_be16 instead.
+ *
+ * \ingroup Group_EndianConversion
+ *
+ * \param[in] x Data to perform the endianness conversion on.
+ *
+ * \return Endian corrected version of the input value.
+ */
+ #define CPU_TO_BE16(x) SWAPENDIAN_16(x)
+
+ /** Performs a conversion on a natively encoded 32-bit piece of data to ensure that it
+ * is in Big Endian format regardless of the currently selected CPU architecture.
+ *
+ * On big endian architectures, this macro does nothing.
+ *
+ * \note This macro is designed for compile-time conversion of data - for run-time endianness
+ * conversion, use \ref cpu_to_be32 instead.
+ *
+ * \ingroup Group_EndianConversion
+ *
+ * \param[in] x Data to perform the endianness conversion on.
+ *
+ * \return Endian corrected version of the input value.
+ */
+ #define CPU_TO_BE32(x) SWAPENDIAN_32(x)
+
+ //! @}
+ #endif
+
+ /* Inline Functions: */
+ /** Function to reverse the byte ordering of the individual bytes in a 16 bit value.
+ *
+ * \ingroup Group_ByteSwapping
+ *
+ * \param[in] Word Word of data whose bytes are to be swapped.
+ *
+ * \return Input data with the individual bytes reversed.
+ */
+ static inline uint16_t SwapEndian_16(const uint16_t Word) ATTR_WARN_UNUSED_RESULT ATTR_CONST;
+ static inline uint16_t SwapEndian_16(const uint16_t Word)
+ {
+ if (GCC_IS_COMPILE_CONST(Word))
+ return SWAPENDIAN_16(Word);
+
+ uint8_t Temp;
+
+ union
+ {
+ uint16_t Word;
+ uint8_t Bytes[2];
+ } Data;
+
+ Data.Word = Word;
+
+ Temp = Data.Bytes[0];
+ Data.Bytes[0] = Data.Bytes[1];
+ Data.Bytes[1] = Temp;
+
+ return Data.Word;
+ }
+
+ /** Function to reverse the byte ordering of the individual bytes in a 32 bit value.
+ *
+ * \ingroup Group_ByteSwapping
+ *
+ * \param[in] DWord Double word of data whose bytes are to be swapped.
+ *
+ * \return Input data with the individual bytes reversed.
+ */
+ static inline uint32_t SwapEndian_32(const uint32_t DWord) ATTR_WARN_UNUSED_RESULT ATTR_CONST;
+ static inline uint32_t SwapEndian_32(const uint32_t DWord)
+ {
+ if (GCC_IS_COMPILE_CONST(DWord))
+ return SWAPENDIAN_32(DWord);
+
+ uint8_t Temp;
+
+ union
+ {
+ uint32_t DWord;
+ uint8_t Bytes[4];
+ } Data;
+
+ Data.DWord = DWord;
+
+ Temp = Data.Bytes[0];
+ Data.Bytes[0] = Data.Bytes[3];
+ Data.Bytes[3] = Temp;
+
+ Temp = Data.Bytes[1];
+ Data.Bytes[1] = Data.Bytes[2];
+ Data.Bytes[2] = Temp;
+
+ return Data.DWord;
+ }
+
+ /** Function to reverse the byte ordering of the individual bytes in a n byte value.
+ *
+ * \ingroup Group_ByteSwapping
+ *
+ * \param[in,out] Data Pointer to a number containing an even number of bytes to be reversed.
+ * \param[in] Length Length of the data in bytes.
+ *
+ * \return Input data with the individual bytes reversed.
+ */
+ static inline void SwapEndian_n(void* const Data,
+ uint8_t Length) ATTR_NON_NULL_PTR_ARG(1);
+ static inline void SwapEndian_n(void* const Data,
+ uint8_t Length)
+ {
+ uint8_t* CurrDataPos = (uint8_t*)Data;
+
+ while (Length > 1)
+ {
+ uint8_t Temp = *CurrDataPos;
+ *CurrDataPos = *(CurrDataPos + Length - 1);
+ *(CurrDataPos + Length - 1) = Temp;
+
+ CurrDataPos++;
+ Length -= 2;
+ }
+ }
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
+