Added default test tone generation mode to the Device mode AudioInput demos.

pull/1469/head
Dean Camera 14 years ago
parent 06f222b3ed
commit bd337aced3

@ -82,9 +82,10 @@ void SetupHardware(void)
/* Hardware Initialization */ /* Hardware Initialization */
LEDs_Init(); LEDs_Init();
USB_Init(); Buttons_Init();
ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32); ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32);
ADC_SetupChannel(MIC_IN_ADC_CHANNEL); ADC_SetupChannel(MIC_IN_ADC_CHANNEL);
USB_Init();
/* Start the ADC conversion in free running mode */ /* Start the ADC conversion in free running mode */
ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | MIC_IN_ADC_MUX_MASK); ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | MIC_IN_ADC_MUX_MASK);
@ -100,15 +101,29 @@ void ProcessNextSample(void)
{ {
/* Clear the sample reload timer compare flag, ready for the next interval */ /* Clear the sample reload timer compare flag, ready for the next interval */
TIFR0 |= (1 << OCF0A); TIFR0 |= (1 << OCF0A);
/* Audio sample is ADC value scaled to fit the entire range */ int16_t AudioSample;
int16_t AudioSample = ((SAMPLE_MAX_RANGE / ADC_MAX_RANGE) * ADC_GetResult());
#if defined(USE_TEST_TONE)
#if defined(MICROPHONE_BIASED_TO_HALF_RAIL) static uint8_t SquareWaveSampleCount;
/* Microphone is biased to half rail voltage, subtract the bias from the sample value */ static int16_t CurrentWaveValue;
AudioSample -= (SAMPLE_MAX_RANGE / 2);
/* In test tone mode, generate a square wave at 1/256 of the sample rate */
if (SquareWaveSampleCount++ == 0xFF)
CurrentWaveValue ^= 0x8000;
/* Only generate audio if the board button is being pressed */
AudioSample = (Buttons_GetStatus() & BUTTONS_BUTTON1) ? CurrentWaveValue : 0;
#else
/* Audio sample is ADC value scaled to fit the entire range */
AudioSample = ((SAMPLE_MAX_RANGE / ADC_MAX_RANGE) * ADC_GetResult());
#if defined(MICROPHONE_BIASED_TO_HALF_RAIL)
/* Microphone is biased to half rail voltage, subtract the bias from the sample value */
AudioSample -= (SAMPLE_MAX_RANGE / 2);
#endif
#endif #endif
Audio_Device_WriteSample16(&Microphone_Audio_Interface, AudioSample); Audio_Device_WriteSample16(&Microphone_Audio_Interface, AudioSample);
} }
} }

@ -44,6 +44,7 @@
#include <LUFA/Version.h> #include <LUFA/Version.h>
#include <LUFA/Drivers/Board/LEDs.h> #include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/Board/Buttons.h>
#include <LUFA/Drivers/Peripheral/ADC.h> #include <LUFA/Drivers/Peripheral/ADC.h>
#include <LUFA/Drivers/USB/USB.h> #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/USB/Class/Audio.h> #include <LUFA/Drivers/USB/Class/Audio.h>

@ -50,11 +50,13 @@
* basic USB Audio 1.0 drivers in all modern OSes (i.e. no special drivers * basic USB Audio 1.0 drivers in all modern OSes (i.e. no special drivers
* required). * required).
* *
* On start-up the system will automatically enumerate and function * On start-up the system will automatically enumerate and function as a
* as a USB microphone. Incoming audio from the ADC channel 1 will * USB microphone. By default, the demo will produce a square wave test tone
* be sampled and sent to the host computer. * when the board button is pressed. If USE_TEST_TONE is not defined in the
* project makefile, incoming audio from the ADC channel 1 will be sampled
* and sent to the host computer instead.
* *
* To use, connect a microphone to the ADC channel 1. * When in microphone mode, connect a microphone to the ADC channel 2.
* *
* Under Windows, if a driver request dialogue pops up, select the option * Under Windows, if a driver request dialogue pops up, select the option
* to automatically install the appropriate drivers. * to automatically install the appropriate drivers.
@ -70,6 +72,12 @@
* <td><b>Description:</b></td> * <td><b>Description:</b></td>
* </tr> * </tr>
* <tr> * <tr>
* <td>USE_TEST_TONE</td>
* <td>Makefile LUFA_OPTS</td>
* <td>When defined, this alters the demo to produce a square wave test tone when the first board button is pressed
* instead of sampling the board microphone.</td>
* </tr>
* <tr>
* <td>MICROPHONE_BIASED_TO_HALF_RAIL</td> * <td>MICROPHONE_BIASED_TO_HALF_RAIL</td>
* <td>Makefile LUFA_OPTS</td> * <td>Makefile LUFA_OPTS</td>
* <td>When defined, this alters the demo so that the half VCC bias of the microphone input is subtracted.</td> * <td>When defined, this alters the demo so that the half VCC bias of the microphone input is subtracted.</td>

