1 /* 2 * Copyright 2021 NXP 3 * All rights reserved. 4 * 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef _FSL_CODEC_ADAPTER_H_ 10 #define _FSL_CODEC_ADAPTER_H_ 11 12 #include "fsl_pcm512x.h" 13 14 /*! 15 * @addtogroup pcm512x_adapter 16 * @{ 17 */ 18 /******************************************************************************* 19 * Definitions 20 ******************************************************************************/ 21 /*!@brief codec handler size */ 22 #define HAL_CODEC_HANDLER_SIZE (4) 23 /*! @brief codec type */ 24 enum _codec_type 25 { 26 kCODEC_PCM512X, /*!< pcm512x */ 27 }; 28 /******************************************************************************* 29 * API 30 ******************************************************************************/ 31 32 #if defined(__cplusplus) 33 extern "C" { 34 #endif 35 /*! 36 * @brief Codec initilization. 37 * 38 * @param handle codec handle. 39 * @param config codec configuration. 40 * @return kStatus_Success is success, else initial failed. 41 */ 42 status_t HAL_CODEC_Init(void *handle, void *config); 43 44 /*! 45 * @brief Codec de-initilization. 46 * 47 * @param handle codec handle. 48 * @return kStatus_Success is success, else de-initial failed. 49 */ 50 status_t HAL_CODEC_Deinit(void *handle); 51 52 /*! 53 * @brief set audio data format. 54 * 55 * @param handle codec handle. 56 * @param mclk master clock frequency in HZ. 57 * @param sampleRate sample rate in HZ. 58 * @param bitWidth bit width. 59 * @return kStatus_Success is success, else configure failed. 60 */ 61 status_t HAL_CODEC_SetFormat(void *handle, uint32_t mclk, uint32_t sampleRate, uint32_t bitWidth); 62 63 /*! 64 * @brief set audio codec module volume. 65 * 66 * @param handle codec handle. 67 * @param playChannel audio codec play channel, can be a value or combine value of _codec_play_channel. 68 * @param volume volume value, support 0 ~ 100, 0 is mute, 100 is the maximum volume value. 69 * @return kStatus_Success is success, else configure failed. 70 */ 71 status_t HAL_CODEC_SetVolume(void *handle, uint32_t playChannel, uint32_t volume); 72 73 /*! 74 * @brief set audio codec module mute. 75 * 76 * @param handle codec handle. 77 * @param playChannel audio codec play channel, can be a value or combine value of _codec_play_channel. 78 * @param isMute true is mute, false is unmute. 79 * @return kStatus_Success is success, else configure failed. 80 */ 81 status_t HAL_CODEC_SetMute(void *handle, uint32_t playChannel, bool isMute); 82 83 /*! 84 * @brief set audio codec module power. 85 * 86 * @param handle codec handle. 87 * @param module audio codec module. 88 * @param powerOn true is power on, false is power down. 89 * @return kStatus_Success is success, else configure failed. 90 */ 91 status_t HAL_CODEC_SetPower(void *handle, uint32_t module, bool powerOn); 92 93 /*! 94 * @brief codec set record source. 95 * 96 * @param handle codec handle. 97 * @param recordSource audio codec record source, can be a value or combine value of _codec_record_source. 98 * 99 * @return kStatus_Success is success, else configure failed. 100 */ 101 status_t HAL_CODEC_SetRecord(void *handle, uint32_t recordSource); 102 103 /*! 104 * @brief codec set record channel. 105 * 106 * @param handle codec handle. 107 * @param leftRecordChannel audio codec record channel, reference _codec_record_channel, can be a value or combine value 108 of member in _codec_record_channel. 109 * @param rightRecordChannel audio codec record channel, reference _codec_record_channel, can be a value combine of 110 member in _codec_record_channel. 111 112 * @return kStatus_Success is success, else configure failed. 113 */ 114 status_t HAL_CODEC_SetRecordChannel(void *handle, uint32_t leftRecordChannel, uint32_t rightRecordChannel); 115 116 /*! 117 * @brief codec set play source. 118 * 119 * @param handle codec handle. 120 * @param playSource audio codec play source, can be a value or combine value of _codec_play_source. 121 * 122 * @return kStatus_Success is success, else configure failed. 123 */ 124 status_t HAL_CODEC_SetPlay(void *handle, uint32_t playSource); 125 126 /*! 127 * @brief codec module control. 128 * 129 * This function is used for codec module control, support switch digital interface cmd, can be expand to support codec 130 * module specific feature 131 * 132 * @param handle codec handle. 133 * @param cmd module control cmd, reference _codec_module_ctrl_cmd. 134 * @param data value to write, when cmd is kCODEC_ModuleRecordSourceChannel, the data should be a value combine 135 * of channel and source, please reference macro CODEC_MODULE_RECORD_SOURCE_CHANNEL(source, LP, LN, RP, RN), reference 136 * codec specific driver for detail configurations. 137 * @return kStatus_Success is success, else configure failed. 138 */ 139 status_t HAL_CODEC_ModuleControl(void *handle, uint32_t cmd, uint32_t data); 140 141 #if defined(__cplusplus) 142 } 143 #endif 144 /*! @} */ 145 146 #endif /* _FSL_CODEC_ADAPTER_H_ */ 147