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/15 00:58:26 UTC
incubator-mynewt-core git commit: SensorAPI - BNO055 Cleaning up &
fixes
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/sensors_branch 521ea9b84 -> 4f61ce122
SensorAPI - BNO055 Cleaning up & fixes
- Adding prototype for write8
- fixing addressing
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/4f61ce12
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4f61ce12
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4f61ce12
Branch: refs/heads/sensors_branch
Commit: 4f61ce122f0b55b90a91e32c655d5982fe1c177c
Parents: 521ea9b
Author: Vipul Rahane <vi...@apache.org>
Authored: Tue Feb 14 16:56:48 2017 -0800
Committer: Vipul Rahane <vi...@apache.org>
Committed: Tue Feb 14 16:56:48 2017 -0800
----------------------------------------------------------------------
.../sensors/bno055/include/bno055/bno055.h | 11 +++++++
hw/drivers/sensors/bno055/src/bno055.c | 16 +++++-----
hw/drivers/sensors/bno055/src/bno055_shell.c | 31 ++++++++++++++++----
3 files changed, 45 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f61ce12/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 64138d5..1e30ba2 100644
--- a/hw/drivers/sensors/bno055/include/bno055/bno055.h
+++ b/hw/drivers/sensors/bno055/include/bno055/bno055.h
@@ -88,6 +88,17 @@ int
bno055_read8(uint8_t reg, uint8_t *value);
/**
+ * Writes a single byte to the specified register
+ *
+ * @param The register address to write to
+ * @param The value to write
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int
+bno055_write8(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/4f61ce12/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 43e72b8..3080f7b 100644
--- a/hw/drivers/sensors/bno055/src/bno055.c
+++ b/hw/drivers/sensors/bno055/src/bno055.c
@@ -113,10 +113,10 @@ static uint8_t g_bno055_mode;
* @return 0 on success, non-zero error on failure.
*/
int
-bno055_write8(uint8_t reg, uint32_t value)
+bno055_write8(uint8_t reg, uint8_t value)
{
int rc;
- uint8_t payload[2] = { reg, value & 0xFF };
+ uint8_t payload[2] = { reg, value};
struct hal_i2c_master_data data_struct = {
.address = MYNEWT_VAL(BNO055_I2CADDR),
@@ -203,7 +203,7 @@ bno055_readlen(uint8_t reg, uint8_t *buffer, uint8_t len)
uint8_t payload[8] = { reg, 0, 0, 0, 0, 0, 0, 0};
struct hal_i2c_master_data data_struct = {
- .address = reg,
+ .address = MYNEWT_VAL(BNO055_I2CADDR),
.len = 1,
.buffer = payload
};
@@ -438,7 +438,7 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
prev_mode = g_bno055_mode;
/* Check if we can read the chip address */
- rc = bno055_read8(BNO055_CHIP_ID_ADDR, &id);
+ rc = bno055_get_chip_id(&id);
if (rc) {
goto err;
}
@@ -446,7 +446,7 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
if (id != BNO055_ID) {
os_time_delay(OS_TICKS_PER_SEC/2);
- rc = bno055_read8(BNO055_CHIP_ID_ADDR, &id);
+ rc = bno055_get_chip_id(&id);
if (rc) {
goto err;
}
@@ -457,13 +457,13 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
}
}
- rc = bno055_set_mode(BNO055_OPERATION_MODE_CONFIG);
+ /* Reset sensor */
+ rc = bno055_write8(BNO055_SYS_TRIGGER_ADDR, BNO055_SYS_TRIGGER_RST_SYS);
if (rc) {
goto err;
}
- /* Reset sensor */
- rc = bno055_write8(BNO055_SYS_TRIGGER_ADDR, BNO055_SYS_TRIGGER_RST_SYS);
+ rc = bno055_set_mode(BNO055_OPERATION_MODE_CONFIG);
if (rc) {
goto err;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f61ce12/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 48a1196..82ba7e3 100644
--- a/hw/drivers/sensors/bno055/src/bno055_shell.c
+++ b/hw/drivers/sensors/bno055/src/bno055_shell.c
@@ -177,10 +177,10 @@ bno055_shell_cmd_read(int argc, char **argv)
}
samples = (uint16_t)val;
- if (bno055_shell_stol(argv[2], 1, UINT16_MAX, &val)) {
+ if (bno055_shell_stol(argv[3], 0, UINT16_MAX, &val)) {
return bno055_shell_err_invalid_arg(argv[2]);
}
- type = (uint16_t)(1 << val);
+ type = (int)(1 << val);
}
while(samples--) {
@@ -199,6 +199,7 @@ bno055_shell_cmd_read(int argc, char **argv)
rc = bno055_get_vector_data(databuf, type);
if (rc) {
console_printf("Read failed: %d\n", rc);
+ goto err;
}
sed = databuf;
console_printf("h:%u r:%u p:%u\n", (unsigned int)sed->sed_h,
@@ -207,6 +208,7 @@ bno055_shell_cmd_read(int argc, char **argv)
rc = bno055_get_vector_data(databuf, type);
if (rc) {
console_printf("Read failed: %d\n", rc);
+ goto err;
}
sad = databuf;
console_printf("x:%u y:%u z:%u\n", (unsigned int)sad->sad_x,
@@ -361,11 +363,13 @@ static int
shell_i2cscan_cmd(int argc, char **argv)
{
uint8_t addr;
- int32_t timeout = OS_TICKS_PER_SEC / 10;
+ int32_t timeout;
uint8_t dev_count = 0;
long i2cnum;
int rc;
+ timeout = OS_TICKS_PER_SEC / 10;
+
if (bno055_shell_stol(argv[2], 0, 0xf, &i2cnum)) {
return bno055_shell_err_invalid_arg(argv[2]);
}
@@ -389,13 +393,29 @@ shell_i2cscan_cmd(int argc, char **argv)
} else {
console_printf("-- ");
}
+ os_time_delay(OS_TICKS_PER_SEC/1000 * 20);
}
- console_printf("\nFound %u devices on I2C bus 0\n", dev_count);
+ console_printf("\nFound %u devices on I2C bus %u\n", dev_count, (uint8_t)i2cnum);
return 0;
}
static int
+bno055_shell_cmd_reset(int argc, char **argv)
+{
+ int rc;
+ /* Reset sensor */
+ rc = bno055_write8(BNO055_SYS_TRIGGER_ADDR, BNO055_SYS_TRIGGER_RST_SYS);
+ if (rc) {
+ goto err;
+ }
+
+ return 0;
+err:
+ return rc;
+}
+
+static int
bno055_shell_cmd(int argc, char **argv)
{
if (argc == 1) {
@@ -421,18 +441,19 @@ bno055_shell_cmd(int argc, char **argv)
if (argc > 1 && strcmp(argv[1], "rev") == 0) {
return bno055_shell_cmd_get_rev_info(argc, argv);
}
-#if 0
/* Reset command */
if (argc > 1 && strcmp(argv[1], "reset") == 0) {
return bno055_shell_cmd_reset(argc, argv);
}
+#if 0
/* Power mode command */
if (argc > 1 && strcmp(argv[1], "pmode") == 0) {
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);