aboutsummaryrefslogtreecommitdiffstats
path: root/Demos/Device/AudioOutput
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-06-04 02:55:30 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-06-04 02:55:30 +0000
commita67bd74e3e8aad87dcee8cf0c0eaaccbe7d00552 (patch)
treefdf670b5b93e2e192d19ca71138a667d7f3ba4f9 /Demos/Device/AudioOutput
parent7c5444b89a49df7cb671b0b041567990d2a3012e (diff)
downloadlufa-a67bd74e3e8aad87dcee8cf0c0eaaccbe7d00552.tar.gz
lufa-a67bd74e3e8aad87dcee8cf0c0eaaccbe7d00552.tar.bz2
lufa-a67bd74e3e8aad87dcee8cf0c0eaaccbe7d00552.zip
Minor documentation page updates.
Redocumented all device demos, now that they have changed over to the new USB class drivers. Added C linkage to class drivers for C++ support. Added prefixes to most of the class driver constants to prevent name clashes.
Diffstat (limited to 'Demos/Device/AudioOutput')
-rw-r--r--Demos/Device/AudioOutput/AudioOutput.c71
-rw-r--r--Demos/Device/AudioOutput/AudioOutput.h7
-rw-r--r--Demos/Device/AudioOutput/Descriptors.c2
3 files changed, 48 insertions, 32 deletions
diff --git a/Demos/Device/AudioOutput/AudioOutput.c b/Demos/Device/AudioOutput/AudioOutput.c
index 0f193567a..4ff2e7453 100644
--- a/Demos/Device/AudioOutput/AudioOutput.c
+++ b/Demos/Device/AudioOutput/AudioOutput.c
@@ -28,16 +28,29 @@
this software.
*/
+/** \file
+ *
+ * Main source file for the AudioOutput demo. This file contains the main tasks of
+ * the demo and is responsible for the initial application hardware configuration.
+ */
+
#include "AudioOutput.h"
+/** LUFA Audio Class driver interface configuration and state information. This structure is
+ * passed to all Audio Class driver functions, so that multiple instances of the same class
+ * within a device can be differentiated from one another.
+ */
USB_ClassInfo_Audio_t Speaker_Audio_Interface =
{
- .InterfaceNumber = 0,
+ .StreamingInterfaceNumber = 1,
- .DataOUTEndpointNumber = AUDIO_STREAM_EPNUM,
- .DataOUTEndpointSize = AUDIO_STREAM_EPSIZE,
+ .DataOUTEndpointNumber = AUDIO_STREAM_EPNUM,
+ .DataOUTEndpointSize = AUDIO_STREAM_EPSIZE,
};
+/** Main program entry point. This routine contains the overall program flow, including initial
+ * setup of all components and the main program loop.
+ */
int main(void)
{
SetupHardware();
@@ -53,6 +66,7 @@ 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 */
@@ -67,6 +81,9 @@ void SetupHardware(void)
USB_Init();
}
+/** Processes the next audio sample by reading the last ADC conversion and writing it to the audio
+ * interface, each time the sample reload timer period elapses to give a constant sample rate.
+ */
void ProcessNextSample(void)
{
if ((TIFR0 & (1 << OCF0A)) && USB_Audio_IsSampleReceived(&Speaker_Audio_Interface))
@@ -82,10 +99,10 @@ void ProcessNextSample(void)
int8_t LeftSample_8Bit = (LeftSample_16Bit >> 8);
int8_t RightSample_8Bit = (RightSample_16Bit >> 8);
-#if defined(AUDIO_OUT_MONO)
/* Mix the two channels together to produce a mono, 8-bit sample */
int8_t MixedSample_8Bit = (((int16_t)LeftSample_8Bit + (int16_t)RightSample_8Bit) >> 1);
+#if defined(AUDIO_OUT_MONO)
/* Load the sample into the PWM timer channel */
OCRxA = ((uint8_t)MixedSample_8Bit ^ (1 << 7));
#elif defined(AUDIO_OUT_STEREO)
@@ -93,42 +110,32 @@ void ProcessNextSample(void)
OCRxA = ((uint8_t)LeftSample_8Bit ^ (1 << 7));
OCRxB = ((uint8_t)RightSample_8Bit ^ (1 << 7));
#elif defined(AUDIO_OUT_PORTC)
- /* Mix the two channels together to produce a mono, 8-bit sample */
- int8_t MixedSample_8Bit = (((int16_t)LeftSample_8Bit + (int16_t)RightSample_8Bit) >> 1);
-
PORTC = MixedSample_8Bit;
#else
uint8_t LEDMask = LEDS_NO_LEDS;
- /* Make left channel positive (absolute) */
- if (LeftSample_8Bit < 0)
- LeftSample_8Bit = -LeftSample_8Bit;
-
- /* Make right channel positive (absolute) */
- if (RightSample_8Bit < 0)
- RightSample_8Bit = -RightSample_8Bit;
+ /* Make mixed sample value positive (absolute) */
+ if (MixedSample_8Bit < 0)
+ MixedSample_8Bit = -MixedSample_8Bit;
- /* Set first LED based on sample value */
- if (LeftSample_8Bit < ((128 / 8) * 1))
- LEDMask |= LEDS_LED2;
- else if (LeftSample_8Bit < ((128 / 8) * 3))
- LEDMask |= (LEDS_LED1 | LEDS_LED2);
- else
+ if (MixedSample_8Bit > ((128 / 8) * 1))
LEDMask |= LEDS_LED1;
+
+ if (MixedSample_8Bit > ((128 / 8) * 2))
+ LEDMask |= LEDS_LED2;
+
+ if (MixedSample_8Bit > ((128 / 8) * 3))
+ LEDMask |= LEDS_LED3;
- /* Set second LED based on sample value */
- if (RightSample_8Bit < ((128 / 8) * 1))
+ if (MixedSample_8Bit > ((128 / 8) * 4))
LEDMask |= LEDS_LED4;
- else if (RightSample_8Bit < ((128 / 8) * 3))
- LEDMask |= (LEDS_LED3 | LEDS_LED4);
- else
- LEDMask |= LEDS_LED3;
-
+
LEDs_SetAllLEDs(LEDMask);
#endif
}
}
+/** Event handler for the library USB Connection event. */
void EVENT_USB_Connect(void)
{
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
@@ -157,16 +164,16 @@ void EVENT_USB_Connect(void)
#endif
}
-/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
- * the status LEDs, disables the sample update and PWM output timers and stops the USB and Audio management tasks.
- */
+/** Event handler for the library USB Disconnection event. */
void EVENT_USB_Disconnect(void)
{
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
- /* Stop the timers */
+ /* Stop the sample reload timer */
TCCR0B = 0;
+
#if (defined(AUDIO_OUT_MONO) || defined(AUDIO_OUT_STEREO))
+ /* Stop the PWM generation timer */
TCCRxB = 0;
#endif
@@ -182,6 +189,7 @@ void EVENT_USB_Disconnect(void)
#endif
}
+/** Event handler for the library USB Configuration Changed event. */
void EVENT_USB_ConfigurationChanged(void)
{
LEDs_SetAllLEDs(LEDMASK_USB_READY);
@@ -190,6 +198,7 @@ void EVENT_USB_ConfigurationChanged(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
+/** Event handler for the library USB Unhandled Control Packet event. */
void EVENT_USB_UnhandledControlPacket(void)
{
USB_Audio_ProcessControlPacket(&Speaker_Audio_Interface);
diff --git a/Demos/Device/AudioOutput/AudioOutput.h b/Demos/Device/AudioOutput/AudioOutput.h
index 7d112db88..e8435e3ad 100644
--- a/Demos/Device/AudioOutput/AudioOutput.h
+++ b/Demos/Device/AudioOutput/AudioOutput.h
@@ -99,9 +99,16 @@
#endif
/* Macros: */
+ /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
#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)
+
+ /** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#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)
/* Function Prototypes: */
diff --git a/Demos/Device/AudioOutput/Descriptors.c b/Demos/Device/AudioOutput/Descriptors.c
index 92d7e0d57..0039c2ba8 100644
--- a/Demos/Device/AudioOutput/Descriptors.c
+++ b/Demos/Device/AudioOutput/Descriptors.c
@@ -201,7 +201,7 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.BitResolution = 16,
.SampleFrequencyType = (sizeof(ConfigurationDescriptor.AudioFormat.SampleFrequencies) / sizeof(AudioSampleFreq_t)),
- .SampleFrequencies = {SAMPLE_FREQ(AUDIO_SAMPLE_FREQUENCY)}
+ .SampleFrequencies = {AUDIO_SAMPLE_FREQ(AUDIO_SAMPLE_FREQUENCY)}
},
.AudioEndpoint =