From: Sam Hansen <hansens@google.com>
To: linux-i2c@vger.kernel.org
Cc: Sam Hansen <hansens@google.com>,
wsa@the-dreams.de, corbet@lwn.net, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 3/3] Documentation/i2c: adopt kernel commenting style in examples
Date: Fri, 13 Apr 2018 09:44:05 -0700 [thread overview]
Message-ID: <20180413164405.127522-3-hansens@google.com> (raw)
In-Reply-To: <20180413164405.127522-1-hansens@google.com>
The example I2C code is rewritten to adopt the preferred kernel block
commenting style.
Signed-off-by: Sam Hansen <hansens@google.com>
---
Documentation/i2c/dev-interface | 57 +++++++++++++++++++++++++--------
1 file changed, 43 insertions(+), 14 deletions(-)
diff --git a/Documentation/i2c/dev-interface b/Documentation/i2c/dev-interface
index f92ee1f59914..e17f5814c199 100644
--- a/Documentation/i2c/dev-interface
+++ b/Documentation/i2c/dev-interface
@@ -30,24 +30,34 @@ assume much about them. They can even change from one boot to the next.
Next thing, open the device file, as follows:
+ /*
+ * The adapter is probably dynamically determined.
+ */
int file;
- int adapter_nr = 2; /* probably dynamically determined */
+ int adapter_nr = 2;
char filename[20];
snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);
file = open(filename, O_RDWR);
if (file < 0) {
- /* ERROR HANDLING; you can check errno to see what went wrong */
+ /*
+ * ERROR HANDLING; you can check errno to see what went wrong.
+ */
exit(1);
}
When you have opened the device, you must specify with what device
address you want to communicate:
- int addr = 0x40; /* The I2C address */
+ /*
+ * The I2C address.
+ */
+ int addr = 0x40;
if (ioctl(file, I2C_SLAVE, addr) < 0) {
- /* ERROR HANDLING; you can check errno to see what went wrong */
+ /*
+ * ERROR HANDLING; you can check errno to see what went wrong.
+ */
exit(1);
}
@@ -55,32 +65,51 @@ Well, you are all set up now. You can now use SMBus commands or plain
I2C to communicate with your device. SMBus commands are preferred if
the device supports them. Both are illustrated below.
- __u8 reg = 0x10; /* Device register to access */
+ /*
+ * The device register to access.
+ */
+ __u8 reg = 0x10;
__s32 res;
char buf[10];
- /* Using SMBus commands */
+ /*
+ * Using SMBus commands.
+ */
res = i2c_smbus_read_word_data(file, reg);
if (res < 0) {
- /* ERROR HANDLING: i2c transaction failed */
+ /*
+ * ERROR HANDLING: i2c transaction failed.
+ */
} else {
- /* res contains the read word */
+ /*
+ * res contains the read word.
+ */
}
- /* Using I2C Write, equivalent of
- i2c_smbus_write_word_data(file, reg, 0x6543) */
+ /*
+ * Using I2C Write, equivalent of
+ * i2c_smbus_write_word_data(file, reg, 0x6543).
+ */
buf[0] = reg;
buf[1] = 0x43;
buf[2] = 0x65;
if (write(file, buf, 3) != 3) {
- /* ERROR HANDLING: i2c transaction failed */
+ /*
+ * ERROR HANDLING: i2c transaction failed.
+ */
}
- /* Using I2C Read, equivalent of i2c_smbus_read_byte(file) */
+ /*
+ * Using I2C Read, equivalent of i2c_smbus_read_byte(file).
+ */
if (read(file, buf, 1) != 1) {
- /* ERROR HANDLING: i2c transaction failed */
+ /*
+ * ERROR HANDLING: i2c transaction failed.
+ */
} else {
- /* buf[0] contains the read byte */
+ /*
+ * buf[0] contains the read byte.
+ */
}
Note that only a subset of the I2C and SMBus protocols can be achieved by
--
2.17.0.484.g0c8726318c-goog
next prev parent reply other threads:[~2018-04-13 16:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-12 21:33 [PATCH] Documentation/i2c: sync docs with current state of i2c-tools Sam Hansen
2018-04-12 22:24 ` Wolfram Sang
2018-04-13 12:13 ` Jean Delvare
2018-04-13 16:02 ` Sam Hansen
2018-04-13 16:44 ` [PATCH v2 1/3] Documentation/i2c: whitespace cleanup Sam Hansen
2018-04-13 16:44 ` [PATCH v2 2/3] Documentation/i2c: sync docs with current state of i2c-tools Sam Hansen
2018-04-13 16:50 ` Wolfram Sang
2018-04-13 16:44 ` Sam Hansen [this message]
2018-04-13 16:50 ` [PATCH v2 3/3] Documentation/i2c: adopt kernel commenting style in examples Wolfram Sang
2018-04-13 17:39 ` Sam Hansen
2018-04-13 16:50 ` [PATCH v2 1/3] Documentation/i2c: whitespace cleanup Wolfram Sang
2018-04-13 18:49 ` [PATCH] Documentation/i2c: sync docs with current state of i2c-tools Jean Delvare
2018-04-13 23:32 ` Sam Hansen
2018-04-14 6:27 ` Wolfram Sang
2018-04-17 19:17 ` Sam Hansen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180413164405.127522-3-hansens@google.com \
--to=hansens@google.com \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wsa@the-dreams.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).