The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_LPC54114/TOOLCHAIN_ARM_STD/fsl_i2s.h@172:65be27845400, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 20:53:29 2019 +0000
- Revision:
- 172:65be27845400
- Parent:
- 171:3a7713b1edbc
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 148:fd96258d940d | 1 | /* |
Kojto | 148:fd96258d940d | 2 | * Copyright (c) 2016, Freescale Semiconductor, Inc. |
Kojto | 148:fd96258d940d | 3 | * |
Kojto | 148:fd96258d940d | 4 | * Redistribution and use in source and binary forms, with or without modification, |
Kojto | 148:fd96258d940d | 5 | * are permitted provided that the following conditions are met: |
Kojto | 148:fd96258d940d | 6 | * |
Kojto | 148:fd96258d940d | 7 | * o Redistributions of source code must retain the above copyright notice, this list |
Kojto | 148:fd96258d940d | 8 | * of conditions and the following disclaimer. |
Kojto | 148:fd96258d940d | 9 | * |
Kojto | 148:fd96258d940d | 10 | * o Redistributions in binary form must reproduce the above copyright notice, this |
Kojto | 148:fd96258d940d | 11 | * list of conditions and the following disclaimer in the documentation and/or |
Kojto | 148:fd96258d940d | 12 | * other materials provided with the distribution. |
Kojto | 148:fd96258d940d | 13 | * |
Kojto | 148:fd96258d940d | 14 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its |
Kojto | 148:fd96258d940d | 15 | * contributors may be used to endorse or promote products derived from this |
Kojto | 148:fd96258d940d | 16 | * software without specific prior written permission. |
Kojto | 148:fd96258d940d | 17 | * |
Kojto | 148:fd96258d940d | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
Kojto | 148:fd96258d940d | 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Kojto | 148:fd96258d940d | 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Kojto | 148:fd96258d940d | 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
Kojto | 148:fd96258d940d | 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Kojto | 148:fd96258d940d | 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Kojto | 148:fd96258d940d | 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
Kojto | 148:fd96258d940d | 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Kojto | 148:fd96258d940d | 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Kojto | 148:fd96258d940d | 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Kojto | 148:fd96258d940d | 28 | */ |
Kojto | 148:fd96258d940d | 29 | #ifndef _FSL_I2S_H_ |
Kojto | 148:fd96258d940d | 30 | #define _FSL_I2S_H_ |
Kojto | 148:fd96258d940d | 31 | |
Kojto | 148:fd96258d940d | 32 | #include "fsl_device_registers.h" |
Kojto | 148:fd96258d940d | 33 | #include "fsl_common.h" |
Kojto | 148:fd96258d940d | 34 | #include "fsl_flexcomm.h" |
Kojto | 148:fd96258d940d | 35 | |
Kojto | 148:fd96258d940d | 36 | /******************************************************************************* |
Kojto | 148:fd96258d940d | 37 | * Definitions |
Kojto | 148:fd96258d940d | 38 | ******************************************************************************/ |
Kojto | 148:fd96258d940d | 39 | |
Kojto | 148:fd96258d940d | 40 | /*! |
Kojto | 148:fd96258d940d | 41 | * @addtogroup i2s_driver |
Kojto | 148:fd96258d940d | 42 | * @{ |
Kojto | 148:fd96258d940d | 43 | */ |
Kojto | 148:fd96258d940d | 44 | |
Kojto | 148:fd96258d940d | 45 | /*! @file */ |
Kojto | 148:fd96258d940d | 46 | |
Kojto | 148:fd96258d940d | 47 | /*! @name Driver version */ |
Kojto | 148:fd96258d940d | 48 | /*@{*/ |
Kojto | 148:fd96258d940d | 49 | /*! @brief I2S driver version 2.0.0. |
Kojto | 148:fd96258d940d | 50 | * |
Kojto | 148:fd96258d940d | 51 | * Current version: 2.0.0 |
Kojto | 148:fd96258d940d | 52 | * |
Kojto | 148:fd96258d940d | 53 | * Change log: |
Kojto | 148:fd96258d940d | 54 | * - Version 2.0.0 |
Kojto | 148:fd96258d940d | 55 | * - initial version |
Kojto | 148:fd96258d940d | 56 | */ |
Kojto | 148:fd96258d940d | 57 | #define FSL_I2S_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) |
Kojto | 148:fd96258d940d | 58 | /*@}*/ |
Kojto | 148:fd96258d940d | 59 | |
Kojto | 148:fd96258d940d | 60 | #ifndef I2S_NUM_BUFFERS |
Kojto | 148:fd96258d940d | 61 | |
Kojto | 148:fd96258d940d | 62 | /*! @brief Number of buffers . */ |
Kojto | 148:fd96258d940d | 63 | #define I2S_NUM_BUFFERS (4) |
Kojto | 148:fd96258d940d | 64 | |
Kojto | 148:fd96258d940d | 65 | #endif |
Kojto | 148:fd96258d940d | 66 | |
Kojto | 148:fd96258d940d | 67 | /*! @brief I2S status codes. */ |
Kojto | 148:fd96258d940d | 68 | enum _i2s_status |
Kojto | 148:fd96258d940d | 69 | { |
Kojto | 148:fd96258d940d | 70 | kStatus_I2S_BufferComplete = |
Kojto | 148:fd96258d940d | 71 | MAKE_STATUS(kStatusGroup_I2S, 0), /*!< Transfer from/into a single buffer has completed */ |
Kojto | 148:fd96258d940d | 72 | kStatus_I2S_Done = MAKE_STATUS(kStatusGroup_I2S, 1), /*!< All buffers transfers have completed */ |
Kojto | 148:fd96258d940d | 73 | kStatus_I2S_Busy = |
Kojto | 148:fd96258d940d | 74 | MAKE_STATUS(kStatusGroup_I2S, 2), /*!< Already performing a transfer and cannot queue another buffer */ |
Kojto | 148:fd96258d940d | 75 | }; |
Kojto | 148:fd96258d940d | 76 | |
Kojto | 148:fd96258d940d | 77 | /*! |
Kojto | 148:fd96258d940d | 78 | * @brief I2S flags. |
Kojto | 148:fd96258d940d | 79 | * |
Kojto | 148:fd96258d940d | 80 | * @note These enums are meant to be OR'd together to form a bit mask. |
Kojto | 148:fd96258d940d | 81 | */ |
Kojto | 148:fd96258d940d | 82 | typedef enum _i2s_flags |
Kojto | 148:fd96258d940d | 83 | { |
Kojto | 148:fd96258d940d | 84 | kI2S_TxErrorFlag = I2S_FIFOINTENSET_TXERR_MASK, /*!< TX error interrupt */ |
Kojto | 148:fd96258d940d | 85 | kI2S_TxLevelFlag = I2S_FIFOINTENSET_TXLVL_MASK, /*!< TX level interrupt */ |
Kojto | 148:fd96258d940d | 86 | kI2S_RxErrorFlag = I2S_FIFOINTENSET_RXERR_MASK, /*!< RX error interrupt */ |
Kojto | 148:fd96258d940d | 87 | kI2S_RxLevelFlag = I2S_FIFOINTENSET_RXLVL_MASK /*!< RX level interrupt */ |
Kojto | 148:fd96258d940d | 88 | } i2s_flags_t; |
Kojto | 148:fd96258d940d | 89 | |
Kojto | 148:fd96258d940d | 90 | /*! @brief Master / slave mode. */ |
Kojto | 148:fd96258d940d | 91 | typedef enum _i2s_master_slave |
Kojto | 148:fd96258d940d | 92 | { |
Kojto | 148:fd96258d940d | 93 | kI2S_MasterSlaveNormalSlave = 0x0, /*!< Normal slave */ |
Kojto | 148:fd96258d940d | 94 | kI2S_MasterSlaveWsSyncMaster = 0x1, /*!< WS synchronized master */ |
Kojto | 148:fd96258d940d | 95 | kI2S_MasterSlaveExtSckMaster = 0x2, /*!< Master using existing SCK */ |
Kojto | 148:fd96258d940d | 96 | kI2S_MasterSlaveNormalMaster = 0x3 /*!< Normal master */ |
Kojto | 148:fd96258d940d | 97 | } i2s_master_slave_t; |
Kojto | 148:fd96258d940d | 98 | |
Kojto | 148:fd96258d940d | 99 | /*! @brief I2S mode. */ |
Kojto | 148:fd96258d940d | 100 | typedef enum _i2s_mode |
Kojto | 148:fd96258d940d | 101 | { |
Kojto | 148:fd96258d940d | 102 | kI2S_ModeI2sClassic = 0x0, /*!< I2S classic mode */ |
Kojto | 148:fd96258d940d | 103 | kI2S_ModeDspWs50 = 0x1, /*!< DSP mode, WS having 50% duty cycle */ |
Kojto | 148:fd96258d940d | 104 | kI2S_ModeDspWsShort = 0x2, /*!< DSP mode, WS having one clock long pulse */ |
Kojto | 148:fd96258d940d | 105 | kI2S_ModeDspWsLong = 0x3 /*!< DSP mode, WS having one data slot long pulse */ |
Kojto | 148:fd96258d940d | 106 | } i2s_mode_t; |
Kojto | 148:fd96258d940d | 107 | |
Kojto | 148:fd96258d940d | 108 | /*! @brief I2S configuration structure. */ |
Kojto | 148:fd96258d940d | 109 | typedef struct _i2s_config |
Kojto | 148:fd96258d940d | 110 | { |
Kojto | 148:fd96258d940d | 111 | i2s_master_slave_t masterSlave; /*!< Master / slave configuration */ |
Kojto | 148:fd96258d940d | 112 | i2s_mode_t mode; /*!< I2S mode */ |
Kojto | 148:fd96258d940d | 113 | bool rightLow; /*!< Right channel data in low portion of FIFO */ |
Kojto | 148:fd96258d940d | 114 | bool leftJust; /*!< Left justify data in FIFO */ |
Kojto | 148:fd96258d940d | 115 | bool pdmData; /*!< Data source is the D-Mic subsystem */ |
Kojto | 148:fd96258d940d | 116 | bool sckPol; /*!< SCK polarity */ |
Kojto | 148:fd96258d940d | 117 | bool wsPol; /*!< WS polarity */ |
Kojto | 148:fd96258d940d | 118 | uint16_t divider; /*!< Flexcomm function clock divider (1 - 4096) */ |
Kojto | 148:fd96258d940d | 119 | bool oneChannel; /*!< true mono, false stereo */ |
Kojto | 148:fd96258d940d | 120 | uint8_t dataLength; /*!< Data length (4 - 32) */ |
Kojto | 148:fd96258d940d | 121 | uint16_t frameLength; /*!< Frame width (4 - 512) */ |
Kojto | 148:fd96258d940d | 122 | uint16_t position; /*!< Data position in the frame */ |
Kojto | 148:fd96258d940d | 123 | uint8_t watermark; /*!< FIFO trigger level */ |
Kojto | 148:fd96258d940d | 124 | bool txEmptyZero; /*!< Transmit zero when buffer becomes empty or last item */ |
Kojto | 148:fd96258d940d | 125 | bool pack48; /*!< Packing format for 48-bit data (false - 24 bit values, true - alternating 32-bit and 16-bit |
Kojto | 148:fd96258d940d | 126 | values) */ |
Kojto | 148:fd96258d940d | 127 | } i2s_config_t; |
Kojto | 148:fd96258d940d | 128 | |
Kojto | 148:fd96258d940d | 129 | /*! @brief Buffer to transfer from or receive audio data into. */ |
Kojto | 148:fd96258d940d | 130 | typedef struct _i2s_transfer |
Kojto | 148:fd96258d940d | 131 | { |
Kojto | 148:fd96258d940d | 132 | volatile uint8_t *data; /*!< Pointer to data buffer. */ |
Kojto | 148:fd96258d940d | 133 | volatile size_t dataSize; /*!< Buffer size in bytes. */ |
Kojto | 148:fd96258d940d | 134 | } i2s_transfer_t; |
Kojto | 148:fd96258d940d | 135 | |
Kojto | 148:fd96258d940d | 136 | /*! @brief Transactional state of the intialized transfer or receive I2S operation. */ |
Kojto | 148:fd96258d940d | 137 | typedef struct _i2s_handle i2s_handle_t; |
Kojto | 148:fd96258d940d | 138 | |
Kojto | 148:fd96258d940d | 139 | /*! |
Kojto | 148:fd96258d940d | 140 | * @brief Callback function invoked from transactional API |
Kojto | 148:fd96258d940d | 141 | * on completion of a single buffer transfer. |
Kojto | 148:fd96258d940d | 142 | * |
Kojto | 148:fd96258d940d | 143 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 144 | * @param handle pointer to I2S transaction. |
Kojto | 148:fd96258d940d | 145 | * @param completionStatus status of the transaction. |
Kojto | 148:fd96258d940d | 146 | * @param userData optional pointer to user arguments data. |
Kojto | 148:fd96258d940d | 147 | */ |
Kojto | 148:fd96258d940d | 148 | typedef void (*i2s_transfer_callback_t)(I2S_Type *base, |
Kojto | 148:fd96258d940d | 149 | i2s_handle_t *handle, |
Kojto | 148:fd96258d940d | 150 | status_t completionStatus, |
Kojto | 148:fd96258d940d | 151 | void *userData); |
Kojto | 148:fd96258d940d | 152 | |
Kojto | 148:fd96258d940d | 153 | /*! @brief Members not to be accessed / modified outside of the driver. */ |
Kojto | 148:fd96258d940d | 154 | struct _i2s_handle |
Kojto | 148:fd96258d940d | 155 | { |
Kojto | 148:fd96258d940d | 156 | uint32_t state; /*!< State of transfer */ |
Kojto | 148:fd96258d940d | 157 | i2s_transfer_callback_t completionCallback; /*!< Callback function pointer */ |
Kojto | 148:fd96258d940d | 158 | void *userData; /*!< Application data passed to callback */ |
Kojto | 148:fd96258d940d | 159 | bool oneChannel; /*!< true mono, false stereo */ |
Kojto | 148:fd96258d940d | 160 | uint8_t dataLength; /*!< Data length (4 - 32) */ |
Kojto | 148:fd96258d940d | 161 | bool pack48; /*!< Packing format for 48-bit data (false - 24 bit values, true - alternating 32-bit and 16-bit |
Kojto | 148:fd96258d940d | 162 | values) */ |
Kojto | 148:fd96258d940d | 163 | bool useFifo48H; /*!< When dataLength 17-24: true use FIFOWR48H, false use FIFOWR */ |
Kojto | 148:fd96258d940d | 164 | volatile i2s_transfer_t i2sQueue[I2S_NUM_BUFFERS]; /*!< Transfer queue storing transfer buffers */ |
Kojto | 148:fd96258d940d | 165 | volatile uint8_t queueUser; /*!< Queue index where user's next transfer will be stored */ |
Kojto | 148:fd96258d940d | 166 | volatile uint8_t queueDriver; /*!< Queue index of buffer actually used by the driver */ |
Kojto | 148:fd96258d940d | 167 | volatile uint32_t errorCount; /*!< Number of buffer underruns/overruns */ |
Kojto | 148:fd96258d940d | 168 | volatile uint32_t transferCount; /*!< Number of bytes transferred */ |
Kojto | 148:fd96258d940d | 169 | volatile uint8_t watermark; /*!< FIFO trigger level */ |
Kojto | 148:fd96258d940d | 170 | }; |
Kojto | 148:fd96258d940d | 171 | |
Kojto | 148:fd96258d940d | 172 | /******************************************************************************* |
Kojto | 148:fd96258d940d | 173 | * API |
Kojto | 148:fd96258d940d | 174 | ******************************************************************************/ |
Kojto | 148:fd96258d940d | 175 | |
Kojto | 148:fd96258d940d | 176 | #if defined(__cplusplus) |
Kojto | 148:fd96258d940d | 177 | extern "C" { |
Kojto | 148:fd96258d940d | 178 | #endif |
Kojto | 148:fd96258d940d | 179 | |
Kojto | 148:fd96258d940d | 180 | /*! |
Kojto | 148:fd96258d940d | 181 | * @name Initialization and deinitialization |
Kojto | 148:fd96258d940d | 182 | * @{ |
Kojto | 148:fd96258d940d | 183 | */ |
Kojto | 148:fd96258d940d | 184 | |
Kojto | 148:fd96258d940d | 185 | /*! |
Kojto | 148:fd96258d940d | 186 | * @brief Initializes the FLEXCOMM peripheral for I2S transmit functionality. |
Kojto | 148:fd96258d940d | 187 | * |
Kojto | 148:fd96258d940d | 188 | * Ungates the FLEXCOMM clock and configures the module |
Kojto | 148:fd96258d940d | 189 | * for I2S transmission using a configuration structure. |
Kojto | 148:fd96258d940d | 190 | * The configuration structure can be custom filled or set with default values by |
Kojto | 148:fd96258d940d | 191 | * I2S_TxGetDefaultConfig(). |
Kojto | 148:fd96258d940d | 192 | * |
Kojto | 148:fd96258d940d | 193 | * @note This API should be called at the beginning of the application to use |
Kojto | 148:fd96258d940d | 194 | * the I2S driver. |
Kojto | 148:fd96258d940d | 195 | * |
Kojto | 148:fd96258d940d | 196 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 197 | * @param config pointer to I2S configuration structure. |
Kojto | 148:fd96258d940d | 198 | */ |
Kojto | 148:fd96258d940d | 199 | void I2S_TxInit(I2S_Type *base, const i2s_config_t *config); |
Kojto | 148:fd96258d940d | 200 | |
Kojto | 148:fd96258d940d | 201 | /*! |
Kojto | 148:fd96258d940d | 202 | * @brief Initializes the FLEXCOMM peripheral for I2S receive functionality. |
Kojto | 148:fd96258d940d | 203 | * |
Kojto | 148:fd96258d940d | 204 | * Ungates the FLEXCOMM clock and configures the module |
Kojto | 148:fd96258d940d | 205 | * for I2S receive using a configuration structure. |
Kojto | 148:fd96258d940d | 206 | * The configuration structure can be custom filled or set with default values by |
Kojto | 148:fd96258d940d | 207 | * I2S_RxGetDefaultConfig(). |
Kojto | 148:fd96258d940d | 208 | * |
Kojto | 148:fd96258d940d | 209 | * @note This API should be called at the beginning of the application to use |
Kojto | 148:fd96258d940d | 210 | * the I2S driver. |
Kojto | 148:fd96258d940d | 211 | * |
Kojto | 148:fd96258d940d | 212 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 213 | * @param config pointer to I2S configuration structure. |
Kojto | 148:fd96258d940d | 214 | */ |
Kojto | 148:fd96258d940d | 215 | void I2S_RxInit(I2S_Type *base, const i2s_config_t *config); |
Kojto | 148:fd96258d940d | 216 | |
Kojto | 148:fd96258d940d | 217 | /*! |
Kojto | 148:fd96258d940d | 218 | * @brief Sets the I2S Tx configuration structure to default values. |
Kojto | 148:fd96258d940d | 219 | * |
Kojto | 148:fd96258d940d | 220 | * This API initializes the configuration structure for use in I2S_TxInit(). |
Kojto | 148:fd96258d940d | 221 | * The initialized structure can remain unchanged in I2S_TxInit(), or it can be modified |
Kojto | 148:fd96258d940d | 222 | * before calling I2S_TxInit(). |
Kojto | 148:fd96258d940d | 223 | * Example: |
Kojto | 148:fd96258d940d | 224 | @code |
Kojto | 148:fd96258d940d | 225 | i2s_config_t config; |
Kojto | 148:fd96258d940d | 226 | I2S_TxGetDefaultConfig(&config); |
Kojto | 148:fd96258d940d | 227 | @endcode |
Kojto | 148:fd96258d940d | 228 | * |
Kojto | 148:fd96258d940d | 229 | * Default values: |
Kojto | 148:fd96258d940d | 230 | * @code |
Kojto | 148:fd96258d940d | 231 | * config->masterSlave = kI2S_MasterSlaveNormalMaster; |
Kojto | 148:fd96258d940d | 232 | * config->mode = kI2S_ModeI2sClassic; |
Kojto | 148:fd96258d940d | 233 | * config->rightLow = false; |
Kojto | 148:fd96258d940d | 234 | * config->leftJust = false; |
Kojto | 148:fd96258d940d | 235 | * config->pdmData = false; |
Kojto | 148:fd96258d940d | 236 | * config->sckPol = false; |
Kojto | 148:fd96258d940d | 237 | * config->wsPol = false; |
Kojto | 148:fd96258d940d | 238 | * config->divider = 1; |
Kojto | 148:fd96258d940d | 239 | * config->oneChannel = false; |
Kojto | 148:fd96258d940d | 240 | * config->dataLength = 16; |
Kojto | 148:fd96258d940d | 241 | * config->frameLength = 32; |
Kojto | 148:fd96258d940d | 242 | * config->position = 0; |
Kojto | 148:fd96258d940d | 243 | * config->watermark = 4; |
Kojto | 148:fd96258d940d | 244 | * config->txEmptyZero = true; |
Kojto | 148:fd96258d940d | 245 | * config->pack48 = false; |
Kojto | 148:fd96258d940d | 246 | * @endcode |
Kojto | 148:fd96258d940d | 247 | * |
Kojto | 148:fd96258d940d | 248 | * @param config pointer to I2S configuration structure. |
Kojto | 148:fd96258d940d | 249 | */ |
Kojto | 148:fd96258d940d | 250 | void I2S_TxGetDefaultConfig(i2s_config_t *config); |
Kojto | 148:fd96258d940d | 251 | |
Kojto | 148:fd96258d940d | 252 | /*! |
Kojto | 148:fd96258d940d | 253 | * @brief Sets the I2S Rx configuration structure to default values. |
Kojto | 148:fd96258d940d | 254 | * |
Kojto | 148:fd96258d940d | 255 | * This API initializes the configuration structure for use in I2S_RxInit(). |
Kojto | 148:fd96258d940d | 256 | * The initialized structure can remain unchanged in I2S_RxInit(), or it can be modified |
Kojto | 148:fd96258d940d | 257 | * before calling I2S_RxInit(). |
Kojto | 148:fd96258d940d | 258 | * Example: |
Kojto | 148:fd96258d940d | 259 | @code |
Kojto | 148:fd96258d940d | 260 | i2s_config_t config; |
Kojto | 148:fd96258d940d | 261 | I2S_RxGetDefaultConfig(&config); |
Kojto | 148:fd96258d940d | 262 | @endcode |
Kojto | 148:fd96258d940d | 263 | * |
Kojto | 148:fd96258d940d | 264 | * Default values: |
Kojto | 148:fd96258d940d | 265 | * @code |
Kojto | 148:fd96258d940d | 266 | * config->masterSlave = kI2S_MasterSlaveNormalSlave; |
Kojto | 148:fd96258d940d | 267 | * config->mode = kI2S_ModeI2sClassic; |
Kojto | 148:fd96258d940d | 268 | * config->rightLow = false; |
Kojto | 148:fd96258d940d | 269 | * config->leftJust = false; |
Kojto | 148:fd96258d940d | 270 | * config->pdmData = false; |
Kojto | 148:fd96258d940d | 271 | * config->sckPol = false; |
Kojto | 148:fd96258d940d | 272 | * config->wsPol = false; |
Kojto | 148:fd96258d940d | 273 | * config->divider = 1; |
Kojto | 148:fd96258d940d | 274 | * config->oneChannel = false; |
Kojto | 148:fd96258d940d | 275 | * config->dataLength = 16; |
Kojto | 148:fd96258d940d | 276 | * config->frameLength = 32; |
Kojto | 148:fd96258d940d | 277 | * config->position = 0; |
Kojto | 148:fd96258d940d | 278 | * config->watermark = 4; |
Kojto | 148:fd96258d940d | 279 | * config->txEmptyZero = false; |
Kojto | 148:fd96258d940d | 280 | * config->pack48 = false; |
Kojto | 148:fd96258d940d | 281 | * @endcode |
Kojto | 148:fd96258d940d | 282 | * |
Kojto | 148:fd96258d940d | 283 | * @param config pointer to I2S configuration structure. |
Kojto | 148:fd96258d940d | 284 | */ |
Kojto | 148:fd96258d940d | 285 | void I2S_RxGetDefaultConfig(i2s_config_t *config); |
Kojto | 148:fd96258d940d | 286 | |
Kojto | 148:fd96258d940d | 287 | /*! |
Kojto | 148:fd96258d940d | 288 | * @brief De-initializes the I2S peripheral. |
Kojto | 148:fd96258d940d | 289 | * |
Kojto | 148:fd96258d940d | 290 | * This API gates the FLEXCOMM clock. The I2S module can't operate unless I2S_TxInit |
Kojto | 148:fd96258d940d | 291 | * or I2S_RxInit is called to enable the clock. |
Kojto | 148:fd96258d940d | 292 | * |
Kojto | 148:fd96258d940d | 293 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 294 | */ |
Kojto | 148:fd96258d940d | 295 | void I2S_Deinit(I2S_Type *base); |
Kojto | 148:fd96258d940d | 296 | |
Kojto | 148:fd96258d940d | 297 | /*! @} */ |
Kojto | 148:fd96258d940d | 298 | |
Kojto | 148:fd96258d940d | 299 | /*! |
Kojto | 148:fd96258d940d | 300 | * @name Non-blocking API |
Kojto | 148:fd96258d940d | 301 | * @{ |
Kojto | 148:fd96258d940d | 302 | */ |
Kojto | 148:fd96258d940d | 303 | |
Kojto | 148:fd96258d940d | 304 | /*! |
Kojto | 148:fd96258d940d | 305 | * @brief Initializes handle for transfer of audio data. |
Kojto | 148:fd96258d940d | 306 | * |
Kojto | 148:fd96258d940d | 307 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 308 | * @param handle pointer to handle structure. |
Kojto | 148:fd96258d940d | 309 | * @param callback function to be called back when transfer is done or fails. |
Kojto | 148:fd96258d940d | 310 | * @param userData pointer to data passed to callback. |
Kojto | 148:fd96258d940d | 311 | */ |
Kojto | 148:fd96258d940d | 312 | void I2S_TxTransferCreateHandle(I2S_Type *base, i2s_handle_t *handle, i2s_transfer_callback_t callback, void *userData); |
Kojto | 148:fd96258d940d | 313 | |
Kojto | 148:fd96258d940d | 314 | /*! |
Kojto | 148:fd96258d940d | 315 | * @brief Begins or queue sending of the given data. |
Kojto | 148:fd96258d940d | 316 | * |
Kojto | 148:fd96258d940d | 317 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 318 | * @param handle pointer to handle structure. |
Kojto | 148:fd96258d940d | 319 | * @param transfer data buffer. |
Kojto | 148:fd96258d940d | 320 | * |
Kojto | 148:fd96258d940d | 321 | * @retval kStatus_Success |
Kojto | 148:fd96258d940d | 322 | * @retval kStatus_I2S_Busy if all queue slots are occupied with unsent buffers. |
Kojto | 148:fd96258d940d | 323 | */ |
Kojto | 148:fd96258d940d | 324 | status_t I2S_TxTransferNonBlocking(I2S_Type *base, i2s_handle_t *handle, i2s_transfer_t transfer); |
Kojto | 148:fd96258d940d | 325 | |
Kojto | 148:fd96258d940d | 326 | /*! |
Kojto | 148:fd96258d940d | 327 | * @brief Aborts sending of data. |
Kojto | 148:fd96258d940d | 328 | * |
Kojto | 148:fd96258d940d | 329 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 330 | * @param handle pointer to handle structure. |
Kojto | 148:fd96258d940d | 331 | */ |
Kojto | 148:fd96258d940d | 332 | void I2S_TxTransferAbort(I2S_Type *base, i2s_handle_t *handle); |
Kojto | 148:fd96258d940d | 333 | |
Kojto | 148:fd96258d940d | 334 | /*! |
Kojto | 148:fd96258d940d | 335 | * @brief Initializes handle for reception of audio data. |
Kojto | 148:fd96258d940d | 336 | * |
Kojto | 148:fd96258d940d | 337 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 338 | * @param handle pointer to handle structure. |
Kojto | 148:fd96258d940d | 339 | * @param callback function to be called back when transfer is done or fails. |
Kojto | 148:fd96258d940d | 340 | * @param userData pointer to data passed to callback. |
Kojto | 148:fd96258d940d | 341 | */ |
Kojto | 148:fd96258d940d | 342 | void I2S_RxTransferCreateHandle(I2S_Type *base, i2s_handle_t *handle, i2s_transfer_callback_t callback, void *userData); |
Kojto | 148:fd96258d940d | 343 | |
Kojto | 148:fd96258d940d | 344 | /*! |
Kojto | 148:fd96258d940d | 345 | * @brief Begins or queue reception of data into given buffer. |
Kojto | 148:fd96258d940d | 346 | * |
Kojto | 148:fd96258d940d | 347 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 348 | * @param handle pointer to handle structure. |
Kojto | 148:fd96258d940d | 349 | * @param transfer data buffer. |
Kojto | 148:fd96258d940d | 350 | * |
Kojto | 148:fd96258d940d | 351 | * @retval kStatus_Success |
Kojto | 148:fd96258d940d | 352 | * @retval kStatus_I2S_Busy if all queue slots are occupied with buffers which are not full. |
Kojto | 148:fd96258d940d | 353 | */ |
Kojto | 148:fd96258d940d | 354 | status_t I2S_RxTransferNonBlocking(I2S_Type *base, i2s_handle_t *handle, i2s_transfer_t transfer); |
Kojto | 148:fd96258d940d | 355 | |
Kojto | 148:fd96258d940d | 356 | /*! |
Kojto | 148:fd96258d940d | 357 | * @brief Aborts receiving of data. |
Kojto | 148:fd96258d940d | 358 | * |
Kojto | 148:fd96258d940d | 359 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 360 | * @param handle pointer to handle structure. |
Kojto | 148:fd96258d940d | 361 | */ |
Kojto | 148:fd96258d940d | 362 | void I2S_RxTransferAbort(I2S_Type *base, i2s_handle_t *handle); |
Kojto | 148:fd96258d940d | 363 | |
Kojto | 148:fd96258d940d | 364 | /*! |
Kojto | 148:fd96258d940d | 365 | * @brief Returns number of bytes transferred so far. |
Kojto | 148:fd96258d940d | 366 | * |
Kojto | 148:fd96258d940d | 367 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 368 | * @param handle pointer to handle structure. |
Kojto | 148:fd96258d940d | 369 | * @param[out] count number of bytes transferred so far by the non-blocking transaction. |
Kojto | 148:fd96258d940d | 370 | * |
Kojto | 148:fd96258d940d | 371 | * @retval kStatus_Success |
Kojto | 148:fd96258d940d | 372 | * @retval kStatus_NoTransferInProgress there is no non-blocking transaction currently in progress. |
Kojto | 148:fd96258d940d | 373 | */ |
Kojto | 148:fd96258d940d | 374 | status_t I2S_TransferGetCount(I2S_Type *base, i2s_handle_t *handle, size_t *count); |
Kojto | 148:fd96258d940d | 375 | |
Kojto | 148:fd96258d940d | 376 | /*! |
Kojto | 148:fd96258d940d | 377 | * @brief Returns number of buffer underruns or overruns. |
Kojto | 148:fd96258d940d | 378 | * |
Kojto | 148:fd96258d940d | 379 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 380 | * @param handle pointer to handle structure. |
Kojto | 148:fd96258d940d | 381 | * @param[out] count number of transmit errors encountered so far by the non-blocking transaction. |
Kojto | 148:fd96258d940d | 382 | * |
Kojto | 148:fd96258d940d | 383 | * @retval kStatus_Success |
Kojto | 148:fd96258d940d | 384 | * @retval kStatus_NoTransferInProgress there is no non-blocking transaction currently in progress. |
Kojto | 148:fd96258d940d | 385 | */ |
Kojto | 148:fd96258d940d | 386 | status_t I2S_TransferGetErrorCount(I2S_Type *base, i2s_handle_t *handle, size_t *count); |
Kojto | 148:fd96258d940d | 387 | |
Kojto | 148:fd96258d940d | 388 | /*! @} */ |
Kojto | 148:fd96258d940d | 389 | |
Kojto | 148:fd96258d940d | 390 | /*! |
Kojto | 148:fd96258d940d | 391 | * @name Enable / disable |
Kojto | 148:fd96258d940d | 392 | * @{ |
Kojto | 148:fd96258d940d | 393 | */ |
Kojto | 148:fd96258d940d | 394 | |
Kojto | 148:fd96258d940d | 395 | /*! |
Kojto | 148:fd96258d940d | 396 | * @brief Enables I2S operation. |
Kojto | 148:fd96258d940d | 397 | * |
Kojto | 148:fd96258d940d | 398 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 399 | */ |
Kojto | 148:fd96258d940d | 400 | static inline void I2S_Enable(I2S_Type *base) |
Kojto | 148:fd96258d940d | 401 | { |
Kojto | 148:fd96258d940d | 402 | base->CFG1 |= I2S_CFG1_MAINENABLE(1U); |
Kojto | 148:fd96258d940d | 403 | } |
Kojto | 148:fd96258d940d | 404 | |
Kojto | 148:fd96258d940d | 405 | /*! |
Kojto | 148:fd96258d940d | 406 | * @brief Disables I2S operation. |
Kojto | 148:fd96258d940d | 407 | * |
Kojto | 148:fd96258d940d | 408 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 409 | */ |
Kojto | 148:fd96258d940d | 410 | static inline void I2S_Disable(I2S_Type *base) |
Kojto | 148:fd96258d940d | 411 | { |
Kojto | 148:fd96258d940d | 412 | base->CFG1 &= (~I2S_CFG1_MAINENABLE(1U)); |
Kojto | 148:fd96258d940d | 413 | } |
Kojto | 148:fd96258d940d | 414 | |
Kojto | 148:fd96258d940d | 415 | /*! @} */ |
Kojto | 148:fd96258d940d | 416 | |
Kojto | 148:fd96258d940d | 417 | /*! |
Kojto | 148:fd96258d940d | 418 | * @name Interrupts |
Kojto | 148:fd96258d940d | 419 | * @{ |
Kojto | 148:fd96258d940d | 420 | */ |
Kojto | 148:fd96258d940d | 421 | |
Kojto | 148:fd96258d940d | 422 | /*! |
Kojto | 148:fd96258d940d | 423 | * @brief Enables I2S FIFO interrupts. |
Kojto | 148:fd96258d940d | 424 | * |
Kojto | 148:fd96258d940d | 425 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 426 | * @param interruptMask bit mask of interrupts to enable. See #i2s_flags_t for the set |
Kojto | 148:fd96258d940d | 427 | * of constants that should be OR'd together to form the bit mask. |
Kojto | 148:fd96258d940d | 428 | */ |
Kojto | 148:fd96258d940d | 429 | static inline void I2S_EnableInterrupts(I2S_Type *base, uint32_t interruptMask) |
Kojto | 148:fd96258d940d | 430 | { |
Kojto | 148:fd96258d940d | 431 | base->FIFOINTENSET = interruptMask; |
Kojto | 148:fd96258d940d | 432 | } |
Kojto | 148:fd96258d940d | 433 | |
Kojto | 148:fd96258d940d | 434 | /*! |
Kojto | 148:fd96258d940d | 435 | * @brief Disables I2S FIFO interrupts. |
Kojto | 148:fd96258d940d | 436 | * |
Kojto | 148:fd96258d940d | 437 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 438 | * @param interruptMask bit mask of interrupts to enable. See #i2s_flags_t for the set |
Kojto | 148:fd96258d940d | 439 | * of constants that should be OR'd together to form the bit mask. |
Kojto | 148:fd96258d940d | 440 | */ |
Kojto | 148:fd96258d940d | 441 | static inline void I2S_DisableInterrupts(I2S_Type *base, uint32_t interruptMask) |
Kojto | 148:fd96258d940d | 442 | { |
Kojto | 148:fd96258d940d | 443 | base->FIFOINTENCLR = interruptMask; |
Kojto | 148:fd96258d940d | 444 | } |
Kojto | 148:fd96258d940d | 445 | |
Kojto | 148:fd96258d940d | 446 | /*! |
Kojto | 148:fd96258d940d | 447 | * @brief Returns the set of currently enabled I2S FIFO interrupts. |
Kojto | 148:fd96258d940d | 448 | * |
Kojto | 148:fd96258d940d | 449 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 450 | * |
Kojto | 148:fd96258d940d | 451 | * @return A bitmask composed of #i2s_flags_t enumerators OR'd together |
Kojto | 148:fd96258d940d | 452 | * to indicate the set of enabled interrupts. |
Kojto | 148:fd96258d940d | 453 | */ |
Kojto | 148:fd96258d940d | 454 | static inline uint32_t I2S_GetEnabledInterrupts(I2S_Type *base) |
Kojto | 148:fd96258d940d | 455 | { |
Kojto | 148:fd96258d940d | 456 | return base->FIFOINTENSET; |
Kojto | 148:fd96258d940d | 457 | } |
Kojto | 148:fd96258d940d | 458 | |
Kojto | 148:fd96258d940d | 459 | /*! |
Kojto | 148:fd96258d940d | 460 | * @brief Invoked from interrupt handler when transmit FIFO level decreases. |
Kojto | 148:fd96258d940d | 461 | * |
Kojto | 148:fd96258d940d | 462 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 463 | * @param handle pointer to handle structure. |
Kojto | 148:fd96258d940d | 464 | */ |
Kojto | 148:fd96258d940d | 465 | void I2S_TxHandleIRQ(I2S_Type *base, i2s_handle_t *handle); |
Kojto | 148:fd96258d940d | 466 | |
Kojto | 148:fd96258d940d | 467 | /*! |
Kojto | 148:fd96258d940d | 468 | * @brief Invoked from interrupt handler when receive FIFO level decreases. |
Kojto | 148:fd96258d940d | 469 | * |
Kojto | 148:fd96258d940d | 470 | * @param base I2S base pointer. |
Kojto | 148:fd96258d940d | 471 | * @param handle pointer to handle structure. |
Kojto | 148:fd96258d940d | 472 | */ |
Kojto | 148:fd96258d940d | 473 | void I2S_RxHandleIRQ(I2S_Type *base, i2s_handle_t *handle); |
Kojto | 148:fd96258d940d | 474 | |
Kojto | 148:fd96258d940d | 475 | /*! @} */ |
Kojto | 148:fd96258d940d | 476 | |
Kojto | 148:fd96258d940d | 477 | /*! @} */ |
Kojto | 148:fd96258d940d | 478 | |
Kojto | 148:fd96258d940d | 479 | #if defined(__cplusplus) |
Kojto | 148:fd96258d940d | 480 | } |
Kojto | 148:fd96258d940d | 481 | #endif |
Kojto | 148:fd96258d940d | 482 | |
Kojto | 148:fd96258d940d | 483 | #endif /* _FSL_I2S_H_ */ |