awonak / libModulove

Arduino library for the hardware abstraction layer of Modulove's SyncLFO and A-RYTH-MATIK eurorack modules
https://awonak.github.io/libModulove/
MIT License
5 stars 3 forks source link

Add configuration options for initializing the ARYTHMATIK module. #2

Closed awonak closed 6 months ago

awonak commented 6 months ago

One caveat with this implementation is that the ROTATE_PANEL is used in the arythmatik.cpp source file, not the header file, so adding #define ROTATE_PANEL in the .ino filea .ino sketch is not enough to make it visible at compile time. To properly compile the sketch with the flag visible to the library, it must be compiled with the flag set as a build property:

arduino-cli compile -b lgt8fx:avr:328 --build-property "build.extra_flags=-DROTATE_PANEL" BitGarden.ino -u -p /dev/ttyUSB0

UPDATE:

Added a struct with configuration settings for changing the behavior of the A-RYTH-MATIK module.

// Configuration settings for the A-RYTH-MATIK module.
struct Config {
    // When compiling for the "updside down" A-RYTH-MATIK panel, set this to true.
    bool RotatePanel;

    // Set ReverseEncoder to true if rotating the encoder counterclockwise should increment.
    bool ReverseEncoder;
};

The config values can be set in the sketch's setup() method by checking preproc build flags:

// Declare A-RYTH-MATIK hardware variable.
Arythmatik hw;

setup() {
  #ifdef ROTATE_PANEL
      hw.config.RotatePanel = true;
  #endif

  #ifdef REVERSE_ENCODER
      hw.config.ReverseEncoder = true;
  #endif
  ...
  hw.Init();
  ...
}
modulove commented 6 months ago

For me that would work for the workflow but would prevent this Feature from working when compiling with arduino IDE right?

awonak commented 6 months ago

Right, I need to reevaluate my approach here, this feels like I'm doing something wrong.

awonak commented 6 months ago

Two ideas I'm exploring:

1) Add new lib methods to call from the Arduino sketch to change behavior. Example:


void setup() {
    // Initialize the A-RYTH-MATIK peripherials.
    hw.Init();
    #ifdef ROTATE_PANEL
    hw.RotatePanel();
    #endif
    ...
}

2) Introduce config flags to Init().


#ifdef ROTATE_PANEL
bool rotate_panel = true;
#else
bool rotate_panel = false;
#endif
...

void setup() {
    // Initialize the A-RYTH-MATIK peripherials.
    hw.Init(rotate_panel=rotate_panel);
    ...
}

Although, I'm not sure either of those are the right solution either because they do not affect the peripheral pin definition: https://github.com/awonak/libModulove/blob/main/arythmatik_peripherials.h

awonak commented 6 months ago

Similar to the idea in option #2, instead of args in Init(), define a config struct and the sketch can set config values based on #define flags.

Then, with flag definitions like #define CLK_PIN 11 and #define CLK_PIN_REVERSED 13, use the config to initialize the pin with either CLK_PIN or CLK_PIN_REVERSED depending on the provided config.

void Arythmatik::InitInputs(Config config) {
    if (config.reverse_panel) {
        clk.Init(CLK_PIN_REVERSED);
        rst.Init(RST_PIN_REVERSED);
    } else {
        clk.Init(CLK_PIN);
        rst.Init(RST_PIN);
    }
}
awonak commented 6 months ago

@modulove please take a look and let me know if this makes sense and if you have any feedback. Thanks!

modulove commented 6 months ago

Looks good to me. Only one thing that is missing is that the outputs 1 - 4, 2 -5 , 3 - 6 need to be swapped as well for the reversed panel.

I hope this will make the module even more usefull with the user prefered mounting direction.

Thanks for integrating this quickly into the lib even though the euclid fw does not support it yet.

Cheers Linus