From 72f9ff79b49f7e5ccf78770edabd4f0b2ec4fca0 Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 20 Sep 2024 22:09:43 +0200 Subject: [PATCH] initial commit from heck_daisy_template --- .clang-format | 42 ++++++++++++ .clang-tidy | 37 +++++++++++ .gitignore | 4 ++ Makefile | 13 ++++ Makefile.conf | 35 ++++++++++ README.md | 151 +++++++++++++++++++++++++++++++++++++++++++ build.conf.example | 12 ++++ src/Makefile | 19 ++++++ src/main_blink.cc | 16 +++++ src/main_testtone.cc | 51 +++++++++++++++ src/types.hh | 19 ++++++ 11 files changed, 399 insertions(+) create mode 100644 .clang-format create mode 100644 .clang-tidy create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 Makefile.conf create mode 100644 README.md create mode 100644 build.conf.example create mode 100644 src/Makefile create mode 100644 src/main_blink.cc create mode 100644 src/main_testtone.cc create mode 100644 src/types.hh diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..0fa41a7 --- /dev/null +++ b/.clang-format @@ -0,0 +1,42 @@ +BasedOnStyle: LLVM +ReflowComments: false + +MacroBlockBegin: "^BEGIN_OPERATOR" +MacroBlockEnd: "^END_OPERATOR" + +Language: Cpp +DerivePointerAlignment: true +SortIncludes: Never +PointerAlignment: Left +AlignAfterOpenBracket: AlwaysBreak +AlignOperands: AlignAfterOperator +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +BinPackArguments: false +BinPackParameters: false +ExperimentalAutoDetectBinPacking: true +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: true +ColumnLimit: 100 +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +PenaltyBreakBeforeFirstCallParameter: 0 +PenaltyReturnTypeOnItsOwnLine: 1000000 +PenaltyBreakAssignment: 1000000 +PenaltyExcessCharacter: 10 +IndentCaseLabels: true +IndentWidth: 4 +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: All +SpaceAfterTemplateKeyword: false +AccessModifierOffset: -4 +AllowShortBlocksOnASingleLine: Always +IndentPPDirectives: BeforeHash +IndentExternBlock: Indent +Cpp11BracedListStyle: false diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..204d1c6 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,37 @@ +Checks: > + -*, + -abseil-*, + -altera-*, + -android-*, + boost-*, + bugprone-*, + -bugprone-infinite-loop, + cert-*, + -clang-analyzer-*, + concurrency-*, + cppcoreguidelines-*, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -cppcoreguidelines-avoid-non-const-global-variables, + -cppcoreguidelines-non-private-member-variables-in-classes, + darwin-*, + -fuchsia-*, + -google-*, + -hicpp-*, + -linuxkernel-*, + -llvm-*, + -llvmlibc-*, + misc-*, + -misc-non-private-member-variables-in-classes, + modernize-*, + -modernize-use-auto, + -modernize-use-trailing-return-type, + -modernize-use-nodiscard, + -mpi-*, + -objc-*, + -openmp-*, + performance-*, + portability-*, + readability-*, + -readability-function-cognitive-complexity, + -readability-implicit-bool-conversion,a + -zircon-*, diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a94fe8f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/.idea +/build.conf + +build/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5c6a46a --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +.PHONY: all flash clean + +all: compile flash + +compile: + $(MAKE) -C src + +flash: + $(MAKE) -C src program + +clean: + $(MAKE) -C src clean + diff --git a/Makefile.conf b/Makefile.conf new file mode 100644 index 0000000..2f42d64 --- /dev/null +++ b/Makefile.conf @@ -0,0 +1,35 @@ +HERE:=$(dir $(lastword $(MAKEFILE_LIST))) + +# Project Name +TARGET?=perkons + +# 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 + +# (optional) Includes FatFS source files within project. +#USE_FATFS = 1 + +# Relative to dir 'src' +LIBDAISY_DIR=../../heck_libDaisyWrong +DAISYSP_DIR=../../heck_DaisySPWrong + +CXXFLAGS+=-Wall -Wno-unused -Wno-reorder-ctor + +######### Overrides from build.conf ######### +-include $(HERE)build.conf + +ifneq (,$(findstring g++,$(CXX))) + CXXFLAGS+=-fdiagnostics-color=always +else ifneq (,$(findstring clang,$(CXX))) + CXXFLAGS+=-fcolor-diagnostics +endif + +ifeq ($(DEBUG),1) + CXXFLAGS+=-g -O0 +else + CXXFLAGS+=-DNDEBUG=1 -O3 +endif diff --git a/README.md b/README.md new file mode 100644 index 0000000..9eb7912 --- /dev/null +++ b/README.md @@ -0,0 +1,151 @@ +# Heck Daisy Template + +Daisy project template featuring: +* toolchain setup +* dependencies setup +* +* build scripts +* upload (DFU and JTAG) +* debug +* clang-format +* clang-tidy + + +## git started + +to use git, either die or use hecks git-ui. +heck-git-ui: https://gitea.heck.live/heck/HeckBashSetup/src/branch/master/bash_profile.d/git.sh + +Alternatively, you can avoid using git... TODO + + +## Toolchain Setup + +### Compiler + +compiler used is gcc for arm: +Options: +* install version specified by electro-smith: https://developer.arm.com/downloads/-/gnu-rm +* install the latest version: https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain + +**IMPORTANT:** Do NOT use any OTHER gcc-arm toolchain than these ones!!! +There is a pitfall that is quite hard to debug. I used the gcc-arm from macports. +There is NO libc-nano shipped with it, because its not GPL. +BUT the daisy build scripts specify the use of libc-nano. + + +### Programmer / Debugger + +on macos: +`port install dfu-util openocd` + + +`dfu-util` is the program that is invoked by the Makefiles to program the thing via DFU. +`openocd` is the program that is invoked by the Makefiles to program the thing via JTAG. +`openocd` also is the debugger we use. + + + +## Flashing + +Can be flashed via: +* DFU: all you need is a micro-usb-cable +* JTAG: any JTAG programmer will work, but the STLink v3 is the fastest. + +### DFU +No magic, you just need a program called `dfu-util`. +TODO... + +### JTAG +no magic, you just need a programm called `openocd` + +TODO: +The JTAG method is heavily recommended since JTAG is faster than DFU, and if you use the (product ad ahead warning, sorry) +STLink v3 its even faster. Its the fastest method i know of. + +### Benchmark DFU vs. JTAG + +**DFU: 15.725s** +**JTAG: 1.850s** + +JTAG is at least **8.5 times** faster (since there is constant time overhead) + +``` shell +[heck@YOOROOX::~/src/DaisyExamples/seed/Blink] (master ?M) $ time m program-dfu; +dfu-util -a 0 -s 0x08000000:leave -D build/Blink.bin -d ,0483:df11 +blabla... +... +real 0m15.725s +``` + +``` shell +[heck@YOOROOX::~/src/DaisyExamples/seed/Blink] (master ?M) $ time m program; +openocd -s /opt/local/bin/openocd/ -f interface/stlink.cfg -f target/stm32h7x.cfg -c "program ./build/Blink.elf verify reset exit" +blabla... +... +real 0m1.850s +``` + + +## Debugging +TODO: + + + + + + + +## Daisy Coding +* C++ bare metal like any STM32 - needlessly brutal +* C++ and libDaisy - libDaisy is the electro-smith hardware abstraction +* Pure-Data patch compiler +* JUCE +* FAUST for DSP algo +* Max-msp gen~ (proprietary $hit) + + +### C++ Bare Metal +Just code like for any STM32 - needlessly brutal +TODO: add hecks STM32 project + +### C++ and libDaisy +libDaisy is the electro-smith hardware abstraction and is basically what makes the daisy be the daisy. +TODO: + + +### Pure-Data Patch Compiler +this here: https://github.com/electro-smith/pd2dsy +TODO: Marc? anyone? + + +### JUCE +TODO: anyone? +e.g. https://github.com/electro-smith/Daisy-Juce-Example + +### FAUST +This here: https://faust.grame.fr/ +stahl has workflow/project + +### Max-Msp gen~ +max is the proprietary version of pure-data, but dont want to exclude them just for that. +gen~ alone will cost you extra $$$ after even you paid for max. just so you know, hu? + + + + + +## Daisy-Hardware + +TODO: PLEASE everyone share their hardware HERE! + + + +## Various + +Stahl and Marcs fire synthesizer. Now with sausage mode: https://wiki.sgmk-ssam.ch/wiki/F%C3%BC%C3%BCr_Synthie_mit_Daisy_Seed + + + + + diff --git a/build.conf.example b/build.conf.example new file mode 100644 index 0000000..de4b963 --- /dev/null +++ b/build.conf.example @@ -0,0 +1,12 @@ +# Build config +# also, infos for the build system about the dev environment + +# The program to compile and flash +# the name of the main cxx file without the prefix 'main_' +TARGET=perkons + +DEBUG=0 + +# Daisy dependencies Relative to dir 'src' +LIBDAISY_DIR=../../heck_libDaisy +DAISYSP_DIR=../../heck_DaisySP diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..e527aa0 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,19 @@ +include ../Makefile.conf + +ALL_SRC=$(wildcard *.cc) +TARGET_SRC=main_$(TARGET).cc +MODULES_SRC=$(filter-out main_%,$(ALL_SRC)) +CXX_SRC=$(MODULES_SRC) $(TARGET_SRC) + +$(info CXXFLAGS: $(CXXFLAGS)) +$(info SOURCES: $(ALL_SRC)) +$(info MODULES: $(MODULES_SRC)) +$(info TARGET_SRC: $(TARGET_SRC)) +$(info CXX_SRC: $(CXX_SRC)) + +# libDaisy Makefile variables +CPPFLAGS=$(CXXFLAGS) +SYSTEM_FILES_DIR=$(LIBDAISY_DIR)/core +CPP_SOURCES=$(CXX_SRC) + +include $(SYSTEM_FILES_DIR)/Makefile diff --git a/src/main_blink.cc b/src/main_blink.cc new file mode 100644 index 0000000..ae45583 --- /dev/null +++ b/src/main_blink.cc @@ -0,0 +1,16 @@ +#include "daisy_seed.h" + +using namespace daisy; + +static DaisySeed hw{}; + +int main() +{ + hw.Init(); + while (true) { + hw.SetLed(true); + hw.DelayMs(100); + hw.SetLed(false); + hw.DelayMs(500); + } +} diff --git a/src/main_testtone.cc b/src/main_testtone.cc new file mode 100644 index 0000000..bf30ed2 --- /dev/null +++ b/src/main_testtone.cc @@ -0,0 +1,51 @@ +#include "daisy_seed.h" +#include "daisysp.h" + +// Use the daisy namespace to prevent having to type +// daisy:: before all libdaisy functions +using namespace daisy; +using namespace daisysp; + +// Declare a DaisySeed object called hardware +DaisySeed hardware; +Oscillator osc; + +void AudioCallback( + AudioHandle::InterleavingInputBuffer in, + AudioHandle::InterleavingOutputBuffer out, + size_t size) +{ + float osc_out; + + //Convert floating point knob to midi (0-127) + //Then convert midi to freq. in Hz + osc.SetFreq(1000); + + //Fill the block with samples + for (size_t i = 0; i < size; i += 2) { + osc.SetAmp(1.0); + osc_out = osc.Process(); + //Set the left and right outputs + out[i] = osc_out; + out[i + 1] = osc_out; + } +} + + +int main(void) +{ + hardware.Configure(); + hardware.Init(); + hardware.SetAudioBlockSize(4); + + float samplerate = hardware.AudioSampleRate(); + + osc.Init(samplerate); + osc.SetWaveform(osc.WAVE_SIN); + osc.SetAmp(1.f); + osc.SetFreq(1000); + + hardware.StartAudio(AudioCallback); + + for (;;) {} +} diff --git a/src/types.hh b/src/types.hh new file mode 100644 index 0000000..c4669d5 --- /dev/null +++ b/src/types.hh @@ -0,0 +1,19 @@ +#ifndef HECK_DAISY_TYPES_HH +#define HECK_DAISY_TYPES_HH + +#include + +using u8 = uint8_t; +using u16 = uint16_t; +using u32 = uint32_t; +using u64 = uint64_t; + +using i8 = int8_t; +using i16 = int16_t; +using i32 = int32_t; +using i64 = int64_t; + +using f32 = float; +using f64 = double; + +#endif \ No newline at end of file