X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/9798440ca4f694e7cd8312a51b82e59589f1ebeb..7f3f39b5750b9ac877798f41efcf82d931d657f8:/Demos/Device/ClassDriver/AudioOutput/AudioOutput.c diff --git a/Demos/Device/ClassDriver/AudioOutput/AudioOutput.c b/Demos/Device/ClassDriver/AudioOutput/AudioOutput.c index 67e08f2c3..9a63af68a 100644 --- a/Demos/Device/ClassDriver/AudioOutput/AudioOutput.c +++ b/Demos/Device/ClassDriver/AudioOutput/AudioOutput.c @@ -40,12 +40,15 @@ * 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, + .Config = + { + .StreamingInterfaceNumber = 1, - .DataOUTEndpointNumber = AUDIO_STREAM_EPNUM, - .DataOUTEndpointSize = AUDIO_STREAM_EPSIZE, + .DataINEndpointNumber = AUDIO_STREAM_EPNUM, + .DataINEndpointSize = AUDIO_STREAM_EPSIZE, + }, }; /** Main program entry point. This routine contains the overall program flow, including initial @@ -59,7 +62,7 @@ int main(void) for (;;) { - if (Speaker_Audio_Interface.InterfaceEnabled) + if (Speaker_Audio_Interface.State.InterfaceEnabled) ProcessNextSample(); Audio_Device_USBTask(&Speaker_Audio_Interface); @@ -100,24 +103,26 @@ void ProcessNextSample(void) int8_t LeftSample_8Bit = (LeftSample_16Bit >> 8); int8_t RightSample_8Bit = (RightSample_16Bit >> 8); +#if !defined(AUDIO_OUT_STEREO) /* 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); +#endif #if defined(AUDIO_OUT_MONO) /* Load the sample into the PWM timer channel */ - OCRxA = ((uint8_t)MixedSample_8Bit ^ (1 << 7)); + OCR3A = ((uint8_t)MixedSample_8Bit ^ (1 << 7)); #elif defined(AUDIO_OUT_STEREO) /* Load the dual 8-bit samples into the PWM timer channels */ - OCRxA = ((uint8_t)LeftSample_8Bit ^ (1 << 7)); - OCRxB = ((uint8_t)RightSample_8Bit ^ (1 << 7)); + OCR3A = ((uint8_t)LeftSample_8Bit ^ (1 << 7)); + OCR3B = ((uint8_t)RightSample_8Bit ^ (1 << 7)); #elif defined(AUDIO_OUT_PORTC) + /* Load the 8-bit mixed sample into PORTC */ PORTC = MixedSample_8Bit; #else uint8_t LEDMask = LEDS_NO_LEDS; /* Make mixed sample value positive (absolute) */ - if (MixedSample_8Bit < 0) - MixedSample_8Bit = -MixedSample_8Bit; + MixedSample_8Bit = abs(MixedSample_8Bit); if (MixedSample_8Bit > ((128 / 8) * 1)) LEDMask |= LEDS_LED1; @@ -159,9 +164,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 - TCCRxB = ((1 << WGMx2) | (1 << CSx0)); // Fast 8-Bit PWM, Fcpu speed + 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 } @@ -175,7 +180,7 @@ void EVENT_USB_Disconnect(void) #if (defined(AUDIO_OUT_MONO) || defined(AUDIO_OUT_STEREO)) /* Stop the PWM generation timer */ - TCCRxB = 0; + TCCR3B = 0; #endif #if defined(AUDIO_OUT_MONO)