309 lines
7.5 KiB
C
309 lines
7.5 KiB
C
/**
|
|
* @file sdrv_codec.c
|
|
* @brief E3 Codec adapter driver
|
|
*
|
|
* @copyright Copyright (c) 2021 Semidrive Semiconductor.
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include <debug.h>
|
|
#include <irq.h>
|
|
#include <string.h>
|
|
|
|
#include "sdrv_codec_adapter.h"
|
|
|
|
/**
|
|
* @brief initializes codec module
|
|
*
|
|
* This function is used to initialize codec module.
|
|
*
|
|
*
|
|
* @param [in] codec sdrv codec device
|
|
* @param [in] cfg sdrv codec device configurations
|
|
* @return sdrv_codec_status_t
|
|
*
|
|
*/
|
|
sdrv_codec_status_t sdrv_codec_adapter_init(sdrv_codec_t *codec,
|
|
sdrv_codec_cfg_t *cfg)
|
|
{
|
|
|
|
ASSERT((codec != NULL) && (cfg != NULL));
|
|
sdrv_codec_status_t status = SDRV_CODEC_STATUS_SUCCESS;
|
|
|
|
codec->config = *cfg;
|
|
|
|
switch (cfg->codec_type) {
|
|
#if CONFIG_CODEC_AK4619
|
|
case SDRV_CODEC_AK4619:
|
|
status = sdrv_codec_ak4619_init(codec, cfg);
|
|
break;
|
|
#endif
|
|
#if CONFIG_CODEC_TLV320
|
|
case SDRV_CODEC_TLV320:
|
|
status = sdrv_codec_tlv320_init(codec, cfg);
|
|
break;
|
|
#endif
|
|
#if CONFIG_CODEC_TAS2505
|
|
case SDRV_CODEC_TAS2505:
|
|
status = sdrv_codec_tas2505_init(codec, cfg);
|
|
break;
|
|
#endif
|
|
|
|
default:
|
|
status = SDRV_CODEC_STATUS_INVALID_PARAMS;
|
|
break;
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
/**
|
|
* @brief brief set audio codec module params.
|
|
*
|
|
* This function is used to set codec params
|
|
*
|
|
* @param [in] codec sdrv codec device
|
|
* @param [in] params sdrv codec params
|
|
* @param [in] type playback or capture type
|
|
* @ return sdrv_codec_status_t
|
|
*
|
|
*
|
|
*/
|
|
sdrv_codec_status_t sdrv_codec_adapter_set_params(sdrv_codec_t *codec,
|
|
sdrv_codec_params_t *params,
|
|
sdrv_codec_stream_type_t type)
|
|
{
|
|
|
|
ASSERT((codec != NULL) && (params != NULL));
|
|
sdrv_codec_status_t status = SDRV_CODEC_STATUS_SUCCESS;
|
|
uint32_t codec_type = codec->config.codec_type;
|
|
|
|
switch (codec_type) {
|
|
#if CONFIG_CODEC_AK4619
|
|
case SDRV_CODEC_AK4619:
|
|
status = sdrv_codec_ak4619_set_params(codec, params, type);
|
|
break;
|
|
#endif
|
|
#if CONFIG_CODEC_TLV320
|
|
case SDRV_CODEC_TLV320:
|
|
status = sdrv_codec_tlv320_set_params(codec, params, type);
|
|
break;
|
|
#endif
|
|
#if CONFIG_CODEC_TAS2505
|
|
case SDRV_CODEC_TAS2505:
|
|
status = sdrv_codec_tas2505_set_params(codec, params, type);
|
|
break;
|
|
#endif
|
|
default:
|
|
status = SDRV_CODEC_STATUS_INVALID_PARAMS;
|
|
break;
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
/**
|
|
* @brief brief start or stop audio codec module
|
|
*
|
|
* This function is used to start audio codec module
|
|
*
|
|
* @param [in] codec sdrv codec device
|
|
* @param [in] type playback or capture type
|
|
* @ return sdrv_codec_status_t
|
|
*
|
|
*
|
|
*/
|
|
static sdrv_codec_status_t
|
|
sdrv_codec_adapter_start(sdrv_codec_t *codec, sdrv_codec_stream_type_t type)
|
|
{
|
|
|
|
sdrv_codec_status_t status = SDRV_CODEC_STATUS_SUCCESS;
|
|
uint32_t codec_type = codec->config.codec_type;
|
|
|
|
switch (codec_type) {
|
|
#if CONFIG_CODEC_AK4619
|
|
case SDRV_CODEC_AK4619:
|
|
sdrv_codec_ak4619_trigger(codec, SDRV_CODEC_TRIGGER_START, type);
|
|
break;
|
|
#endif
|
|
#if CONFIG_CODEC_TLV320
|
|
case SDRV_CODEC_TLV320:
|
|
sdrv_codec_tlv320_trigger(codec, SDRV_CODEC_TRIGGER_START, type);
|
|
break;
|
|
#endif
|
|
#if CONFIG_CODEC_TAS2505
|
|
case SDRV_CODEC_TAS2505:
|
|
sdrv_codec_tas2505_trigger(codec, SDRV_CODEC_TRIGGER_START, type);
|
|
break;
|
|
#endif
|
|
default:
|
|
status = SDRV_CODEC_STATUS_INVALID_PARAMS;
|
|
break;
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
/**
|
|
* @brief brief start or stop audio codec module
|
|
*
|
|
* This function is used to stop audio codec module
|
|
*
|
|
* @param [in] codec sdrv codec device
|
|
* @param [in] type playback or capture type
|
|
* @ return sdrv_codec_status_t
|
|
*
|
|
*
|
|
*/
|
|
static sdrv_codec_status_t
|
|
sdrv_codec_adapter_stop(sdrv_codec_t *codec, sdrv_codec_stream_type_t type)
|
|
{
|
|
|
|
sdrv_codec_status_t status = SDRV_CODEC_STATUS_SUCCESS;
|
|
uint32_t codec_type = codec->config.codec_type;
|
|
|
|
switch (codec_type) {
|
|
#if CONFIG_CODEC_AK4619
|
|
case SDRV_CODEC_AK4619:
|
|
sdrv_codec_ak4619_trigger(codec, SDRV_CODEC_TRIGGER_STOP, type);
|
|
break;
|
|
#endif
|
|
|
|
#if CONFIG_CODEC_TLV320
|
|
case SDRV_CODEC_TLV320:
|
|
sdrv_codec_tlv320_trigger(codec, SDRV_CODEC_TRIGGER_STOP, type);
|
|
break;
|
|
#endif
|
|
|
|
#if CONFIG_CODEC_TAS2505
|
|
case SDRV_CODEC_TAS2505:
|
|
sdrv_codec_tas2505_trigger(codec, SDRV_CODEC_TRIGGER_STOP, type);
|
|
break;
|
|
#endif
|
|
|
|
default:
|
|
status = SDRV_CODEC_STATUS_INVALID_PARAMS;
|
|
break;
|
|
}
|
|
return status;
|
|
}
|
|
|
|
/**
|
|
* @brief brief start or stop audio codec module
|
|
*
|
|
* This function is used to start or stop audio codec module
|
|
*
|
|
* @param [in] codec sdrv codec device
|
|
* @param [in] cmd start or stop cmd
|
|
* @param [in] type playback or capture type
|
|
* @ return sdrv_codec_status_t
|
|
*
|
|
*
|
|
*/
|
|
sdrv_codec_status_t sdrv_codec_adapter_trigger(sdrv_codec_t *codec,
|
|
sdrv_codec_trigger_op_t cmd,
|
|
sdrv_codec_stream_type_t type)
|
|
{
|
|
|
|
ASSERT(codec != NULL);
|
|
sdrv_codec_status_t status = SDRV_CODEC_STATUS_SUCCESS;
|
|
|
|
switch (cmd) {
|
|
|
|
case SDRV_CODEC_TRIGGER_START:
|
|
sdrv_codec_adapter_start(codec, type);
|
|
break;
|
|
case SDRV_CODEC_TRIGGER_STOP:
|
|
sdrv_codec_adapter_stop(codec, type);
|
|
break;
|
|
default:
|
|
status = SDRV_CODEC_STATUS_INVALID_PARAMS;
|
|
break;
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
/*!
|
|
* @brief set audio codec volume.
|
|
*
|
|
* @param codec_dev_t *
|
|
* @param volume volume value, support 0 ~ 100, 0 is mute, 100 is the maximum
|
|
* volume value.
|
|
*
|
|
* @return sdrv_codec_status_t is success, else configure failed.
|
|
*/
|
|
sdrv_codec_status_t sdrv_codec_adapter_set_volume(sdrv_codec_t *codec,
|
|
uint8_t volume,
|
|
sdrv_codec_stream_type_t type)
|
|
{
|
|
ASSERT(codec != NULL);
|
|
sdrv_codec_status_t status = SDRV_CODEC_STATUS_SUCCESS;
|
|
uint32_t codec_type = codec->config.codec_type;
|
|
|
|
switch (codec_type) {
|
|
#if CONFIG_CODEC_AK4619
|
|
case SDRV_CODEC_AK4619:
|
|
|
|
status = sdrv_codec_ak4619_set_volume(codec, volume, type);
|
|
break;
|
|
#endif
|
|
#if CONFIG_CODEC_TLV320
|
|
case SDRV_CODEC_TLV320:
|
|
status = sdrv_codec_tlv320_set_volume(codec, volume, type);
|
|
break;
|
|
#endif
|
|
#if CONFIG_CODEC_TAS2505
|
|
case SDRV_CODEC_TAS2505:
|
|
|
|
status = sdrv_codec_tas2505_set_volume(codec, volume, type);
|
|
break;
|
|
#endif
|
|
default:
|
|
status = SDRV_CODEC_STATUS_INVALID_PARAMS;
|
|
break;
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
/*!
|
|
* brief set audio codec module mute.
|
|
*
|
|
* param handle codec handle.
|
|
* param mute true is mute, false is unmute.
|
|
* return sdrv_codec_status_t is success, else configure failed.
|
|
*/
|
|
sdrv_codec_status_t sdrv_codec_adapter_set_mute(sdrv_codec_t *codec, bool mute,
|
|
sdrv_codec_stream_type_t type)
|
|
{
|
|
ASSERT(codec != NULL);
|
|
sdrv_codec_status_t status = SDRV_CODEC_STATUS_SUCCESS;
|
|
uint32_t codec_type = codec->config.codec_type;
|
|
|
|
switch (codec_type) {
|
|
#if CONFIG_CODEC_AK4619
|
|
case SDRV_CODEC_AK4619:
|
|
status = sdrv_codec_ak4619_set_mute(codec, mute, type);
|
|
break;
|
|
#endif
|
|
#if CONFIG_CODEC_TLV320
|
|
case SDRV_CODEC_TLV320:
|
|
status = sdrv_codec_tlv320_set_mute(codec, mute, type);
|
|
break;
|
|
#endif
|
|
#if CONFIG_CODEC_TAS2505
|
|
case SDRV_CODEC_TAS2505:
|
|
status = sdrv_codec_tas2505_set_mute(codec, mute, type);
|
|
break;
|
|
#endif
|
|
|
|
default:
|
|
status = SDRV_CODEC_STATUS_INVALID_PARAMS;
|
|
break;
|
|
}
|
|
|
|
return status;
|
|
}
|