Skip to content

Commit

Permalink
Merge pull request #121 from 4ms/sls-dev
Browse files Browse the repository at this point in the history
Firmware GUI: Mapping Pane extended, KnobSets page added, PatchView cleaned up
  • Loading branch information
danngreen authored Oct 3, 2023
2 parents ac53a8a + 063c432 commit 75820c3
Show file tree
Hide file tree
Showing 118 changed files with 5,165 additions and 2,315 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
url = https://github.com/lvgl/lv_img_conv.git
[submodule "shared/patch_convert/ryml/rapidyaml"]
path = shared/patch_convert/ryml/rapidyaml
url = https://github.com/biojppm/rapidyaml.git
url = https://github.com/danngreen/rapidyaml.git
[submodule "shared/cpputil"]
path = shared/cpputil
url = https://github.com/4ms/cpputil.git
Expand Down
7 changes: 6 additions & 1 deletion firmware/.clangd
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ CompileFlags:
"-mthumb-interwork",
"-ffold-simple-inlines",
"-std=gnu++23",
"-DSIMULATOR",
]
Add: [
"--target=arm-none-eabi",
"-std=gnu++2b",
"-I../src/console", #Needed because clangd16 infers compilation of some headers with a file from a different cmake target
"-I../src/medium",
"-I../src/console",
"-I../lib/lvgl/lvgl",
"-I../lib/cmsis/Core_A/Include",
"-DSTM32MP1",
"-DCORE_CA7",
]
---
If:
Expand Down
11 changes: 10 additions & 1 deletion firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,18 @@ add_custom_target(
COMMAND cd ${SHARED}/patch_convert && make --no-print-directory -f tests/Makefile -j8
COMMAND cd ${SHARED}/CoreModules && make --no-print-directory -f tests/Makefile -j8
COMMAND cd ${SHARED}/axoloti-wrapper && make --no-print-directory -f tests/Makefile -j8
BYPRODUCTS ${PROJECT_SOURCE_DIR}/tests/build/*
VERBATIM USES_TERMINAL
)
file(
GLOB
tests_clean_files
CONFIGURE_DEPENDS
"${PROJECT_SOURCE_DIR}/tests/build/*"
"${SHARED}/patch_convert/tests/build/*"
"${SHARED}/CoreModules/tests/build/*"
"${SHARED}/axoloti-wrapper/tests/build/*"
)
set_target_properties(tests PROPERTIES ADDITIONAL_CLEAN_FILES "${tests_clean_files}")

add_custom_target(
dep_tests
Expand Down
12 changes: 6 additions & 6 deletions firmware/lib/lvgl/lv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@

/*Enable/disable LV_LOG_TRACE in modules that produces a huge number of logs*/
#define LV_LOG_TRACE_MEM 1
#define LV_LOG_TRACE_TIMER 1
#define LV_LOG_TRACE_TIMER 0
#define LV_LOG_TRACE_INDEV 1
#define LV_LOG_TRACE_DISP_REFR 0
#define LV_LOG_TRACE_DISP_REFR 1
#define LV_LOG_TRACE_EVENT 1
#define LV_LOG_TRACE_OBJ_CREATE 1
#define LV_LOG_TRACE_LAYOUT 0
#define LV_LOG_TRACE_ANIM 0
#define LV_LOG_TRACE_LAYOUT 1
#define LV_LOG_TRACE_ANIM 1

#endif /*LV_USE_LOG*/

Expand All @@ -236,7 +236,7 @@

/*Add a custom handler when assert happens e.g. to restart the MCU*/
#define LV_ASSERT_HANDLER_INCLUDE <stdint.h>
#define LV_ASSERT_HANDLER while(1); /*Halt by default*/
#define LV_ASSERT_HANDLER do {lv_log("Assert failed\n"); while(1);} while(0); /*Halt by default*/

/*-------------
* Others
Expand Down Expand Up @@ -327,7 +327,7 @@
*https://fonts.google.com/specimen/Montserrat*/
#define LV_FONT_MONTSERRAT_8 0
#define LV_FONT_MONTSERRAT_10 1
#define LV_FONT_MONTSERRAT_12 0
#define LV_FONT_MONTSERRAT_12 1
#define LV_FONT_MONTSERRAT_14 1
#define LV_FONT_MONTSERRAT_16 1
#define LV_FONT_MONTSERRAT_18 0
Expand Down
46 changes: 9 additions & 37 deletions firmware/src/audio/audio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "drivers/cache.hh"
#include "drivers/hsem.hh"
#include "param_block.hh"
#include "patch_play/patch_mods.hh"
#include "patch_play/patch_player.hh"
#include "patch_play/patch_playloader.hh"
#include "sync_params.hh"
Expand All @@ -35,15 +36,6 @@ __attribute__((optimize("O0"))) void output_silence(AudioOutBuffer &out) {

using namespace mdrivlib;

constexpr bool DEBUG_PASSTHRU_AUDIO = false;
constexpr bool DEBUG_SINEOUT_AUDIO = false;
constexpr bool DEBUG_NE10_FFT = false;
// static FFTfx fftfx;
// static Convolver fftfx;

static constexpr unsigned block_0 = 1; //TargetName == Targets::stm32h7x5 ? 0 : 1;
static constexpr unsigned block_1 = 1 - block_0;

AudioStream::AudioStream(PatchPlayer &patchplayer,
AudioInBlock &audio_in_block,
AudioOutBlock &audio_out_block,
Expand Down Expand Up @@ -91,7 +83,7 @@ AudioStream::AudioStream(PatchPlayer &patchplayer,
auto audio_callback = [this]<unsigned block>() {
// Debug::Pin0::high();

load_lpf += (load_measure.get_last_measurement_load_float() - load_lpf) * 0.005f;
load_lpf += (load_measure.get_last_measurement_load_float() - load_lpf) * 0.05f;
param_blocks[block].metaparams.audio_load = static_cast<uint8_t>(load_lpf * 100.f);
load_measure.start_measurement();

Expand All @@ -117,6 +109,12 @@ AudioStream::AudioStream(PatchPlayer &patchplayer,
-1.f * (float)AudioInFrame::kMaxValue, (float)AudioInFrame::kMaxValue - 1.f);
}

void AudioStream::start() {
codec_.start();
if (ext_audio_connected)
codec_ext_.start();
}

AudioConf::SampleT AudioStream::get_audio_output(int output_id) {
auto raw_out = player.get_panel_output(output_id) * mute_ctr;
raw_out = -raw_out / OutputHighRangeVolts;
Expand All @@ -128,14 +126,6 @@ void AudioStream::process(CombinedAudioBlock &audio_block, ParamBlock &param_blo
auto &in = audio_block.in_codec;
auto &out = audio_block.out_codec;

if constexpr (DEBUG_PASSTHRU_AUDIO) {
AudioTestSignal::passthrough(in, out, aux);
return;
} else if (DEBUG_SINEOUT_AUDIO) {
AudioTestSignal::sines_out(in, out);
return;
}

if (patch_loader.is_loading_new_patch()) {
if (mute_ctr > 0.f)
mute_ctr -= 0.1f;
Expand All @@ -160,7 +150,7 @@ void AudioStream::process(CombinedAudioBlock &audio_block, ParamBlock &param_blo
return;
}

handle_patch_mods();
handle_patch_mods(patch_mod_queue, player);

// TODO: handle second codec
if (ext_audio_connected)
Expand Down Expand Up @@ -221,24 +211,6 @@ void AudioStream::process(CombinedAudioBlock &audio_block, ParamBlock &param_blo
}
}

void AudioStream::start() {
codec_.start();
if (ext_audio_connected)
codec_ext_.start();
}

void AudioStream::handle_patch_mods() {
if (auto patch_mod = patch_mod_queue.get()) {
std::visit(overloaded{
[this](SetStaticParam &mod) { player.apply_static_param(mod.param); },
[this](ChangeKnobSet mod) { player.set_active_knob_set(mod.knobset_num); },
[](AddMapping &mod) { /*TODO*/ },
[](ModifyMapping &mod) { /*TODO*/ },
},
patch_mod.value());
}
}

void AudioStream::propagate_sense_pins(Params &params) {
for (int i = 0; i < PanelDef::NumUserFacingInJacks; i++) {
auto pin_bit = jacksense_pin_order[i];
Expand Down
2 changes: 0 additions & 2 deletions firmware/src/audio/audio.hh
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,10 @@ private:
bool ext_audio_connected = false;

AudioConf::SampleT get_audio_output(int output_id);
uint32_t get_dac_output(int output_id);
void set_input(int input_id, AudioConf::SampleT in);
bool check_patch_change(int motion);
void send_zeros_to_patch();
void propagate_sense_pins(Params &params);
void handle_patch_mods();

// void output_silence(AudioOutBuffer &out, AuxStreamBlock &aux);

Expand Down
20 changes: 11 additions & 9 deletions firmware/src/console/pr_dbg.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,40 @@
namespace
{

/////////////////////////////////////////////////
// Change these to enable/disable logging levels
inline constexpr bool PRINT_ERROR = true;
inline constexpr bool PRINT_WARN = true;
inline constexpr bool PRINT_DEBUG = false;
static constexpr bool PRINT_ERROR = true;
static constexpr bool PRINT_WARN = true;
static constexpr bool PRINT_DEBUG = false;
inline constexpr bool PRINT_TRACE = false;
/////////////////////////////////////////////////

inline void do_printf_(auto str) {
inline void _do_printf_impl(const char *str) {
printf_("%s", str);
}

inline void do_printf_(auto... args) {
inline void _do_printf_impl(auto... args) {
printf_(args...);
}

inline void pr_err(auto... args) {
if constexpr (PRINT_ERROR)
do_printf_(args...);
_do_printf_impl(args...);
}

inline void pr_warn(auto... args) {
if constexpr (PRINT_WARN)
do_printf_(args...);
_do_printf_impl(args...);
}

inline void pr_dbg(auto... args) {
if constexpr (PRINT_DEBUG)
do_printf_(args...);
_do_printf_impl(args...);
}

inline void pr_trace(auto... args) {
if constexpr (PRINT_TRACE)
do_printf_(args...);
_do_printf_impl(args...);
}

} // namespace
2 changes: 1 addition & 1 deletion firmware/src/gui/elements/context.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace MetaModule
struct GuiElement {
lv_obj_t *obj = nullptr; //gui object
lv_obj_t *map_ring = nullptr; //gui map ring object
uint16_t module_idx = 0; //index in patch
uint16_t module_idx = 0; //index of module in patch
ElementCount::Counts count{}; //Number elements of each category in module
ElementCount::Indices idx; //index within cateogry in module: param_idx, injack_idx, etc
std::optional<uint16_t> mapped_panel_id; //patch mapping
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/gui/elements/element_name.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ std::string get_panel_name(const BaseElement &, uint16_t) {
}

template<typename PanelDef>
std::string get_panel_name(const Knob &, uint16_t panel_id) {
std::string get_panel_name(const ParamElement &, uint16_t panel_id) {
std::string name{8};
name += PanelDef::get_map_param_name(panel_id);
return name;
Expand Down
45 changes: 45 additions & 0 deletions firmware/src/gui/elements/helpers.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once
#include "CoreModules/elements/element_counter.hh"
#include "CoreModules/moduleFactory.hh"
#include "patch/patch.hh"
#include "patch/patch_data.hh"
#include <algorithm>

namespace MetaModule
{

struct FullElementName {
std::string_view module_name;
std::string_view element_name;
};

enum class ElementType { Param, Input, Output, Light };

inline FullElementName
get_full_element_name(unsigned module_id, unsigned element_idx, ElementType type, PatchData const &patch) {
FullElementName fullname{"?", "?"};

if (module_id < patch.module_slugs.size()) {
fullname.module_name = patch.module_slugs[module_id];

auto &info = ModuleFactory::getModuleInfo(patch.module_slugs[module_id]);

if (info.width_hp) {
auto res = std::ranges::find_if(info.indices, [=](auto idx) {
return (type == ElementType::Param) ? element_idx == idx.param_idx :
(type == ElementType::Input) ? element_idx == idx.input_idx :
(type == ElementType::Output) ? element_idx == idx.output_idx :
(type == ElementType::Light) ? element_idx == idx.light_idx :
false;
});

if (res != info.indices.end()) {
auto el_id = std::distance(info.indices.begin(), res);
fullname.element_name = base_element(info.elements[el_id]).short_name;
}
}
}
return fullname;
}

} // namespace MetaModule
47 changes: 32 additions & 15 deletions firmware/src/gui/elements/module_param.hh
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
#pragma once
#include "CoreModules/elements/element_counter.hh"
#include "CoreModules/elements/elements.hh"
#include <cstdint>

namespace MetaModule
{

struct ModuleParam {
enum class Type { Knob, Switch, InJack, OutJack } type{Type::OutJack};
uint32_t id;
const Element *el{nullptr};

static auto get_type(const BaseElement &) {
return Type::Knob;
}
//Are type and id needed?
enum class Type { None, Knob, Switch, InJack, OutJack, Light } type{Type::None};
uint32_t id{};

static auto get_type(const Pot &) {
return Type::Knob;
}
ModuleParam() = default;

static auto get_type(const Switch &) {
return Type::Switch;
ModuleParam(const Element &element, ElementCount::Indices idx)
: el{&element} {
std::visit([&](auto &el) { set_type(el, idx); }, element);
}

static auto get_type(const JackInput &) {
return Type::InJack;
private:
void set_type(const BaseElement &el, ElementCount::Indices idx) {
type = Type::None;
id = 0;
}

static auto get_type(const JackOutput &) {
return Type::OutJack;
void set_type(const Pot &el, ElementCount::Indices idx) {
type = Type::Knob;
id = idx.param_idx;
}
void set_type(const Switch &el, ElementCount::Indices idx) {
type = Type::Switch;
id = idx.param_idx;
}
void set_type(const JackInput &el, ElementCount::Indices idx) {
type = Type::InJack;
id = idx.input_idx;
}
void set_type(const JackOutput &el, ElementCount::Indices idx) {
type = Type::OutJack;
id = idx.output_idx;
}
void set_type(const LightElement &el, ElementCount::Indices idx) {
type = Type::Light;
id = idx.light_idx;
}
};

Expand Down
6 changes: 3 additions & 3 deletions firmware/src/gui/elements/redraw.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ inline bool redraw_element(const Knob &, const GuiElement &gui_el, float val) {
constexpr int32_t threshold_centidegrees = 30; // = 3.0 degrees

int32_t angle = val * 3000.f - 1500.f;
if (angle < 0)
while (angle < 0)
angle += 3600;
int32_t cur_angle = lv_img_get_angle(gui_el.obj);

Expand Down Expand Up @@ -71,7 +71,7 @@ inline bool redraw_element(const Toggle3pos &element, const GuiElement &gui_el,

auto handle = lv_obj_get_child(gui_el.obj, 0);
if (!handle) {
printf_("No handle sub-object for toggle3pos\n");
pr_err("No handle sub-object for toggle3pos\n");
return false;
}
auto height = lv_obj_get_height(gui_el.obj);
Expand Down Expand Up @@ -112,7 +112,7 @@ inline bool redraw_element(const Toggle2pos &element, const GuiElement &gui_el,

auto handle = lv_obj_get_child(gui_el.obj, 0);
if (!handle) {
printf_("No handle sub-object for toggle2pos\n");
pr_err("No handle sub-object for toggle2pos\n");
return false;
}
auto height = lv_obj_get_height(gui_el.obj);
Expand Down
Loading

0 comments on commit 75820c3

Please sign in to comment.