| ISF 2.1 Intelligent Sensing Framework for Kinetis with Processor Expert

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

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.*/
42 } i2c_direction_t;
43
44 /*! @brief Optional flags to control a transfer.*/
45 enum _i2c_transfer_flags
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 */
57 }sync_object_t;
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;
68 uint32_t lastBaudRate_kbps;
69 LDD_TUserData* pUserData;
70 LDD_TDeviceData *pDeviceHandle; /* pointer to the device handle */
71 bool isTransferInProgress;
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 */
113 i2c_status_t i2c_master_configure_bus(i2c_master_t * master, const i2c_device_t * device);
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 */
130 i2c_status_t i2c_master_transfer(i2c_master_t * master,
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
i2c_direction_t
enum I2CDirection i2c_direction_t
Constants for the direction of an I2C transfer.
I2CMasterState::i2cEventHandler
LWEVENT_STRUCT i2cEventHandler
Definition: fsl_i2c_master_driver.h:72
I2CMasterState::instance
uint32_t instance
Definition: fsl_i2c_master_driver.h:67
kI2CWrite
Definition: fsl_i2c_master_driver.h:41
I2CDeviceInfo
Information necessary to communicate with an I2C slave device.
Definition: fsl_i2c_master_driver.h:30
kI2CRead
Definition: fsl_i2c_master_driver.h:40
i2c_master_shutdown
void i2c_master_shutdown(i2c_master_t *master)
Shut down the driver.
Definition: fsl_i2c_master_driver.c:73
sync_object_t
Type for an synchronization object.
Definition: fsl_i2c_master_driver.h:52
sync_object_t::timerId
uint8_t timerId
Definition: fsl_i2c_master_driver.h:56
i2c_master_configure_bus
i2c_status_t i2c_master_configure_bus(i2c_master_t *master, const i2c_device_t *device)
Configure the I2C bus to access a device.
Definition: fsl_i2c_master_driver.c:87
sync_object_t::semCount
volatile uint8_t semCount
Definition: fsl_i2c_master_driver.h:55
I2CDeviceInfo::baudRate_kbps
uint32_t baudRate_kbps
Definition: fsl_i2c_master_driver.h:33
fsl_i2c_hal.h
fsl_i2c_hal.h defines structures and types for the i2c master HAL layer.
I2CMasterState
Internal driver state information.
Definition: fsl_i2c_master_driver.h:66
i2c_status_t
enum _i2c_status i2c_status_t
I2C status return codes.
_i2c_transfer_flags
_i2c_transfer_flags
Optional flags to control a transfer.
Definition: fsl_i2c_master_driver.h:45
kI2CNoStart
Definition: fsl_i2c_master_driver.h:47
i2c_master_init
void i2c_master_init(uint32_t instance, i2c_master_t *master)
Initialize the I2C master mode driver.
Definition: fsl_i2c_master_driver.c:53
I2CDeviceInfo::addrType
LDD_I2C_TAddrType addrType
Definition: fsl_i2c_master_driver.h:34
I2CMasterState::isTransferInProgress
bool isTransferInProgress
Definition: fsl_i2c_master_driver.h:71
i2c_master_transfer
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.
Definition: fsl_i2c_master_driver.c:102
i2c_master_t
struct I2CMasterState i2c_master_t
Internal driver state information.
I2CMasterState::pDeviceHandle
LDD_TDeviceData * pDeviceHandle
Definition: fsl_i2c_master_driver.h:70
I2CDirection
I2CDirection
Constants for the direction of an I2C transfer.
Definition: fsl_i2c_master_driver.h:38
I2CMasterState::lastBaudRate_kbps
uint32_t lastBaudRate_kbps
Definition: fsl_i2c_master_driver.h:68
sync_object_t::isWaiting
volatile bool isWaiting
Definition: fsl_i2c_master_driver.h:54
I2CMasterState::pUserData
LDD_TUserData * pUserData
Definition: fsl_i2c_master_driver.h:69
I2CDeviceInfo::address
uint16_t address
Definition: fsl_i2c_master_driver.h:32
kI2CNoStop
Definition: fsl_i2c_master_driver.h:48
i2c_device_t
struct I2CDeviceInfo i2c_device_t
Information necessary to communicate with an I2C slave device.
- © Freescale Semiconductor, Inc. 2015. All Rights Reserved.