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