Commit 41babf1c authored by Dean Camera's avatar Dean Camera
Browse files

Fix incorrect configuration in the ClassDriver AudioOutput demo.

Make all audio device Class Driver functions require a reference to the Audio class instance, so that the endpoint size can be checked (and to standardize the APIs).

Make LEDs more responsive in the AudioOutput device demos.
parent 41b54a2a
......@@ -62,8 +62,7 @@ int main(void)
for (;;)
{
if (Microphone_Audio_Interface.State.InterfaceEnabled)
ProcessNextSample();
ProcessNextSample();
Audio_Device_USBTask(&Microphone_Audio_Interface);
USB_USBTask();
......@@ -95,6 +94,7 @@ void SetupHardware(void)
*/
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_IsReadyForNextSample(&Microphone_Audio_Interface))
{
TIFR0 |= (1 << OCF0A);
......@@ -107,7 +107,7 @@ void ProcessNextSample(void)
AudioSample -= (SAMPLE_MAX_RANGE / 2));
#endif
Audio_Device_WriteSample16(AudioSample);
Audio_Device_WriteSample16(&Microphone_Audio_Interface, AudioSample);
}
}
......
......@@ -43,12 +43,8 @@
#include <avr/pgmspace.h>
/* Macros: */
#if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)
/** Endpoint number of the Audio isochronous streaming data endpoint. */
#define AUDIO_STREAM_EPNUM 1
#else
#define AUDIO_STREAM_EPNUM 3
#endif
/** Endpoint number of the Audio isochronous streaming data endpoint. */
#define AUDIO_STREAM_EPNUM 1
/** Endpoint size in bytes of the Audio isochronous streaming data endpoint. The Windows audio stack requires
* at least 192 bytes for correct output, thus the smaller 128 byte maximum endpoint size on some of the smaller
......
......@@ -46,8 +46,8 @@ USB_ClassInfo_Audio_Device_t Speaker_Audio_Interface =
{
.StreamingInterfaceNumber = 1,
.DataINEndpointNumber = AUDIO_STREAM_EPNUM,
.DataINEndpointSize = AUDIO_STREAM_EPSIZE,
.DataOUTEndpointNumber = AUDIO_STREAM_EPNUM,
.DataOUTEndpointSize = AUDIO_STREAM_EPSIZE,
},
};
......@@ -62,8 +62,7 @@ int main(void)
for (;;)
{
if (Speaker_Audio_Interface.State.InterfaceEnabled)
ProcessNextSample();
ProcessNextSample();
Audio_Device_USBTask(&Speaker_Audio_Interface);
USB_USBTask();
......@@ -90,14 +89,15 @@ void SetupHardware(void)
*/
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 */
TIFR0 |= (1 << OCF0A);
/* Retrieve the signed 16-bit left and right audio samples */
int16_t LeftSample_16Bit = (int16_t)Audio_Device_ReadSample16();
int16_t RightSample_16Bit = (int16_t)Audio_Device_ReadSample16();
int16_t LeftSample_16Bit = Audio_Device_ReadSample16(&Speaker_Audio_Interface);
int16_t RightSample_16Bit = Audio_Device_ReadSample16(&Speaker_Audio_Interface);
/* Massage signed 16-bit left and right audio samples into signed 8-bit */
int8_t LeftSample_8Bit = (LeftSample_16Bit >> 8);
......@@ -124,16 +124,16 @@ void ProcessNextSample(void)
/* Make mixed sample value positive (absolute) */
MixedSample_8Bit = abs(MixedSample_8Bit);
if (MixedSample_8Bit > ((128 / 8) * 1))
if (MixedSample_8Bit > 2)
LEDMask |= LEDS_LED1;
if (MixedSample_8Bit > ((128 / 8) * 2))
if (MixedSample_8Bit > 4)
LEDMask |= LEDS_LED2;
if (MixedSample_8Bit > ((128 / 8) * 3))
if (MixedSample_8Bit > 8)
LEDMask |= LEDS_LED3;
if (MixedSample_8Bit > ((128 / 8) * 4))
if (MixedSample_8Bit > 16)
LEDMask |= LEDS_LED4;
LEDs_SetAllLEDs(LEDMask);
......
......@@ -40,6 +40,7 @@
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/power.h>
#include <stdlib.h>
#include "Descriptors.h"
......
......@@ -43,12 +43,8 @@
#include <avr/pgmspace.h>
/* Macros: */
#if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)
/** Endpoint number of the Audio isochronous streaming data endpoint. */
#define AUDIO_STREAM_EPNUM 1
#else
#define AUDIO_STREAM_EPNUM 3
#endif
/** Endpoint number of the Audio isochronous streaming data endpoint. */
#define AUDIO_STREAM_EPNUM 1
/** Endpoint size in bytes of the Audio isochronous streaming data endpoint. The Windows audio stack requires
* at least 192 bytes for correct output, thus the smaller 128 byte maximum endpoint size on some of the smaller
......
......@@ -137,12 +137,8 @@
*/
#define EP_ACCEPTS_SMALL_PACKETS (0 << 7)
#if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)
/** Endpoint number of the Audio isochronous streaming data endpoint. */
#define AUDIO_STREAM_EPNUM 1
#else
#define AUDIO_STREAM_EPNUM 3
#endif
/** Endpoint number of the Audio isochronous streaming data endpoint. */
#define AUDIO_STREAM_EPNUM 1
/** Endpoint size in bytes of the Audio isochronous streaming data endpoint. The Windows audio stack requires
* at least 192 bytes for correct output, thus the smaller 128 byte maximum endpoint size on some of the smaller
......
......@@ -30,7 +30,7 @@
/** \file
*
* Main source file for the Audio Output demo. This file contains the main tasks of the demo and
* 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.
*/
......@@ -231,16 +231,16 @@ void USB_Audio_Task(void)
/* Make mixed sample value positive (absolute) */
MixedSample_8Bit = abs(MixedSample_8Bit);
if (MixedSample_8Bit > ((128 / 8) * 1))
if (MixedSample_8Bit > 2)
LEDMask |= LEDS_LED1;
if (MixedSample_8Bit > ((128 / 8) * 2))
if (MixedSample_8Bit > 4)
LEDMask |= LEDS_LED2;
if (MixedSample_8Bit > ((128 / 8) * 3))
if (MixedSample_8Bit > 8)
LEDMask |= LEDS_LED3;
if (MixedSample_8Bit > ((128 / 8) * 4))
if (MixedSample_8Bit > 16)
LEDMask |= LEDS_LED4;
LEDs_SetAllLEDs(LEDMask);
......
......@@ -40,6 +40,7 @@
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/power.h>
#include <stdlib.h>
#include "Descriptors.h"
......
......@@ -137,12 +137,8 @@
*/
#define EP_ACCEPTS_SMALL_PACKETS (0 << 7)
#if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)
/** Endpoint number of the Audio isochronous streaming data endpoint. */
#define AUDIO_STREAM_EPNUM 1
#else
#define AUDIO_STREAM_EPNUM 3
#endif
/** Endpoint number of the Audio isochronous streaming data endpoint. */
#define AUDIO_STREAM_EPNUM 1
/** Endpoint size in bytes of the Audio isochronous streaming data endpoint. The Windows audio stack requires
* at least 192 bytes for correct output, thus the smaller 128 byte maximum endpoint size on some of the smaller
......
......@@ -89,75 +89,81 @@ void Audio_Device_USBTask(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo
}
int8_t Audio_Device_ReadSample8(void)
int8_t Audio_Device_ReadSample8(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
{
int8_t Sample;
Sample = Endpoint_Read_Byte();
if (!(Endpoint_IsReadWriteAllowed()))
if (!(Endpoint_BytesInEndpoint()))
Endpoint_ClearOUT();
return Sample;
}
int16_t Audio_Device_ReadSample16(void)
int16_t Audio_Device_ReadSample16(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
{
int16_t Sample;
Sample = (int16_t)Endpoint_Read_Word_LE();
if (!(Endpoint_IsReadWriteAllowed()))
if (!(Endpoint_BytesInEndpoint()))
Endpoint_ClearOUT();
return Sample;
}
int32_t Audio_Device_ReadSample24(void)
int32_t Audio_Device_ReadSample24(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
{
int32_t Sample;
Sample = (((uint32_t)Endpoint_Read_Byte() << 16) | Endpoint_Read_Word_LE());
if (!(Endpoint_IsReadWriteAllowed()))
if (!(Endpoint_BytesInEndpoint()))
Endpoint_ClearOUT();
return Sample;
}
void Audio_Device_WriteSample8(const int8_t Sample)
void Audio_Device_WriteSample8(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo, const int8_t Sample)
{
Endpoint_Write_Byte(Sample);
if (!(Endpoint_IsReadWriteAllowed()))
if (Endpoint_BytesInEndpoint() == AudioInterfaceInfo->Config.DataINEndpointSize)
Endpoint_ClearIN();
}
void Audio_Device_WriteSample16(const int16_t Sample)
void Audio_Device_WriteSample16(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo, const int16_t Sample)
{
Endpoint_Write_Word_LE(Sample);
if (!(Endpoint_IsReadWriteAllowed()))
if (Endpoint_BytesInEndpoint() == AudioInterfaceInfo->Config.DataINEndpointSize)
Endpoint_ClearIN();
}
void Audio_Device_WriteSample24(const int32_t Sample)
void Audio_Device_WriteSample24(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo, const int32_t Sample)
{
Endpoint_Write_Byte(Sample >> 16);
Endpoint_Write_Word_LE(Sample);
if (!(Endpoint_IsReadWriteAllowed()))
if (Endpoint_BytesInEndpoint() == AudioInterfaceInfo->Config.DataINEndpointSize)
Endpoint_ClearIN();
}
bool Audio_Device_IsSampleReceived(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
{
Endpoint_SelectEndpoint(AudioInterfaceInfo->Config.DataOUTEndpointNumber);
if ((USB_DeviceState != DEVICE_STATE_Configured) || !(AudioInterfaceInfo->State.InterfaceEnabled))
return false;
Endpoint_SelectEndpoint(AudioInterfaceInfo->Config.DataOUTEndpointNumber);
return Endpoint_IsOUTReceived();
}
bool Audio_Device_IsReadyForNextSample(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
{
if ((USB_DeviceState != DEVICE_STATE_Configured) || !(AudioInterfaceInfo->State.InterfaceEnabled))
return false;
Endpoint_SelectEndpoint(AudioInterfaceInfo->Config.DataINEndpointNumber);
return Endpoint_IsINReady();
}
......
......@@ -125,54 +125,62 @@
* \note This should be preceeded immediately by a call to the USB_Audio_IsSampleReceived() function to ensure that
* the correct endpoint is selected and ready for data.
*
* \param[in,out] AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
*
* \return Signed 8-bit audio sample from the audio interface
*/
int8_t Audio_Device_ReadSample8(void);
int8_t Audio_Device_ReadSample8(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo);
/** Reads the next 16-bit audio sample from the current audio interface.
*
* \note This should be preceeded immediately by a call to the USB_Audio_IsSampleReceived() function to ensure that
* the correct endpoint is selected and ready for data.
*
* \param[in,out] AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
*
* \return Signed 16-bit audio sample from the audio interface
*/
int16_t Audio_Device_ReadSample16(void);
int16_t Audio_Device_ReadSample16(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo);
/** Reads the next 24-bit audio sample from the current audio interface.
*
* \note This should be preceeded immediately by a call to the USB_Audio_IsSampleReceived() function to ensure that
* the correct endpoint is selected and ready for data.
*
* \param[in,out] AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
* \return Signed 24-bit audio sample from the audio interface
*/
int32_t Audio_Device_ReadSample24(void);
int32_t Audio_Device_ReadSample24(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo);
/** Writes the next 8-bit audio sample to the current audio interface.
*
* \note This should be preceeded immediately by a call to the USB_Audio_IsReadyForNextSample() function to ensure that
* the correct endpoint is selected and ready for data.
*
* \param[in,out] AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
* \param[in] Sample Signed 8-bit audio sample
*/
void Audio_Device_WriteSample8(const int8_t Sample);
void Audio_Device_WriteSample8(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo, const int8_t Sample);
/** Writes the next 16-bit audio sample to the current audio interface.
*
* \note This should be preceeded immediately by a call to the USB_Audio_IsReadyForNextSample() function to ensure that
* the correct endpoint is selected and ready for data.
*
* \param[in,out] AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
* \param[in] Sample Signed 16-bit audio sample
*/
void Audio_Device_WriteSample16(const int16_t Sample);
void Audio_Device_WriteSample16(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo, const int16_t Sample);
/** Writes the next 24-bit audio sample to the current audio interface.
*
* \note This should be preceeded immediately by a call to the USB_Audio_IsReadyForNextSample() function to ensure that
* the correct endpoint is selected and ready for data.
*
* \param[in,out] AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
* \param[in] Sample Signed 24-bit audio sample
*/
void Audio_Device_WriteSample24(const int32_t Sample);
void Audio_Device_WriteSample24(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo, const int32_t Sample);
/** Determines if the given audio interface is ready for a sample to be read from it.
*
......
......@@ -10,52 +10,52 @@
*
* <b>New:</b>
* - Added new class drivers and matching demos to the library for rapid application development
* - Added new PrinterHost demo (thanks to John Andrews)
* - Added USB Missle Launcher project, submitted by Dave Fletcher
* - Added new Benito Arduino Programmer project
* - Added incomplete device and host mode demos for later enhancement
* - Updated MassStorage device block write routines to use ping-pong Dataflash buffering to increase throughput by around 30%
* - Error status LEDs shown when device endpoint configuration fails to complete in all demos and projects
* - Added new USB_Host_SetDeviceConfiguration() convenience function for easy configuration selection of devices while in USB
* host mode
* - Added new USB_Host_ClearPipeStall() convenience function to clear a stall condition on an attached device's endpoint
* - Added new USB_Host_GetDeviceDescriptor() convenience function to retrieve the attached device's Device descriptor
* - Added USB Missle Launcher project, submitted by Dave Fletcher
* - Added new Endpoint_ClearStatusStage() convenience function to assist with the status stages of control transfers
* - Added new USE_INTERNAL_SERIAL define for using the unique serial numbers in some AVR models as the USB device's serial number,
* added NO_INTERNAL_SERIAL compile time option to turn off new serial number reading code
* - Added new DATAFLASH_CHIP_MASK() macro to the Dataflash driver, which returns the Dataflash select mask for the given chip index
* - Updated MassStorage device block write routines to use ping-pong Dataflash buffering to increase throughput by around 30%
* - Added new HOST_STATE_WaitForDeviceRemoval host state machine state for non-blocking disabling of device communications until the
* device has been removed (for use when an error occurs or communications with the device have completed)
* - Added new FAST_STREAM_TRANSFERS compile time option for faster stream transfers via multiple bytes copied per stream loop
* - Added stdio stream demo code to the low-level CDC demo, to show how to create standard streams out of the virtual serial ports
* - Added stdio stream demo code to the CDC device demos, to show how to create standard streams out of the virtual serial ports
* - Added new EEPROM and FLASH buffer versions of the Endpoint and Pipe stream functions
* - Added new USE_FLASH_DESCRIPTORS and TOTAL_NUM_CONFIGURATIONS compile time options
* - Added support for the new ATMEGA32U2, ATMEGA16U2 and ATMEGA8U2 AVR models
* - Added new PrinterHost demo (thanks to John Andrews)
* - Added new USB_DeviceState variable to keep track of the current Device mode USB state
* - Added new Endpoint_ClearStatusStage() convenience function to assist with the status stages of control transfers
* - Added new Benito Arduino Programmer project
* - Added new LEDs_ToggleLEDs() function to the LEDs driver
* - Added new Pipe_BoundEndpointNumber() and Pipe_IsEndpointBound() functions
* - Added new DEVICE_STATE_AS_GPIOR and HOST_STATE_AS_GPIOR compile time options
* - Added 404 errors to the Webserver in the RNDIS demos to indicate invalid URLs
* - Added 404 Not Found errors to the webserver in the RNDIS demos to indicate invalid URLs
*
* <b>Changed:</b>
* - Deprecated psuedo-scheduler and removed dynamic memory allocator from the library (first no longer needed and second unused)
* - The device-mode CALLBACK_USB_GetDescriptor() function now has an extra parameter so that the memory space in which the requested
* descriptor is located can be specified. This means that descriptors can now be located in multiple memory spaces within a device.
* - Removed vague USB_IsConnected global - test USB_DeviceState or USB_HostState explicitly to gain previous functionality
* - Removed USB_IsSuspended global - test USB_DeviceState against DEVICE_STATE_Suspended instead
* - Extended USB_GetDeviceConfigDescriptor() routine to require the configuration number within the device to fetch
* - Dataflash_WaitWhileBusy() now always ensures that the dataflash is ready for the next command immediately after returning,
* no need to call Dataflash_ToggleSelectedChipCS() afterwards
* - Low level API MIDI device demo no longer blocks if a note change event is sent while the endpoint is not ready
* - Internal per-device preprocessing conditions changed to per-device series rather than per controller group for finer-grain
* internal control
* - Pipe_GetErrorFlags() now returns additional error flags for overflow and underflow errors
* - Extended USB_GetDeviceConfigDescriptor() routine to require the configuration number within the device to fetch
* - Pipe stream functions now automatically set the correct pipe token, so that bidirectional pipes can be used
* - Pipe_ConfigurePipe() now automatically defaults IN pipes to accepting infinite IN requests, this can still be changed by calling
* the existing Pipe_SetFiniteINRequests() function
* - Dataflash_WaitWhileBusy() now always ensures that the dataflash is ready for the next command immediately after returning,
* no need to call Dataflash_ToggleSelectedChipCS() afterwards
* - Changed F_CLOCK entries in project makefiles to alias to F_CPU by default, as this is the most common case
* - The device-mode CALLBACK_USB_GetDescriptor() function now has an extra parameter so that the memory space in which the requested
* descriptor is located can be specified. This means that descriptors can now be located in multiple memory spaces within a device.
* - Host mode demos now use sane terminal escape codes, so that text is always readable and events/program output is visually distinguished
* from oneanother using foreground colours
* - Removed vague USB_IsConnected global - test USB_DeviceState or USB_HostState explicitly to gain previous functionality
* - Removed USB_IsSuspended global - test USB_DeviceState against DEVICE_STATE_Suspended instead
* - Internal per-device preprocessing conditions changed to per-device series rather than per-controller group for finer-grain
* internal control
*
* <b>Fixed:</b>
* - Changed bootloaders to use FLASHEND rather than the existence of RAMPZ to determine if far FLASH pointers are needed to fix
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment