You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2022/02/14 08:11:54 UTC
[mynewt-core] 10/10: i2c_scan: Allow usage with bus drivers
This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 71e395f88c67889ed32d5a13be01f8cc5ce6dd26
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Wed Jun 30 16:18:20 2021 +0200
i2c_scan: Allow usage with bus drivers
Package test/i2c_scan can be now used with MCUs
that have only bus driver support.
---
test/i2c_scan/src/i2c_scan.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/test/i2c_scan/src/i2c_scan.c b/test/i2c_scan/src/i2c_scan.c
index 8420497..00cffda 100644
--- a/test/i2c_scan/src/i2c_scan.c
+++ b/test/i2c_scan/src/i2c_scan.c
@@ -23,6 +23,9 @@
#include <shell/shell.h>
#include <console/console.h>
#include <parse/parse.h>
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+#include <bus/drivers/i2c_common.h>
+#endif
static int i2c_scan_cli_cmd(int argc, char **argv);
@@ -31,6 +34,32 @@ static struct shell_cmd i2c_scan_cmd_struct = {
.sc_cmd_func = i2c_scan_cli_cmd
};
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+static int
+i2c_scan_probe(int i2c_num, uint16_t address, uint32_t timeout)
+{
+ char bus_name[5] = "i2cX";
+ struct bus_i2c_dev *bus;
+ int rc = SYS_EINVAL;
+
+ bus_name[3] = i2c_num + '0';
+
+ bus = (struct bus_i2c_dev *)os_dev_open(bus_name, timeout, NULL);
+ if (bus) {
+ rc = bus_i2c_probe(bus, address, timeout);
+ (void)os_dev_close((struct os_dev *)bus);
+ }
+
+ return rc;
+}
+#else
+static int
+i2c_scan_probe(int i2cnum, uint16_t address, uint32_t timeout)
+{
+ return hal_i2c_master_probe(i2cnum, address, timeout);
+}
+#endif
+
static int
i2c_scan_cli_cmd(int argc, char **argv)
{
@@ -60,7 +89,7 @@ i2c_scan_cli_cmd(int argc, char **argv)
/* Scan all valid I2C addresses (0x08..0x77) */
for (addr = 0x08; addr < 0x78; addr++) {
- rc = hal_i2c_master_probe(i2cnum, addr, timeout);
+ rc = i2c_scan_probe(i2cnum, addr, timeout);
/* Print addr header every 16 bytes */
if (!(addr % 16)) {
console_printf("\n%02x: ", addr);