From d735416c463a8f33666edc6a37eaf86fa5a77f85 Mon Sep 17 00:00:00 2001 From: heck Date: Sat, 21 Sep 2024 09:12:24 +0200 Subject: [PATCH 1/5] Add types.hh --- src/types.hh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/types.hh diff --git a/src/types.hh b/src/types.hh new file mode 100644 index 0000000..2e7f7d0 --- /dev/null +++ b/src/types.hh @@ -0,0 +1,30 @@ +#ifndef HECK_DAISY_TYPES_HH +#define HECK_DAISY_TYPES_HH + +#include +#include "daisy_seed.h" +#include "daisysp.h" + +namespace Heck { + + // Types + 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; + + // namespace aliases + namespace ld = daisy; + namespace dsp = daisysp; +} // namespace Heck + + +#endif \ No newline at end of file From 432b6143618666b107f7f8903546abe360153fba Mon Sep 17 00:00:00 2001 From: heck Date: Sat, 21 Sep 2024 09:12:41 +0200 Subject: [PATCH 2/5] blink - update to use types.hh --- src/main_blink.cc | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main_blink.cc b/src/main_blink.cc index cac3593..a3fb4e4 100644 --- a/src/main_blink.cc +++ b/src/main_blink.cc @@ -1,16 +1,31 @@ #include "daisy_seed.h" +#include "types.hh" -namespace ld = daisy; +namespace Heck { + namespace Constants { + constexpr float BLINK_FREQ_HZ{ 1 }; + } + + ld::DaisySeed hw{}; + + float hz_to_ms(float hz) + { + return 1000. / hz; + } -static ld::DaisySeed hw{}; + int main() + { + hw.Init(); + while (true) { + hw.SetLed(true); + hw.DelayMs(hz_to_ms(Constants::BLINK_FREQ_HZ * 2)); + hw.SetLed(false); + hw.DelayMs(hz_to_ms(Constants::BLINK_FREQ_HZ * 2)); + } + } +} // namespace Heck int main() { - hw.Init(); - while (true) { - hw.SetLed(true); - hw.DelayMs(100); - hw.SetLed(false); - hw.DelayMs(100); - } + return Heck::main(); } From 770b710e35d23af458ed65b9260990768ef2f3bf Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 26 Sep 2024 21:22:57 +0200 Subject: [PATCH 3/5] Build: Improve build.conf.example --- build.conf.example | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/build.conf.example b/build.conf.example index 6f077aa..1deb0f5 100644 --- a/build.conf.example +++ b/build.conf.example @@ -1,13 +1,14 @@ -# Build config -# also, infos for the build system about the dev environment +# Dev environment build config +# This is a template, make a local copy called 'build.conf', +# remove this line, and tweak the values as you develop -# TARGET sets the program to compile and flash -# the name of the main cxx file without the prefix 'main_' -TARGET?=blink -#TARGET?=testtone +# The program to compile and flash +# the name of the main cxx file without the suffix -DEBUG?=0 +TARGET ?= main_blink +DEBUG ?= 0 + +# dependencies relative to dir 'src' +LIBDAISY_DIR ?= ../../heck_libDaisy +DAISYSP_DIR ?= ../../heck_DaisySP -# Daisy dependencies relative to dir 'src' -LIBDAISY_DIR?=../../heck_libDaisy -DAISYSP_DIR?=../../heck_DaisySP From aa88142f8b02908e33b5a708f5b8e3203b98febd Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 26 Sep 2024 21:23:32 +0200 Subject: [PATCH 4/5] types and testtone --- src/main_testtone.cc | 77 +++++++++++++++++++++++++------------------- src/types.hh | 6 +++- 2 files changed, 49 insertions(+), 34 deletions(-) diff --git a/src/main_testtone.cc b/src/main_testtone.cc index ddf1ea2..0890985 100644 --- a/src/main_testtone.cc +++ b/src/main_testtone.cc @@ -1,43 +1,54 @@ -#include "daisy_seed.h" -#include "daisysp.h" +#include "types.hh" -namespace ld = daisy; -namespace dsp = daisysp; - -static ld::DaisySeed hardware; -static dsp::Oscillator osc; +namespace Heck { + namespace Constants { + } -void AudioCallback( - ld::AudioHandle::InterleavingInputBuffer in, - ld::AudioHandle::InterleavingOutputBuffer out, - size_t size) -{ - float osc_out; - osc.SetFreq(1000); - for (size_t i = 0; i < size; i += 2) { - osc.SetAmp(1.0); - osc_out = osc.Process(); - osc_out *= 0.01; - out[i] = osc_out; - out[i + 1] = osc_out; + ld::DaisySeed hw{}; + dsp::Oscillator osc{}; + + void AudioCallback( + ld::AudioHandle::InterleavingInputBuffer in, + ld::AudioHandle::InterleavingOutputBuffer out, + size_t size) + { + float osc_out; + osc.SetFreq(1000); + + for (size_t i = 0; i < size; i += 2) { + osc.SetAmp(1.0); + osc_out = osc.Process(); + osc_out *= 0.005; + out[i] = osc_out; + out[i + 1] = osc_out; + } } -} + void init() + { + hw.Configure(); + hw.Init(); + hw.SetAudioBlockSize(4); + float samplerate = hw.AudioSampleRate(); -int main(void) -{ - hardware.Configure(); - hardware.Init(); - hardware.SetAudioBlockSize(4); + osc.Init(samplerate); + osc.SetWaveform(osc.WAVE_SIN); + osc.SetAmp(1.f); + osc.SetFreq(1000); - float samplerate = hardware.AudioSampleRate(); + hw.StartAudio(AudioCallback); + } - osc.Init(samplerate); - osc.SetWaveform(osc.WAVE_SIN); - osc.SetAmp(1.f); - osc.SetFreq(1000); + void mainloop() + { + for (;;) {} + } +} // namespace Heck - hardware.StartAudio(AudioCallback); - while (true) {} +int main(void) +{ + Heck::init(); + Heck::mainloop(); + return 0; } diff --git a/src/types.hh b/src/types.hh index 2e7f7d0..c459beb 100644 --- a/src/types.hh +++ b/src/types.hh @@ -7,7 +7,7 @@ namespace Heck { - // Types + // fundamental types using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; @@ -24,6 +24,10 @@ namespace Heck { // namespace aliases namespace ld = daisy; namespace dsp = daisysp; + + // type aliases from libs + using Samplerate = ld::SaiHandle::Config::SampleRate; + } // namespace Heck From f417c19bf701325cc3dd6f596dde409257147ec0 Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 26 Sep 2024 21:24:40 +0200 Subject: [PATCH 5/5] Build: Simplify --- Makefile.conf | 27 --------------------------- src/Makefile | 31 ++++++++++++++++--------------- 2 files changed, 16 insertions(+), 42 deletions(-) delete mode 100644 Makefile.conf diff --git a/Makefile.conf b/Makefile.conf deleted file mode 100644 index 52733ff..0000000 --- a/Makefile.conf +++ /dev/null @@ -1,27 +0,0 @@ -HERE:=$(dir $(lastword $(MAKEFILE_LIST))) --include $(HERE)build.conf - -# Project Name -TARGET?=blink - -# 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_libDaisy -DAISYSP_DIR?=../../heck_DaisySP - -CXXFLAGS+=-Wall -Wno-unused -Wno-reorder-ctor -Wno-switch - -ifneq (,$(findstring g++,$(CXX))) - CXXFLAGS+=-fdiagnostics-color=always -else ifneq (,$(findstring clang,$(CXX))) - CXXFLAGS+=-fcolor-diagnostics -endif diff --git a/src/Makefile b/src/Makefile index e527aa0..f251f80 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,19 +1,20 @@ -include ../Makefile.conf +HERE:=$(dir $(lastword $(MAKEFILE_LIST))) +-include $(HERE)../build.conf -ALL_SRC=$(wildcard *.cc) -TARGET_SRC=main_$(TARGET).cc -MODULES_SRC=$(filter-out main_%,$(ALL_SRC)) -CXX_SRC=$(MODULES_SRC) $(TARGET_SRC) +TARGET ?= main_blink +DEBUG ?= 0 +LIBDAISY_DIR ?= ../../heck_libDaisy +DAISYSP_DIR ?= ../../heck_DaisySP -$(info CXXFLAGS: $(CXXFLAGS)) -$(info SOURCES: $(ALL_SRC)) -$(info MODULES: $(MODULES_SRC)) -$(info TARGET_SRC: $(TARGET_SRC)) -$(info CXX_SRC: $(CXX_SRC)) +CXX_STANDARD ?= -std=c++17 +CXXFLAGS += -Wall -Wno-unused -Wno-reorder-ctor -Wno-switch +CXXFLAGS += -fdiagnostics-color=always -# libDaisy Makefile variables -CPPFLAGS=$(CXXFLAGS) -SYSTEM_FILES_DIR=$(LIBDAISY_DIR)/core -CPP_SOURCES=$(CXX_SRC) +ALL_SRC = $(wildcard *.cc) +TARGET_SRC = $(TARGET).cc +MODULES_SRC = $(filter-out main_%,$(ALL_SRC)) +CXX_SRC = $(MODULES_SRC) $(TARGET_SRC) -include $(SYSTEM_FILES_DIR)/Makefile +CXX_SOURCES = $(CXX_SRC) + +include $(LIBDAISY_DIR)/core/Makefile