aboutsummaryrefslogtreecommitdiffstats
path: root/Demos/Device/ClassDriver
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-10-20 07:39:11 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-10-20 07:39:11 +0000
commitbd337aced3b1888373030878bf1a49367bc37ab5 (patch)
treeb2633f86bc8d5155659cc9eae31672ff3958c07e /Demos/Device/ClassDriver
parent06f222b3ed6f612f4ac1b21566547797d4db8013 (diff)
downloadlufa-bd337aced3b1888373030878bf1a49367bc37ab5.tar.gz
lufa-bd337aced3b1888373030878bf1a49367bc37ab5.tar.bz2
lufa-bd337aced3b1888373030878bf1a49367bc37ab5.zip
Added default test tone generation mode to the Device mode AudioInput demos.
Diffstat (limited to 'Demos/Device/ClassDriver')
-rw-r--r--Demos/Device/ClassDriver/AudioInput/AudioInput.c33
-rw-r--r--Demos/Device/ClassDriver/AudioInput/AudioInput.h1
-rw-r--r--Demos/Device/ClassDriver/AudioInput/AudioInput.txt16
-rw-r--r--Demos/Device/ClassDriver/AudioInput/makefile1
4 files changed, 38 insertions, 13 deletions
diff --git a/Demos/Device/ClassDriver/AudioInput/AudioInput.c b/Demos/Device/ClassDriver/AudioInput/AudioInput.c
index dc7a076e4..54e70f6b1 100644
--- a/Demos/Device/ClassDriver/AudioInput/AudioInput.c
+++ b/Demos/Device/ClassDriver/AudioInput/AudioInput.c
@@ -82,9 +82,10 @@ void SetupHardware(void)
/* Hardware Initialization */
LEDs_Init();
- USB_Init();
+ Buttons_Init();
ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32);
ADC_SetupChannel(MIC_IN_ADC_CHANNEL);
+ USB_Init();
/* Start the ADC conversion in free running mode */
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 */
TIFR0 |= (1 << OCF0A);
-
- /* Audio sample is ADC value scaled to fit the entire range */
- int16_t 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);
+
+ int16_t AudioSample;
+
+ #if defined(USE_TEST_TONE)
+ static uint8_t SquareWaveSampleCount;
+ static int16_t CurrentWaveValue;
+
+ /* 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
-
+
Audio_Device_WriteSample16(&Microphone_Audio_Interface, AudioSample);
}
}
diff --git a/Demos/Device/ClassDriver/AudioInput/AudioInput.h b/Demos/Device/ClassDriver/AudioInput/AudioInput.h
index 8ed6096f0..741a091d0 100644
--- a/Demos/Device/ClassDriver/AudioInput/AudioInput.h
+++ b/Demos/Device/ClassDriver/AudioInput/AudioInput.h
@@ -44,6 +44,7 @@
#include <LUFA/Version.h>
#include <LUFA/Drivers/Board/LEDs.h>
+ #include <LUFA/Drivers/Board/Buttons.h>
#include <LUFA/Drivers/Peripheral/ADC.h>
#include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/USB/Class/Audio.h>
diff --git a/Demos/Device/ClassDriver/AudioInput/AudioInput.txt b/Demos/Device/ClassDriver/AudioInput/AudioInput.txt
index 830163f3b..fea31b66e 100644
--- a/Demos/Device/ClassDriver/AudioInput/AudioInput.txt
+++ b/Demos/Device/ClassDriver/AudioInput/AudioInput.txt
@@ -50,11 +50,13 @@
* basic USB Audio 1.0 drivers in all modern OSes (i.e. no special drivers
* required).
*
- * On start-up the system will automatically enumerate and function
- * as a USB microphone. Incoming audio from the ADC channel 1 will
- * be sampled and sent to the host computer.
+ * On start-up the system will automatically enumerate and function as a
+ * USB microphone. By default, the demo will produce a square wave test tone
+ * 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
* to automatically install the appropriate drivers.
@@ -70,6 +72,12 @@
* <td><b>Description:</b></td>
* </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>Makefile LUFA_OPTS</td>
* <td>When defined, this alters the demo so that the half VCC bias of the microphone input is subtracted.</td>
diff --git a/Demos/Device/ClassDriver/AudioInput/makefile b/Demos/Device/ClassDriver/AudioInput/makefile
index 8eda3c68b..3c26c97ed 100644
--- a/Demos/Device/ClassDriver/AudioInput/makefile
+++ b/Demos/Device/ClassDriver/AudioInput/makefile
@@ -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 MICROPHONE_BIASED_TO_HALF_RAIL
+LUFA_OPTS += -D USE_TEST_TONE
# Create the LUFA source path variables by including the LUFA root makefile