Update Mouse demo to support the UC3 devices in the MultiArchDemos branch.
authorDean Camera <dean@fourwalledcubicle.com>
Mon, 20 Jun 2011 14:46:09 +0000 (14:46 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Mon, 20 Jun 2011 14:46:09 +0000 (14:46 +0000)
Demos/Device/ClassDriver/Mouse/Descriptors.c
Demos/Device/ClassDriver/Mouse/Descriptors.h
Demos/Device/ClassDriver/Mouse/Mouse.c
Demos/Device/ClassDriver/Mouse/Mouse.h
Demos/Device/ClassDriver/Mouse/makefile.uc3 [new file with mode: 0644]

index b3c9e38..4c5e6cf 100644 (file)
@@ -72,13 +72,13 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
 
        .Endpoint0Size          = FIXED_CONTROL_ENDPOINT_SIZE,
 
-       .VendorID               = 0x03EB,
-       .ProductID              = 0x2041,
-       .ReleaseNumber          = VERSION_BCD(00.01),
+       .VendorID               = CPU_TO_LE16(0x03EB),
+       .ProductID              = CPU_TO_LE16(0x2041),
+       .ReleaseNumber          = VERSION_BCD(00.02),
 
        .ManufacturerStrIndex   = 0x01,
        .ProductStrIndex        = 0x02,
-       .SerialNumStrIndex      = NO_DESCRIPTOR,
+       .SerialNumStrIndex      = USE_INTERNAL_SERIAL,
 
        .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
 };
@@ -94,7 +94,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
                {
                        .Header                 = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
 
-                       .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
+                       .TotalConfigurationSize = CPU_TO_LE16(sizeof(USB_Descriptor_Configuration_t)),
                        .TotalInterfaces        = 1,
 
                        .ConfigurationNumber    = 1,
@@ -129,7 +129,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
                        .CountryCode            = 0x00,
                        .TotalReportDescriptors = 1,
                        .HIDReportType          = HID_DTYPE_Report,
-                       .HIDReportLength        = sizeof(MouseReport)
+                       .HIDReportLength        = CPU_TO_LE16(sizeof(MouseReport))
                },
 
        .HID_ReportINEndpoint =
@@ -138,7 +138,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
 
                        .EndpointAddress        = (ENDPOINT_DESCRIPTOR_DIR_IN | MOUSE_EPNUM),
                        .Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
-                       .EndpointSize           = MOUSE_EPSIZE,
+                       .EndpointSize           = CPU_TO_LE16(MOUSE_EPSIZE),
                        .PollingIntervalMS      = 0x01
                }
 };
@@ -162,7 +162,17 @@ const USB_Descriptor_String_t PROGMEM ManufacturerString =
 {
        .Header                 = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},
 
-       .UnicodeString          = L"Dean Camera"
+       .UnicodeString          = {CPU_TO_LE16('D'),
+                                  CPU_TO_LE16('e'),
+                                  CPU_TO_LE16('a'),
+                                  CPU_TO_LE16('n'),
+                                  CPU_TO_LE16(' '),
+                                  CPU_TO_LE16('C'),
+                                  CPU_TO_LE16('a'),
+                                  CPU_TO_LE16('m'),
+                                  CPU_TO_LE16('e'),
+                                  CPU_TO_LE16('r'),
+                                  CPU_TO_LE16('a')}
 };
 
 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
@@ -173,7 +183,21 @@ const USB_Descriptor_String_t PROGMEM ProductString =
 {
        .Header                 = {.Size = USB_STRING_LEN(15), .Type = DTYPE_String},
 
-       .UnicodeString          = L"LUFA Mouse Demo"
+       .UnicodeString          = {CPU_TO_LE16('L'),
+                                  CPU_TO_LE16('U'),
+                                  CPU_TO_LE16('F'),
+                                  CPU_TO_LE16('A'),
+                                  CPU_TO_LE16(' '),
+                                  CPU_TO_LE16('M'),
+                                  CPU_TO_LE16('o'),
+                                  CPU_TO_LE16('u'),
+                                  CPU_TO_LE16('s'),
+                                  CPU_TO_LE16('e'),
+                                  CPU_TO_LE16(' '),
+                                  CPU_TO_LE16('D'),
+                                  CPU_TO_LE16('e'),
+                                  CPU_TO_LE16('m'),
+                                  CPU_TO_LE16('o')}
 };
 
 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
