Skip to content

Commit

Permalink
Merge pull request #1 from electro-smith/more-isolated-examples
Browse files Browse the repository at this point in the history
Additional hardware-specific examples
  • Loading branch information
stephenhensley authored Jun 28, 2023
2 parents f1c494e + e0caed5 commit c2c91b3
Show file tree
Hide file tree
Showing 10 changed files with 407 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"compilerPath": "C:/Program Files/DaisyToolchain/bin/arm-none-eabi-gcc.exe",
"includePath": [
"${workspaceFolder}/BasicExample/**",
"${workspaceFolder}/PassthruAndBypass/**",
"${workspaceFolder}/SimplePotReading/**",
"${workspaceFolder}/SimpleSwitchReading/**",
"${workspaceFolder}/libs/libDaisy/**",
"${workspaceFolder}/libs/DaisySP/**"
],
Expand All @@ -24,6 +27,9 @@
"compilerPath": "/usr/bin/arm-none-eabi-gcc",
"includePath": [
"${workspaceFolder}/BasicExample/**",
"${workspaceFolder}/PassthruAndBypass/**",
"${workspaceFolder}/SimplePotReading/**",
"${workspaceFolder}/SimpleSwitchReading/**",
"${workspaceFolder}/libs/libDaisy/**",
"${workspaceFolder}/libs/DaisySP/**"
],
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"reset init",
"gdb_breakpoint_override hard"
],
"preLaunchTask": "Build",
"preLaunchTask": "BasicExample - Build",
"preRestartCommands": [
"load",
"enable breakpoint",
Expand Down
161 changes: 158 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,59 @@
"problemMatcher": [],
"type": "shell"
},
// Tasks for operations on the selected file's example.
{
"label": "Build",
"command": "make",
"options": {
"cwd": "${workspaceFolder}/BasicExample"
"cwd": "${fileDirname}"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [],
"type": "shell"
},
{
"label": "Clean",
"command": "make clean",
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [],
"type": "shell"
},
{
"label": "Program-DFU",
"command": "make program-dfu",
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [],
"type": "shell"
},
// BasicExample Tasks
{
"label": "BasicExample - Build",
"command": "make",
"options": {
"cwd": "${workspaceFolder}/BasicExample"
},
"problemMatcher": [],
"type": "shell"
},
{
"label": "BasicExample - Clean",
"command": "make clean",
"options": {
"cwd": "${workspaceFolder}/BasicExample"
},
"problemMatcher": [],
"type": "shell"
},
{
"label": "Program DFU",
"label": "BasicExample - Program DFU",
"command": "make program-dfu",
"options": {
"cwd": "${workspaceFolder}/BasicExample"
Expand All @@ -37,13 +70,135 @@
"type": "shell"
},
{
"label": "Rebuild and Program DFU",
"label": "BasicExample - Rebuild and Program DFU",
"command": "make clean; make; make program-dfu",
"options": {
"cwd": "${workspaceFolder}/BasicExample"
},
"problemMatcher": [],
"type": "shell"
},
// SimplePotReading Tasks
{
"label": "SimplePotReading - Build",
"command": "make",
"options": {
"cwd": "${workspaceFolder}/SimplePotReading"
},
"problemMatcher": [],
"type": "shell"
},
{
"label": "SimplePotReading - Clean",
"command": "make clean",
"options": {
"cwd": "${workspaceFolder}/SimplePotReading"
},
"problemMatcher": [],
"type": "shell"
},
{
"label": "SimplePotReading - Program DFU",
"command": "make program-dfu",
"options": {
"cwd": "${workspaceFolder}/SimplePotReading"
},
"problemMatcher": [],
"type": "shell"
},
{
"label": "SimplePotReading - Rebuild and Program DFU",
"command": "make clean; make; make program-dfu",
"options": {
"cwd": "${workspaceFolder}/SimplePotReading"
},
"problemMatcher": [],
"type": "shell"
},
// SimpleSwitchReading Tasks
{
"label": "SimpleSwitchReading - Build",
"command": "make",
"options": {
"cwd": "${workspaceFolder}/SimpleSwitchReading"
},
"problemMatcher": [],
"type": "shell"
},
{
"label": "SimpleSwitchReading - Clean",
"command": "make clean",
"options": {
"cwd": "${workspaceFolder}/SimpleSwitchReading"
},
"problemMatcher": [],
"type": "shell"
},
{
"label": "SimpleSwitchReading - Program DFU",
"command": "make program-dfu",
"options": {
"cwd": "${workspaceFolder}/SimpleSwitchReading"
},
"problemMatcher": [],
"type": "shell"
},
{
"label": "SimpleSwitchReading - Rebuild and Program DFU",
"command": "make clean; make; make program-dfu",
"options": {
"cwd": "${workspaceFolder}/SimpleSwitchReading"
},
"problemMatcher": [],
"type": "shell"
},
// PassthruAndBypass Tasks
{
"label": "PassthruAndBypass - Build",
"command": "make",
"options": {
"cwd": "${workspaceFolder}/PassthruAndBypass"
},
"problemMatcher": [],
"type": "shell"
},
{
"label": "PassthruAndBypass - Clean",
"command": "make clean",
"options": {
"cwd": "${workspaceFolder}/PassthruAndBypass"
},
"problemMatcher": [],
"type": "shell"
},
{
"label": "PassthruAndBypass - Program DFU",
"command": "make program-dfu",
"options": {
"cwd": "${workspaceFolder}/PassthruAndBypass"
},
"problemMatcher": [],
"type": "shell"
},
{
"label": "PassthruAndBypass - Rebuild and Program DFU",
"command": "make clean; make; make program-dfu",
"options": {
"cwd": "${workspaceFolder}/PassthruAndBypass"
},
"problemMatcher": [],
"type": "shell"
},
// Combined Tasks for doing operations on all examples.
{
"label": "Build All",
"dependsOn": ["BasicExample - Build", "PassthruAndBypass - Build",
"SimplePotReading - Build", "SimpleSwitchReading - Build"]
},
{
"label": "Clean All",
"dependsOn": ["BasicExample - Clean", "PassthruAndBypass - Clean",
"SimplePotReading - Clean", "SimpleSwitchReading - Clean"]
}
],
"version": "2.0.0"
Expand Down
22 changes: 22 additions & 0 deletions PassthruAndBypass/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Project Name
TARGET = PassthruAndBypass

# Configure for debugging
# common configurations:
# use DEBUG = 1 and OPT = -Og for debugging
# or DEBUG = 0 and OPT = -O3 for performance
DEBUG = 0
OPT = -O3

# Sources
CPP_SOURCES = main.cpp

LIBDAISY_DIR = ../libs/libDaisy
DAISYSP_DIR = ../libs/DaisySP

# (optional) Includes FatFS source files within project.
#USE_FATFS = 1

# Core location, and generic Makefile.
SYSTEM_FILES_DIR = $(LIBDAISY_DIR)/core
include $(SYSTEM_FILES_DIR)/Makefile
78 changes: 78 additions & 0 deletions PassthruAndBypass/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/** Daisy Seed2 DFM Pedal Dev Kit Basic Example
*
* This example does a few things that can serve as a great jumping off
* point for new effects pedal projects.
*
* 1. Initializes Switch and GPIO for control of the true-bypass relays
* 2. Initializes an LED to indicate bypass state (illuminate RED when audio runs through software)
* 3. Sets up basic audio passthru
*/
#include "daisy_seed.h"

using namespace daisy;

/** Global objects that need to be accessed in both main() and the audio callback */
DaisySeed hardware;

/** The audio callback that fires whenever new audio samples can be prepared */
void AudioCallback(AudioHandle::InputBuffer in,
AudioHandle::OutputBuffer out,
size_t size)
{
for (size_t i = 0; i < size; i++)
{
/** For each sample in the loop we'll multiply the input by our volume control
* OUT_x and IN_x are macros that access the out, and in buffers respectively.
* This would be equivalent to: out[0][i] = in[0][i] * volume;, etc.
*/
OUT_L[i] = IN_L[i];
OUT_R[i] = IN_R[i];

/** Due to minor errata on the Rev4 hardware we need to phase invert the
* left channel so both outputs have the same phase */
OUT_L[i] *= -1.f;
}
}

int main()
{

/** Initialize the Daisy Seed at maximum clock speed */
hardware.Init(true);

/** Relay Control/UI init */
GPIO relay_left, relay_right;
Switch relay_control;
Led relay_led;
relay_left.Init(seed::D20, GPIO::Mode::OUTPUT);
relay_right.Init(seed::D21, GPIO::Mode::OUTPUT);
relay_control.Init(seed::D23, hardware.AudioCallbackRate());
relay_led.Init(seed::D11, true);

/** Start the Audio */
hardware.StartAudio(AudioCallback);

while (true)
{
/** Debounce the toggle */
relay_control.Debounce();

/** Update the relay states based on the toggle position */
bool bypass_state = relay_control.Pressed();
relay_left.Write(bypass_state);
relay_right.Write(bypass_state);

/** Update the LED brightness based on true bypass state */
if (bypass_state)
relay_led.Set(1);
else
relay_led.Set(0);
/** Update the LED (required in case of software PWM for values between 0-1)*/
relay_led.Update();

/** We'll delay for one millisecond before looping back over to keep everything nice, and predictable
* The hardware control work could be moved to the audio callback as well.
*/
System::Delay(1);
}
}
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,27 @@ Includes:
* libDaisy - hardware library for Daisy
* DaisySP - DSP library
* BasicExample - Basic example demonstrating hardware setup code for the dev kit hardware.
* PassthruAndBypass - Example demonstrating toggling between audio passthru and true bypass
* SimplePotReading - Exmaple demonstrating reading two pots, and printing their values to a serial monitor.
* SimpleSwitchReading - Example demonstrating reading the position of a toggle.

This also contains the following VS code tasks:
When you have the Makefile, or a source file within an examples folder open, you can run the "Build task" with "ctrl-shift-B" on windows, or "cmd-shift-B" on Mac OS, and that will compile the selected example.
A similar, generic set of tasks for "Clean" and "Program DFU" are also available for the selected example.

For each of these examples, there are the following VS code tasks:

* Build: build the specified example
* Clean: removes the specified example's build folder, and it's contents.
* Program DFU: programs the specified example's binary file via USB
* Build and Program DFU: Rebuilds the specified program and downloads it via USB DFU

In addition, there is a set of tasks that will operate on the entire workspace:

* Build Libraries: builds libDaisy, and DaisySP from scratch. This is only necessary when manually updating, or cloning for the first time.
* Build: build the blink example
* Clean: removes compiled BasicExample code
* Program DFU: programs the BasicExample.bin file via USB
* Build and Program DFU: Rebuilds the program and downloads it via USB DFU
* Build All: builds all of the individual example projects.
* Clean All: removes all examples' build folders, and their contents.

In addition, the following debug configurations are available:
The following debug configurations are available:

* Debug BasicExample: debugs the BasicExample application

Expand Down
22 changes: 22 additions & 0 deletions SimplePotReading/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Project Name
TARGET = SimplePotReading

# Configure for debugging
# common configurations:
# use DEBUG = 1 and OPT = -Og for debugging
# or DEBUG = 0 and OPT = -O3 for performance
DEBUG = 0
OPT = -O3

# Sources
CPP_SOURCES = main.cpp

LIBDAISY_DIR = ../libs/libDaisy
DAISYSP_DIR = ../libs/DaisySP

# (optional) Includes FatFS source files within project.
#USE_FATFS = 1

# Core location, and generic Makefile.
SYSTEM_FILES_DIR = $(LIBDAISY_DIR)/core
include $(SYSTEM_FILES_DIR)/Makefile
Loading

0 comments on commit c2c91b3

Please sign in to comment.