ISF  2.1
Intelligent Sensing Framework for Kinetis with Processor Expert
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
fsl_i2c_master_driver.h
Go to the documentation of this file.
1 /*!
2 ********************************************************************************
3 * File: fsl_i2c_master_driver.h
4 *
5 * Copyright (c) 2014, Freescale Semiconductor, Inc.
6 *
7 *******************************************************************************/
8 /*!
9 * @file fsl_i2c_master_driver.h
10 * @brief \b fsl_i2c_master_driver.h defines structures and types for the i2c master driver.
11 */
12 #ifndef FSL_I2C_MASTER_DRIVER_H_
13 #define FSL_I2C_MASTER_DRIVER_H_
14 
15 #include <stdlib.h>
16 #include "fsl_i2c_hal.h"
17 #include "PE_Types.h"
18 #include "mqxlite.h"
19 #include "lwevent.h"
20 /*!
21  * @addtogroup i2c_master
22  * @{
23  */
24 
25 /*******************************************************************************
26  * Definitions
27  ******************************************************************************/
28 
29 /*! @brief Information necessary to communicate with an I2C slave device.*/
30 typedef struct I2CDeviceInfo
31 {
32  uint16_t address; /*!< The slave's 7-bit or 10 bit address.*/
33  uint32_t baudRate_kbps; /*!< The baud rate in kbps to use with this slave device.*/
34  LDD_I2C_TAddrType addrType; /*!< Address Types.*/
35 } i2c_device_t;
36 
37 /*! @brief Constants for the direction of an I2C transfer.*/
38 typedef enum I2CDirection
39 {
40  kI2CRead = 1, /*!< Read from slave device.*/
41  kI2CWrite = 0 /*!< Write to slave device.*/
43 
44 /*! @brief Optional flags to control a transfer.*/
46 {
47  kI2CNoStart = 1 << 1, /*!< Set this flag to prevent sending a START signal.*/
48  kI2CNoStop = 1 << 2 /*!< Set this flag to prevent sending a STOP signal.*/
49 };
50 
51 /*! @brief Type for an synchronization object */
52 typedef struct
53 {
54  volatile bool isWaiting; /*!< Is any task waiting for a timeout on this object */
55  volatile uint8_t semCount; /*!< The count value of the object */
56  uint8_t timerId; /*!< The software timer channel this object bind to */
58 
59 /*!
60  * @brief Internal driver state information.
61  *
62  * @note The contents of this structure are internal to the driver and should not be
63  * modified by users. Also, contents of the structure are subject to change in
64  * future releases.
65  */
66 typedef struct I2CMasterState {
67  uint32_t instance;
69  LDD_TUserData* pUserData;
70  LDD_TDeviceData *pDeviceHandle; /* pointer to the device handle */
72  LWEVENT_STRUCT i2cEventHandler;
73 } i2c_master_t;
74 
75 #define I2C_PEX_WRITE_EVENT_SUCCESS (1)
76 #define I2C_PEX_WRITE_EVENT_ERROR (I2C_PEX_WRITE_EVENT_SUCCESS << 1)
77 #define I2C_PEX_READ_EVENT_SUCCESS (I2C_PEX_WRITE_EVENT_ERROR << 1)
78 #define I2C_PEX_READ_EVENT_ERROR (I2C_PEX_READ_EVENT_SUCCESS << 1)
79 
80 
81 /*******************************************************************************
82  * API
83  ******************************************************************************/
84 
85 #if defined(__cplusplus)
86 extern "C" {
87 #endif
88 
89 /*!
90  * @brief Initialize the I2C master mode driver.
91  *
92  * @param instance The I2C peripheral instance number.
93  * @param master The pointer to the I2C master driver state structure.
94  * @return None.
95  */
96 void i2c_master_init(uint32_t instance, i2c_master_t * master);
97 
98 /*!
99  * @brief Shut down the driver.
100  *
101  * @param master The pointer to the I2C master driver state structure.
102  * @return None.
103  */
104 void i2c_master_shutdown(i2c_master_t * master);
105 
106 /*!
107  * @brief Configure the I2C bus to access a device.
108  *
109  * @param master The pointer to the I2C master driver state structure.
110  * @param device The pointer to the I2C device information struct.
111  * @return ::i2c_master_configure_bus() returns a value of type ::i2c_status_t indicating whether the operation was successful or unsuccessful.
112  */
114 
115 /*!
116  * @brief Perform a blocking read or write transaction on the I2C bus.
117  *
118  * @param master The pointer to the I2C master driver state structure.
119  * @param device The pointer to the I2C device information struct.
120  * @param direction The direction of an I2C transfer.
121  * @param stopAfterTransfer Send STOP signal after this transfer or not.
122  * @param subaddress The subaddress for a device if it has.
123  * @param subaddressLength The length of the subaddress.
124  * @param data The pointer to the data to be transfered.
125  * @param dataLength The length in bytes of the data to be transfered.
126  * @param actualLengthTransferred The length in bytes of the data thansfered.
127  * @param timeout_ms A timeout for the transfer in microseconds.
128  * @return ::i2c_master_transfer() returns a value of type ::i2c_status_t indicating whether the operation was successful or unsuccessful.
129  */
131  const i2c_device_t * device,
132  i2c_direction_t direction,
133  bool stopAfterTransfer,
134  uint32_t subaddress,
135  size_t subaddressLength,
136  uint8_t * data,
137  size_t dataLength,
138  size_t * actualLengthTransferred,
139  uint32_t timeout_ms);
140 
141 #if defined(__cplusplus)
142 }
143 #endif
144 
145 /*! @}*/
146 #endif /* FSL_I2C_MASTER_DRIVER_H_ */
147 
enum I2CDirection i2c_direction_t
Constants for the direction of an I2C transfer.
LWEVENT_STRUCT i2cEventHandler
Information necessary to communicate with an I2C slave device.
void i2c_master_shutdown(i2c_master_t *master)
Shut down the driver.
Type for an synchronization object.
i2c_status_t i2c_master_configure_bus(i2c_master_t *master, const i2c_device_t *device)
Configure the I2C bus to access a device.
volatile uint8_t semCount
fsl_i2c_hal.h defines structures and types for the i2c master HAL layer.
Internal driver state information.
enum _i2c_status i2c_status_t
I2C status return codes.
_i2c_transfer_flags
Optional flags to control a transfer.
void i2c_master_init(uint32_t instance, i2c_master_t *master)
Initialize the I2C master mode driver.
LDD_I2C_TAddrType addrType
i2c_status_t i2c_master_transfer(i2c_master_t *master, const i2c_device_t *device, i2c_direction_t direction, bool stopAfterTransfer, uint32_t subaddress, size_t subaddressLength, uint8_t *data, size_t dataLength, size_t *actualLengthTransferred, uint32_t timeout_ms)
Perform a blocking read or write transaction on the I2C bus.
struct I2CMasterState i2c_master_t
Internal driver state information.
LDD_TDeviceData * pDeviceHandle
I2CDirection
Constants for the direction of an I2C transfer.
volatile bool isWaiting
LDD_TUserData * pUserData
struct I2CDeviceInfo i2c_device_t
Information necessary to communicate with an I2C slave device.