-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
S2DFM Update and a number of examples (#555)
* updated gitignore to avoid nested build folders in examples. * started adding a few more basic examples * more basic examples. * modernized gate input class to accept new Pin object, and mark old init as deprecated. * added Gate Input Example * added example for working with four channel audio using two codecs. * added a few helper functions for retrieving the configured SAI Handle from the Initialized Daisy * updated the external codec init to use new DaisySeed function to simplify example * added DAC example (polling only for now) * added OLED w/ hardware SPI example * added MIDI and SDMMC examples - both could use some improvement * set speed to standard 25MHz for maximum compatibility with custom hardware. * revert launch.json to libDaisy master branch state. * updated changelog with s2dfm, and gatein changes. --------- Co-authored-by: stephenhensley <stephen.p.hensley@gmail.com>
- Loading branch information
1 parent
5f1d862
commit b65a1ba
Showing
32 changed files
with
1,062 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,5 +130,5 @@ vs/*.log | |
|
||
tests/libDaisy_gtest | ||
tests/build/bin/ | ||
examples/*/build/ | ||
examples/**/build/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** Example of initializing multiple ADC inputs */ | ||
#include "daisy_seed.h" | ||
|
||
/** This prevents us from having to type "daisy::" in front of a lot of things. */ | ||
using namespace daisy; | ||
|
||
/** Global Hardware access */ | ||
DaisySeed hw; | ||
|
||
int main(void) | ||
{ | ||
/** Initialize our hardware */ | ||
hw.Init(); | ||
|
||
/** Configure the ADC | ||
* | ||
* Three CV inputs (-5V to 5V -> 3V3 to 0V) | ||
* A0, A6, and A2 | ||
* | ||
* This example was made for the Daisy Seed2 DFM, but the pins can be swapped for other hardware. | ||
*/ | ||
AdcChannelConfig adc_cfg[3]; | ||
adc_cfg[0].InitSingle(seed::A0); | ||
adc_cfg[1].InitSingle(seed::A6); | ||
adc_cfg[2].InitSingle(seed::A2); | ||
|
||
/** Initialize the ADC with our configuration */ | ||
hw.adc.Init(adc_cfg, 3); | ||
|
||
/** Start the ADC conversions in the background */ | ||
hw.adc.Start(); | ||
|
||
/** Startup the USB Serial port */ | ||
hw.StartLog(); | ||
|
||
/** Infinite Loop */ | ||
while(1) | ||
{ | ||
/** Print the values via Serial every 250ms | ||
* Values will be 0 when inputs are 0V | ||
* Values will be 65536 when inputs are 3v3 | ||
* | ||
* Based on the CV input circuit this means that | ||
* Values will be 0 when input is 5V | ||
* Values will be ~32768 when input is ~0V | ||
* Values will be 65536 when input is -5V | ||
*/ | ||
System::Delay(250); | ||
hw.PrintLine("Input 1: %d", hw.adc.Get(0)); | ||
hw.PrintLine("Input 2: %d", hw.adc.Get(1)); | ||
hw.PrintLine("Input 3: %d", hw.adc.Get(2)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Project Name | ||
TARGET = ADCMulti | ||
|
||
# Sources | ||
CPP_SOURCES = ADCMulti.cpp | ||
|
||
# Library Locations | ||
LIBDAISY_DIR = ../.. | ||
|
||
# Core location, and generic Makefile. | ||
SYSTEM_FILES_DIR = $(LIBDAISY_DIR)/core | ||
include $(SYSTEM_FILES_DIR)/Makefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** Example of using a CD4051 multiplexor to expand the ADC inputs */ | ||
#include "daisy_seed.h" | ||
|
||
/** This prevents us from having to type "daisy::" in front of a lot of things. */ | ||
using namespace daisy; | ||
|
||
/** Global Hardware access */ | ||
DaisySeed hw; | ||
|
||
int main(void) | ||
{ | ||
/** Initialize our hardware */ | ||
hw.Init(); | ||
|
||
/** Configure the ADC | ||
* | ||
* One channel configured for four inputs via CD4051 mux | ||
* The Analog signal coming from the multiplexor is connected to pin A3 | ||
* The select pins from the Daisy are D12, and D31 (we only need two SEL pins since we're using 4 inputs) | ||
* | ||
* This example was made for the Daisy Seed2 DFM, but the pins can be swapped for other hardware. | ||
*/ | ||
AdcChannelConfig adc_cfg; | ||
adc_cfg.InitMux(seed::A3, 4, seed::D12, seed::D31); | ||
|
||
/** Initialize the ADC with our configuration */ | ||
hw.adc.Init(&adc_cfg, 1); | ||
|
||
/** Start the ADC conversions in the background */ | ||
hw.adc.Start(); | ||
|
||
/** Startup the USB Serial port */ | ||
hw.StartLog(); | ||
|
||
/** Infinite Loop */ | ||
while(1) | ||
{ | ||
/** Print the values via Serial every 250ms | ||
* Values will be 0 when inputs are 0V | ||
* Values will be 65536 when inputs are 3v3 | ||
*/ | ||
System::Delay(250); | ||
hw.PrintLine("Input 1: %d", hw.adc.GetMux(0, 0)); | ||
hw.PrintLine("Input 2: %d", hw.adc.GetMux(0, 1)); | ||
hw.PrintLine("Input 3: %d", hw.adc.GetMux(0, 2)); | ||
hw.PrintLine("Input 4: %d", hw.adc.GetMux(0, 3)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Project Name | ||
TARGET = ADCMux | ||
|
||
# Sources | ||
CPP_SOURCES = ADCMux.cpp | ||
|
||
# Library Locations | ||
LIBDAISY_DIR = ../.. | ||
|
||
# Core location, and generic Makefile. | ||
SYSTEM_FILES_DIR = $(LIBDAISY_DIR)/core | ||
include $(SYSTEM_FILES_DIR)/Makefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** Generation of a simple Audio signal */ | ||
#include "daisy_seed.h" | ||
#include <cmath> | ||
|
||
/** This prevents us from having to type "daisy::" in front of a lot of things. */ | ||
using namespace daisy; | ||
|
||
/** An increment for generating a 220Hz wave form at 48kHz sample rate | ||
* Check out DaisySP for a more complete Oscillator implementation for your project. | ||
*/ | ||
const float kSignalIncrement = (M_TWOPI * 220) * (1.0 / 48000); | ||
|
||
/** Global Hardware access */ | ||
DaisySeed hw; | ||
|
||
/** Global phase value for generated signal */ | ||
float phs; | ||
|
||
/** Function that gets called at a regular interval by the hardware to | ||
* process, and/or generate audio signals | ||
*/ | ||
void AudioCallback(AudioHandle::InputBuffer in, | ||
AudioHandle::OutputBuffer out, | ||
size_t size) | ||
{ | ||
for(size_t i = 0; i < size; i++) | ||
{ | ||
/** | ||
* Generate the next sample of our output signal | ||
* | ||
* This is a very basic sine-wave oscillator with a fixed increment to generate | ||
* a 220Hz waveform at 48kHz samplerate | ||
*/ | ||
float signal = sin(phs) * 0.5f; | ||
phs += kSignalIncrement; | ||
if(phs > M_TWOPI) | ||
phs -= M_TWOPI; | ||
|
||
/** Set each of our outputs to the value of this sine wave */ | ||
OUT_L[i] = signal; | ||
OUT_R[i] = signal; | ||
} | ||
} | ||
|
||
int main(void) | ||
{ | ||
/** Initialize our hardware */ | ||
hw.Init(); | ||
|
||
/** Set our initial phs value for the oscillator to 0 */ | ||
phs = 0.0; | ||
|
||
/** Start the Audio engine, and call the "AudioCallback" function to fill new data */ | ||
hw.StartAudio(AudioCallback); | ||
|
||
/** Infinite Loop */ | ||
while(1) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Project Name | ||
TARGET = AudioOutput | ||
|
||
# Sources | ||
CPP_SOURCES = AudioOutput.cpp | ||
|
||
# Library Locations | ||
LIBDAISY_DIR = ../.. | ||
|
||
# Core location, and generic Makefile. | ||
SYSTEM_FILES_DIR = $(LIBDAISY_DIR)/core | ||
include $(SYSTEM_FILES_DIR)/Makefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** Demonstration of running audio through the codec | ||
* Passes the audio input directly out to the audio output. | ||
*/ | ||
#include "daisy_seed.h" | ||
|
||
/** This prevents us from having to type "daisy::" in front of a lot of things. */ | ||
using namespace daisy; | ||
|
||
/** Global Hardware access */ | ||
DaisySeed hw; | ||
|
||
/** Function that gets called at a regular interval by the hardware to | ||
* process, and/or generate audio signals | ||
*/ | ||
void AudioCallback(AudioHandle::InputBuffer in, | ||
AudioHandle::OutputBuffer out, | ||
size_t size) | ||
{ | ||
for(size_t i = 0; i < size; i++) | ||
{ | ||
/** Set each of our outputs to the value of this sine wave */ | ||
OUT_L[i] = IN_L[i]; | ||
OUT_R[i] = IN_R[i]; | ||
} | ||
} | ||
|
||
int main(void) | ||
{ | ||
/** Initialize our hardware */ | ||
hw.Init(); | ||
|
||
/** Start the Audio engine, and call the "AudioCallback" function to fill new data */ | ||
hw.StartAudio(AudioCallback); | ||
|
||
/** Infinite Loop */ | ||
while(1) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Project Name | ||
TARGET = AudioPassthru | ||
|
||
# Sources | ||
CPP_SOURCES = AudioPassthru.cpp | ||
|
||
# Library Locations | ||
LIBDAISY_DIR = ../.. | ||
|
||
# Core location, and generic Makefile. | ||
SYSTEM_FILES_DIR = $(LIBDAISY_DIR)/core | ||
include $(SYSTEM_FILES_DIR)/Makefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** Example of DAC Output using basic Polling implementation | ||
* | ||
* This will use A8 to demonstrate DAC output | ||
* This will generate a ramp wave from 0-3v3 | ||
* | ||
* A7 will output a ramp, and output A8 will output an inverted ramp | ||
*/ | ||
#include "daisy_seed.h" | ||
|
||
/** This prevents us from having to type "daisy::" in front of a lot of things. */ | ||
using namespace daisy; | ||
|
||
/** Global Hardware access */ | ||
DaisySeed hw; | ||
|
||
int main(void) | ||
{ | ||
/** Initialize our hardware */ | ||
hw.Init(); | ||
|
||
/** Configure and Initialize the DAC */ | ||
DacHandle::Config dac_cfg; | ||
dac_cfg.bitdepth = DacHandle::BitDepth::BITS_12; | ||
dac_cfg.buff_state = DacHandle::BufferState::ENABLED; | ||
dac_cfg.mode = DacHandle::Mode::POLLING; | ||
dac_cfg.chn = DacHandle::Channel::BOTH; | ||
hw.dac.Init(dac_cfg); | ||
|
||
/** Variable for output */ | ||
int output_val_1 = 0; | ||
int output_val_2 = 0; | ||
|
||
/** Infinite Loop */ | ||
while(1) | ||
{ | ||
/** Every 1millisecond we'll increment our 12-bit value | ||
* The value will go from 0-4095 | ||
* The full ramp waveform will have a period of about 4 seconds | ||
* The secondary waveform will be an inverted ramp (saw) | ||
* at the same frequency | ||
*/ | ||
System::Delay(1); | ||
|
||
/** increment our output value, and wrap around if it goes out range. */ | ||
output_val_1 += 1; | ||
if(output_val_1 > 4095) | ||
output_val_1 = 0; | ||
|
||
/** This sets our second output to the opposite of the first */ | ||
output_val_2 = 4095 - output_val_1; | ||
|
||
/** And write our 12-bit value to the output */ | ||
hw.dac.WriteValue(DacHandle::Channel::ONE, output_val_1); | ||
hw.dac.WriteValue(DacHandle::Channel::TWO, output_val_2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Project Name | ||
TARGET = DAC_Polling_Output | ||
|
||
# Sources | ||
CPP_SOURCES = DAC_Polling_Output.cpp | ||
|
||
# Library Locations | ||
LIBDAISY_DIR = ../.. | ||
|
||
# Core location, and generic Makefile. | ||
SYSTEM_FILES_DIR = $(LIBDAISY_DIR)/core | ||
include $(SYSTEM_FILES_DIR)/Makefile |
Oops, something went wrong.