From b7560fce34f54d2947832fa98dd862f343afc7a4 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Wed, 7 Feb 2024 09:29:53 +0100 Subject: [PATCH] Set initial volume --- .../audiotools-custom-max.ino | 4 ++-- .../audiotools-custom-min.ino | 4 ++-- .../audiotools-standard/audiotools-standard.ino | 4 ++-- examples/custom/custom-max/custom-max.ino | 4 ++++ examples/custom/custom-min/custom-min.ino | 4 ++++ .../custom/custom-standard/custom-standard.ino | 4 ++++ src/AudioBoard.h | 4 +++- src/Common.h | 17 +++++++++++------ 8 files changed, 32 insertions(+), 13 deletions(-) diff --git a/examples/audiotools/audiotools-custom-max/audiotools-custom-max.ino b/examples/audiotools/audiotools-custom-max/audiotools-custom-max.ino index 1eb841c..ed9b0bc 100644 --- a/examples/audiotools/audiotools-custom-max/audiotools-custom-max.ino +++ b/examples/audiotools/audiotools-custom-max/audiotools-custom-max.ino @@ -18,8 +18,8 @@ StreamCopy copier(out, sound); void setup() { // Setup logging Serial.begin(115200); - AudioLogger::instance().begin(Serial, AudioLogger::Info); - LOGLEVEL_AUDIODRIVER = AudioDriverInfo; + AudioLogger::instance().begin(Serial, AudioLogger::Warning); + LOGLEVEL_AUDIODRIVER = AudioDriverWarning; // setup pins // - add i2c codec pins: scl, sda, port, (I2C object) diff --git a/examples/audiotools/audiotools-custom-min/audiotools-custom-min.ino b/examples/audiotools/audiotools-custom-min/audiotools-custom-min.ino index 7393ed9..50b279a 100644 --- a/examples/audiotools/audiotools-custom-min/audiotools-custom-min.ino +++ b/examples/audiotools/audiotools-custom-min/audiotools-custom-min.ino @@ -17,8 +17,8 @@ StreamCopy copier(out, sound); void setup() { // Setup logging Serial.begin(115200); - AudioLogger::instance().begin(Serial, AudioLogger::Info); - LOGLEVEL_AUDIODRIVER = AudioDriverInfo; + AudioLogger::instance().begin(Serial, AudioLogger::Warning); + LOGLEVEL_AUDIODRIVER = AudioDriverWarning; // initialize i2c because board has no i2c definition Wire.begin(); diff --git a/examples/audiotools/audiotools-standard/audiotools-standard.ino b/examples/audiotools/audiotools-standard/audiotools-standard.ino index a2fa0e0..394f29b 100644 --- a/examples/audiotools/audiotools-standard/audiotools-standard.ino +++ b/examples/audiotools/audiotools-standard/audiotools-standard.ino @@ -16,8 +16,8 @@ StreamCopy copier(out, sound); void setup() { // Setup logging Serial.begin(115200); - AudioLogger::instance().begin(Serial, AudioLogger::Info); - LOGLEVEL_AUDIODRIVER = AudioDriverInfo; + AudioLogger::instance().begin(Serial, AudioLogger::Warning); + LOGLEVEL_AUDIODRIVER = AudioDriverWarning; // start I2S & codec with i2c and i2s configured above Serial.println("starting I2S..."); diff --git a/examples/custom/custom-max/custom-max.ino b/examples/custom/custom-max/custom-max.ino index 4439b58..dbfec6c 100644 --- a/examples/custom/custom-max/custom-max.ino +++ b/examples/custom/custom-max/custom-max.ino @@ -11,6 +11,10 @@ DriverPins my_pins; AudioBoard board(AudioDriverES8388); void setup() { + // Setup logging + Serial.begin(115200); + LOGLEVEL_AUDIODRIVER = AudioDriverInfo; + // add i2c codec pins: scl, sda, port my_pins.addI2C(CODEC, 32, 22, 0x20); // example add other pins: PA on gpio 21 diff --git a/examples/custom/custom-min/custom-min.ino b/examples/custom/custom-min/custom-min.ino index fce7c09..bb4fa6f 100644 --- a/examples/custom/custom-min/custom-min.ino +++ b/examples/custom/custom-min/custom-min.ino @@ -9,6 +9,10 @@ AudioBoard board(AudioDriverES8388); void setup() { + // Setup logging + Serial.begin(115200); + LOGLEVEL_AUDIODRIVER = AudioDriverInfo; + // start I2C for the communication with the codec Wire.begin(); // configure codec diff --git a/examples/custom/custom-standard/custom-standard.ino b/examples/custom/custom-standard/custom-standard.ino index 62419f7..d42cf42 100644 --- a/examples/custom/custom-standard/custom-standard.ino +++ b/examples/custom/custom-standard/custom-standard.ino @@ -6,6 +6,10 @@ #include "AudioBoard.h" void setup() { + // Setup logging + Serial.begin(115200); + LOGLEVEL_AUDIODRIVER = AudioDriverInfo; + // configure codec CodecConfig cfg; cfg.adc_input = ADC_INPUT_LINE1; diff --git a/src/AudioBoard.h b/src/AudioBoard.h index b2a5c99..2599dca 100644 --- a/src/AudioBoard.h +++ b/src/AudioBoard.h @@ -23,7 +23,9 @@ class AudioBoard { } bool begin(){ - return pins.begin() && driver->begin(codec_cfg, pins); + bool result = pins.begin() && driver->begin(codec_cfg, pins); + setVolume(DRIVER_DEFAULT_VOLUME); + return result; } bool begin(CodecConfig cfg) { diff --git a/src/Common.h b/src/Common.h index 8555611..1236f39 100644 --- a/src/Common.h +++ b/src/Common.h @@ -7,19 +7,24 @@ * @defgroup enumerations Public enumeration types */ -/// Definitions for error constants. -#define RESULT_OK 0 /*!< error_t value indicating success (no error) */ -#define RESULT_FAIL -1 /*!< Generic error_t code indicating failure */ -#define ERROR_INVALID_ARG 1 -#define I2C_END true +// Default volume at startup +#ifndef DRIVER_DEFAULT_VOLUME +# define DRIVER_DEFAULT_VOLUME 70 +#endif // Define the default gain for the microphone amp (see values from // es_mic_gain_t) Alternativly you can call es8388_set_mic_gain(es_mic_gain_t // gain) if you prefer to use value from an comprehensive enum #ifndef ES8388_DEFAULT_INPUT_GAIN -#define ES8388_DEFAULT_INPUT_GAIN 25 +# define ES8388_DEFAULT_INPUT_GAIN 25 #endif +/// Fixed Definitions +#define RESULT_OK 0 /*!< error_t value indicating success (no error) */ +#define RESULT_FAIL -1 /*!< Generic error_t code indicating failure */ +#define ERROR_INVALID_ARG 1 +#define I2C_END true + #ifdef __cplusplus namespace audio_driver { #endif