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
Kojto 148:fd96258d940d 1 /*
Kojto 148:fd96258d940d 2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
Kojto 148:fd96258d940d 3 *
Kojto 148:fd96258d940d 4 * Redistribution and use in source and binary forms, with or without modification,
Kojto 148:fd96258d940d 5 * are permitted provided that the following conditions are met:
Kojto 148:fd96258d940d 6 *
Kojto 148:fd96258d940d 7 * o Redistributions of source code must retain the above copyright notice, this list
Kojto 148:fd96258d940d 8 * of conditions and the following disclaimer.
Kojto 148:fd96258d940d 9 *
Kojto 148:fd96258d940d 10 * o Redistributions in binary form must reproduce the above copyright notice, this
Kojto 148:fd96258d940d 11 * list of conditions and the following disclaimer in the documentation and/or
Kojto 148:fd96258d940d 12 * other materials provided with the distribution.
Kojto 148:fd96258d940d 13 *
Kojto 148:fd96258d940d 14 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
Kojto 148:fd96258d940d 15 * contributors may be used to endorse or promote products derived from this
Kojto 148:fd96258d940d 16 * software without specific prior written permission.
Kojto 148:fd96258d940d 17 *
Kojto 148:fd96258d940d 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Kojto 148:fd96258d940d 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Kojto 148:fd96258d940d 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Kojto 148:fd96258d940d 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Kojto 148:fd96258d940d 22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Kojto 148:fd96258d940d 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Kojto 148:fd96258d940d 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Kojto 148:fd96258d940d 25 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Kojto 148:fd96258d940d 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Kojto 148:fd96258d940d 27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 148:fd96258d940d 28 */
Kojto 148:fd96258d940d 29 #ifndef _FSL_I2C_H_
Kojto 148:fd96258d940d 30 #define _FSL_I2C_H_
Kojto 148:fd96258d940d 31
Kojto 148:fd96258d940d 32 #include <stddef.h>
Kojto 148:fd96258d940d 33 #include "fsl_device_registers.h"
Kojto 148:fd96258d940d 34 #include "fsl_common.h"
Kojto 148:fd96258d940d 35
Kojto 148:fd96258d940d 36 /*******************************************************************************
Kojto 148:fd96258d940d 37 * Definitions
Kojto 148:fd96258d940d 38 ******************************************************************************/
Kojto 148:fd96258d940d 39
Kojto 148:fd96258d940d 40 #define I2C_CFG_MASK 0x1f
Kojto 148:fd96258d940d 41
Kojto 148:fd96258d940d 42 /*!
Kojto 148:fd96258d940d 43 * @addtogroup i2c_driver
Kojto 148:fd96258d940d 44 * @{
Kojto 148:fd96258d940d 45 */
Kojto 148:fd96258d940d 46
Kojto 148:fd96258d940d 47 /*! @file */
Kojto 148:fd96258d940d 48
Kojto 148:fd96258d940d 49 /*! @name Driver version */
Kojto 148:fd96258d940d 50 /*@{*/
Kojto 148:fd96258d940d 51 /*! @brief I2C driver version 1.0.0. */
Kojto 148:fd96258d940d 52 #define NXP_I2C_DRIVER_VERSION (MAKE_VERSION(1, 0, 0))
Kojto 148:fd96258d940d 53 /*@}*/
Kojto 148:fd96258d940d 54
Kojto 148:fd96258d940d 55 /* definitions for MSTCODE bits in I2C Status register STAT */
Kojto 148:fd96258d940d 56 #define I2C_STAT_MSTCODE_IDLE (0) /*!< Master Idle State Code */
Kojto 148:fd96258d940d 57 #define I2C_STAT_MSTCODE_RXREADY (1) /*!< Master Receive Ready State Code */
Kojto 148:fd96258d940d 58 #define I2C_STAT_MSTCODE_TXREADY (2) /*!< Master Transmit Ready State Code */
Kojto 148:fd96258d940d 59 #define I2C_STAT_MSTCODE_NACKADR (3) /*!< Master NACK by slave on address State Code */
Kojto 148:fd96258d940d 60 #define I2C_STAT_MSTCODE_NACKDAT (4) /*!< Master NACK by slave on data State Code */
Kojto 148:fd96258d940d 61
Kojto 148:fd96258d940d 62 /* definitions for SLVSTATE bits in I2C Status register STAT */
Kojto 148:fd96258d940d 63 #define I2C_STAT_SLVST_ADDR (0)
Kojto 148:fd96258d940d 64 #define I2C_STAT_SLVST_RX (1)
Kojto 148:fd96258d940d 65 #define I2C_STAT_SLVST_TX (2)
Kojto 148:fd96258d940d 66
Kojto 148:fd96258d940d 67 /*! @brief I2C status return codes. */
Kojto 148:fd96258d940d 68 enum _i2c_status
Kojto 148:fd96258d940d 69 {
Kojto 148:fd96258d940d 70 kStatus_I2C_Busy = MAKE_STATUS(kStatusGroup_FLEXCOMM_I2C, 0), /*!< The master is already performing a transfer. */
Kojto 148:fd96258d940d 71 kStatus_I2C_Idle = MAKE_STATUS(kStatusGroup_FLEXCOMM_I2C, 1), /*!< The slave driver is idle. */
Kojto 148:fd96258d940d 72 kStatus_I2C_Nak =
Kojto 148:fd96258d940d 73 MAKE_STATUS(kStatusGroup_FLEXCOMM_I2C, 2), /*!< The slave device sent a NAK in response to a byte. */
Kojto 148:fd96258d940d 74 kStatus_I2C_InvalidParameter =
Kojto 148:fd96258d940d 75 MAKE_STATUS(kStatusGroup_FLEXCOMM_I2C, 3), /*!< Unable to proceed due to invalid parameter. */
Kojto 148:fd96258d940d 76 kStatus_I2C_BitError = MAKE_STATUS(kStatusGroup_FLEXCOMM_I2C, 4), /*!< Transferred bit was not seen on the bus. */
Kojto 148:fd96258d940d 77 kStatus_I2C_ArbitrationLost = MAKE_STATUS(kStatusGroup_FLEXCOMM_I2C, 5), /*!< Arbitration lost error. */
Kojto 148:fd96258d940d 78 kStatus_I2C_NoTransferInProgress =
Kojto 148:fd96258d940d 79 MAKE_STATUS(kStatusGroup_FLEXCOMM_I2C, 7), /*!< Attempt to abort a transfer when one is not in progress. */
Kojto 148:fd96258d940d 80 kStatus_I2C_DmaRequestFail = MAKE_STATUS(kStatusGroup_FLEXCOMM_I2C, 7), /*!< DMA request failed. */
Kojto 148:fd96258d940d 81 kStatus_I2C_StartStopError = MAKE_STATUS(kStatusGroup_FLEXCOMM_I2C, 8),
Kojto 148:fd96258d940d 82 kStatus_I2C_UnexpectedState = MAKE_STATUS(kStatusGroup_FLEXCOMM_I2C, 9),
Kojto 148:fd96258d940d 83 };
Kojto 148:fd96258d940d 84
Kojto 148:fd96258d940d 85 /*! @} */
Kojto 148:fd96258d940d 86
Kojto 148:fd96258d940d 87 /*!
Kojto 148:fd96258d940d 88 * @addtogroup i2c_master_driver
Kojto 148:fd96258d940d 89 * @{
Kojto 148:fd96258d940d 90 */
Kojto 148:fd96258d940d 91
Kojto 148:fd96258d940d 92 /*!
Kojto 148:fd96258d940d 93 * @brief I2C master peripheral flags.
Kojto 148:fd96258d940d 94 *
Kojto 148:fd96258d940d 95 * @note These enums are meant to be OR'd together to form a bit mask.
Kojto 148:fd96258d940d 96 */
Kojto 148:fd96258d940d 97 enum _i2c_master_flags
Kojto 148:fd96258d940d 98 {
Kojto 148:fd96258d940d 99 kI2C_MasterPendingFlag = I2C_STAT_MSTPENDING_MASK, /*!< The I2C module is waiting for software interaction. */
Kojto 148:fd96258d940d 100 kI2C_MasterArbitrationLostFlag = I2C_STAT_MSTARBLOSS_MASK, /*!< The arbitration of the bus was lost. There was collision on the bus */
Kojto 148:fd96258d940d 101 kI2C_MasterStartStopErrorFlag = I2C_STAT_MSTSTSTPERR_MASK /*!< There was an error during start or stop phase of the transaction. */
Kojto 148:fd96258d940d 102 };
Kojto 148:fd96258d940d 103
Kojto 148:fd96258d940d 104 /*! @brief Direction of master and slave transfers. */
Kojto 148:fd96258d940d 105 typedef enum _i2c_direction
Kojto 148:fd96258d940d 106 {
Kojto 148:fd96258d940d 107 kI2C_Write = 0U, /*!< Master transmit. */
Kojto 148:fd96258d940d 108 kI2C_Read = 1U /*!< Master receive. */
Kojto 148:fd96258d940d 109 } i2c_direction_t;
Kojto 148:fd96258d940d 110
Kojto 148:fd96258d940d 111 /*!
Kojto 148:fd96258d940d 112 * @brief Structure with settings to initialize the I2C master module.
Kojto 148:fd96258d940d 113 *
Kojto 148:fd96258d940d 114 * This structure holds configuration settings for the I2C peripheral. To initialize this
Kojto 148:fd96258d940d 115 * structure to reasonable defaults, call the I2C_MasterGetDefaultConfig() function and
Kojto 148:fd96258d940d 116 * pass a pointer to your configuration structure instance.
Kojto 148:fd96258d940d 117 *
Kojto 148:fd96258d940d 118 * The configuration structure can be made constant so it resides in flash.
Kojto 148:fd96258d940d 119 */
Kojto 148:fd96258d940d 120 typedef struct _i2c_master_config
Kojto 148:fd96258d940d 121 {
Kojto 148:fd96258d940d 122 bool enableMaster; /*!< Whether to enable master mode. */
Kojto 148:fd96258d940d 123 uint32_t baudRate_Bps; /*!< Desired baud rate in bits per second. */
Kojto 148:fd96258d940d 124 bool enableTimeout; /*!< Enable internal timeout function. */
Kojto 148:fd96258d940d 125 } i2c_master_config_t;
Kojto 148:fd96258d940d 126
Kojto 148:fd96258d940d 127 /* Forward declaration of the transfer descriptor and handle typedefs. */
Kojto 148:fd96258d940d 128 /*! @brief I2C master transfer typedef */
Kojto 148:fd96258d940d 129 typedef struct _i2c_master_transfer i2c_master_transfer_t;
Kojto 148:fd96258d940d 130
Kojto 148:fd96258d940d 131 /*! @brief I2C master handle typedef */
Kojto 148:fd96258d940d 132 typedef struct _i2c_master_handle i2c_master_handle_t;
Kojto 148:fd96258d940d 133
Kojto 148:fd96258d940d 134 /*!
Kojto 148:fd96258d940d 135 * @brief Master completion callback function pointer type.
Kojto 148:fd96258d940d 136 *
Kojto 148:fd96258d940d 137 * This callback is used only for the non-blocking master transfer API. Specify the callback you wish to use
Kojto 148:fd96258d940d 138 * in the call to I2C_MasterTransferCreateHandle().
Kojto 148:fd96258d940d 139 *
Kojto 148:fd96258d940d 140 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 141 * @param completionStatus Either kStatus_Success or an error code describing how the transfer completed.
Kojto 148:fd96258d940d 142 * @param userData Arbitrary pointer-sized value passed from the application.
Kojto 148:fd96258d940d 143 */
Kojto 148:fd96258d940d 144 typedef void (*i2c_master_transfer_callback_t)(I2C_Type *base,
Kojto 148:fd96258d940d 145 i2c_master_handle_t *handle,
Kojto 148:fd96258d940d 146 status_t completionStatus,
Kojto 148:fd96258d940d 147 void *userData);
Kojto 148:fd96258d940d 148
Kojto 148:fd96258d940d 149 /*!
Kojto 148:fd96258d940d 150 * @brief Transfer option flags.
Kojto 148:fd96258d940d 151 *
Kojto 148:fd96258d940d 152 * @note These enumerations are intended to be OR'd together to form a bit mask of options for
Kojto 148:fd96258d940d 153 * the #_i2c_master_transfer::flags field.
Kojto 148:fd96258d940d 154 */
Kojto 148:fd96258d940d 155 enum _i2c_master_transfer_flags
Kojto 148:fd96258d940d 156 {
Kojto 148:fd96258d940d 157 kI2C_TransferDefaultFlag = 0x00U, /*!< Transfer starts with a start signal, stops with a stop signal. */
Kojto 148:fd96258d940d 158 kI2C_TransferNoStartFlag = 0x01U, /*!< Don't send a start condition, address, and sub address */
Kojto 148:fd96258d940d 159 kI2C_TransferRepeatedStartFlag = 0x02U, /*!< Send a repeated start condition */
Kojto 148:fd96258d940d 160 kI2C_TransferNoStopFlag = 0x04U, /*!< Don't send a stop condition. */
Kojto 148:fd96258d940d 161 };
Kojto 148:fd96258d940d 162
Kojto 148:fd96258d940d 163 /*! @brief States for the state machine used by transactional APIs. */
Kojto 148:fd96258d940d 164 enum _i2c_transfer_states
Kojto 148:fd96258d940d 165 {
Kojto 148:fd96258d940d 166 kIdleState = 0,
Kojto 148:fd96258d940d 167 kTransmitSubaddrState,
Kojto 148:fd96258d940d 168 kTransmitDataState,
Kojto 148:fd96258d940d 169 kReceiveDataState,
Kojto 148:fd96258d940d 170 kReceiveLastDataState,
Kojto 148:fd96258d940d 171 kStartState,
Kojto 148:fd96258d940d 172 kStopState,
Kojto 148:fd96258d940d 173 kWaitForCompletionState
Kojto 148:fd96258d940d 174 };
Kojto 148:fd96258d940d 175
Kojto 148:fd96258d940d 176 /*!
Kojto 148:fd96258d940d 177 * @brief Non-blocking transfer descriptor structure.
Kojto 148:fd96258d940d 178 *
Kojto 148:fd96258d940d 179 * This structure is used to pass transaction parameters to the I2C_MasterTransferNonBlocking() API.
Kojto 148:fd96258d940d 180 */
Kojto 148:fd96258d940d 181 struct _i2c_master_transfer
Kojto 148:fd96258d940d 182 {
Kojto 148:fd96258d940d 183 uint32_t flags; /*!< Bit mask of options for the transfer. See enumeration #_i2c_master_transfer_flags for available
Kojto 148:fd96258d940d 184 options. Set to 0 or #kI2C_TransferDefaultFlag for normal transfers. */
Kojto 148:fd96258d940d 185 uint16_t slaveAddress; /*!< The 7-bit slave address. */
Kojto 148:fd96258d940d 186 i2c_direction_t direction; /*!< Either #kI2C_Read or #kI2C_Write. */
Kojto 148:fd96258d940d 187 uint32_t subaddress; /*!< Sub address. Transferred MSB first. */
Kojto 148:fd96258d940d 188 size_t subaddressSize; /*!< Length of sub address to send in bytes. Maximum size is 4 bytes. */
Kojto 148:fd96258d940d 189 void *data; /*!< Pointer to data to transfer. */
Kojto 148:fd96258d940d 190 size_t dataSize; /*!< Number of bytes to transfer. */
Kojto 148:fd96258d940d 191 };
Kojto 148:fd96258d940d 192
Kojto 148:fd96258d940d 193 /*!
Kojto 148:fd96258d940d 194 * @brief Driver handle for master non-blocking APIs.
Kojto 148:fd96258d940d 195 * @note The contents of this structure are private and subject to change.
Kojto 148:fd96258d940d 196 */
Kojto 148:fd96258d940d 197 struct _i2c_master_handle
Kojto 148:fd96258d940d 198 {
Kojto 148:fd96258d940d 199 uint8_t state; /*!< Transfer state machine current state. */
Kojto 148:fd96258d940d 200 uint32_t transferCount; /*!< Indicates progress of the transfer */
Kojto 148:fd96258d940d 201 uint32_t remainingBytes; /*!< Remaining byte count in current state. */
Kojto 148:fd96258d940d 202 uint8_t *buf; /*!< Buffer pointer for current state. */
Kojto 148:fd96258d940d 203 uint32_t remainingSubaddr;
Kojto 148:fd96258d940d 204 uint8_t subaddrBuf[4];
Kojto 148:fd96258d940d 205 i2c_master_transfer_t transfer; /*!< Copy of the current transfer info. */
Kojto 148:fd96258d940d 206 i2c_master_transfer_callback_t completionCallback; /*!< Callback function pointer. */
Kojto 148:fd96258d940d 207 void *userData; /*!< Application data passed to callback. */
Kojto 148:fd96258d940d 208 };
Kojto 148:fd96258d940d 209
Kojto 148:fd96258d940d 210 /*! @} */
Kojto 148:fd96258d940d 211
Kojto 148:fd96258d940d 212 /*!
Kojto 148:fd96258d940d 213 * @addtogroup i2c_slave_driver
Kojto 148:fd96258d940d 214 * @{
Kojto 148:fd96258d940d 215 */
Kojto 148:fd96258d940d 216
Kojto 148:fd96258d940d 217 /*!
Kojto 148:fd96258d940d 218 * @brief I2C slave peripheral flags.
Kojto 148:fd96258d940d 219 *
Kojto 148:fd96258d940d 220 * @note These enums are meant to be OR'd together to form a bit mask.
Kojto 148:fd96258d940d 221 */
Kojto 148:fd96258d940d 222 enum _i2c_slave_flags
Kojto 148:fd96258d940d 223 {
Kojto 148:fd96258d940d 224 kI2C_SlavePendingFlag = I2C_STAT_SLVPENDING_MASK, /*!< The I2C module is waiting for software interaction. */
Kojto 148:fd96258d940d 225 kI2C_SlaveNotStretching = I2C_STAT_SLVNOTSTR_MASK, /*!< Indicates whether the slave is currently stretching clock (0 = yes, 1 = no). */
Kojto 148:fd96258d940d 226 kI2C_SlaveSelected = I2C_STAT_SLVSEL_MASK, /*!< Indicates whether the slave is selected by an address match. */
Kojto 148:fd96258d940d 227 kI2C_SaveDeselected = I2C_STAT_SLVDESEL_MASK /*!< Indicates that slave was previously deselected (deselect event took place, w1c). */
Kojto 148:fd96258d940d 228 };
Kojto 148:fd96258d940d 229
Kojto 148:fd96258d940d 230 /*! @brief I2C slave address register. */
Kojto 148:fd96258d940d 231 typedef enum _i2c_slave_address_register
Kojto 148:fd96258d940d 232 {
Kojto 148:fd96258d940d 233 kI2C_SlaveAddressRegister0 = 0U, /*!< Slave Address 0 register. */
Kojto 148:fd96258d940d 234 kI2C_SlaveAddressRegister1 = 1U, /*!< Slave Address 1 register. */
Kojto 148:fd96258d940d 235 kI2C_SlaveAddressRegister2 = 2U, /*!< Slave Address 2 register. */
Kojto 148:fd96258d940d 236 kI2C_SlaveAddressRegister3 = 3U, /*!< Slave Address 3 register. */
Kojto 148:fd96258d940d 237 } i2c_slave_address_register_t;
Kojto 148:fd96258d940d 238
Kojto 148:fd96258d940d 239 /*! @brief Data structure with 7-bit Slave address and Slave address disable. */
Kojto 148:fd96258d940d 240 typedef struct _i2c_slave_address
Kojto 148:fd96258d940d 241 {
Kojto 148:fd96258d940d 242 uint8_t address; /*!< 7-bit Slave address SLVADR. */
Kojto 148:fd96258d940d 243 bool addressDisable; /*!< Slave address disable SADISABLE. */
Kojto 148:fd96258d940d 244 } i2c_slave_address_t;
Kojto 148:fd96258d940d 245
Kojto 148:fd96258d940d 246 /*! @brief I2C slave address match options. */
Kojto 148:fd96258d940d 247 typedef enum _i2c_slave_address_qual_mode
Kojto 148:fd96258d940d 248 {
Kojto 148:fd96258d940d 249 kI2C_QualModeMask = 0U, /*!< The SLVQUAL0 field (qualAddress) is used as a logical mask for matching address0. */
Kojto 148:fd96258d940d 250 kI2C_QualModeExtend =
Kojto 148:fd96258d940d 251 1U, /*!< The SLVQUAL0 (qualAddress) field is used to extend address 0 matching in a range of addresses. */
Kojto 148:fd96258d940d 252 } i2c_slave_address_qual_mode_t;
Kojto 148:fd96258d940d 253
Kojto 148:fd96258d940d 254 /*! @brief I2C slave bus speed options. */
Kojto 148:fd96258d940d 255 typedef enum _i2c_slave_bus_speed
Kojto 148:fd96258d940d 256 {
Kojto 148:fd96258d940d 257 kI2C_SlaveStandardMode = 0U,
Kojto 148:fd96258d940d 258 kI2C_SlaveFastMode = 1U,
Kojto 148:fd96258d940d 259 kI2C_SlaveFastModePlus = 2U,
Kojto 148:fd96258d940d 260 kI2C_SlaveHsMode = 3U,
Kojto 148:fd96258d940d 261 } i2c_slave_bus_speed_t;
Kojto 148:fd96258d940d 262
Kojto 148:fd96258d940d 263 /*!
Kojto 148:fd96258d940d 264 * @brief Structure with settings to initialize the I2C slave module.
Kojto 148:fd96258d940d 265 *
Kojto 148:fd96258d940d 266 * This structure holds configuration settings for the I2C slave peripheral. To initialize this
Kojto 148:fd96258d940d 267 * structure to reasonable defaults, call the I2C_SlaveGetDefaultConfig() function and
Kojto 148:fd96258d940d 268 * pass a pointer to your configuration structure instance.
Kojto 148:fd96258d940d 269 *
Kojto 148:fd96258d940d 270 * The configuration structure can be made constant so it resides in flash.
Kojto 148:fd96258d940d 271 */
Kojto 148:fd96258d940d 272 typedef struct _i2c_slave_config
Kojto 148:fd96258d940d 273 {
Kojto 148:fd96258d940d 274 i2c_slave_address_t address0; /*!< Slave's 7-bit address and disable. */
Kojto 148:fd96258d940d 275 i2c_slave_address_t address1; /*!< Alternate slave 7-bit address and disable. */
Kojto 148:fd96258d940d 276 i2c_slave_address_t address2; /*!< Alternate slave 7-bit address and disable. */
Kojto 148:fd96258d940d 277 i2c_slave_address_t address3; /*!< Alternate slave 7-bit address and disable. */
Kojto 148:fd96258d940d 278 i2c_slave_address_qual_mode_t qualMode; /*!< Qualify mode for slave address 0. */
Kojto 148:fd96258d940d 279 uint8_t qualAddress; /*!< Slave address qualifier for address 0. */
Kojto 148:fd96258d940d 280 i2c_slave_bus_speed_t
Kojto 148:fd96258d940d 281 busSpeed; /*!< Slave bus speed mode. If the slave function stretches SCL to allow for software response, it must
Kojto 148:fd96258d940d 282 provide sufficient data setup time to the master before releasing the stretched clock.
Kojto 148:fd96258d940d 283 This is accomplished by inserting one clock time of CLKDIV at that point.
Kojto 148:fd96258d940d 284 The #busSpeed value is used to configure CLKDIV
Kojto 148:fd96258d940d 285 such that one clock time is greater than the tSU;DAT value noted
Kojto 148:fd96258d940d 286 in the I2C bus specification for the I2C mode that is being used.
Kojto 148:fd96258d940d 287 If the #busSpeed mode is unknown at compile time, use the longest data setup time
Kojto 148:fd96258d940d 288 kI2C_SlaveStandardMode (250 ns) */
Kojto 148:fd96258d940d 289 bool enableSlave; /*!< Enable slave mode. */
Kojto 148:fd96258d940d 290 } i2c_slave_config_t;
Kojto 148:fd96258d940d 291
Kojto 148:fd96258d940d 292 /*!
Kojto 148:fd96258d940d 293 * @brief Set of events sent to the callback for non blocking slave transfers.
Kojto 148:fd96258d940d 294 *
Kojto 148:fd96258d940d 295 * These event enumerations are used for two related purposes. First, a bit mask created by OR'ing together
Kojto 148:fd96258d940d 296 * events is passed to I2C_SlaveTransferNonBlocking() in order to specify which events to enable.
Kojto 148:fd96258d940d 297 * Then, when the slave callback is invoked, it is passed the current event through its @a transfer
Kojto 148:fd96258d940d 298 * parameter.
Kojto 148:fd96258d940d 299 *
Kojto 148:fd96258d940d 300 * @note These enumerations are meant to be OR'd together to form a bit mask of events.
Kojto 148:fd96258d940d 301 */
Kojto 148:fd96258d940d 302 typedef enum _i2c_slave_transfer_event
Kojto 148:fd96258d940d 303 {
Kojto 148:fd96258d940d 304 kI2C_SlaveAddressMatchEvent = 0x01U, /*!< Received the slave address after a start or repeated start. */
Kojto 148:fd96258d940d 305 kI2C_SlaveTransmitEvent = 0x02U, /*!< Callback is requested to provide data to transmit
Kojto 148:fd96258d940d 306 (slave-transmitter role). */
Kojto 148:fd96258d940d 307 kI2C_SlaveReceiveEvent = 0x04U, /*!< Callback is requested to provide a buffer in which to place received
Kojto 148:fd96258d940d 308 data (slave-receiver role). */
Kojto 148:fd96258d940d 309 kI2C_SlaveCompletionEvent = 0x20U, /*!< All data in the active transfer have been consumed. */
Kojto 148:fd96258d940d 310 kI2C_SlaveDeselectedEvent =
Kojto 148:fd96258d940d 311 0x40U, /*!< The slave function has become deselected (SLVSEL flag changing from 1 to 0. */
Kojto 148:fd96258d940d 312
Kojto 148:fd96258d940d 313 /*! Bit mask of all available events. */
Kojto 148:fd96258d940d 314 kI2C_SlaveAllEvents = kI2C_SlaveAddressMatchEvent | kI2C_SlaveTransmitEvent | kI2C_SlaveReceiveEvent |
Kojto 148:fd96258d940d 315 kI2C_SlaveCompletionEvent | kI2C_SlaveDeselectedEvent,
Kojto 148:fd96258d940d 316 } i2c_slave_transfer_event_t;
Kojto 148:fd96258d940d 317
Kojto 148:fd96258d940d 318 /*! @brief I2C slave handle typedef. */
Kojto 148:fd96258d940d 319 typedef struct _i2c_slave_handle i2c_slave_handle_t;
Kojto 148:fd96258d940d 320
Kojto 148:fd96258d940d 321 /*! @brief I2C slave transfer structure */
Kojto 148:fd96258d940d 322 typedef struct _i2c_slave_transfer
Kojto 148:fd96258d940d 323 {
Kojto 148:fd96258d940d 324 i2c_slave_handle_t *handle; /*!< Pointer to handle that contains this transfer. */
Kojto 148:fd96258d940d 325 i2c_slave_transfer_event_t event; /*!< Reason the callback is being invoked. */
Kojto 148:fd96258d940d 326 uint8_t receivedAddress; /*!< Matching address send by master. 7-bits plus R/nW bit0 */
Kojto 148:fd96258d940d 327 uint32_t eventMask; /*!< Mask of enabled events. */
Kojto 148:fd96258d940d 328 uint8_t *rxData; /*!< Transfer buffer for receive data */
Kojto 148:fd96258d940d 329 const uint8_t *txData; /*!< Transfer buffer for transmit data */
Kojto 148:fd96258d940d 330 size_t txSize; /*!< Transfer size */
Kojto 148:fd96258d940d 331 size_t rxSize; /*!< Transfer size */
Kojto 148:fd96258d940d 332 size_t transferredCount; /*!< Number of bytes transferred during this transfer. */
Kojto 148:fd96258d940d 333 status_t completionStatus; /*!< Success or error code describing how the transfer completed. Only applies for
Kojto 148:fd96258d940d 334 #kI2C_SlaveCompletionEvent. */
Kojto 148:fd96258d940d 335 } i2c_slave_transfer_t;
Kojto 148:fd96258d940d 336
Kojto 148:fd96258d940d 337 /*!
Kojto 148:fd96258d940d 338 * @brief Slave event callback function pointer type.
Kojto 148:fd96258d940d 339 *
Kojto 148:fd96258d940d 340 * This callback is used only for the slave non-blocking transfer API. To install a callback,
Kojto 148:fd96258d940d 341 * use the I2C_SlaveSetCallback() function after you have created a handle.
Kojto 148:fd96258d940d 342 *
Kojto 148:fd96258d940d 343 * @param base Base address for the I2C instance on which the event occurred.
Kojto 148:fd96258d940d 344 * @param transfer Pointer to transfer descriptor containing values passed to and/or from the callback.
Kojto 148:fd96258d940d 345 * @param userData Arbitrary pointer-sized value passed from the application.
Kojto 148:fd96258d940d 346 */
Kojto 148:fd96258d940d 347 typedef void (*i2c_slave_transfer_callback_t)(I2C_Type *base, volatile i2c_slave_transfer_t *transfer, void *userData);
Kojto 148:fd96258d940d 348
Kojto 148:fd96258d940d 349 /*!
Kojto 148:fd96258d940d 350 * @brief I2C slave software finite state machine states.
Kojto 148:fd96258d940d 351 */
Kojto 148:fd96258d940d 352 typedef enum _i2c_slave_fsm
Kojto 148:fd96258d940d 353 {
Kojto 148:fd96258d940d 354 kI2C_SlaveFsmAddressMatch = 0u,
Kojto 148:fd96258d940d 355 kI2C_SlaveFsmReceive = 2u,
Kojto 148:fd96258d940d 356 kI2C_SlaveFsmTransmit = 3u,
Kojto 148:fd96258d940d 357 } i2c_slave_fsm_t;
Kojto 148:fd96258d940d 358
Kojto 148:fd96258d940d 359 /*!
Kojto 148:fd96258d940d 360 * @brief I2C slave handle structure.
Kojto 148:fd96258d940d 361 * @note The contents of this structure are private and subject to change.
Kojto 148:fd96258d940d 362 */
Kojto 148:fd96258d940d 363 struct _i2c_slave_handle
Kojto 148:fd96258d940d 364 {
Kojto 148:fd96258d940d 365 volatile i2c_slave_transfer_t transfer; /*!< I2C slave transfer. */
Kojto 148:fd96258d940d 366 volatile bool isBusy; /*!< Whether transfer is busy. */
Kojto 148:fd96258d940d 367 volatile i2c_slave_fsm_t slaveFsm; /*!< slave transfer state machine. */
Kojto 148:fd96258d940d 368 i2c_slave_transfer_callback_t callback; /*!< Callback function called at transfer event. */
Kojto 148:fd96258d940d 369 void *userData; /*!< Callback parameter passed to callback. */
Kojto 148:fd96258d940d 370 };
Kojto 148:fd96258d940d 371
Kojto 148:fd96258d940d 372 /*! @} */
Kojto 148:fd96258d940d 373
Kojto 148:fd96258d940d 374 /*******************************************************************************
Kojto 148:fd96258d940d 375 * API
Kojto 148:fd96258d940d 376 ******************************************************************************/
Kojto 148:fd96258d940d 377
Kojto 148:fd96258d940d 378 #if defined(__cplusplus)
Kojto 148:fd96258d940d 379 extern "C" {
Kojto 148:fd96258d940d 380 #endif
Kojto 148:fd96258d940d 381
Kojto 148:fd96258d940d 382 /*!
Kojto 148:fd96258d940d 383 * @addtogroup i2c_master_driver
Kojto 148:fd96258d940d 384 * @{
Kojto 148:fd96258d940d 385 */
Kojto 148:fd96258d940d 386
Kojto 148:fd96258d940d 387 /*! @name Initialization and deinitialization */
Kojto 148:fd96258d940d 388 /*@{*/
Kojto 148:fd96258d940d 389
Kojto 148:fd96258d940d 390 /*!
Kojto 148:fd96258d940d 391 * @brief Provides a default configuration for the I2C master peripheral.
Kojto 148:fd96258d940d 392 *
Kojto 148:fd96258d940d 393 * This function provides the following default configuration for the I2C master peripheral:
Kojto 148:fd96258d940d 394 * @code
Kojto 148:fd96258d940d 395 * masterConfig->enableMaster = true;
Kojto 148:fd96258d940d 396 * masterConfig->baudRate_Bps = 100000U;
Kojto 148:fd96258d940d 397 * masterConfig->enableTimeout = false;
Kojto 148:fd96258d940d 398 * @endcode
Kojto 148:fd96258d940d 399 *
Kojto 148:fd96258d940d 400 * After calling this function, you can override any settings in order to customize the configuration,
Kojto 148:fd96258d940d 401 * prior to initializing the master driver with I2C_MasterInit().
Kojto 148:fd96258d940d 402 *
Kojto 148:fd96258d940d 403 * @param[out] masterConfig User provided configuration structure for default values. Refer to #i2c_master_config_t.
Kojto 148:fd96258d940d 404 */
Kojto 148:fd96258d940d 405 void I2C_MasterGetDefaultConfig(i2c_master_config_t *masterConfig);
Kojto 148:fd96258d940d 406
Kojto 148:fd96258d940d 407 /*!
Kojto 148:fd96258d940d 408 * @brief Initializes the I2C master peripheral.
Kojto 148:fd96258d940d 409 *
Kojto 148:fd96258d940d 410 * This function enables the peripheral clock and initializes the I2C master peripheral as described by the user
Kojto 148:fd96258d940d 411 * provided configuration. A software reset is performed prior to configuration.
Kojto 148:fd96258d940d 412 *
Kojto 148:fd96258d940d 413 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 414 * @param masterConfig User provided peripheral configuration. Use I2C_MasterGetDefaultConfig() to get a set of
Kojto 148:fd96258d940d 415 * defaults
Kojto 148:fd96258d940d 416 * that you can override.
Kojto 148:fd96258d940d 417 * @param srcClock_Hz Frequency in Hertz of the I2C functional clock. Used to calculate the baud rate divisors,
Kojto 148:fd96258d940d 418 * filter widths, and timeout periods.
Kojto 148:fd96258d940d 419 */
Kojto 148:fd96258d940d 420 void I2C_MasterInit(I2C_Type *base, const i2c_master_config_t *masterConfig, uint32_t srcClock_Hz);
Kojto 148:fd96258d940d 421
Kojto 148:fd96258d940d 422 /*!
Kojto 148:fd96258d940d 423 * @brief Deinitializes the I2C master peripheral.
Kojto 148:fd96258d940d 424 *
Kojto 148:fd96258d940d 425 * This function disables the I2C master peripheral and gates the clock. It also performs a software
Kojto 148:fd96258d940d 426 * reset to restore the peripheral to reset conditions.
Kojto 148:fd96258d940d 427 *
Kojto 148:fd96258d940d 428 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 429 */
Kojto 148:fd96258d940d 430 void I2C_MasterDeinit(I2C_Type *base);
Kojto 148:fd96258d940d 431
Kojto 148:fd96258d940d 432 /*!
Kojto 148:fd96258d940d 433 * @brief Performs a software reset.
Kojto 148:fd96258d940d 434 *
Kojto 148:fd96258d940d 435 * Restores the I2C master peripheral to reset conditions.
Kojto 148:fd96258d940d 436 *
Kojto 148:fd96258d940d 437 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 438 */
Kojto 148:fd96258d940d 439 static inline void I2C_MasterReset(I2C_Type *base)
Kojto 148:fd96258d940d 440 {
Kojto 148:fd96258d940d 441 }
Kojto 148:fd96258d940d 442
Kojto 148:fd96258d940d 443 /*!
Kojto 148:fd96258d940d 444 * @brief Enables or disables the I2C module as master.
Kojto 148:fd96258d940d 445 *
Kojto 148:fd96258d940d 446 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 447 * @param enable Pass true to enable or false to disable the specified I2C as master.
Kojto 148:fd96258d940d 448 */
Kojto 148:fd96258d940d 449 static inline void I2C_MasterEnable(I2C_Type *base, bool enable)
Kojto 148:fd96258d940d 450 {
Kojto 148:fd96258d940d 451 if (enable)
Kojto 148:fd96258d940d 452 {
Kojto 148:fd96258d940d 453 base->CFG = (base->CFG & I2C_CFG_MASK) | I2C_CFG_MSTEN_MASK;
Kojto 148:fd96258d940d 454 }
Kojto 148:fd96258d940d 455 else
Kojto 148:fd96258d940d 456 {
Kojto 148:fd96258d940d 457 base->CFG = (base->CFG & I2C_CFG_MASK) & ~I2C_CFG_MSTEN_MASK;
Kojto 148:fd96258d940d 458 }
Kojto 148:fd96258d940d 459 }
Kojto 148:fd96258d940d 460
Kojto 148:fd96258d940d 461 /*@}*/
Kojto 148:fd96258d940d 462
Kojto 148:fd96258d940d 463 /*! @name Status */
Kojto 148:fd96258d940d 464 /*@{*/
Kojto 148:fd96258d940d 465
Kojto 148:fd96258d940d 466 /*!
Kojto 148:fd96258d940d 467 * @brief Gets the I2C status flags.
Kojto 148:fd96258d940d 468 *
Kojto 148:fd96258d940d 469 * A bit mask with the state of all I2C status flags is returned. For each flag, the corresponding bit
Kojto 148:fd96258d940d 470 * in the return value is set if the flag is asserted.
Kojto 148:fd96258d940d 471 *
Kojto 148:fd96258d940d 472 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 473 * @return State of the status flags:
Kojto 148:fd96258d940d 474 * - 1: related status flag is set.
Kojto 148:fd96258d940d 475 * - 0: related status flag is not set.
Kojto 148:fd96258d940d 476 * @see _i2c_master_flags
Kojto 148:fd96258d940d 477 */
Kojto 148:fd96258d940d 478 static inline uint32_t I2C_GetStatusFlags(I2C_Type *base)
Kojto 148:fd96258d940d 479 {
Kojto 148:fd96258d940d 480 return base->STAT;
Kojto 148:fd96258d940d 481 }
Kojto 148:fd96258d940d 482
Kojto 148:fd96258d940d 483 /*!
Kojto 148:fd96258d940d 484 * @brief Clears the I2C master status flag state.
Kojto 148:fd96258d940d 485 *
Kojto 148:fd96258d940d 486 * The following status register flags can be cleared:
Kojto 148:fd96258d940d 487 * - #kI2C_MasterArbitrationLostFlag
Kojto 148:fd96258d940d 488 * - #kI2C_MasterStartStopErrorFlag
Kojto 148:fd96258d940d 489 *
Kojto 148:fd96258d940d 490 * Attempts to clear other flags has no effect.
Kojto 148:fd96258d940d 491 *
Kojto 148:fd96258d940d 492 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 493 * @param statusMask A bitmask of status flags that are to be cleared. The mask is composed of
Kojto 148:fd96258d940d 494 * #_i2c_master_flags enumerators OR'd together. You may pass the result of a previous call to
Kojto 148:fd96258d940d 495 * I2C_GetStatusFlags().
Kojto 148:fd96258d940d 496 * @see _i2c_master_flags.
Kojto 148:fd96258d940d 497 */
Kojto 148:fd96258d940d 498 static inline void I2C_MasterClearStatusFlags(I2C_Type *base, uint32_t statusMask)
Kojto 148:fd96258d940d 499 {
Kojto 148:fd96258d940d 500 /* Allow clearing just master status flags */
Kojto 148:fd96258d940d 501 base->STAT = statusMask & (I2C_STAT_MSTARBLOSS_MASK | I2C_STAT_MSTSTSTPERR_MASK);
Kojto 148:fd96258d940d 502 }
Kojto 148:fd96258d940d 503
Kojto 148:fd96258d940d 504 /*@}*/
Kojto 148:fd96258d940d 505
Kojto 148:fd96258d940d 506 /*! @name Interrupts */
Kojto 148:fd96258d940d 507 /*@{*/
Kojto 148:fd96258d940d 508
Kojto 148:fd96258d940d 509 /*!
Kojto 148:fd96258d940d 510 * @brief Enables the I2C master interrupt requests.
Kojto 148:fd96258d940d 511 *
Kojto 148:fd96258d940d 512 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 513 * @param interruptMask Bit mask of interrupts to enable. See #_i2c_master_flags for the set
Kojto 148:fd96258d940d 514 * of constants that should be OR'd together to form the bit mask.
Kojto 148:fd96258d940d 515 */
Kojto 148:fd96258d940d 516 static inline void I2C_EnableInterrupts(I2C_Type *base, uint32_t interruptMask)
Kojto 148:fd96258d940d 517 {
Kojto 148:fd96258d940d 518 base->INTENSET = interruptMask;
Kojto 148:fd96258d940d 519 }
Kojto 148:fd96258d940d 520
Kojto 148:fd96258d940d 521 /*!
Kojto 148:fd96258d940d 522 * @brief Disables the I2C master interrupt requests.
Kojto 148:fd96258d940d 523 *
Kojto 148:fd96258d940d 524 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 525 * @param interruptMask Bit mask of interrupts to disable. See #_i2c_master_flags for the set
Kojto 148:fd96258d940d 526 * of constants that should be OR'd together to form the bit mask.
Kojto 148:fd96258d940d 527 */
Kojto 148:fd96258d940d 528 static inline void I2C_DisableInterrupts(I2C_Type *base, uint32_t interruptMask)
Kojto 148:fd96258d940d 529 {
Kojto 148:fd96258d940d 530 base->INTENCLR = interruptMask;
Kojto 148:fd96258d940d 531 }
Kojto 148:fd96258d940d 532
Kojto 148:fd96258d940d 533 /*!
Kojto 148:fd96258d940d 534 * @brief Returns the set of currently enabled I2C master interrupt requests.
Kojto 148:fd96258d940d 535 *
Kojto 148:fd96258d940d 536 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 537 * @return A bitmask composed of #_i2c_master_flags enumerators OR'd together to indicate the
Kojto 148:fd96258d940d 538 * set of enabled interrupts.
Kojto 148:fd96258d940d 539 */
Kojto 148:fd96258d940d 540 static inline uint32_t I2C_GetEnabledInterrupts(I2C_Type *base)
Kojto 148:fd96258d940d 541 {
Kojto 148:fd96258d940d 542 return base->INTSTAT;
Kojto 148:fd96258d940d 543 }
Kojto 148:fd96258d940d 544
Kojto 148:fd96258d940d 545 /*@}*/
Kojto 148:fd96258d940d 546
Kojto 148:fd96258d940d 547 /*! @name Bus operations */
Kojto 148:fd96258d940d 548 /*@{*/
Kojto 148:fd96258d940d 549
Kojto 148:fd96258d940d 550 /*!
Kojto 148:fd96258d940d 551 * @brief Sets the I2C bus frequency for master transactions.
Kojto 148:fd96258d940d 552 *
Kojto 148:fd96258d940d 553 * The I2C master is automatically disabled and re-enabled as necessary to configure the baud
Kojto 148:fd96258d940d 554 * rate. Do not call this function during a transfer, or the transfer is aborted.
Kojto 148:fd96258d940d 555 *
Kojto 148:fd96258d940d 556 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 557 * @param srcClock_Hz I2C functional clock frequency in Hertz.
Kojto 148:fd96258d940d 558 * @param baudRate_Bps Requested bus frequency in bits per second.
Kojto 148:fd96258d940d 559 */
Kojto 148:fd96258d940d 560 void I2C_MasterSetBaudRate(I2C_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz);
Kojto 148:fd96258d940d 561
Kojto 148:fd96258d940d 562 /*!
Kojto 148:fd96258d940d 563 * @brief Returns whether the bus is idle.
Kojto 148:fd96258d940d 564 *
Kojto 148:fd96258d940d 565 * Requires the master mode to be enabled.
Kojto 148:fd96258d940d 566 *
Kojto 148:fd96258d940d 567 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 568 * @retval true Bus is busy.
Kojto 148:fd96258d940d 569 * @retval false Bus is idle.
Kojto 148:fd96258d940d 570 */
Kojto 148:fd96258d940d 571 static inline bool I2C_MasterGetBusIdleState(I2C_Type *base)
Kojto 148:fd96258d940d 572 {
Kojto 148:fd96258d940d 573 /* True if MSTPENDING flag is set and MSTSTATE is zero == idle */
Kojto 148:fd96258d940d 574 return ((base->STAT & (I2C_STAT_MSTPENDING_MASK | I2C_STAT_MSTSTATE_MASK)) == I2C_STAT_MSTPENDING_MASK);
Kojto 148:fd96258d940d 575 }
Kojto 148:fd96258d940d 576
Kojto 148:fd96258d940d 577 /*!
Kojto 148:fd96258d940d 578 * @brief Sends a START on the I2C bus.
Kojto 148:fd96258d940d 579 *
Kojto 148:fd96258d940d 580 * This function is used to initiate a new master mode transfer by sending the START signal.
Kojto 148:fd96258d940d 581 * The slave address is sent following the I2C START signal.
Kojto 148:fd96258d940d 582 *
Kojto 148:fd96258d940d 583 * @param base I2C peripheral base pointer
Kojto 148:fd96258d940d 584 * @param address 7-bit slave device address.
Kojto 148:fd96258d940d 585 * @param direction Master transfer directions(transmit/receive).
Kojto 148:fd96258d940d 586 * @retval kStatus_Success Successfully send the start signal.
Kojto 148:fd96258d940d 587 * @retval kStatus_I2C_Busy Current bus is busy.
Kojto 148:fd96258d940d 588 */
Kojto 148:fd96258d940d 589 status_t I2C_MasterStart(I2C_Type *base, uint8_t address, i2c_direction_t direction);
Kojto 148:fd96258d940d 590
Kojto 148:fd96258d940d 591 /*!
Kojto 148:fd96258d940d 592 * @brief Sends a STOP signal on the I2C bus.
Kojto 148:fd96258d940d 593 *
Kojto 148:fd96258d940d 594 * @retval kStatus_Success Successfully send the stop signal.
Kojto 148:fd96258d940d 595 * @retval kStatus_I2C_Timeout Send stop signal failed, timeout.
Kojto 148:fd96258d940d 596 */
Kojto 148:fd96258d940d 597 status_t I2C_MasterStop(I2C_Type *base);
Kojto 148:fd96258d940d 598
Kojto 148:fd96258d940d 599 /*!
Kojto 148:fd96258d940d 600 * @brief Sends a REPEATED START on the I2C bus.
Kojto 148:fd96258d940d 601 *
Kojto 148:fd96258d940d 602 * @param base I2C peripheral base pointer
Kojto 148:fd96258d940d 603 * @param address 7-bit slave device address.
Kojto 148:fd96258d940d 604 * @param direction Master transfer directions(transmit/receive).
Kojto 148:fd96258d940d 605 * @retval kStatus_Success Successfully send the start signal.
Kojto 148:fd96258d940d 606 * @retval kStatus_I2C_Busy Current bus is busy but not occupied by current I2C master.
Kojto 148:fd96258d940d 607 */
Kojto 148:fd96258d940d 608 static inline status_t I2C_MasterRepeatedStart(I2C_Type *base, uint8_t address, i2c_direction_t direction)
Kojto 148:fd96258d940d 609 {
Kojto 148:fd96258d940d 610 return I2C_MasterStart(base, address, direction);
Kojto 148:fd96258d940d 611 }
Kojto 148:fd96258d940d 612
Kojto 148:fd96258d940d 613 /*!
Kojto 148:fd96258d940d 614 * @brief Performs a polling send transfer on the I2C bus.
Kojto 148:fd96258d940d 615 *
Kojto 148:fd96258d940d 616 * Sends up to @a txSize number of bytes to the previously addressed slave device. The slave may
Kojto 148:fd96258d940d 617 * reply with a NAK to any byte in order to terminate the transfer early. If this happens, this
Kojto 148:fd96258d940d 618 * function returns #kStatus_I2C_Nak.
Kojto 148:fd96258d940d 619 *
Kojto 148:fd96258d940d 620 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 621 * @param txBuff The pointer to the data to be transferred.
Kojto 148:fd96258d940d 622 * @param txSize The length in bytes of the data to be transferred.
Kojto 148:fd96258d940d 623 * @param flags Transfer control flag to control special behavior like suppressing start or stop, for normal transfers use kI2C_TransferDefaultFlag
Kojto 148:fd96258d940d 624 * @retval kStatus_Success Data was sent successfully.
Kojto 148:fd96258d940d 625 * @retval #kStatus_I2C_Busy Another master is currently utilizing the bus.
Kojto 148:fd96258d940d 626 * @retval #kStatus_I2C_Nak The slave device sent a NAK in response to a byte.
Kojto 148:fd96258d940d 627 * @retval #kStatus_I2C_ArbitrationLost Arbitration lost error.
Kojto 148:fd96258d940d 628 */
Kojto 148:fd96258d940d 629 status_t I2C_MasterWriteBlocking(I2C_Type *base, const void *txBuff, size_t txSize, uint32_t flags);
Kojto 148:fd96258d940d 630
Kojto 148:fd96258d940d 631 /*!
Kojto 148:fd96258d940d 632 * @brief Performs a polling receive transfer on the I2C bus.
Kojto 148:fd96258d940d 633 *
Kojto 148:fd96258d940d 634 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 635 * @param rxBuff The pointer to the data to be transferred.
Kojto 148:fd96258d940d 636 * @param rxSize The length in bytes of the data to be transferred.
Kojto 148:fd96258d940d 637 * @param flags Transfer control flag to control special behavior like suppressing start or stop, for normal transfers use kI2C_TransferDefaultFlag
Kojto 148:fd96258d940d 638 * @retval kStatus_Success Data was received successfully.
Kojto 148:fd96258d940d 639 * @retval #kStatus_I2C_Busy Another master is currently utilizing the bus.
Kojto 148:fd96258d940d 640 * @retval #kStatus_I2C_Nak The slave device sent a NAK in response to a byte.
Kojto 148:fd96258d940d 641 * @retval #kStatus_I2C_ArbitrationLost Arbitration lost error.
Kojto 148:fd96258d940d 642 */
Kojto 148:fd96258d940d 643 status_t I2C_MasterReadBlocking(I2C_Type *base, void *rxBuff, size_t rxSize, uint32_t flags);
Kojto 148:fd96258d940d 644
Kojto 148:fd96258d940d 645 /*!
Kojto 148:fd96258d940d 646 * @brief Performs a master polling transfer on the I2C bus.
Kojto 148:fd96258d940d 647 *
Kojto 148:fd96258d940d 648 * @note The API does not return until the transfer succeeds or fails due
Kojto 148:fd96258d940d 649 * to arbitration lost or receiving a NAK.
Kojto 148:fd96258d940d 650 *
Kojto 148:fd96258d940d 651 * @param base I2C peripheral base address.
Kojto 148:fd96258d940d 652 * @param xfer Pointer to the transfer structure.
Kojto 148:fd96258d940d 653 * @retval kStatus_Success Successfully complete the data transmission.
Kojto 148:fd96258d940d 654 * @retval kStatus_I2C_Busy Previous transmission still not finished.
Kojto 148:fd96258d940d 655 * @retval kStatus_I2C_Timeout Transfer error, wait signal timeout.
Kojto 148:fd96258d940d 656 * @retval kStatus_I2C_ArbitrationLost Transfer error, arbitration lost.
Kojto 148:fd96258d940d 657 * @retval kStataus_I2C_Nak Transfer error, receive NAK during transfer.
Kojto 148:fd96258d940d 658 */
Kojto 148:fd96258d940d 659 status_t I2C_MasterTransferBlocking(I2C_Type *base, i2c_master_transfer_t *xfer);
Kojto 148:fd96258d940d 660
Kojto 148:fd96258d940d 661 /*@}*/
Kojto 148:fd96258d940d 662
Kojto 148:fd96258d940d 663 /*! @name Non-blocking */
Kojto 148:fd96258d940d 664 /*@{*/
Kojto 148:fd96258d940d 665
Kojto 148:fd96258d940d 666 /*!
Kojto 148:fd96258d940d 667 * @brief Creates a new handle for the I2C master non-blocking APIs.
Kojto 148:fd96258d940d 668 *
Kojto 148:fd96258d940d 669 * The creation of a handle is for use with the non-blocking APIs. Once a handle
Kojto 148:fd96258d940d 670 * is created, there is not a corresponding destroy handle. If the user wants to
Kojto 148:fd96258d940d 671 * terminate a transfer, the I2C_MasterTransferAbort() API shall be called.
Kojto 148:fd96258d940d 672 *
Kojto 148:fd96258d940d 673 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 674 * @param[out] handle Pointer to the I2C master driver handle.
Kojto 148:fd96258d940d 675 * @param callback User provided pointer to the asynchronous callback function.
Kojto 148:fd96258d940d 676 * @param userData User provided pointer to the application callback data.
Kojto 148:fd96258d940d 677 */
Kojto 148:fd96258d940d 678 void I2C_MasterTransferCreateHandle(I2C_Type *base,
Kojto 148:fd96258d940d 679 i2c_master_handle_t *handle,
Kojto 148:fd96258d940d 680 i2c_master_transfer_callback_t callback,
Kojto 148:fd96258d940d 681 void *userData);
Kojto 148:fd96258d940d 682
Kojto 148:fd96258d940d 683 /*!
Kojto 148:fd96258d940d 684 * @brief Performs a non-blocking transaction on the I2C bus.
Kojto 148:fd96258d940d 685 *
Kojto 148:fd96258d940d 686 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 687 * @param handle Pointer to the I2C master driver handle.
Kojto 148:fd96258d940d 688 * @param xfer The pointer to the transfer descriptor.
Kojto 148:fd96258d940d 689 * @retval kStatus_Success The transaction was started successfully.
Kojto 148:fd96258d940d 690 * @retval #kStatus_I2C_Busy Either another master is currently utilizing the bus, or a non-blocking
Kojto 148:fd96258d940d 691 * transaction is already in progress.
Kojto 148:fd96258d940d 692 */
Kojto 148:fd96258d940d 693 status_t I2C_MasterTransferNonBlocking(I2C_Type *base, i2c_master_handle_t *handle, i2c_master_transfer_t *xfer);
Kojto 148:fd96258d940d 694
Kojto 148:fd96258d940d 695 /*!
Kojto 148:fd96258d940d 696 * @brief Returns number of bytes transferred so far.
Kojto 148:fd96258d940d 697 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 698 * @param handle Pointer to the I2C master driver handle.
Kojto 148:fd96258d940d 699 * @param[out] count Number of bytes transferred so far by the non-blocking transaction.
Kojto 148:fd96258d940d 700 * @retval kStatus_Success
Kojto 148:fd96258d940d 701 * @retval #kStatus_I2C_Busy
Kojto 148:fd96258d940d 702 */
Kojto 148:fd96258d940d 703 status_t I2C_MasterTransferGetCount(I2C_Type *base, i2c_master_handle_t *handle, size_t *count);
Kojto 148:fd96258d940d 704
Kojto 148:fd96258d940d 705 /*!
Kojto 148:fd96258d940d 706 * @brief Terminates a non-blocking I2C master transmission early.
Kojto 148:fd96258d940d 707 *
Kojto 148:fd96258d940d 708 * @note It is not safe to call this function from an IRQ handler that has a higher priority than the
Kojto 148:fd96258d940d 709 * I2C peripheral's IRQ priority.
Kojto 148:fd96258d940d 710 *
Kojto 148:fd96258d940d 711 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 712 * @param handle Pointer to the I2C master driver handle.
Kojto 148:fd96258d940d 713 * @retval kStatus_Success A transaction was successfully aborted.
Kojto 148:fd96258d940d 714 * @retval #kStatus_I2C_Idle There is not a non-blocking transaction currently in progress.
Kojto 148:fd96258d940d 715 */
Kojto 148:fd96258d940d 716 void I2C_MasterTransferAbort(I2C_Type *base, i2c_master_handle_t *handle);
Kojto 148:fd96258d940d 717
Kojto 148:fd96258d940d 718 /*@}*/
Kojto 148:fd96258d940d 719
Kojto 148:fd96258d940d 720 /*! @name IRQ handler */
Kojto 148:fd96258d940d 721 /*@{*/
Kojto 148:fd96258d940d 722
Kojto 148:fd96258d940d 723 /*!
Kojto 148:fd96258d940d 724 * @brief Reusable routine to handle master interrupts.
Kojto 148:fd96258d940d 725 * @note This function does not need to be called unless you are reimplementing the
Kojto 148:fd96258d940d 726 * nonblocking API's interrupt handler routines to add special functionality.
Kojto 148:fd96258d940d 727 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 728 * @param handle Pointer to the I2C master driver handle.
Kojto 148:fd96258d940d 729 */
Kojto 148:fd96258d940d 730 void I2C_MasterTransferHandleIRQ(I2C_Type *base, i2c_master_handle_t *handle);
Kojto 148:fd96258d940d 731
Kojto 148:fd96258d940d 732 /*@}*/
Kojto 148:fd96258d940d 733
Kojto 148:fd96258d940d 734 /*! @} */ /* end of i2c_master_driver */
Kojto 148:fd96258d940d 735
Kojto 148:fd96258d940d 736 /*!
Kojto 148:fd96258d940d 737 * @addtogroup i2c_slave_driver
Kojto 148:fd96258d940d 738 * @{
Kojto 148:fd96258d940d 739 */
Kojto 148:fd96258d940d 740
Kojto 148:fd96258d940d 741 /*! @name Slave initialization and deinitialization */
Kojto 148:fd96258d940d 742 /*@{*/
Kojto 148:fd96258d940d 743
Kojto 148:fd96258d940d 744 /*!
Kojto 148:fd96258d940d 745 * @brief Provides a default configuration for the I2C slave peripheral.
Kojto 148:fd96258d940d 746 *
Kojto 148:fd96258d940d 747 * This function provides the following default configuration for the I2C slave peripheral:
Kojto 148:fd96258d940d 748 * @code
Kojto 148:fd96258d940d 749 * slaveConfig->enableSlave = true;
Kojto 148:fd96258d940d 750 * slaveConfig->address0.disable = false;
Kojto 148:fd96258d940d 751 * slaveConfig->address0.address = 0u;
Kojto 148:fd96258d940d 752 * slaveConfig->address1.disable = true;
Kojto 148:fd96258d940d 753 * slaveConfig->address2.disable = true;
Kojto 148:fd96258d940d 754 * slaveConfig->address3.disable = true;
Kojto 148:fd96258d940d 755 * slaveConfig->busSpeed = kI2C_SlaveStandardMode;
Kojto 148:fd96258d940d 756 * @endcode
Kojto 148:fd96258d940d 757 *
Kojto 148:fd96258d940d 758 * After calling this function, override any settings to customize the configuration,
Kojto 148:fd96258d940d 759 * prior to initializing the master driver with I2C_SlaveInit(). Be sure to override at least the @a
Kojto 148:fd96258d940d 760 * address0.address member of the configuration structure with the desired slave address.
Kojto 148:fd96258d940d 761 *
Kojto 148:fd96258d940d 762 * @param[out] slaveConfig User provided configuration structure that is set to default values. Refer to
Kojto 148:fd96258d940d 763 * #i2c_slave_config_t.
Kojto 148:fd96258d940d 764 */
Kojto 148:fd96258d940d 765 void I2C_SlaveGetDefaultConfig(i2c_slave_config_t *slaveConfig);
Kojto 148:fd96258d940d 766
Kojto 148:fd96258d940d 767 /*!
Kojto 148:fd96258d940d 768 * @brief Initializes the I2C slave peripheral.
Kojto 148:fd96258d940d 769 *
Kojto 148:fd96258d940d 770 * This function enables the peripheral clock and initializes the I2C slave peripheral as described by the user
Kojto 148:fd96258d940d 771 * provided configuration.
Kojto 148:fd96258d940d 772 *
Kojto 148:fd96258d940d 773 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 774 * @param slaveConfig User provided peripheral configuration. Use I2C_SlaveGetDefaultConfig() to get a set of defaults
Kojto 148:fd96258d940d 775 * that you can override.
Kojto 148:fd96258d940d 776 * @param srcClock_Hz Frequency in Hertz of the I2C functional clock. Used to calculate CLKDIV value to provide
Kojto 148:fd96258d940d 777 * enough
Kojto 148:fd96258d940d 778 * data setup time for master when slave stretches the clock.
Kojto 148:fd96258d940d 779 */
Kojto 148:fd96258d940d 780 status_t I2C_SlaveInit(I2C_Type *base, const i2c_slave_config_t *slaveConfig, uint32_t srcClock_Hz);
Kojto 148:fd96258d940d 781
Kojto 148:fd96258d940d 782 /*!
Kojto 148:fd96258d940d 783 * @brief Configures Slave Address n register.
Kojto 148:fd96258d940d 784 *
Kojto 148:fd96258d940d 785 * This function writes new value to Slave Address register.
Kojto 148:fd96258d940d 786 *
Kojto 148:fd96258d940d 787 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 788 * @param addressRegister The module supports multiple address registers. The parameter determines which one shall be changed.
Kojto 148:fd96258d940d 789 * @param address The slave address to be stored to the address register for matching.
Kojto 148:fd96258d940d 790 * @param addressDisable Disable matching of the specified address register.
Kojto 148:fd96258d940d 791 */
Kojto 148:fd96258d940d 792 void I2C_SlaveSetAddress(I2C_Type *base,
Kojto 148:fd96258d940d 793 i2c_slave_address_register_t addressRegister,
Kojto 148:fd96258d940d 794 uint8_t address,
Kojto 148:fd96258d940d 795 bool addressDisable);
Kojto 148:fd96258d940d 796
Kojto 148:fd96258d940d 797 /*!
Kojto 148:fd96258d940d 798 * @brief Deinitializes the I2C slave peripheral.
Kojto 148:fd96258d940d 799 *
Kojto 148:fd96258d940d 800 * This function disables the I2C slave peripheral and gates the clock. It also performs a software
Kojto 148:fd96258d940d 801 * reset to restore the peripheral to reset conditions.
Kojto 148:fd96258d940d 802 *
Kojto 148:fd96258d940d 803 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 804 */
Kojto 148:fd96258d940d 805 void I2C_SlaveDeinit(I2C_Type *base);
Kojto 148:fd96258d940d 806
Kojto 148:fd96258d940d 807 /*!
Kojto 148:fd96258d940d 808 * @brief Enables or disables the I2C module as slave.
Kojto 148:fd96258d940d 809 *
Kojto 148:fd96258d940d 810 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 811 * @param enable True to enable or flase to disable.
Kojto 148:fd96258d940d 812 */
Kojto 148:fd96258d940d 813 static inline void I2C_SlaveEnable(I2C_Type *base, bool enable)
Kojto 148:fd96258d940d 814 {
Kojto 148:fd96258d940d 815 /* Set or clear the SLVEN bit in the CFG register. */
Kojto 148:fd96258d940d 816 base->CFG = I2C_CFG_SLVEN(enable);
Kojto 148:fd96258d940d 817 }
Kojto 148:fd96258d940d 818
Kojto 148:fd96258d940d 819 /*@}*/ /* end of Slave initialization and deinitialization */
Kojto 148:fd96258d940d 820
Kojto 148:fd96258d940d 821 /*! @name Slave status */
Kojto 148:fd96258d940d 822 /*@{*/
Kojto 148:fd96258d940d 823
Kojto 148:fd96258d940d 824 /*!
Kojto 148:fd96258d940d 825 * @brief Clears the I2C status flag state.
Kojto 148:fd96258d940d 826 *
Kojto 148:fd96258d940d 827 * The following status register flags can be cleared:
Kojto 148:fd96258d940d 828 * - slave deselected flag
Kojto 148:fd96258d940d 829 *
Kojto 148:fd96258d940d 830 * Attempts to clear other flags has no effect.
Kojto 148:fd96258d940d 831 *
Kojto 148:fd96258d940d 832 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 833 * @param statusMask A bitmask of status flags that are to be cleared. The mask is composed of
Kojto 148:fd96258d940d 834 * #_i2c_slave_flags enumerators OR'd together. You may pass the result of a previous call to
Kojto 148:fd96258d940d 835 * I2C_SlaveGetStatusFlags().
Kojto 148:fd96258d940d 836 * @see _i2c_slave_flags.
Kojto 148:fd96258d940d 837 */
Kojto 148:fd96258d940d 838 static inline void I2C_SlaveClearStatusFlags(I2C_Type *base, uint32_t statusMask)
Kojto 148:fd96258d940d 839 {
Kojto 148:fd96258d940d 840 /* Allow clearing just slave status flags */
Kojto 148:fd96258d940d 841 base->STAT = statusMask & I2C_STAT_SLVDESEL_MASK;
Kojto 148:fd96258d940d 842 }
Kojto 148:fd96258d940d 843
Kojto 148:fd96258d940d 844 /*@}*/ /* end of Slave status */
Kojto 148:fd96258d940d 845
Kojto 148:fd96258d940d 846 /*! @name Slave bus operations */
Kojto 148:fd96258d940d 847 /*@{*/
Kojto 148:fd96258d940d 848
Kojto 148:fd96258d940d 849 /*!
Kojto 148:fd96258d940d 850 * @brief Performs a polling send transfer on the I2C bus.
Kojto 148:fd96258d940d 851 *
Kojto 148:fd96258d940d 852 * The function executes blocking address phase and blocking data phase.
Kojto 148:fd96258d940d 853 *
Kojto 148:fd96258d940d 854 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 855 * @param txBuff The pointer to the data to be transferred.
Kojto 148:fd96258d940d 856 * @param txSize The length in bytes of the data to be transferred.
Kojto 148:fd96258d940d 857 * @return kStatus_Success Data has been sent.
Kojto 148:fd96258d940d 858 * @return kStatus_Fail Unexpected slave state (master data write while master read from slave is expected).
Kojto 148:fd96258d940d 859 */
Kojto 148:fd96258d940d 860 status_t I2C_SlaveWriteBlocking(I2C_Type *base, const uint8_t *txBuff, size_t txSize);
Kojto 148:fd96258d940d 861
Kojto 148:fd96258d940d 862 /*!
Kojto 148:fd96258d940d 863 * @brief Performs a polling receive transfer on the I2C bus.
Kojto 148:fd96258d940d 864 *
Kojto 148:fd96258d940d 865 * The function executes blocking address phase and blocking data phase.
Kojto 148:fd96258d940d 866 *
Kojto 148:fd96258d940d 867 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 868 * @param rxBuff The pointer to the data to be transferred.
Kojto 148:fd96258d940d 869 * @param rxSize The length in bytes of the data to be transferred.
Kojto 148:fd96258d940d 870 * @return kStatus_Success Data has been received.
Kojto 148:fd96258d940d 871 * @return kStatus_Fail Unexpected slave state (master data read while master write to slave is expected).
Kojto 148:fd96258d940d 872 */
Kojto 148:fd96258d940d 873 status_t I2C_SlaveReadBlocking(I2C_Type *base, uint8_t *rxBuff, size_t rxSize);
Kojto 148:fd96258d940d 874
Kojto 148:fd96258d940d 875 /*@}*/ /* end of Slave bus operations */
Kojto 148:fd96258d940d 876
Kojto 148:fd96258d940d 877 /*! @name Slave non-blocking */
Kojto 148:fd96258d940d 878 /*@{*/
Kojto 148:fd96258d940d 879
Kojto 148:fd96258d940d 880 /*!
Kojto 148:fd96258d940d 881 * @brief Creates a new handle for the I2C slave non-blocking APIs.
Kojto 148:fd96258d940d 882 *
Kojto 148:fd96258d940d 883 * The creation of a handle is for use with the non-blocking APIs. Once a handle
Kojto 148:fd96258d940d 884 * is created, there is not a corresponding destroy handle. If the user wants to
Kojto 148:fd96258d940d 885 * terminate a transfer, the I2C_SlaveTransferAbort() API shall be called.
Kojto 148:fd96258d940d 886 *
Kojto 148:fd96258d940d 887 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 888 * @param[out] handle Pointer to the I2C slave driver handle.
Kojto 148:fd96258d940d 889 * @param callback User provided pointer to the asynchronous callback function.
Kojto 148:fd96258d940d 890 * @param userData User provided pointer to the application callback data.
Kojto 148:fd96258d940d 891 */
Kojto 148:fd96258d940d 892 void I2C_SlaveTransferCreateHandle(I2C_Type *base,
Kojto 148:fd96258d940d 893 i2c_slave_handle_t *handle,
Kojto 148:fd96258d940d 894 i2c_slave_transfer_callback_t callback,
Kojto 148:fd96258d940d 895 void *userData);
Kojto 148:fd96258d940d 896
Kojto 148:fd96258d940d 897 /*!
Kojto 148:fd96258d940d 898 * @brief Starts accepting slave transfers.
Kojto 148:fd96258d940d 899 *
Kojto 148:fd96258d940d 900 * Call this API after calling I2C_SlaveInit() and I2C_SlaveTransferCreateHandle() to start processing
Kojto 148:fd96258d940d 901 * transactions driven by an I2C master. The slave monitors the I2C bus and pass events to the
Kojto 148:fd96258d940d 902 * callback that was passed into the call to I2C_SlaveTransferCreateHandle(). The callback is always invoked
Kojto 148:fd96258d940d 903 * from the interrupt context.
Kojto 148:fd96258d940d 904 *
Kojto 148:fd96258d940d 905 * If no slave Tx transfer is busy, a master read from slave request invokes #kI2C_SlaveTransmitEvent callback.
Kojto 148:fd96258d940d 906 * If no slave Rx transfer is busy, a master write to slave request invokes #kI2C_SlaveReceiveEvent callback.
Kojto 148:fd96258d940d 907 *
Kojto 148:fd96258d940d 908 * The set of events received by the callback is customizable. To do so, set the @a eventMask parameter to
Kojto 148:fd96258d940d 909 * the OR'd combination of #i2c_slave_transfer_event_t enumerators for the events you wish to receive.
Kojto 148:fd96258d940d 910 * The #kI2C_SlaveTransmitEvent and #kI2C_SlaveReceiveEvent events are always enabled and do not need
Kojto 148:fd96258d940d 911 * to be included in the mask. Alternatively, you can pass 0 to get a default set of only the transmit and
Kojto 148:fd96258d940d 912 * receive events that are always enabled. In addition, the #kI2C_SlaveAllEvents constant is provided as
Kojto 148:fd96258d940d 913 * a convenient way to enable all events.
Kojto 148:fd96258d940d 914 *
Kojto 148:fd96258d940d 915 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 916 * @param handle Pointer to i2c_slave_handle_t structure which stores the transfer state.
Kojto 148:fd96258d940d 917 * @param eventMask Bit mask formed by OR'ing together #i2c_slave_transfer_event_t enumerators to specify
Kojto 148:fd96258d940d 918 * which events to send to the callback. Other accepted values are 0 to get a default set of
Kojto 148:fd96258d940d 919 * only the transmit and receive events, and #kI2C_SlaveAllEvents to enable all events.
Kojto 148:fd96258d940d 920 *
Kojto 148:fd96258d940d 921 * @retval kStatus_Success Slave transfers were successfully started.
Kojto 148:fd96258d940d 922 * @retval #kStatus_I2C_Busy Slave transfers have already been started on this handle.
Kojto 148:fd96258d940d 923 */
Kojto 148:fd96258d940d 924 status_t I2C_SlaveTransferNonBlocking(I2C_Type *base, i2c_slave_handle_t *handle, uint32_t eventMask);
Kojto 148:fd96258d940d 925
Kojto 148:fd96258d940d 926 /*!
Kojto 148:fd96258d940d 927 * @brief Starts accepting master read from slave requests.
Kojto 148:fd96258d940d 928 *
Kojto 148:fd96258d940d 929 * The function can be called in response to #kI2C_SlaveTransmitEvent callback to start a new slave Tx transfer
Kojto 148:fd96258d940d 930 * from within the transfer callback.
Kojto 148:fd96258d940d 931 *
Kojto 148:fd96258d940d 932 * The set of events received by the callback is customizable. To do so, set the @a eventMask parameter to
Kojto 148:fd96258d940d 933 * the OR'd combination of #i2c_slave_transfer_event_t enumerators for the events you wish to receive.
Kojto 148:fd96258d940d 934 * The #kI2C_SlaveTransmitEvent and #kI2C_SlaveReceiveEvent events are always enabled and do not need
Kojto 148:fd96258d940d 935 * to be included in the mask. Alternatively, you can pass 0 to get a default set of only the transmit and
Kojto 148:fd96258d940d 936 * receive events that are always enabled. In addition, the #kI2C_SlaveAllEvents constant is provided as
Kojto 148:fd96258d940d 937 * a convenient way to enable all events.
Kojto 148:fd96258d940d 938 *
Kojto 148:fd96258d940d 939 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 940 * @param transfer Pointer to #i2c_slave_transfer_t structure.
Kojto 148:fd96258d940d 941 * @param txData Pointer to data to send to master.
Kojto 148:fd96258d940d 942 * @param txSize Size of txData in bytes.
Kojto 148:fd96258d940d 943 * @param eventMask Bit mask formed by OR'ing together #i2c_slave_transfer_event_t enumerators to specify
Kojto 148:fd96258d940d 944 * which events to send to the callback. Other accepted values are 0 to get a default set of
Kojto 148:fd96258d940d 945 * only the transmit and receive events, and #kI2C_SlaveAllEvents to enable all events.
Kojto 148:fd96258d940d 946 *
Kojto 148:fd96258d940d 947 * @retval kStatus_Success Slave transfers were successfully started.
Kojto 148:fd96258d940d 948 * @retval #kStatus_I2C_Busy Slave transfers have already been started on this handle.
Kojto 148:fd96258d940d 949 */
Kojto 148:fd96258d940d 950 status_t I2C_SlaveSetSendBuffer(
Kojto 148:fd96258d940d 951 I2C_Type *base, volatile i2c_slave_transfer_t *transfer, const void *txData, size_t txSize, uint32_t eventMask);
Kojto 148:fd96258d940d 952
Kojto 148:fd96258d940d 953 /*!
Kojto 148:fd96258d940d 954 * @brief Starts accepting master write to slave requests.
Kojto 148:fd96258d940d 955 *
Kojto 148:fd96258d940d 956 * The function can be called in response to #kI2C_SlaveReceiveEvent callback to start a new slave Rx transfer
Kojto 148:fd96258d940d 957 * from within the transfer callback.
Kojto 148:fd96258d940d 958 *
Kojto 148:fd96258d940d 959 * The set of events received by the callback is customizable. To do so, set the @a eventMask parameter to
Kojto 148:fd96258d940d 960 * the OR'd combination of #i2c_slave_transfer_event_t enumerators for the events you wish to receive.
Kojto 148:fd96258d940d 961 * The #kI2C_SlaveTransmitEvent and #kI2C_SlaveReceiveEvent events are always enabled and do not need
Kojto 148:fd96258d940d 962 * to be included in the mask. Alternatively, you can pass 0 to get a default set of only the transmit and
Kojto 148:fd96258d940d 963 * receive events that are always enabled. In addition, the #kI2C_SlaveAllEvents constant is provided as
Kojto 148:fd96258d940d 964 * a convenient way to enable all events.
Kojto 148:fd96258d940d 965 *
Kojto 148:fd96258d940d 966 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 967 * @param transfer Pointer to #i2c_slave_transfer_t structure.
Kojto 148:fd96258d940d 968 * @param rxData Pointer to data to store data from master.
Kojto 148:fd96258d940d 969 * @param rxSize Size of rxData in bytes.
Kojto 148:fd96258d940d 970 * @param eventMask Bit mask formed by OR'ing together #i2c_slave_transfer_event_t enumerators to specify
Kojto 148:fd96258d940d 971 * which events to send to the callback. Other accepted values are 0 to get a default set of
Kojto 148:fd96258d940d 972 * only the transmit and receive events, and #kI2C_SlaveAllEvents to enable all events.
Kojto 148:fd96258d940d 973 *
Kojto 148:fd96258d940d 974 * @retval kStatus_Success Slave transfers were successfully started.
Kojto 148:fd96258d940d 975 * @retval #kStatus_I2C_Busy Slave transfers have already been started on this handle.
Kojto 148:fd96258d940d 976 */
Kojto 148:fd96258d940d 977 status_t I2C_SlaveSetReceiveBuffer(
Kojto 148:fd96258d940d 978 I2C_Type *base, volatile i2c_slave_transfer_t *transfer, void *rxData, size_t rxSize, uint32_t eventMask);
Kojto 148:fd96258d940d 979
Kojto 148:fd96258d940d 980 /*!
Kojto 148:fd96258d940d 981 * @brief Returns the slave address sent by the I2C master.
Kojto 148:fd96258d940d 982 *
Kojto 148:fd96258d940d 983 * This function should only be called from the address match event callback #kI2C_SlaveAddressMatchEvent.
Kojto 148:fd96258d940d 984 *
Kojto 148:fd96258d940d 985 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 986 * @param transfer The I2C slave transfer.
Kojto 148:fd96258d940d 987 * @return The 8-bit address matched by the I2C slave. Bit 0 contains the R/w direction bit, and
Kojto 148:fd96258d940d 988 * the 7-bit slave address is in the upper 7 bits.
Kojto 148:fd96258d940d 989 */
Kojto 148:fd96258d940d 990 static inline uint32_t I2C_SlaveGetReceivedAddress(I2C_Type *base, volatile i2c_slave_transfer_t *transfer)
Kojto 148:fd96258d940d 991 {
Kojto 148:fd96258d940d 992 return transfer->receivedAddress;
Kojto 148:fd96258d940d 993 }
Kojto 148:fd96258d940d 994
Kojto 148:fd96258d940d 995 /*!
Kojto 148:fd96258d940d 996 * @brief Aborts the slave non-blocking transfers.
Kojto 148:fd96258d940d 997 * @note This API could be called at any time to stop slave for handling the bus events.
Kojto 148:fd96258d940d 998 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 999 * @param handle Pointer to i2c_slave_handle_t structure which stores the transfer state.
Kojto 148:fd96258d940d 1000 * @retval kStatus_Success
Kojto 148:fd96258d940d 1001 * @retval #kStatus_I2C_Idle
Kojto 148:fd96258d940d 1002 */
Kojto 148:fd96258d940d 1003 void I2C_SlaveTransferAbort(I2C_Type *base, i2c_slave_handle_t *handle);
Kojto 148:fd96258d940d 1004
Kojto 148:fd96258d940d 1005 /*!
Kojto 148:fd96258d940d 1006 * @brief Gets the slave transfer remaining bytes during a interrupt non-blocking transfer.
Kojto 148:fd96258d940d 1007 *
Kojto 148:fd96258d940d 1008 * @param base I2C base pointer.
Kojto 148:fd96258d940d 1009 * @param handle pointer to i2c_slave_handle_t structure.
Kojto 148:fd96258d940d 1010 * @param count Number of bytes transferred so far by the non-blocking transaction.
Kojto 148:fd96258d940d 1011 * @retval kStatus_InvalidArgument count is Invalid.
Kojto 148:fd96258d940d 1012 * @retval kStatus_Success Successfully return the count.
Kojto 148:fd96258d940d 1013 */
Kojto 148:fd96258d940d 1014 status_t I2C_SlaveTransferGetCount(I2C_Type *base, i2c_slave_handle_t *handle, size_t *count);
Kojto 148:fd96258d940d 1015
Kojto 148:fd96258d940d 1016 /*@}*/ /* end of Slave non-blocking */
Kojto 148:fd96258d940d 1017
Kojto 148:fd96258d940d 1018 /*! @name Slave IRQ handler */
Kojto 148:fd96258d940d 1019 /*@{*/
Kojto 148:fd96258d940d 1020
Kojto 148:fd96258d940d 1021 /*!
Kojto 148:fd96258d940d 1022 * @brief Reusable routine to handle slave interrupts.
Kojto 148:fd96258d940d 1023 * @note This function does not need to be called unless you are reimplementing the
Kojto 148:fd96258d940d 1024 * non blocking API's interrupt handler routines to add special functionality.
Kojto 148:fd96258d940d 1025 * @param base The I2C peripheral base address.
Kojto 148:fd96258d940d 1026 * @param handle Pointer to i2c_slave_handle_t structure which stores the transfer state.
Kojto 148:fd96258d940d 1027 */
Kojto 148:fd96258d940d 1028 void I2C_SlaveTransferHandleIRQ(I2C_Type *base, i2c_slave_handle_t *handle);
Kojto 148:fd96258d940d 1029
Kojto 148:fd96258d940d 1030 /*@}*/ /* end of Slave IRQ handler */
Kojto 148:fd96258d940d 1031
Kojto 148:fd96258d940d 1032 /*! @} */ /* end of i2c_slave_driver */
Kojto 148:fd96258d940d 1033
Kojto 148:fd96258d940d 1034 #if defined(__cplusplus)
Kojto 148:fd96258d940d 1035 }
Kojto 148:fd96258d940d 1036 #endif
Kojto 148:fd96258d940d 1037
Kojto 148:fd96258d940d 1038 #endif /* _FSL_I2C_H_ */