Skip to content

Commit

Permalink
Sync with sample stuffing (CarlosDerSeher#69)
Browse files Browse the repository at this point in the history
* upgrade to IDF v5.1.1
* add new synchronization implementation, use sample stuffing / removal to keep up sync
* use big DMA buffer for I2S and improve sync
* Add DAC TAS5805M as custom board
* add wifi credential reset
  o press reset button (nRESET pin) 3 times
    but wait about 1s between button presses
    the button press counter is reset 5s after boot
* Add support for PT8211 DAC (CarlosDerSeher#78)
* upgrade ethernet interface to IDF v5 (CarlosDerSeher#84)
* port official example of ethernet for IDF v5.x
* Fix cmake if guard for ethernet

Signed-off-by: Karl Osterseher <[email protected]>
Co-authored-by: DerPicknicker <[email protected]>
Co-authored-by: whc2001 <[email protected]>
  • Loading branch information
3 people authored and Andriy Malyshenko committed Jun 14, 2024
1 parent 7e355cd commit 34af2f8
Show file tree
Hide file tree
Showing 20 changed files with 2,566 additions and 1,174 deletions.
773 changes: 429 additions & 344 deletions .project

Large diffs are not rendered by default.

37 changes: 35 additions & 2 deletions components/audio_board/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
menu "Audio Board"

config I2S_USE_MSB_FORMAT
bool
default n
help
Specifies if the I2S should use MSB format instead. Some DACs (such as PT8211) need this enabled to ensure
compatibility with their LSBJ timing under their native bit-depth. This option is only adjusted by the DAC
choice and is not exposed to menuconfig.
See https://github.com/schreibfaul1/ESP32-audioI2S/blob/1d9b299d0197f99fc70335295adcd226dc220f88/src/Audio.cpp#L4929

choice AUDIO_BOARD
prompt "Audio board"
default ESP_LYRAT_V4_3_BOARD
Expand Down Expand Up @@ -93,28 +102,34 @@ menu "Audio Board"
config DAC_TAS5805M
bool "Texas Instruments TAS5805M"

config DAC_PT8211
bool "Princeton Technology PT8211"
select I2S_USE_MSB_FORMAT

endchoice

menu "DAC I2C control interface"
config DAC_I2C_SDA
int "SDA pin"
default 12 if DAC_ADAU1961
default 21 if DAC_MA120 || DAC_PCM51XX || DAC_MA120 || DAC_MA120X0 || DAC_MAX98357 || DAC_PCM5102A || DAC_TAS5805M

default -1 if DAC_PT8211
help
I2C SDA pin of the DAC control interface
config DAC_I2C_SCL
int "SCL pin"
default 14 if DAC_ADAU1961
default 22 if DAC_MA120 || DAC_PCM51XX || DAC_MA120 || DAC_MA120X0 || DAC_MAX98357 || DAC_PCM5102A
default 27 if DAC_TAS5805M
default 27 if DAC_TAS5805M
default -1 if DAC_PT8211
help
I2C SCL pin of the DAC control interface
config DAC_I2C_ADDR
hex "I2C address"
default 0x70 if DAC_ADAU1961
default 0x20 if DAC_MA120 || DAC_PCM51XX || DAC_MA120 || DAC_MA120X0 || DAC_MAX98357 || DAC_PCM5102A
default 0x2D if DAC_TAS5805M
default 0x00 if DAC_PT8211
help
I2C Address of the DAC control interface
endmenu
Expand Down Expand Up @@ -274,6 +289,24 @@ menu "Audio Board"
This is labeled "SD" on chip/boards.
endmenu

menu "PT8211 interface Configuration"
depends on DAC_PT8211

config PT8211_MUTE_PIN
int "Master mute/unmute"
default -1
help
GPIO number to control mute/unmute.
Note that PT8211 does not have a mute control pin. This output is intended to control external circuit (e.g., amplifier).

config PT8211_MUTE_ACTIVE_LOW
bool "Mute active LOW"
default false
help
Output LOW instead of HIGH on mute/unmute pin when in mute state.

endmenu

menu "Logic-Level-Settings"
config INVERT_MCLK_LEVEL
bool "Invert Logic Level MCLK"
Expand Down
6 changes: 6 additions & 0 deletions components/custom_board/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ if(CONFIG_AUDIO_BOARD_CUSTOM)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./tas5805m/include)
list(APPEND COMPONENT_SRCS ./tas5805m/tas5805m.c)
endif()

if(CONFIG_DAC_PT8211)
message(STATUS "Selected DAC is " CONFIG_DAC_PT8211)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./pt8211/include)
list(APPEND COMPONENT_SRCS ./pt8211/pt8211.c)
endif()
endif()

register_component()
Expand Down
5 changes: 5 additions & 0 deletions components/custom_board/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ COMPONENT_ADD_INCLUDEDIRS += ./tas5805m/include
COMPONENT_SRCDIRS += ./tas5805m
endif

ifdef CONFIG_DAC_PT8211
COMPONENT_ADD_INCLUDEDIRS += ./pt8211/include
COMPONENT_SRCDIRS += ./pt8211
endif

endif
3 changes: 3 additions & 0 deletions components/custom_board/generic_board/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ extern audio_hal_func_t AUDIO_CODEC_MAX98357_DEFAULT_HANDLE;
#elif CONFIG_DAC_TAS5805M
extern audio_hal_func_t AUDIO_CODEC_TAS5805M_DEFAULT_HANDLE;
#define AUDIO_CODEC_DEFAULT_HANDLE AUDIO_CODEC_TAS5805M_DEFAULT_HANDLE
#elif CONFIG_DAC_PT8211
extern audio_hal_func_t AUDIO_CODEC_PT8211_DEFAULT_HANDLE;
#define AUDIO_CODEC_DEFAULT_HANDLE AUDIO_CODEC_PT8211_DEFAULT_HANDLE
#endif

static const char *TAG = "AUDIO_BOARD";
Expand Down
49 changes: 49 additions & 0 deletions components/custom_board/pt8211/include/pt8211.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Princeton Technology PT8211 audio hal
*/

#ifndef _PT8211_H_
#define _PT8211_H_

#include "audio_hal.h"
#include "esp_err.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* Initialize PT8211 codec chip
*/
esp_err_t pt8211_init(audio_hal_codec_config_t *codec_cfg);

/**
* Deinitialize PT8211 codec chip
*/
esp_err_t pt8211_deinit(void);

/**
* Set volume - NOT AVAILABLE
*/
esp_err_t pt8211_set_volume(int vol);

/**
* Get volume - NOT AVAILABLE
*/
esp_err_t pt8211_get_volume(int *value);

/**
* Set PT8211 mute or not
*/
esp_err_t pt8211_set_mute(bool enable);

/**
* Get PT8211 mute status - NOT IMPLEMENTED
*/
esp_err_t pt8211_get_mute(bool *enabled);

#ifdef __cplusplus
}
#endif

