Fixed broken USE_RAM_DESCRIPTORS compile time option when the FIXED_NUM_CONFIGURATION...
[pub/USBasp.git] / Demos / Device / LowLevel / AudioOutput / AudioOutput.c
index c5d9363..89fef03 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2011.
+     Copyright (C) Dean Camera, 2015.
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
-  Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2015  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
@@ -18,7 +18,7 @@
   advertising or publicity pertaining to distribution of the
   software without specific, written prior permission.
 
-  The author disclaim all warranties with regard to this
+  The author disclaims all warranties with regard to this
   software, including all implied warranties of merchantability
   and fitness.  In no event shall the author be liable for any
   special, indirect or consequential damages or any damages
@@ -51,7 +51,7 @@ int main(void)
        SetupHardware();
 
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
-       sei();
+       GlobalInterruptEnable();
 
        for (;;)
        {
@@ -62,12 +62,14 @@ int main(void)
 /** Configures the board hardware and chip peripherals for the demo's functionality. */
 void SetupHardware(void)
 {
+#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);
+#endif
 
        /* Hardware Initialization */
        LEDs_Init();
@@ -144,8 +146,7 @@ void EVENT_USB_Device_ConfigurationChanged(void)
        bool ConfigSuccess = true;
 
        /* Setup Audio Stream Endpoint */
-       ConfigSuccess &= Endpoint_ConfigureEndpoint(AUDIO_STREAM_EPNUM, EP_TYPE_ISOCHRONOUS, ENDPOINT_DIR_OUT,
-                                                   AUDIO_STREAM_EPSIZE, ENDPOINT_BANK_DOUBLE);
+       ConfigSuccess &= Endpoint_ConfigureEndpoint(AUDIO_STREAM_EPADDR, EP_TYPE_ISOCHRONOUS, AUDIO_STREAM_EPSIZE, 2);
 
        /* Indicate endpoint configuration success or failure */
        LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
@@ -186,19 +187,19 @@ void EVENT_USB_Device_ControlRequest(void)
                case AUDIO_REQ_SetCurrent:
                        if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT))
                        {
-                               /* Extract out the relevant request information to get the target Endpoint index and control being set */
-                               uint8_t EndpointIndex   = (uint8_t)USB_ControlRequest.wIndex;
+                               /* Extract out the relevant request information to get the target Endpoint address and control being set */
+                               uint8_t EndpointAddress = (uint8_t)USB_ControlRequest.wIndex;
                                uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8);
-                               
+
                                /* Only handle SET CURRENT requests to the audio endpoint's sample frequency property */
-                               if ((EndpointIndex == AUDIO_STREAM_EPNUM) && (EndpointControl == AUDIO_EPCONTROL_SamplingFreq))
+                               if ((EndpointAddress == AUDIO_STREAM_EPADDR) && (EndpointControl == AUDIO_EPCONTROL_SamplingFreq))
                                {
                                        uint8_t SampleRate[3];
-                               
+
                                        Endpoint_ClearSETUP();
                                        Endpoint_Read_Control_Stream_LE(SampleRate, sizeof(SampleRate));
-                                       Endpoint_ClearOUT();
-                                       
+                                       Endpoint_ClearIN();
+
                                        /* Set the new sampling frequency to the value given by the host */
                                        CurrentAudioSampleFrequency = (((uint32_t)SampleRate[2] << 16) | ((uint32_t)SampleRate[1] << 8) | (uint32_t)SampleRate[0]);
 
@@ -206,28 +207,28 @@ void EVENT_USB_Device_ControlRequest(void)
                                        OCR0A = ((F_CPU / 8 / CurrentAudioSampleFrequency) - 1);
                                }
                        }
-                       
+
                        break;
                case AUDIO_REQ_GetCurrent:
-                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT))
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
                        {
-                               /* Extract out the relevant request information to get the target Endpoint index and control being retrieved */
-                               uint8_t EndpointIndex   = (uint8_t)USB_ControlRequest.wIndex;
+                               /* Extract out the relevant request information to get the target Endpoint address and control being retrieved */
+                               uint8_t EndpointAddress = (uint8_t)USB_ControlRequest.wIndex;
                                uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8);
-                               
+
                                /* Only handle GET CURRENT requests to the audio endpoint's sample frequency property */
-                               if ((EndpointIndex == AUDIO_STREAM_EPNUM) && (EndpointControl == AUDIO_EPCONTROL_SamplingFreq))
+                               if ((EndpointAddress == AUDIO_STREAM_EPADDR) && (EndpointControl == AUDIO_EPCONTROL_SamplingFreq))
                                {
                                        uint8_t SampleRate[3];
-                                       
+
                                        /* Convert the sampling rate value into the 24-bit format the host expects for the property */
                                        SampleRate[2] = (CurrentAudioSampleFrequency >> 16);
                                        SampleRate[1] = (CurrentAudioSampleFrequency >> 8);
                                        SampleRate[0] = (CurrentAudioSampleFrequency &  0xFF);
-                               
+
                                        Endpoint_ClearSETUP();
                                        Endpoint_Write_Control_Stream_LE(SampleRate, sizeof(SampleRate));
-                                       Endpoint_ClearOUT();                                    
+                                       Endpoint_ClearOUT();
                                }
                        }
 
@@ -241,7 +242,7 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
        uint8_t PrevEndpoint = Endpoint_GetCurrentEndpoint();
 
        /* Select the audio stream endpoint */
-       Endpoint_SelectEndpoint(AUDIO_STREAM_EPNUM);
+       Endpoint_SelectEndpoint(AUDIO_STREAM_EPADDR);
 
        /* Check if the current endpoint can be read from (contains a packet) and the host is sending data */
        if (Endpoint_IsOUTReceived() && StreamingAudioInterfaceSelected)
@@ -286,7 +287,7 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
 
                LEDs_SetAllLEDs(LEDMask);
        }
-       
+
        Endpoint_SelectEndpoint(PrevEndpoint);
 }