Commit 4f442a9a authored by Erik Strand's avatar Erik Strand
Browse files

Start making the audio example work for XMEGAs

parent 8aec4fce
......@@ -66,7 +66,10 @@ int main(void)
{
SetupHardware();
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
PORTC.DIRSET = (1 << 5) | (1u << 6) | (1u << 7);
PORTC.OUTSET = (1 << 5) | (1u << 6) | (1u << 7);
//LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
GlobalInterruptEnable();
for (;;)
......@@ -86,17 +89,29 @@ void SetupHardware(void)
/* Disable clock division */
clock_prescale_set(clock_div_1);
#elif (ARCH == ARCH_XMEGA)
/* Start the PLL to multiply the 2MHz RC oscillator to 32MHz and switch the CPU core to run from it */
XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, F_CPU);
XMEGACLK_SetCPUClockSource(CLOCK_SRC_PLL);
/* Start the 32MHz internal RC oscillator and start the DFLL to increase it to 48MHz using the USB SOF as a reference */
XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ);
XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB);
PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
#endif
/* Hardware Initialization */
LEDs_Init();
Buttons_Init();
ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32);
ADC_SetupChannel(MIC_IN_ADC_CHANNEL);
//LEDs_Init();
//Buttons_Init();
//ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32);
//ADC_SetupChannel(MIC_IN_ADC_CHANNEL);
USB_Init();
/* Start the ADC conversion in free running mode */
ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | ADC_GET_CHANNEL_MASK(MIC_IN_ADC_CHANNEL));
//ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | ADC_GET_CHANNEL_MASK(MIC_IN_ADC_CHANNEL));
}
/** ISR to handle the reloading of the data endpoint with the next sample. */
......@@ -118,7 +133,7 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
CurrentWaveValue ^= 0x8000;
/* Only generate audio if the board button is being pressed */
AudioSample = (Buttons_GetStatus() & BUTTONS_BUTTON1) ? CurrentWaveValue : 0;
//AudioSample = (Buttons_GetStatus() & BUTTONS_BUTTON1) ? CurrentWaveValue : 0;
#else
/* Audio sample is ADC value scaled to fit the entire range */
AudioSample = ((SAMPLE_MAX_RANGE / ADC_MAX_RANGE) * ADC_GetResult());
......@@ -138,7 +153,7 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
/** Event handler for the library USB Connection event. */
void EVENT_USB_Device_Connect(void)
{
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
//LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
/* Sample reload timer initialization */
TIMSK0 = (1 << OCIE0A);
......@@ -153,7 +168,7 @@ void EVENT_USB_Device_Disconnect(void)
/* Stop the sample reload timer */
TCCR0B = 0;
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
//LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
}
/** Event handler for the library USB Configuration Changed event. */
......@@ -163,7 +178,7 @@ void EVENT_USB_Device_ConfigurationChanged(void)
ConfigSuccess &= Audio_Device_ConfigureEndpoints(&Microphone_Audio_Interface);
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
//LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
}
/** Event handler for the library USB Control Request reception event. */
......
......@@ -42,9 +42,9 @@
#include <avr/power.h>
#include <avr/interrupt.h>
#include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/Board/Buttons.h>
#include <LUFA/Drivers/Peripheral/ADC.h>
//#include <LUFA/Drivers/Board/LEDs.h>
//#include <LUFA/Drivers/Board/Buttons.h>
//#include <LUFA/Drivers/Peripheral/ADC.h>
#include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Platform/Platform.h>
......@@ -56,19 +56,21 @@
#define SAMPLE_MAX_RANGE 0xFFFF
/** Maximum ADC range for the microphone input. */
#define ADC_MAX_RANGE 0x3FF
//#define ADC_MAX_RANGE 0x3FF
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
#define LEDMASK_USB_NOTREADY LEDS_LED1
//#define LEDMASK_USB_NOTREADY LEDS_LED1
/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
#define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
//#define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
//#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
//#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
#define USE_TEST_TONEE 1
/* Function Prototypes: */
void SetupHardware(void);
......
......@@ -85,6 +85,14 @@
// #define NO_AUTO_VBUS_MANAGEMENT
// #define INVERTED_VBUS_ENABLE_LINE
#elif (ARCH == ARCH_XMEGA)
#define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)
#define USE_FLASH_DESCRIPTORS
#define FIXED_CONTROL_ENDPOINT_SIZE 8
#define FIXED_NUM_CONFIGURATIONS 1
#define MAX_ENDPOINT_INDEX 2
#else
#error Unsupported architecture for this LUFA configuration file.
......
......@@ -11,10 +11,10 @@
# Run "make help" for target help.
MCU = at90usb1287
ARCH = AVR8
BOARD = USBKEY
F_CPU = 8000000
MCU = atxmega128a4u
ARCH = XMEGA
BOARD = BOARD_USER
F_CPU = 48000000
F_USB = $(F_CPU)
OPTIMIZATION = s
TARGET = AudioInput
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment