/TARGET_K64F/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/hal/adc/fsl_adc_hal.h substitute line 894 extern } by }

Fork of mbed by mbed official

Committer:
bogdanm
Date:
Mon Apr 07 18:28:36 2014 +0100
Revision:
82:6473597d706e
Child:
90:cb3d968589d8
Release 82 of the mbed library

Main changes:

- support for K64F
- Revisited Nordic code structure
- Test infrastructure improvements
- various bug fixes

Who changed what in which revision?

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