210 lines
5.7 KiB
C
210 lines
5.7 KiB
C
/**
|
|
* @file sdrv_codec.h
|
|
* @brief E3 Codec driver
|
|
*
|
|
* @copyright Copyright (c) 2021 Semidrive Semiconductor.
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#ifndef _SDRV_CODEC_H_
|
|
#define _SDRV_CODEC_H_
|
|
|
|
#include <debug.h>
|
|
#include <types.h>
|
|
|
|
#include "sdrv_i2s.h"
|
|
|
|
/**
|
|
* @brief codec playback capture type.
|
|
*
|
|
*/
|
|
typedef enum {
|
|
SDRV_CODEC_STREAM_PLAYBACK = 0,
|
|
SDRV_CODEC_STREAM_CAPTURE,
|
|
} sdrv_codec_stream_type_t;
|
|
|
|
/**
|
|
* @brief codec trigger cmd ,start or stop
|
|
*
|
|
*/
|
|
typedef enum sdrv_codec_trigger_op {
|
|
SDRV_CODEC_TRIGGER_START,
|
|
SDRV_CODEC_TRIGGER_STOP,
|
|
} sdrv_codec_trigger_op_t;
|
|
|
|
typedef enum sdrv_codec_status {
|
|
/**< status for Success. */
|
|
SDRV_CODEC_STATUS_SUCCESS = 0,
|
|
/**< status for Fail. */
|
|
SDRV_CODEC_STATUS_FAIL = 1,
|
|
/**< status for invalid argument check. */
|
|
SDRV_CODEC_STATUS_INVALID_PARAMS = 2,
|
|
} sdrv_codec_status_t;
|
|
|
|
/**
|
|
* @brief codec control interface
|
|
*
|
|
*/
|
|
typedef enum {
|
|
/**< i2c interface. */
|
|
PROTOCOL_TYPE_I2C = 0,
|
|
/**< spi interface. */
|
|
PROTOCOL_TYPE_SPI,
|
|
} codec_protocol_type_t;
|
|
|
|
/**
|
|
* @brief struct reg_default - Default value for a register.
|
|
*
|
|
* We use an array of structs rather than a simple array as many modern devices
|
|
* have very sparse register maps.
|
|
*/
|
|
struct reg_default {
|
|
unsigned int reg; /**< Register address. */
|
|
unsigned int val; /**< Register default value. */
|
|
};
|
|
|
|
/**
|
|
* @brief sdrv codec configure
|
|
*
|
|
* Configure codec type and control interface,codec device specific
|
|
* configuration.
|
|
*
|
|
*/
|
|
typedef struct sdrv_codec_cfg {
|
|
/*!< codec type. */
|
|
uint32_t codec_type;
|
|
/*!< codec protocol type : i2c spi. */
|
|
codec_protocol_type_t protocol;
|
|
/*!< codec device specific configuration , it is defined by specific codec
|
|
* device. */
|
|
void *codec_config;
|
|
} sdrv_codec_cfg_t;
|
|
|
|
/**
|
|
* @brief codec configurations params.
|
|
*
|
|
*/
|
|
typedef struct sdrv_codec_params {
|
|
/*!< codec sample format. */
|
|
uint32_t fmt;
|
|
/*!< codec sample channels. */
|
|
sdrv_i2s_channel_t channels;
|
|
/*!< codec sample width. */
|
|
sdrv_i2s_sample_width_t sample_width;
|
|
/*!< codec sample rate. */
|
|
sdrv_i2s_sample_rate_t sample_rate;
|
|
/*!< codec volume level ,min 0 max 100. */
|
|
uint8_t volume;
|
|
/*!< codec mute state, true : status for mute, false : status for unmute. */
|
|
uint8_t mute;
|
|
/*!< codec slot num, only working in TDM mode requires configuration. */
|
|
sdrv_i2s_channel_t slots;
|
|
/*!< codec slot data width , only working in TDM mode requires
|
|
* configuration.*/
|
|
sdrv_i2s_slot_width_t slot_width;
|
|
/*!< tdm mode must set :codec slot mask ,1 :slot enable; 0:slot disable
|
|
* only working in TDM mode requires configuration. */
|
|
unsigned int tx_slot_mask;
|
|
/*!< tdm mode must set :codec slot mask ,1 :slot enable; 0:slot disable
|
|
* only working in TDM mode requires configuration. */
|
|
unsigned int rx_slot_mask;
|
|
} sdrv_codec_params_t;
|
|
|
|
/**
|
|
* @brief codec playback or capture descriptions.
|
|
*
|
|
*/
|
|
typedef struct sdrv_codec_stream {
|
|
/*!< codec configurations params. */
|
|
sdrv_codec_params_t params;
|
|
/*!< status for stream, true status for active,false : status for idle. */
|
|
bool active;
|
|
/*!< codec mute state, true : status for mute, false : status for unmute. */
|
|
bool mute;
|
|
/*!< volume value, support 0 ~ 100, 0 is mute, 100 is the maximum. */
|
|
uint8_t volume;
|
|
} sdrv_codec_stream_t;
|
|
|
|
/**
|
|
* @brief sdrv codec device.
|
|
*
|
|
*/
|
|
typedef struct sdrv_codec {
|
|
/*!< codec playback or capture stream. */
|
|
sdrv_codec_stream_t streams[2];
|
|
/*!< codec board config, type i2c or spi control interface and codec device
|
|
* specific configuration which is defined by specific codec device. */
|
|
sdrv_codec_cfg_t config;
|
|
} sdrv_codec_t;
|
|
|
|
/**
|
|
* @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_init(sdrv_codec_t *codec, sdrv_codec_cfg_t *cfg);
|
|
|
|
/**
|
|
* @brief brief set audio codec module params.
|
|
*
|
|
* This fuction 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_set_params(sdrv_codec_t *codec,
|
|
sdrv_codec_params_t *params,
|
|
sdrv_codec_stream_type_t type);
|
|
|
|
/**
|
|
* @brief brief start or stop audio codec module
|
|
*
|
|
* This fuction 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_trigger(sdrv_codec_t *codec,
|
|
sdrv_codec_trigger_op_t cmd,
|
|
sdrv_codec_stream_type_t type);
|
|
|
|
/*!
|
|
* @brief set audio codec volume.
|
|
*
|
|
* @param codec sdrv codec device
|
|
* @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_set_volume(sdrv_codec_t *codec, uint8_t volume,
|
|
sdrv_codec_stream_type_t type);
|
|
|
|
/**
|
|
* @brief set audio codec mute.
|
|
*
|
|
* @param codec sdrv codec device
|
|
* @param mute true is mute, false is unmute
|
|
* @param type playback or capture type
|
|
* @return sdrv_codec_status_t
|
|
*/
|
|
sdrv_codec_status_t sdrv_codec_set_mute(sdrv_codec_t *codec, bool mute,
|
|
sdrv_codec_stream_type_t type);
|
|
|
|
#endif /* _SDRV_CODEC_H_ */
|