@@ -207,15 +231,15 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
                        {
                                case 0x00:
                                        Address = &LanguageString;
-                                       Size    = pgm_read_byte(&LanguageString.Header.Size);
+                                       Size    = LanguageString.Header.Size;
                                        break;
                                case 0x01:
                                        Address = &ManufacturerString;
-                                       Size    = pgm_read_byte(&ManufacturerString.Header.Size);
+                                       Size    = ManufacturerString.Header.Size;
                                        break;
                                case 0x02:
                                        Address = &ProductString;
-                                       Size    = pgm_read_byte(&ProductString.Header.Size);
+                                       Size    = ProductString.Header.Size;
                                        break;
                        }
 
index 8ea34e0..e875462 100644 (file)
 #define _DESCRIPTORS_H_
 
        /* Includes: */
+               #include <LUFA/Common/Common.h>
                #include <LUFA/Drivers/USB/USB.h>
 
-               #include <avr/pgmspace.h>
-
+               #if (ARCH == ARCH_AVR8)
+                       #include <avr/pgmspace.h>
+               #endif
+               
        /* Type Defines: */
                /** Type define for the device configuration descriptor structure. This must be defined in the
                 *  application code, as the configuration descriptor contains several sub-descriptors which
@@ -52,7 +55,7 @@
                        USB_Descriptor_Interface_t            HID_Interface;
                        USB_HID_Descriptor_HID_t              HID_MouseHID;
                USB_Descriptor_Endpoint_t             HID_ReportINEndpoint;
-               } USB_Descriptor_Configuration_t;
+               } ATTR_PACKED USB_Descriptor_Configuration_t;
 
        /* Macros: */
                /** Endpoint number of the Mouse HID reporting IN endpoint. */
