Skip to content

Commit 0e2983e

Browse files
Cruz Monrreal IICruz Monrreal II
authored andcommitted
Merge branch 'doc-fix-i2c_slave' of ssh://github.com/paul-szczepanek-arm/mbed-os into rollup
2 parents 2274fc8 + 7fa3a44 commit 0e2983e

File tree

1 file changed

+55
-47
lines changed

1 file changed

+55
-47
lines changed

drivers/I2CSlave.h

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,41 @@
2525
namespace mbed {
2626
/** \addtogroup drivers */
2727

28-
/** An I2C Slave, used for communicating with an I2C Master device
28+
/** An I2C Slave, used for communicating with an I2C Master device.
2929
*
3030
* @note Synchronization level: Not protected
3131
*
32-
* Example:
32+
* Example Simple I2C responder:
3333
* @code
34-
* // Simple I2C responder
3534
* #include <mbed.h>
3635
*
37-
* I2CSlave slave(p9, p10);
36+
* const int SLAVE_ADDRESS = 0xA0;
37+
* const char message[] = "Slave!";
3838
*
39-
* int main() {
40-
* char buf[10];
41-
* char msg[] = "Slave!";
39+
* I2CSlave slave(I2C_SDA, I2C_SCL);
4240
*
43-
* slave.address(0xA0);
41+
* int main() {
42+
* slave.address(SLAVE_ADDRESS);
4443
* while (1) {
45-
* int i = slave.receive();
46-
* switch (i) {
44+
* int operation = slave.receive();
45+
* switch (operation) {
4746
* case I2CSlave::ReadAddressed:
48-
* slave.write(msg, strlen(msg) + 1); // Includes null char
47+
* int status = slave.write(message, sizeof(message));
48+
* if (status == 0) {
49+
* printf("Written message: %s\n", message);
50+
* } else {
51+
* printf("Failed to write message.\n");
52+
* }
4953
* break;
5054
* case I2CSlave::WriteGeneral:
51-
* slave.read(buf, 10);
52-
* printf("Read G: %s\n", buf);
55+
* int byte_read = slave.read();
56+
* printf("Read General: %c (%d)\n", byte_read, byte_read);
5357
* break;
5458
* case I2CSlave::WriteAddressed:
55-
* slave.read(buf, 10);
56-
* printf("Read A: %s\n", buf);
59+
* int byte_read = slave.read();
60+
* printf("Read Addressed: %c (%d)\n", byte_read, byte_read);
5761
* break;
5862
* }
59-
* for(int i = 0; i < 10; i++) buf[i] = 0; // Clear buffer
6063
* }
6164
* }
6265
* @endcode
@@ -74,71 +77,71 @@ class I2CSlave {
7477

7578
/** Create an I2C Slave interface, connected to the specified pins.
7679
*
77-
* @param sda I2C data line pin
78-
* @param scl I2C clock line pin
80+
* @param sda I2C data line pin.
81+
* @param scl I2C clock line pin.
7982
*/
8083
I2CSlave(PinName sda, PinName scl);
8184

82-
/** Set the frequency of the I2C interface
85+
/** Set the frequency of the I2C interface.
8386
*
84-
* @param hz The bus frequency in hertz
87+
* @param hz The bus frequency in Hertz.
8588
*/
8689
void frequency(int hz);
8790

88-
/** Checks to see if this I2C Slave has been addressed.
91+
/** Check if this I2C Slave has been addressed.
8992
*
90-
* @returns
91-
* A status indicating if the device has been addressed, and how
92-
* - NoData - the slave has not been addressed
93-
* - ReadAddressed - the master has requested a read from this slave
94-
* - WriteAddressed - the master is writing to this slave
95-
* - WriteGeneral - the master is writing to all slave
93+
* @return A status indicating if the device has been addressed and how.
94+
* @retval NoData The slave has not been addressed.
95+
* @retval ReadAddressed The master has requested a read from this slave.
96+
* @retval WriteAddressed The master is writing to this slave.
97+
* @retval WriteGeneral The master is writing to all slave.
9698
*/
9799
int receive(void);
98100

99-
/** Read from an I2C master.
101+
/** Read specified number of bytes from an I2C master.
100102
*
101-
* @param data pointer to the byte array to read data in to
102-
* @param length maximum number of bytes to read
103+
* @param data Pointer to the buffer to read data into.
104+
* @param length Number of bytes to read.
103105
*
104-
* @returns
105-
* 0 on success,
106-
* non-0 otherwise
106+
* @return Result of the operation.
107+
* @retval 0 If the number of bytes read is equal to length requested.
108+
* @retval nonzero On error or if the number of bytes read is less than requested.
107109
*/
108110
int read(char *data, int length);
109111

110112
/** Read a single byte from an I2C master.
111113
*
112-
* @returns
113-
* the byte read
114+
* @return The byte read.
114115
*/
115116
int read(void);
116117

117118
/** Write to an I2C master.
118119
*
119-
* @param data pointer to the byte array to be transmitted
120-
* @param length the number of bytes to transmite
120+
* @param data Pointer to the buffer containing the data to be sent.
121+
* @param length Number of bytes to send.
121122
*
122-
* @returns
123-
* 0 on success,
124-
* non-0 otherwise
123+
* @return
124+
* @retval 0 If written all bytes successfully.
125+
* @retval nonzero On error or if the number of bytes written is less than requested.
125126
*/
126127
int write(const char *data, int length);
127128

128129
/** Write a single byte to an I2C master.
129130
*
130-
* @param data the byte to write
131+
* @param data Value to write.
131132
*
132-
* @returns
133-
* '1' if an ACK was received,
134-
* '0' otherwise
133+
* @return Result of the operation.
134+
* @retval 0 If a NACK is received.
135+
* @retval 1 If an ACK is received.
136+
* @retval 2 On timeout.
135137
*/
136138
int write(int data);
137139

138-
/** Sets the I2C slave address.
140+
/** Set the I2C slave address.
141+
*
142+
* @param address The address to set for the slave (least significant bit is ignored).
139143
*
140-
* @param address The address to set for the slave (ignoring the least
141-
* signifcant bit). If set to 0, the slave will only respond to the
144+
* @note If address is set to 0, the slave will only respond to the
142145
* general call address.
143146
*/
144147
void address(int address);
@@ -147,8 +150,13 @@ class I2CSlave {
147150
*/
148151
void stop(void);
149152

153+
#if !defined(DOXYGEN_ONLY)
154+
150155
protected:
156+
/* Internal i2c object identifying the resources */
151157
i2c_t _i2c;
158+
159+
#endif //!defined(DOXYGEN_ONLY)
152160
};
153161

154162
} // namespace mbed

0 commit comments

Comments
 (0)