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 /*******************************************************************************
AnnaBridge 145:64910690c574 42 * Definitions
AnnaBridge 145:64910690c574 43 ******************************************************************************/
AnnaBridge 145:64910690c574 44
AnnaBridge 145:64910690c574 45 /*! @name Driver version */
AnnaBridge 145:64910690c574 46 /*@{*/
AnnaBridge 145:64910690c574 47 /*! @brief I2C driver version 2.0.1. */
AnnaBridge 145:64910690c574 48 #define FSL_I2C_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
AnnaBridge 145:64910690c574 49 /*@}*/
AnnaBridge 145:64910690c574 50
AnnaBridge 145:64910690c574 51 #if (defined(FSL_FEATURE_I2C_HAS_START_STOP_DETECT) && FSL_FEATURE_I2C_HAS_START_STOP_DETECT || \
AnnaBridge 145:64910690c574 52 defined(FSL_FEATURE_I2C_HAS_STOP_DETECT) && FSL_FEATURE_I2C_HAS_STOP_DETECT)
AnnaBridge 145:64910690c574 53 #define I2C_HAS_STOP_DETECT
AnnaBridge 145:64910690c574 54 #endif /* FSL_FEATURE_I2C_HAS_START_STOP_DETECT / FSL_FEATURE_I2C_HAS_STOP_DETECT */
AnnaBridge 145:64910690c574 55
AnnaBridge 145:64910690c574 56 /*! @brief I2C status return codes. */
AnnaBridge 145:64910690c574 57 enum _i2c_status
AnnaBridge 145:64910690c574 58 {
AnnaBridge 145:64910690c574 59 kStatus_I2C_Busy = MAKE_STATUS(kStatusGroup_I2C, 0), /*!< I2C is busy with current transfer. */
AnnaBridge 145:64910690c574 60 kStatus_I2C_Idle = MAKE_STATUS(kStatusGroup_I2C, 1), /*!< Bus is Idle. */
AnnaBridge 145:64910690c574 61 kStatus_I2C_Nak = MAKE_STATUS(kStatusGroup_I2C, 2), /*!< NAK received during transfer. */
AnnaBridge 145:64910690c574 62 kStatus_I2C_ArbitrationLost = MAKE_STATUS(kStatusGroup_I2C, 3), /*!< Arbitration lost during transfer. */
AnnaBridge 145:64910690c574 63 kStatus_I2C_Timeout = MAKE_STATUS(kStatusGroup_I2C, 4), /*!< Wait event timeout. */
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 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 transmit to slave. */
AnnaBridge 145:64910690c574 115 kI2C_Read = 0x1U, /*!< Master receive from 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, /*!< Transfer starts with a start signal, stops with a stop signal. */
AnnaBridge 145:64910690c574 129 kI2C_TransferNoStartFlag = 0x1U, /*!< Transfer starts without a start signal. */
AnnaBridge 145:64910690c574 130 kI2C_TransferRepeatedStartFlag = 0x2U, /*!< Transfer starts with a repeated start signal. */
AnnaBridge 145:64910690c574 131 kI2C_TransferNoStopFlag = 0x4U, /*!< 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() in order 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, /*!< Callback is requested to provide data to transmit
AnnaBridge 145:64910690c574 148 (slave-transmitter role). */
AnnaBridge 145:64910690c574 149 kI2C_SlaveReceiveEvent = 0x04U, /*!< 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, /*!< 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
AnnaBridge 145:64910690c574 157 /*! Bit mask of all available events. */
AnnaBridge 145:64910690c574 158 kI2C_SlaveAllEvents = kI2C_SlaveAddressMatchEvent | kI2C_SlaveTransmitEvent | kI2C_SlaveReceiveEvent |
AnnaBridge 145:64910690c574 159 #if defined(FSL_FEATURE_I2C_HAS_START_STOP_DETECT) && FSL_FEATURE_I2C_HAS_START_STOP_DETECT
AnnaBridge 145:64910690c574 160 kI2C_SlaveStartEvent |
AnnaBridge 145:64910690c574 161 #endif
AnnaBridge 145:64910690c574 162 kI2C_SlaveCompletionEvent,
AnnaBridge 145:64910690c574 163 } i2c_slave_transfer_event_t;
AnnaBridge 145:64910690c574 164
AnnaBridge 145:64910690c574 165 /*! @brief I2C master user configuration. */
AnnaBridge 145:64910690c574 166 typedef struct _i2c_master_config
AnnaBridge 145:64910690c574 167 {
AnnaBridge 145:64910690c574 168 bool enableMaster; /*!< Enables the I2C peripheral at initialization time. */
AnnaBridge 145:64910690c574 169 #if defined(FSL_FEATURE_I2C_HAS_HIGH_DRIVE_SELECTION) && FSL_FEATURE_I2C_HAS_HIGH_DRIVE_SELECTION
AnnaBridge 145:64910690c574 170 bool enableHighDrive; /*!< Controls the drive capability of the I2C pads. */
AnnaBridge 145:64910690c574 171 #endif
AnnaBridge 145:64910690c574 172 #if defined(FSL_FEATURE_I2C_HAS_STOP_HOLD_OFF) && FSL_FEATURE_I2C_HAS_STOP_HOLD_OFF
AnnaBridge 145:64910690c574 173 bool enableStopHold; /*!< Controls the stop hold enable. */
AnnaBridge 145:64910690c574 174 #endif
AnnaBridge 145:64910690c574 175 #if defined(FSL_FEATURE_I2C_HAS_DOUBLE_BUFFER_ENABLE) && FSL_FEATURE_I2C_HAS_DOUBLE_BUFFER_ENABLE
AnnaBridge 145:64910690c574 176 bool enableDoubleBuffering; /*!< Controls double buffer enable, notice that
AnnaBridge 145:64910690c574 177 enabling the double buffer disables the clock stretch. */
AnnaBridge 145:64910690c574 178 #endif
AnnaBridge 145:64910690c574 179 uint32_t baudRate_Bps; /*!< Baud rate configuration of I2C peripheral. */
AnnaBridge 145:64910690c574 180 uint8_t glitchFilterWidth; /*!< Controls the width of the glitch. */
AnnaBridge 145:64910690c574 181 } i2c_master_config_t;
AnnaBridge 145:64910690c574 182
AnnaBridge 145:64910690c574 183 /*! @brief I2C slave user configuration. */
AnnaBridge 145:64910690c574 184 typedef struct _i2c_slave_config
AnnaBridge 145:64910690c574 185 {
AnnaBridge 145:64910690c574 186 bool enableSlave; /*!< Enables the I2C peripheral at initialization time. */
AnnaBridge 145:64910690c574 187 bool enableGeneralCall; /*!< Enable general call addressing mode. */
AnnaBridge 145:64910690c574 188 bool enableWakeUp; /*!< Enables/disables waking up MCU from low-power mode. */
AnnaBridge 145:64910690c574 189 #if defined(FSL_FEATURE_I2C_HAS_HIGH_DRIVE_SELECTION) && FSL_FEATURE_I2C_HAS_HIGH_DRIVE_SELECTION
AnnaBridge 145:64910690c574 190 bool enableHighDrive; /*!< Controls the drive capability of the I2C pads. */
AnnaBridge 145:64910690c574 191 #endif
AnnaBridge 145:64910690c574 192 #if defined(FSL_FEATURE_I2C_HAS_DOUBLE_BUFFER_ENABLE) && FSL_FEATURE_I2C_HAS_DOUBLE_BUFFER_ENABLE
AnnaBridge 145:64910690c574 193 bool enableDoubleBuffering; /*!< Controls double buffer enable, notice that
AnnaBridge 145:64910690c574 194 enabling the double buffer disables the clock stretch. */
AnnaBridge 145:64910690c574 195 #endif
AnnaBridge 145:64910690c574 196 bool enableBaudRateCtl; /*!< Enables/disables independent slave baud rate on SCL in very fast I2C modes. */
AnnaBridge 145:64910690c574 197 uint16_t slaveAddress; /*!< Slave address configuration. */
AnnaBridge 145:64910690c574 198 uint16_t upperAddress; /*!< Maximum boundary slave address used in range matching mode. */
AnnaBridge 145:64910690c574 199 i2c_slave_address_mode_t addressingMode; /*!< Addressing mode configuration of i2c_slave_address_mode_config_t. */
AnnaBridge 145:64910690c574 200 } i2c_slave_config_t;
AnnaBridge 145:64910690c574 201
AnnaBridge 145:64910690c574 202 /*! @brief I2C master handle typedef. */
AnnaBridge 145:64910690c574 203 typedef struct _i2c_master_handle i2c_master_handle_t;
AnnaBridge 145:64910690c574 204
AnnaBridge 145:64910690c574 205 /*! @brief I2C master transfer callback typedef. */
AnnaBridge 145:64910690c574 206 typedef void (*i2c_master_transfer_callback_t)(I2C_Type *base,
AnnaBridge 145:64910690c574 207 i2c_master_handle_t *handle,
AnnaBridge 145:64910690c574 208 status_t status,
AnnaBridge 145:64910690c574 209 void *userData);
AnnaBridge 145:64910690c574 210
AnnaBridge 145:64910690c574 211 /*! @brief I2C slave handle typedef. */
AnnaBridge 145:64910690c574 212 typedef struct _i2c_slave_handle i2c_slave_handle_t;
AnnaBridge 145:64910690c574 213
AnnaBridge 145:64910690c574 214 /*! @brief I2C master transfer structure. */
AnnaBridge 145:64910690c574 215 typedef struct _i2c_master_transfer
AnnaBridge 145:64910690c574 216 {
AnnaBridge 145:64910690c574 217 uint32_t flags; /*!< Transfer flag which controls the transfer. */
AnnaBridge 145:64910690c574 218 uint8_t slaveAddress; /*!< 7-bit slave address. */
AnnaBridge 145:64910690c574 219 i2c_direction_t direction; /*!< Transfer direction, read or write. */
AnnaBridge 145:64910690c574 220 uint32_t subaddress; /*!< Sub address. Transferred MSB first. */
AnnaBridge 145:64910690c574 221 uint8_t subaddressSize; /*!< Size of command buffer. */
AnnaBridge 145:64910690c574 222 uint8_t *volatile data; /*!< Transfer buffer. */
AnnaBridge 145:64910690c574 223 volatile size_t dataSize; /*!< Transfer size. */
AnnaBridge 145:64910690c574 224 } i2c_master_transfer_t;
AnnaBridge 145:64910690c574 225
AnnaBridge 145:64910690c574 226 /*! @brief I2C master handle structure. */
AnnaBridge 145:64910690c574 227 struct _i2c_master_handle
AnnaBridge 145:64910690c574 228 {
AnnaBridge 145:64910690c574 229 i2c_master_transfer_t transfer; /*!< I2C master transfer copy. */
AnnaBridge 145:64910690c574 230 size_t transferSize; /*!< Total bytes to be transferred. */
AnnaBridge 145:64910690c574 231 uint8_t state; /*!< Transfer state maintained during transfer. */
AnnaBridge 145:64910690c574 232 i2c_master_transfer_callback_t completionCallback; /*!< Callback function called when transfer finished. */
AnnaBridge 145:64910690c574 233 void *userData; /*!< Callback parameter passed to callback function. */
AnnaBridge 145:64910690c574 234 };
AnnaBridge 145:64910690c574 235
AnnaBridge 145:64910690c574 236 /*! @brief I2C slave transfer structure. */
AnnaBridge 145:64910690c574 237 typedef struct _i2c_slave_transfer
AnnaBridge 145:64910690c574 238 {
AnnaBridge 145:64910690c574 239 i2c_slave_transfer_event_t event; /*!< Reason the callback is being invoked. */
AnnaBridge 145:64910690c574 240 uint8_t *volatile data; /*!< Transfer buffer. */
AnnaBridge 145:64910690c574 241 volatile size_t dataSize; /*!< Transfer size. */
AnnaBridge 145:64910690c574 242 status_t completionStatus; /*!< Success or error code describing how the transfer completed. Only applies for
AnnaBridge 145:64910690c574 243 #kI2C_SlaveCompletionEvent. */
AnnaBridge 145:64910690c574 244 size_t transferredCount; /*!< Number of bytes actually transferred since start or last repeated start. */
AnnaBridge 145:64910690c574 245 } i2c_slave_transfer_t;
AnnaBridge 145:64910690c574 246
AnnaBridge 145:64910690c574 247 /*! @brief I2C slave transfer callback typedef. */
AnnaBridge 145:64910690c574 248 typedef void (*i2c_slave_transfer_callback_t)(I2C_Type *base, i2c_slave_transfer_t *xfer, void *userData);
AnnaBridge 145:64910690c574 249
AnnaBridge 145:64910690c574 250 /*! @brief I2C slave handle structure. */
AnnaBridge 145:64910690c574 251 struct _i2c_slave_handle
AnnaBridge 145:64910690c574 252 {
AnnaBridge 145:64910690c574 253 bool isBusy; /*!< Whether transfer is busy. */
AnnaBridge 145:64910690c574 254 i2c_slave_transfer_t transfer; /*!< I2C slave transfer copy. */
AnnaBridge 145:64910690c574 255 uint32_t eventMask; /*!< Mask of enabled events. */
AnnaBridge 145:64910690c574 256 i2c_slave_transfer_callback_t callback; /*!< Callback function called at transfer event. */
AnnaBridge 145:64910690c574 257 void *userData; /*!< Callback parameter passed to callback. */
AnnaBridge 145:64910690c574 258 };
AnnaBridge 145:64910690c574 259
AnnaBridge 145:64910690c574 260 /*******************************************************************************
AnnaBridge 145:64910690c574 261 * API
AnnaBridge 145:64910690c574 262 ******************************************************************************/
AnnaBridge 145:64910690c574 263
AnnaBridge 145:64910690c574 264 #if defined(__cplusplus)
AnnaBridge 145:64910690c574 265 extern "C" {
AnnaBridge 145:64910690c574 266 #endif /*_cplusplus. */
AnnaBridge 145:64910690c574 267
AnnaBridge 145:64910690c574 268 /*!
AnnaBridge 145:64910690c574 269 * @name Initialization and deinitialization
AnnaBridge 145:64910690c574 270 * @{
AnnaBridge 145:64910690c574 271 */
AnnaBridge 145:64910690c574 272
AnnaBridge 145:64910690c574 273 /*!
AnnaBridge 145:64910690c574 274 * @brief Initializes the I2C peripheral. Call this API to ungate the I2C clock
AnnaBridge 145:64910690c574 275 * and configure the I2C with master configuration.
AnnaBridge 145:64910690c574 276 *
AnnaBridge 145:64910690c574 277 * @note This API should be called at the beginning of the application to use
AnnaBridge 145:64910690c574 278 * the I2C driver, or any operation to the I2C module may cause a hard fault
AnnaBridge 145:64910690c574 279 * because clock is not enabled. The configuration structure can be filled by user
AnnaBridge 145:64910690c574 280 * from scratch, or be set with default values by I2C_MasterGetDefaultConfig().
AnnaBridge 145:64910690c574 281 * After calling this API, the master is ready to transfer.
AnnaBridge 145:64910690c574 282 * Example:
AnnaBridge 145:64910690c574 283 * @code
AnnaBridge 145:64910690c574 284 * i2c_master_config_t config = {
AnnaBridge 145:64910690c574 285 * .enableMaster = true,
AnnaBridge 145:64910690c574 286 * .enableStopHold = false,
AnnaBridge 145:64910690c574 287 * .highDrive = false,
AnnaBridge 145:64910690c574 288 * .baudRate_Bps = 100000,
AnnaBridge 145:64910690c574 289 * .glitchFilterWidth = 0
AnnaBridge 145:64910690c574 290 * };
AnnaBridge 145:64910690c574 291 * I2C_MasterInit(I2C0, &config, 12000000U);
AnnaBridge 145:64910690c574 292 * @endcode
AnnaBridge 145:64910690c574 293 *
AnnaBridge 145:64910690c574 294 * @param base I2C base pointer
AnnaBridge 145:64910690c574 295 * @param masterConfig pointer to master configuration structure
AnnaBridge 145:64910690c574 296 * @param srcClock_Hz I2C peripheral clock frequency in Hz
AnnaBridge 145:64910690c574 297 */
AnnaBridge 145:64910690c574 298 void I2C_MasterInit(I2C_Type *base, const i2c_master_config_t *masterConfig, uint32_t srcClock_Hz);
AnnaBridge 145:64910690c574 299
AnnaBridge 145:64910690c574 300 /*!
AnnaBridge 145:64910690c574 301 * @brief Initializes the I2C peripheral. Call this API to ungate the I2C clock
AnnaBridge 145:64910690c574 302 * and initializes the I2C with slave configuration.
AnnaBridge 145:64910690c574 303 *
AnnaBridge 145:64910690c574 304 * @note This API should be called at the beginning of the application to use
AnnaBridge 145:64910690c574 305 * the I2C driver, or any operation to the I2C module can cause a hard fault
AnnaBridge 145:64910690c574 306 * because the clock is not enabled. The configuration structure can partly be set
AnnaBridge 145:64910690c574 307 * with default values by I2C_SlaveGetDefaultConfig(), or can be filled by the user.
AnnaBridge 145:64910690c574 308 * Example
AnnaBridge 145:64910690c574 309 * @code
AnnaBridge 145:64910690c574 310 * i2c_slave_config_t config = {
AnnaBridge 145:64910690c574 311 * .enableSlave = true,
AnnaBridge 145:64910690c574 312 * .enableGeneralCall = false,
AnnaBridge 145:64910690c574 313 * .addressingMode = kI2C_Address7bit,
AnnaBridge 145:64910690c574 314 * .slaveAddress = 0x1DU,
AnnaBridge 145:64910690c574 315 * .enableWakeUp = false,
AnnaBridge 145:64910690c574 316 * .enablehighDrive = false,
AnnaBridge 145:64910690c574 317 * .enableBaudRateCtl = false
AnnaBridge 145:64910690c574 318 * };
AnnaBridge 145:64910690c574 319 * I2C_SlaveInit(I2C0, &config);
AnnaBridge 145:64910690c574 320 * @endcode
AnnaBridge 145:64910690c574 321 *
AnnaBridge 145:64910690c574 322 * @param base I2C base pointer
AnnaBridge 145:64910690c574 323 * @param slaveConfig pointer to slave configuration structure
AnnaBridge 145:64910690c574 324 */
AnnaBridge 145:64910690c574 325 void I2C_SlaveInit(I2C_Type *base, const i2c_slave_config_t *slaveConfig);
AnnaBridge 145:64910690c574 326
AnnaBridge 145:64910690c574 327 /*!
AnnaBridge 145:64910690c574 328 * @brief De-initializes the I2C master peripheral. Call this API to gate the I2C clock.
AnnaBridge 145:64910690c574 329 * The I2C master module can't work unless the I2C_MasterInit is called.
AnnaBridge 145:64910690c574 330 * @param base I2C base pointer
AnnaBridge 145:64910690c574 331 */
AnnaBridge 145:64910690c574 332 void I2C_MasterDeinit(I2C_Type *base);
AnnaBridge 145:64910690c574 333
AnnaBridge 145:64910690c574 334 /*!
AnnaBridge 145:64910690c574 335 * @brief De-initializes the I2C slave peripheral. Calling this API gates the I2C clock.
AnnaBridge 145:64910690c574 336 * The I2C slave module can't work unless the I2C_SlaveInit is called to enable the clock.
AnnaBridge 145:64910690c574 337 * @param base I2C base pointer
AnnaBridge 145:64910690c574 338 */
AnnaBridge 145:64910690c574 339 void I2C_SlaveDeinit(I2C_Type *base);
AnnaBridge 145:64910690c574 340
AnnaBridge 145:64910690c574 341 /*!
AnnaBridge 145:64910690c574 342 * @brief Sets the I2C master configuration structure to default values.
AnnaBridge 145:64910690c574 343 *
AnnaBridge 145:64910690c574 344 * The purpose of this API is to get the configuration structure initialized for use in the I2C_MasterConfigure().
AnnaBridge 145:64910690c574 345 * Use the initialized structure unchanged in I2C_MasterConfigure(), or modify some fields of
AnnaBridge 145:64910690c574 346 * the structure before calling I2C_MasterConfigure().
AnnaBridge 145:64910690c574 347 * Example:
AnnaBridge 145:64910690c574 348 * @code
AnnaBridge 145:64910690c574 349 * i2c_master_config_t config;
AnnaBridge 145:64910690c574 350 * I2C_MasterGetDefaultConfig(&config);
AnnaBridge 145:64910690c574 351 * @endcode
AnnaBridge 145:64910690c574 352 * @param masterConfig Pointer to the master configuration structure.
AnnaBridge 145:64910690c574 353 */
AnnaBridge 145:64910690c574 354 void I2C_MasterGetDefaultConfig(i2c_master_config_t *masterConfig);
AnnaBridge 145:64910690c574 355
AnnaBridge 145:64910690c574 356 /*!
AnnaBridge 145:64910690c574 357 * @brief Sets the I2C slave configuration structure to default values.
AnnaBridge 145:64910690c574 358 *
AnnaBridge 145:64910690c574 359 * The purpose of this API is to get the configuration structure initialized for use in I2C_SlaveConfigure().
AnnaBridge 145:64910690c574 360 * Modify fields of the structure before calling the I2C_SlaveConfigure().
AnnaBridge 145:64910690c574 361 * Example:
AnnaBridge 145:64910690c574 362 * @code
AnnaBridge 145:64910690c574 363 * i2c_slave_config_t config;
AnnaBridge 145:64910690c574 364 * I2C_SlaveGetDefaultConfig(&config);
AnnaBridge 145:64910690c574 365 * @endcode
AnnaBridge 145:64910690c574 366 * @param slaveConfig Pointer to the slave configuration structure.
AnnaBridge 145:64910690c574 367 */
AnnaBridge 145:64910690c574 368 void I2C_SlaveGetDefaultConfig(i2c_slave_config_t *slaveConfig);
AnnaBridge 145:64910690c574 369
AnnaBridge 145:64910690c574 370 /*!
AnnaBridge 145:64910690c574 371 * @brief Enables or disabless the I2C peripheral operation.
AnnaBridge 145:64910690c574 372 *
AnnaBridge 145:64910690c574 373 * @param base I2C base pointer
AnnaBridge 145:64910690c574 374 * @param enable pass true to enable module, false to disable module
AnnaBridge 145:64910690c574 375 */
AnnaBridge 145:64910690c574 376 static inline void I2C_Enable(I2C_Type *base, bool enable)
AnnaBridge 145:64910690c574 377 {
AnnaBridge 145:64910690c574 378 if (enable)
AnnaBridge 145:64910690c574 379 {
AnnaBridge 145:64910690c574 380 base->C1 |= I2C_C1_IICEN_MASK;
AnnaBridge 145:64910690c574 381 }
AnnaBridge 145:64910690c574 382 else
AnnaBridge 145:64910690c574 383 {
AnnaBridge 145:64910690c574 384 base->C1 &= ~I2C_C1_IICEN_MASK;
AnnaBridge 145:64910690c574 385 }
AnnaBridge 145:64910690c574 386 }
AnnaBridge 145:64910690c574 387
AnnaBridge 145:64910690c574 388 /* @} */
AnnaBridge 145:64910690c574 389
AnnaBridge 145:64910690c574 390 /*!
AnnaBridge 145:64910690c574 391 * @name Status
AnnaBridge 145:64910690c574 392 * @{
AnnaBridge 145:64910690c574 393 */
AnnaBridge 145:64910690c574 394
AnnaBridge 145:64910690c574 395 /*!
AnnaBridge 145:64910690c574 396 * @brief Gets the I2C status flags.
AnnaBridge 145:64910690c574 397 *
AnnaBridge 145:64910690c574 398 * @param base I2C base pointer
AnnaBridge 145:64910690c574 399 * @return status flag, use status flag to AND #_i2c_flags to get the related status.
AnnaBridge 145:64910690c574 400 */
AnnaBridge 145:64910690c574 401 uint32_t I2C_MasterGetStatusFlags(I2C_Type *base);
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 static inline uint32_t I2C_SlaveGetStatusFlags(I2C_Type *base)
AnnaBridge 145:64910690c574 410 {
AnnaBridge 145:64910690c574 411 return I2C_MasterGetStatusFlags(base);
AnnaBridge 145:64910690c574 412 }
AnnaBridge 145:64910690c574 413
AnnaBridge 145:64910690c574 414 /*!
AnnaBridge 145:64910690c574 415 * @brief Clears the I2C status flag state.
AnnaBridge 145:64910690c574 416 *
AnnaBridge 145:64910690c574 417 * The following status register flags can be cleared: kI2C_ArbitrationLostFlag and kI2C_IntPendingFlag
AnnaBridge 145:64910690c574 418 *
AnnaBridge 145:64910690c574 419 * @param base I2C base pointer
AnnaBridge 145:64910690c574 420 * @param statusMask The status flag mask, defined in type i2c_status_flag_t.
AnnaBridge 145:64910690c574 421 * The parameter can be any combination of the following values:
AnnaBridge 145:64910690c574 422 * @arg kI2C_StartDetectFlag (if available)
AnnaBridge 145:64910690c574 423 * @arg kI2C_StopDetectFlag (if available)
AnnaBridge 145:64910690c574 424 * @arg kI2C_ArbitrationLostFlag
AnnaBridge 145:64910690c574 425 * @arg kI2C_IntPendingFlagFlag
AnnaBridge 145:64910690c574 426 */
AnnaBridge 145:64910690c574 427 static inline void I2C_MasterClearStatusFlags(I2C_Type *base, uint32_t statusMask)
AnnaBridge 145:64910690c574 428 {
AnnaBridge 145:64910690c574 429 /* Must clear the STARTF / STOPF bits prior to clearing IICIF */
AnnaBridge 145:64910690c574 430 #if defined(FSL_FEATURE_I2C_HAS_START_STOP_DETECT) && FSL_FEATURE_I2C_HAS_START_STOP_DETECT
AnnaBridge 145:64910690c574 431 if (statusMask & kI2C_StartDetectFlag)
AnnaBridge 145:64910690c574 432 {
AnnaBridge 145:64910690c574 433 /* Shift the odd-ball flags back into place. */
AnnaBridge 145:64910690c574 434 base->FLT |= (uint8_t)(statusMask >> 8U);
AnnaBridge 145:64910690c574 435 }
AnnaBridge 145:64910690c574 436 #endif
AnnaBridge 145:64910690c574 437
AnnaBridge 145:64910690c574 438 #ifdef I2C_HAS_STOP_DETECT
AnnaBridge 145:64910690c574 439 if (statusMask & kI2C_StopDetectFlag)
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 base->S = (uint8_t)statusMask;
AnnaBridge 145:64910690c574 447 }
AnnaBridge 145:64910690c574 448
AnnaBridge 145:64910690c574 449 /*!
AnnaBridge 145:64910690c574 450 * @brief Clears the I2C status flag state.
AnnaBridge 145:64910690c574 451 *
AnnaBridge 145:64910690c574 452 * The following status register flags can be cleared: kI2C_ArbitrationLostFlag and kI2C_IntPendingFlag
AnnaBridge 145:64910690c574 453 *
AnnaBridge 145:64910690c574 454 * @param base I2C base pointer
AnnaBridge 145:64910690c574 455 * @param statusMask The status flag mask, defined in type i2c_status_flag_t.
AnnaBridge 145:64910690c574 456 * The parameter can be any combination of the following values:
AnnaBridge 145:64910690c574 457 * @arg kI2C_StartDetectFlag (if available)
AnnaBridge 145:64910690c574 458 * @arg kI2C_StopDetectFlag (if available)
AnnaBridge 145:64910690c574 459 * @arg kI2C_ArbitrationLostFlag
AnnaBridge 145:64910690c574 460 * @arg kI2C_IntPendingFlagFlag
AnnaBridge 145:64910690c574 461 */
AnnaBridge 145:64910690c574 462 static inline void I2C_SlaveClearStatusFlags(I2C_Type *base, uint32_t statusMask)
AnnaBridge 145:64910690c574 463 {
AnnaBridge 145:64910690c574 464 I2C_MasterClearStatusFlags(base, statusMask);
AnnaBridge 145:64910690c574 465 }
AnnaBridge 145:64910690c574 466
AnnaBridge 145:64910690c574 467 /* @} */
AnnaBridge 145:64910690c574 468
AnnaBridge 145:64910690c574 469 /*!
AnnaBridge 145:64910690c574 470 * @name Interrupts
AnnaBridge 145:64910690c574 471 * @{
AnnaBridge 145:64910690c574 472 */
AnnaBridge 145:64910690c574 473
AnnaBridge 145:64910690c574 474 /*!
AnnaBridge 145:64910690c574 475 * @brief Enables I2C interrupt requests.
AnnaBridge 145:64910690c574 476 *
AnnaBridge 145:64910690c574 477 * @param base I2C base pointer
AnnaBridge 145:64910690c574 478 * @param mask interrupt source
AnnaBridge 145:64910690c574 479 * The parameter can be combination of the following source if defined:
AnnaBridge 145:64910690c574 480 * @arg kI2C_GlobalInterruptEnable
AnnaBridge 145:64910690c574 481 * @arg kI2C_StopDetectInterruptEnable/kI2C_StartDetectInterruptEnable
AnnaBridge 145:64910690c574 482 * @arg kI2C_SdaTimeoutInterruptEnable
AnnaBridge 145:64910690c574 483 */
AnnaBridge 145:64910690c574 484 void I2C_EnableInterrupts(I2C_Type *base, uint32_t mask);
AnnaBridge 145:64910690c574 485
AnnaBridge 145:64910690c574 486 /*!
AnnaBridge 145:64910690c574 487 * @brief Disables I2C interrupt requests.
AnnaBridge 145:64910690c574 488 *
AnnaBridge 145:64910690c574 489 * @param base I2C base pointer
AnnaBridge 145:64910690c574 490 * @param mask interrupt source
AnnaBridge 145:64910690c574 491 * The parameter can be combination of the following source if defined:
AnnaBridge 145:64910690c574 492 * @arg kI2C_GlobalInterruptEnable
AnnaBridge 145:64910690c574 493 * @arg kI2C_StopDetectInterruptEnable/kI2C_StartDetectInterruptEnable
AnnaBridge 145:64910690c574 494 * @arg kI2C_SdaTimeoutInterruptEnable
AnnaBridge 145:64910690c574 495 */
AnnaBridge 145:64910690c574 496 void I2C_DisableInterrupts(I2C_Type *base, uint32_t mask);
AnnaBridge 145:64910690c574 497
AnnaBridge 145:64910690c574 498 /*!
AnnaBridge 145:64910690c574 499 * @name DMA Control
AnnaBridge 145:64910690c574 500 * @{
AnnaBridge 145:64910690c574 501 */
AnnaBridge 145:64910690c574 502 #if defined(FSL_FEATURE_I2C_HAS_DMA_SUPPORT) && FSL_FEATURE_I2C_HAS_DMA_SUPPORT
AnnaBridge 145:64910690c574 503 /*!
AnnaBridge 145:64910690c574 504 * @brief Enables/disables the I2C DMA interrupt.
AnnaBridge 145:64910690c574 505 *
AnnaBridge 145:64910690c574 506 * @param base I2C base pointer
AnnaBridge 145:64910690c574 507 * @param enable true to enable, false to disable
AnnaBridge 145:64910690c574 508 */
AnnaBridge 145:64910690c574 509 static inline void I2C_EnableDMA(I2C_Type *base, bool enable)
AnnaBridge 145:64910690c574 510 {
AnnaBridge 145:64910690c574 511 if (enable)
AnnaBridge 145:64910690c574 512 {
AnnaBridge 145:64910690c574 513 base->C1 |= I2C_C1_DMAEN_MASK;
AnnaBridge 145:64910690c574 514 }
AnnaBridge 145:64910690c574 515 else
AnnaBridge 145:64910690c574 516 {
AnnaBridge 145:64910690c574 517 base->C1 &= ~I2C_C1_DMAEN_MASK;
AnnaBridge 145:64910690c574 518 }
AnnaBridge 145:64910690c574 519 }
AnnaBridge 145:64910690c574 520
AnnaBridge 145:64910690c574 521 #endif /* FSL_FEATURE_I2C_HAS_DMA_SUPPORT */
AnnaBridge 145:64910690c574 522
AnnaBridge 145:64910690c574 523 /*!
AnnaBridge 145:64910690c574 524 * @brief Gets the I2C tx/rx data register address. This API is used to provide a transfer address
AnnaBridge 145:64910690c574 525 * for I2C DMA transfer configuration.
AnnaBridge 145:64910690c574 526 *
AnnaBridge 145:64910690c574 527 * @param base I2C base pointer
AnnaBridge 145:64910690c574 528 * @return data register address
AnnaBridge 145:64910690c574 529 */
AnnaBridge 145:64910690c574 530 static inline uint32_t I2C_GetDataRegAddr(I2C_Type *base)
AnnaBridge 145:64910690c574 531 {
AnnaBridge 145:64910690c574 532 return (uint32_t)(&(base->D));
AnnaBridge 145:64910690c574 533 }
AnnaBridge 145:64910690c574 534
AnnaBridge 145:64910690c574 535 /* @} */
AnnaBridge 145:64910690c574 536 /*!
AnnaBridge 145:64910690c574 537 * @name Bus Operations
AnnaBridge 145:64910690c574 538 * @{
AnnaBridge 145:64910690c574 539 */
AnnaBridge 145:64910690c574 540
AnnaBridge 145:64910690c574 541 /*!
AnnaBridge 145:64910690c574 542 * @brief Sets the I2C master transfer baud rate.
AnnaBridge 145:64910690c574 543 *
AnnaBridge 145:64910690c574 544 * @param base I2C base pointer
AnnaBridge 145:64910690c574 545 * @param baudRate_Bps the baud rate value in bps
AnnaBridge 145:64910690c574 546 * @param srcClock_Hz Source clock
AnnaBridge 145:64910690c574 547 */
AnnaBridge 145:64910690c574 548 void I2C_MasterSetBaudRate(I2C_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz);
AnnaBridge 145:64910690c574 549
AnnaBridge 145:64910690c574 550 /*!
AnnaBridge 145:64910690c574 551 * @brief Sends a START on the I2C bus.
AnnaBridge 145:64910690c574 552 *
AnnaBridge 145:64910690c574 553 * This function is used to initiate a new master mode transfer by sending the START signal.
AnnaBridge 145:64910690c574 554 * The slave address is sent following the I2C START signal.
AnnaBridge 145:64910690c574 555 *
AnnaBridge 145:64910690c574 556 * @param base I2C peripheral base pointer
AnnaBridge 145:64910690c574 557 * @param address 7-bit slave device address.
AnnaBridge 145:64910690c574 558 * @param direction Master transfer directions(transmit/receive).
AnnaBridge 145:64910690c574 559 * @retval kStatus_Success Successfully send the start signal.
AnnaBridge 145:64910690c574 560 * @retval kStatus_I2C_Busy Current bus is busy.
AnnaBridge 145:64910690c574 561 */
AnnaBridge 145:64910690c574 562 status_t I2C_MasterStart(I2C_Type *base, uint8_t address, i2c_direction_t direction);
AnnaBridge 145:64910690c574 563
AnnaBridge 145:64910690c574 564 /*!
AnnaBridge 145:64910690c574 565 * @brief Sends a STOP signal on the I2C bus.
AnnaBridge 145:64910690c574 566 *
AnnaBridge 145:64910690c574 567 * @retval kStatus_Success Successfully send the stop signal.
AnnaBridge 145:64910690c574 568 * @retval kStatus_I2C_Timeout Send stop signal failed, timeout.
AnnaBridge 145:64910690c574 569 */
AnnaBridge 145:64910690c574 570 status_t I2C_MasterStop(I2C_Type *base);
AnnaBridge 145:64910690c574 571
AnnaBridge 145:64910690c574 572 /*!
AnnaBridge 145:64910690c574 573 * @brief Sends a REPEATED START on the I2C bus.
AnnaBridge 145:64910690c574 574 *
AnnaBridge 145:64910690c574 575 * @param base I2C peripheral base pointer
AnnaBridge 145:64910690c574 576 * @param address 7-bit slave device address.
AnnaBridge 145:64910690c574 577 * @param direction Master transfer directions(transmit/receive).
AnnaBridge 145:64910690c574 578 * @retval kStatus_Success Successfully send the start signal.
AnnaBridge 145:64910690c574 579 * @retval kStatus_I2C_Busy Current bus is busy but not occupied by current I2C master.
AnnaBridge 145:64910690c574 580 */
AnnaBridge 145:64910690c574 581 status_t I2C_MasterRepeatedStart(I2C_Type *base, uint8_t address, i2c_direction_t direction);
AnnaBridge 145:64910690c574 582
AnnaBridge 145:64910690c574 583 /*!
AnnaBridge 145:64910690c574 584 * @brief Performs a polling send transaction on the I2C bus without a STOP signal.
AnnaBridge 145:64910690c574 585 *
AnnaBridge 145:64910690c574 586 * @param base The I2C peripheral base pointer.
AnnaBridge 145:64910690c574 587 * @param txBuff The pointer to the data to be transferred.
AnnaBridge 145:64910690c574 588 * @param txSize The length in bytes of the data to be transferred.
AnnaBridge 145:64910690c574 589 * @retval kStatus_Success Successfully complete the data transmission.
AnnaBridge 145:64910690c574 590 * @retval kStatus_I2C_ArbitrationLost Transfer error, arbitration lost.
AnnaBridge 145:64910690c574 591 * @retval kStataus_I2C_Nak Transfer error, receive NAK during transfer.
AnnaBridge 145:64910690c574 592 */
AnnaBridge 145:64910690c574 593 status_t I2C_MasterWriteBlocking(I2C_Type *base, const uint8_t *txBuff, size_t txSize);
AnnaBridge 145:64910690c574 594
AnnaBridge 145:64910690c574 595 /*!
AnnaBridge 145:64910690c574 596 * @brief Performs a polling receive transaction on the I2C bus with a STOP signal.
AnnaBridge 145:64910690c574 597 *
AnnaBridge 145:64910690c574 598 * @note The I2C_MasterReadBlocking function stops the bus before reading the final byte.
AnnaBridge 145:64910690c574 599 * Without stopping the bus prior for the final read, the bus issues another read, resulting
AnnaBridge 145:64910690c574 600 * in garbage data being read into the data register.
AnnaBridge 145:64910690c574 601 *
AnnaBridge 145:64910690c574 602 * @param base I2C peripheral base pointer.
AnnaBridge 145:64910690c574 603 * @param rxBuff The pointer to the data to store the received data.
AnnaBridge 145:64910690c574 604 * @param rxSize The length in bytes of the data to be received.
AnnaBridge 145:64910690c574 605 * @retval kStatus_Success Successfully complete the data transmission.
AnnaBridge 145:64910690c574 606 * @retval kStatus_I2C_Timeout Send stop signal failed, timeout.
AnnaBridge 145:64910690c574 607 */
AnnaBridge 145:64910690c574 608 status_t I2C_MasterReadBlocking(I2C_Type *base, uint8_t *rxBuff, size_t rxSize);
AnnaBridge 145:64910690c574 609
AnnaBridge 145:64910690c574 610 /*!
AnnaBridge 145:64910690c574 611 * @brief Performs a polling send transaction on the I2C bus.
AnnaBridge 145:64910690c574 612 *
AnnaBridge 145:64910690c574 613 * @param base The I2C peripheral base pointer.
AnnaBridge 145:64910690c574 614 * @param txBuff The pointer to the data to be transferred.
AnnaBridge 145:64910690c574 615 * @param txSize The length in bytes of the data to be transferred.
AnnaBridge 145:64910690c574 616 * @retval kStatus_Success Successfully complete the data transmission.
AnnaBridge 145:64910690c574 617 * @retval kStatus_I2C_ArbitrationLost Transfer error, arbitration lost.
AnnaBridge 145:64910690c574 618 * @retval kStataus_I2C_Nak Transfer error, receive NAK during transfer.
AnnaBridge 145:64910690c574 619 */
AnnaBridge 145:64910690c574 620 status_t I2C_SlaveWriteBlocking(I2C_Type *base, const uint8_t *txBuff, size_t txSize);
AnnaBridge 145:64910690c574 621
AnnaBridge 145:64910690c574 622 /*!
AnnaBridge 145:64910690c574 623 * @brief Performs a polling receive transaction on the I2C bus.
AnnaBridge 145:64910690c574 624 *
AnnaBridge 145:64910690c574 625 * @param base I2C peripheral base pointer.
AnnaBridge 145:64910690c574 626 * @param rxBuff The pointer to the data to store the received data.
AnnaBridge 145:64910690c574 627 * @param rxSize The length in bytes of the data to be received.
AnnaBridge 145:64910690c574 628 */
AnnaBridge 145:64910690c574 629 void I2C_SlaveReadBlocking(I2C_Type *base, uint8_t *rxBuff, size_t rxSize);
AnnaBridge 145:64910690c574 630
AnnaBridge 145:64910690c574 631 /*!
AnnaBridge 145:64910690c574 632 * @brief Performs a master polling transfer on the I2C bus.
AnnaBridge 145:64910690c574 633 *
AnnaBridge 145:64910690c574 634 * @note The API does not return until the transfer succeeds or fails due
AnnaBridge 145:64910690c574 635 * to arbitration lost or receiving a NAK.
AnnaBridge 145:64910690c574 636 *
AnnaBridge 145:64910690c574 637 * @param base I2C peripheral base address.
AnnaBridge 145:64910690c574 638 * @param xfer Pointer to the transfer structure.
AnnaBridge 145:64910690c574 639 * @retval kStatus_Success Successfully complete the data transmission.
AnnaBridge 145:64910690c574 640 * @retval kStatus_I2C_Busy Previous transmission still not finished.
AnnaBridge 145:64910690c574 641 * @retval kStatus_I2C_Timeout Transfer error, wait signal timeout.
AnnaBridge 145:64910690c574 642 * @retval kStatus_I2C_ArbitrationLost Transfer error, arbitration lost.
AnnaBridge 145:64910690c574 643 * @retval kStataus_I2C_Nak Transfer error, receive NAK during transfer.
AnnaBridge 145:64910690c574 644 */
AnnaBridge 145:64910690c574 645 status_t I2C_MasterTransferBlocking(I2C_Type *base, i2c_master_transfer_t *xfer);
AnnaBridge 145:64910690c574 646
AnnaBridge 145:64910690c574 647 /* @} */
AnnaBridge 145:64910690c574 648
AnnaBridge 145:64910690c574 649 /*!
AnnaBridge 145:64910690c574 650 * @name Transactional
AnnaBridge 145:64910690c574 651 * @{
AnnaBridge 145:64910690c574 652 */
AnnaBridge 145:64910690c574 653
AnnaBridge 145:64910690c574 654 /*!
AnnaBridge 145:64910690c574 655 * @brief Initializes the I2C handle which is used in transactional functions.
AnnaBridge 145:64910690c574 656 *
AnnaBridge 145:64910690c574 657 * @param base I2C base pointer.
AnnaBridge 145:64910690c574 658 * @param handle pointer to i2c_master_handle_t structure to store the transfer state.
AnnaBridge 145:64910690c574 659 * @param callback pointer to user callback function.
AnnaBridge 145:64910690c574 660 * @param userData user parameter passed to the callback function.
AnnaBridge 145:64910690c574 661 */
AnnaBridge 145:64910690c574 662 void I2C_MasterTransferCreateHandle(I2C_Type *base,
AnnaBridge 145:64910690c574 663 i2c_master_handle_t *handle,
AnnaBridge 145:64910690c574 664 i2c_master_transfer_callback_t callback,
AnnaBridge 145:64910690c574 665 void *userData);
AnnaBridge 145:64910690c574 666
AnnaBridge 145:64910690c574 667 /*!
AnnaBridge 145:64910690c574 668 * @brief Performs a master interrupt non-blocking transfer on the I2C bus.
AnnaBridge 145:64910690c574 669 *
AnnaBridge 145:64910690c574 670 * @note Calling the API returns immediately after transfer initiates. The user needs
AnnaBridge 145:64910690c574 671 * to call I2C_MasterGetTransferCount to poll the transfer status to check whether
AnnaBridge 145:64910690c574 672 * the transfer is finished. If the return status is not kStatus_I2C_Busy, the transfer
AnnaBridge 145:64910690c574 673 * is finished.
AnnaBridge 145:64910690c574 674 *
AnnaBridge 145:64910690c574 675 * @param base I2C base pointer.
AnnaBridge 145:64910690c574 676 * @param handle pointer to i2c_master_handle_t structure which stores the transfer state.
AnnaBridge 145:64910690c574 677 * @param xfer pointer to i2c_master_transfer_t structure.
AnnaBridge 145:64910690c574 678 * @retval kStatus_Success Successfully start the data transmission.
AnnaBridge 145:64910690c574 679 * @retval kStatus_I2C_Busy Previous transmission still not finished.
AnnaBridge 145:64910690c574 680 * @retval kStatus_I2C_Timeout Transfer error, wait signal timeout.
AnnaBridge 145:64910690c574 681 */
AnnaBridge 145:64910690c574 682 status_t I2C_MasterTransferNonBlocking(I2C_Type *base, i2c_master_handle_t *handle, i2c_master_transfer_t *xfer);
AnnaBridge 145:64910690c574 683
AnnaBridge 145:64910690c574 684 /*!
AnnaBridge 145:64910690c574 685 * @brief Gets the master transfer status during a interrupt non-blocking transfer.
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 count Number of bytes transferred so far by the non-blocking transaction.
AnnaBridge 145:64910690c574 690 * @retval kStatus_InvalidArgument count is Invalid.
AnnaBridge 145:64910690c574 691 * @retval kStatus_Success Successfully return the count.
AnnaBridge 145:64910690c574 692 */
AnnaBridge 145:64910690c574 693 status_t I2C_MasterTransferGetCount(I2C_Type *base, i2c_master_handle_t *handle, size_t *count);
AnnaBridge 145:64910690c574 694
AnnaBridge 145:64910690c574 695 /*!
AnnaBridge 145:64910690c574 696 * @brief Aborts an interrupt non-blocking transfer early.
AnnaBridge 145:64910690c574 697 *
AnnaBridge 145:64910690c574 698 * @note This API can be called at any time when an interrupt non-blocking transfer initiates
AnnaBridge 145:64910690c574 699 * to abort the transfer early.
AnnaBridge 145:64910690c574 700 *
AnnaBridge 145:64910690c574 701 * @param base I2C base pointer.
AnnaBridge 145:64910690c574 702 * @param handle pointer to i2c_master_handle_t structure which stores the transfer state
AnnaBridge 145:64910690c574 703 */
AnnaBridge 145:64910690c574 704 void I2C_MasterTransferAbort(I2C_Type *base, i2c_master_handle_t *handle);
AnnaBridge 145:64910690c574 705
AnnaBridge 145:64910690c574 706 /*!
AnnaBridge 145:64910690c574 707 * @brief Master interrupt handler.
AnnaBridge 145:64910690c574 708 *
AnnaBridge 145:64910690c574 709 * @param base I2C base pointer.
AnnaBridge 145:64910690c574 710 * @param i2cHandle pointer to i2c_master_handle_t structure.
AnnaBridge 145:64910690c574 711 */
AnnaBridge 145:64910690c574 712 void I2C_MasterTransferHandleIRQ(I2C_Type *base, void *i2cHandle);
AnnaBridge 145:64910690c574 713
AnnaBridge 145:64910690c574 714 /*!
AnnaBridge 145:64910690c574 715 * @brief Initializes the I2C handle which is used in transactional functions.
AnnaBridge 145:64910690c574 716 *
AnnaBridge 145:64910690c574 717 * @param base I2C base pointer.
AnnaBridge 145:64910690c574 718 * @param handle pointer to i2c_slave_handle_t structure to store the transfer state.
AnnaBridge 145:64910690c574 719 * @param callback pointer to user callback function.
AnnaBridge 145:64910690c574 720 * @param userData user parameter passed to the callback function.
AnnaBridge 145:64910690c574 721 */
AnnaBridge 145:64910690c574 722 void I2C_SlaveTransferCreateHandle(I2C_Type *base,
AnnaBridge 145:64910690c574 723 i2c_slave_handle_t *handle,
AnnaBridge 145:64910690c574 724 i2c_slave_transfer_callback_t callback,
AnnaBridge 145:64910690c574 725 void *userData);
AnnaBridge 145:64910690c574 726
AnnaBridge 145:64910690c574 727 /*!
AnnaBridge 145:64910690c574 728 * @brief Starts accepting slave transfers.
AnnaBridge 145:64910690c574 729 *
AnnaBridge 145:64910690c574 730 * Call this API after calling the I2C_SlaveInit() and I2C_SlaveTransferCreateHandle() to start processing
AnnaBridge 145:64910690c574 731 * transactions driven by an I2C master. The slave monitors the I2C bus and passes events to the
AnnaBridge 145:64910690c574 732 * callback that was passed into the call to I2C_SlaveTransferCreateHandle(). The callback is always invoked
AnnaBridge 145:64910690c574 733 * from the interrupt context.
AnnaBridge 145:64910690c574 734 *
AnnaBridge 145:64910690c574 735 * The set of events received by the callback is customizable. To do so, set the @a eventMask parameter to
AnnaBridge 145:64910690c574 736 * the OR'd combination of #i2c_slave_transfer_event_t enumerators for the events you wish to receive.
AnnaBridge 145:64910690c574 737 * The #kI2C_SlaveTransmitEvent and #kLPI2C_SlaveReceiveEvent events are always enabled and do not need
AnnaBridge 145:64910690c574 738 * to be included in the mask. Alternatively, pass 0 to get a default set of only the transmit and
AnnaBridge 145:64910690c574 739 * receive events that are always enabled. In addition, the #kI2C_SlaveAllEvents constant is provided as
AnnaBridge 145:64910690c574 740 * a convenient way to enable all events.
AnnaBridge 145:64910690c574 741 *
AnnaBridge 145:64910690c574 742 * @param base The I2C peripheral base address.
AnnaBridge 145:64910690c574 743 * @param handle Pointer to #i2c_slave_handle_t structure which stores the transfer state.
AnnaBridge 145:64910690c574 744 * @param eventMask Bit mask formed by OR'ing together #i2c_slave_transfer_event_t enumerators to specify
AnnaBridge 145:64910690c574 745 * which events to send to the callback. Other accepted values are 0 to get a default set of
AnnaBridge 145:64910690c574 746 * only the transmit and receive events, and #kI2C_SlaveAllEvents to enable all events.
AnnaBridge 145:64910690c574 747 *
AnnaBridge 145:64910690c574 748 * @retval #kStatus_Success Slave transfers were successfully started.
AnnaBridge 145:64910690c574 749 * @retval #kStatus_I2C_Busy Slave transfers have already been started on this handle.
AnnaBridge 145:64910690c574 750 */
AnnaBridge 145:64910690c574 751 status_t I2C_SlaveTransferNonBlocking(I2C_Type *base, i2c_slave_handle_t *handle, uint32_t eventMask);
AnnaBridge 145:64910690c574 752
AnnaBridge 145:64910690c574 753 /*!
AnnaBridge 145:64910690c574 754 * @brief Aborts the slave transfer.
AnnaBridge 145:64910690c574 755 *
AnnaBridge 145:64910690c574 756 * @note This API can be called at any time to stop slave for handling the bus events.
AnnaBridge 145:64910690c574 757 *
AnnaBridge 145:64910690c574 758 * @param base I2C base pointer.
AnnaBridge 145:64910690c574 759 * @param handle pointer to i2c_slave_handle_t structure which stores the transfer state.
AnnaBridge 145:64910690c574 760 */
AnnaBridge 145:64910690c574 761 void I2C_SlaveTransferAbort(I2C_Type *base, i2c_slave_handle_t *handle);
AnnaBridge 145:64910690c574 762
AnnaBridge 145:64910690c574 763 /*!
AnnaBridge 145:64910690c574 764 * @brief Gets the slave transfer remaining bytes during a interrupt non-blocking transfer.
AnnaBridge 145:64910690c574 765 *
AnnaBridge 145:64910690c574 766 * @param base I2C base pointer.
AnnaBridge 145:64910690c574 767 * @param handle pointer to i2c_slave_handle_t structure.
AnnaBridge 145:64910690c574 768 * @param count Number of bytes transferred so far by the non-blocking transaction.
AnnaBridge 145:64910690c574 769 * @retval kStatus_InvalidArgument count is Invalid.
AnnaBridge 145:64910690c574 770 * @retval kStatus_Success Successfully return the count.
AnnaBridge 145:64910690c574 771 */
AnnaBridge 145:64910690c574 772 status_t I2C_SlaveTransferGetCount(I2C_Type *base, i2c_slave_handle_t *handle, size_t *count);
AnnaBridge 145:64910690c574 773
AnnaBridge 145:64910690c574 774 /*!
AnnaBridge 145:64910690c574 775 * @brief Slave interrupt handler.
AnnaBridge 145:64910690c574 776 *
AnnaBridge 145:64910690c574 777 * @param base I2C base pointer.
AnnaBridge 145:64910690c574 778 * @param i2cHandle pointer to i2c_slave_handle_t structure which stores the transfer state
AnnaBridge 145:64910690c574 779 */
AnnaBridge 145:64910690c574 780 void I2C_SlaveTransferHandleIRQ(I2C_Type *base, void *i2cHandle);
AnnaBridge 145:64910690c574 781
AnnaBridge 145:64910690c574 782 /* @} */
AnnaBridge 145:64910690c574 783 #if defined(__cplusplus)
AnnaBridge 145:64910690c574 784 }
AnnaBridge 145:64910690c574 785 #endif /*_cplusplus. */
AnnaBridge 145:64910690c574 786 /*@}*/
AnnaBridge 145:64910690c574 787
AnnaBridge 145:64910690c574 788 #endif /* _FSL_I2C_H_*/