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

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 167:84c0a372a020 1 /**
AnnaBridge 167:84c0a372a020 2 * @file
AnnaBridge 167:84c0a372a020 3 * @brief I2CM (Inter-Integrated Circuit Master) function prototypes and
AnnaBridge 167:84c0a372a020 4 * data types.
AnnaBridge 167:84c0a372a020 5 */
AnnaBridge 167:84c0a372a020 6
AnnaBridge 167:84c0a372a020 7 /* ****************************************************************************
AnnaBridge 167:84c0a372a020 8 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
AnnaBridge 167:84c0a372a020 9 *
AnnaBridge 167:84c0a372a020 10 * Permission is hereby granted, free of charge, to any person obtaining a
AnnaBridge 167:84c0a372a020 11 * copy of this software and associated documentation files (the "Software"),
AnnaBridge 167:84c0a372a020 12 * to deal in the Software without restriction, including without limitation
AnnaBridge 167:84c0a372a020 13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
AnnaBridge 167:84c0a372a020 14 * and/or sell copies of the Software, and to permit persons to whom the
AnnaBridge 167:84c0a372a020 15 * Software is furnished to do so, subject to the following conditions:
AnnaBridge 167:84c0a372a020 16 *
AnnaBridge 167:84c0a372a020 17 * The above copyright notice and this permission notice shall be included
AnnaBridge 167:84c0a372a020 18 * in all copies or substantial portions of the Software.
AnnaBridge 167:84c0a372a020 19 *
AnnaBridge 167:84c0a372a020 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
AnnaBridge 167:84c0a372a020 21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
AnnaBridge 167:84c0a372a020 22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
AnnaBridge 167:84c0a372a020 23 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
AnnaBridge 167:84c0a372a020 24 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
AnnaBridge 167:84c0a372a020 25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
AnnaBridge 167:84c0a372a020 26 * OTHER DEALINGS IN THE SOFTWARE.
AnnaBridge 167:84c0a372a020 27 *
AnnaBridge 167:84c0a372a020 28 * Except as contained in this notice, the name of Maxim Integrated
AnnaBridge 167:84c0a372a020 29 * Products, Inc. shall not be used except as stated in the Maxim Integrated
AnnaBridge 167:84c0a372a020 30 * Products, Inc. Branding Policy.
AnnaBridge 167:84c0a372a020 31 *
AnnaBridge 167:84c0a372a020 32 * The mere transfer of this software does not imply any licenses
AnnaBridge 167:84c0a372a020 33 * of trade secrets, proprietary technology, copyrights, patents,
AnnaBridge 167:84c0a372a020 34 * trademarks, maskwork rights, or any other form of intellectual
AnnaBridge 167:84c0a372a020 35 * property whatsoever. Maxim Integrated Products, Inc. retains all
AnnaBridge 167:84c0a372a020 36 * ownership rights.
AnnaBridge 167:84c0a372a020 37 *
AnnaBridge 167:84c0a372a020 38 * $Date: 2017-02-16 12:08:14 -0600 (Thu, 16 Feb 2017) $
AnnaBridge 167:84c0a372a020 39 * $Revision: 26469 $
AnnaBridge 167:84c0a372a020 40 *
AnnaBridge 167:84c0a372a020 41 *************************************************************************** */
AnnaBridge 167:84c0a372a020 42
AnnaBridge 167:84c0a372a020 43 /* Define to prevent redundant inclusion */
AnnaBridge 167:84c0a372a020 44 #ifndef _I2CM_H_
AnnaBridge 167:84c0a372a020 45 #define _I2CM_H_
AnnaBridge 167:84c0a372a020 46
AnnaBridge 167:84c0a372a020 47 /***** Includes *****/
AnnaBridge 167:84c0a372a020 48 #include "mxc_config.h"
AnnaBridge 167:84c0a372a020 49 #include "mxc_sys.h"
AnnaBridge 167:84c0a372a020 50 /**
AnnaBridge 167:84c0a372a020 51 * @ingroup periphlibs
AnnaBridge 167:84c0a372a020 52 * @defgroup i2cm I2C Master
AnnaBridge 167:84c0a372a020 53 * @brief I2C Master Peripheral API
AnnaBridge 167:84c0a372a020 54 * @{
AnnaBridge 167:84c0a372a020 55 */
AnnaBridge 167:84c0a372a020 56 #include "i2cm_regs.h"
AnnaBridge 167:84c0a372a020 57
AnnaBridge 167:84c0a372a020 58 #ifdef __cplusplus
AnnaBridge 167:84c0a372a020 59 extern "C" {
AnnaBridge 167:84c0a372a020 60 #endif
AnnaBridge 167:84c0a372a020 61
AnnaBridge 167:84c0a372a020 62
AnnaBridge 167:84c0a372a020 63 /* **** Definitions **** */
AnnaBridge 167:84c0a372a020 64
AnnaBridge 167:84c0a372a020 65 /**
AnnaBridge 167:84c0a372a020 66 * Enumeration type to select supported I2CM frequencies.
AnnaBridge 167:84c0a372a020 67 */
AnnaBridge 167:84c0a372a020 68 typedef enum {
AnnaBridge 167:84c0a372a020 69 I2CM_SPEED_100KHZ = 0, /**< Use to select a bus communication speed of 100 kHz. */
AnnaBridge 167:84c0a372a020 70 I2CM_SPEED_400KHZ = 1 /**< Use to select a bus communication speed of 400 kHz. */
AnnaBridge 167:84c0a372a020 71 } i2cm_speed_t;
AnnaBridge 167:84c0a372a020 72
AnnaBridge 167:84c0a372a020 73 /**
AnnaBridge 167:84c0a372a020 74 * Structure type for an I2CM Transaction request.
AnnaBridge 167:84c0a372a020 75 */
AnnaBridge 167:84c0a372a020 76 typedef struct i2cm_req i2cm_req_t;
AnnaBridge 167:84c0a372a020 77
AnnaBridge 167:84c0a372a020 78 /**
AnnaBridge 167:84c0a372a020 79 * @addtogroup i2cm_async
AnnaBridge 167:84c0a372a020 80 * @{
AnnaBridge 167:84c0a372a020 81 * Function type for the I2C Master callback. The function declaration for the
AnnaBridge 167:84c0a372a020 82 * I2CM callback is:
AnnaBridge 167:84c0a372a020 83 * @code
AnnaBridge 167:84c0a372a020 84 * void callback(i2cm_req_t * req, int error_code);
AnnaBridge 167:84c0a372a020 85 * @endcode
AnnaBridge 167:84c0a372a020 86 * | | |
AnnaBridge 167:84c0a372a020 87 * | -----: | :----------------------------------------- |
AnnaBridge 167:84c0a372a020 88 * | @p req | Pointer to an #i2cm_req object representing the I2CM active transaction. |
AnnaBridge 167:84c0a372a020 89 * | @p error_code | An error code if the active transaction had a failure or #E_NO_ERROR if successful. |
AnnaBridge 167:84c0a372a020 90 *
AnnaBridge 167:84c0a372a020 91 */
AnnaBridge 167:84c0a372a020 92 typedef void (*i2cm_callback_fn)(i2cm_req_t * req, int error_code);
AnnaBridge 167:84c0a372a020 93 /**@}*/
AnnaBridge 167:84c0a372a020 94
AnnaBridge 167:84c0a372a020 95
AnnaBridge 167:84c0a372a020 96 /**
AnnaBridge 167:84c0a372a020 97 * I2CM Transaction request structure.
AnnaBridge 167:84c0a372a020 98 * @note Only supports 7-bit addressing. Driver will shift the address and
AnnaBridge 167:84c0a372a020 99 * add the read bit when necessary.
AnnaBridge 167:84c0a372a020 100 */
AnnaBridge 167:84c0a372a020 101 struct i2cm_req {
AnnaBridge 167:84c0a372a020 102 uint8_t addr; /**< 7-Bit unshifted address of the slave for communication. */
AnnaBridge 167:84c0a372a020 103 const uint8_t *cmd_data; /**< Pointer to a command data buffer to send to the slave before either a read or write transaction. */
AnnaBridge 167:84c0a372a020 104 uint32_t cmd_len; /**< Number of bytes in command. */
AnnaBridge 167:84c0a372a020 105 uint8_t *data; /**< Data to write or read. */
AnnaBridge 167:84c0a372a020 106 uint32_t data_len; /**< Length of data. */
AnnaBridge 167:84c0a372a020 107 uint32_t cmd_num; /**< Number of command bytes sent. */
AnnaBridge 167:84c0a372a020 108 uint32_t data_num; /**< Number of data bytes sent. */
AnnaBridge 167:84c0a372a020 109 i2cm_callback_fn callback; /**< Function pointer to a callback function. */
AnnaBridge 167:84c0a372a020 110 };
AnnaBridge 167:84c0a372a020 111
AnnaBridge 167:84c0a372a020 112 /* **** Globals **** */
AnnaBridge 167:84c0a372a020 113
AnnaBridge 167:84c0a372a020 114 /* **** Function Prototypes **** */
AnnaBridge 167:84c0a372a020 115
AnnaBridge 167:84c0a372a020 116 /**
AnnaBridge 167:84c0a372a020 117 * @brief Initialize the I2CM peripheral module.
AnnaBridge 167:84c0a372a020 118 *
AnnaBridge 167:84c0a372a020 119 * @param i2cm Pointer to the I2CM registers, see #mxc_i2cm_regs_t.
AnnaBridge 167:84c0a372a020 120 * @param sys_cfg Pointer to an I2CM configuration structure of type
AnnaBridge 167:84c0a372a020 121 * #sys_cfg_i2cm_t.
AnnaBridge 167:84c0a372a020 122 * @param speed I2CM bus speed, see #i2cm_speed_t.
AnnaBridge 167:84c0a372a020 123 *
AnnaBridge 167:84c0a372a020 124 * @return #E_NO_ERROR if initialized successfully, error if unsuccessful.
AnnaBridge 167:84c0a372a020 125 */
AnnaBridge 167:84c0a372a020 126 int I2CM_Init(mxc_i2cm_regs_t *i2cm, const sys_cfg_i2cm_t *sys_cfg, i2cm_speed_t speed);
AnnaBridge 167:84c0a372a020 127
AnnaBridge 167:84c0a372a020 128 /**
AnnaBridge 167:84c0a372a020 129 * @brief Shutdown I2CM module.
AnnaBridge 167:84c0a372a020 130 *
AnnaBridge 167:84c0a372a020 131 * @param i2cm Pointer to the I2CM registers, see #mxc_i2cm_regs_t.
AnnaBridge 167:84c0a372a020 132 *
AnnaBridge 167:84c0a372a020 133 * @returns #E_NO_ERROR if everything is successful, error if unsuccessful.
AnnaBridge 167:84c0a372a020 134 *
AnnaBridge 167:84c0a372a020 135 */
AnnaBridge 167:84c0a372a020 136 int I2CM_Shutdown(mxc_i2cm_regs_t *i2cm);
AnnaBridge 167:84c0a372a020 137
AnnaBridge 167:84c0a372a020 138 /**
AnnaBridge 167:84c0a372a020 139 * @defgroup i2cm_blocking I2CM Blocking Functions
AnnaBridge 167:84c0a372a020 140 * @{
AnnaBridge 167:84c0a372a020 141 */
AnnaBridge 167:84c0a372a020 142
AnnaBridge 167:84c0a372a020 143 /**
AnnaBridge 167:84c0a372a020 144 * @brief Read I2CM data. Will block until transaction is complete.
AnnaBridge 167:84c0a372a020 145 *
AnnaBridge 167:84c0a372a020 146 * @note Command is an optional feature where the master will write the @c
AnnaBridge 167:84c0a372a020 147 * cmd_data before reading from the slave. If command is undesired,
AnnaBridge 167:84c0a372a020 148 * set the @c *cmd_data parameter to NULL and pass 0 for the @c
AnnaBridge 167:84c0a372a020 149 * cmd_len parameter.
AnnaBridge 167:84c0a372a020 150 * @note If there is a command, the master will send a repeated start
AnnaBridge 167:84c0a372a020 151 * sequence before attempting to read from the slave.
AnnaBridge 167:84c0a372a020 152 * @note This function blocks until the transaction has completed.
AnnaBridge 167:84c0a372a020 153 *
AnnaBridge 167:84c0a372a020 154 * @param i2cm Pointer to the I2CM registers, see #mxc_i2cm_regs_t.
AnnaBridge 167:84c0a372a020 155 * @param addr I2C address of the slave.
AnnaBridge 167:84c0a372a020 156 * @param cmd_data Data to write before reading.
AnnaBridge 167:84c0a372a020 157 * @param cmd_len Number of bytes to write before reading.
AnnaBridge 167:84c0a372a020 158 * @param data Where to store the data read.
AnnaBridge 167:84c0a372a020 159 * @param len Number of bytes to read.
AnnaBridge 167:84c0a372a020 160 *
AnnaBridge 167:84c0a372a020 161 * @return Number of bytes read if successful, error code if unsuccessful.
AnnaBridge 167:84c0a372a020 162 */
AnnaBridge 167:84c0a372a020 163 int I2CM_Read(mxc_i2cm_regs_t *i2cm, uint8_t addr, const uint8_t *cmd_data,
AnnaBridge 167:84c0a372a020 164 uint32_t cmd_len, uint8_t* data, uint32_t len, uint8_t stop);
AnnaBridge 167:84c0a372a020 165
AnnaBridge 167:84c0a372a020 166 /**
AnnaBridge 167:84c0a372a020 167 * @brief Write data to a slave device.
AnnaBridge 167:84c0a372a020 168 *
AnnaBridge 167:84c0a372a020 169 * @note Command is an optional feature where the master will write the @c
AnnaBridge 167:84c0a372a020 170 * cmd_data before writing the @c data to the slave. If command is
AnnaBridge 167:84c0a372a020 171 * not needed, set the @c cmd_data to @c NULL and set @c cmd_len to
AnnaBridge 167:84c0a372a020 172 * 0. If there is a command, the master will send a repeated start
AnnaBridge 167:84c0a372a020 173 * sequence before attempting to read from the slave.
AnnaBridge 167:84c0a372a020 174 * @note This function blocks until the transaction has completed.
AnnaBridge 167:84c0a372a020 175 *
AnnaBridge 167:84c0a372a020 176 * @param i2cm Pointer to the I2CM registers, see #mxc_i2cm_regs_t.
AnnaBridge 167:84c0a372a020 177 * @param addr I2C address of the slave.
AnnaBridge 167:84c0a372a020 178 * @param cmd_data Data to write before writing data.
AnnaBridge 167:84c0a372a020 179 * @param cmd_len Number of bytes to write before writing data.
AnnaBridge 167:84c0a372a020 180 * @param data Data to be written.
AnnaBridge 167:84c0a372a020 181 * @param len Number of bytes to Write.
AnnaBridge 167:84c0a372a020 182 *
AnnaBridge 167:84c0a372a020 183 * @return Number of bytes writen if successful or an @ref MXC_Error_Codes
AnnaBridge 167:84c0a372a020 184 * "Error Code" if unsuccessful.
AnnaBridge 167:84c0a372a020 185 */
AnnaBridge 167:84c0a372a020 186 int I2CM_Write(mxc_i2cm_regs_t *i2cm, uint8_t addr, const uint8_t *cmd_data,
AnnaBridge 167:84c0a372a020 187 uint32_t cmd_len, uint8_t* data, uint32_t len);
AnnaBridge 167:84c0a372a020 188 /**@} end of i2cm_blocking functions */
AnnaBridge 167:84c0a372a020 189
AnnaBridge 167:84c0a372a020 190 /**
AnnaBridge 167:84c0a372a020 191 * @defgroup i2cm_async I2CM Asynchrous Functions
AnnaBridge 167:84c0a372a020 192 * @{
AnnaBridge 167:84c0a372a020 193 */
AnnaBridge 167:84c0a372a020 194
AnnaBridge 167:84c0a372a020 195 /**
AnnaBridge 167:84c0a372a020 196 * @brief Asynchronously read I2CM data.
AnnaBridge 167:84c0a372a020 197 *
AnnaBridge 167:84c0a372a020 198 * @param i2cm Pointer to the I2CM registers, see #mxc_i2cm_regs_t.
AnnaBridge 167:84c0a372a020 199 * @param req Pointer to an I2CM transaction request structure, see
AnnaBridge 167:84c0a372a020 200 * #i2cm_req.
AnnaBridge 167:84c0a372a020 201 *
AnnaBridge 167:84c0a372a020 202 * @return #E_NO_ERROR if everything is successful or an @ref
AnnaBridge 167:84c0a372a020 203 * MXC_Error_Codes "Error Code" if unsuccessful.
AnnaBridge 167:84c0a372a020 204 */
AnnaBridge 167:84c0a372a020 205 int I2CM_ReadAsync(mxc_i2cm_regs_t *i2cm, i2cm_req_t *req);
AnnaBridge 167:84c0a372a020 206
AnnaBridge 167:84c0a372a020 207 /**
AnnaBridge 167:84c0a372a020 208 * @brief Asynchronously write I2CM data.
AnnaBridge 167:84c0a372a020 209 *
AnnaBridge 167:84c0a372a020 210 * @param i2cm Pointer to the I2CM registers, see #mxc_i2cm_regs_t.
AnnaBridge 167:84c0a372a020 211 * @param req Pointer to an I2CM transaction request structure, see
AnnaBridge 167:84c0a372a020 212 * #i2cm_req.
AnnaBridge 167:84c0a372a020 213 *
AnnaBridge 167:84c0a372a020 214 * @return #E_NO_ERROR if everything is successful, error if unsuccessful.
AnnaBridge 167:84c0a372a020 215 */
AnnaBridge 167:84c0a372a020 216 int I2CM_WriteAsync(mxc_i2cm_regs_t *i2cm, i2cm_req_t *req);
AnnaBridge 167:84c0a372a020 217
AnnaBridge 167:84c0a372a020 218 /**
AnnaBridge 167:84c0a372a020 219 * @brief Abort asynchronous request.
AnnaBridge 167:84c0a372a020 220 * @param req Pointer to request for an I2CM transaction.
AnnaBridge 167:84c0a372a020 221 * @note Will call the callback for the request.
AnnaBridge 167:84c0a372a020 222 *
AnnaBridge 167:84c0a372a020 223 * @return #E_NO_ERROR if request aborted, error if unsuccessful.
AnnaBridge 167:84c0a372a020 224 */
AnnaBridge 167:84c0a372a020 225 int I2CM_AbortAsync(i2cm_req_t *req);
AnnaBridge 167:84c0a372a020 226
AnnaBridge 167:84c0a372a020 227 /**
AnnaBridge 167:84c0a372a020 228 * @brief I2CM interrupt handler.
AnnaBridge 167:84c0a372a020 229 *
AnnaBridge 167:84c0a372a020 230 * @details This function is an IRQ handler and will be called by the core if
AnnaBridge 167:84c0a372a020 231 * I2CM interrupts are enabled. Alternately, if the application is
AnnaBridge 167:84c0a372a020 232 * using asynchronous methods, this function can be periodically
AnnaBridge 167:84c0a372a020 233 * called by the application if the I2CM interrupts are disabled.
AnnaBridge 167:84c0a372a020 234 *
AnnaBridge 167:84c0a372a020 235 * @param i2cm Base address of the I2CM module.
AnnaBridge 167:84c0a372a020 236 */
AnnaBridge 167:84c0a372a020 237 void I2CM_Handler(mxc_i2cm_regs_t *i2cm);
AnnaBridge 167:84c0a372a020 238 /**@} end of i2cm_async */
AnnaBridge 167:84c0a372a020 239
AnnaBridge 167:84c0a372a020 240 /**
AnnaBridge 167:84c0a372a020 241 * @brief Returns the status of the I2CM peripheral module.
AnnaBridge 167:84c0a372a020 242 *
AnnaBridge 167:84c0a372a020 243 * @param i2cm Pointer to the I2CM register structure, see
AnnaBridge 167:84c0a372a020 244 * #mxc_i2cm_regs_t.
AnnaBridge 167:84c0a372a020 245 *
AnnaBridge 167:84c0a372a020 246 * @return #E_NO_ERROR if idle.
AnnaBridge 167:84c0a372a020 247 * @return #E_BUSY if in use.
AnnaBridge 167:84c0a372a020 248 */
AnnaBridge 167:84c0a372a020 249 int I2CM_Busy(mxc_i2cm_regs_t *i2cm);
AnnaBridge 167:84c0a372a020 250
AnnaBridge 167:84c0a372a020 251 /**
AnnaBridge 167:84c0a372a020 252 * @brief Attempt to prepare the I2CM for sleep.
AnnaBridge 167:84c0a372a020 253 * @details Checks for any ongoing transactions. Disables interrupts if the
AnnaBridge 167:84c0a372a020 254 * I2CM is idle.
AnnaBridge 167:84c0a372a020 255 *
AnnaBridge 167:84c0a372a020 256 * @param i2cm Pointer to the I2CM register structure, see
AnnaBridge 167:84c0a372a020 257 * #mxc_i2cm_regs_t.
AnnaBridge 167:84c0a372a020 258 *
AnnaBridge 167:84c0a372a020 259 * @return #E_NO_ERROR if ready to sleep.
AnnaBridge 167:84c0a372a020 260 * @return #E_BUSY if the bus is not ready for sleep.
AnnaBridge 167:84c0a372a020 261 */
AnnaBridge 167:84c0a372a020 262 int I2CM_PrepForSleep(mxc_i2cm_regs_t *i2cm);
AnnaBridge 167:84c0a372a020 263
AnnaBridge 167:84c0a372a020 264 /**
AnnaBridge 167:84c0a372a020 265 * @brief Check the I2C bus to determine if any other masters are using the
AnnaBridge 167:84c0a372a020 266 * bus.
AnnaBridge 167:84c0a372a020 267 *
AnnaBridge 167:84c0a372a020 268 * @param i2cm Pointer to the I2CM register structure, see
AnnaBridge 167:84c0a372a020 269 * #mxc_i2cm_regs_t.
AnnaBridge 167:84c0a372a020 270 *
AnnaBridge 167:84c0a372a020 271 * @return #E_NO_ERROR if SCL and SDA are high,
AnnaBridge 167:84c0a372a020 272 * @return #E_BUSY otherwise.
AnnaBridge 167:84c0a372a020 273 */
AnnaBridge 167:84c0a372a020 274 int I2CM_BusCheck(mxc_i2cm_regs_t *i2cm);
AnnaBridge 167:84c0a372a020 275
AnnaBridge 167:84c0a372a020 276 /**
AnnaBridge 167:84c0a372a020 277 * @brief Drain/Empty all of the data in the I2CM Receive FIFO.
AnnaBridge 167:84c0a372a020 278 *
AnnaBridge 167:84c0a372a020 279 * @param i2cm Pointer to the I2CM register structure, see
AnnaBridge 167:84c0a372a020 280 * #mxc_i2cm_regs_t.
AnnaBridge 167:84c0a372a020 281 */
AnnaBridge 167:84c0a372a020 282 __STATIC_INLINE void I2CM_DrainRX(mxc_i2cm_regs_t *i2cm)
AnnaBridge 167:84c0a372a020 283 {
AnnaBridge 167:84c0a372a020 284 i2cm->ctrl &= ~(MXC_F_I2CM_CTRL_RX_FIFO_EN);
AnnaBridge 167:84c0a372a020 285 i2cm->ctrl |= MXC_F_I2CM_CTRL_RX_FIFO_EN;
AnnaBridge 167:84c0a372a020 286 }
AnnaBridge 167:84c0a372a020 287
AnnaBridge 167:84c0a372a020 288 /**
AnnaBridge 167:84c0a372a020 289 * @brief Drain/Empty any data in the I2CM Transmit FIFO.
AnnaBridge 167:84c0a372a020 290 *
AnnaBridge 167:84c0a372a020 291 * @param i2cm Pointer to the I2CM register structure, see
AnnaBridge 167:84c0a372a020 292 * #mxc_i2cm_regs_t.
AnnaBridge 167:84c0a372a020 293 */
AnnaBridge 167:84c0a372a020 294 __STATIC_INLINE void I2CM_DrainTX(mxc_i2cm_regs_t *i2cm)
AnnaBridge 167:84c0a372a020 295 {
AnnaBridge 167:84c0a372a020 296 i2cm->ctrl &= ~(MXC_F_I2CM_CTRL_TX_FIFO_EN);
AnnaBridge 167:84c0a372a020 297 i2cm->ctrl |= MXC_F_I2CM_CTRL_TX_FIFO_EN;
AnnaBridge 167:84c0a372a020 298 }
AnnaBridge 167:84c0a372a020 299
AnnaBridge 167:84c0a372a020 300 /**
AnnaBridge 167:84c0a372a020 301 * @brief Clear interrupt flags.
AnnaBridge 167:84c0a372a020 302 *
AnnaBridge 167:84c0a372a020 303 * @param i2cm Pointer to the I2CM register structure, see
AnnaBridge 167:84c0a372a020 304 * #mxc_i2cm_regs_t.
AnnaBridge 167:84c0a372a020 305 * @param mask Mask of I2CM interrupts to clear (1 to clear),
AnnaBridge 167:84c0a372a020 306 * @see I2CM_INTFL_Register for the interrupt flag masks.
AnnaBridge 167:84c0a372a020 307 */
AnnaBridge 167:84c0a372a020 308 __STATIC_INLINE void I2CM_ClearFlags(mxc_i2cm_regs_t *i2cm, uint32_t mask)
AnnaBridge 167:84c0a372a020 309 {
AnnaBridge 167:84c0a372a020 310 i2cm->intfl = mask;
AnnaBridge 167:84c0a372a020 311 }
AnnaBridge 167:84c0a372a020 312
AnnaBridge 167:84c0a372a020 313 /**
AnnaBridge 167:84c0a372a020 314 * @brief Gets the current I2CM interrupt flags.
AnnaBridge 167:84c0a372a020 315 * @param i2cm Pointer to the I2CM register structure, see
AnnaBridge 167:84c0a372a020 316 * #mxc_i2cm_regs_t.
AnnaBridge 167:84c0a372a020 317 *
AnnaBridge 167:84c0a372a020 318 * @return The currently set interrupt flags, @see I2CM_INTFL_Register
AnnaBridge 167:84c0a372a020 319 * for the interrupt flag masks.
AnnaBridge 167:84c0a372a020 320 */
AnnaBridge 167:84c0a372a020 321 __STATIC_INLINE unsigned I2CM_GetFlags(mxc_i2cm_regs_t *i2cm)
AnnaBridge 167:84c0a372a020 322 {
AnnaBridge 167:84c0a372a020 323 return(i2cm->intfl);
AnnaBridge 167:84c0a372a020 324 }
AnnaBridge 167:84c0a372a020 325
AnnaBridge 167:84c0a372a020 326 /**@} end of group i2cm */
AnnaBridge 167:84c0a372a020 327
AnnaBridge 167:84c0a372a020 328 void I2CM_Recover(mxc_i2cm_regs_t *i2cm);
AnnaBridge 167:84c0a372a020 329 int I2CM_Tx(mxc_i2cm_regs_t *i2cm, mxc_i2cm_fifo_regs_t *fifo, uint8_t addr, const uint8_t *data, uint32_t len, uint8_t stop);
AnnaBridge 167:84c0a372a020 330 int I2CM_TxInProgress(mxc_i2cm_regs_t *i2cm);
AnnaBridge 167:84c0a372a020 331 int I2CM_WriteTxFifo(mxc_i2cm_regs_t *regs, mxc_i2cm_fifo_regs_t *fifo, const uint16_t data);
AnnaBridge 167:84c0a372a020 332 int I2CM_Rx(mxc_i2cm_regs_t *i2cm, mxc_i2cm_fifo_regs_t *fifo, uint8_t addr, uint8_t *data, uint32_t len, uint8_t stop);
AnnaBridge 167:84c0a372a020 333
AnnaBridge 167:84c0a372a020 334 #ifdef __cplusplus
AnnaBridge 167:84c0a372a020 335 }
AnnaBridge 167:84c0a372a020 336 #endif
AnnaBridge 167:84c0a372a020 337
AnnaBridge 167:84c0a372a020 338 #endif /* _I2CM_H_ */