drivers: i2c: shell: add I2C bus recovery shell command

Add I2C shell command for initiating a bus recovery.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
Henrik Brix Andersen 2020-04-20 14:13:55 +02:00 committed by Carles Cufí
parent 6aa8a83682
commit 338cecbe1a
2 changed files with 24 additions and 1 deletions

View file

@ -21,7 +21,7 @@ config I2C_SHELL
help
Enable I2C Shell.
The I2C shell currently support scanning.
The I2C shell currently support scanning and bus recovery.
# Include these first so that any properties (e.g. defaults) below can be
# overridden (by defining symbols in multiple locations)

View file

@ -66,6 +66,27 @@ static int cmd_i2c_scan(const struct shell *shell,
return 0;
}
static int cmd_i2c_recover(const struct shell *shell,
size_t argc, char **argv)
{
struct device *dev;
int err;
dev = device_get_binding(argv[1]);
if (!dev) {
shell_error(shell, "I2C: Device driver %s not found.", argv[1]);
return -ENODEV;
}
err = i2c_recover_bus(dev);
if (err) {
shell_error(shell, "I2C: Bus recovery failed (err %d)", err);
return err;
}
return 0;
}
static void device_name_get(size_t idx, struct shell_static_entry *entry);
SHELL_DYNAMIC_CMD_CREATE(dsub_device_name, device_name_get);
@ -96,6 +117,8 @@ static void device_name_get(size_t idx, struct shell_static_entry *entry)
SHELL_STATIC_SUBCMD_SET_CREATE(sub_i2c_cmds,
SHELL_CMD(scan, &dsub_device_name,
"Scan I2C devices", cmd_i2c_scan),
SHELL_CMD(recover, &dsub_device_name,
"Recover I2C bus", cmd_i2c_recover),
SHELL_SUBCMD_SET_END /* Array terminated. */
);