Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate pull request 137 #143

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
6 changes: 1 addition & 5 deletions edrumulus.ino
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,8 @@ void setup()
#endif

edrumulus.setup(number_pads, analog_pins, analog_pins_rimshot);
digitalWrite(status_LED_pin, LOW); // set board LED to low right after setup is done
#ifdef ESP_PLATFORM
preset_settings(); // for ESP32, the load/save of settings is not supported, preset instead
#else
read_settings();
#endif
digitalWrite(status_LED_pin, LOW); // set board LED to low right after setup is done
}

void preset_settings()
Expand Down
20 changes: 18 additions & 2 deletions hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,30 @@ int Edrumulus_hardware::get_prototype_pins(int** analog_pins,
# endif
}

void Edrumulus_hardware::write_setting(const int pad_index,
const int address,
const byte value)
{
const char* key = String(pad_index * MAX_NUM_SET_PER_PAD + address).c_str();
settings.putUChar(key, value);
}

byte Edrumulus_hardware::read_setting(const int pad_index,
const int address)
{
const char* key = String(pad_index * MAX_NUM_SET_PER_PAD + address).c_str();
return settings.getUChar(key, 0);
}

void Edrumulus_hardware::setup(const int conf_Fs,
const int number_pads,
const int number_inputs[],
int analog_pin[][MAX_NUM_PAD_INPUTS])
{
// set essential parameters
Fs = conf_Fs;
eeprom_settings.begin((number_pads + 1) * MAX_NUM_SET_PER_PAD); // "+ 1" for pad-independent global settings
Fs = conf_Fs;
char preferences_namespace[16] = "Edrumulus";
settings.begin(preferences_namespace, false);

// create linear vectors containing the pin/ADC information for each pad and pad-input
bool input_is_used[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
Expand Down
11 changes: 7 additions & 4 deletions hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#pragma once

#include "Arduino.h"
#include "EEPROM.h"
#include "common.h"

#define MAX_EEPROM_SIZE 512 // bytes (Teensy 4.0: max 1024 bytes)
Expand All @@ -31,6 +30,8 @@

# include <ADC.h>

# include "EEPROM.h"

# define BOARD_LED_PIN 13 // pin number of the LED on the Teensy 4.0 board
# define ADC_MAX_RANGE 4096 // Teensy 4.0/4.1 ADC has 12 bits -> 0..4095
# define ADC_MAX_NOISE_AMPL 8 // highest assumed ADC noise amplitude in the ADC input range unit (measured)
Expand Down Expand Up @@ -77,6 +78,8 @@ class Edrumulus_hardware
// -----------------------------------------------------------------------------
#ifdef ESP_PLATFORM

# include <Preferences.h>

# include "driver/adc.h"
# include "soc/sens_reg.h"
# ifdef CONFIG_IDF_TARGET_ESP32
Expand Down Expand Up @@ -109,12 +112,12 @@ class Edrumulus_hardware
int analog_pin[][MAX_NUM_PAD_INPUTS],
int sample_org[][MAX_NUM_PAD_INPUTS]);

void write_setting(const int, const int, const byte){}; // not supported
byte read_setting(const int, const int) { return 0; }; // not supported
void write_setting(const int pad_index, const int address, const byte value);
byte read_setting(const int pad_index, const int address);

protected:
int Fs;
EEPROMClass eeprom_settings;
Preferences settings;
volatile SemaphoreHandle_t timer_semaphore;
hw_timer_t* timer = nullptr;
static void IRAM_ATTR on_timer();
Expand Down
Loading