You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by vi...@apache.org on 2017/02/24 19:38:31 UTC
[36/50] incubator-mynewt-core git commit: SensorAPI - Add some more
commands for debugging
SensorAPI - Add some more commands for debugging
- Add i2cscan command for debugging
- Add register dump command for dumping value of any register
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/521ea9b8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/521ea9b8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/521ea9b8
Branch: refs/heads/develop
Commit: 521ea9b845a443cbc9b16160c812dee0b1114fd0
Parents: 33253b2
Author: Vipul Rahane <vi...@apache.org>
Authored: Mon Feb 13 17:22:11 2017 -0800
Committer: Vipul Rahane <vi...@apache.org>
Committed: Mon Feb 13 17:22:11 2017 -0800
----------------------------------------------------------------------
apps/slinky/src/main.c | 2 +-
.../sensors/bno055/include/bno055/bno055.h | 11 +++
hw/drivers/sensors/bno055/src/bno055.c | 30 ++++---
hw/drivers/sensors/bno055/src/bno055_shell.c | 90 ++++++++++++++------
4 files changed, 92 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/521ea9b8/apps/slinky/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c
index 2bdcc76..aceca28 100755
--- a/apps/slinky/src/main.c
+++ b/apps/slinky/src/main.c
@@ -305,7 +305,7 @@ config_sensor(void)
rc = bno055_config((struct bno055 *) dev, &bcfg);
if (rc) {
os_dev_close(dev);
- assert(0);
+ //assert(0);
goto err;
}
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/521ea9b8/hw/drivers/sensors/bno055/include/bno055/bno055.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/include/bno055/bno055.h b/hw/drivers/sensors/bno055/include/bno055/bno055.h
index a540628..64138d5 100644
--- a/hw/drivers/sensors/bno055/include/bno055/bno055.h
+++ b/hw/drivers/sensors/bno055/include/bno055/bno055.h
@@ -77,6 +77,17 @@ int
bno055_get_temp(int8_t *temp);
/**
+ * Reads a single byte from the specified register
+ *
+ * @param The register address to read from
+ * @param Pointer to where the register value should be written
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int
+bno055_read8(uint8_t reg, uint8_t *value);
+
+/**
* Setting mode for the bno055 sensor
*
* @param Operation mode for the sensor
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/521ea9b8/hw/drivers/sensors/bno055/src/bno055.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055.c b/hw/drivers/sensors/bno055/src/bno055.c
index b74fcb2..43e72b8 100644
--- a/hw/drivers/sensors/bno055/src/bno055.c
+++ b/hw/drivers/sensors/bno055/src/bno055.c
@@ -125,7 +125,7 @@ bno055_write8(uint8_t reg, uint32_t value)
};
rc = hal_i2c_master_write(MYNEWT_VAL(BNO055_I2CBUS), &data_struct,
- OS_TICKS_PER_SEC / 10, 1);
+ OS_TICKS_PER_SEC, 1);
if (rc) {
BNO055_ERR("Failed to write to 0x%02X:0x%02X with value 0x%02X\n",
data_struct.address, reg, value);
@@ -347,6 +347,12 @@ err:
return (rc);
}
+/**
+ * Get chip ID from the sensor
+ *
+ * @param Pointer to the variable to fill up chip ID in
+ * @return 0 on success, non-zero on failure
+ */
int
bno055_get_chip_id(uint8_t *id)
{
@@ -431,16 +437,6 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
prev_mode = g_bno055_mode;
- /**
- * As per Section 5.5 in the BNO055 Datasheet,
- * external crystal should be used for accurate
- * results
- */
- rc = bno055_set_ext_xtal_use(1);
- if (rc) {
- goto err;
- }
-
/* Check if we can read the chip address */
rc = bno055_read8(BNO055_CHIP_ID_ADDR, &id);
if (rc) {
@@ -467,7 +463,7 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
}
/* Reset sensor */
- rc = bno055_write8(BNO055_SYS_TRIGGER_ADDR, 0x20);
+ rc = bno055_write8(BNO055_SYS_TRIGGER_ADDR, BNO055_SYS_TRIGGER_RST_SYS);
if (rc) {
goto err;
}
@@ -488,6 +484,16 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
os_time_delay(OS_TICKS_PER_SEC/1000 * 10);
+ /**
+ * As per Section 5.5 in the BNO055 Datasheet,
+ * external crystal should be used for accurate
+ * results
+ */
+ rc = bno055_set_ext_xtal_use(1);
+ if (rc) {
+ goto err;
+ }
+
/* Overwrite the configuration data. */
memcpy(&bno055->cfg, cfg, sizeof(*cfg));
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/521ea9b8/hw/drivers/sensors/bno055/src/bno055_shell.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055_shell.c b/hw/drivers/sensors/bno055/src/bno055_shell.c
index 3f39a38..48a1196 100644
--- a/hw/drivers/sensors/bno055/src/bno055_shell.c
+++ b/hw/drivers/sensors/bno055/src/bno055_shell.c
@@ -30,6 +30,7 @@
#include "sensor/mag.h"
#include "sensor/quat.h"
#include "sensor/euler.h"
+#include "hal/hal_i2c.h"
#if MYNEWT_VAL(BNO055_CLI)
extern uint8_t g_bno055_mode;
@@ -333,37 +334,66 @@ bno055_shell_cmd_int(int argc, char **argv)
/* Unknown command */
return bno055_shell_err_invalid_arg(argv[2]);
}
+#endif
static int
-bno055_shell_cmd_dump(int argc, char **argv)
+bno055_shell_cmd_dumpreg(int argc, char **argv)
{
- uint8_t val;
-
- if (argc > 3) {
- return bno055_shell_err_too_many_args(argv[1]);
- }
-
- val = 0;
- assert(0 == bno055_read8(BNO055_COMMAND_BIT | BNO055_REGISTER_CONTROL, &val));
- console_printf("0x%02X (CONTROL): 0x%02X\n", BNO055_REGISTER_CONTROL, val);
- assert(0 == bno055_read8(BNO055_COMMAND_BIT | BNO055_REGISTER_TIMING, &val));
- console_printf("0x%02X (TIMING): 0x%02X\n", BNO055_REGISTER_TIMING, val);
- assert(0 == bno055_read8(BNO055_COMMAND_BIT | BNO055_REGISTER_THRESHHOLDL_LOW, &val));
- console_printf("0x%02X (THRLL): 0x%02X\n", BNO055_REGISTER_THRESHHOLDL_LOW, val);
- assert(0 == bno055_read8(BNO055_COMMAND_BIT | BNO055_REGISTER_THRESHHOLDL_HIGH, &val));
- console_printf("0x%02X (THRLH): 0x%02X\n", BNO055_REGISTER_THRESHHOLDL_HIGH, val);
- assert(0 == bno055_read8(BNO055_COMMAND_BIT | BNO055_REGISTER_THRESHHOLDH_LOW, &val));
- console_printf("0x%02X (THRHL): 0x%02X\n", BNO055_REGISTER_THRESHHOLDH_LOW, val);
- assert(0 == bno055_read8(BNO055_COMMAND_BIT | BNO055_REGISTER_THRESHHOLDH_HIGH, &val));
- console_printf("0x%02X (THRHH): 0x%02X\n", BNO055_REGISTER_THRESHHOLDH_HIGH, val);
- assert(0 == bno055_read8(BNO055_COMMAND_BIT | BNO055_REGISTER_INTERRUPT, &val));
- console_printf("0x%02X (INTER): 0x%02X\n", BNO055_REGISTER_INTERRUPT, val);
- assert(0 == bno055_read8(BNO055_COMMAND_BIT | BNO055_REGISTER_ID, &val));
- console_printf("0x%02X (ID): 0x%02X\n", BNO055_REGISTER_ID, val);
-
- return 0;
+ long addr;
+ uint8_t val;
+ int rc;
+
+ if (bno055_shell_stol(argv[2], 0, UINT8_MAX, &addr)) {
+ return bno055_shell_err_invalid_arg(argv[2]);
+ }
+ rc = bno055_read8((uint8_t)addr, &val);
+ if (rc) {
+ goto err;
+ }
+ console_printf("0x%02X (ADDR): 0x%02X", (uint8_t)addr, val);
+
+ return 0;
+err:
+ return rc;
+}
+
+static int
+shell_i2cscan_cmd(int argc, char **argv)
+{
+ uint8_t addr;
+ int32_t timeout = OS_TICKS_PER_SEC / 10;
+ uint8_t dev_count = 0;
+ long i2cnum;
+ int rc;
+
+ if (bno055_shell_stol(argv[2], 0, 0xf, &i2cnum)) {
+ return bno055_shell_err_invalid_arg(argv[2]);
+ }
+
+ console_printf("Scanning I2C bus %u\n"
+ " 0 1 2 3 4 5 6 7 8 9 a b c d e f\n"
+ "00: ", (uint8_t)i2cnum);
+
+
+ /* Scan all valid I2C addresses (0x08..0x77) */
+ for (addr = 0x08; addr < 0x78; addr++) {
+ rc = hal_i2c_master_probe((uint8_t)i2cnum, addr, timeout);
+ /* Print addr header every 16 bytes */
+ if (!(addr % 16)) {
+ console_printf("\n%02x: ", addr);
+ }
+ /* Display the addr if a response was received */
+ if (!rc) {
+ console_printf("%02x ", addr);
+ dev_count++;
+ } else {
+ console_printf("-- ");
+ }
+ }
+ console_printf("\nFound %u devices on I2C bus 0\n", dev_count);
+
+ return 0;
}
-#endif
static int
bno055_shell_cmd(int argc, char **argv)
@@ -402,11 +432,15 @@ bno055_shell_cmd(int argc, char **argv)
return bno055_shell_cmd_pmode(argc, argv);
}
+#endif
/* Dump Registers command */
if (argc > 1 && strcmp(argv[1], "dumpreg") == 0) {
return bno055_shell_cmd_dumpreg(argc, argv);
}
-#endif
+
+ if (argc > 1 && strcmp(argv[1], "i2cscan") == 0) {
+ return shell_i2cscan_cmd(argc, argv);
+ }
return bno055_shell_err_unknown_arg(argv[1]);
}