X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/b9b03aadb219d06fbad9d110e508db93e45461af..2a0c28e6e47c8a173f32fc99cd8666a2633c5c12:/Demos/Device/ClassDriver/AudioOutput/AudioOutput.c diff --git a/Demos/Device/ClassDriver/AudioOutput/AudioOutput.c b/Demos/Device/ClassDriver/AudioOutput/AudioOutput.c index 8c3bf6188..f859c7c6e 100644 --- a/Demos/Device/ClassDriver/AudioOutput/AudioOutput.c +++ b/Demos/Device/ClassDriver/AudioOutput/AudioOutput.c @@ -40,12 +40,20 @@ * 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 = +USB_ClassInfo_Audio_Device_t Speaker_Audio_Interface = { - .StreamingInterfaceNumber = 1, - - .DataOUTEndpointNumber = AUDIO_STREAM_EPNUM, - .DataOUTEndpointSize = AUDIO_STREAM_EPSIZE, + .Config = + { + .StreamingInterfaceNumber = 1, + + .DataINEndpointNumber = AUDIO_STREAM_EPNUM, + .DataINEndpointSize = AUDIO_STREAM_EPSIZE, + }, + + .State = + { + // Leave all state values to their defaults + } }; /** Main program entry point. This routine contains the overall program flow, including initial @@ -59,10 +67,10 @@ int main(void) for (;;) { - if (Speaker_Audio_Interface.InterfaceEnabled) + if (Speaker_Audio_Interface.State.InterfaceEnabled) ProcessNextSample(); - USB_Audio_USBTask(&Speaker_Audio_Interface); + Audio_Device_USBTask(&Speaker_Audio_Interface); USB_USBTask(); } } @@ -87,19 +95,19 @@ void SetupHardware(void) */ void ProcessNextSample(void) { - if ((TIFR0 & (1 << OCF0A)) && USB_Audio_IsSampleReceived(&Speaker_Audio_Interface)) + if ((TIFR0 & (1 << OCF0A)) && Audio_Device_IsSampleReceived(&Speaker_Audio_Interface)) { /* Clear the sample reload timer */ TIFR0 |= (1 << OCF0A); /* Retrieve the signed 16-bit left and right audio samples */ - int16_t LeftSample_16Bit = (int16_t)USB_Audio_ReadSample16(); - int16_t RightSample_16Bit = (int16_t)USB_Audio_ReadSample16(); + int16_t LeftSample_16Bit = (int16_t)Audio_Device_ReadSample16(); + int16_t RightSample_16Bit = (int16_t)Audio_Device_ReadSample16(); /* Massage signed 16-bit left and right audio samples into signed 8-bit */ int8_t LeftSample_8Bit = (LeftSample_16Bit >> 8); int8_t RightSample_8Bit = (RightSample_16Bit >> 8); - + /* 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); @@ -160,9 +168,9 @@ void EVENT_USB_Connect(void) #if (defined(AUDIO_OUT_MONO) || defined(AUDIO_OUT_STEREO)) /* PWM speaker timer initialization */ TCCRxA = ((1 << WGMx0) | (1 << COMxA1) | (1 << COMxA0) - | (1 << COMxB1) | (1 << COMxB0)); // Set on match, clear on TOP + | (1 << COMxB1) | (1 << COMxB0)); // Set on match, clear on TOP TCCRxB = ((1 << WGMx2) | (1 << CSx0)); // Fast 8-Bit PWM, Fcpu speed -#endif +#endif } /** Event handler for the library USB Disconnection event. */ @@ -176,7 +184,7 @@ void EVENT_USB_Disconnect(void) #if (defined(AUDIO_OUT_MONO) || defined(AUDIO_OUT_STEREO)) /* Stop the PWM generation timer */ TCCRxB = 0; -#endif +#endif #if defined(AUDIO_OUT_MONO) /* Set speaker as input to reduce current draw */ @@ -195,12 +203,12 @@ void EVENT_USB_ConfigurationChanged(void) { LEDs_SetAllLEDs(LEDMASK_USB_READY); - if (!(USB_Audio_ConfigureEndpoints(&Speaker_Audio_Interface))) + if (!(Audio_Device_ConfigureEndpoints(&Speaker_Audio_Interface))) 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); + Audio_Device_ProcessControlPacket(&Speaker_Audio_Interface); }