#endif
90 changes: 90 additions & 0 deletions components/custom_board/pt8211/pt8211.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Princeton Technology PT8211 audio hal
*
* Mostly stubs (no I2C or volume control)
* Configuration of mute/unmute gpio in init (for external amplifier)
*/

#include "pt8211.h"

#include <driver/gpio.h>

#include "board.h"
#include "esp_log.h"

#ifndef CONFIG_PT8211_MUTE_ACTIVE_LOW
#define CONFIG_PT8211_MUTE_ACTIVE_LOW 0
#endif

static const char *TAG = "PT8211";

esp_err_t pt8211_ctrl(audio_hal_codec_mode_t mode, audio_hal_ctrl_t ctrl_state);
esp_err_t pt8211_config_iface(audio_hal_codec_mode_t mode,
audio_hal_codec_i2s_iface_t *iface);

audio_hal_func_t AUDIO_CODEC_PT8211_DEFAULT_HANDLE = {
.audio_codec_initialize = pt8211_init,
.audio_codec_deinitialize = pt8211_deinit,
.audio_codec_ctrl = pt8211_ctrl,
.audio_codec_config_iface = pt8211_config_iface,
.audio_codec_set_mute = pt8211_set_mute,
.audio_codec_set_volume = pt8211_set_volume,
.audio_codec_get_volume = pt8211_get_volume,
.audio_hal_lock = NULL,
.handle = NULL,
};

esp_err_t pt8211_init(audio_hal_codec_config_t *codec_cfg) {
esp_err_t ret = ESP_OK;

#if CONFIG_PT8211_MUTE_PIN != -1
gpio_config_t io_conf;

io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = (1ULL << CONFIG_PT8211_MUTE_PIN);
io_conf.pull_down_en = 0;
io_conf.pull_up_en = 0;

ret = gpio_config(&io_conf);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Mute gpio config failed for pin %d", CONFIG_PT8211_MUTE_PIN);
} else {
gpio_set_level(CONFIG_PT8211_MUTE_PIN, 0);
ESP_LOGD(TAG, "Setup mute output %d\n", CONFIG_PT8211_MUTE_PIN);
}
#else
ESP_LOGD(TAG, "Mute gpio not specified\n");
#endif

return ret;
}

esp_err_t pt8211_set_volume(int vol) { return ESP_OK; }

esp_err_t pt8211_get_volume(int *value) { return ESP_OK; }

esp_err_t pt8211_set_mute(bool enable) {
esp_err_t ret = ESP_OK;

#if CONFIG_PT8211_MUTE_PIN != -1
ret = gpio_set_level(CONFIG_PT8211_MUTE_PIN,
enable ^ CONFIG_PT8211_MUTE_ACTIVE_LOW);
#endif

return ret;
}

esp_err_t pt8211_get_mute(bool *enabled) { return ESP_OK; }

esp_err_t pt8211_deinit(void) { return gpio_reset_pin(CONFIG_PT8211_MUTE_PIN); }

esp_err_t pt8211_ctrl(audio_hal_codec_mode_t mode,
audio_hal_ctrl_t ctrl_state) {
return ESP_OK;
}

esp_err_t pt8211_config_iface(audio_hal_codec_mode_t mode,
audio_hal_codec_i2s_iface_t *iface) {
return ESP_OK;
}
12 changes: 2 additions & 10 deletions components/eth_interface/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@

if(CONFIG_SNAPCLIENT_ENABLE_ETHERNET)

idf_component_register(SRCS "eth_interface.c"
INCLUDE_DIRS "include")

else()

idf_component_register()

endif()
INCLUDE_DIRS "include"
REQUIRES driver esp_eth esp_netif)
Loading

0 comments on commit 34af2f8

Please sign in to comment.