Skip to content

Commit b18c819

Browse files
author
Cruz Monrreal
authored
Merge pull request #8519 from cmonr/rollup
Rollup PR - UK Docathon pt1
2 parents 7cd1478 + fe1d6b0 commit b18c819

File tree

6 files changed

+148
-101
lines changed

6 files changed

+148
-101
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

drivers/SPISlave.h

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,18 @@
2626
namespace mbed {
2727
/** \addtogroup drivers */
2828

29-
/** A SPI slave, used for communicating with a SPI Master device
29+
/** A SPI slave, used for communicating with a SPI master device.
3030
*
31-
* The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz
31+
* The default format is set to 8 bits, mode 0 and a clock frequency of 1MHz.
3232
*
3333
* @note Synchronization level: Not protected
3434
*
35-
* Example:
35+
* Example of how to reply to a SPI master as slave:
3636
* @code
37-
* // Reply to a SPI master as slave
3837
*
3938
* #include "mbed.h"
4039
*
41-
* SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
40+
* SPISlave device(SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS);
4241
*
4342
* int main() {
4443
* device.reply(0x00); // Prime SPI with first reply
@@ -57,21 +56,21 @@ class SPISlave : private NonCopyable<SPISlave> {
5756

5857
public:
5958

60-
/** Create a SPI slave connected to the specified pins
59+
/** Create a SPI slave connected to the specified pins.
6160
*
62-
* mosi or miso can be specified as NC if not used
61+
* @note Either mosi or miso can be specified as NC if not used.
6362
*
64-
* @param mosi SPI Master Out, Slave In pin
65-
* @param miso SPI Master In, Slave Out pin
66-
* @param sclk SPI Clock pin
67-
* @param ssel SPI chip select pin
63+
* @param mosi SPI Master Out, Slave In pin.
64+
* @param miso SPI Master In, Slave Out pin.
65+
* @param sclk SPI Clock pin.
66+
* @param ssel SPI Chip Select pin.
6867
*/
6968
SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel);
7069

71-
/** Configure the data transmission format
70+
/** Configure the data transmission format.
7271
*
73-
* @param bits Number of bits per SPI frame (4 - 16)
74-
* @param mode Clock polarity and phase mode (0 - 3)
72+
* @param bits Number of bits per SPI frame (4 - 16).
73+
* @param mode Clock polarity and phase mode (0 - 3).
7574
*
7675
* @code
7776
* mode | POL PHA
@@ -84,40 +83,47 @@ class SPISlave : private NonCopyable<SPISlave> {
8483
*/
8584
void format(int bits, int mode = 0);
8685

87-
/** Set the spi bus clock frequency
86+
/** Set the SPI bus clock frequency.
8887
*
89-
* @param hz SCLK frequency in hz (default = 1MHz)
88+
* @param hz Clock frequency in hz (default = 1MHz).
9089
*/
9190
void frequency(int hz = 1000000);
9291

93-
/** Polls the SPI to see if data has been received
92+
/** Polls the SPI to see if data has been received.
9493
*
95-
* @returns
96-
* 0 if no data,
97-
* 1 otherwise
94+
* @return Presence of received data.
95+
* @retval 0 No data waiting.
96+
* @retval 1 Data waiting.
9897
*/
9998
int receive(void);
10099

101-
/** Retrieve data from receive buffer as slave
100+
/** Retrieve data from receive buffer as slave.
102101
*
103-
* @returns
104-
* the data in the receive buffer
102+
* @return The data in the receive buffer.
105103
*/
106104
int read(void);
107105

108106
/** Fill the transmission buffer with the value to be written out
109107
* as slave on the next received message from the master.
110108
*
111-
* @param value the data to be transmitted next
109+
* @param value The data to be transmitted next.
112110
*/
113111
void reply(int value);
114112

113+
#if !defined(DOXYGEN_ONLY)
114+
115115
protected:
116+
/* Internal SPI object identifying the resources */
116117
spi_t _spi;
117118

119+
/* How many bits in an SPI frame */
118120
int _bits;
121+
/* Clock phase and polarity */
119122
int _mode;
123+
/* Clock frequency */
120124
int _hz;
125+
126+
#endif //!defined(DOXYGEN_ONLY)
121127
};
122128

123129
} // namespace mbed

features/netsocket/SocketAddress.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SocketAddress {
4242
*
4343
* @param stack Network stack to use for DNS resolution
4444
* @param host Hostname to resolve
45-
* @param port Optional 16-bit port
45+
* @param port Optional 16-bit port, defaults to 0
4646
* @deprecated
4747
* Constructors hide possible errors. Replaced by
4848
* NetworkInterface::gethostbyname.
@@ -57,24 +57,26 @@ class SocketAddress {
5757
}
5858

5959
/** Create a SocketAddress from a raw IP address and port
60+
*
61+
* To construct from a host name, use NetworkInterface::gethostbyname
6062
*
6163
* @param addr Raw IP address
62-
* @param port Optional 16-bit port
64+
* @param port Optional 16-bit port, defaults to 0
6365
*/
6466
SocketAddress(nsapi_addr_t addr = nsapi_addr_t(), uint16_t port = 0);
6567

6668
/** Create a SocketAddress from an IP address and port
6769
*
6870
* @param addr Null-terminated representation of the IP address
69-
* @param port Optional 16-bit port
71+
* @param port Optional 16-bit port, defaults to 0
7072
*/
7173
SocketAddress(const char *addr, uint16_t port = 0);
7274

7375
/** Create a SocketAddress from raw IP bytes, IP version, and port
7476
*
7577
* @param bytes Raw IP address in big-endian order
7678
* @param version IP address version, NSAPI_IPv4 or NSAPI_IPv6
77-
* @param port Optional 16-bit port
79+
* @param port Optional 16-bit port, defaults to 0
7880
*/
7981
SocketAddress(const void *bytes, nsapi_version_t version, uint16_t port = 0);
8082

0 commit comments

Comments
 (0)