@@ -41,16 +41,32 @@ namespace mbed {
41
41
*
42
42
* Example:
43
43
* @code
44
- * // Read from I2C slave at address 0x62
45
- *
44
+ * Read temperature from LM75BD
46
45
* #include "mbed.h"
47
- *
48
- * I2C i2c(p28, p27);
46
+ * I2C i2c(I2C_SDA , I2C_SCL);
47
+ * const int addr7bit = 0x48; // 7-bit I2C address
48
+ * const int addr8bit = 0x48 << 1; // 8-bit I2C address, 0x90
49
49
*
50
50
* int main() {
51
- * int address = 0x62;
52
- * char data[2];
53
- * i2c.read(address, data, 2);
51
+ * char cmd[2];
52
+ * while (1) {
53
+ * cmd[0] = 0x01;
54
+ * cmd[1] = 0x00;
55
+ *
56
+ * // read and write takes the 8-bit version of the address.
57
+ * // set up configuration register (at 0x01)
58
+ * i2c.write(addr8bit, cmd, 2);
59
+ *
60
+ * wait(0.5);
61
+ *
62
+ * // read temperature register
63
+ * cmd[0] = 0x00;
64
+ * i2c.write(addr8bit, cmd, 1);
65
+ * i2c.read( addr8bit, cmd, 2);
66
+ *
67
+ * float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0);
68
+ * printf("Temp = %.2f\n", tmp);
69
+ * }
54
70
* }
55
71
* @endcode
56
72
* @ingroup drivers
@@ -92,10 +108,11 @@ class I2C : private NonCopyable<I2C> {
92
108
* @param data Pointer to the byte-array to read data in to
93
109
* @param length Number of bytes to read
94
110
* @param repeated Repeated start, true - don't send stop at end
111
+ * default value is false.
95
112
*
96
113
* @returns
97
114
* 0 on success (ack),
98
- * non-0 on failure (nack)
115
+ * nonzero on failure (nack)
99
116
*/
100
117
int read (int address, char *data, int length, bool repeated = false );
101
118
@@ -117,10 +134,11 @@ class I2C : private NonCopyable<I2C> {
117
134
* @param data Pointer to the byte-array data to send
118
135
* @param length Number of bytes to send
119
136
* @param repeated Repeated start, true - do not send stop at end
137
+ * default value is false.
120
138
*
121
139
* @returns
122
140
* 0 on success (ack),
123
- * non-0 on failure (nack)
141
+ * nonzero on failure (nack)
124
142
*/
125
143
int write (int address, const char *data, int length, bool repeated = false );
126
144
@@ -137,7 +155,6 @@ class I2C : private NonCopyable<I2C> {
137
155
138
156
/* * Creates a start condition on the I2C bus
139
157
*/
140
-
141
158
void start (void );
142
159
143
160
/* * Creates a stop condition on the I2C bus
@@ -159,23 +176,25 @@ class I2C : private NonCopyable<I2C> {
159
176
160
177
#if DEVICE_I2C_ASYNCH
161
178
162
- /* * Start non-blocking I2C transfer.
179
+ /* * Start nonblocking I2C transfer.
163
180
*
164
181
* This function locks the deep sleep until any event has occurred
165
182
*
166
183
* @param address 8/10 bit I2C slave address
167
184
* @param tx_buffer The TX buffer with data to be transfered
168
185
* @param tx_length The length of TX buffer in bytes
169
- * @param rx_buffer The RX buffer which is used for received data
186
+ * @param rx_buffer The RX buffer, which is used for received data
170
187
* @param rx_length The length of RX buffer in bytes
171
188
* @param event The logical OR of events to modify
172
189
* @param callback The event callback function
173
190
* @param repeated Repeated start, true - do not send stop at end
174
- * @return Zero if the transfer has started, or -1 if I2C peripheral is busy
191
+ * default value is false.
192
+ *
193
+ * @returns Zero if the transfer has started, or -1 if I2C peripheral is busy
175
194
*/
176
195
int transfer (int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t &callback, int event = I2C_EVENT_TRANSFER_COMPLETE, bool repeated = false );
177
196
178
- /* * Abort the on-going I2C transfer
197
+ /* * Abort the ongoing I2C transfer
179
198
*/
180
199
void abort_transfer ();
181
200
@@ -193,6 +212,7 @@ class I2C : private NonCopyable<I2C> {
193
212
bool _deep_sleep_locked;
194
213
#endif
195
214
215
+ #if !defined(DOXYGEN_ONLY)
196
216
protected:
197
217
void aquire ();
198
218
@@ -202,6 +222,7 @@ class I2C : private NonCopyable<I2C> {
202
222
static SingletonPtr<PlatformMutex> _mutex;
203
223
PinName _sda;
204
224
PinName _scl;
225
+ #endif
205
226
206
227
private:
207
228
/* * Recover I2C bus, when stuck with SDA low
@@ -210,7 +231,7 @@ class I2C : private NonCopyable<I2C> {
210
231
* @param sda I2C data line pin
211
232
* @param scl I2C clock line pin
212
233
*
213
- * @returns:
234
+ * @returns
214
235
* '0' - Successfully recovered
215
236
* 'I2C_ERROR_BUS_BUSY' - In case of failure
216
237
*
0 commit comments