diff --git a/edrumulus.ino b/edrumulus.ino index 2315ad2..17c4830 100644 --- a/edrumulus.ino +++ b/edrumulus.ino @@ -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() diff --git a/hardware.cpp b/hardware.cpp index 69d49d3..d140b4b 100644 --- a/hardware.cpp +++ b/hardware.cpp @@ -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]; diff --git a/hardware.h b/hardware.h index 00a7f80..d5a540f 100644 --- a/hardware.h +++ b/hardware.h @@ -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) @@ -31,6 +30,8 @@ # include +# 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) @@ -77,6 +78,8 @@ class Edrumulus_hardware // ----------------------------------------------------------------------------- #ifdef ESP_PLATFORM +# include + # include "driver/adc.h" # include "soc/sens_reg.h" # ifdef CONFIG_IDF_TARGET_ESP32 @@ -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();