From acabbebdb4e582d7628c35c7c0867ee9d7b3c83a Mon Sep 17 00:00:00 2001 From: Naveen Kaje Date: Fri, 12 Oct 2018 12:06:39 -0500 Subject: [PATCH 1/3] I2C.h: Remove protected attributes from appearing on docs site --- drivers/I2C.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/I2C.h b/drivers/I2C.h index c031d65b59..330f1746ef 100644 --- a/drivers/I2C.h +++ b/drivers/I2C.h @@ -193,6 +193,7 @@ protected: bool _deep_sleep_locked; #endif +#if !defined(DOXYGEN_ONLY) protected: void aquire(); @@ -202,6 +203,7 @@ protected: static SingletonPtr _mutex; PinName _sda; PinName _scl; +#endif private: /** Recover I2C bus, when stuck with SDA low From 19c91081c677ae7beb3670572446152ad5395600 Mon Sep 17 00:00:00 2001 From: Naveen Kaje Date: Fri, 12 Oct 2018 13:44:41 -0500 Subject: [PATCH 2/3] I2C.h: Update documentation, example and formatting Change the example to a more elaborate implementation. Fix formatting and update documentation. --- drivers/I2C.h | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/drivers/I2C.h b/drivers/I2C.h index 330f1746ef..b9df4f864a 100644 --- a/drivers/I2C.h +++ b/drivers/I2C.h @@ -41,16 +41,32 @@ namespace mbed { * * Example: * @code - * // Read from I2C slave at address 0x62 - * + * Read temperature from LM75BD * #include "mbed.h" - * - * I2C i2c(p28, p27); + * I2C i2c(I2C_SDA , I2C_SCL); + * const int addr7bit = 0x48; // 7 bit I2C address + * const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90 * * int main() { - * int address = 0x62; - * char data[2]; - * i2c.read(address, data, 2); + * char cmd[2]; + * while (1) { + * cmd[0] = 0x01; + * cmd[1] = 0x00; + * + * // read and write takes the 8 bit version of the address. + * // set up configuration register (at 0x01) + * i2c.write(addr8bit, cmd, 2); + * + * wait(0.5); + * + * // read temperature register + * cmd[0] = 0x00; + * i2c.write(addr8bit, cmd, 1); + * i2c.read( addr8bit, cmd, 2); + * + * float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0); + * printf("Temp = %.2f\n", tmp); + * } * } * @endcode * @ingroup drivers @@ -92,10 +108,11 @@ public: * @param data Pointer to the byte-array to read data in to * @param length Number of bytes to read * @param repeated Repeated start, true - don't send stop at end + * default value is false. * * @returns * 0 on success (ack), - * non-0 on failure (nack) + * non-zero on failure (nack) */ int read(int address, char *data, int length, bool repeated = false); @@ -117,10 +134,11 @@ public: * @param data Pointer to the byte-array data to send * @param length Number of bytes to send * @param repeated Repeated start, true - do not send stop at end + * default value is false. * * @returns * 0 on success (ack), - * non-0 on failure (nack) + * non-zero on failure (nack) */ int write(int address, const char *data, int length, bool repeated = false); @@ -137,7 +155,6 @@ public: /** Creates a start condition on the I2C bus */ - void start(void); /** Creates a stop condition on the I2C bus @@ -171,7 +188,9 @@ public: * @param event The logical OR of events to modify * @param callback The event callback function * @param repeated Repeated start, true - do not send stop at end - * @return Zero if the transfer has started, or -1 if I2C peripheral is busy + * default value is false. + * + * @returns Zero if the transfer has started, or -1 if I2C peripheral is busy */ 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); @@ -212,7 +231,7 @@ private: * @param sda I2C data line pin * @param scl I2C clock line pin * - * @returns: + * @returns * '0' - Successfully recovered * 'I2C_ERROR_BUS_BUSY' - In case of failure * From 19472ff1543be5446d1441e6c55021b79fbcb630 Mon Sep 17 00:00:00 2001 From: Amanda Butler Date: Fri, 12 Oct 2018 14:56:01 -0500 Subject: [PATCH 3/3] Copy edit I2C.h Edit existing text. --- drivers/I2C.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/I2C.h b/drivers/I2C.h index b9df4f864a..db3b505ae3 100644 --- a/drivers/I2C.h +++ b/drivers/I2C.h @@ -44,8 +44,8 @@ namespace mbed { * Read temperature from LM75BD * #include "mbed.h" * I2C i2c(I2C_SDA , I2C_SCL); - * const int addr7bit = 0x48; // 7 bit I2C address - * const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90 + * const int addr7bit = 0x48; // 7-bit I2C address + * const int addr8bit = 0x48 << 1; // 8-bit I2C address, 0x90 * * int main() { * char cmd[2]; @@ -53,7 +53,7 @@ namespace mbed { * cmd[0] = 0x01; * cmd[1] = 0x00; * - * // read and write takes the 8 bit version of the address. + * // read and write takes the 8-bit version of the address. * // set up configuration register (at 0x01) * i2c.write(addr8bit, cmd, 2); * @@ -112,7 +112,7 @@ public: * * @returns * 0 on success (ack), - * non-zero on failure (nack) + * nonzero on failure (nack) */ int read(int address, char *data, int length, bool repeated = false); @@ -138,7 +138,7 @@ public: * * @returns * 0 on success (ack), - * non-zero on failure (nack) + * nonzero on failure (nack) */ int write(int address, const char *data, int length, bool repeated = false); @@ -176,14 +176,14 @@ public: #if DEVICE_I2C_ASYNCH - /** Start non-blocking I2C transfer. + /** Start nonblocking I2C transfer. * * This function locks the deep sleep until any event has occurred * * @param address 8/10 bit I2C slave address * @param tx_buffer The TX buffer with data to be transfered * @param tx_length The length of TX buffer in bytes - * @param rx_buffer The RX buffer which is used for received data + * @param rx_buffer The RX buffer, which is used for received data * @param rx_length The length of RX buffer in bytes * @param event The logical OR of events to modify * @param callback The event callback function @@ -194,7 +194,7 @@ public: */ 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); - /** Abort the on-going I2C transfer + /** Abort the ongoing I2C transfer */ void abort_transfer();