From b426acc78eab412e62a44d4ac950e7b76d09ee06 Mon Sep 17 00:00:00 2001 From: majoreffort <41589814+majoreffort@users.noreply.github.com> Date: Sun, 24 Jul 2022 17:25:58 +0200 Subject: [PATCH] Added TI PCM5102A custom board --- components/custom_board/CMakeLists.txt | 6 ++ components/custom_board/Kconfig.projbuild | 14 +++ components/custom_board/component.mk | 5 + components/custom_board/generic_board/board.c | 3 + .../custom_board/pcm5102a/include/pcm5102a.h | 49 ++++++++++ components/custom_board/pcm5102a/pcm5102a.c | 94 +++++++++++++++++++ 6 files changed, 171 insertions(+) create mode 100644 components/custom_board/pcm5102a/include/pcm5102a.h create mode 100644 components/custom_board/pcm5102a/pcm5102a.c diff --git a/components/custom_board/CMakeLists.txt b/components/custom_board/CMakeLists.txt index dc21f86..5a1d737 100644 --- a/components/custom_board/CMakeLists.txt +++ b/components/custom_board/CMakeLists.txt @@ -16,6 +16,12 @@ if(CONFIG_AUDIO_BOARD_CUSTOM) list(APPEND COMPONENT_SRCS ./pcm51xx/pcm51xx.c) endif() + if(CONFIG_DAC_PCM5102A) + message(STATUS "Selected DAC is " CONFIG_DAC_PCM5102A) + list(APPEND COMPONENT_ADD_INCLUDEDIRS ./pcm5102a/include) + list(APPEND COMPONENT_SRCS ./pcm5102a/pcm5102a.c) + endif() + if(CONFIG_DAC_MA120X0) message(STATUS "Selected DAC is " CONFIG_DAC_MA120X0) list(APPEND COMPONENT_ADD_INCLUDEDIRS ./ma120x0/include) diff --git a/components/custom_board/Kconfig.projbuild b/components/custom_board/Kconfig.projbuild index 705a43f..ae2b159 100644 --- a/components/custom_board/Kconfig.projbuild +++ b/components/custom_board/Kconfig.projbuild @@ -10,6 +10,9 @@ menu "Custom Audio Board" config DAC_PCM51XX bool "TI PCM51XX/TAS57XX based DAC" + config DAC_PCM5102A + bool "TI PCM5102A based DAC" + config DAC_MA120 bool "Infineon MA120 ClassD AMP" @@ -134,4 +137,15 @@ menu "Custom Audio Board" GPIO number low if clip observed endmenu + menu "TI PCM5102A interface Configuration" + depends on DAC_PCM5102A + + config PCM5102A_MUTE_PIN + int "Master mute/unmute for PCM5102A" + default 18 + help + GPIO number to control mute/unmute. + This is labeled "X(S)MT" on chip/boards + endmenu + endmenu diff --git a/components/custom_board/component.mk b/components/custom_board/component.mk index 75ac2e7..e5fbe4d 100644 --- a/components/custom_board/component.mk +++ b/components/custom_board/component.mk @@ -12,6 +12,11 @@ COMPONENT_ADD_INCLUDEDIRS += ./pcm51xx/include COMPONENT_SRCDIRS += ./pcm51xx endif +ifdef CONFIG_DAC_PCM5102A +COMPONENT_ADD_INCLUDEDIRS += ./pcm5102a/include +COMPONENT_SRCDIRS += ./pcm5102a +endif + ifdef CONFIG_DAC_MA120X0 COMPONENT_ADD_INCLUDEDIRS += ./ma120x0/include COMPONENT_SRCDIRS += ./ma120x0 diff --git a/components/custom_board/generic_board/board.c b/components/custom_board/generic_board/board.c index 8f9cff2..ea6865a 100644 --- a/components/custom_board/generic_board/board.c +++ b/components/custom_board/generic_board/board.c @@ -34,6 +34,9 @@ #if CONFIG_DAC_PCM51XX extern audio_hal_func_t AUDIO_CODEC_PCM51XX_DEFAULT_HANDLE; #define AUDIO_CODEC_DEFAULT_HANDLE AUDIO_CODEC_PCM51XX_DEFAULT_HANDLE +#elif CONFIG_DAC_PCM5102A +extern audio_hal_func_t AUDIO_CODEC_PCM5102A_DEFAULT_HANDLE; +#define AUDIO_CODEC_DEFAULT_HANDLE AUDIO_CODEC_PCM5102A_DEFAULT_HANDLE #elif CONFIG_DAC_MA120X0 extern audio_hal_func_t AUDIO_CODEC_MA120X0_DEFAULT_HANDLE; #define AUDIO_CODEC_DEFAULT_HANDLE AUDIO_CODEC_MA120X0_DEFAULT_HANDLE diff --git a/components/custom_board/pcm5102a/include/pcm5102a.h b/components/custom_board/pcm5102a/include/pcm5102a.h new file mode 100644 index 0000000..8de0fbc --- /dev/null +++ b/components/custom_board/pcm5102a/include/pcm5102a.h @@ -0,0 +1,49 @@ +/* + * TI PCM5102A audio hal + */ + +#ifndef _PCM5102A_H_ +#define _PCM5102A_H_ + +#include "audio_hal.h" +#include "esp_err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Initialize PCM5102A codec chip + */ +esp_err_t pcm5102a_init(audio_hal_codec_config_t *codec_cfg); + +/** + * Deinitialize PCM5102A codec chip + */ +esp_err_t pcm5102a_deinit(void); + +/** + * Set volume - NOT AVAILABLE + */ +esp_err_t pcm5102a_set_volume(int vol); + +/** + * Get volume - NOT AVAILABLE + */ +esp_err_t pcm5102a_get_volume(int *value); + +/** + * Set PCM5102A mute or not + */ +esp_err_t pcm5102a_set_mute(bool enable); + +/** + * Get PCM5102A mute status - NOT IMPLEMENTED + */ +esp_err_t pcm5102a_get_mute(bool *enabled); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/custom_board/pcm5102a/pcm5102a.c b/components/custom_board/pcm5102a/pcm5102a.c new file mode 100644 index 0000000..f116796 --- /dev/null +++ b/components/custom_board/pcm5102a/pcm5102a.c @@ -0,0 +1,94 @@ +/* + * TI PCM5102A audio hal + * + * Mostly stubs (no I2C or volume control) + * Configuration of mute/unmute gpio in init (connected to XSMT) + */ + +#include "pcm5102a.h" + +#include "board.h" +#include "esp_log.h" +#include + +static const char *TAG = "PCM5102A"; + + +#define PCM5102A_ASSERT(a, format, b, ...) \ + if ((a) != 0) { \ + ESP_LOGE(TAG, format, ##__VA_ARGS__); \ + return b; \ + } + +esp_err_t pcm5102a_ctrl(audio_hal_codec_mode_t mode, + audio_hal_ctrl_t ctrl_state); +esp_err_t pcm5102a_config_iface(audio_hal_codec_mode_t mode, + audio_hal_codec_i2s_iface_t *iface); + + +audio_hal_func_t AUDIO_CODEC_PCM5102A_DEFAULT_HANDLE = { + .audio_codec_initialize = pcm5102a_init, + .audio_codec_deinitialize = pcm5102a_deinit, + .audio_codec_ctrl = pcm5102a_ctrl, + .audio_codec_config_iface = pcm5102a_config_iface, + .audio_codec_set_mute = pcm5102a_set_mute, + .audio_codec_set_volume = pcm5102a_set_volume, + .audio_codec_get_volume = pcm5102a_get_volume, + .audio_hal_lock = NULL, + .handle = NULL, +}; + +esp_err_t pcm5102a_init(audio_hal_codec_config_t *codec_cfg) { + esp_err_t ret; + + gpio_config_t io_conf; + + io_conf.intr_type = GPIO_PIN_INTR_DISABLE; + io_conf.mode = GPIO_MODE_OUTPUT; + io_conf.pin_bit_mask = (1ULL << CONFIG_PCM5102A_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_PCM5102A_MUTE_PIN); + } + else + { + gpio_set_level(CONFIG_PCM5102A_MUTE_PIN, 0); + ESP_LOGD(TAG, "Setup mute (XMT) output %d\n", CONFIG_PCM5102A_MUTE_PIN); + } + + return ret; +} + +esp_err_t pcm5102a_set_volume(int vol) { + return ESP_OK; +} + +esp_err_t pcm5102a_get_volume(int *value) { + return ESP_OK; +} + +esp_err_t pcm5102a_set_mute(bool enable) { + return gpio_set_level(CONFIG_PCM5102A_MUTE_PIN, enable ? 0 : 1); +} + +esp_err_t pcm5102a_get_mute(bool *enabled) { + return ESP_OK; +} + +esp_err_t pcm5102a_deinit(void) { + return gpio_reset_pin(CONFIG_PCM5102A_MUTE_PIN); +} + +esp_err_t pcm5102a_ctrl(audio_hal_codec_mode_t mode, + audio_hal_ctrl_t ctrl_state) { + return ESP_OK; +} + +esp_err_t pcm5102a_config_iface(audio_hal_codec_mode_t mode, + audio_hal_codec_i2s_iface_t *iface) { + return ESP_OK; +}