Commit | Line | Data |
---|---|---|
ca3355a9 DH |
1 | /* |
2 | Copyright (c), 2004-2005,2007-2010 Trident Microsystems, Inc. | |
3 | All rights reserved. | |
4 | ||
5 | Redistribution and use in source and binary forms, with or without | |
6 | modification, are permitted provided that the following conditions are met: | |
7 | ||
8 | * Redistributions of source code must retain the above copyright notice, | |
9 | this list of conditions and the following disclaimer. | |
10 | * Redistributions in binary form must reproduce the above copyright notice, | |
11 | this list of conditions and the following disclaimer in the documentation | |
12 | and/or other materials provided with the distribution. | |
13 | * Neither the name of Trident Microsystems nor Hauppauge Computer Works | |
14 | nor the names of its contributors may be used to endorse or promote | |
15 | products derived from this software without specific prior written | |
16 | permission. | |
17 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
28 | POSSIBILITY OF SUCH DAMAGE. | |
29 | */ | |
30 | ||
38b2df95 DH |
31 | /** |
32 | * \file $Id: bsp_i2c.h,v 1.5 2009/07/07 14:20:30 justin Exp $ | |
33 | * | |
34 | * \brief I2C API, implementation depends on board specifics | |
35 | * | |
36 | * This module encapsulates I2C access.In some applications several devices | |
37 | * share one I2C bus. If these devices have the same I2C address some kind | |
38 | * off "switch" must be implemented to ensure error free communication with | |
39 | * one device. In case such a "switch" is used, the device ID can be used | |
40 | * to implement control over this "switch". | |
41 | * | |
42 | * | |
43 | */ | |
44 | ||
38b2df95 DH |
45 | #ifndef __BSPI2C_H__ |
46 | #define __BSPI2C_H__ | |
47 | /*------------------------------------------------------------------------------ | |
48 | INCLUDES | |
49 | ------------------------------------------------------------------------------*/ | |
50 | #include "bsp_types.h" | |
51 | ||
52 | #ifdef __cplusplus | |
53 | extern "C" { | |
54 | #endif | |
55 | /*------------------------------------------------------------------------------ | |
56 | TYPEDEFS | |
57 | ------------------------------------------------------------------------------*/ | |
58 | /** | |
59 | * \typedef I2Caddr_t | |
60 | * \brief I2C device address (7-bit or 10-bit) | |
61 | */ | |
62 | typedef u16_t I2Caddr_t; | |
63 | ||
64 | /** | |
65 | * \typedef I2CdevId_t | |
66 | * \brief Device identifier. | |
67 | * | |
68 | * The device ID can be useful if several devices share an I2C address, | |
69 | * or if multiple I2C busses are used. | |
70 | * It can be used to control a "switch" selecting the correct device and/or | |
71 | * I2C bus. | |
72 | * | |
73 | */ | |
74 | typedef u16_t I2CdevId_t; | |
75 | ||
76 | /** | |
77 | * \struct _I2CDeviceAddr_t | |
78 | * \brief I2C device parameters. | |
79 | * | |
80 | * This structure contains the I2C address, the device ID and a userData pointer. | |
81 | * The userData pointer can be used for application specific purposes. | |
82 | * | |
83 | */ | |
84 | struct _I2CDeviceAddr_t { | |
85 | I2Caddr_t i2cAddr; /**< The I2C address of the device. */ | |
86 | I2CdevId_t i2cDevId; /**< The device identifier. */ | |
87 | void *userData; /**< User data pointer */ | |
88 | }; | |
89 | ||
90 | /** | |
91 | * \typedef I2CDeviceAddr_t | |
92 | * \brief I2C device parameters. | |
93 | * | |
94 | * This structure contains the I2C address and the device ID. | |
95 | * | |
96 | */ | |
97 | typedef struct _I2CDeviceAddr_t I2CDeviceAddr_t; | |
98 | ||
99 | /** | |
100 | * \typedef pI2CDeviceAddr_t | |
101 | * \brief Pointer to I2C device parameters. | |
102 | */ | |
103 | typedef I2CDeviceAddr_t *pI2CDeviceAddr_t; | |
104 | ||
105 | /*------------------------------------------------------------------------------ | |
106 | DEFINES | |
107 | ------------------------------------------------------------------------------*/ | |
108 | ||
109 | /*------------------------------------------------------------------------------ | |
110 | MACROS | |
111 | ------------------------------------------------------------------------------*/ | |
112 | ||
113 | /** | |
114 | * \def IS_I2C_10BIT( addr ) | |
115 | * \brief Determine if I2C address 'addr' is a 10 bits address or not. | |
116 | * \param addr The I2C address. | |
117 | * \return int. | |
118 | * \retval 0 if address is not a 10 bits I2C address. | |
119 | * \retval 1 if address is a 10 bits I2C address. | |
120 | */ | |
121 | #define IS_I2C_10BIT(addr) \ | |
122 | (((addr) & 0xF8) == 0xF0) | |
123 | ||
124 | /*------------------------------------------------------------------------------ | |
125 | ENUM | |
126 | ------------------------------------------------------------------------------*/ | |
127 | ||
128 | /*------------------------------------------------------------------------------ | |
129 | STRUCTS | |
130 | ------------------------------------------------------------------------------*/ | |
131 | ||
132 | /*------------------------------------------------------------------------------ | |
133 | Exported FUNCTIONS | |
134 | ------------------------------------------------------------------------------*/ | |
135 | ||
136 | ||
137 | /** | |
138 | * \fn DRXBSP_I2C_Init() | |
139 | * \brief Initialize I2C communication module. | |
140 | * \return DRXStatus_t Return status. | |
141 | * \retval DRX_STS_OK Initialization successful. | |
142 | * \retval DRX_STS_ERROR Initialization failed. | |
143 | */ | |
144 | DRXStatus_t DRXBSP_I2C_Init( void ); | |
145 | ||
146 | ||
147 | /** | |
148 | * \fn DRXBSP_I2C_Term() | |
149 | * \brief Terminate I2C communication module. | |
150 | * \return DRXStatus_t Return status. | |
151 | * \retval DRX_STS_OK Termination successful. | |
152 | * \retval DRX_STS_ERROR Termination failed. | |
153 | */ | |
154 | DRXStatus_t DRXBSP_I2C_Term( void ); | |
155 | ||
156 | /** | |
157 | * \fn DRXStatus_t DRXBSP_I2C_WriteRead( pI2CDeviceAddr_t wDevAddr, | |
158 | * u16_t wCount, | |
159 | * pu8_t wData, | |
160 | * pI2CDeviceAddr_t rDevAddr, | |
161 | * u16_t rCount, | |
162 | * pu8_t rData) | |
163 | * \brief Read and/or write count bytes from I2C bus, store them in data[]. | |
164 | * \param wDevAddr The device i2c address and the device ID to write to | |
165 | * \param wCount The number of bytes to write | |
166 | * \param wData The array to write the data to | |
167 | * \param rDevAddr The device i2c address and the device ID to read from | |
168 | * \param rCount The number of bytes to read | |
169 | * \param rData The array to read the data from | |
170 | * \return DRXStatus_t Return status. | |
171 | * \retval DRX_STS_OK Succes. | |
172 | * \retval DRX_STS_ERROR Failure. | |
173 | * \retval DRX_STS_INVALID_ARG Parameter 'wcount' is not zero but parameter | |
174 | * 'wdata' contains NULL. | |
175 | * Idem for 'rcount' and 'rdata'. | |
176 | * Both wDevAddr and rDevAddr are NULL. | |
177 | * | |
178 | * This function must implement an atomic write and/or read action on the I2C bus | |
179 | * No other process may use the I2C bus when this function is executing. | |
180 | * The critical section of this function runs from and including the I2C | |
181 | * write, up to and including the I2C read action. | |
182 | * | |
183 | * The device ID can be useful if several devices share an I2C address. | |
184 | * It can be used to control a "switch" on the I2C bus to the correct device. | |
185 | */ | |
186 | DRXStatus_t DRXBSP_I2C_WriteRead( pI2CDeviceAddr_t wDevAddr, | |
187 | u16_t wCount, | |
188 | pu8_t wData, | |
189 | pI2CDeviceAddr_t rDevAddr, | |
190 | u16_t rCount, | |
191 | pu8_t rData); | |
192 | ||
193 | ||
194 | /** | |
195 | * \fn DRXBSP_I2C_ErrorText() | |
196 | * \brief Returns a human readable error. | |
197 | * Counter part of numerical DRX_I2C_Error_g. | |
198 | * | |
199 | * \return char* Pointer to human readable error text. | |
200 | */ | |
201 | char* DRXBSP_I2C_ErrorText( void ); | |
202 | ||
203 | /** | |
204 | * \var DRX_I2C_Error_g; | |
205 | * \brief I2C specific error codes, platform dependent. | |
206 | */ | |
207 | extern int DRX_I2C_Error_g; | |
208 | ||
209 | ||
210 | /*------------------------------------------------------------------------------ | |
211 | THE END | |
212 | ------------------------------------------------------------------------------*/ | |
213 | #ifdef __cplusplus | |
214 | } | |
215 | #endif | |
216 | #endif /* __BSPI2C_H__ */ |