@ -123,6 +123,7 @@ LUFA_OPTS += -D USE_FLASH_DESCRIPTORS
LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
LUFA_OPTS += -D MICROPHONE_BIASED_TO_HALF_RAIL LUFA_OPTS += -D MICROPHONE_BIASED_TO_HALF_RAIL
LUFA_OPTS += -D USE_TEST_TONE
# Create the LUFA source path variables by including the LUFA root makefile # Create the LUFA source path variables by including the LUFA root makefile

@ -68,6 +68,7 @@ void SetupHardware(void)
/* Hardware Initialization */ /* Hardware Initialization */
LEDs_Init(); LEDs_Init();
Buttons_Init();
ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32); ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32);
ADC_SetupChannel(MIC_IN_ADC_CHANNEL); ADC_SetupChannel(MIC_IN_ADC_CHANNEL);
USB_Init(); USB_Init();
@ -164,13 +165,27 @@ void USB_Audio_Task(void)
/* Clear the sample reload timer */ /* Clear the sample reload timer */
TIFR0 |= (1 << OCF0A); TIFR0 |= (1 << OCF0A);
/* Audio sample is ADC value scaled to fit the entire range */ int16_t AudioSample;
int16_t AudioSample = ((SAMPLE_MAX_RANGE / ADC_MAX_RANGE) * ADC_GetResult());
#if defined(USE_TEST_TONE)
#if defined(MICROPHONE_BIASED_TO_HALF_RAIL) static uint8_t SquareWaveSampleCount;
/* Microphone is biased to half rail voltage, subtract the bias from the sample value */ static int16_t CurrentWaveValue;
AudioSample -= (SAMPLE_MAX_RANGE / 2);
#endif /* In test tone mode, generate a square wave at 1/256 of the sample rate */
if (SquareWaveSampleCount++ == 0xFF)
CurrentWaveValue ^= 0x8000;
/* Only generate audio if the board button is being pressed */
AudioSample = (Buttons_GetStatus() & BUTTONS_BUTTON1) ? CurrentWaveValue : 0;
#else
/* Audio sample is ADC value scaled to fit the entire range */
AudioSample = ((SAMPLE_MAX_RANGE / ADC_MAX_RANGE) * ADC_GetResult());
#if defined(MICROPHONE_BIASED_TO_HALF_RAIL)
/* Microphone is biased to half rail voltage, subtract the bias from the sample value */
AudioSample -= (SAMPLE_MAX_RANGE / 2);
#endif
#end if
/* Write the sample to the buffer */ /* Write the sample to the buffer */
Endpoint_Write_Word_LE(AudioSample); Endpoint_Write_Word_LE(AudioSample);

@ -47,6 +47,7 @@
#include <LUFA/Version.h> #include <LUFA/Version.h>
#include <LUFA/Drivers/USB/USB.h> #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Board/LEDs.h> #include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/Board/Buttons.h>
#include <LUFA/Drivers/Peripheral/ADC.h> #include <LUFA/Drivers/Peripheral/ADC.h>
/* Macros: */ /* Macros: */

