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