X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/071e02c6b6b4837fa9cf0b6d4c749994e02638d7..5517f96e86b9447780a3e27bb455697f9fc65eea:/Demos/Device/LowLevel/AudioOutput/AudioOutput.c?ds=inline diff --git a/Demos/Device/LowLevel/AudioOutput/AudioOutput.c b/Demos/Device/LowLevel/AudioOutput/AudioOutput.c index db6bc3c75..e33eb401e 100644 --- a/Demos/Device/LowLevel/AudioOutput/AudioOutput.c +++ b/Demos/Device/LowLevel/AudioOutput/AudioOutput.c @@ -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 @@ -33,7 +33,7 @@ * 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" /** Flag to indicate if the streaming audio alternative interface has been selected by the host. */ @@ -48,7 +48,7 @@ int main(void) LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); sei(); - + for (;;) { USB_Audio_Task(); @@ -65,7 +65,7 @@ void SetupHardware(void) /* Disable clock division */ clock_prescale_set(clock_div_1); - + /* Hardware Initialization */ LEDs_Init(); USB_Init(); @@ -78,12 +78,12 @@ void EVENT_USB_Device_Connect(void) { /* Indicate USB enumerating */ LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); - + /* Sample reload timer initialization */ OCR0A = (F_CPU / 8 / AUDIO_SAMPLE_FREQUENCY) - 1; TCCR0A = (1 << WGM01); // CTC mode TCCR0B = (1 << CS01); // Fcpu/8 speed - + #if defined(AUDIO_OUT_MONO) /* Set speaker as output */ DDRC |= (1 << 6); @@ -99,8 +99,8 @@ 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 -#endif + TCCR3B = ((1 << WGM32) | (1 << CS30)); // Fast 8-Bit PWM, F_CPU speed +#endif } /** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via @@ -112,7 +112,7 @@ void EVENT_USB_Device_Disconnect(void) TCCR0B = 0; #if (defined(AUDIO_OUT_MONO) || defined(AUDIO_OUT_STEREO)) TCCR3B = 0; -#endif +#endif #if defined(AUDIO_OUT_MONO) /* Set speaker as input to reduce current draw */ @@ -137,16 +137,14 @@ void EVENT_USB_Device_Disconnect(void) */ void EVENT_USB_Device_ConfigurationChanged(void) { - /* Indicate USB connected and ready */ - LEDs_SetAllLEDs(LEDMASK_USB_READY); + bool ConfigSuccess = true; - /* Setup audio stream endpoint */ - if (!(Endpoint_ConfigureEndpoint(AUDIO_STREAM_EPNUM, EP_TYPE_ISOCHRONOUS, - ENDPOINT_DIR_OUT, AUDIO_STREAM_EPSIZE, - ENDPOINT_BANK_DOUBLE))) - { - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - } + /* Setup Audio Stream Endpoint */ + ConfigSuccess &= Endpoint_ConfigureEndpoint(AUDIO_STREAM_EPNUM, EP_TYPE_ISOCHRONOUS, ENDPOINT_DIR_OUT, + AUDIO_STREAM_EPSIZE, ENDPOINT_BANK_DOUBLE); + + /* Indicate endpoint configuration success or failure */ + LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR); } /** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific @@ -163,11 +161,10 @@ void EVENT_USB_Device_UnhandledControlRequest(void) if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE)) { Endpoint_ClearSETUP(); - + Endpoint_ClearStatusStage(); + /* Check if the host is enabling the audio interface (setting AlternateSetting to 1) */ StreamingAudioInterfaceSelected = ((USB_ControlRequest.wValue) != 0); - - Endpoint_ClearStatusStage(); } break; @@ -185,11 +182,11 @@ void USB_Audio_Task(void) /* Check to see if the streaming interface is selected, if not the host is not receiving audio */ if (!(StreamingAudioInterfaceSelected)) - return; + return; /* Select the audio stream endpoint */ Endpoint_SelectEndpoint(AUDIO_STREAM_EPNUM); - + /* Check if the current endpoint can be read from (contains a packet) and that the next sample should be read */ if (Endpoint_IsOUTReceived() && (TIFR0 & (1 << OCF0A))) { @@ -237,3 +234,4 @@ void USB_Audio_Task(void) LEDs_SetAllLEDs(LEDMask); } } +