@ -50,11 +50,13 @@
* basic USB Audio 1.0 drivers in all modern OSes (i.e. no special drivers * basic USB Audio 1.0 drivers in all modern OSes (i.e. no special drivers
* required). * required).
* *
* On start-up the system will automatically enumerate and function * On start-up the system will automatically enumerate and function as a
* as a USB microphone. Incoming audio from the ADC channel 1 will * USB microphone. By default, the demo will produce a square wave test tone
* be sampled and sent to the host computer. * when the board button is pressed. If USE_TEST_TONE is not defined in the
* project makefile, incoming audio from the ADC channel 1 will be sampled
* and sent to the host computer instead.
* *
* To use, connect a microphone to the ADC channel 2. * When in microphone mode, connect a microphone to the ADC channel 2.
* *
* Under Windows, if a driver request dialogue pops up, select the option * Under Windows, if a driver request dialogue pops up, select the option
* to automatically install the appropriate drivers. * to automatically install the appropriate drivers.
@ -70,6 +72,12 @@
* <td><b>Description:</b></td> * <td><b>Description:</b></td>
* </tr> * </tr>
* <tr> * <tr>
* <td>USE_TEST_TONE</td>
* <td>Makefile LUFA_OPTS</td>
* <td>When defined, this alters the demo to produce a square wave test tone when the first board button is pressed
* instead of sampling the board microphone.</td>
* </tr>
* <tr>
* <td>MICROPHONE_BIASED_TO_HALF_RAIL</td> * <td>MICROPHONE_BIASED_TO_HALF_RAIL</td>
* <td>Makefile LUFA_OPTS</td> * <td>Makefile LUFA_OPTS</td>
* <td>When defined, this alters the demo so that the half VCC bias of the microphone input is subtracted.</td> * <td>When defined, this alters the demo so that the half VCC bias of the microphone input is subtracted.</td>

@ -123,6 +123,7 @@ LUFA_OPTS += -D USE_FLASH_DESCRIPTORS
LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
LUFA_OPTS += -D MICROPHONE_BIASED_TO_HALF_RAIL LUFA_OPTS += -D MICROPHONE_BIASED_TO_HALF_RAIL
LUFA_OPTS += -D USE_TEST_TONE
# Create the LUFA source path variables by including the LUFA root makefile # Create the LUFA source path variables by including the LUFA root makefile

@ -27,6 +27,7 @@
* - Added board hardware driver support for the Blackcat USB JTAG board (thanks to the PSGroove team) * - Added board hardware driver support for the Blackcat USB JTAG board (thanks to the PSGroove team)
* - Added board hardware driver support for the Maximus board (thanks to the PSGroove team) * - Added board hardware driver support for the Maximus board (thanks to the PSGroove team)
* - Added board hardware driver support for the Minimus board (thanks to the PSGroove team) * - Added board hardware driver support for the Minimus board (thanks to the PSGroove team)
* - Added default test tone generation mode to the Device mode AudioInput demos
* *
* <b>Changed:</b> * <b>Changed:</b>
* - Removed complicated logic for the Endpoint_ConfigureEndpoint() function to use inlined or function called versions * - Removed complicated logic for the Endpoint_ConfigureEndpoint() function to use inlined or function called versions

@ -7,7 +7,7 @@
/** \page Page_FutureChanges Future Changes /** \page Page_FutureChanges Future Changes
* *
* Below is a list of future changes which are proposed for the LUFA library, but not yet started/complete. * Below is a list of future changes which are proposed for the LUFA library, but not yet started/complete.
* This gives an unordered list of future changes which will be available in future releases of the library. * This gives an unordered list of future changes which may be available in future releases of the library.
* If you have an item to add to this list, please contact the library author via email, the LUFA mailing list, * If you have an item to add to this list, please contact the library author via email, the LUFA mailing list,
* or post your suggestion as an enhancement request to the project bug tracker. * or post your suggestion as an enhancement request to the project bug tracker.
* *
@ -18,9 +18,10 @@
* -# Add ability to get number of bytes not written with pipe/endpoint write routines after an error * -# Add ability to get number of bytes not written with pipe/endpoint write routines after an error
* -# Change makefiles to allow for absolute LUFA location to be used * -# Change makefiles to allow for absolute LUFA location to be used
* -# Re-add interrupt Pipe/Endpoint support * -# Re-add interrupt Pipe/Endpoint support
* -# Fix intermittent device mode enumeration errors
* -# Add HID report macros to make HID report editing easier * -# Add HID report macros to make HID report editing easier
* -# Add endpoint/pipe bank kill macros * -# Add endpoint/pipe bank kill macros
* -# Investigate dynamically created device descriptors
* -# Add new event for EVENT_USB_Device_ControlRequest() fired before the internal library request handlers
* - Documentation/Support * - Documentation/Support
* -# Add detailed overviews of how each demo works * -# Add detailed overviews of how each demo works
* -# Add board overviews * -# Add board overviews

Loading…
Cancel
Save