Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
Resolve conflicts with AudioTools
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Dec 12, 2021
1 parent 0ed1d68 commit d0f4d98
Show file tree
Hide file tree
Showing 44 changed files with 1,434 additions and 207 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions LICENSE-espressif
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ESPRESSIF MIT License

Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>

Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
it is free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ You can define your board and the default settings in the ```AudioKitSettings.h`
* 3) lyrat_mini_v1_1
* 4) esp32_s2_kaluga_1_v1_2
* 5) ai_thinker_v2_2
* 6) generic_es8388
*/
#define AUDIOKIT_BOARD 1
Expand Down Expand Up @@ -75,7 +76,8 @@ The functionality has a built in logger. The default log level has been set to W

## Documentation

Here is the documentaion of the [AudioKit class](https://pschatzmann.github.io/arduino-audiokit-hal/html/class_audio_kit.html)
Here is the documentaion of the [AudioKit class](https://pschatzmann.github.io/arduino-audiokit/html/class_audio_kit.html).

Further information can be found in my [Blogs](https://www.pschatzmann.ch/home/tag/esp32audiokit/).


Expand All @@ -92,7 +94,7 @@ git clone https://github.com/pschatzmann/arduino-audiokit.git
If you want to use the library in PlatformIO, you can find a [detailed description in the Wiki](https://github.com/pschatzmann/arduino-audiokit-hal/wiki/PlatformIO).


## Supprted Devices / Processors
## Supported Devices / Processors

The examples have been tested with a AI Thinker v2.2. I do not own any other AudioKit devices, so I can't guarantee that they work properly. I also made sure that the code is compiling on other processors, but I did not perform any tests. Please note that because I2S is not standardized in Arduino, you need to take care of the I2S initialization and processing yourself on other processors.

Expand Down
3 changes: 1 addition & 2 deletions examples/input/input.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @file input.ino
* @author Phil Schatzmann
* @brief Input of audio data from the AudioKit microphones
* @version 0.1
* @date 2021-12-10
*
* @copyright Copyright (c) 2021
Expand All @@ -26,7 +25,7 @@ void printBuffer(int len){

void setup() {
Serial.begin(115200);
// open in write mode
// open in read mode
auto cfg = kit.defaultConfig(false);
cfg.adc_input = AUDIO_HAL_ADC_INPUT_LINE1; // microphone
cfg.sample_rate = AUDIO_HAL_16K_SAMPLES;
Expand Down
10 changes: 10 additions & 0 deletions examples/output/SineWaveGenerator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/**
* @file SineWaveGenerator.h
* @author Phil Schatzmann
* @brief A simple sine wave generator
* @version 0.1
* @date 2021-12-12
*
* @copyright Copyright (c) 2021
*
*/
#pragma once

#include <stdint.h>
Expand Down
1 change: 0 additions & 1 deletion examples/output/output.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @file output.ino
* @author Phil Schatzmann
* @brief Output of audio data to the AudioKit
* @version 0.1
* @date 2021-12-10
*
* @copyright Copyright (c) 2021
Expand Down
1 change: 0 additions & 1 deletion examples/sdbegin/sdbegin.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @file sdbegin.ino
* @author Phil Schatzmann
* @brief A simple test if we can start the SD of the AudioKit
* @version 0.1
* @date 2021-12-10
*
* @copyright Copyright (c) 2021
Expand Down
46 changes: 29 additions & 17 deletions src/AudioKit.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/**
* @file AudioKit.h
* @author Phil Schatzmann
* @brief Arduino API for AudioKit
* @version 0.1
* @date 2021-12-12
*
* @copyright Copyright (c) 2021
*
*/
#pragma once
#include "AudioKitSettings.h"

Expand All @@ -12,9 +22,11 @@
#include "audiokit_board.h"
#include "audiokit_logger.h"
#include "SPI.h"

#ifdef ESP32
#include "esp_a2dp_api.h"
#include "audio_system.h"
#include "audio_version.h"
#include "driver/i2s.h"
#endif

Expand All @@ -30,9 +42,9 @@
(I2S_COMM_FORMAT_PCM | I2S_COMM_FORMAT_PCM_LONG)
#define I2S_COMM_FORMAT_STAND_PCM_SHORT \
(I2S_COMM_FORMAT_PCM | I2S_COMM_FORMAT_PCM_SHORT)
typedef int eps32_i2s_sample_rate_type;
typedef int eps32_i2s_audio_sample_rate_type;
#else
typedef uint32_t eps32_i2s_sample_rate_type;
typedef uint32_t eps32_i2s_audio_sample_rate_type;
#endif

/**
Expand Down Expand Up @@ -71,7 +83,7 @@ struct AudioKitConfig {
case AUDIO_HAL_BIT_LENGTH_32BITS:
return 32;
}
// LOGE("bits_per_sample not supported: %d", bits_per_sample);
// KIT_LOGE("bits_per_sample not supported: %d", bits_per_sample);
return 0;
}

Expand All @@ -95,7 +107,7 @@ struct AudioKitConfig {
case AUDIO_HAL_48K_SAMPLES: /*!< set to 48k samples per second */
return 48000;
}
// LOGE("sample rate not supported: %d", sample_rate);
// KIT_LOGE("sample rate not supported: %d", sample_rate);
return 0;
}

Expand Down Expand Up @@ -199,8 +211,8 @@ class AudioKit {

/// Starts the codec
bool begin(AudioKitConfig cnfg) {
LOGI(LOG_METHOD);
LOGI("Selected board: %d", AUDIOKIT_BOARD);
KIT_LOGI(LOG_METHOD);
KIT_LOGI("Selected board: %d", AUDIOKIT_BOARD);

audio_hal_conf.adc_input = cfg.adc_input;
audio_hal_conf.dac_output = cfg.dac_output;
Expand All @@ -212,7 +224,7 @@ class AudioKit {

hal_handle = audio_hal_init(&audio_hal_conf, &AUDIO_DRIVER);
if (hal_handle == 0) {
LOGE("audio_hal_init");
KIT_LOGE("audio_hal_init");
return false;
}

Expand All @@ -223,27 +235,27 @@ class AudioKit {
// setup i2s driver - with no queue
i2s_config_t i2s_config = cfg.i2sConfig();
if (i2s_driver_install(cfg.i2s_num, &i2s_config, 0, NULL) != ESP_OK) {
LOGE("i2s_driver_install");
KIT_LOGE("i2s_driver_install");
return false;
}

// define i2s pins
i2s_pin_config_t pin_config = cfg.i2sPins();
if (i2s_set_pin(cfg.i2s_num, &pin_config) != ESP_OK) {
LOGE("i2s_set_pin");
KIT_LOGE("i2s_set_pin");
return false;
}

if (i2s_mclk_gpio_select(cfg.i2s_num, cfg.mclk_gpio) != ESP_OK) {
LOGE("i2s_mclk_gpio_select");
KIT_LOGE("i2s_mclk_gpio_select");
return false;
}

#endif

// call start
if (!setActive(true)) {
LOGE("setActive");
KIT_LOGE("setActive");
return false;
}

Expand All @@ -252,7 +264,7 @@ class AudioKit {

/// Stops the CODEC
bool end() {
LOGI(LOG_METHOD);
KIT_LOGI(LOG_METHOD);

#ifdef ESP32
// uninstall i2s driver
Expand Down Expand Up @@ -299,23 +311,23 @@ class AudioKit {
/// Writes the audio data via i2s to the DAC
size_t write(const void *src, size_t size,
TickType_t ticks_to_wait = portMAX_DELAY) {
LOGD("write: %zu", size);
KIT_LOGD("write: %zu", size);
size_t bytes_written = 0;
if (i2s_write(cfg.i2s_num, src, size, &bytes_written, ticks_to_wait) !=
ESP_OK) {
LOGE("i2s_write");
KIT_LOGE("i2s_write");
}
return bytes_written;
}

/// Reads the audio data via i2s from the ADC
size_t read(void *dest, size_t size,
TickType_t ticks_to_wait = portMAX_DELAY) {
LOGD("read: %zu", size);
KIT_LOGD("read: %zu", size);
size_t bytes_read = 0;
if (i2s_read(cfg.i2s_num, dest, size, &bytes_read, ticks_to_wait) !=
ESP_OK) {
LOGE("i2s_read");
KIT_LOGE("i2s_read");
}
return bytes_read;
}
Expand Down Expand Up @@ -463,7 +475,7 @@ class AudioKit {
* @brief Setup the SPI so that we can access the SD Drive
*/
void setupSPI() {
LOGD(LOG_METHOD);
KIT_LOGD(LOG_METHOD);
// I assume this is valid for all AudioKits!
#if defined(ESP32) && defined(AUDIOKIT_SETUP_SD)
spi_cs_pin = PIN_AUDIO_KIT_SD_CARD_CS;
Expand Down
25 changes: 15 additions & 10 deletions src/AudioKitSettings.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#pragma once

/**
* @file AudioKitSettings.h
* @author Phil Schatzmann
* @brief AUDIOKIT_BOARD selects a specic board:
* 1) lyrat_v4_3
* 2) lyrat_v4_2
* 3) lyrat_mini_v1_1
* 4) lyratd_msc_v2_2
* 5) lyratd_msc_v2_1
* 6) ai_thinker_v2_2
* 7) esp32_s2_kaluga_1_v1_2
* 1) lyrat_v4_3
* 2) lyrat_v4_2
* 3) lyrat_mini_v1_1
* 4) esp32_s2_kaluga_1_v1_2
* 5) ai_thinker_v2_2
* 6) generci_es8388
* @version 0.1
* @date 2021-12-12
*
* @copyright Copyright (c) 2021
*/

#pragma once

#ifndef AUDIOKIT_BOARD
#define AUDIOKIT_BOARD 5
#define AUDIOKIT_BOARD 6
#endif

// Default settings
Expand Down
2 changes: 1 addition & 1 deletion src/audio_board/ai_thinker_v2_2/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static audio_board_handle_t board_handle = 0;
audio_board_handle_t audio_board_init(void)
{
if (board_handle) {
LOGW("The board has already been initialized!");
KIT_LOGW("The board has already been initialized!");
return board_handle;
}
board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle));
Expand Down
18 changes: 9 additions & 9 deletions src/audio_board/ai_thinker_v2_2/board_pins_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config)
} else {
i2c_config->sda_io_num = -1;
i2c_config->scl_io_num = -1;
LOGE( "i2c port %d is not supported", port);
KIT_LOGE( "i2c port %d is not supported", port);
return ESP_FAIL;
}

LOGI("i2c port: %d", port);
LOGI("i2c sda: %d", i2c_config->sda_io_num);
LOGI("i2c scl: %d", i2c_config->scl_io_num);
KIT_LOGI("i2c port: %d", port);
KIT_LOGI("i2c sda: %d", i2c_config->sda_io_num);
KIT_LOGI("i2c scl: %d", i2c_config->scl_io_num);

return ESP_OK;
}
Expand All @@ -65,7 +65,7 @@ esp_err_t get_i2s_pins(i2s_port_t port, i2s_pin_config_t *i2s_config)
i2s_config->data_in_num = GPIO_NUM_35;
} else {
memset(i2s_config, -1, sizeof(i2s_pin_config_t));
LOGE( "i2s port %d is not supported", port);
KIT_LOGE( "i2s port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
Expand All @@ -85,21 +85,21 @@ esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config

spi_device_interface_config->spics_io_num = -1;

LOGW("SPI interface is not supported");
KIT_LOGW("SPI interface is not supported");
return ESP_OK;
}

esp_err_t i2s_mclk_gpio_select(i2s_port_t i2s_num, gpio_num_t gpio_num)
{
if (i2s_num >= I2S_NUM_MAX) {
LOGE( "Does not support i2s number(%d)", i2s_num);
KIT_LOGE( "Does not support i2s number(%d)", i2s_num);
return ESP_ERR_INVALID_ARG;
}
if (gpio_num != GPIO_NUM_0 && gpio_num != GPIO_NUM_1 && gpio_num != GPIO_NUM_3) {
LOGE( "Only support GPIO0/GPIO1/GPIO3, gpio_num:%d", gpio_num);
KIT_LOGE( "Only support GPIO0/GPIO1/GPIO3, gpio_num:%d", gpio_num);
return ESP_ERR_INVALID_ARG;
}
LOGI( "I2S%d, MCLK output by GPIO%d", i2s_num, gpio_num);
KIT_LOGI( "I2S%d, MCLK output by GPIO%d", i2s_num, gpio_num);
if (i2s_num == I2S_NUM_0) {
if (gpio_num == GPIO_NUM_0) {
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1);
Expand Down
2 changes: 1 addition & 1 deletion src/audio_board/esp32_s2_kaluga_1_v1_2/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static audio_board_handle_t board_handle = NULL;
audio_board_handle_t audio_board_init(void)
{
if (board_handle) {
LOGW("The board has already been initialized!");
KIT_LOGW("The board has already been initialized!");
return board_handle;
}
board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle));
Expand Down
8 changes: 4 additions & 4 deletions src/audio_board/esp32_s2_kaluga_1_v1_2/board_pins_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config)
} else {
i2c_config->sda_io_num = -1;
i2c_config->scl_io_num = -1;
LOGE( "i2c port %d is not supported", port);
KIT_LOGE( "i2c port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
Expand Down Expand Up @@ -74,18 +74,18 @@ esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config

spi_device_interface_config->spics_io_num = -1;

LOGW("SPI interface is not supported");
KIT_LOGW("SPI interface is not supported");
return ESP_OK;
}

esp_err_t i2s_mclk_gpio_select(i2s_port_t i2s_num, gpio_num_t gpio_num)
{
if (i2s_num >= I2S_NUM_MAX) {
LOGE( "Does not support i2s number(%d)", i2s_num);
KIT_LOGE( "Does not support i2s number(%d)", i2s_num);
return ESP_ERR_INVALID_ARG;
}
gpio_num = (gpio_num_t)GPIO_NUM_35;
LOGD( "I2S%d, MCLK output by GPIO%d", i2s_num, gpio_num);
KIT_LOGD( "I2S%d, MCLK output by GPIO%d", i2s_num, gpio_num);
gpio_matrix_out(gpio_num, CLK_I2S_MUX_IDX, 0, 0);

return ESP_OK;
Expand Down
Loading

0 comments on commit d0f4d98

Please sign in to comment.