1 /*!
2  * \file      i2c-board.h
3  *
4  * \brief     Target board I2C driver implementation
5  *
6  * \copyright Revised BSD License, see section \ref LICENSE.
7  *
8  * \code
9  *                ______                              _
10  *               / _____)             _              | |
11  *              ( (____  _____ ____ _| |_ _____  ____| |__
12  *               \____ \| ___ |    (_   _) ___ |/ ___)  _ \
13  *               _____) ) ____| | | || |_| ____( (___| | | |
14  *              (______/|_____)_|_|_| \__)_____)\____)_| |_|
15  *              (C)2013-2017 Semtech
16  *
17  * \endcode
18  *
19  * \author    Miguel Luis ( Semtech )
20  *
21  * \author    Gregory Cristian ( Semtech )
22  */
23 #ifndef __I2C_BOARD_H__
24 #define __I2C_BOARD_H__
25 
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30 
31 #include <stdint.h>
32 #include <stdbool.h>
33 #include "i2c.h"
34 
35 /*!
36  * Operation Mode for the I2C
37  */
38 typedef enum
39 {
40     MODE_I2C = 0,
41     MODE_SMBUS_DEVICE,
42     MODE_SMBUS_HOST
43 }I2cMode;
44 
45 /*!
46  * I2C signal duty cycle
47  */
48 typedef enum
49 {
50     I2C_DUTY_CYCLE_2 = 0,
51     I2C_DUTY_CYCLE_16_9
52 }I2cDutyCycle;
53 
54 /*!
55  * I2C select if the acknowledge in after the 7th or 10th bit
56  */
57 typedef enum
58 {
59     I2C_ACK_ADD_7_BIT = 0,
60     I2C_ACK_ADD_10_BIT
61 }I2cAckAddrMode;
62 
63 /*!
64  * Internal device address size
65  */
66 typedef enum
67 {
68     I2C_ADDR_SIZE_8 = 0,
69     I2C_ADDR_SIZE_16,
70 }I2cAddrSize;
71 
72 /*!
73  * \brief Initializes the I2C object and MCU peripheral
74  *
75  * \param [IN] obj  I2C object
76  * \param [IN] scl  I2C Scl pin name to be used
77  * \param [IN] sda  I2C Sda pin name to be used
78  */
79 void I2cMcuInit( I2c_t *obj, I2cId_t i2cId, PinNames scl, PinNames sda );
80 
81 /*!
82  * \brief Initializes the I2C object and MCU peripheral
83  *
84  * \param [IN] obj              I2C object
85  * \param [IN] mode             Mode of operation for the I2C Bus
86  * \param [IN] dutyCycle        Signal duty cycle
87  * \param [IN] I2cAckEnable     Enable or Disable to ack
88  * \param [IN] AckAddrMode      7bit or 10 bit addressing
89  * \param [IN] I2cFrequency     I2C bus clock frequency
90  */
91 void I2cMcuFormat( I2c_t *obj, I2cMode mode, I2cDutyCycle dutyCycle, bool I2cAckEnable, I2cAckAddrMode AckAddrMode, uint32_t I2cFrequency );
92 
93 /*!
94  * \brief DeInitializes the I2C object and MCU peripheral
95  *
96  * \param [IN] obj  I2C object
97  */
98 void I2cMcuDeInit( I2c_t *obj );
99 
100 /*!
101  * \brief Reset the I2C object and MCU peripheral
102  *
103  * \param [IN] obj  I2C object
104  */
105 void I2cMcuResetBus( I2c_t *obj );
106 
107 /*!
108  * \brief Write data buffer to the I2C device
109  *
110  * \param [IN] obj              I2C object
111  * \param [IN] deviceAddr       device address
112  * \param [IN] buffer           data buffer to write
113  * \param [IN] size             number of data bytes to write
114  */
115 LmnStatus_t I2cMcuWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size );
116 
117 /*!
118  * \brief Read data buffer from the I2C device
119  *
120  * \param [IN] obj              I2C object
121  * \param [IN] deviceAddr       device address
122  * \param [IN] buffer           data buffer to read
123  * \param [IN] size             number of data bytes to read
124  */
125 LmnStatus_t I2cMcuReadBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size );
126 
127 /*!
128  * \brief Write data buffer starting at addr to the I2C device
129  *
130  * \param [IN] obj              I2C object
131  * \param [IN] deviceAddr       device address
132  * \param [IN] addr             data address
133  * \param [IN] buffer           data buffer to write
134  * \param [IN] size             number of data bytes to write
135  */
136 LmnStatus_t I2cMcuWriteMemBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size );
137 
138 /*!
139  * \brief Read data buffer starting at addr from the I2C device
140  *
141  * \param [IN] obj              I2C object
142  * \param [IN] deviceAddr       device address
143  * \param [IN] addr             data address
144  * \param [IN] buffer           data buffer to read
145  * \param [IN] size             number of data bytes to read
146  */
147 LmnStatus_t I2cMcuReadMemBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size );
148 
149 /*!
150  * \brief Waits until the given device is in standby mode
151  *
152  * \param [IN] obj              I2C object
153  * \param [IN] deviceAddr       device address
154  */
155 LmnStatus_t I2cMcuWaitStandbyState( I2c_t *obj, uint8_t deviceAddr );
156 
157 /*!
158  * \brief Sets the internal device address size
159  *
160  * \param [IN] obj              I2C object
161  * \param [IN] addrSize         Internal address size
162  */
163 void I2cSetAddrSize( I2c_t *obj, I2cAddrSize addrSize );
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif // __I2C_BOARD_H__
170