summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorAntony Pavlov <antonynpavlov@gmail.com>2018-02-08 10:48:56 +0300
committerSascha Hauer <s.hauer@pengutronix.de>2018-02-09 09:34:47 +0100
commit34fadb685905530a15bb78d1c09bb281bc91458b (patch)
tree4df411a2311f8e74cf18600a4d0f3966cc7d69e3 /commands
parentbdf5be35d7b7d4b74de0e101e9b874d41235b157 (diff)
downloadbarebox-34fadb685905530a15bb78d1c09bb281bc91458b.tar.gz
commands: i2c_write: enable raw write to address
Sometimes for communication with a simple I2C devices (e.g. PCF8574 or TM1650) it's necessary to send only one data byte into the I2C device. Current i2c_write command makes this impossible because you can't just pass 'device address' and 'register number' (or 'device address' and 'one data byte') to the command. You always have to pass all three parameters: 'device address', 'register number' and 'data'. This commit fixes the problem. Sample usage: barebox@barebox sandbox:/ i2c_write -a 0x24 0x01 Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/i2c.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/commands/i2c.c b/commands/i2c.c
index b74c535..21c39fe 100644
--- a/commands/i2c.c
+++ b/commands/i2c.c
@@ -115,7 +115,7 @@ static int do_i2c_write(int argc, char *argv[])
count = argc - optind;
- if ((addr < 0) || (reg < 0) || (count == 0) || (addr > 0x7F))
+ if ((addr < 0) || (count == 0) || (addr > 0x7F))
return COMMAND_ERROR_USAGE;
adapter = i2c_get_adapter(bus);
@@ -131,7 +131,11 @@ static int do_i2c_write(int argc, char *argv[])
for (i = 0; i < count; i++)
*(buf + i) = (char) simple_strtol(argv[optind+i], NULL, 0);
- ret = i2c_write_reg(&client, reg | wide, buf, count);
+ if (reg > 0) {
+ ret = i2c_write_reg(&client, reg | wide, buf, count);
+ } else {
+ ret = i2c_master_send(&client, buf, count);
+ }
if (ret != count) {
if (verbose)
printf("write aborted, count(%i) != writestatus(%i)\n",