Add power mode command to the bno055 shell
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/43179745 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/43179745 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/43179745 Branch: refs/heads/develop Commit: 43179745c890e6a195440d5050ec21e32f5ed023 Parents: ea2ff6d Author: Vipul Rahane <[email protected]> Authored: Wed Feb 15 16:29:39 2017 -0800 Committer: Vipul Rahane <[email protected]> Committed: Wed Feb 15 16:29:39 2017 -0800 ---------------------------------------------------------------------- .../sensors/bno055/include/bno055/bno055.h | 29 +++++++++- hw/drivers/sensors/bno055/src/bno055.c | 58 ++++++++++++++++---- hw/drivers/sensors/bno055/src/bno055_shell.c | 50 ++++++++++++++--- 3 files changed, 114 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/43179745/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 1e30ba2..09fa3ec 100644 --- a/hw/drivers/sensors/bno055/include/bno055/bno055.h +++ b/hw/drivers/sensors/bno055/include/bno055/bno055.h @@ -99,13 +99,13 @@ int bno055_write8(uint8_t reg, uint8_t value); /** - * Setting mode for the bno055 sensor + * Set operation mode for the bno055 sensor * * @param Operation mode for the sensor * @return 0 on success, non-zero on failure */ int -bno055_set_mode(uint8_t mode); +bno055_set_opr_mode(uint8_t mode); #if MYNEWT_VAL(BNO055_CLI) int bno055_shell_init(void); @@ -140,8 +140,31 @@ bno055_get_chip_id(uint8_t *id); * @return mode */ uint8_t -bno055_get_mode(void); +bno055_get_opr_mode(void); +/** + * Read current power mode of the sensor + * + * @return mode + */ +uint8_t +bno055_get_pwr_mode(void); + +/** + * Set power mode for the sensor + * + * @return mode + */ +int +bno055_set_pwr_mode(uint8_t mode); + +/** + * Get power mode for the sensor + * + * @return mode + */ +uint8_t +bno055_get_pwr_mode(void); #ifdef __cplusplus } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/43179745/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 8b31ac6..bcc880d 100644 --- a/hw/drivers/sensors/bno055/src/bno055.c +++ b/hw/drivers/sensors/bno055/src/bno055.c @@ -102,7 +102,8 @@ static const struct sensor_driver g_bno055_sensor_driver = { bno055_sensor_get_config }; -static uint8_t g_bno055_mode; +static uint8_t g_bno055_opr_mode; +static uint8_t g_bno055_pwr_mode; /** * Writes a single byte to the specified register @@ -251,13 +252,13 @@ err: /** - * Setting mode for the bno055 sensor + * Setting operation mode for the bno055 sensor * * @param Operation mode for the sensor * @return 0 on success, non-zero on failure */ int -bno055_set_mode(uint8_t mode) +bno055_set_opr_mode(uint8_t mode) { int rc; @@ -273,21 +274,54 @@ bno055_set_mode(uint8_t mode) os_time_delay(OS_TICKS_PER_SEC/1000 * 7); } - g_bno055_mode = mode; + g_bno055_opr_mode = mode; return 0; err: return rc; } /** + * Setting power mode for the bno055 sensor + * + * @param power mode for the sensor + * @return 0 on success, non-zero on failure + */ +int +bno055_set_pwr_mode(uint8_t mode) +{ + int rc; + + rc = bno055_write8(BNO055_PWR_MODE_ADDR, mode); + if (rc) { + goto err; + } + + g_bno055_pwr_mode = mode; + return 0; +err: + return rc; +} + +/** + * Read current power mode of the sensor + * + * @return mode + */ +uint8_t +bno055_get_pwr_mode(void) +{ + return g_bno055_pwr_mode; +} + +/** * Read current operational mode of the sensor * * @return mode */ uint8_t -bno055_get_mode(void) +bno055_get_opr_mode(void) { - return g_bno055_mode; + return g_bno055_opr_mode; } /** @@ -384,10 +418,10 @@ bno055_set_ext_xtal_use(uint8_t use_xtal) int rc; uint8_t prev_mode; - prev_mode = g_bno055_mode; + prev_mode = g_bno055_opr_mode; /* Switch to config mode */ - rc = bno055_set_mode(BNO055_OPERATION_MODE_CONFIG); + rc = bno055_set_opr_mode(BNO055_OPERATION_MODE_CONFIG); if (rc) { goto err; } @@ -416,7 +450,7 @@ bno055_set_ext_xtal_use(uint8_t use_xtal) os_time_delay(OS_TICKS_PER_SEC/1000 * 10); /* Reset to previous operating mode */ - rc = bno055_set_mode(prev_mode); + rc = bno055_set_opr_mode(prev_mode); if (rc) { goto err; } @@ -436,7 +470,7 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg) uint8_t id; uint8_t prev_mode; - prev_mode = g_bno055_mode; + prev_mode = g_bno055_opr_mode; /* Check if we can read the chip address */ rc = bno055_get_chip_id(&id); @@ -464,7 +498,7 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg) goto err; } - rc = bno055_set_mode(BNO055_OPERATION_MODE_CONFIG); + rc = bno055_set_opr_mode(BNO055_OPERATION_MODE_CONFIG); if (rc) { goto err; } @@ -499,7 +533,7 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg) memcpy(&bno055->cfg, cfg, sizeof(*cfg)); /* Change back to previous mode */ - rc = bno055_set_mode(prev_mode); + rc = bno055_set_opr_mode(prev_mode); if (rc) { goto err; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/43179745/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 919aa48..9de1ed5 100644 --- a/hw/drivers/sensors/bno055/src/bno055_shell.c +++ b/hw/drivers/sensors/bno055/src/bno055_shell.c @@ -222,7 +222,7 @@ err: } static int -bno055_shell_cmd_mode(int argc, char **argv) +bno055_shell_cmd_opr_mode(int argc, char **argv) { long val; int rc; @@ -233,7 +233,7 @@ bno055_shell_cmd_mode(int argc, char **argv) /* Display the mode */ if (argc == 2) { - val = bno055_get_mode(); + val = bno055_get_opr_mode(); console_printf("%u\n", (unsigned int)val); } @@ -247,7 +247,44 @@ bno055_shell_cmd_mode(int argc, char **argv) return bno055_shell_err_invalid_arg(argv[2]); } - rc = bno055_set_mode(val); + rc = bno055_set_opr_mode(val); + if (rc) { + goto err; + } + } + + return 0; +err: + return rc; +} + +static int +bno055_shell_cmd_pwr_mode(int argc, char **argv) +{ + long val; + int rc; + + if (argc > 3) { + return bno055_shell_err_too_many_args(argv[1]); + } + + /* Display the mode */ + if (argc == 2) { + val = bno055_get_pwr_mode(); + console_printf("%u\n", (unsigned int)val); + } + + /* Update the mode */ + if (argc == 3) { + if (bno055_shell_stol(argv[2], 0, 16, &val)) { + return bno055_shell_err_invalid_arg(argv[2]); + } + /* Make sure mode is */ + if (val > BNO055_POWER_MODE_SUSPEND) { + return bno055_shell_err_invalid_arg(argv[2]); + } + + rc = bno055_set_pwr_mode(val); if (rc) { goto err; } @@ -349,7 +386,7 @@ bno055_shell_cmd(int argc, char **argv) /* Mode command */ if (argc > 1 && strcmp(argv[1], "mode") == 0) { - return bno055_shell_cmd_mode(argc, argv); + return bno055_shell_cmd_opr_mode(argc, argv); } /* Chip ID command */ @@ -366,14 +403,11 @@ bno055_shell_cmd(int argc, char **argv) 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); + return bno055_shell_cmd_pwr_mode(argc, argv); } -#endif - /* Dump Registers command */ if (argc > 1 && strcmp(argv[1], "dumpreg") == 0) { return bno055_shell_cmd_dumpreg(argc, argv);
