mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Apr 03 11:45:06 2014 +0100
Revision:
149:1fb5f62b92bd
Parent:
targets/hal/TARGET_Freescale/TARGET_KSDK_MCUS/TARGET_KSDK_CODE/hal/i2c/fsl_i2c_hal.h@146:f64d43ff0c18
Child:
324:406fd2029f23
Synchronized with git revision 220c0bb39ceee40016e1e86350c058963d01ed42

Full URL: https://github.com/mbedmicro/mbed/commit/220c0bb39ceee40016e1e86350c058963d01ed42/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 146:f64d43ff0c18 1 /*
mbed_official 146:f64d43ff0c18 2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
mbed_official 146:f64d43ff0c18 3 * All rights reserved.
mbed_official 146:f64d43ff0c18 4 *
mbed_official 146:f64d43ff0c18 5 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 146:f64d43ff0c18 6 * are permitted provided that the following conditions are met:
mbed_official 146:f64d43ff0c18 7 *
mbed_official 146:f64d43ff0c18 8 * o Redistributions of source code must retain the above copyright notice, this list
mbed_official 146:f64d43ff0c18 9 * of conditions and the following disclaimer.
mbed_official 146:f64d43ff0c18 10 *
mbed_official 146:f64d43ff0c18 11 * o Redistributions in binary form must reproduce the above copyright notice, this
mbed_official 146:f64d43ff0c18 12 * list of conditions and the following disclaimer in the documentation and/or
mbed_official 146:f64d43ff0c18 13 * other materials provided with the distribution.
mbed_official 146:f64d43ff0c18 14 *
mbed_official 146:f64d43ff0c18 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
mbed_official 146:f64d43ff0c18 16 * contributors may be used to endorse or promote products derived from this
mbed_official 146:f64d43ff0c18 17 * software without specific prior written permission.
mbed_official 146:f64d43ff0c18 18 *
mbed_official 146:f64d43ff0c18 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
mbed_official 146:f64d43ff0c18 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
mbed_official 146:f64d43ff0c18 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 146:f64d43ff0c18 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
mbed_official 146:f64d43ff0c18 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
mbed_official 146:f64d43ff0c18 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mbed_official 146:f64d43ff0c18 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
mbed_official 146:f64d43ff0c18 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
mbed_official 146:f64d43ff0c18 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
mbed_official 146:f64d43ff0c18 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 146:f64d43ff0c18 29 */
mbed_official 146:f64d43ff0c18 30 #if !defined(__FSL_I2C_HAL_H__)
mbed_official 146:f64d43ff0c18 31 #define __FSL_I2C_HAL_H__
mbed_official 146:f64d43ff0c18 32
mbed_official 146:f64d43ff0c18 33 #include <assert.h>
mbed_official 146:f64d43ff0c18 34 #include <stdbool.h>
mbed_official 146:f64d43ff0c18 35 #include "fsl_i2c_features.h"
mbed_official 146:f64d43ff0c18 36 #include "fsl_device_registers.h"
mbed_official 146:f64d43ff0c18 37
mbed_official 146:f64d43ff0c18 38 /*!
mbed_official 146:f64d43ff0c18 39 * @addtogroup i2c_hal
mbed_official 146:f64d43ff0c18 40 * @{
mbed_official 146:f64d43ff0c18 41 */
mbed_official 146:f64d43ff0c18 42
mbed_official 146:f64d43ff0c18 43 /*******************************************************************************
mbed_official 146:f64d43ff0c18 44 * Definitions
mbed_official 146:f64d43ff0c18 45 ******************************************************************************/
mbed_official 146:f64d43ff0c18 46
mbed_official 146:f64d43ff0c18 47 /*! @brief I2C status return codes*/
mbed_official 146:f64d43ff0c18 48 typedef enum _i2c_status
mbed_official 146:f64d43ff0c18 49 {
mbed_official 146:f64d43ff0c18 50 kStatus_I2C_Success = 0,
mbed_official 146:f64d43ff0c18 51 kStatus_I2C_OutOfRange,
mbed_official 146:f64d43ff0c18 52 kStatus_I2C_InvalidArgument,
mbed_official 146:f64d43ff0c18 53 kStatus_I2C_Fail,
mbed_official 146:f64d43ff0c18 54 kStatus_I2C_Busy, /*!< The master is already performing a transfer.*/
mbed_official 146:f64d43ff0c18 55 kStatus_I2C_Timeout, /*!< The transfer timed out.*/
mbed_official 146:f64d43ff0c18 56 kStatus_I2C_ReceivedNak, /*!< The slave device sent a NAK in response to a byte.*/
mbed_official 146:f64d43ff0c18 57 kStatus_I2C_SlaveTxUnderrun, /*!< I2C Slave TX Underrun error.*/
mbed_official 146:f64d43ff0c18 58 kStatus_I2C_SlaveRxOverrun, /*!< I2C Slave RX Overrun error.*/
mbed_official 146:f64d43ff0c18 59 kStatus_I2C_AribtrationLost, /*!< I2C Arbitration Lost error.*/
mbed_official 146:f64d43ff0c18 60 } i2c_status_t;
mbed_official 146:f64d43ff0c18 61
mbed_official 146:f64d43ff0c18 62 /*! @brief Direction of master and slave transfers*/
mbed_official 146:f64d43ff0c18 63 typedef enum _i2c_transmit_receive_mode {
mbed_official 146:f64d43ff0c18 64 kI2CReceive = 0, /*!< Master and slave receive.*/
mbed_official 146:f64d43ff0c18 65 kI2CTransmit = 1 /*!< Master and slave transmit.*/
mbed_official 146:f64d43ff0c18 66 } i2c_transmit_receive_mode_t;
mbed_official 146:f64d43ff0c18 67
mbed_official 146:f64d43ff0c18 68 /*!
mbed_official 146:f64d43ff0c18 69 * @brief I2C module configuration
mbed_official 146:f64d43ff0c18 70 *
mbed_official 146:f64d43ff0c18 71 * Pass an instance of this structure to the i2c_hal_init() to configure the entire I2C peripheral
mbed_official 146:f64d43ff0c18 72 * in a single function call.
mbed_official 146:f64d43ff0c18 73 */
mbed_official 146:f64d43ff0c18 74 typedef struct I2CConfig {
mbed_official 146:f64d43ff0c18 75 bool enableModule; /*!< Whether the I2C peripheral operation is enabled.*/
mbed_official 146:f64d43ff0c18 76 uint32_t baudRate_kbps; /*!< Requested baud rate in kilobits per second, for example, 100 or 400. Pass zero to not set the baud rate.*/
mbed_official 146:f64d43ff0c18 77 bool useIndependentSlaveBaud; /*!< Enables independent slave mode baud rate at maximum frequency.*/
mbed_official 146:f64d43ff0c18 78 bool enableInterrupt; /*!< Enable for the I2C interrupt.*/
mbed_official 146:f64d43ff0c18 79 bool enableDma; /*!< Enable DMA transfer signalling.*/
mbed_official 146:f64d43ff0c18 80 bool enableHighDrive; /*!< Enable high drive pin mode.*/
mbed_official 146:f64d43ff0c18 81 bool enableWakeup; /*!< Enable low power wakeup.*/
mbed_official 146:f64d43ff0c18 82 uint8_t glitchFilterWidth; /*!< Specify the glitch filter width in terms of bus clock cycles. Set this value to zero to disable the glitch filter.*/
mbed_official 146:f64d43ff0c18 83 uint16_t slaveAddress; /*!< 7-bit or 10-bit slave address.*/
mbed_official 146:f64d43ff0c18 84 uint8_t upperSlaveAddress; /*!< 7-bit upper slave address, or zero to disable. If 10-bit addresses are enabled, the top 3 bits are provided by the @a slaveAddress field.*/
mbed_official 146:f64d43ff0c18 85 bool use10bitSlaveAddress; /*!< Controls whether 10-bit slave addresses are enabled.*/
mbed_official 146:f64d43ff0c18 86 bool enableGeneralCallAddress; /*!< Enable general call address matching.*/
mbed_official 146:f64d43ff0c18 87 bool enableRangeAddressMatch; /*!< Determines if addresses between @a slaveAddress and @a upperSlaveAddress are matched. Both of those fields must be non-zero.*/
mbed_official 146:f64d43ff0c18 88
mbed_official 146:f64d43ff0c18 89 #if FSL_FEATURE_I2C_HAS_STOP_DETECT
mbed_official 146:f64d43ff0c18 90 bool enableStopModeHoldoff; /*!< Option to hold off CPU low power stop mode until the current byte transfer is complete.*/
mbed_official 146:f64d43ff0c18 91 bool enableBusStopInterrupt; /*!< Enable for the bus stop detection interrupt.*/
mbed_official 146:f64d43ff0c18 92 #endif /* FSL_FEATURE_I2C_HAS_STOP_DETECT*/
mbed_official 146:f64d43ff0c18 93 } i2c_config_t;
mbed_official 146:f64d43ff0c18 94
mbed_official 146:f64d43ff0c18 95 /*******************************************************************************
mbed_official 146:f64d43ff0c18 96 * API
mbed_official 146:f64d43ff0c18 97 ******************************************************************************/
mbed_official 146:f64d43ff0c18 98
mbed_official 146:f64d43ff0c18 99 #if defined(__cplusplus)
mbed_official 146:f64d43ff0c18 100 extern "C" {
mbed_official 146:f64d43ff0c18 101 #endif
mbed_official 146:f64d43ff0c18 102
mbed_official 146:f64d43ff0c18 103 /*! @name Module controls*/
mbed_official 146:f64d43ff0c18 104 /*@{*/
mbed_official 146:f64d43ff0c18 105
mbed_official 146:f64d43ff0c18 106 /*!
mbed_official 146:f64d43ff0c18 107 * @brief Initializes and configures the I2C peripheral.
mbed_official 146:f64d43ff0c18 108 *
mbed_official 146:f64d43ff0c18 109 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 110 * @param config Pointer to the configuration settings
mbed_official 146:f64d43ff0c18 111 * @param sourceClockInHz I2C source input clock in Hertz.
mbed_official 146:f64d43ff0c18 112 */
mbed_official 146:f64d43ff0c18 113 void i2c_hal_init(uint32_t instance, const i2c_config_t * config, uint32_t sourceClockInHz);
mbed_official 146:f64d43ff0c18 114
mbed_official 146:f64d43ff0c18 115 /*!
mbed_official 146:f64d43ff0c18 116 * @brief Restores the I2C peripheral to reset state.
mbed_official 146:f64d43ff0c18 117 *
mbed_official 146:f64d43ff0c18 118 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 119 */
mbed_official 146:f64d43ff0c18 120 void i2c_hal_reset(uint32_t instance);
mbed_official 146:f64d43ff0c18 121
mbed_official 146:f64d43ff0c18 122 /*!
mbed_official 146:f64d43ff0c18 123 * @brief Enables the I2C module operation.
mbed_official 146:f64d43ff0c18 124 *
mbed_official 146:f64d43ff0c18 125 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 126 */
mbed_official 146:f64d43ff0c18 127 static inline void i2c_hal_enable(uint32_t instance)
mbed_official 146:f64d43ff0c18 128 {
mbed_official 146:f64d43ff0c18 129 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 130 HW_I2C_C1_SET(instance, BM_I2C_C1_IICEN);
mbed_official 146:f64d43ff0c18 131 }
mbed_official 146:f64d43ff0c18 132
mbed_official 146:f64d43ff0c18 133 /*!
mbed_official 146:f64d43ff0c18 134 * @brief Disables the I2C module operation.
mbed_official 146:f64d43ff0c18 135 *
mbed_official 146:f64d43ff0c18 136 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 137 */
mbed_official 146:f64d43ff0c18 138 static inline void i2c_hal_disable(uint32_t instance)
mbed_official 146:f64d43ff0c18 139 {
mbed_official 146:f64d43ff0c18 140 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 141 HW_I2C_C1_CLR(instance, BM_I2C_C1_IICEN);
mbed_official 146:f64d43ff0c18 142 }
mbed_official 146:f64d43ff0c18 143
mbed_official 146:f64d43ff0c18 144 /*@}*/
mbed_official 146:f64d43ff0c18 145
mbed_official 146:f64d43ff0c18 146 /*! @name DMA*/
mbed_official 146:f64d43ff0c18 147 /*@{*/
mbed_official 146:f64d43ff0c18 148
mbed_official 146:f64d43ff0c18 149 /*!
mbed_official 146:f64d43ff0c18 150 * @brief Enables or disables the DMA support.
mbed_official 146:f64d43ff0c18 151 *
mbed_official 146:f64d43ff0c18 152 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 153 * @param enable Pass true to enable DMA transfer signalling
mbed_official 146:f64d43ff0c18 154 */
mbed_official 146:f64d43ff0c18 155 static inline void i2c_hal_set_dma_enable(uint32_t instance, bool enable)
mbed_official 146:f64d43ff0c18 156 {
mbed_official 146:f64d43ff0c18 157 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 158 BW_I2C_C1_DMAEN(instance, (uint8_t)enable);
mbed_official 146:f64d43ff0c18 159 }
mbed_official 146:f64d43ff0c18 160
mbed_official 146:f64d43ff0c18 161 /*@}*/
mbed_official 146:f64d43ff0c18 162
mbed_official 146:f64d43ff0c18 163 /*! @name Pin functions*/
mbed_official 146:f64d43ff0c18 164 /*@{*/
mbed_official 146:f64d43ff0c18 165
mbed_official 146:f64d43ff0c18 166 /*!
mbed_official 146:f64d43ff0c18 167 * @brief Controls the drive capability of the I2C pads.
mbed_official 146:f64d43ff0c18 168 *
mbed_official 146:f64d43ff0c18 169 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 170 * @param enable Passing true will enable high drive mode of the I2C pads. False sets normal
mbed_official 146:f64d43ff0c18 171 * drive mode.
mbed_official 146:f64d43ff0c18 172 */
mbed_official 146:f64d43ff0c18 173 static inline void i2c_hal_set_high_drive(uint32_t instance, bool enable)
mbed_official 146:f64d43ff0c18 174 {
mbed_official 146:f64d43ff0c18 175 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 176 BW_I2C_C2_HDRS(instance, (uint8_t)enable);
mbed_official 146:f64d43ff0c18 177 }
mbed_official 146:f64d43ff0c18 178
mbed_official 146:f64d43ff0c18 179 /*!
mbed_official 146:f64d43ff0c18 180 * @brief Controls the width of the programmable glitch filter.
mbed_official 146:f64d43ff0c18 181 *
mbed_official 146:f64d43ff0c18 182 * Controls the width of the glitch, in terms of bus clock cycles, that the filter must absorb.
mbed_official 146:f64d43ff0c18 183 * The filter does not allow any glitch whose size is less than or equal to this width setting,
mbed_official 146:f64d43ff0c18 184 * to pass.
mbed_official 146:f64d43ff0c18 185 *
mbed_official 146:f64d43ff0c18 186 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 187 * @param glitchWidth Maximum width in bus clock cycles of the glitches that is filtered.
mbed_official 146:f64d43ff0c18 188 * Pass zero to disable the glitch filter.
mbed_official 146:f64d43ff0c18 189 */
mbed_official 146:f64d43ff0c18 190 static inline void i2c_hal_set_glitch_filter(uint32_t instance, uint8_t glitchWidth)
mbed_official 146:f64d43ff0c18 191 {
mbed_official 146:f64d43ff0c18 192 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 193 BW_I2C_FLT_FLT(instance, glitchWidth);
mbed_official 146:f64d43ff0c18 194 }
mbed_official 146:f64d43ff0c18 195
mbed_official 146:f64d43ff0c18 196 /*@}*/
mbed_official 146:f64d43ff0c18 197
mbed_official 146:f64d43ff0c18 198 /*! @name Low power*/
mbed_official 146:f64d43ff0c18 199 /*@{*/
mbed_official 146:f64d43ff0c18 200
mbed_official 146:f64d43ff0c18 201 /*!
mbed_official 146:f64d43ff0c18 202 * @brief Controls the I2C wakeup enable.
mbed_official 146:f64d43ff0c18 203 *
mbed_official 146:f64d43ff0c18 204 * The I2C module can wake the MCU from low power mode with no peripheral bus running when
mbed_official 146:f64d43ff0c18 205 * slave address matching occurs.
mbed_official 146:f64d43ff0c18 206 *
mbed_official 146:f64d43ff0c18 207 * @param instance The I2C peripheral instance number.
mbed_official 146:f64d43ff0c18 208 * @param enable true - Enables the wakeup function in low power mode.<br>
mbed_official 146:f64d43ff0c18 209 * false - Normal operation. No interrupt is generated when address matching in
mbed_official 146:f64d43ff0c18 210 * low power mode.
mbed_official 146:f64d43ff0c18 211 */
mbed_official 146:f64d43ff0c18 212 static inline void i2c_hal_set_wakeup_enable(uint32_t instance, bool enable)
mbed_official 146:f64d43ff0c18 213 {
mbed_official 146:f64d43ff0c18 214 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 215 BW_I2C_C1_WUEN(instance, (uint8_t)enable);
mbed_official 146:f64d43ff0c18 216 }
mbed_official 146:f64d43ff0c18 217
mbed_official 146:f64d43ff0c18 218 #if FSL_FEATURE_I2C_HAS_STOP_HOLD_OFF
mbed_official 146:f64d43ff0c18 219 /*!
mbed_official 146:f64d43ff0c18 220 * @brief Controls the stop mode hold off.
mbed_official 146:f64d43ff0c18 221 *
mbed_official 146:f64d43ff0c18 222 * This function lets you enable the hold off entry to low power stop mode when any data transmission
mbed_official 146:f64d43ff0c18 223 * or reception is occurring.
mbed_official 146:f64d43ff0c18 224 *
mbed_official 146:f64d43ff0c18 225 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 226 * @param enable false - Stop hold off is disabled. The MCU's entry to stop mode is not gated.<br>
mbed_official 146:f64d43ff0c18 227 * true - Stop hold off is enabled.
mbed_official 146:f64d43ff0c18 228 */
mbed_official 146:f64d43ff0c18 229
mbed_official 146:f64d43ff0c18 230 static inline void i2c_hal_set_stop_holdoff(uint32_t instance, bool enable)
mbed_official 146:f64d43ff0c18 231 {
mbed_official 146:f64d43ff0c18 232 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 233 BW_I2C_FLT_SHEN(instance, (uint8_t)enable);
mbed_official 146:f64d43ff0c18 234 }
mbed_official 146:f64d43ff0c18 235 #endif /* FSL_FEATURE_I2C_HAS_STOP_HOLD_OFF*/
mbed_official 146:f64d43ff0c18 236
mbed_official 146:f64d43ff0c18 237 /*@}*/
mbed_official 146:f64d43ff0c18 238
mbed_official 146:f64d43ff0c18 239 /*! @name Baud rate*/
mbed_official 146:f64d43ff0c18 240 /*@{*/
mbed_official 146:f64d43ff0c18 241
mbed_official 146:f64d43ff0c18 242 /*!
mbed_official 146:f64d43ff0c18 243 * brief Returns the maximum supported baud rate in kilohertz.
mbed_official 146:f64d43ff0c18 244 *
mbed_official 146:f64d43ff0c18 245 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 246 * @param sourceClockInHz I2C source input clock in Hertz
mbed_official 146:f64d43ff0c18 247 * @return The maximum baud rate in kilohertz
mbed_official 146:f64d43ff0c18 248 */
mbed_official 146:f64d43ff0c18 249 uint32_t i2c_hal_get_max_baud(uint32_t instance, uint32_t sourceClockInHz);
mbed_official 146:f64d43ff0c18 250
mbed_official 146:f64d43ff0c18 251 /*!
mbed_official 146:f64d43ff0c18 252 * @brief Sets the I2C bus frequency for master transactions.
mbed_official 146:f64d43ff0c18 253 *
mbed_official 146:f64d43ff0c18 254 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 255 * @param sourceClockInHz I2C source input clock in Hertz
mbed_official 146:f64d43ff0c18 256 * @param kbps Requested bus frequency in kilohertz. Common values are either 100 or 400.
mbed_official 146:f64d43ff0c18 257 * @param absoluteError_Hz If this parameter is not NULL, it is filled in with the
mbed_official 146:f64d43ff0c18 258 * difference in Hertz between the requested bus frequency and the closest frequency
mbed_official 146:f64d43ff0c18 259 * possible given available divider values.
mbed_official 146:f64d43ff0c18 260 *
mbed_official 146:f64d43ff0c18 261 * @retval kStatus_Success The baud rate was changed successfully. However, there is no
mbed_official 146:f64d43ff0c18 262 * guarantee on the minimum error. If you want to ensure that the baud was set to within
mbed_official 146:f64d43ff0c18 263 * a certain error, then use the @a absoluteError_Hz parameter.
mbed_official 146:f64d43ff0c18 264 * @retval kStatus_OutOfRange The requested baud rate was not within the range of rates
mbed_official 146:f64d43ff0c18 265 * supported by the peripheral.
mbed_official 146:f64d43ff0c18 266 */
mbed_official 146:f64d43ff0c18 267 i2c_status_t i2c_hal_set_baud(uint32_t instance, uint32_t sourceClockInHz, uint32_t kbps,
mbed_official 146:f64d43ff0c18 268 uint32_t * absoluteError_Hz);
mbed_official 146:f64d43ff0c18 269
mbed_official 146:f64d43ff0c18 270 /*!
mbed_official 146:f64d43ff0c18 271 * @brief Sets the I2C baud rate multiplier and table entry.
mbed_official 146:f64d43ff0c18 272 *
mbed_official 146:f64d43ff0c18 273 * Use this function to set the I2C bus frequency register values directly, if they are
mbed_official 146:f64d43ff0c18 274 * known in advance.
mbed_official 146:f64d43ff0c18 275 *
mbed_official 146:f64d43ff0c18 276 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 277 * @param mult Value of the MULT bitfield, ranging from 0-2.
mbed_official 146:f64d43ff0c18 278 * @param icr The ICR bitfield value, which is the index into an internal table in the I2C
mbed_official 146:f64d43ff0c18 279 * hardware that selects the baud rate divisor and SCL hold time.
mbed_official 146:f64d43ff0c18 280 */
mbed_official 146:f64d43ff0c18 281 static inline void i2c_hal_set_baud_icr(uint32_t instance, uint8_t mult, uint8_t icr)
mbed_official 146:f64d43ff0c18 282 {
mbed_official 146:f64d43ff0c18 283 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 284 HW_I2C_F_WR(instance, BF_I2C_F_MULT(mult) | BF_I2C_F_ICR(icr));
mbed_official 146:f64d43ff0c18 285 }
mbed_official 146:f64d43ff0c18 286
mbed_official 146:f64d43ff0c18 287 /*!
mbed_official 146:f64d43ff0c18 288 * @brief Slave baud rate control
mbed_official 146:f64d43ff0c18 289 *
mbed_official 146:f64d43ff0c18 290 * Enables an independent slave mode baud rate at the maximum frequency. This forces clock stretching
mbed_official 146:f64d43ff0c18 291 * on the SCL in very fast I2C modes.
mbed_official 146:f64d43ff0c18 292 *
mbed_official 146:f64d43ff0c18 293 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 294 * @param enable true - Slave baud rate is independent of the master baud rate;<br>
mbed_official 146:f64d43ff0c18 295 * false - The slave baud rate follows the master baud rate and clock stretching may occur.
mbed_official 146:f64d43ff0c18 296 */
mbed_official 146:f64d43ff0c18 297 static inline void i2c_hal_set_independent_slave_baud(uint32_t instance, bool enable)
mbed_official 146:f64d43ff0c18 298 {
mbed_official 146:f64d43ff0c18 299 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 300 BW_I2C_C2_SBRC(instance, (uint8_t)enable);
mbed_official 146:f64d43ff0c18 301 }
mbed_official 146:f64d43ff0c18 302
mbed_official 146:f64d43ff0c18 303 /*@}*/
mbed_official 146:f64d43ff0c18 304
mbed_official 146:f64d43ff0c18 305 /*! @name Bus operations*/
mbed_official 146:f64d43ff0c18 306 /*@{*/
mbed_official 146:f64d43ff0c18 307
mbed_official 146:f64d43ff0c18 308 /*!
mbed_official 146:f64d43ff0c18 309 * @brief Sends a START or a Repeated START signal on the I2C bus.
mbed_official 146:f64d43ff0c18 310 *
mbed_official 146:f64d43ff0c18 311 * This function is used to initiate a new master mode transfer by sending the START signal. It
mbed_official 146:f64d43ff0c18 312 * is also used to send a Repeated START signal when a transfer is already in progress.
mbed_official 146:f64d43ff0c18 313 *
mbed_official 146:f64d43ff0c18 314 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 315 */
mbed_official 146:f64d43ff0c18 316 void i2c_hal_send_start(uint32_t instance);
mbed_official 146:f64d43ff0c18 317
mbed_official 146:f64d43ff0c18 318 /*!
mbed_official 146:f64d43ff0c18 319 * @brief Sends a STOP signal on the I2C bus.
mbed_official 146:f64d43ff0c18 320 *
mbed_official 146:f64d43ff0c18 321 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 322 */
mbed_official 146:f64d43ff0c18 323 static inline void i2c_hal_send_stop(uint32_t instance)
mbed_official 146:f64d43ff0c18 324 {
mbed_official 146:f64d43ff0c18 325 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 326 assert(HW_I2C_C1(instance).B.MST == 1);
mbed_official 146:f64d43ff0c18 327 HW_I2C_C1_CLR(instance, BM_I2C_C1_MST | BM_I2C_C1_TX);
mbed_official 146:f64d43ff0c18 328 }
mbed_official 146:f64d43ff0c18 329
mbed_official 146:f64d43ff0c18 330 /*!
mbed_official 146:f64d43ff0c18 331 * @brief Selects either transmit or receive modes.
mbed_official 146:f64d43ff0c18 332 *
mbed_official 146:f64d43ff0c18 333 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 334 * @param mode Specifies either transmit mode or receive mode. The valid values are:
mbed_official 146:f64d43ff0c18 335 * - #kI2CTransmit
mbed_official 146:f64d43ff0c18 336 * - #kI2CReceive
mbed_official 146:f64d43ff0c18 337 */
mbed_official 146:f64d43ff0c18 338 static inline void i2c_hal_set_direction(uint32_t instance, i2c_transmit_receive_mode_t mode)
mbed_official 146:f64d43ff0c18 339 {
mbed_official 146:f64d43ff0c18 340 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 341 BW_I2C_C1_TX(instance, (uint8_t)mode);
mbed_official 146:f64d43ff0c18 342 }
mbed_official 146:f64d43ff0c18 343
mbed_official 146:f64d43ff0c18 344 /*!
mbed_official 146:f64d43ff0c18 345 * @brief Returns the currently selected transmit or receive mode.
mbed_official 146:f64d43ff0c18 346 *
mbed_official 146:f64d43ff0c18 347 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 348 * @retval #kI2CTransmit I2C is configured for master or slave transmit mode.
mbed_official 146:f64d43ff0c18 349 * @retval #kI2CReceive I2C is configured for master or slave receive mode.
mbed_official 146:f64d43ff0c18 350 */
mbed_official 146:f64d43ff0c18 351 static inline i2c_transmit_receive_mode_t i2c_hal_get_direction(uint32_t instance)
mbed_official 146:f64d43ff0c18 352 {
mbed_official 146:f64d43ff0c18 353 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 354 return HW_I2C_C1(instance).B.TX ? kI2CTransmit : kI2CReceive;
mbed_official 146:f64d43ff0c18 355 }
mbed_official 146:f64d43ff0c18 356
mbed_official 146:f64d43ff0c18 357 /*!
mbed_official 146:f64d43ff0c18 358 * @brief Causes an ACK to be sent on the bus.
mbed_official 146:f64d43ff0c18 359 *
mbed_official 146:f64d43ff0c18 360 * This function specifies that an ACK signal is sent in response to the next received byte.
mbed_official 146:f64d43ff0c18 361 *
mbed_official 146:f64d43ff0c18 362 * Note that the behavior of this function is changed when the I2C peripheral is placed in
mbed_official 146:f64d43ff0c18 363 * Fast ACK mode. In this case, this function causes an ACK signal to be sent in
mbed_official 146:f64d43ff0c18 364 * response to the current byte, rather than the next received byte.
mbed_official 146:f64d43ff0c18 365 *
mbed_official 146:f64d43ff0c18 366 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 367 */
mbed_official 146:f64d43ff0c18 368 static inline void i2c_hal_send_ack(uint32_t instance)
mbed_official 146:f64d43ff0c18 369 {
mbed_official 146:f64d43ff0c18 370 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 371 HW_I2C_C1_CLR(instance, BM_I2C_C1_TXAK);
mbed_official 146:f64d43ff0c18 372 }
mbed_official 146:f64d43ff0c18 373
mbed_official 146:f64d43ff0c18 374 /*!
mbed_official 146:f64d43ff0c18 375 * @brief Causes a NAK to be sent on the bus.
mbed_official 146:f64d43ff0c18 376 *
mbed_official 146:f64d43ff0c18 377 * This function specifies that a NAK signal is sent in response to the next received byte.
mbed_official 146:f64d43ff0c18 378 *
mbed_official 146:f64d43ff0c18 379 * Note that the behavior of this function is changed when the I2C peripheral is placed in the
mbed_official 146:f64d43ff0c18 380 * Fast ACK mode. In this case, this function causes an NAK signal to be sent in
mbed_official 146:f64d43ff0c18 381 * response to the current byte, rather than the next received byte.
mbed_official 146:f64d43ff0c18 382 *
mbed_official 146:f64d43ff0c18 383 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 384 */
mbed_official 146:f64d43ff0c18 385 static inline void i2c_hal_send_nak(uint32_t instance)
mbed_official 146:f64d43ff0c18 386 {
mbed_official 146:f64d43ff0c18 387 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 388 HW_I2C_C1_SET(instance, BM_I2C_C1_TXAK);
mbed_official 146:f64d43ff0c18 389 }
mbed_official 146:f64d43ff0c18 390
mbed_official 146:f64d43ff0c18 391 /*@}*/
mbed_official 146:f64d43ff0c18 392
mbed_official 146:f64d43ff0c18 393 /*! @name Data transfer*/
mbed_official 146:f64d43ff0c18 394 /*@{*/
mbed_official 146:f64d43ff0c18 395
mbed_official 146:f64d43ff0c18 396 /*!
mbed_official 146:f64d43ff0c18 397 * @brief Returns the last byte of data read from the bus and initiate another read.
mbed_official 146:f64d43ff0c18 398 *
mbed_official 146:f64d43ff0c18 399 * In a master receive mode, calling this function initiates receiving the next byte of data.
mbed_official 146:f64d43ff0c18 400 *
mbed_official 146:f64d43ff0c18 401 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 402 * @return This function returns the last byte received while the I2C module is configured in master
mbed_official 146:f64d43ff0c18 403 * receive or slave receive mode.
mbed_official 146:f64d43ff0c18 404 */
mbed_official 146:f64d43ff0c18 405 static inline uint8_t i2c_hal_read(uint32_t instance)
mbed_official 146:f64d43ff0c18 406 {
mbed_official 146:f64d43ff0c18 407 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 408 return HW_I2C_D_RD(instance);
mbed_official 146:f64d43ff0c18 409 }
mbed_official 146:f64d43ff0c18 410
mbed_official 146:f64d43ff0c18 411 /*!
mbed_official 146:f64d43ff0c18 412 * @brief Writes one byte of data to the I2C bus.
mbed_official 146:f64d43ff0c18 413 *
mbed_official 146:f64d43ff0c18 414 * When this function is called in the master transmit mode, a data transfer is initiated. In slave
mbed_official 146:f64d43ff0c18 415 * mode, the same function is available after an address match occurs.
mbed_official 146:f64d43ff0c18 416 *
mbed_official 146:f64d43ff0c18 417 * In a master transmit mode, the first byte of data written following the start bit or repeated
mbed_official 146:f64d43ff0c18 418 * start bit is used for the address transfer and must consist of the slave address (in bits 7-1)
mbed_official 146:f64d43ff0c18 419 * concatenated with the required R/\#W bit (in position bit 0).
mbed_official 146:f64d43ff0c18 420 *
mbed_official 146:f64d43ff0c18 421 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 422 * @param data The byte of data to transmit
mbed_official 146:f64d43ff0c18 423 */
mbed_official 146:f64d43ff0c18 424 static inline void i2c_hal_write(uint32_t instance, uint8_t data)
mbed_official 146:f64d43ff0c18 425 {
mbed_official 146:f64d43ff0c18 426 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 427 HW_I2C_D_WR(instance, data);
mbed_official 146:f64d43ff0c18 428 }
mbed_official 146:f64d43ff0c18 429
mbed_official 146:f64d43ff0c18 430 /*@}*/
mbed_official 146:f64d43ff0c18 431
mbed_official 146:f64d43ff0c18 432 /*! @name Slave address*/
mbed_official 146:f64d43ff0c18 433 /*@{*/
mbed_official 146:f64d43ff0c18 434
mbed_official 146:f64d43ff0c18 435 /*!
mbed_official 146:f64d43ff0c18 436 * @brief Sets the primary 7-bit slave address.
mbed_official 146:f64d43ff0c18 437 *
mbed_official 146:f64d43ff0c18 438 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 439 * @param address The slave address in the upper 7 bits. Bit 0 of this value must be 0.
mbed_official 146:f64d43ff0c18 440 */
mbed_official 146:f64d43ff0c18 441 void i2c_hal_set_slave_address_7bit(uint32_t instance, uint8_t address);
mbed_official 146:f64d43ff0c18 442
mbed_official 146:f64d43ff0c18 443 /*!
mbed_official 146:f64d43ff0c18 444 * @brief Sets the primary slave address and enables 10-bit address mode.
mbed_official 146:f64d43ff0c18 445 *
mbed_official 146:f64d43ff0c18 446 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 447 * @param address The 10-bit slave address, in bits [10:1] of the value. Bit 0 must be 0.
mbed_official 146:f64d43ff0c18 448 */
mbed_official 146:f64d43ff0c18 449 void i2c_hal_set_slave_address_10bit(uint32_t instance, uint16_t address);
mbed_official 146:f64d43ff0c18 450
mbed_official 146:f64d43ff0c18 451 /*!
mbed_official 146:f64d43ff0c18 452 * @brief Controls whether the general call address is recognized.
mbed_official 146:f64d43ff0c18 453 *
mbed_official 146:f64d43ff0c18 454 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 455 * @param enable Whether to enable the general call address.
mbed_official 146:f64d43ff0c18 456 */
mbed_official 146:f64d43ff0c18 457 static inline void i2c_hal_set_general_call_enable(uint32_t instance, bool enable)
mbed_official 146:f64d43ff0c18 458 {
mbed_official 146:f64d43ff0c18 459 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 460 BW_I2C_C2_GCAEN(instance, (uint8_t)enable);
mbed_official 146:f64d43ff0c18 461 }
mbed_official 146:f64d43ff0c18 462
mbed_official 146:f64d43ff0c18 463 /*!
mbed_official 146:f64d43ff0c18 464 * @brief Enables or disables the slave address range matching.
mbed_official 146:f64d43ff0c18 465 *
mbed_official 146:f64d43ff0c18 466 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 467 * @param enable Pass true to enable the range address matching. You must also call the
mbed_official 146:f64d43ff0c18 468 * i2c_hal_set_upper_slave_address_7bit() to set the upper address.
mbed_official 146:f64d43ff0c18 469 */
mbed_official 146:f64d43ff0c18 470 static inline void i2c_hal_set_slave_range_address_enable(uint32_t instance, bool enable)
mbed_official 146:f64d43ff0c18 471 {
mbed_official 146:f64d43ff0c18 472 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 473 BW_I2C_C2_RMEN(instance, (uint8_t)enable);
mbed_official 146:f64d43ff0c18 474 }
mbed_official 146:f64d43ff0c18 475
mbed_official 146:f64d43ff0c18 476 /*!
mbed_official 146:f64d43ff0c18 477 * @brief Sets the upper slave address.
mbed_official 146:f64d43ff0c18 478 *
mbed_official 146:f64d43ff0c18 479 * This slave address is used as a secondary slave address. If range address
mbed_official 146:f64d43ff0c18 480 * matching is enabled, this slave address acts as the upper bound on the slave address
mbed_official 146:f64d43ff0c18 481 * range.
mbed_official 146:f64d43ff0c18 482 *
mbed_official 146:f64d43ff0c18 483 * This function sets only a 7-bit slave address. If 10-bit addressing was enabled by calling the
mbed_official 146:f64d43ff0c18 484 * i2c_hal_set_slave_address_10bit(), then the top 3 bits set with that function are also used
mbed_official 146:f64d43ff0c18 485 * with the address set with this function to form a 10-bit address.
mbed_official 146:f64d43ff0c18 486 *
mbed_official 146:f64d43ff0c18 487 * Passing 0 for the @a address parameter disables matching the upper slave address.
mbed_official 146:f64d43ff0c18 488 *
mbed_official 146:f64d43ff0c18 489 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 490 * @param address The upper slave address in the upper 7 bits. Bit 0 of this value must be 0.
mbed_official 146:f64d43ff0c18 491 * This address must be greater than the primary slave address that is set by
mbed_official 146:f64d43ff0c18 492 * calling the i2c_hal_set_slave_address_7bit().
mbed_official 146:f64d43ff0c18 493 */
mbed_official 146:f64d43ff0c18 494 static inline void i2c_hal_set_upper_slave_address_7bit(uint32_t instance, uint8_t address)
mbed_official 146:f64d43ff0c18 495 {
mbed_official 146:f64d43ff0c18 496 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 497 assert((address & 1) == 0);
mbed_official 146:f64d43ff0c18 498 assert((address == 0) || (address > HW_I2C_A1_RD(instance)));
mbed_official 146:f64d43ff0c18 499 HW_I2C_RA_WR(instance, address);
mbed_official 146:f64d43ff0c18 500 }
mbed_official 146:f64d43ff0c18 501
mbed_official 146:f64d43ff0c18 502 /*@}*/
mbed_official 146:f64d43ff0c18 503
mbed_official 146:f64d43ff0c18 504 /*! @name Status*/
mbed_official 146:f64d43ff0c18 505 /*@{*/
mbed_official 146:f64d43ff0c18 506
mbed_official 146:f64d43ff0c18 507 /*!
mbed_official 146:f64d43ff0c18 508 * @brief Returns whether the I2C module is in master mode.
mbed_official 146:f64d43ff0c18 509 *
mbed_official 146:f64d43ff0c18 510 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 511 * @retval true The module is in master mode, which implies it is also performing a transfer.
mbed_official 146:f64d43ff0c18 512 * @retval false The module is in slave mode.
mbed_official 146:f64d43ff0c18 513 */
mbed_official 146:f64d43ff0c18 514 static inline bool i2c_hal_is_master(uint32_t instance)
mbed_official 146:f64d43ff0c18 515 {
mbed_official 146:f64d43ff0c18 516 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 517 return (bool)HW_I2C_C1(instance).B.MST;
mbed_official 146:f64d43ff0c18 518 }
mbed_official 146:f64d43ff0c18 519
mbed_official 146:f64d43ff0c18 520 /*!
mbed_official 146:f64d43ff0c18 521 * @brief Gets the transfer complete flag.
mbed_official 146:f64d43ff0c18 522 *
mbed_official 146:f64d43ff0c18 523 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 524 * @retval true Transfer is complete.
mbed_official 146:f64d43ff0c18 525 * @retval false Transfer is in progress.
mbed_official 146:f64d43ff0c18 526 */
mbed_official 146:f64d43ff0c18 527 static inline bool i2c_hal_is_transfer_complete(uint32_t instance)
mbed_official 146:f64d43ff0c18 528 {
mbed_official 146:f64d43ff0c18 529 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 530 return (bool)HW_I2C_S(instance).B.TCF;
mbed_official 146:f64d43ff0c18 531 }
mbed_official 146:f64d43ff0c18 532
mbed_official 146:f64d43ff0c18 533 /*!
mbed_official 146:f64d43ff0c18 534 * @brief Returns whether the I2C slave was addressed.
mbed_official 146:f64d43ff0c18 535 *
mbed_official 146:f64d43ff0c18 536 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 537 * @retval true Addressed as slave.
mbed_official 146:f64d43ff0c18 538 * @retval false Not addressed.
mbed_official 146:f64d43ff0c18 539 */
mbed_official 146:f64d43ff0c18 540 static inline bool i2c_hal_is_addressed_as_slave(uint32_t instance)
mbed_official 146:f64d43ff0c18 541 {
mbed_official 146:f64d43ff0c18 542 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 543 return (bool)HW_I2C_S(instance).B.IAAS;
mbed_official 146:f64d43ff0c18 544 }
mbed_official 146:f64d43ff0c18 545
mbed_official 146:f64d43ff0c18 546 /*!
mbed_official 146:f64d43ff0c18 547 * @brief Determines whether the I2C bus is busy.
mbed_official 146:f64d43ff0c18 548 *
mbed_official 146:f64d43ff0c18 549 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 550 * @retval true Bus is busy.
mbed_official 146:f64d43ff0c18 551 * @retval false Bus is idle.
mbed_official 146:f64d43ff0c18 552 */
mbed_official 146:f64d43ff0c18 553 static inline bool i2c_hal_is_bus_busy(uint32_t instance)
mbed_official 146:f64d43ff0c18 554 {
mbed_official 146:f64d43ff0c18 555 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 556 return (bool)HW_I2C_S(instance).B.BUSY;
mbed_official 146:f64d43ff0c18 557 }
mbed_official 146:f64d43ff0c18 558
mbed_official 146:f64d43ff0c18 559 /*!
mbed_official 146:f64d43ff0c18 560 * @brief Returns whether the arbitration procedure was lost.
mbed_official 146:f64d43ff0c18 561 *
mbed_official 146:f64d43ff0c18 562 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 563 * @retval true Loss of arbitration
mbed_official 146:f64d43ff0c18 564 * @retval false Standard bus operation
mbed_official 146:f64d43ff0c18 565 */
mbed_official 146:f64d43ff0c18 566 static inline bool i2c_hal_was_arbitration_lost(uint32_t instance)
mbed_official 146:f64d43ff0c18 567 {
mbed_official 146:f64d43ff0c18 568 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 569 return (bool)HW_I2C_S(instance).B.ARBL;
mbed_official 146:f64d43ff0c18 570 }
mbed_official 146:f64d43ff0c18 571
mbed_official 146:f64d43ff0c18 572 /*!
mbed_official 146:f64d43ff0c18 573 * @brief Clears the arbitration lost flag.
mbed_official 146:f64d43ff0c18 574 *
mbed_official 146:f64d43ff0c18 575 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 576 */
mbed_official 146:f64d43ff0c18 577 static inline void i2c_hal_clear_arbitration_lost(uint32_t instance)
mbed_official 146:f64d43ff0c18 578 {
mbed_official 146:f64d43ff0c18 579 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 580 HW_I2C_S_WR(instance, BM_I2C_S_ARBL);
mbed_official 146:f64d43ff0c18 581 }
mbed_official 146:f64d43ff0c18 582
mbed_official 146:f64d43ff0c18 583 /*!
mbed_official 146:f64d43ff0c18 584 * @brief Get the range address match flag.
mbed_official 146:f64d43ff0c18 585 *
mbed_official 146:f64d43ff0c18 586 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 587 * @retval true Addressed as slave.
mbed_official 146:f64d43ff0c18 588 * @retval false Not addressed.
mbed_official 146:f64d43ff0c18 589 */
mbed_official 146:f64d43ff0c18 590 static inline bool i2c_hal_is_range_address_match(uint32_t instance)
mbed_official 146:f64d43ff0c18 591 {
mbed_official 146:f64d43ff0c18 592 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 593 return (bool)HW_I2C_S(instance).B.RAM;
mbed_official 146:f64d43ff0c18 594 }
mbed_official 146:f64d43ff0c18 595
mbed_official 146:f64d43ff0c18 596 /*!
mbed_official 146:f64d43ff0c18 597 * @brief Returns whether the I2C slave was addressed in read or write mode.
mbed_official 146:f64d43ff0c18 598 *
mbed_official 146:f64d43ff0c18 599 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 600 * @retval #kI2CReceive Slave receive, master writing to slave
mbed_official 146:f64d43ff0c18 601 * @retval #kI2CTransmit Slave transmit, master reading from slave
mbed_official 146:f64d43ff0c18 602 */
mbed_official 146:f64d43ff0c18 603 static inline i2c_transmit_receive_mode_t i2c_hal_get_slave_direction(uint32_t instance)
mbed_official 146:f64d43ff0c18 604 {
mbed_official 146:f64d43ff0c18 605 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 606 return HW_I2C_S(instance).B.SRW ? kI2CTransmit : kI2CReceive;
mbed_official 146:f64d43ff0c18 607 }
mbed_official 146:f64d43ff0c18 608
mbed_official 146:f64d43ff0c18 609 /*!
mbed_official 146:f64d43ff0c18 610 * @brief Returns whether an ACK was received after the last byte was transmitted.
mbed_official 146:f64d43ff0c18 611 *
mbed_official 146:f64d43ff0c18 612 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 613 * @retval true Acknowledges that the signal was received after the completion of one byte of data
mbed_official 146:f64d43ff0c18 614 * transmission on the bus.
mbed_official 146:f64d43ff0c18 615 * @retval false No acknowledgement of the signal is detected.
mbed_official 146:f64d43ff0c18 616 */
mbed_official 146:f64d43ff0c18 617 static inline bool i2c_hal_get_receive_ack(uint32_t instance)
mbed_official 146:f64d43ff0c18 618 {
mbed_official 146:f64d43ff0c18 619 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 620 return (bool)!(HW_I2C_S(instance).B.RXAK);
mbed_official 146:f64d43ff0c18 621 }
mbed_official 146:f64d43ff0c18 622
mbed_official 146:f64d43ff0c18 623 /*@}*/
mbed_official 146:f64d43ff0c18 624
mbed_official 146:f64d43ff0c18 625 /*! @name Interrupt*/
mbed_official 146:f64d43ff0c18 626 /*@{*/
mbed_official 146:f64d43ff0c18 627
mbed_official 146:f64d43ff0c18 628 /*!
mbed_official 146:f64d43ff0c18 629 * @brief Enables the I2C interrupt requests.
mbed_official 146:f64d43ff0c18 630 *
mbed_official 146:f64d43ff0c18 631 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 632 */
mbed_official 146:f64d43ff0c18 633 static inline void i2c_hal_enable_interrupt(uint32_t instance)
mbed_official 146:f64d43ff0c18 634 {
mbed_official 146:f64d43ff0c18 635 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 636 HW_I2C_C1_SET(instance, BM_I2C_C1_IICIE);
mbed_official 146:f64d43ff0c18 637 }
mbed_official 146:f64d43ff0c18 638
mbed_official 146:f64d43ff0c18 639 /*!
mbed_official 146:f64d43ff0c18 640 * @brief Disables the I2C interrupt requests.
mbed_official 146:f64d43ff0c18 641 *
mbed_official 146:f64d43ff0c18 642 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 643 */
mbed_official 146:f64d43ff0c18 644 static inline void i2c_hal_disable_interrupt(uint32_t instance)
mbed_official 146:f64d43ff0c18 645 {
mbed_official 146:f64d43ff0c18 646 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 647 HW_I2C_C1_CLR(instance, BM_I2C_C1_IICIE);
mbed_official 146:f64d43ff0c18 648 }
mbed_official 146:f64d43ff0c18 649
mbed_official 146:f64d43ff0c18 650 /*!
mbed_official 146:f64d43ff0c18 651 * @brief Returns whether the I2C interrupts are enabled.
mbed_official 146:f64d43ff0c18 652 *
mbed_official 146:f64d43ff0c18 653 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 654 * @retval true I2C interrupts are enabled.
mbed_official 146:f64d43ff0c18 655 * @retval false I2C interrupts are disabled.
mbed_official 146:f64d43ff0c18 656 */
mbed_official 146:f64d43ff0c18 657 static inline bool i2c_hal_is_interrupt_enabled(uint32_t instance)
mbed_official 146:f64d43ff0c18 658 {
mbed_official 146:f64d43ff0c18 659 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 660 return (bool)HW_I2C_C1(instance).B.IICIE;
mbed_official 146:f64d43ff0c18 661 }
mbed_official 146:f64d43ff0c18 662
mbed_official 146:f64d43ff0c18 663 /*!
mbed_official 146:f64d43ff0c18 664 * @brief Returns the current I2C interrupt flag.
mbed_official 146:f64d43ff0c18 665 *
mbed_official 146:f64d43ff0c18 666 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 667 * @retval true An interrupt is pending.
mbed_official 146:f64d43ff0c18 668 * @retval false No interrupt is pending.
mbed_official 146:f64d43ff0c18 669 */
mbed_official 146:f64d43ff0c18 670 static inline bool i2c_hal_get_interrupt_status(uint32_t instance)
mbed_official 146:f64d43ff0c18 671 {
mbed_official 146:f64d43ff0c18 672 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 673 return (bool)HW_I2C_S(instance).B.IICIF;
mbed_official 146:f64d43ff0c18 674 }
mbed_official 146:f64d43ff0c18 675
mbed_official 146:f64d43ff0c18 676 /*!
mbed_official 146:f64d43ff0c18 677 * @brief Clears the I2C interrupt if set.
mbed_official 146:f64d43ff0c18 678 *
mbed_official 146:f64d43ff0c18 679 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 680 */
mbed_official 146:f64d43ff0c18 681 static inline void i2c_hal_clear_interrupt(uint32_t instance)
mbed_official 146:f64d43ff0c18 682 {
mbed_official 146:f64d43ff0c18 683 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 684 HW_I2C_S_SET(instance, BM_I2C_S_IICIF);
mbed_official 146:f64d43ff0c18 685 }
mbed_official 146:f64d43ff0c18 686
mbed_official 146:f64d43ff0c18 687 /*@}*/
mbed_official 146:f64d43ff0c18 688
mbed_official 146:f64d43ff0c18 689 #if FSL_FEATURE_I2C_HAS_STOP_DETECT
mbed_official 146:f64d43ff0c18 690
mbed_official 146:f64d43ff0c18 691 /*! @name Bus stop detection status*/
mbed_official 146:f64d43ff0c18 692 /*@{*/
mbed_official 146:f64d43ff0c18 693
mbed_official 146:f64d43ff0c18 694 /*!
mbed_official 146:f64d43ff0c18 695 * @brief Gets the flag indicating a STOP signal was detected on the I2C bus.
mbed_official 146:f64d43ff0c18 696 *
mbed_official 146:f64d43ff0c18 697 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 698 * @retval true STOP signal detected on bus.
mbed_official 146:f64d43ff0c18 699 * @retval false No STOP signal was detected on the bus.
mbed_official 146:f64d43ff0c18 700 */
mbed_official 146:f64d43ff0c18 701 static inline bool i2c_hal_get_stop_detect(uint32_t instance)
mbed_official 146:f64d43ff0c18 702 {
mbed_official 146:f64d43ff0c18 703 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 704 return (bool)HW_I2C_FLT(instance).B.STOPF;
mbed_official 146:f64d43ff0c18 705 }
mbed_official 146:f64d43ff0c18 706
mbed_official 146:f64d43ff0c18 707 /*!
mbed_official 146:f64d43ff0c18 708 * @brief Clears the bus STOP signal detected flag.
mbed_official 146:f64d43ff0c18 709 *
mbed_official 146:f64d43ff0c18 710 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 711 */
mbed_official 146:f64d43ff0c18 712 static inline void i2c_hal_clear_stop_detect(uint32_t instance)
mbed_official 146:f64d43ff0c18 713 {
mbed_official 146:f64d43ff0c18 714 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 715 HW_I2C_FLT_SET(instance, BM_I2C_FLT_STOPF);
mbed_official 146:f64d43ff0c18 716 }
mbed_official 146:f64d43ff0c18 717
mbed_official 146:f64d43ff0c18 718 /*@}*/
mbed_official 146:f64d43ff0c18 719 #if FSL_FEATURE_I2C_HAS_START_DETECT
mbed_official 146:f64d43ff0c18 720
mbed_official 146:f64d43ff0c18 721 /*! @name Bus stop detection interrupt*/
mbed_official 146:f64d43ff0c18 722 /*@{*/
mbed_official 146:f64d43ff0c18 723
mbed_official 146:f64d43ff0c18 724 /*!
mbed_official 146:f64d43ff0c18 725 * @brief Enables the I2C bus stop detection interrupt.
mbed_official 146:f64d43ff0c18 726 *
mbed_official 146:f64d43ff0c18 727 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 728 */
mbed_official 146:f64d43ff0c18 729 static inline void i2c_hal_enable_bus_stop_interrupt(uint32_t instance)
mbed_official 146:f64d43ff0c18 730 {
mbed_official 146:f64d43ff0c18 731 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 732 HW_I2C_FLT_SET(instance, BM_I2C_FLT_SSIE);
mbed_official 146:f64d43ff0c18 733 }
mbed_official 146:f64d43ff0c18 734
mbed_official 146:f64d43ff0c18 735 /*!
mbed_official 146:f64d43ff0c18 736 * @brief Disables the I2C bus stop detection interrupt.
mbed_official 146:f64d43ff0c18 737 *
mbed_official 146:f64d43ff0c18 738 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 739 */
mbed_official 146:f64d43ff0c18 740 static inline void i2c_hal_disable_bus_stop_interrupt(uint32_t instance)
mbed_official 146:f64d43ff0c18 741 {
mbed_official 146:f64d43ff0c18 742 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 743 HW_I2C_FLT_CLR(instance, BM_I2C_FLT_SSIE);
mbed_official 146:f64d43ff0c18 744 }
mbed_official 146:f64d43ff0c18 745
mbed_official 146:f64d43ff0c18 746 /*!
mbed_official 146:f64d43ff0c18 747 * @brief Returns whether the I2C bus stop detection interrupts are enabled.
mbed_official 146:f64d43ff0c18 748 *
mbed_official 146:f64d43ff0c18 749 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 750 * @retval true Stop detect interrupts are enabled.
mbed_official 146:f64d43ff0c18 751 * @retval false Stop detect interrupts are disabled.
mbed_official 146:f64d43ff0c18 752 */
mbed_official 146:f64d43ff0c18 753 static inline bool i2c_hal_is_bus_stop_interrupt_enabled(uint32_t instance)
mbed_official 146:f64d43ff0c18 754 {
mbed_official 146:f64d43ff0c18 755 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 756 return (bool)HW_I2C_FLT(instance).B.SSIE;
mbed_official 146:f64d43ff0c18 757 }
mbed_official 146:f64d43ff0c18 758
mbed_official 146:f64d43ff0c18 759 #else
mbed_official 146:f64d43ff0c18 760
mbed_official 146:f64d43ff0c18 761 /*! @name Bus stop detection interrupt*/
mbed_official 146:f64d43ff0c18 762 /*@{*/
mbed_official 146:f64d43ff0c18 763
mbed_official 146:f64d43ff0c18 764 /*!
mbed_official 146:f64d43ff0c18 765 * @brief Enables the I2C bus stop detection interrupt.
mbed_official 146:f64d43ff0c18 766 *
mbed_official 146:f64d43ff0c18 767 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 768 */
mbed_official 146:f64d43ff0c18 769 static inline void i2c_hal_enable_bus_stop_interrupt(uint32_t instance)
mbed_official 146:f64d43ff0c18 770 {
mbed_official 146:f64d43ff0c18 771 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 772 HW_I2C_FLT_SET(instance, BM_I2C_FLT_STOPIE);
mbed_official 146:f64d43ff0c18 773 }
mbed_official 146:f64d43ff0c18 774
mbed_official 146:f64d43ff0c18 775 /*!
mbed_official 146:f64d43ff0c18 776 * @brief Disables the I2C bus stop detection interrupt.
mbed_official 146:f64d43ff0c18 777 *
mbed_official 146:f64d43ff0c18 778 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 779 */
mbed_official 146:f64d43ff0c18 780 static inline void i2c_hal_disable_bus_stop_interrupt(uint32_t instance)
mbed_official 146:f64d43ff0c18 781 {
mbed_official 146:f64d43ff0c18 782 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 783 HW_I2C_FLT_CLR(instance, BM_I2C_FLT_STOPIE);
mbed_official 146:f64d43ff0c18 784 }
mbed_official 146:f64d43ff0c18 785
mbed_official 146:f64d43ff0c18 786 /*!
mbed_official 146:f64d43ff0c18 787 * @brief Returns whether the I2C bus stop detection interrupts are enabled.
mbed_official 146:f64d43ff0c18 788 *
mbed_official 146:f64d43ff0c18 789 * @param instance The I2C peripheral instance number
mbed_official 146:f64d43ff0c18 790 * @retval true Stop detect interrupts are enabled.
mbed_official 146:f64d43ff0c18 791 * @retval false Stop detect interrupts are disabled.
mbed_official 146:f64d43ff0c18 792 */
mbed_official 146:f64d43ff0c18 793 static inline bool i2c_hal_is_bus_stop_interrupt_enabled(uint32_t instance)
mbed_official 146:f64d43ff0c18 794 {
mbed_official 146:f64d43ff0c18 795 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 796 return (bool)HW_I2C_FLT(instance).B.STOPIE;
mbed_official 146:f64d43ff0c18 797 }
mbed_official 146:f64d43ff0c18 798
mbed_official 146:f64d43ff0c18 799 #endif /* FSL_FEATURE_I2C_HAS_START_DETECT*/
mbed_official 146:f64d43ff0c18 800
mbed_official 146:f64d43ff0c18 801 /*@}*/
mbed_official 146:f64d43ff0c18 802 #endif /* FSL_FEATURE_I2C_HAS_STOP_DETECT*/
mbed_official 146:f64d43ff0c18 803
mbed_official 146:f64d43ff0c18 804 #if defined(__cplusplus)
mbed_official 146:f64d43ff0c18 805 }
mbed_official 146:f64d43ff0c18 806 #endif
mbed_official 146:f64d43ff0c18 807
mbed_official 146:f64d43ff0c18 808 /*! @}*/
mbed_official 146:f64d43ff0c18 809
mbed_official 146:f64d43ff0c18 810 #endif /* __FSL_I2C_HAL_H__*/
mbed_official 146:f64d43ff0c18 811 /*******************************************************************************
mbed_official 146:f64d43ff0c18 812 * EOF
mbed_official 146:f64d43ff0c18 813 ******************************************************************************/
mbed_official 146:f64d43ff0c18 814