LUFA is a USB communication library used extensively in the MIDI Harp project. We found incorporating LUFA with ASF libraries to be a bit of a chore, so below we have detailed the steps that will get you through modifying your project so you can get on our level.
The first step is to download the LUFA software pack for Atmel Studio 7, which can be found here: https://gallery.atmel.com/Products/Details/d1057c19-3815-487e-baa7-0001985c6901.
Once you have this fully installed, create a new temperature sensor example project for the A3BU (We started here as we knew this included everything for utilizing ADC). Import the required LUFA modules, shown below, via ASF Wizard.
Now, ASF and LUFA employ conflicting numerical definitions to indicate the feature-set of various models of Atmel boards. To correct this, you first need to go to your project’s properties by right clicking the orange project folder in the Solution Explorer, clicking properties, and going to the toolchain tab. Under AVR/GNU C Compiler->Symbols you will discover contradicting BOARD definitions from ASF and LUFA respectively. We found it easiest to keep the definition used by Atmel and update the LUFA files accordingly.
Two additional symbols must be created with the green + button as follows: F_USB=48000000UL and F_CPU=32000000UL
With BOARD=BOARD_A3BU_XPLAINED deleted and BOARD=XMEGA_A3BU_XPLAINED remaining, you will need to make a series of changes to the files associated with LUFA. First, in the Solution Explorer, go to src/LUFA/LUFA/Common/ and open BoardTypes.h. Two lines have to be commented here to correct the conflicting definitions. First, comment line 160, “#define BOARD_A3BU_XPLAINED 31”. This removes LUFA’s numerical definition for the board definition we are no longer using. Then, comment line 148, “#define BOARD_EVK1101 27”. This conflicts with Atmel because XMEGA_A3BU_XPLAINED is defined as 27, and gets mixed up with this other board definition from LUFA. LUFA files then attempt to set up the project for the EVK1101 board instead of A3BU.
Next, go into Solution Explorer src/LUFA/LUFA/Drivers/Board/ and open Buttons.h, Dataflash.h, and LEDs.h. (There should also be a folder called XMEGA. If this is not in the folder with the above files, create the LUFA example project “MIDI Device Demo (Class Driver APIs) – XMEGA Architecture”, and copy this folder into this location.) Within each of these files, find a line that looks similar to #elif (BOARD == BOARD_A3BU_XPLAINED) and change BOARD_A3BU_XPLAINED to XMEGA_A3BU_XPLAINED as shown below.
Once each of these files have been changed, you may close these files. Now go to src/config/LUFAConfig.h and make the changes shown below to the XMEGA section starting at line 91:
These will initially all be commented out. Uncomment the lines shown and add the values shown to the right (lines 106, 113,116, 118, and 120).
Finally, you will need to copy the files Descriptors.h, Descriptors.c, and MIDI.h from the src folder of the MIDI example project mentioned above, and put them into the src folder for your project. There are several functions which can be found in MIDI.c from this example project that must be used to make the USB connection and send MIDI signals. Copying these files allows the necessary functions to work properly. Then make sure to include these files in the Solution Explorer so your project knows where to find them.
You should copy code sections into your project from the MIDI demo project’s MIDI.c file that initialize and facilitate USB communication, including one to manage clock sources and speeds, while removing a conflicting initialization of ASF’s system clock management module. After that, you’re good to go! We’ll leave the rest of the coding to you. Have fun with your MIDI harp!