Oops - fix broken SPI driver due to missing bit inversion on a port mask.
[pub/USBasp.git] / Demos / Device / ClassDriver / AudioOutput / AudioOutput.c
index 622e423..33b52a1 100644 (file)
@@ -1,7 +1,7 @@
 /*
              LUFA Library
      Copyright (C) Dean Camera, 2010.
-              
+
   dean [at] fourwalledcubicle [dot] com
       www.fourwalledcubicle.com
 */
@@ -9,13 +9,13 @@
 /*
   Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
-  Permission to use, copy, modify, distribute, and sell this 
+  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 
+  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 
+  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
@@ -60,7 +60,7 @@ int main(void)
 
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
        sei();
-       
+
        for (;;)
        {
                ProcessNextSample();
@@ -93,7 +93,7 @@ void ProcessNextSample(void)
        /* Check if the sample reload timer period has elapsed, and that the USB bus is ready for a new sample */
        if ((TIFR0 & (1 << OCF0A)) && Audio_Device_IsSampleReceived(&Speaker_Audio_Interface))
        {
-               /* Clear the sample reload timer */
+               /* Clear the sample reload timer compare flag, ready for the next interval */
                TIFR0 |= (1 << OCF0A);
 
                /* Retrieve the signed 16-bit left and right audio samples, convert to 8-bit */
@@ -135,7 +135,7 @@ void ProcessNextSample(void)
 void EVENT_USB_Device_Connect(void)
 {
        LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
-       
+
        /* Sample reload timer initialization */
        OCR0A   = (F_CPU / 8 / AUDIO_SAMPLE_FREQUENCY) - 1;
        TCCR0A  = (1 << WGM01);  // CTC mode
@@ -156,7 +156,7 @@ void EVENT_USB_Device_Connect(void)
        /* PWM speaker timer initialization */
        TCCR3A  = ((1 << WGM30) | (1 << COM3A1) | (1 << COM3A0)
                | (1 << COM3B1) | (1 << COM3B0)); // Set on match, clear on TOP
-       TCCR3B  = ((1 << WGM32) | (1 << CS30));  // Fast 8-Bit PWM, Fcpu speed
+       TCCR3B  = ((1 << WGM32) | (1 << CS30));  // Fast 8-Bit PWM, F_CPU speed
 #endif
 }
 
@@ -188,10 +188,11 @@ void EVENT_USB_Device_Disconnect(void)
 /** Event handler for the library USB Configuration Changed event. */
 void EVENT_USB_Device_ConfigurationChanged(void)
 {
-       LEDs_SetAllLEDs(LEDMASK_USB_READY);
-       
-       if (!(Audio_Device_ConfigureEndpoints(&Speaker_Audio_Interface)))
-         LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+       bool ConfigSuccess = true;
+
+       ConfigSuccess &= Audio_Device_ConfigureEndpoints(&Speaker_Audio_Interface);
+
+       LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
 }
 
 /** Event handler for the library USB Unhandled Control Request event. */
@@ -199,3 +200,4 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
 {
        Audio_Device_ProcessControlRequest(&Speaker_Audio_Interface);
 }
+