1 /** 2 * @file i2s.h 3 * @brief I2S (Inter-Integrated Sound) driver function prototypes and data types. 4 */ 5 6 /****************************************************************************** 7 * 8 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by 9 * Analog Devices, Inc.), 10 * Copyright (C) 2023-2024 Analog Devices, Inc. 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 * 24 ******************************************************************************/ 25 26 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_I2S_H_ 27 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_I2S_H_ 28 29 /* **** Includes **** */ 30 #include "mxc_sys.h" 31 #include "dma.h" 32 #include "spimss_regs.h" 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 /** 39 * @defgroup spimss SPIMSS 40 * @ingroup periphlibs 41 * @{ 42 */ 43 44 /* **** Definitions **** */ 45 46 typedef enum { 47 LEFT_JUSTIFIED = 0, 48 RIGHT_JUSTIFIED = 1, 49 } mxc_i2s_justify_t; 50 51 typedef enum { 52 STEREO_MODE = 0, 53 MONO_MODE = 1, 54 } mxc_i2s_audio_mode_t; 55 56 /** @brief I2S audio directions */ 57 typedef enum { 58 AUDIO_OUT = 1, 59 AUDIO_IN = 2, 60 } mxc_i2s_direction_t; 61 62 /** @brief I2S Configuration Struct */ 63 typedef struct { 64 mxc_i2s_justify_t justify; 65 mxc_i2s_audio_mode_t audio_mode; 66 mxc_i2s_direction_t audio_direction; 67 uint16_t sample_rate; 68 unsigned int start_immediately; 69 unsigned int dma_reload_en; 70 void *src_addr; 71 void *dst_addr; 72 uint32_t length; 73 } mxc_i2s_config_t; 74 75 /* **** Function Prototypes **** */ 76 77 /** 78 * @brief Initialize I2S resources 79 * 80 * @param cfg I2S Configuration Struct 81 * @param dma_ctz_cb Optional function to be called when the DMA completes 82 * a transfer. Set to NULL if unused. 83 * 84 * @details This initialization is required before using the I2S driver 85 * functions. 86 * @return #E_NO_ERROR if successful 87 */ 88 int MXC_I2S_Init(const mxc_i2s_config_t *cfg, void (*dma_ctz_cb)(int, int)); 89 90 /** 91 * @brief Release I2S 92 * @details Deconfigures the I2S protocol and stops DMA request 93 * @return #E_BAD_PARAM if DMA cannot be stopped, #E_NO_ERROR otherwise 94 */ 95 int MXC_I2S_Shutdown(void); 96 97 /** 98 * @brief Mute I2S Output 99 * @details Sets I2S data to zero, continues sending clock and accessing DMA 100 * @return #E_NO_ERROR 101 */ 102 int MXC_I2S_Mute(void); 103 104 /** 105 * @brief Unmute I2S Output 106 * @details Restores I2S data 107 * @return #E_NO_ERROR 108 */ 109 int MXC_I2S_Unmute(void); 110 111 /** 112 * @brief Pause I2S Output 113 * @details Similar to mute, but stops FIFO and DMA access, clocks continue 114 * @return #E_NO_ERROR 115 */ 116 int MXC_I2S_Pause(void); 117 118 /** 119 * @brief Unpause I2S Output 120 * @details Similar to mute, but restarts FIFO and DMA access 121 * @return #E_NO_ERROR 122 */ 123 int MXC_I2S_Unpause(void); 124 125 /** 126 * @brief Stops I2S Output 127 * @details Similar to pause, but also halts clock 128 * @return #E_NO_ERROR 129 */ 130 int MXC_I2S_Stop(void); 131 132 /** 133 * @brief Starts I2S Output 134 * @details Starts I2S Output, automatically called by configure if requested 135 * @return #E_NO_ERROR 136 */ 137 int MXC_I2S_Start(void); 138 139 /** 140 * @brief Clears DMA Interrupt Flags 141 * @details Clears the DMA Interrupt flags, should be called at the end of a dma_ctz_cb 142 * @return #E_NO_ERROR 143 */ 144 int MXC_I2S_DMA_ClearFlags(void); 145 146 /** 147 * @brief Set DMA Addr (Source or Dest) and bytes to transfer 148 * @param src_addr The address to read data from (Audio Out) 149 * @param dst_addr The address to write data to (Audio In) 150 * @param count The length of the transfer in bytes 151 * @details Sets the address to read/write data in memory and the length of 152 * the transfer. The unused addr parameter is ignored. 153 * @return #E_NO_ERROR 154 */ 155 int MXC_I2S_DMA_SetAddrCnt(void *src_addr, void *dst_addr, unsigned int count); 156 157 /** 158 * @brief Sets the DMA reload address and count 159 * @param src_addr The address to read data from (Audio Out) 160 * @param dst_addr The address to write data to (Audio In) 161 * @param count The length of the transfer in bytes 162 * @details If DMA reload is enabled, when the DMA has transfered $count bytes 163 * (a CTZ event occurs) the src, dst, and count registers will be 164 * set to these. The DMA reload flag clears after a reload occurs. 165 * @return #E_NO_ERROR 166 */ 167 int MXC_I2S_DMA_SetReload(void *src_addr, void *dst_addr, unsigned int count); 168 169 #ifdef __cplusplus 170 } 171 #endif 172 173 /**@} end of group i2s */ 174 175 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_I2S_H_ 176