index 070b481..f972644 100644 (file)
@@ -67,7 +67,7 @@ int main(void)
        SetupHardware();
 
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
-       sei();
+       GlobalInterruptEnable();
 
        for (;;)
        {
@@ -79,13 +79,35 @@ int main(void)
 /** Configures the board hardware and chip peripherals for the demo's functionality. */
 void SetupHardware(void)
 {
-       /* Disable watchdog if enabled by bootloader/fuses */
-       MCUSR &= ~(1 << WDRF);
-       wdt_disable();
-
-       /* Disable clock division */
-       clock_prescale_set(clock_div_1);
-
+       #if (ARCH == ARCH_AVR8)
+               /* Disable watchdog if enabled by bootloader/fuses */
+               MCUSR &= ~(1 << WDRF);
+               wdt_disable();
+
+               /* Disable clock division */
+               clock_prescale_set(clock_div_1);
+       #elif (ARCH == ARCH_UC3)
+               /* Initialize interrupt subsystem */
+               INTC_Init();
+               INTC_RegisterGroupHandler(AVR32_USBB_IRQ, AVR32_INTC_INT0, USB_GEN_vect);
+
+               /* Select slow startup, external high frequency crystal attached to OSC0 */
+               AVR32_PM.OSCCTRL0.startup = 6;
+               AVR32_PM.OSCCTRL0.mode    = 7;
+               AVR32_PM.MCCTRL.osc0en    = true;
+               while (!(AVR32_PM.POSCSR.osc0rdy));
+
+               /* Switch CPU core to use OSC0 as the system clock */
+               AVR32_PM.MCCTRL.mcsel     = 1;
+
+               /* Start PLL1 to feed into the USB generic clock module */
+               AVR32_PM.PLL[1].pllmul    = (F_USB / F_CPU) ? (((F_USB / F_CPU) - 1) / 2) : 0;
+               AVR32_PM.PLL[1].plldiv    = 0;
+               AVR32_PM.PLL[1].pllosc    = 0;  
+               AVR32_PM.PLL[1].pllen     = true;
+               while (!(AVR32_PM.POSCSR.lock1));       
+       #endif
+       
        /* Hardware Initialization */
        Joystick_Init();
        LEDs_Init();
@@ -147,8 +169,8 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
 {
        USB_MouseReport_Data_t* MouseReport = (USB_MouseReport_Data_t*)ReportData;
 
-       uint8_t JoyStatus_LCL    = Joystick_GetStatus();
-       uint8_t ButtonStatus_LCL = Buttons_GetStatus();
+       uint_reg_t JoyStatus_LCL    = Joystick_GetStatus();
+       uint_reg_t ButtonStatus_LCL = Buttons_GetStatus();
 
        if (JoyStatus_LCL & JOY_UP)
          MouseReport->Y = -1;
index c85932a..6e18275 100644 (file)
 #define _MOUSE_H_
 
        /* Includes: */
-               #include <avr/io.h>
-               #include <avr/wdt.h>
-               #include <avr/interrupt.h>
-               #include <avr/power.h>
-               #include <avr/interrupt.h>
-               #include <stdbool.h>
-               #include <string.h>
-
-               #include "Descriptors.h"
-
-               #include <LUFA/Version.h>
+               #include <LUFA/Common/Common.h>
                #include <LUFA/Drivers/Board/Joystick.h>
                #include <LUFA/Drivers/Board/LEDs.h>
                #include <LUFA/Drivers/Board/Buttons.h>
                #include <LUFA/Drivers/USB/USB.h>
 
+               #if (ARCH == ARCH_AVR8)
+                       #include <avr/io.h>
+                       #include <avr/wdt.h>
+                       #include <avr/interrupt.h>
+                       #include <avr/power.h>
+                       #include <avr/interrupt.h>
+                       #include <stdbool.h>
+                       #include <string.h>
+               #elif (ARCH == ARCH_UC3)
+                       #include <LUFA/Platform/UC3/INTC.h>
+
+                       #include <avr32/io.h>                   
+               #endif
+
+               #include "Descriptors.h"
+
        /* Macros: */
                /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
                #define LEDMASK_USB_NOTREADY      LEDS_LED1
diff --git a/Demos/Device/ClassDriver/Mouse/makefile.uc3 b/Demos/Device/ClassDriver/Mouse/makefile.uc3
new file mode 100644 (file)
index 0000000..fc9438e
--- /dev/null
@@ -0,0 +1,493 @@
+# Hey Emacs, this is a -*- makefile -*-\r
+#----------------------------------------------------------------------------\r
+# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.\r
+#  >> Modified for use with the LUFA project. <<\r
+#\r
+# Released to the Public Domain\r
+#\r
+# Additional material for this makefile was written by:\r
+# Peter Fleury\r
+# Tim Henigan\r
+# Colin O'Flynn\r
+# Reiner Patommel\r
+# Markus Pfaff\r
+# Sander Pool\r
+# Frederik Rouleau\r
+# Carlos Lamas\r
+# Dean Camera\r
+# Opendous Inc.\r
+# Denver Gingerich\r
+#\r
+#----------------------------------------------------------------------------\r
+# On command line:\r
+#\r
+# make all = Make software.\r
+#\r
+# make clean = Clean out built project files.\r
+#\r
+# make dfu = Download the hex file to the device, using dfu-programmer (must\r
+#            have dfu-programmer installed).\r
+#\r
+# make flip = Download the hex file to the device, using Atmel FLIP (must\r
+#             have Atmel FLIP installed).\r
+#\r
+# make doxygen = Generate DoxyGen documentation for the project (must have\r
+#                DoxyGen installed)\r
+#\r
+# make filename.s = Just compile filename.c into the assembler code only.\r
+#\r
+# make filename.i = Create a preprocessed source file for use in submitting\r
+#                   bug reports to the GCC project.\r
+#\r
+# To rebuild project do "make clean" then "make all".\r
+#----------------------------------------------------------------------------\r
+\r
+\r
+# MCU name\r
+MCU = uc3b0256\r
+\r
+\r
+# Target board (see library "Board Types" documentation, NONE for projects not requiring\r
+# LUFA board drivers). If USER is selected, put custom board drivers in a directory called\r
+# "Board" inside the application directory.\r
+BOARD = EVK1101\r
+\r
+\r
+# Targeted chip architecture (see library "Architectures" documentation)\r
+ARCH = UC3\r
+\r
+\r
+# Processor frequency.\r
+#     This will define a symbol, F_CPU, in all source code files equal to the\r
+#     processor frequency in Hz. You can then use this symbol in your source code to\r
+#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done\r
+#     automatically to create a 32-bit value in your source code.\r
+#\r
+#     This will be an integer division of F_USB below, as it is sourced by\r
+#     F_USB after it has run through any CPU prescalers. Note that this value\r
+#     does not *change* the processor frequency - it should merely be updated to\r
+#     reflect the processor speed set externally so that the code can use accurate\r
+#     software delays.\r
+F_CPU = 12000000\r
+\r
+\r
+# Input clock frequency.\r
+#     This will define a symbol, F_USB, in all source code files equal to the\r
+#     input clock frequency (before any prescaling is performed) in Hz. This value may\r
+#     differ from F_CPU if prescaling is used on the latter, and is required as the\r
+#     raw input clock is fed directly to the PLL sections of the AVR for high speed\r
+#     clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'\r
+#     at the end, this will be done automatically to create a 32-bit value in your\r
+#     source code.\r
+#\r
+#     If no clock division is performed on the input clock inside the AVR (via the\r
+#     CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.\r
+F_USB = 48000000\r
+\r
+\r
+# Output format. (can be srec, ihex, binary)\r
+FORMAT = ihex\r
+\r
+\r
+# Target file name (without extension).\r
+TARGET = Mouse\r
+\r
+\r
+# Object files directory\r
+#     To put object files in current directory, use a dot (.), do NOT make\r
+#     this an empty or blank macro!\r
+OBJDIR = .\r
+\r
+\r
+# Path to the LUFA library\r
+LUFA_PATH = ../../../../\r
+\r
+\r
+# LUFA library compile-time options and predefined tokens\r
+LUFA_OPTS  = -D USB_DEVICE_ONLY\r
+LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=32\r
+LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1\r
+LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_GCLK_SRC_PLL | USB_OPT_GCLK_CHANNEL_1)"\r
+\r
+\r
+# Create the LUFA source path variables by including the LUFA root makefile\r
+include $(LUFA_PATH)/LUFA/makefile\r
+\r
+\r
+# List C source files here. (C dependencies are automatically generated.)\r
+SRC = $(TARGET).c                                                 \\r
+         Descriptors.c                                               \\r
+         $(LUFA_PATH)/LUFA/Platform/UC3/INTC.c                       \\r
+         $(LUFA_SRC_USB)                                             \\r
+         $(LUFA_SRC_USBCLASS)\r
+\r
+\r
+# List C++ source files here. (C dependencies are automatically generated.)\r
+CPPSRC =\r
+\r
+\r
+# List Assembler source files here.\r
+#     Make them always end in a capital .S.  Files ending in a lowercase .s\r
+#     will not be considered source files but generated files (assembler\r
+#     output from the compiler), and will be deleted upon "make clean"!\r
+#     Even though the DOS/Win* filesystem matches both .s and .S the same,\r
+#     it will preserve the spelling of the filenames, and gcc itself does\r
+#     care about how the name is spelled on its command-line.\r
+ASRC = $(LUFA_PATH)/LUFA/Platform/UC3/Exception.S\r
+\r
+\r
+# Optimization level, can be [0, 1, 2, 3, s].\r
+#     0 = turn off optimization. s = optimize for size.\r
+#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)\r
+OPT = 0\r
+\r
+\r
+# Debugging level.\r
+DEBUG = 3\r
+\r
+\r
+# List any extra directories to look for include files here.\r
+#     Each directory must be seperated by a space.\r
+#     Use forward slashes for directory separators.\r
+#     For a directory that has spaces, enclose it in quotes.\r
+EXTRAINCDIRS = $(LUFA_PATH)/\r
+\r
+\r
+# Compiler flag to set the C Standard level.\r
+#     c89   = "ANSI" C\r
+#     gnu89 = c89 plus GCC extensions\r
+#     c99   = ISO C99 standard (not yet fully implemented)\r
+#     gnu99 = c99 plus GCC extensions\r
+CSTANDARD = -std=gnu99\r
+\r
+\r
+# Place -D or -U options here for C sources\r
+CDEFS  = -DF_CPU=$(F_CPU)UL\r
+CDEFS += -DF_USB=$(F_USB)UL\r
+CDEFS += -DBOARD=BOARD_$(BOARD)\r
+CDEFS += -DARCH=ARCH_$(ARCH)\r
+CDEFS += $(LUFA_OPTS)\r
+\r
+\r
+# Place -D or -U options here for ASM sources\r
+ADEFS  = -DF_CPU=$(F_CPU)\r
+ADEFS += -DF_USB=$(F_USB)UL\r
+ADEFS += -DBOARD=BOARD_$(BOARD)\r
+ADEFS += -DARCH=ARCH_$(ARCH)\r
+ADEFS += $(LUFA_OPTS)\r
+\r
+# Place -D or -U options here for C++ sources\r
+CPPDEFS  = -DF_CPU=$(F_CPU)UL\r
+CPPDEFS += -DF_USB=$(F_USB)UL\r
+CPPDEFS += -DBOARD=BOARD_$(BOARD)\r
+CPPDEFS += -DARCH=ARCH_$(ARCH)\r
+CPPDEFS += $(LUFA_OPTS)\r
+#CPPDEFS += -D__STDC_LIMIT_MACROS\r
+#CPPDEFS += -D__STDC_CONSTANT_MACROS\r
+\r
+\r
+\r
+#---------------- Compiler Options C ----------------\r
+#  -g*:          generate debugging information\r
+#  -O*:          optimization level\r
+#  -f...:        tuning, see GCC manual and avr-libc documentation\r
+#  -Wall...:     warning level\r
+#  -Wa,...:      tell GCC to pass this to the assembler.\r
+#    -adhlns...: create assembler listing\r
+CFLAGS = -g$(DEBUG)\r
+CFLAGS += $(CDEFS)\r
+CFLAGS += -O$(OPT)\r
+CFLAGS += -funsigned-char\r
+CFLAGS += -funsigned-bitfields\r
+CFLAGS += -ffunction-sections\r
+CFLAGS += -fno-strict-aliasing\r
+CFLAGS += -masm-addr-pseudos\r
+CFLAGS += -Wall\r
+CFLAGS += -Wstrict-prototypes\r
+CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)\r
+CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))\r
+CFLAGS += $(CSTANDARD)\r
+\r
+\r
+#---------------- Compiler Options C++ ----------------\r
+#  -g*:          generate debugging information\r
+#  -O*:          optimization level\r
+#  -f...:        tuning, see GCC manual and avr-libc documentation\r
+#  -Wall...:     warning level\r
+#  -Wa,...:      tell GCC to pass this to the assembler.\r
+#    -adhlns...: create assembler listing\r
+CPPFLAGS = -g$(DEBUG)\r
+CPPFLAGS += $(CPPDEFS)\r
+CPPFLAGS += -O$(OPT)\r
+CPPFLAGS += -funsigned-char\r
+CPPFLAGS += -funsigned-bitfields\r
+CPPFLAGS += -ffunction-sections\r
+CPPFLAGS += -fno-strict-aliasing\r
+CPPFLAGS += -fno-exceptions\r
+CPPFLAGS += -masm-addr-pseudos\r
+CPPFLAGS += -Wall\r
+CPPFLAGS += -Wundef\r
+CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)\r
+CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))\r
+#CPPFLAGS += $(CSTANDARD)\r
+\r
+\r
+#---------------- Assembler Options ----------------\r
+#  -Wa,...:   tell GCC to pass this to the assembler.\r
+#  -adhlns:   create listing\r
+#  -gstabs:   have the assembler create line number information; note that\r
+#             for use in COFF files, additional information about filenames\r
+#             and function names needs to be present in the assembler source\r
+#             files -- see avr-libc docs [FIXME: not yet described there]\r
+#  -listing-cont-lines: Sets the maximum number of continuation lines of hex\r
+#       dump that will be displayed for a given single line of source input.\r
+ASFLAGS = -g3 $(ADEFS)\r
+\r
+\r
+#---------------- Linker Options ----------------\r
+#  -Wl,...:     tell GCC to pass this to linker.\r
+#    -Map:      create map file\r
+#    --cref:    add cross reference to  map file\r
+LDFLAGS  = -Wl,-Map=$(TARGET).map,--cref\r
+LDFLAGS += -Wl,--gc-sections --rodata-writable\r
+LDFLAGS += -Wl,--direct-data\r
+#LDFLAGS += -T avr32elf_uc3b0256.x\r
+\r
+\r
+#============================================================================\r
+\r
+\r
+# Define programs and commands.\r
+SHELL = sh\r
+CC = avr32-gcc\r
+OBJCOPY = avr32-objcopy\r
+OBJDUMP = avr32-objdump\r
+SIZE = avr32-size\r
+AR = avr32-ar rcs\r
+NM = avr32-nm\r
+REMOVE = rm -f\r
+REMOVEDIR = rm -rf\r
+COPY = cp\r
+WINSHELL = cmd\r
+\r
+\r
+# Define Messages\r
+# English\r
+MSG_ERRORS_NONE = Errors: none\r
+MSG_BEGIN = -------- begin --------\r
+MSG_END = --------  end  --------\r
+MSG_SIZE_BEFORE = Size before:\r
+MSG_SIZE_AFTER = Size after:\r
+MSG_COFF = Converting to AVR COFF:\r
+MSG_FLASH = Creating load file for Flash:\r
+MSG_EEPROM = Creating load file for EEPROM:\r
+MSG_EXTENDED_LISTING = Creating Extended Listing:\r
+MSG_SYMBOL_TABLE = Creating Symbol Table:\r
+MSG_LINKING = Linking:\r
+MSG_COMPILING = Compiling C:\r
+MSG_COMPILING_CPP = Compiling C++:\r
+MSG_ASSEMBLING = Assembling:\r
+MSG_CLEANING = Cleaning project:\r
+MSG_CREATING_LIBRARY = Creating library:\r
+\r
+\r
+\r
+\r
+# Define all object files.\r
+OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)\r
+\r
+# Define all listing files.\r
+LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)\r
+\r
+\r
+# Compiler flags to generate dependency files.\r
+GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d\r
+\r
+\r
+# Combine all necessary flags and optional flags.\r
+# Add target processor to flags.\r
+ALL_CFLAGS = -mpart=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)\r
+ALL_CPPFLAGS = -mpart=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)\r
+ALL_ASFLAGS = -mpart=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)\r
+\r
+\r
+\r
+\r
+\r
+# Default target.\r
+all: begin gccversion sizebefore build sizeafter end\r
+\r
+# Change the build target to build a HEX file or a library.\r
+build: elf hex lss sym\r
+#build: lib\r
+\r
+\r
+elf: $(TARGET).elf\r
+hex: $(TARGET).hex\r
+lss: $(TARGET).lss\r
+sym: $(TARGET).sym\r
+LIBNAME=lib$(TARGET).a\r
+lib: $(LIBNAME)\r
+\r
+\r
+\r
+# Eye candy.\r
+# AVR Studio 3.x does not check make's exit code but relies on\r
+# the following magic strings to be generated by the compile job.\r
+begin:\r
+       @echo\r
+       @echo $(MSG_BEGIN)\r
+\r
+end:\r
+       @echo $(MSG_END)\r
+       @echo\r
+\r
+\r
+# Display size of file.\r
+HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex\r
+ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf\r
+MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )\r
+FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )\r
+\r
+\r
+sizebefore:\r
+       @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \\r
+       2>/dev/null; echo; fi\r
+\r
+sizeafter:\r
+       @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \\r
+       2>/dev/null; echo; fi\r
+\r
+\r
+\r
+# Display compiler version information.\r
+gccversion :\r
+       @$(CC) --version\r
+\r
+\r
+# Program the device.\r
+flip: $(TARGET).hex\r
+       batchisp -hardware usb -device $(MCU) -operation erase f\r
+       batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program\r
+       batchisp -hardware usb -device $(MCU) -operation start reset 0\r
+\r
+dfu: $(TARGET).hex\r
+       dfu-programmer $(MCU) erase\r
+       dfu-programmer $(MCU) flash $(TARGET).hex\r
+       dfu-programmer $(MCU) reset\r
+\r
+\r
+# Create final output files (.hex, .eep) from ELF output file.\r
+%.hex: %.elf\r
+       @echo\r
+       @echo $(MSG_FLASH) $@\r
+       $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@\r
+\r
+# Create extended listing file from ELF output file.\r
+%.lss: %.elf\r
+       @echo\r
+       @echo $(MSG_EXTENDED_LISTING) $@\r
+       $(OBJDUMP) -h -S $< > $@\r
+\r
+# Create a symbol table from ELF output file.\r
+%.sym: %.elf\r
+       @echo\r
+       @echo $(MSG_SYMBOL_TABLE) $@\r
+       $(NM) -n $< > $@\r
+\r
+\r
+\r
+# Create library from object files.\r
+.SECONDARY : $(TARGET).a\r
+.PRECIOUS : $(OBJ)\r
+%.a: $(OBJ)\r
+       @echo\r
+       @echo $(MSG_CREATING_LIBRARY) $@\r
+       $(AR) $@ $(OBJ)\r
+\r
+\r
+# Link: create ELF output file from object files.\r
+.SECONDARY : $(TARGET).elf\r
+.PRECIOUS : $(OBJ)\r
+%.elf: $(OBJ)\r
+       @echo\r
+       @echo $(MSG_LINKING) $@\r
+       $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)\r
+\r
+\r
+# Compile: create object files from C source files.\r
+$(OBJDIR)/%.o : %.c\r
+       @echo\r
+       @echo $(MSG_COMPILING) $<\r
+       $(CC) -c $(ALL_CFLAGS) $< -o $@\r
+\r
+\r
+# Compile: create object files from C++ source files.\r
+$(OBJDIR)/%.o : %.cpp\r
+       @echo\r
+       @echo $(MSG_COMPILING_CPP) $<\r
+       $(CC) -c $(ALL_CPPFLAGS) $< -o $@\r
+\r
+\r
+# Compile: create assembler files from C source files.\r
+%.s : %.c\r
+       $(CC) -S $(ALL_CFLAGS) $< -o $@\r
+\r
+\r
+# Compile: create assembler files from C++ source files.\r
+%.s : %.cpp\r
+       $(CC) -S $(ALL_CPPFLAGS) $< -o $@\r
+\r
+\r
+# Assemble: create object files from assembler source files.\r
+$(OBJDIR)/%.o : %.S\r
+       @echo\r
+       @echo $(MSG_ASSEMBLING) $<\r
+       $(CC) -c $(ALL_ASFLAGS) $< -o $@\r
+\r
+\r
+# Create preprocessed source for use in sending a bug report.\r
+%.i : %.c\r
+       $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@\r
+\r
+\r
+# Target: clean project.\r
+clean: begin clean_list end\r
+\r
+clean_list :\r
+       @echo\r
+       @echo $(MSG_CLEANING)\r
+       $(REMOVE) $(TARGET).hex\r
+       $(REMOVE) $(TARGET).cof\r
+       $(REMOVE) $(TARGET).elf\r
+       $(REMOVE) $(TARGET).map\r
+       $(REMOVE) $(TARGET).sym\r
+       $(REMOVE) $(TARGET).lss\r
+       $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)\r
+       $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)\r
+       $(REMOVE) $(SRC:.c=.s)\r
+       $(REMOVE) $(SRC:.c=.d)\r
+       $(REMOVE) $(SRC:.c=.i)\r
+       $(REMOVEDIR) .dep\r
+\r
+doxygen:\r
+       @echo Generating Project Documentation...\r
+       @doxygen Doxygen.conf\r
+       @echo Documentation Generation Complete.\r
+\r
+clean_doxygen:\r
+       rm -rf Documentation\r
+\r
+# Create object files directory\r
+$(shell mkdir $(OBJDIR) 2>/dev/null)\r
+\r
+\r
+# Include the dependency files.\r
+-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)\r
+\r
+\r
+# Listing of phony targets.\r
+.PHONY : all begin finish end sizebefore sizeafter gccversion \\r
+build elf hex lss sym doxygen clean clean_list clean_doxygen  \\r
+dfu flip\r
+\r