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.

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?

UserRevisionLine numberNew contents of line
AnnaBridge 143:86740a56073b 1 /*
AnnaBridge 143:86740a56073b 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
AnnaBridge 143:86740a56073b 3 * Copyright 2016-2017 NXP
AnnaBridge 143:86740a56073b 4 *
AnnaBridge 143:86740a56073b 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 143:86740a56073b 6 * are permitted provided that the following conditions are met:
AnnaBridge 143:86740a56073b 7 *
AnnaBridge 143:86740a56073b 8 * o Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 143:86740a56073b 9 * of conditions and the following disclaimer.
AnnaBridge 143:86740a56073b 10 *
AnnaBridge 143:86740a56073b 11 * o Redistributions in binary form must reproduce the above copyright notice, this
AnnaBridge 143:86740a56073b 12 * list of conditions and the following disclaimer in the documentation and/or
AnnaBridge 143:86740a56073b 13 * other materials provided with the distribution.
AnnaBridge 143:86740a56073b 14 *
AnnaBridge 143:86740a56073b 15 * o Neither the name of the copyright holder nor the names of its
AnnaBridge 143:86740a56073b 16 * contributors may be used to endorse or promote products derived from this
AnnaBridge 143:86740a56073b 17 * software without specific prior written permission.
AnnaBridge 143:86740a56073b 18 *
AnnaBridge 143:86740a56073b 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 143:86740a56073b 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 143:86740a56073b 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 143:86740a56073b 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 143:86740a56073b 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 143:86740a56073b 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 143:86740a56073b 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 143:86740a56073b 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 143:86740a56073b 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 143:86740a56073b 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 143:86740a56073b 29 */
AnnaBridge 143:86740a56073b 30 #ifndef _FSL_I2C_H_
AnnaBridge 143:86740a56073b 31 #define _FSL_I2C_H_
AnnaBridge 143:86740a56073b 32
AnnaBridge 143:86740a56073b 33 #include "fsl_common.h"
AnnaBridge 143:86740a56073b 34
AnnaBridge 143:86740a56073b 35 /*!
AnnaBridge 143:86740a56073b 36 * @addtogroup i2c_driver
AnnaBridge 143:86740a56073b 37 * @{
AnnaBridge 143:86740a56073b 38 */
AnnaBridge 143:86740a56073b 39
AnnaBridge 143:86740a56073b 40 /*******************************************************************************
AnnaBridge 143:86740a56073b 41 * Definitions
AnnaBridge 143:86740a56073b 42 ******************************************************************************/
AnnaBridge 143:86740a56073b 43
AnnaBridge 143:86740a56073b 44 /*! @name Driver version */
AnnaBridge 143:86740a56073b 45 /*@{*/
AnnaBridge 143:86740a56073b 46 /*! @brief I2C driver version 2.0.3. */
AnnaBridge 143:86740a56073b 47 #define FSL_I2C_DRIVER_VERSION (MAKE_VERSION(2, 0, 3))
AnnaBridge 143:86740a56073b 48 /*@}*/
AnnaBridge 143:86740a56073b 49
AnnaBridge 143:86740a56073b 50 #if (defined(FSL_FEATURE_I2C_HAS_START_STOP_DETECT) && FSL_FEATURE_I2C_HAS_START_STOP_DETECT || \
AnnaBridge 143:86740a56073b 51 defined(FSL_FEATURE_I2C_HAS_STOP_DETECT) && FSL_FEATURE_I2C_HAS_STOP_DETECT)
AnnaBridge 143:86740a56073b 52 #define I2C_HAS_STOP_DETECT
AnnaBridge 143:86740a56073b 53 #endif /* FSL_FEATURE_I2C_HAS_START_STOP_DETECT / FSL_FEATURE_I2C_HAS_STOP_DETECT */
AnnaBridge 143:86740a56073b 54
AnnaBridge 143:86740a56073b 55 /*! @brief I2C status return codes. */
AnnaBridge 143:86740a56073b 56 enum _i2c_status
AnnaBridge 143:86740a56073b 57 {
AnnaBridge 143:86740a56073b 58 kStatus_I2C_Busy = MAKE_STATUS(kStatusGroup_I2C, 0), /*!< I2C is busy with current transfer. */
AnnaBridge 143:86740a56073b 59 kStatus_I2C_Idle = MAKE_STATUS(kStatusGroup_I2C, 1), /*!< Bus is Idle. */
AnnaBridge 143:86740a56073b 60 kStatus_I2C_Nak = MAKE_STATUS(kStatusGroup_I2C, 2), /*!< NAK received during transfer. */
AnnaBridge 143:86740a56073b 61 kStatus_I2C_ArbitrationLost = MAKE_STATUS(kStatusGroup_I2C, 3), /*!< Arbitration lost during transfer. */
AnnaBridge 143:86740a56073b 62 kStatus_I2C_Timeout = MAKE_STATUS(kStatusGroup_I2C, 4), /*!< Wait event timeout. */
AnnaBridge 143:86740a56073b 63 kStatus_I2C_Addr_Nak = MAKE_STATUS(kStatusGroup_I2C, 5), /*!< NAK received during the address probe. */
AnnaBridge 143:86740a56073b 64 };
AnnaBridge 143:86740a56073b 65
AnnaBridge 143:86740a56073b 66 /*!
AnnaBridge 143:86740a56073b 67 * @brief I2C peripheral flags
AnnaBridge 143:86740a56073b 68 *
AnnaBridge 143:86740a56073b 69 * The following status register flags can be cleared:
AnnaBridge 143:86740a56073b 70 * - #kI2C_ArbitrationLostFlag
AnnaBridge 143:86740a56073b 71 * - #kI2C_IntPendingFlag
AnnaBridge 143:86740a56073b 72 * - #kI2C_StartDetectFlag
AnnaBridge 143:86740a56073b 73 * - #kI2C_StopDetectFlag
AnnaBridge 143:86740a56073b 74 *
AnnaBridge 143:86740a56073b 75 * @note These enumerations are meant to be OR'd together to form a bit mask.
AnnaBridge 143:86740a56073b 76 *
AnnaBridge 143:86740a56073b 77 */
AnnaBridge 143:86740a56073b 78 enum _i2c_flags
AnnaBridge 143:86740a56073b 79 {
AnnaBridge 143:86740a56073b 80 kI2C_ReceiveNakFlag = I2C_S_RXAK_MASK, /*!< I2C receive NAK flag. */
AnnaBridge 143:86740a56073b 81 kI2C_IntPendingFlag = I2C_S_IICIF_MASK, /*!< I2C interrupt pending flag. */
AnnaBridge 143:86740a56073b 82 kI2C_TransferDirectionFlag = I2C_S_SRW_MASK, /*!< I2C transfer direction flag. */
AnnaBridge 143:86740a56073b 83 kI2C_RangeAddressMatchFlag = I2C_S_RAM_MASK, /*!< I2C range address match flag. */
AnnaBridge 143:86740a56073b 84 kI2C_ArbitrationLostFlag = I2C_S_ARBL_MASK, /*!< I2C arbitration lost flag. */
AnnaBridge 143:86740a56073b 85 kI2C_BusBusyFlag = I2C_S_BUSY_MASK, /*!< I2C bus busy flag. */
AnnaBridge 143:86740a56073b 86 kI2C_AddressMatchFlag = I2C_S_IAAS_MASK, /*!< I2C address match flag. */
AnnaBridge 143:86740a56073b 87 kI2C_TransferCompleteFlag = I2C_S_TCF_MASK, /*!< I2C transfer complete flag. */
AnnaBridge 143:86740a56073b 88 #ifdef I2C_HAS_STOP_DETECT
AnnaBridge 143:86740a56073b 89 kI2C_StopDetectFlag = I2C_FLT_STOPF_MASK << 8, /*!< I2C stop detect flag. */
AnnaBridge 143:86740a56073b 90 #endif /* FSL_FEATURE_I2C_HAS_START_STOP_DETECT / FSL_FEATURE_I2C_HAS_STOP_DETECT */
AnnaBridge 143:86740a56073b 91
AnnaBridge 143:86740a56073b 92 #if defined(FSL_FEATURE_I2C_HAS_START_STOP_DETECT) && FSL_FEATURE_I2C_HAS_START_STOP_DETECT
AnnaBridge 143:86740a56073b 93 kI2C_StartDetectFlag = I2C_FLT_STARTF_MASK << 8, /*!< I2C start detect flag. */
AnnaBridge 143:86740a56073b 94 #endif /* FSL_FEATURE_I2C_HAS_START_STOP_DETECT */
AnnaBridge 143:86740a56073b 95 };
AnnaBridge 143:86740a56073b 96
AnnaBridge 143:86740a56073b 97 /*! @brief I2C feature interrupt source. */
AnnaBridge 143:86740a56073b 98 enum _i2c_interrupt_enable
AnnaBridge 143:86740a56073b 99 {
AnnaBridge 143:86740a56073b 100 kI2C_GlobalInterruptEnable = I2C_C1_IICIE_MASK, /*!< I2C global interrupt. */
AnnaBridge 143:86740a56073b 101
AnnaBridge 143:86740a56073b 102 #if defined(FSL_FEATURE_I2C_HAS_STOP_DETECT) && FSL_FEATURE_I2C_HAS_STOP_DETECT
AnnaBridge 143:86740a56073b 103 kI2C_StopDetectInterruptEnable = I2C_FLT_STOPIE_MASK, /*!< I2C stop detect interrupt. */
AnnaBridge 143:86740a56073b 104 #endif /* FSL_FEATURE_I2C_HAS_STOP_DETECT */
AnnaBridge 143:86740a56073b 105
AnnaBridge 143:86740a56073b 106 #if defined(FSL_FEATURE_I2C_HAS_START_STOP_DETECT) && FSL_FEATURE_I2C_HAS_START_STOP_DETECT
AnnaBridge 143:86740a56073b 107 kI2C_StartStopDetectInterruptEnable = I2C_FLT_SSIE_MASK, /*!< I2C start&stop detect interrupt. */
AnnaBridge 143:86740a56073b 108 #endif /* FSL_FEATURE_I2C_HAS_START_STOP_DETECT */
AnnaBridge 143:86740a56073b 109 };
AnnaBridge 143:86740a56073b 110
AnnaBridge 143:86740a56073b 111 /*! @brief The direction of master and slave transfers. */
AnnaBridge 143:86740a56073b 112 typedef enum _i2c_direction
AnnaBridge 143:86740a56073b 113 {
AnnaBridge 143:86740a56073b 114 kI2C_Write = 0x0U, /*!< Master transmits to the slave. */
AnnaBridge 143:86740a56073b 115 kI2C_Read = 0x1U, /*!< Master receives from the slave. */
AnnaBridge 143:86740a56073b 116 } i2c_direction_t;
AnnaBridge 143:86740a56073b 117
AnnaBridge 143:86740a56073b 118 /*! @brief Addressing mode. */
AnnaBridge 143:86740a56073b 119 typedef enum _i2c_slave_address_mode
AnnaBridge 143:86740a56073b 120 {
AnnaBridge 143:86740a56073b 121 kI2C_Address7bit = 0x0U, /*!< 7-bit addressing mode. */
AnnaBridge 143:86740a56073b 122 kI2C_RangeMatch = 0X2U, /*!< Range address match addressing mode. */
AnnaBridge 143:86740a56073b 123 } i2c_slave_address_mode_t;
AnnaBridge 143:86740a56073b 124
AnnaBridge 143:86740a56073b 125 /*! @brief I2C transfer control flag. */
AnnaBridge 143:86740a56073b 126 enum _i2c_master_transfer_flags
AnnaBridge 143:86740a56073b 127 {
AnnaBridge 143:86740a56073b 128 kI2C_TransferDefaultFlag = 0x0U, /*!< A transfer starts with a start signal, stops with a stop signal. */
AnnaBridge 143:86740a56073b 129 kI2C_TransferNoStartFlag = 0x1U, /*!< A transfer starts without a start signal. */
AnnaBridge 143:86740a56073b 130 kI2C_TransferRepeatedStartFlag = 0x2U, /*!< A transfer starts with a repeated start signal. */
AnnaBridge 143:86740a56073b 131 kI2C_TransferNoStopFlag = 0x4U, /*!< A transfer ends without a stop signal. */
AnnaBridge 143:86740a56073b 132 };
AnnaBridge 143:86740a56073b 133
AnnaBridge 143:86740a56073b 134 /*!
AnnaBridge 143:86740a56073b 135 * @brief Set of events sent to the callback for nonblocking slave transfers.
AnnaBridge 143:86740a56073b 136 *
AnnaBridge 143:86740a56073b 137 * These event enumerations are used for two related purposes. First, a bit mask created by OR'ing together
AnnaBridge 143:86740a56073b 138 * events is passed to I2C_SlaveTransferNonBlocking() to specify which events to enable.
AnnaBridge 143:86740a56073b 139 * Then, when the slave callback is invoked, it is passed the current event through its @a transfer
AnnaBridge 143:86740a56073b 140 * parameter.
AnnaBridge 143:86740a56073b 141 *
AnnaBridge 143:86740a56073b 142 * @note These enumerations are meant to be OR'd together to form a bit mask of events.
AnnaBridge 143:86740a56073b 143 */
AnnaBridge 143:86740a56073b 144 typedef enum _i2c_slave_transfer_event
AnnaBridge 143:86740a56073b 145 {
AnnaBridge 143:86740a56073b 146 kI2C_SlaveAddressMatchEvent = 0x01U, /*!< Received the slave address after a start or repeated start. */
AnnaBridge 143:86740a56073b 147 kI2C_SlaveTransmitEvent = 0x02U, /*!< A callback is requested to provide data to transmit
AnnaBridge 143:86740a56073b 148 (slave-transmitter role). */
AnnaBridge 143:86740a56073b 149 kI2C_SlaveReceiveEvent = 0x04U, /*!< A callback is requested to provide a buffer in which to place received
AnnaBridge 143:86740a56073b 150 data (slave-receiver role). */
AnnaBridge 143:86740a56073b 151 kI2C_SlaveTransmitAckEvent = 0x08U, /*!< A callback needs to either transmit an ACK or NACK. */
AnnaBridge 143:86740a56073b 152 #if defined(FSL_FEATURE_I2C_HAS_START_STOP_DETECT) && FSL_FEATURE_I2C_HAS_START_STOP_DETECT
AnnaBridge 143:86740a56073b 153 kI2C_SlaveStartEvent = 0x10U, /*!< A start/repeated start was detected. */
AnnaBridge 143:86740a56073b 154 #endif
AnnaBridge 143:86740a56073b 155 kI2C_SlaveCompletionEvent = 0x20U, /*!< A stop was detected or finished transfer, completing the transfer. */
AnnaBridge 143:86740a56073b 156 kI2C_SlaveGenaralcallEvent = 0x40U, /*!< Received the general call address after a start or repeated start. */
AnnaBridge 143:86740a56073b 157
AnnaBridge 143:86740a56073b 158 /*! A bit mask of all available events. */
AnnaBridge 143:86740a56073b 159 kI2C_SlaveAllEvents = kI2C_SlaveAddressMatchEvent | kI2C_SlaveTransmitEvent | kI2C_SlaveReceiveEvent |
AnnaBridge 143:86740a56073b 160 #if defined(FSL_FEATURE_I2C_HAS_START_STOP_DETECT) && FSL_FEATURE_I2C_HAS_START_STOP_DETECT
AnnaBridge 143:86740a56073b 161 kI2C_SlaveStartEvent |
AnnaBridge 143:86740a56073b 162 #endif
AnnaBridge 143:86740a56073b 163 kI2C_SlaveCompletionEvent | kI2C_SlaveGenaralcallEvent,
AnnaBridge 143:86740a56073b 164 } i2c_slave_transfer_event_t;
AnnaBridge 143:86740a56073b 165
AnnaBridge 143:86740a56073b 166 /*! @brief I2C master user configuration. */
AnnaBridge 143:86740a56073b 167 typedef struct _i2c_master_config
AnnaBridge 143:86740a56073b 168 {
AnnaBridge 143:86740a56073b 169 bool enableMaster; /*!< Enables the I2C peripheral at initialization time. */
AnnaBridge 143:86740a56073b 170 #if defined(FSL_FEATURE_I2C_HAS_STOP_HOLD_OFF) && FSL_FEATURE_I2C_HAS_STOP_HOLD_OFF
AnnaBridge 143:86740a56073b 171 bool enableStopHold; /*!< Controls the stop hold enable. */
AnnaBridge 143:86740a56073b 172 #endif
AnnaBridge 143:86740a56073b 173 #if defined(FSL_FEATURE_I2C_HAS_DOUBLE_BUFFER_ENABLE) && FSL_FEATURE_I2C_HAS_DOUBLE_BUFFER_ENABLE
AnnaBridge 143:86740a56073b 174 bool enableDoubleBuffering; /*!< Controls double buffer enable; notice that
AnnaBridge 143:86740a56073b 175 enabling the double buffer disables the clock stretch. */
AnnaBridge 143:86740a56073b 176 #endif
AnnaBridge 143:86740a56073b 177 uint32_t baudRate_Bps; /*!< Baud rate configuration of I2C peripheral. */
AnnaBridge 143:86740a56073b 178 uint8_t glitchFilterWidth; /*!< Controls the width of the glitch. */
AnnaBridge 143:86740a56073b 179 } i2c_master_config_t;
AnnaBridge 143:86740a56073b 180
AnnaBridge 143:86740a56073b 181 /*! @brief I2C slave user configuration. */
AnnaBridge 143:86740a56073b 182 typedef struct _i2c_slave_config
AnnaBridge 143:86740a56073b 183 {
AnnaBridge 143:86740a56073b 184 bool enableSlave; /*!< Enables the I2C peripheral at initialization time. */
AnnaBridge 143:86740a56073b 185 bool enableGeneralCall; /*!< Enables the general call addressing mode. */
AnnaBridge 143:86740a56073b 186 bool enableWakeUp; /*!< Enables/disables waking up MCU from low-power mode. */
AnnaBridge 143:86740a56073b 187 #if defined(FSL_FEATURE_I2C_HAS_DOUBLE_BUFFER_ENABLE) && FSL_FEATURE_I2C_HAS_DOUBLE_BUFFER_ENABLE
AnnaBridge 143:86740a56073b 188 bool enableDoubleBuffering; /*!< Controls a double buffer enable; notice that
AnnaBridge 143:86740a56073b 189 enabling the double buffer disables the clock stretch. */
AnnaBridge 143:86740a56073b 190 #endif
AnnaBridge 143:86740a56073b 191 bool enableBaudRateCtl; /*!< Enables/disables independent slave baud rate on SCL in very fast I2C modes. */
AnnaBridge 143:86740a56073b 192 uint16_t slaveAddress; /*!< A slave address configuration. */
AnnaBridge 143:86740a56073b 193 uint16_t upperAddress; /*!< A maximum boundary slave address used in a range matching mode. */
AnnaBridge 143:86740a56073b 194 i2c_slave_address_mode_t
AnnaBridge 143:86740a56073b 195 addressingMode; /*!< An addressing mode configuration of i2c_slave_address_mode_config_t. */
AnnaBridge 143:86740a56073b 196 uint32_t sclStopHoldTime_ns; /*!< the delay from the rising edge of SCL (I2C clock) to the rising edge of SDA (I2C
AnnaBridge 143:86740a56073b 197 data) while SCL is high (stop condition), SDA hold time and SCL start hold time
AnnaBridge 143:86740a56073b 198 are also configured according to the SCL stop hold time. */
AnnaBridge 143:86740a56073b 199 } i2c_slave_config_t;
AnnaBridge 143:86740a56073b 200
AnnaBridge 143:86740a56073b 201 /*! @brief I2C master handle typedef. */
AnnaBridge 143:86740a56073b 202 typedef struct _i2c_master_handle i2c_master_handle_t;
AnnaBridge 143:86740a56073b 203
AnnaBridge 143:86740a56073b 204 /*! @brief I2C master transfer callback typedef. */
AnnaBridge 143:86740a56073b 205 typedef void (*i2c_master_transfer_callback_t)(I2C_Type *base,
AnnaBridge 143:86740a56073b 206 i2c_master_handle_t *handle,
AnnaBridge 143:86740a56073b 207 status_t status,
AnnaBridge 143:86740a56073b 208 void *userData);
AnnaBridge 143:86740a56073b 209
AnnaBridge 143:86740a56073b 210 /*! @brief I2C slave handle typedef. */
AnnaBridge 143:86740a56073b 211 typedef struct _i2c_slave_handle i2c_slave_handle_t;
AnnaBridge 143:86740a56073b 212
AnnaBridge 143:86740a56073b 213 /*! @brief I2C master transfer structure. */
AnnaBridge 143:86740a56073b 214 typedef struct _i2c_master_transfer
AnnaBridge 143:86740a56073b 215 {
AnnaBridge 143:86740a56073b 216 uint32_t flags; /*!< A transfer flag which controls the transfer. */
AnnaBridge 143:86740a56073b 217 uint8_t slaveAddress; /*!< 7-bit slave address. */
AnnaBridge 143:86740a56073b 218 i2c_direction_t direction; /*!< A transfer direction, read or write. */
AnnaBridge 143:86740a56073b 219 uint32_t subaddress; /*!< A sub address. Transferred MSB first. */
AnnaBridge 143:86740a56073b 220 uint8_t subaddressSize; /*!< A size of the command buffer. */
AnnaBridge 143:86740a56073b 221 uint8_t *volatile data; /*!< A transfer buffer. */
AnnaBridge 143:86740a56073b 222 volatile size_t dataSize; /*!< A transfer size. */
AnnaBridge 143:86740a56073b 223 } i2c_master_transfer_t;
AnnaBridge 143:86740a56073b 224
AnnaBridge 143:86740a56073b 225 /*! @brief I2C master handle structure. */
AnnaBridge 143:86740a56073b 226 struct _i2c_master_handle
AnnaBridge 143:86740a56073b 227 {
AnnaBridge 143:86740a56073b 228 i2c_master_transfer_t transfer; /*!< I2C master transfer copy. */
AnnaBridge 143:86740a56073b 229 size_t transferSize; /*!< Total bytes to be transferred. */
AnnaBridge 143:86740a56073b 230 uint8_t state; /*!< A transfer state maintained during transfer. */
AnnaBridge 143:86740a56073b 231 i2c_master_transfer_callback_t completionCallback; /*!< A callback function called when the transfer is finished. */
AnnaBridge 143:86740a56073b 232 void *userData; /*!< A callback parameter passed to the callback function. */
AnnaBridge 143:86740a56073b 233 };
AnnaBridge 143:86740a56073b 234
AnnaBridge 143:86740a56073b 235 /*! @brief I2C slave transfer structure. */
AnnaBridge 143:86740a56073b 236 typedef struct _i2c_slave_transfer
AnnaBridge 143:86740a56073b 237 {
AnnaBridge 143:86740a56073b 238 i2c_slave_transfer_event_t event; /*!< A reason that the callback is invoked. */
AnnaBridge 143:86740a56073b 239 uint8_t *volatile data; /*!< A transfer buffer. */
AnnaBridge 143:86740a56073b 240 volatile size_t dataSize; /*!< A transfer size. */
AnnaBridge 143:86740a56073b 241 status_t completionStatus; /*!< Success or error code describing how the transfer completed. Only applies for
AnnaBridge 143:86740a56073b 242 #kI2C_SlaveCompletionEvent. */
AnnaBridge 143:86740a56073b 243 size_t transferredCount; /*!< A number of bytes actually transferred since the start or since the last repeated
AnnaBridge 143:86740a56073b 244 start. */
AnnaBridge 143:86740a56073b 245 } i2c_slave_transfer_t;
AnnaBridge 143:86740a56073b 246
AnnaBridge 143:86740a56073b 247 /*! @brief I2C slave transfer callback typedef. */
AnnaBridge 143:86740a56073b 248 typedef void (*i2c_slave_transfer_callback_t)(I2C_Type *base, i2c_slave_transfer_t *xfer, void *userData);
AnnaBridge 143:86740a56073b 249
AnnaBridge 143:86740a56073b 250 /*! @brief I2C slave handle structure. */
AnnaBridge 143:86740a56073b 251 struct _i2c_slave_handle
AnnaBridge 143:86740a56073b 252 {
AnnaBridge 143:86740a56073b 253 volatile bool isBusy; /*!< Indicates whether a transfer is busy. */
AnnaBridge 143:86740a56073b 254 i2c_slave_transfer_t transfer; /*!< I2C slave transfer copy. */
AnnaBridge 143:86740a56073b 255 uint32_t eventMask; /*!< A mask of enabled events. */
AnnaBridge 143:86740a56073b 256 i2c_slave_transfer_callback_t callback; /*!< A callback function called at the transfer event. */
AnnaBridge 143:86740a56073b 257 void *userData; /*!< A callback parameter passed to the callback. */
AnnaBridge 143:86740a56073b 258 };
AnnaBridge 143:86740a56073b 259
AnnaBridge 143:86740a56073b 260 /*******************************************************************************
AnnaBridge 143:86740a56073b 261 * API
AnnaBridge 143:86740a56073b 262 ******************************************************************************/
AnnaBridge 143:86740a56073b 263
AnnaBridge 143:86740a56073b 264 #if defined(__cplusplus)
AnnaBridge 143:86740a56073b 265 extern "C" {
AnnaBridge 143:86740a56073b 266 #endif /*_cplusplus. */
AnnaBridge 143:86740a56073b 267
AnnaBridge 143:86740a56073b 268 /*!
AnnaBridge 143:86740a56073b 269 * @name Initialization and deinitialization
AnnaBridge 143:86740a56073b 270 * @{
AnnaBridge 143:86740a56073b 271 */
AnnaBridge 143:86740a56073b 272
AnnaBridge 143:86740a56073b 273 /*!
AnnaBridge 143:86740a56073b 274 * @brief Initializes the I2C peripheral. Call this API to ungate the I2C clock
AnnaBridge 143:86740a56073b 275 * and configure the I2C with master configuration.
AnnaBridge 143:86740a56073b 276 *
AnnaBridge 143:86740a56073b 277 * @note This API should be called at the beginning of the application.
AnnaBridge 143:86740a56073b 278 * Otherwise, any operation to the I2C module can cause a hard fault
AnnaBridge 143:86740a56073b 279 * because the clock is not enabled. The configuration structure can be custom filled
AnnaBridge 143:86740a56073b 280 * or it can be set with default values by using the I2C_MasterGetDefaultConfig().
AnnaBridge 143:86740a56073b 281 * After calling this API, the master is ready to transfer.
AnnaBridge 143:86740a56073b 282 * This is an example.
AnnaBridge 143:86740a56073b 283 * @code
AnnaBridge 143:86740a56073b 284 * i2c_master_config_t config = {
AnnaBridge 143:86740a56073b 285 * .enableMaster = true,
AnnaBridge 143:86740a56073b 286 * .enableStopHold = false,
AnnaBridge 143:86740a56073b 287 * .highDrive = false,
AnnaBridge 143:86740a56073b 288 * .baudRate_Bps = 100000,
AnnaBridge 143:86740a56073b 289 * .glitchFilterWidth = 0
AnnaBridge 143:86740a56073b 290 * };
AnnaBridge 143:86740a56073b 291 * I2C_MasterInit(I2C0, &config, 12000000U);
AnnaBridge 143:86740a56073b 292 * @endcode
AnnaBridge 143:86740a56073b 293 *
AnnaBridge 143:86740a56073b 294 * @param base I2C base pointer
AnnaBridge 143:86740a56073b 295 * @param masterConfig A pointer to the master configuration structure
AnnaBridge 143:86740a56073b 296 * @param srcClock_Hz I2C peripheral clock frequency in Hz
AnnaBridge 143:86740a56073b 297 */
AnnaBridge 143:86740a56073b 298 void I2C_MasterInit(I2C_Type *base, const i2c_master_config_t *masterConfig, uint32_t srcClock_Hz);
AnnaBridge 143:86740a56073b 299
AnnaBridge 143:86740a56073b 300 /*!
AnnaBridge 143:86740a56073b 301 * @brief Initializes the I2C peripheral. Call this API to ungate the I2C clock
AnnaBridge 143:86740a56073b 302 * and initialize the I2C with the slave configuration.
AnnaBridge 143:86740a56073b 303 *
AnnaBridge 143:86740a56073b 304 * @note This API should be called at the beginning of the application.
AnnaBridge 143:86740a56073b 305 * Otherwise, any operation to the I2C module can cause a hard fault
AnnaBridge 143:86740a56073b 306 * because the clock is not enabled. The configuration structure can partly be set
AnnaBridge 143:86740a56073b 307 * with default values by I2C_SlaveGetDefaultConfig() or it can be custom filled by the user.
AnnaBridge 143:86740a56073b 308 * This is an example.
AnnaBridge 143:86740a56073b 309 * @code
AnnaBridge 143:86740a56073b 310 * i2c_slave_config_t config = {
AnnaBridge 143:86740a56073b 311 * .enableSlave = true,
AnnaBridge 143:86740a56073b 312 * .enableGeneralCall = false,
AnnaBridge 143:86740a56073b 313 * .addressingMode = kI2C_Address7bit,
AnnaBridge 143:86740a56073b 314 * .slaveAddress = 0x1DU,
AnnaBridge 143:86740a56073b 315 * .enableWakeUp = false,
AnnaBridge 143:86740a56073b 316 * .enablehighDrive = false,
AnnaBridge 143:86740a56073b 317 * .enableBaudRateCtl = false,
AnnaBridge 143:86740a56073b 318 * .sclStopHoldTime_ns = 4000
AnnaBridge 143:86740a56073b 319 * };
AnnaBridge 143:86740a56073b 320 * I2C_SlaveInit(I2C0, &config, 12000000U);
AnnaBridge 143:86740a56073b 321 * @endcode
AnnaBridge 143:86740a56073b 322 *
AnnaBridge 143:86740a56073b 323 * @param base I2C base pointer
AnnaBridge 143:86740a56073b 324 * @param slaveConfig A pointer to the slave configuration structure
AnnaBridge 143:86740a56073b 325 * @param srcClock_Hz I2C peripheral clock frequency in Hz
AnnaBridge 143:86740a56073b 326 */
AnnaBridge 143:86740a56073b 327 void I2C_SlaveInit(I2C_Type *base, const i2c_slave_config_t *slaveConfig, uint32_t srcClock_Hz);
AnnaBridge 143:86740a56073b 328
AnnaBridge 143:86740a56073b 329 /*!
AnnaBridge 143:86740a56073b 330 * @brief De-initializes the I2C master peripheral. Call this API to gate the I2C clock.
AnnaBridge 143:86740a56073b 331 * The I2C master module can't work unless the I2C_MasterInit is called.
AnnaBridge 143:86740a56073b 332 * @param base I2C base pointer
AnnaBridge 143:86740a56073b 333 */
AnnaBridge 143:86740a56073b 334 void I2C_MasterDeinit(I2C_Type *base);
AnnaBridge 143:86740a56073b 335
AnnaBridge 143:86740a56073b 336 /*!
AnnaBridge 143:86740a56073b 337 * @brief De-initializes the I2C slave peripheral. Calling this API gates the I2C clock.
AnnaBridge 143:86740a56073b 338 * The I2C slave module can't work unless the I2C_SlaveInit is called to enable the clock.
AnnaBridge 143:86740a56073b 339 * @param base I2C base pointer
AnnaBridge 143:86740a56073b 340 */
AnnaBridge 143:86740a56073b 341 void I2C_SlaveDeinit(I2C_Type *base);
AnnaBridge 143:86740a56073b 342
AnnaBridge 143:86740a56073b 343 /*!
AnnaBridge 143:86740a56073b 344 * @brief Sets the I2C master configuration structure to default values.
AnnaBridge 143:86740a56073b 345 *
AnnaBridge 143:86740a56073b 346 * The purpose of this API is to get the configuration structure initialized for use in the I2C_MasterConfigure().
AnnaBridge 143:86740a56073b 347 * Use the initialized structure unchanged in the I2C_MasterConfigure() or modify
AnnaBridge 143:86740a56073b 348 * the structure before calling the I2C_MasterConfigure().
AnnaBridge 143:86740a56073b 349 * This is an example.
AnnaBridge 143:86740a56073b 350 * @code
AnnaBridge 143:86740a56073b 351 * i2c_master_config_t config;
AnnaBridge 143:86740a56073b 352 * I2C_MasterGetDefaultConfig(&config);
AnnaBridge 143:86740a56073b 353 * @endcode
AnnaBridge 143:86740a56073b 354 * @param masterConfig A pointer to the master configuration structure.
AnnaBridge 143:86740a56073b 355 */
AnnaBridge 143:86740a56073b 356 void I2C_MasterGetDefaultConfig(i2c_master_config_t *masterConfig);
AnnaBridge 143:86740a56073b 357
AnnaBridge 143:86740a56073b 358 /*!
AnnaBridge 143:86740a56073b 359 * @brief Sets the I2C slave configuration structure to default values.
AnnaBridge 143:86740a56073b 360 *
AnnaBridge 143:86740a56073b 361 * The purpose of this API is to get the configuration structure initialized for use in the I2C_SlaveConfigure().
AnnaBridge 143:86740a56073b 362 * Modify fields of the structure before calling the I2C_SlaveConfigure().
AnnaBridge 143:86740a56073b 363 * This is an example.
AnnaBridge 143:86740a56073b 364 * @code
AnnaBridge 143:86740a56073b 365 * i2c_slave_config_t config;
AnnaBridge 143:86740a56073b 366 * I2C_SlaveGetDefaultConfig(&config);
AnnaBridge 143:86740a56073b 367 * @endcode
AnnaBridge 143:86740a56073b 368 * @param slaveConfig A pointer to the slave configuration structure.
AnnaBridge 143:86740a56073b 369 */
AnnaBridge 143:86740a56073b 370 void I2C_SlaveGetDefaultConfig(i2c_slave_config_t *slaveConfig);
AnnaBridge 143:86740a56073b 371
AnnaBridge 143:86740a56073b 372 /*!
AnnaBridge 143:86740a56073b 373 * @brief Enables or disabless the I2C peripheral operation.
AnnaBridge 143:86740a56073b 374 *
AnnaBridge 143:86740a56073b 375 * @param base I2C base pointer
AnnaBridge 143:86740a56073b 376 * @param enable Pass true to enable and false to disable the module.
AnnaBridge 143:86740a56073b 377 */
AnnaBridge 143:86740a56073b 378 static inline void I2C_Enable(I2C_Type *base, bool enable)
AnnaBridge 143:86740a56073b 379 {
AnnaBridge 143:86740a56073b 380 if (enable)
AnnaBridge 143:86740a56073b 381 {
AnnaBridge 143:86740a56073b 382 base->C1 |= I2C_C1_IICEN_MASK;
AnnaBridge 143:86740a56073b 383 }
AnnaBridge 143:86740a56073b 384 else
AnnaBridge 143:86740a56073b 385 {
AnnaBridge 143:86740a56073b 386 base->C1 &= ~I2C_C1_IICEN_MASK;
AnnaBridge 143:86740a56073b 387 }
AnnaBridge 143:86740a56073b 388 }
AnnaBridge 143:86740a56073b 389
AnnaBridge 143:86740a56073b 390 /* @} */
AnnaBridge 143:86740a56073b 391
AnnaBridge 143:86740a56073b 392 /*!
AnnaBridge 143:86740a56073b 393 * @name Status
AnnaBridge 143:86740a56073b 394 * @{
AnnaBridge 143:86740a56073b 395 */
AnnaBridge 143:86740a56073b 396
AnnaBridge 143:86740a56073b 397 /*!
AnnaBridge 143:86740a56073b 398 * @brief Gets the I2C status flags.
AnnaBridge 143:86740a56073b 399 *
AnnaBridge 143:86740a56073b 400 * @param base I2C base pointer
AnnaBridge 143:86740a56073b 401 * @return status flag, use status flag to AND #_i2c_flags to get the related status.
AnnaBridge 143:86740a56073b 402 */
AnnaBridge 143:86740a56073b 403 uint32_t I2C_MasterGetStatusFlags(I2C_Type *base);
AnnaBridge 143:86740a56073b 404
AnnaBridge 143:86740a56073b 405 /*!
AnnaBridge 143:86740a56073b 406 * @brief Gets the I2C status flags.
AnnaBridge 143:86740a56073b 407 *
AnnaBridge 143:86740a56073b 408 * @param base I2C base pointer
AnnaBridge 143:86740a56073b 409 * @return status flag, use status flag to AND #_i2c_flags to get the related status.
AnnaBridge 143:86740a56073b 410 */
AnnaBridge 143:86740a56073b 411 static inline uint32_t I2C_SlaveGetStatusFlags(I2C_Type *base)
AnnaBridge 143:86740a56073b 412 {
AnnaBridge 143:86740a56073b 413 return I2C_MasterGetStatusFlags(base);
AnnaBridge 143:86740a56073b 414 }
AnnaBridge 143:86740a56073b 415
AnnaBridge 143:86740a56073b 416 /*!
AnnaBridge 143:86740a56073b 417 * @brief Clears the I2C status flag state.
AnnaBridge 143:86740a56073b 418 *
AnnaBridge 143:86740a56073b 419 * The following status register flags can be cleared kI2C_ArbitrationLostFlag and kI2C_IntPendingFlag.
AnnaBridge 143:86740a56073b 420 *
AnnaBridge 143:86740a56073b 421 * @param base I2C base pointer
AnnaBridge 143:86740a56073b 422 * @param statusMask The status flag mask, defined in type i2c_status_flag_t.
AnnaBridge 143:86740a56073b 423 * The parameter can be any combination of the following values:
AnnaBridge 143:86740a56073b 424 * @arg kI2C_StartDetectFlag (if available)
AnnaBridge 143:86740a56073b 425 * @arg kI2C_StopDetectFlag (if available)
AnnaBridge 143:86740a56073b 426 * @arg kI2C_ArbitrationLostFlag
AnnaBridge 143:86740a56073b 427 * @arg kI2C_IntPendingFlagFlag
AnnaBridge 143:86740a56073b 428 */
AnnaBridge 143:86740a56073b 429 static inline void I2C_MasterClearStatusFlags(I2C_Type *base, uint32_t statusMask)
AnnaBridge 143:86740a56073b 430 {
AnnaBridge 143:86740a56073b 431 /* Must clear the STARTF / STOPF bits prior to clearing IICIF */
AnnaBridge 143:86740a56073b 432 #if defined(FSL_FEATURE_I2C_HAS_START_STOP_DETECT) && FSL_FEATURE_I2C_HAS_START_STOP_DETECT
AnnaBridge 143:86740a56073b 433 if (statusMask & kI2C_StartDetectFlag)
AnnaBridge 143:86740a56073b 434 {
AnnaBridge 143:86740a56073b 435 /* Shift the odd-ball flags back into place. */
AnnaBridge 143:86740a56073b 436 base->FLT |= (uint8_t)(statusMask >> 8U);
AnnaBridge 143:86740a56073b 437 }
AnnaBridge 143:86740a56073b 438 #endif
AnnaBridge 143:86740a56073b 439
AnnaBridge 143:86740a56073b 440 #ifdef I2C_HAS_STOP_DETECT
AnnaBridge 143:86740a56073b 441 if (statusMask & kI2C_StopDetectFlag)
AnnaBridge 143:86740a56073b 442 {
AnnaBridge 143:86740a56073b 443 /* Shift the odd-ball flags back into place. */
AnnaBridge 143:86740a56073b 444 base->FLT |= (uint8_t)(statusMask >> 8U);
AnnaBridge 143:86740a56073b 445 }
AnnaBridge 143:86740a56073b 446 #endif
AnnaBridge 143:86740a56073b 447
AnnaBridge 143:86740a56073b 448 base->S = (uint8_t)statusMask;
AnnaBridge 143:86740a56073b 449 }
AnnaBridge 143:86740a56073b 450
AnnaBridge 143:86740a56073b 451 /*!
AnnaBridge 143:86740a56073b 452 * @brief Clears the I2C status flag state.
AnnaBridge 143:86740a56073b 453 *
AnnaBridge 143:86740a56073b 454 * The following status register flags can be cleared kI2C_ArbitrationLostFlag and kI2C_IntPendingFlag
AnnaBridge 143:86740a56073b 455 *
AnnaBridge 143:86740a56073b 456 * @param base I2C base pointer
AnnaBridge 143:86740a56073b 457 * @param statusMask The status flag mask, defined in type i2c_status_flag_t.
AnnaBridge 143:86740a56073b 458 * The parameter can be any combination of the following values:
AnnaBridge 143:86740a56073b 459 * @arg kI2C_StartDetectFlag (if available)
AnnaBridge 143:86740a56073b 460 * @arg kI2C_StopDetectFlag (if available)
AnnaBridge 143:86740a56073b 461 * @arg kI2C_ArbitrationLostFlag
AnnaBridge 143:86740a56073b 462 * @arg kI2C_IntPendingFlagFlag
AnnaBridge 143:86740a56073b 463 */
AnnaBridge 143:86740a56073b 464 static inline void I2C_SlaveClearStatusFlags(I2C_Type *base, uint32_t statusMask)
AnnaBridge 143:86740a56073b 465 {
AnnaBridge 143:86740a56073b 466 I2C_MasterClearStatusFlags(base, statusMask);
AnnaBridge 143:86740a56073b 467 }
AnnaBridge 143:86740a56073b 468
AnnaBridge 143:86740a56073b 469 /* @} */
AnnaBridge 143:86740a56073b 470
AnnaBridge 143:86740a56073b 471 /*!
AnnaBridge 143:86740a56073b 472 * @name Interrupts
AnnaBridge 143:86740a56073b 473 * @{
AnnaBridge 143:86740a56073b 474 */
AnnaBridge 143:86740a56073b 475
AnnaBridge 143:86740a56073b 476 /*!
AnnaBridge 143:86740a56073b 477 * @brief Enables I2C interrupt requests.
AnnaBridge 143:86740a56073b 478 *
AnnaBridge 143:86740a56073b 479 * @param base I2C base pointer
AnnaBridge 143:86740a56073b 480 * @param mask interrupt source
AnnaBridge 143:86740a56073b 481 * The parameter can be combination of the following source if defined:
AnnaBridge 143:86740a56073b 482 * @arg kI2C_GlobalInterruptEnable
AnnaBridge 143:86740a56073b 483 * @arg kI2C_StopDetectInterruptEnable/kI2C_StartDetectInterruptEnable
AnnaBridge 143:86740a56073b 484 * @arg kI2C_SdaTimeoutInterruptEnable
AnnaBridge 143:86740a56073b 485 */
AnnaBridge 143:86740a56073b 486 void I2C_EnableInterrupts(I2C_Type *base, uint32_t mask);
AnnaBridge 143:86740a56073b 487
AnnaBridge 143:86740a56073b 488 /*!
AnnaBridge 143:86740a56073b 489 * @brief Disables I2C interrupt requests.
AnnaBridge 143:86740a56073b 490 *
AnnaBridge 143:86740a56073b 491 * @param base I2C base pointer
AnnaBridge 143:86740a56073b 492 * @param mask interrupt source
AnnaBridge 143:86740a56073b 493 * The parameter can be combination of the following source if defined:
AnnaBridge 143:86740a56073b 494 * @arg kI2C_GlobalInterruptEnable
AnnaBridge 143:86740a56073b 495 * @arg kI2C_StopDetectInterruptEnable/kI2C_StartDetectInterruptEnable
AnnaBridge 143:86740a56073b 496 * @arg kI2C_SdaTimeoutInterruptEnable
AnnaBridge 143:86740a56073b 497 */
AnnaBridge 143:86740a56073b 498 void I2C_DisableInterrupts(I2C_Type *base, uint32_t mask);
AnnaBridge 143:86740a56073b 499
AnnaBridge 143:86740a56073b 500 /*!
AnnaBridge 143:86740a56073b 501 * @name DMA Control
AnnaBridge 143:86740a56073b 502 * @{
AnnaBridge 143:86740a56073b 503 */
AnnaBridge 143:86740a56073b 504 #if defined(FSL_FEATURE_I2C_HAS_DMA_SUPPORT) && FSL_FEATURE_I2C_HAS_DMA_SUPPORT
AnnaBridge 143:86740a56073b 505 /*!
AnnaBridge 143:86740a56073b 506 * @brief Enables/disables the I2C DMA interrupt.
AnnaBridge 143:86740a56073b 507 *
AnnaBridge 143:86740a56073b 508 * @param base I2C base pointer
AnnaBridge 143:86740a56073b 509 * @param enable true to enable, false to disable
AnnaBridge 143:86740a56073b 510 */
AnnaBridge 143:86740a56073b 511 static inline void I2C_EnableDMA(I2C_Type *base, bool enable)
AnnaBridge 143:86740a56073b 512 {
AnnaBridge 143:86740a56073b 513 if (enable)
AnnaBridge 143:86740a56073b 514 {
AnnaBridge 143:86740a56073b 515 base->C1 |= I2C_C1_DMAEN_MASK;
AnnaBridge 143:86740a56073b 516 }
AnnaBridge 143:86740a56073b 517 else
AnnaBridge 143:86740a56073b 518 {
AnnaBridge 143:86740a56073b 519 base->C1 &= ~I2C_C1_DMAEN_MASK;
AnnaBridge 143:86740a56073b 520 }
AnnaBridge 143:86740a56073b 521 }
AnnaBridge 143:86740a56073b 522
AnnaBridge 143:86740a56073b 523 #endif /* FSL_FEATURE_I2C_HAS_DMA_SUPPORT */
AnnaBridge 143:86740a56073b 524
AnnaBridge 143:86740a56073b 525 /*!
AnnaBridge 143:86740a56073b 526 * @brief Gets the I2C tx/rx data register address. This API is used to provide a transfer address
AnnaBridge 143:86740a56073b 527 * for I2C DMA transfer configuration.
AnnaBridge 143:86740a56073b 528 *
AnnaBridge 143:86740a56073b 529 * @param base I2C base pointer
AnnaBridge 143:86740a56073b 530 * @return data register address
AnnaBridge 143:86740a56073b 531 */
AnnaBridge 143:86740a56073b 532 static inline uint32_t I2C_GetDataRegAddr(I2C_Type *base)
AnnaBridge 143:86740a56073b 533 {
AnnaBridge 143:86740a56073b 534 return (uint32_t)(&(base->D));
AnnaBridge 143:86740a56073b 535 }
AnnaBridge 143:86740a56073b 536
AnnaBridge 143:86740a56073b 537 /* @} */
AnnaBridge 143:86740a56073b 538 /*!
AnnaBridge 143:86740a56073b 539 * @name Bus Operations
AnnaBridge 143:86740a56073b 540 * @{
AnnaBridge 143:86740a56073b 541 */
AnnaBridge 143:86740a56073b 542
AnnaBridge 143:86740a56073b 543 /*!
AnnaBridge 143:86740a56073b 544 * @brief Sets the I2C master transfer baud rate.
AnnaBridge 143:86740a56073b 545 *
AnnaBridge 143:86740a56073b 546 * @param base I2C base pointer
AnnaBridge 143:86740a56073b 547 * @param baudRate_Bps the baud rate value in bps
AnnaBridge 143:86740a56073b 548 * @param srcClock_Hz Source clock
AnnaBridge 143:86740a56073b 549 */
AnnaBridge 143:86740a56073b 550 void I2C_MasterSetBaudRate(I2C_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz);
AnnaBridge 143:86740a56073b 551
AnnaBridge 143:86740a56073b 552 /*!
AnnaBridge 143:86740a56073b 553 * @brief Sends a START on the I2C bus.
AnnaBridge 143:86740a56073b 554 *
AnnaBridge 143:86740a56073b 555 * This function is used to initiate a new master mode transfer by sending the START signal.
AnnaBridge 143:86740a56073b 556 * The slave address is sent following the I2C START signal.
AnnaBridge 143:86740a56073b 557 *
AnnaBridge 143:86740a56073b 558 * @param base I2C peripheral base pointer
AnnaBridge 143:86740a56073b 559 * @param address 7-bit slave device address.
AnnaBridge 143:86740a56073b 560 * @param direction Master transfer directions(transmit/receive).
AnnaBridge 143:86740a56073b 561 * @retval kStatus_Success Successfully send the start signal.
AnnaBridge 143:86740a56073b 562 * @retval kStatus_I2C_Busy Current bus is busy.
AnnaBridge 143:86740a56073b 563 */
AnnaBridge 143:86740a56073b 564 status_t I2C_MasterStart(I2C_Type *base, uint8_t address, i2c_direction_t direction);
AnnaBridge 143:86740a56073b 565
AnnaBridge 143:86740a56073b 566 /*!
AnnaBridge 143:86740a56073b 567 * @brief Sends a STOP signal on the I2C bus.
AnnaBridge 143:86740a56073b 568 *
AnnaBridge 143:86740a56073b 569 * @retval kStatus_Success Successfully send the stop signal.
AnnaBridge 143:86740a56073b 570 * @retval kStatus_I2C_Timeout Send stop signal failed, timeout.
AnnaBridge 143:86740a56073b 571 */
AnnaBridge 143:86740a56073b 572 status_t I2C_MasterStop(I2C_Type *base);
AnnaBridge 143:86740a56073b 573
AnnaBridge 143:86740a56073b 574 /*!
AnnaBridge 143:86740a56073b 575 * @brief Sends a REPEATED START on the I2C bus.
AnnaBridge 143:86740a56073b 576 *
AnnaBridge 143:86740a56073b 577 * @param base I2C peripheral base pointer
AnnaBridge 143:86740a56073b 578 * @param address 7-bit slave device address.
AnnaBridge 143:86740a56073b 579 * @param direction Master transfer directions(transmit/receive).
AnnaBridge 143:86740a56073b 580 * @retval kStatus_Success Successfully send the start signal.
AnnaBridge 143:86740a56073b 581 * @retval kStatus_I2C_Busy Current bus is busy but not occupied by current I2C master.
AnnaBridge 143:86740a56073b 582 */
AnnaBridge 143:86740a56073b 583 status_t I2C_MasterRepeatedStart(I2C_Type *base, uint8_t address, i2c_direction_t direction);
AnnaBridge 143:86740a56073b 584
AnnaBridge 143:86740a56073b 585 /*!
AnnaBridge 143:86740a56073b 586 * @brief Performs a polling send transaction on the I2C bus.
AnnaBridge 143:86740a56073b 587 *
AnnaBridge 143:86740a56073b 588 * @param base The I2C peripheral base pointer.
AnnaBridge 143:86740a56073b 589 * @param txBuff The pointer to the data to be transferred.
AnnaBridge 143:86740a56073b 590 * @param txSize The length in bytes of the data to be transferred.
AnnaBridge 143:86740a56073b 591 * @param flags Transfer control flag to decide whether need to send a stop, use kI2C_TransferDefaultFlag
AnnaBridge 143:86740a56073b 592 * to issue a stop and kI2C_TransferNoStop to not send a stop.
AnnaBridge 143:86740a56073b 593 * @retval kStatus_Success Successfully complete the data transmission.
AnnaBridge 143:86740a56073b 594 * @retval kStatus_I2C_ArbitrationLost Transfer error, arbitration lost.
AnnaBridge 143:86740a56073b 595 * @retval kStataus_I2C_Nak Transfer error, receive NAK during transfer.
AnnaBridge 143:86740a56073b 596 */
AnnaBridge 143:86740a56073b 597 status_t I2C_MasterWriteBlocking(I2C_Type *base, const uint8_t *txBuff, size_t txSize, uint32_t flags);
AnnaBridge 143:86740a56073b 598
AnnaBridge 143:86740a56073b 599 /*!
AnnaBridge 143:86740a56073b 600 * @brief Performs a polling receive transaction on the I2C bus.
AnnaBridge 143:86740a56073b 601 *
AnnaBridge 143:86740a56073b 602 * @note The I2C_MasterReadBlocking function stops the bus before reading the final byte.
AnnaBridge 143:86740a56073b 603 * Without stopping the bus prior for the final read, the bus issues another read, resulting
AnnaBridge 143:86740a56073b 604 * in garbage data being read into the data register.
AnnaBridge 143:86740a56073b 605 *
AnnaBridge 143:86740a56073b 606 * @param base I2C peripheral base pointer.
AnnaBridge 143:86740a56073b 607 * @param rxBuff The pointer to the data to store the received data.
AnnaBridge 143:86740a56073b 608 * @param rxSize The length in bytes of the data to be received.
AnnaBridge 143:86740a56073b 609 * @param flags Transfer control flag to decide whether need to send a stop, use kI2C_TransferDefaultFlag
AnnaBridge 143:86740a56073b 610 * to issue a stop and kI2C_TransferNoStop to not send a stop.
AnnaBridge 143:86740a56073b 611 * @retval kStatus_Success Successfully complete the data transmission.
AnnaBridge 143:86740a56073b 612 * @retval kStatus_I2C_Timeout Send stop signal failed, timeout.
AnnaBridge 143:86740a56073b 613 */
AnnaBridge 143:86740a56073b 614 status_t I2C_MasterReadBlocking(I2C_Type *base, uint8_t *rxBuff, size_t rxSize, uint32_t flags);
AnnaBridge 143:86740a56073b 615
AnnaBridge 143:86740a56073b 616 /*!
AnnaBridge 143:86740a56073b 617 * @brief Performs a polling send transaction on the I2C bus.
AnnaBridge 143:86740a56073b 618 *
AnnaBridge 143:86740a56073b 619 * @param base The I2C peripheral base pointer.
AnnaBridge 143:86740a56073b 620 * @param txBuff The pointer to the data to be transferred.
AnnaBridge 143:86740a56073b 621 * @param txSize The length in bytes of the data to be transferred.
AnnaBridge 143:86740a56073b 622 * @retval kStatus_Success Successfully complete the data transmission.
AnnaBridge 143:86740a56073b 623 * @retval kStatus_I2C_ArbitrationLost Transfer error, arbitration lost.
AnnaBridge 143:86740a56073b 624 * @retval kStataus_I2C_Nak Transfer error, receive NAK during transfer.
AnnaBridge 143:86740a56073b 625 */
AnnaBridge 143:86740a56073b 626 status_t I2C_SlaveWriteBlocking(I2C_Type *base, const uint8_t *txBuff, size_t txSize);
AnnaBridge 143:86740a56073b 627
AnnaBridge 143:86740a56073b 628 /*!
AnnaBridge 143:86740a56073b 629 * @brief Performs a polling receive transaction on the I2C bus.
AnnaBridge 143:86740a56073b 630 *
AnnaBridge 143:86740a56073b 631 * @param base I2C peripheral base pointer.
AnnaBridge 143:86740a56073b 632 * @param rxBuff The pointer to the data to store the received data.
AnnaBridge 143:86740a56073b 633 * @param rxSize The length in bytes of the data to be received.
AnnaBridge 143:86740a56073b 634 */
AnnaBridge 143:86740a56073b 635 void I2C_SlaveReadBlocking(I2C_Type *base, uint8_t *rxBuff, size_t rxSize);
AnnaBridge 143:86740a56073b 636
AnnaBridge 143:86740a56073b 637 /*!
AnnaBridge 143:86740a56073b 638 * @brief Performs a master polling transfer on the I2C bus.
AnnaBridge 143:86740a56073b 639 *
AnnaBridge 143:86740a56073b 640 * @note The API does not return until the transfer succeeds or fails due
AnnaBridge 143:86740a56073b 641 * to arbitration lost or receiving a NAK.
AnnaBridge 143:86740a56073b 642 *
AnnaBridge 143:86740a56073b 643 * @param base I2C peripheral base address.
AnnaBridge 143:86740a56073b 644 * @param xfer Pointer to the transfer structure.
AnnaBridge 143:86740a56073b 645 * @retval kStatus_Success Successfully complete the data transmission.
AnnaBridge 143:86740a56073b 646 * @retval kStatus_I2C_Busy Previous transmission still not finished.
AnnaBridge 143:86740a56073b 647 * @retval kStatus_I2C_Timeout Transfer error, wait signal timeout.
AnnaBridge 143:86740a56073b 648 * @retval kStatus_I2C_ArbitrationLost Transfer error, arbitration lost.
AnnaBridge 143:86740a56073b 649 * @retval kStataus_I2C_Nak Transfer error, receive NAK during transfer.
AnnaBridge 143:86740a56073b 650 */
AnnaBridge 143:86740a56073b 651 status_t I2C_MasterTransferBlocking(I2C_Type *base, i2c_master_transfer_t *xfer);
AnnaBridge 143:86740a56073b 652
AnnaBridge 143:86740a56073b 653 /* @} */
AnnaBridge 143:86740a56073b 654
AnnaBridge 143:86740a56073b 655 /*!
AnnaBridge 143:86740a56073b 656 * @name Transactional
AnnaBridge 143:86740a56073b 657 * @{
AnnaBridge 143:86740a56073b 658 */
AnnaBridge 143:86740a56073b 659
AnnaBridge 143:86740a56073b 660 /*!
AnnaBridge 143:86740a56073b 661 * @brief Initializes the I2C handle which is used in transactional functions.
AnnaBridge 143:86740a56073b 662 *
AnnaBridge 143:86740a56073b 663 * @param base I2C base pointer.
AnnaBridge 143:86740a56073b 664 * @param handle pointer to i2c_master_handle_t structure to store the transfer state.
AnnaBridge 143:86740a56073b 665 * @param callback pointer to user callback function.
AnnaBridge 143:86740a56073b 666 * @param userData user parameter passed to the callback function.
AnnaBridge 143:86740a56073b 667 */
AnnaBridge 143:86740a56073b 668 void I2C_MasterTransferCreateHandle(I2C_Type *base,
AnnaBridge 143:86740a56073b 669 i2c_master_handle_t *handle,
AnnaBridge 143:86740a56073b 670 i2c_master_transfer_callback_t callback,
AnnaBridge 143:86740a56073b 671 void *userData);
AnnaBridge 143:86740a56073b 672
AnnaBridge 143:86740a56073b 673 /*!
AnnaBridge 143:86740a56073b 674 * @brief Performs a master interrupt non-blocking transfer on the I2C bus.
AnnaBridge 143:86740a56073b 675 *
AnnaBridge 143:86740a56073b 676 * @note Calling the API returns immediately after transfer initiates. The user needs
AnnaBridge 143:86740a56073b 677 * to call I2C_MasterGetTransferCount to poll the transfer status to check whether
AnnaBridge 143:86740a56073b 678 * the transfer is finished. If the return status is not kStatus_I2C_Busy, the transfer
AnnaBridge 143:86740a56073b 679 * is finished.
AnnaBridge 143:86740a56073b 680 *
AnnaBridge 143:86740a56073b 681 * @param base I2C base pointer.
AnnaBridge 143:86740a56073b 682 * @param handle pointer to i2c_master_handle_t structure which stores the transfer state.
AnnaBridge 143:86740a56073b 683 * @param xfer pointer to i2c_master_transfer_t structure.
AnnaBridge 143:86740a56073b 684 * @retval kStatus_Success Successfully start the data transmission.
AnnaBridge 143:86740a56073b 685 * @retval kStatus_I2C_Busy Previous transmission still not finished.
AnnaBridge 143:86740a56073b 686 * @retval kStatus_I2C_Timeout Transfer error, wait signal timeout.
AnnaBridge 143:86740a56073b 687 */
AnnaBridge 143:86740a56073b 688 status_t I2C_MasterTransferNonBlocking(I2C_Type *base, i2c_master_handle_t *handle, i2c_master_transfer_t *xfer);
AnnaBridge 143:86740a56073b 689
AnnaBridge 143:86740a56073b 690 /*!
AnnaBridge 143:86740a56073b 691 * @brief Gets the master transfer status during a interrupt non-blocking transfer.
AnnaBridge 143:86740a56073b 692 *
AnnaBridge 143:86740a56073b 693 * @param base I2C base pointer.
AnnaBridge 143:86740a56073b 694 * @param handle pointer to i2c_master_handle_t structure which stores the transfer state.
AnnaBridge 143:86740a56073b 695 * @param count Number of bytes transferred so far by the non-blocking transaction.
AnnaBridge 143:86740a56073b 696 * @retval kStatus_InvalidArgument count is Invalid.
AnnaBridge 143:86740a56073b 697 * @retval kStatus_Success Successfully return the count.
AnnaBridge 143:86740a56073b 698 */
AnnaBridge 143:86740a56073b 699 status_t I2C_MasterTransferGetCount(I2C_Type *base, i2c_master_handle_t *handle, size_t *count);
AnnaBridge 143:86740a56073b 700
AnnaBridge 143:86740a56073b 701 /*!
AnnaBridge 143:86740a56073b 702 * @brief Aborts an interrupt non-blocking transfer early.
AnnaBridge 143:86740a56073b 703 *
AnnaBridge 143:86740a56073b 704 * @note This API can be called at any time when an interrupt non-blocking transfer initiates
AnnaBridge 143:86740a56073b 705 * to abort the transfer early.
AnnaBridge 143:86740a56073b 706 *
AnnaBridge 143:86740a56073b 707 * @param base I2C base pointer.
AnnaBridge 143:86740a56073b 708 * @param handle pointer to i2c_master_handle_t structure which stores the transfer state
AnnaBridge 143:86740a56073b 709 */
AnnaBridge 143:86740a56073b 710 void I2C_MasterTransferAbort(I2C_Type *base, i2c_master_handle_t *handle);
AnnaBridge 143:86740a56073b 711
AnnaBridge 143:86740a56073b 712 /*!
AnnaBridge 143:86740a56073b 713 * @brief Master interrupt handler.
AnnaBridge 143:86740a56073b 714 *
AnnaBridge 143:86740a56073b 715 * @param base I2C base pointer.
AnnaBridge 143:86740a56073b 716 * @param i2cHandle pointer to i2c_master_handle_t structure.
AnnaBridge 143:86740a56073b 717 */
AnnaBridge 143:86740a56073b 718 void I2C_MasterTransferHandleIRQ(I2C_Type *base, void *i2cHandle);
AnnaBridge 143:86740a56073b 719
AnnaBridge 143:86740a56073b 720 /*!
AnnaBridge 143:86740a56073b 721 * @brief Initializes the I2C handle which is used in transactional functions.
AnnaBridge 143:86740a56073b 722 *
AnnaBridge 143:86740a56073b 723 * @param base I2C base pointer.
AnnaBridge 143:86740a56073b 724 * @param handle pointer to i2c_slave_handle_t structure to store the transfer state.
AnnaBridge 143:86740a56073b 725 * @param callback pointer to user callback function.
AnnaBridge 143:86740a56073b 726 * @param userData user parameter passed to the callback function.
AnnaBridge 143:86740a56073b 727 */
AnnaBridge 143:86740a56073b 728 void I2C_SlaveTransferCreateHandle(I2C_Type *base,
AnnaBridge 143:86740a56073b 729 i2c_slave_handle_t *handle,
AnnaBridge 143:86740a56073b 730 i2c_slave_transfer_callback_t callback,
AnnaBridge 143:86740a56073b 731 void *userData);
AnnaBridge 143:86740a56073b 732
AnnaBridge 143:86740a56073b 733 /*!
AnnaBridge 143:86740a56073b 734 * @brief Starts accepting slave transfers.
AnnaBridge 143:86740a56073b 735 *
AnnaBridge 143:86740a56073b 736 * Call this API after calling the I2C_SlaveInit() and I2C_SlaveTransferCreateHandle() to start processing
AnnaBridge 143:86740a56073b 737 * transactions driven by an I2C master. The slave monitors the I2C bus and passes events to the
AnnaBridge 143:86740a56073b 738 * callback that was passed into the call to I2C_SlaveTransferCreateHandle(). The callback is always invoked
AnnaBridge 143:86740a56073b 739 * from the interrupt context.
AnnaBridge 143:86740a56073b 740 *
AnnaBridge 143:86740a56073b 741 * The set of events received by the callback is customizable. To do so, set the @a eventMask parameter to
AnnaBridge 143:86740a56073b 742 * the OR'd combination of #i2c_slave_transfer_event_t enumerators for the events you wish to receive.
AnnaBridge 143:86740a56073b 743 * The #kI2C_SlaveTransmitEvent and #kLPI2C_SlaveReceiveEvent events are always enabled and do not need
AnnaBridge 143:86740a56073b 744 * to be included in the mask. Alternatively, pass 0 to get a default set of only the transmit and
AnnaBridge 143:86740a56073b 745 * receive events that are always enabled. In addition, the #kI2C_SlaveAllEvents constant is provided as
AnnaBridge 143:86740a56073b 746 * a convenient way to enable all events.
AnnaBridge 143:86740a56073b 747 *
AnnaBridge 143:86740a56073b 748 * @param base The I2C peripheral base address.
AnnaBridge 143:86740a56073b 749 * @param handle Pointer to #i2c_slave_handle_t structure which stores the transfer state.
AnnaBridge 143:86740a56073b 750 * @param eventMask Bit mask formed by OR'ing together #i2c_slave_transfer_event_t enumerators to specify
AnnaBridge 143:86740a56073b 751 * which events to send to the callback. Other accepted values are 0 to get a default set of
AnnaBridge 143:86740a56073b 752 * only the transmit and receive events, and #kI2C_SlaveAllEvents to enable all events.
AnnaBridge 143:86740a56073b 753 *
AnnaBridge 143:86740a56073b 754 * @retval #kStatus_Success Slave transfers were successfully started.
AnnaBridge 143:86740a56073b 755 * @retval #kStatus_I2C_Busy Slave transfers have already been started on this handle.
AnnaBridge 143:86740a56073b 756 */
AnnaBridge 143:86740a56073b 757 status_t I2C_SlaveTransferNonBlocking(I2C_Type *base, i2c_slave_handle_t *handle, uint32_t eventMask);
AnnaBridge 143:86740a56073b 758
AnnaBridge 143:86740a56073b 759 /*!
AnnaBridge 143:86740a56073b 760 * @brief Aborts the slave transfer.
AnnaBridge 143:86740a56073b 761 *
AnnaBridge 143:86740a56073b 762 * @note This API can be called at any time to stop slave for handling the bus events.
AnnaBridge 143:86740a56073b 763 *
AnnaBridge 143:86740a56073b 764 * @param base I2C base pointer.
AnnaBridge 143:86740a56073b 765 * @param handle pointer to i2c_slave_handle_t structure which stores the transfer state.
AnnaBridge 143:86740a56073b 766 */
AnnaBridge 143:86740a56073b 767 void I2C_SlaveTransferAbort(I2C_Type *base, i2c_slave_handle_t *handle);
AnnaBridge 143:86740a56073b 768
AnnaBridge 143:86740a56073b 769 /*!
AnnaBridge 143:86740a56073b 770 * @brief Gets the slave transfer remaining bytes during a interrupt non-blocking transfer.
AnnaBridge 143:86740a56073b 771 *
AnnaBridge 143:86740a56073b 772 * @param base I2C base pointer.
AnnaBridge 143:86740a56073b 773 * @param handle pointer to i2c_slave_handle_t structure.
AnnaBridge 143:86740a56073b 774 * @param count Number of bytes transferred so far by the non-blocking transaction.
AnnaBridge 143:86740a56073b 775 * @retval kStatus_InvalidArgument count is Invalid.
AnnaBridge 143:86740a56073b 776 * @retval kStatus_Success Successfully return the count.
AnnaBridge 143:86740a56073b 777 */
AnnaBridge 143:86740a56073b 778 status_t I2C_SlaveTransferGetCount(I2C_Type *base, i2c_slave_handle_t *handle, size_t *count);
AnnaBridge 143:86740a56073b 779
AnnaBridge 143:86740a56073b 780 /*!
AnnaBridge 143:86740a56073b 781 * @brief Slave interrupt handler.
AnnaBridge 143:86740a56073b 782 *
AnnaBridge 143:86740a56073b 783 * @param base I2C base pointer.
AnnaBridge 143:86740a56073b 784 * @param i2cHandle pointer to i2c_slave_handle_t structure which stores the transfer state
AnnaBridge 143:86740a56073b 785 */
AnnaBridge 143:86740a56073b 786 void I2C_SlaveTransferHandleIRQ(I2C_Type *base, void *i2cHandle);
AnnaBridge 143:86740a56073b 787
AnnaBridge 143:86740a56073b 788 /* @} */
AnnaBridge 143:86740a56073b 789 #if defined(__cplusplus)
AnnaBridge 143:86740a56073b 790 }
AnnaBridge 143:86740a56073b 791 #endif /*_cplusplus. */
AnnaBridge 143:86740a56073b 792 /*@}*/
AnnaBridge 143:86740a56073b 793
AnnaBridge 143:86740a56073b 794 #endif /* _FSL_I2C_H_*/