1 /* 2 * Copyright 2021 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef _FSL_PCM186X_H_ 8 #define _FSL_PCM186X_H_ 9 10 #include "fsl_codec_i2c.h" 11 #include "fsl_common.h" 12 13 /*! 14 * @addtogroup pcm186X 15 * @ingroup codec 16 * @{ 17 */ 18 19 /******************************************************************************* 20 * Definitions 21 ******************************************************************************/ 22 /*! @name Driver version */ 23 /*@{*/ 24 /*! @brief CLOCK driver version 2.2.0 */ 25 #define FSL_PCM186X_DRIVER_VERSION (MAKE_VERSION(0, 1, 0)) 26 /*@}*/ 27 28 /*! @brief PCM186X handle size */ 29 #ifndef PCM186X_I2C_HANDLER_SIZE 30 #define PCM186X_I2C_HANDLER_SIZE CODEC_I2C_MASTER_HANDLER_SIZE 31 #endif 32 33 /*! @brief Define the register addresses of PCM186X. */ 34 #define PCM186X_REG_00 ( 0) 35 #define PCM186X_PCM_CFG ( 11) 36 #define PCM186X_TDM_TX_OFFSET ( 13) 37 #define PCM186X_GPIO1_0_CTRL ( 16) 38 #define PCM186X_GPIO3_2_CTRL ( 17) 39 #define PCM186X_GPIO1_0_DIR_CTRL ( 18) 40 #define PCM186X_GPIO3_2_DIR_CTRL ( 19) 41 #define PCM186X_GPIO_IN_OUT ( 20) 42 #define PCM186X_CLK_CTRL ( 32) 43 #define PCM186X_POWER_CTRL (112) 44 45 /*! @brief PCM186X_PAGE */ 46 #define PCM186X_RESET (0xfe) 47 48 /*! @brief Page 0, Register 11 */ 49 #define PCM186X_RX_WLEN (3 << 6) 50 #define PCM186X_TX_WLEN (3 << 2) 51 #define PCM186X_FMT (3 << 0) 52 #define PCM186X_WLEN_16 (3) 53 #define PCM186X_WLEN_24 (1) 54 #define PCM186X_WLEN_32 (0) 55 #define PCM186X_FMT_I2S (0) 56 57 /*! @brief Page 0, Register 16 */ 58 #define PCM186X_GPIO0_FUNC (7 << 0) 59 #define PCM186X_GPIO1_FUNC (7 << 4) 60 61 /*! @brief Page 0, Register 17 */ 62 #define PCM186X_GPIO2_FUNC (7 << 0) 63 #define PCM186X_GPIO3_FUNC (7 << 4) 64 65 /*! @brief Page 0, Register 18 */ 66 #define PCM186X_GPIO0_DIR (7 << 0) 67 #define PCM186X_GPIO1_DIR (7 << 4) 68 69 /*! @brief Page 0, Register 19 */ 70 #define PCM186X_GPIO2_DIR (7 << 0) 71 #define PCM186X_GPIO3_DIR (7 << 4) 72 73 /*! @brief Page 0, Register 32 */ 74 #define PCM186X_SCK_XI_SEL1 (1 << 7) 75 #define PCM186X_SCK_XI_SEL0 (1 << 6) 76 #define PCM186X_SCK_SRC_PLL (1 << 5) 77 #define PCM186X_MST_MODE (1 << 4) 78 #define PCM186X_ADC_SRC_PLL (1 << 3) 79 #define PCM186X_DSP2_SRC_PLL (1 << 2) 80 #define PCM186X_DSP1_SRC_PLL (1 << 1) 81 #define PCM186X_CLKDET_EN (1 << 0) 82 83 /*! @brief Page 0, Register 112 */ 84 #define PCM186X_PWRDN (1 << 2) 85 86 /*! @brief PCM186x I2C baudrate */ 87 #define PCM186X_I2C_BAUDRATE (100000U) 88 89 /*! @brief audio bit width 90 * @anchor _pcm186x_audio_bit_width 91 */ 92 enum 93 { 94 kPCM186x_AudioBitWidth16bit = 16U, /*!< audio bit width 16 */ 95 kPCM186x_AudioBitWidth20bit = 20U, /*!< audio bit width 20 */ 96 kPCM186x_AudioBitWidth24bit = 24U, /*!< audio bit width 24 */ 97 kPCM186x_AudioBitWidth32bit = 32U, /*!< audio bit width 32 */ 98 }; 99 100 /*! @brief PCM186x audio format */ 101 typedef struct _pcm186x_audio_format 102 { 103 uint32_t mclk_HZ; /*!< master clock frequency */ 104 uint32_t sampleRate; /*!< sample rate */ 105 uint32_t bitWidth; /*!< bit width */ 106 } pcm186x_audio_format_t; 107 108 /*! @brief Initialize structure of PCM186x */ 109 typedef struct pcm186x_config 110 { 111 pcm186x_audio_format_t format; /*!< Audio format */ 112 bool master_slave; /*!< Master or slave. */ 113 uint8_t slaveAddress; /*!< PCM186x device address */ 114 codec_i2c_config_t i2cConfig; /*!< i2c configuration */ 115 uint8_t gpio_led; /*!< led gpio number */ 116 } pcm186x_config_t; 117 118 /*! @brief PCM186x codec handler 119 */ 120 typedef struct _pcm186x_handle 121 { 122 const pcm186x_config_t *config; /*!< PCM186x config pointer */ 123 uint8_t i2cHandle[PCM186X_I2C_HANDLER_SIZE]; /*!< i2c handle */ 124 } pcm186x_handle_t; 125 126 /******************************************************************************* 127 * API 128 ******************************************************************************/ 129 #if defined(__cplusplus) 130 extern "C" { 131 #endif 132 133 /*! 134 * @brief PCM186x initialise function. 135 * 136 * @param handle PCM186x handle structure. 137 * @param config PCM186x configuration structure. 138 */ 139 status_t PCM186x_Init(pcm186x_handle_t *handle, const pcm186x_config_t *config); 140 141 /*! 142 * @brief Deinit the PCM186x codec. 143 * 144 * This function close all modules in PCM186x to save power. 145 * 146 * @param handle PCM186x handle structure pointer. 147 */ 148 status_t PCM186x_Deinit(pcm186x_handle_t *handle); 149 150 /*! 151 * @brief Configure the data format of audio data. 152 * 153 * This function would configure the registers about the sample rate, bit depths. 154 * 155 * @param handle PCM186x handle structure pointer. 156 * @param sysclk system clock of the codec which can be generated by MCLK or PLL output. 157 * @param sample_rate Sample rate of audio file running in PCM186x. 158 * @param bits Bit depth of audio file. 159 */ 160 status_t PCM186x_SetFormat(pcm186x_handle_t *handle, uint32_t sysclk, uint32_t sample_rate, uint32_t bits); 161 162 /*! 163 * @brief Write register to PCM186x using I2C. 164 * 165 * @param handle PCM186x handle structure. 166 * @param reg The register address in PCM186x. 167 * @param val Value needs to write into the register. 168 */ 169 status_t PCM186x_WriteReg(pcm186x_handle_t *handle, uint8_t reg, uint8_t val); 170 171 /*! 172 * @brief Read register from PCM186x using I2C. 173 * @param handle PCM186x handle structure. 174 * @param reg The register address in PCM186x. 175 * @param val Value written to. 176 */ 177 status_t PCM186x_ReadReg(pcm186x_handle_t *handle, uint8_t reg, uint8_t *val); 178 179 /*! 180 * @brief Modify some bits in the register using I2C. 181 * @param handle PCM186x handle structure. 182 * @param reg The register address in PCM186x. 183 * @param mask The mask code for the bits want to write. The bit you want to write should be 0. 184 * @param val Value needs to write into the register. 185 */ 186 status_t PCM186x_ModifyReg(pcm186x_handle_t *handle, uint8_t reg, uint8_t mask, uint8_t val); 187 188 #if defined(__cplusplus) 189 } 190 #endif 191 192 /*! @} */ 193 194 #endif /* _FSL_PCM186X_H_ */ 195 196 /******************************************************************************* 197 * API 198 ******************************************************************************/ 199