diff --git a/README.md b/README.md index bb24dab..7f4021b 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,27 @@ -# BHI260AB/BHA260AB/BHI260AP/BHI360 Sensor API +# BHI260AB/BHA260AB/BHI260AP/BHI360/BHI380 SensorAPI -> This package contains BHI260AB/BHA260AB/BHI260AP/BHI360 generically clustered as BHy2 sensor API +This package contains BHI260AB/BHA260AB/BHI260AP/BHI360/BHI380 generically clustered as BHy2 SensorAPI + +This package can be used together with [COINES](https://www.bosch-sensortec.com/software-tools/tools/coines/) to modify, compile and run the sample applications. Product links + - [BHA260AB](https://www.bosch-sensortec.com/products/smart-sensors/bha260ab.html) + - [BHI260AB](https://www.bosch-sensortec.com/products/smart-sensors/bhi260ab.html) + - [BHI260AP](https://www.bosch-sensortec.com/products/smart-sensors/bhi260ap/) + - [BHI360](https://www.bosch-sensortec.com/products/smart-sensor-systems/bhi360/) +- [BHI380](https://www.bosch-sensortec.com/products/smart-sensor-systems/bhi380/) + +> If you are interested in the BHI380 smart sensor, please use our [contact form](https://www.bosch-sensortec.com/products/smart-sensor-systems/bhi380/#contact) + +> *Please be aware that the BHI380 is currently only available to a limited number of projects. Therefore, we are only considering information requests for projects with a minimum lifetime quantity of 1,00,000 units and above.* + + + --- -#### Copyright (C) 2022 Bosch Sensortec GmbH. All rights reserved \ No newline at end of file + +#### Copyright (C) 2023 Bosch Sensortec GmbH. All rights reserved \ No newline at end of file diff --git a/bhi3.c b/bhi3.c index 40ece7e..75dc6ee 100644 --- a/bhi3.c +++ b/bhi3.c @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhi3.c -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ diff --git a/bhi3.h b/bhi3.h index e7de708..e1879a9 100644 --- a/bhi3.h +++ b/bhi3.h @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,15 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhi3.h -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ #ifndef __BHI3_H__ #define __BHI3_H__ -/* Start of CPP guard */ +/* Start of CPP Guard */ #ifdef __cplusplus extern "C" { #endif /*__cplusplus */ @@ -322,7 +322,7 @@ int8_t bhi3_set_wrist_gesture_detect_config(const uint8_t *wgd_cnfg, struct bhy2 */ int8_t bhi3_get_wrist_gesture_detect_config(uint8_t *wgd_cnfg, struct bhy2_dev *dev); -/* End of CPP guard */ +/* End of CPP Guard */ #ifdef __cplusplus } #endif /*__cplusplus */ diff --git a/bhi3_defs.h b/bhi3_defs.h index 03a6a35..8174e85 100644 --- a/bhi3_defs.h +++ b/bhi3_defs.h @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,15 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhi3_defs.h -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ #ifndef __BHI3_DEFS_H__ #define __BHI3_DEFS_H__ -/* Start of CPP guard */ +/* Start of CPP Guard */ #ifdef __cplusplus extern "C" { #endif /*__cplusplus */ @@ -102,6 +102,7 @@ extern "C" { #define BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_CODE UINT8_C(0x05) #define BHI3_PHY_GYRO_NORMAL_POWER_MODE UINT8_C(0x00) +#define BHI3_PHY_GYRO_PERFORMANCE_POWER_MODE UINT8_C(0x01) #define BHI3_PHY_GYRO_LOW_POWER_MODE UINT8_C(0x02) #define BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_LEN 1 @@ -172,16 +173,26 @@ static const char * const bhi3_wrist_gesture_detect_output[] = { [FLICK_OUT] = "FLICK_OUT" }; /*lint -e528 */ -enum bhi3_phy_sensor_power_mode { - NORMAL, - LOW_POWER = 0x02 +enum bhi3_phy_sensor_acc_power_mode { + ACC_NORMAL, + ACC_LOW_POWER = 0x02 }; -static const char * const bhi3_phy_sensor_pwm_output[] = { - [NORMAL] = "NORMAL", [LOW_POWER] = "LOW POWER" +enum bhi3_phy_sensor_gyro_power_mode { + GYRO_NORMAL, + GYRO_PERFORMANCE, + GYRO_LOW_POWER +}; + +static const char * const bhi3_phy_sensor_acc_pwm_output[] = { + [ACC_NORMAL] = "NORMAL", [ACC_LOW_POWER] = "LOW POWER" +}; /*lint -e528 */ + +static const char * const bhi3_phy_sensor_gyro_pwm_output[] = { + [GYRO_NORMAL] = "NORMAL", [GYRO_PERFORMANCE] = "PERFORMANCE", [GYRO_LOW_POWER] = "LOW POWER" }; /*lint -e528 */ -/* End of CPP guard */ +/* End of CPP Guard */ #ifdef __cplusplus } #endif /*__cplusplus */ diff --git a/bhi3_multi_tap.c b/bhi3_multi_tap.c index 8f4bfd4..2f17ca9 100644 --- a/bhi3_multi_tap.c +++ b/bhi3_multi_tap.c @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhi3_multi_tap.c -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ diff --git a/bhi3_multi_tap.h b/bhi3_multi_tap.h index 5e5c2c7..d8df9bb 100644 --- a/bhi3_multi_tap.h +++ b/bhi3_multi_tap.h @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,15 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhi3_multi_tap.h -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ #ifndef _BHY2_MULTI_TAP_H_ #define _BHY2_MULTI_TAP_H_ -/* Start of CPP guard */ +/* Start of CPP Guard */ #ifdef __cplusplus extern "C" { #endif /*__cplusplus */ @@ -103,7 +103,7 @@ int8_t bhi3_multi_tap_detector_set_config(const void *buffer, struct bhy2_dev *d */ int8_t bhi3_multi_tap_detector_get_config(const void *buffer, struct bhy2_dev *dev); -/* End of CPP guard */ +/* End of CPP Guard */ #ifdef __cplusplus } #endif /*__cplusplus */ diff --git a/bhi3_multi_tap_defs.h b/bhi3_multi_tap_defs.h index 5386910..e6f9137 100644 --- a/bhi3_multi_tap_defs.h +++ b/bhi3_multi_tap_defs.h @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,18 +31,18 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhi3_multi_tap_defs.h -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ #ifndef _BHI3_MULTI_TAP_DEFS_H_ #define _BHI3_MULTI_TAP_DEFS_H_ -/* Start of CPP guard */ +/* Start of CPP Guard */ #ifdef __cplusplus extern "C" { -#endif +#endif /*__cplusplus */ #include #include @@ -74,7 +74,7 @@ extern "C" { #define BHI3_SINGLE_TAP_AXIS_SEL_MASK 0x03 #define BHI3_SINGLE_TAP_WAIT_TIMEOUT_MASK 0x04 -#define BHI3_SINGLE_TAP_MAX_PEAKS_FOR_TAP_MASK 0x3C +#define BHI3_SINGLE_TAP_MAX_PEAKS_FOR_TAP_MASK 0x38 #define BHI3_SINGLE_TAP_FILTER_MODE_MASK 0xC0 #define BHI3_DOUBLE_TAP_TAP_PEAK_DUR_MASK 0x03FF @@ -181,9 +181,9 @@ static const char * const bhi3_multi_tap_string_out[] = { [TRIPLE_DOUBLE_TAP] = "TRIPLE_DOUBLE_TAP", [TRIPLE_DOUBLE_SINGLE_TAP] = "TRIPLE_DOUBLE_SINGLE_TAP" }; /*lint -e528 */ -/* End of CPP guard */ +/* End of CPP Guard */ #ifdef __cplusplus } -#endif +#endif /*__cplusplus */ #endif /* _BHI3_MULTI_TAP_DEFS_H_ */ diff --git a/bhy2.c b/bhy2.c index 2fc6714..d3ef110 100644 --- a/bhy2.c +++ b/bhy2.c @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhy2.c -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ diff --git a/bhy2.h b/bhy2.h index a6d287d..d2304ec 100644 --- a/bhy2.h +++ b/bhy2.h @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,15 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhy2.h -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ #ifndef __BHY2_H__ #define __BHY2_H__ -/* Start of CPP guard */ +/* Start of CPP Guard */ #ifdef __cplusplus extern "C" { #endif /*__cplusplus */ @@ -656,7 +656,7 @@ int8_t bhy2_read_status(uint16_t *status_code, uint32_t *actual_len, struct bhy2_dev *dev); -/* End of CPP guard */ +/* End of CPP Guard */ #ifdef __cplusplus } #endif /*__cplusplus */ diff --git a/bhy2_bsec.c b/bhy2_bsec.c index 70c50c7..e32f708 100644 --- a/bhy2_bsec.c +++ b/bhy2_bsec.c @@ -1,5 +1,5 @@ /** - * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. + * Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhy2_bsec.c - * @date 2023-02-10 - * @version v1.5.0 + * @date 2023-03-24 + * @version v1.6.0 * */ diff --git a/bhy2_bsec.h b/bhy2_bsec.h index 30ff5c8..2d018fe 100644 --- a/bhy2_bsec.h +++ b/bhy2_bsec.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. + * Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,15 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhy2_bsec.h - * @date 2023-02-10 - * @version v1.5.0 + * @date 2023-03-24 + * @version v1.6.0 * */ #ifndef _BHY2_BSEC_H_ #define _BHY2_BSEC_H_ -/* Start of CPP guard */ +/* Start of CPP Guard */ #ifdef __cplusplus extern "C" { #endif /*__cplusplus */ @@ -66,7 +66,7 @@ struct bhy2_bsec_air_quality void bhy2_bsec_parse_air_quality(const uint8_t *payload, struct bhy2_bsec_air_quality *data); -/* End of CPP guard */ +/* End of CPP Guard */ #ifdef __cplusplus } #endif /*__cplusplus */ diff --git a/bhy2_defs.h b/bhy2_defs.h index 4bb7ec7..4baa56d 100644 --- a/bhy2_defs.h +++ b/bhy2_defs.h @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,15 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhy2_defs.h -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ #ifndef __BHY2_DEFS_H__ #define __BHY2_DEFS_H__ -/* Start of CPP guard */ +/* Start of CPP Guard */ #ifdef __cplusplus extern "C" { #endif /*__cplusplus */ @@ -801,7 +801,7 @@ enum bhy2_data_inj_mode { #define BHY2_BYTE_TO_NIBBLE(X) (((uint8_t)(X)[0] & 0x0F) | (((uint8_t)(X)[1] << 4) & 0xF0)) -/* End of CPP guard */ +/* End of CPP Guard */ #ifdef __cplusplus } #endif /*__cplusplus */ diff --git a/bhy2_head_tracker.c b/bhy2_head_tracker.c new file mode 100644 index 0000000..263cd19 --- /dev/null +++ b/bhy2_head_tracker.c @@ -0,0 +1,353 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2_head_tracker.c +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +/*********************************************************************/ +/* system header files */ +/*********************************************************************/ +#include +#include + +/*********************************************************************/ +/* BHY2 SensorAPI header files */ +/*********************************************************************/ +#include "bhy2.h" + +/*********************************************************************/ +/* own header files */ +/*********************************************************************/ +#include "bhy2_head_tracker.h" + +/*Parsing callback for Head Orientation Quaternion*/ +void bhy2_head_tracker_quat_parsing(const uint8_t *payload, struct bhy2_head_tracker_quat_data *data) +{ + uint8_t i = 0; + + if ((payload != NULL) && (data != NULL)) + { + data->x = BHY2_LE2S16(&payload[i]); + i += 2; + data->y = BHY2_LE2S16(&payload[i]); + i += 2; + data->z = BHY2_LE2S16(&payload[i]); + i += 2; + data->w = BHY2_LE2S16(&payload[i]); + i += 2; + data->accuracy = payload[i]; + } +} + +/*Parsing callback for Head Orientation Euler*/ +void bhy2_head_tracker_eul_parsing(const uint8_t *payload, struct bhy2_head_tracker_eul_data *data) +{ + uint8_t i = 0; + + if ((payload != NULL) && (data != NULL)) + { + data->heading = BHY2_LE2S16(&payload[i]); + i += 2; + data->pitch = BHY2_LE2S16(&payload[i]); + i += 2; + data->roll = BHY2_LE2S16(&payload[i]); + i += 2; + data->accuracy = payload[i]; + } +} + +/*Callback for triggering Head Misalignment Calibration*/ +int8_t bhy2_head_tracker_trigger_hmc_calibration(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Trigger Head Misalignment Calibration */ + rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_TRIGGER_CALIB), + (uint8_t*)buffer, + BHY2_HEAD_ORI_HMC_TRIGGER_CALIB_LENGTH, + dev); + } + + return rslt; +} + +/*Callback for setting Head Misalignment Calibration Configuration*/ +int8_t bhy2_head_tracker_set_hmc_configuration(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set Head Misalignment Configuration */ + rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_CONFIG), + (uint8_t*)buffer, + BHY2_HEAD_ORI_HMC_CONFIG_LENGTH, + dev); + } + + return rslt; +} + +/*Callback for getting Head Misalignment Calibration Configuration*/ +int8_t bhy2_head_tracker_get_hmc_configuration(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t act_len; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get Head Misalignment Configuration */ + rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_CONFIG), + (uint8_t*)buffer, + BHY2_HEAD_ORI_HMC_CONFIG_LENGTH, + &act_len, + dev); + } + + return rslt; +} + +/*Callback for setting default Head Misalignment Calibration Configuration*/ +int8_t bhy2_head_tracker_set_default_hmc_configuration(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set default Head Misalignment Configuration */ + rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_SET_DEF_CONFIG), + (uint8_t*)buffer, + BHY2_HEAD_ORI_HMC_SET_DEF_CONFIG_LENGTH, + dev); + } + + return rslt; +} + +/*Callback for getting Head Misalignment Calibrator Version*/ +int8_t bhy2_head_tracker_get_hmc_version(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t act_len; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get Head Misalignment Calibrator Version */ + rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_VERSION), + (uint8_t*)buffer, + BHY2_HEAD_ORI_HMC_VERSION_LENGTH, + &act_len, + dev); + } + + return rslt; +} + +/*Callback for setting Head Misalignment Calibration Correction Quaternion Configuration*/ +int8_t bhy2_head_tracker_set_hmc_quat_calib_corr_config(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set Head Misalignment Calibration Correction Quaternion Configuration */ + rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR), + (uint8_t*)buffer, + BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR_WLENGTH, + dev); + } + + return rslt; +} + +/*Callback for getting Head Misalignment Calibration Correction Quaternion Configuration*/ +int8_t bhy2_head_tracker_get_hmc_quat_calib_corr_config(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t act_len; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get Head Misalignment Calibration Correction Quaternion Configuration */ + rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR), + (uint8_t*)buffer, + BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR_RLENGTH, + &act_len, + dev); + } + + return rslt; +} + +/*Callback for setting Head Orientation Initial Head Correction for Quaternion*/ +int8_t bhy2_head_tracker_set_quat_initial_head_correction(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set Head Orientation Initial Head Correction for Quaternion */ + rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR), + (uint8_t*)buffer, + BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR_LENGTH, + dev); + } + + return rslt; +} + +/*Callback for getting Head Orientation Initial Head Correction for Quaternion*/ +int8_t bhy2_head_tracker_get_quat_initial_head_correction(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t act_len; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get Head Orientation Initial Head Correction for Quaternion */ + rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR), + (uint8_t*)buffer, + BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR_LENGTH, + &act_len, + dev); + } + + return rslt; +} + +/*Callback for getting Head Orientation Version*/ +int8_t bhy2_head_tracker_get_ho_version(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t act_len; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get IMU/NDOF Head Orientation Version */ + rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_VERSION), + (uint8_t*)buffer, + BHY2_HEAD_ORI_VERSION_LENGTH, + &act_len, + dev); + } + + return rslt; +} + +/*Callback for setting Head Orientation Initial Head Correction for Euler*/ +int8_t bhy2_head_tracker_set_eul_initial_head_correction(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Set Head Orientation Initial Head Correction for Euler */ + rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR), + (uint8_t*)buffer, + BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR_LENGTH, + dev); + } + + return rslt; +} + +/*Callback for getting Head Orientation Initial Head Correction for Euler*/ +int8_t bhy2_head_tracker_get_eul_initial_head_correction(const void *buffer, struct bhy2_dev *dev) +{ + int8_t rslt = BHY2_OK; + uint32_t act_len; + + if (dev == NULL) + { + rslt = BHY2_E_NULL_PTR; + } + else + { + /*! Get Head Orientation Initial Head Correction for Euler */ + rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR), + (uint8_t*)buffer, + BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR_LENGTH, + &act_len, + dev); + } + + return rslt; +} diff --git a/bhy2_head_tracker.h b/bhy2_head_tracker.h new file mode 100644 index 0000000..94a5f31 --- /dev/null +++ b/bhy2_head_tracker.h @@ -0,0 +1,213 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2_head_tracker.h +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +#ifndef _BHY2_HEAD_TRACKER_H_ +#define _BHY2_HEAD_TRACKER_H_ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include +#include +#include + +#include "bhy2.h" +#include "bhy2_head_tracker_defs.h" + +/*! + * @brief Parsing callback for Head Orientation Quaternion + * + * @param[in] payload + * @param[out] bhy2_head_tracker_quat_data to store Head Orientation [Quaternion] data + * + * @return API error codes + * + */ +void bhy2_head_tracker_quat_parsing(const uint8_t *payload, struct bhy2_head_tracker_quat_data *data); + +/*! + * @brief Parsing callback for Head Orientation Euler + * + * @param[in] payload + * @param[out] bhy2_head_tracker_eul_data to store Head Orientation [Euler] data + * + * @return API error codes + * + */ +void bhy2_head_tracker_eul_parsing(const uint8_t *payload, struct bhy2_head_tracker_eul_data *data); + +/*! + * @brief To trigger the Head Misalignment Calibration + * + * @param[in] buffer + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_trigger_hmc_calibration(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To set the Head Misalignment Calibration Configuration + * + * @param[in] buffer to hold the Head Misalignment Calibration Configuration + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_set_hmc_configuration(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To get the Head Misalignment Calibration Configuration + * + * @param[out] buffer to hold the Head Misalignment Calibration Configuration + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_get_hmc_configuration(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To set the default Head Misalignment Calibration Configuration + * + * @param[in] command buffer + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_set_default_hmc_configuration(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To get the Head Misalignment Calibrator Version + * + * @param[out] buffer to hold the Head Misalignment Calibrator Version + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_get_hmc_version(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To set the Head Misalignment Quaternion Calibration Correction Configuration + * + * @param[in] buffer to hold the Head Misalignment Quaternion Calibration Correction Configuration + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_set_hmc_quat_calib_corr_config(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To get the Head Misalignment Quaternion Calibration Correction Configuration + * + * @param[out] buffer to hold the Head Misalignment Quaternion Calibration Correction Configuration + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_get_hmc_quat_calib_corr_config(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To set the Head Misalignment Quaternion Initial Head Correction + * + * @param[in] buffer to hold the Head Misalignment Quaternion Initial Head Correction + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_set_quat_initial_head_correction(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To get the Head Misalignment Quaternion Initial Head Correction + * + * @param[out] buffer to hold the Head Misalignment Quaternion Initial Head Correction + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_get_quat_initial_head_correction(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To get the IMU/NDOF Head Orientation Version + * + * @param[out] buffer to hold the IMU/NDOF Head Orientation Version + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_get_ho_version(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To set the Head Misalignment Euler Initial Head Correction + * + * @param[in] buffer to hold the Head Misalignment Euler Initial Head Correction + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_set_eul_initial_head_correction(const void *buffer, struct bhy2_dev *dev); + +/*! + * @brief To get the Head Misalignment Euler Initial Head Correction + * + * @param[out] buffer to hold the Head Misalignment Euler Initial Head Correction + * @param[in] dev hub handle + * + * @return API error codes + * + */ +int8_t bhy2_head_tracker_get_eul_initial_head_correction(const void *buffer, struct bhy2_dev *dev); + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* _BHY2_HEAD_TRACKER_H_ */ diff --git a/bhy2_head_tracker_defs.h b/bhy2_head_tracker_defs.h new file mode 100644 index 0000000..3c2c03a --- /dev/null +++ b/bhy2_head_tracker_defs.h @@ -0,0 +1,138 @@ +/** +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bhy2_head_tracker_defs.h +* @date 2023-03-24 +* @version v1.6.0 +* +*/ + +#ifndef _BHY2_HEAD_TRACKER_DEFS_H_ +#define _BHY2_HEAD_TRACKER_DEFS_H_ + +/* Start of CPP Guard */ +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include +#include +#include + +#include "bhy2.h" + +/*! Virtual Sensor Macros */ +#define BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG UINT8_C(120) /*Head Orientation Misalignment*/ +#define BHY2_SENSOR_ID_IMU_HEAD_ORI_Q UINT8_C(121) /*IMU Head Orientation Quaternion*/ +#define BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q UINT8_C(122) /*NDOF Head Orientation Quaternion*/ +#define BHY2_SENSOR_ID_IMU_HEAD_ORI_E UINT8_C(123) /*IMU Head Orientation Euler*/ +#define BHY2_SENSOR_ID_NDOF_HEAD_ORI_E UINT8_C(124) /*NDOF Head Orientation Euler*/ + +#define BHY2_HEAD_ORI_PAGE UINT16_C(12) +#define BHY2_HEAD_ORI_PARAM(id) (((BHY2_HEAD_ORI_PAGE) << 8) | (id)) + +#define BHY2_HEAD_ORI_HMC_TRIGGER_CALIB UINT8_C(1) +#define BHY2_HEAD_ORI_HMC_TRIGGER_CALIB_LENGTH UINT8_C(4) +#define BHY2_HEAD_ORI_HMC_TRIGGER_CALIB_SET UINT8_C(1) + +#define BHY2_HEAD_ORI_HMC_CONFIG UINT8_C(2) +#define BHY2_HEAD_ORI_HMC_CONFIG_LENGTH UINT8_C(8) + +#define BHY2_HEAD_ORI_HMC_SET_DEF_CONFIG UINT8_C(3) +#define BHY2_HEAD_ORI_HMC_SET_DEF_CONFIG_LENGTH UINT8_C(4) +#define BHY2_HEAD_ORI_HMC_SET_DEF_CONFIG_SET UINT8_C(1) + +#define BHY2_HEAD_ORI_HMC_VERSION UINT8_C(4) +#define BHY2_HEAD_ORI_HMC_VERSION_LENGTH UINT8_C(4) + +#define BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR UINT8_C(5) +#define BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR_WLENGTH UINT8_C(16) +#define BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR_RLENGTH UINT8_C(20) + +#define BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR UINT8_C(10) +#define BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR_LENGTH UINT8_C(4) +#define BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR_DISABLE UINT8_C(0) +#define BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR_ENABLE UINT8_C(1) + +#define BHY2_HEAD_ORI_VERSION UINT8_C(11) +#define BHY2_HEAD_ORI_VERSION_LENGTH UINT8_C(4) + +#define BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR UINT8_C(12) +#define BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR_LENGTH UINT8_C(4) +#define BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR_DISABLE UINT8_C(0) +#define BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR_ENABLE UINT8_C(1) + +/*! Sensor Structure for Head Orientation Quaternion */ +struct bhy2_head_tracker_quat_data +{ + int16_t x, y, z, w; + uint8_t accuracy; +}; + +/*! Sensor Structure for Head Orientation Euler */ +struct bhy2_head_tracker_eul_data +{ + int16_t heading, pitch, roll; + uint8_t accuracy; +}; + +/*! Structure for Head Misalignment Configuration */ +struct bhy2_head_tracker_misalignment_config +{ + uint8_t still_phase_max_dur; + uint8_t still_phase_min_dur; + uint8_t still_phase_max_samples; + int32_t acc_diff_threshold; +}; + +/*! Structure for Head Orientation /Head Misalignment version */ +struct bhy2_head_tracker_ver +{ + uint8_t major, minor, patch, reserved; +}; + +/*! Structure for Head Misalignment Quaternion Correction */ +struct bhy2_head_tracker_misalignment_quat_corr +{ + int32_t quaternion_x; + int32_t quaternion_y; + int32_t quaternion_z; + int32_t quaternion_w; + int32_t accuracy; +}; + +/* End of CPP Guard */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* _BHY2_HEAD_TRACKER_DEFS_H_ */ diff --git a/bhy2_hif.c b/bhy2_hif.c index 133a4dd..d3aa2dd 100644 --- a/bhy2_hif.c +++ b/bhy2_hif.c @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhy2_hif.c -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ @@ -447,7 +447,7 @@ int8_t bhy2_hif_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len { int8_t rslt = BHY2_OK; - if ((hif != NULL) && (hif->read != NULL) && (reg_data != NULL)) + if ((hif != NULL) && (hif->write != NULL) && (reg_data != NULL)) { if (hif->intf == BHY2_SPI_INTERFACE) { diff --git a/bhy2_hif.h b/bhy2_hif.h index 8088e5b..1a17d12 100644 --- a/bhy2_hif.h +++ b/bhy2_hif.h @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,18 +31,18 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhy2_hif.h -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ #ifndef __BHY2_HIF_H__ #define __BHY2_HIF_H__ -/* Start of CPP guard */ +/* Start of CPP Guard */ #ifdef __cplusplus extern "C" { -#endif +#endif /*__cplusplus */ #include "bhy2_defs.h" @@ -568,9 +568,9 @@ int8_t bhy2_hif_inject_data(const uint8_t *payload, uint32_t payload_len, struct */ int8_t bhy2_hif_wait_status_ready(struct bhy2_hif_dev *hif); -/* End of CPP guard */ +/* End of CPP Guard */ #ifdef __cplusplus } -#endif +#endif /*__cplusplus */ #endif /* __BHY2_HIF_H__ */ diff --git a/bhy2_klio.c b/bhy2_klio.c index 59c4e4d..3f3a3a9 100644 --- a/bhy2_klio.c +++ b/bhy2_klio.c @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhy2_klio.c -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ diff --git a/bhy2_klio.h b/bhy2_klio.h index 85d4e6e..db66a62 100644 --- a/bhy2_klio.h +++ b/bhy2_klio.h @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,15 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhy2_klio.h -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ #ifndef __BHY2_KLIO_H__ #define __BHY2_KLIO_H__ -/* Start of CPP guard */ +/* Start of CPP Guard */ #ifdef __cplusplus extern "C" { #endif /*__cplusplus */ @@ -219,7 +219,7 @@ int8_t bhy2_klio_get_parameter(const bhy2_klio_parameter_t id, uint16_t *size, struct bhy2_dev *dev); -/* End of CPP guard */ +/* End of CPP Guard */ #ifdef __cplusplus } #endif /*__cplusplus */ diff --git a/bhy2_klio_defs.h b/bhy2_klio_defs.h index 819be2a..2d4b05e 100644 --- a/bhy2_klio_defs.h +++ b/bhy2_klio_defs.h @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,18 +31,18 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhy2_klio_defs.h -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ #ifndef __BHY2_KLIO_DEFS_H__ #define __BHY2_KLIO_DEFS_H__ -/* Start of CPP guard */ +/* Start of CPP Guard */ #ifdef __cplusplus extern "C" { -#endif +#endif /*__cplusplus */ #include @@ -341,9 +341,9 @@ typedef enum KLIO_DRIVER_ERROR_OPERATION_PENDING = 8 } bhy2_klio_driver_error_state_t; -/* End of CPP guard */ +/* End of CPP Guard */ #ifdef __cplusplus } -#endif +#endif /*__cplusplus */ #endif /* __BHY2_KLIO_DEFS_H__ */ diff --git a/bhy2_parse.c b/bhy2_parse.c index 16a5c0e..37dda7a 100644 --- a/bhy2_parse.c +++ b/bhy2_parse.c @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhy2_parse.c -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ diff --git a/bhy2_parse.h b/bhy2_parse.h index 9b32373..3f9e7a9 100644 --- a/bhy2_parse.h +++ b/bhy2_parse.h @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,14 +31,14 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhy2_parse.h -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ #ifndef __BHY2_PARSE_H__ #define __BHY2_PARSE_H__ -/* Start of CPP guard */ +/* Start of CPP Guard */ #ifdef __cplusplus extern "C" { #endif /*__cplusplus */ @@ -94,7 +94,7 @@ void bhy2_parse_orientation(const uint8_t *data, struct bhy2_data_orientation *o */ void bhy2_parse_xyz(const uint8_t *data, struct bhy2_data_xyz *vector); -/* End of CPP guard */ +/* End of CPP Guard */ #ifdef __cplusplus } #endif /*__cplusplus */ diff --git a/bhy2_pdr.c b/bhy2_pdr.c deleted file mode 100644 index dfe2173..0000000 --- a/bhy2_pdr.c +++ /dev/null @@ -1,238 +0,0 @@ -/** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. -* -* BSD-3-Clause -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* -* 3. Neither the name of the copyright holder nor the names of its -* contributors may be used to endorse or promote products derived from -* this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -* -* @file bhy2_pdr.c -* @date 2023-02-10 -* @version v1.5.0 -* -*/ - -/*********************************************************************/ -/* system header files */ -#include -#include - -/*********************************************************************/ -/* BHY2 SensorAPI header files */ -#include "bhy2.h" - -/*********************************************************************/ -/* own header files */ -#include "bhy2_pdr.h" - -void bhy2_pdr_parse_frame(const uint8_t *data, struct bhy2_pdr_frame *pdr_frame) -{ - if (data && pdr_frame) - { - pdr_frame->pos_x = BHY2_LE2S24(&data[0]); - pdr_frame->pos_y = BHY2_LE2S24(&data[3]); - pdr_frame->hor_acc = BHY2_LE2S16(&data[6]); - pdr_frame->heading = BHY2_LE2U16(&data[8]); - pdr_frame->heading_acc = BHY2_LE2U16(&data[10]); - pdr_frame->step_count = BHY2_LE2U16(&data[12]); - pdr_frame->status = data[14]; - } -} - -int8_t bhy2_pdr_reset_full(struct bhy2_dev *dev) -{ - uint8_t full_reset[4] = { 1, 0, 0, 0 }; - - return bhy2_set_parameter(BHY2_PDR_PARAM(BHY2_PDR_PARAM_FULL_RESET), full_reset, sizeof(full_reset), dev); -} - -int8_t bhy2_pdr_reset_position(struct bhy2_dev *dev) -{ - uint8_t pos_reset[4] = { 1, 0, 0, 0 }; - - return bhy2_set_parameter(BHY2_PDR_PARAM(BHY2_PDR_PARAM_POS_RESET), pos_reset, sizeof(pos_reset), dev); -} - -int8_t bhy2_pdr_set_ref_heading_del(float heading, struct bhy2_dev *dev) -{ - uint8_t ref_heading[4] = { 0 }; - uint16_t heading_delta; - - if (heading >= 0.0f) - { - heading_delta = (uint16_t)(heading * 10.0f); /* 0.1 degree/LSB */ - } - else - { - heading_delta = 0; - } - - if (heading_delta > 3599) - { - heading_delta = 3599; - } - - ref_heading[0] = heading_delta & 0x00FF; - ref_heading[1] = (heading_delta & 0xFF00) >> 8; - - return bhy2_set_parameter(BHY2_PDR_PARAM(BHY2_PDR_PARAM_REF_HEAD_DELTA), ref_heading, sizeof(ref_heading), dev); -} - -int8_t bhy2_pdr_set_step_info(float step_length, float step_length_acc, struct bhy2_dev *dev) -{ - uint8_t stp_len[4] = { 0 }; - uint16_t length = (uint16_t)(step_length * 100.0f); /* 0.01m / LSB */ - uint16_t length_acc = (uint16_t)(step_length_acc * 100.0f); - - if (length > 500) - { - length = 500; - } - - if (length_acc > 500) - { - length_acc = 500; - } - - stp_len[0] = length & 0x00FF; - stp_len[1] = (length & 0xFF00) >> 8; - stp_len[2] = length_acc & 0x00FF; - stp_len[3] = (length_acc & 0xFF00) >> 8; - - return bhy2_set_parameter(BHY2_PDR_PARAM(BHY2_PDR_PARAM_STEP_LENGTH), stp_len, sizeof(stp_len), dev); -} - -int8_t bhy2_pdr_set_hand(uint8_t right_hand, struct bhy2_dev *dev) -{ - uint8_t handedness[4] = { 0 }; - - if (right_hand) - { - handedness[0] = 1; - } - - return bhy2_set_parameter(BHY2_PDR_PARAM(BHY2_PDR_PARAM_HANDEDNESS), handedness, sizeof(handedness), dev); -} - -int8_t bhy2_pdr_get_driver_version(struct bhy2_pdr_ver *version, struct bhy2_dev *dev) -{ - int8_t rslt = BHY2_OK; - uint8_t ver[8] = { 0 }; - uint32_t act_len; - - if (version == NULL) - { - rslt = BHY2_E_NULL_PTR; - } - else - { - rslt = bhy2_get_parameter(BHY2_PDR_PARAM(BHY2_PDR_PARAM_DRIVER_VER), ver, sizeof(ver), &act_len, dev); - - if (rslt == BHY2_OK) - { - version->major = ver[0]; - version->minor = ver[1]; - version->patch = ver[2]; - version->fw_build = BHY2_LE2U16(&ver[3]); - } - } - - return rslt; -} - -int8_t bhy2_pdr_get_algo_version(struct bhy2_pdr_ver *version, struct bhy2_dev *dev) -{ - int8_t rslt = BHY2_OK; - uint8_t ver[8] = { 0 }; - uint32_t act_len; - - if (version == NULL) - { - rslt = BHY2_E_NULL_PTR; - } - else - { - rslt = bhy2_get_parameter(BHY2_PDR_PARAM(BHY2_PDR_PARAM_ALGO_VER), ver, sizeof(ver), &act_len, dev); - - if (rslt == BHY2_OK) - { - version->major = ver[0]; - version->minor = ver[1]; - version->patch = ver[2]; - version->fw_build = BHY2_LE2U16(&ver[3]); - } - } - - return rslt; -} - -int8_t bhy2_pdr_get_pdr_variant(uint8_t *variant, struct bhy2_dev *dev) -{ - int8_t rslt = BHY2_OK; - uint8_t ver[4] = { 0 }; - uint32_t act_len; - - if (variant == NULL) - { - rslt = BHY2_E_NULL_PTR; - } - else - { - rslt = bhy2_get_parameter(BHY2_PDR_PARAM(BHY2_PDR_PARAM_PDR_VARIANT), ver, sizeof(ver), &act_len, dev); - - if (rslt == BHY2_OK) - { - *variant = ver[0]; - } - } - - return rslt; -} - -int8_t bhy2_pdr_get_device_position(uint8_t *dev_pos, struct bhy2_dev *dev) -{ - int8_t rslt = BHY2_OK; - uint8_t ver[4] = { 0 }; - uint32_t act_len; - - if (dev_pos == NULL) - { - rslt = BHY2_E_NULL_PTR; - } - else - { - - rslt = bhy2_get_parameter(BHY2_PDR_PARAM(BHY2_PDR_PARAM_DEVICE_POS), ver, sizeof(ver), &act_len, dev); - - if (rslt == BHY2_OK) - { - *dev_pos = ver[0]; - } - } - - return rslt; -} diff --git a/bhy2_pdr.h b/bhy2_pdr.h deleted file mode 100644 index 27bd7d1..0000000 --- a/bhy2_pdr.h +++ /dev/null @@ -1,78 +0,0 @@ -/** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. -* -* BSD-3-Clause -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* -* 3. Neither the name of the copyright holder nor the names of its -* contributors may be used to endorse or promote products derived from -* this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -* -* @file bhy2_pdr.h -* @date 2023-02-10 -* @version v1.5.0 -* -*/ - -#ifndef __BHY2_PDR_H__ -#define __BHY2_PDR_H__ - -/* Start of CPP guard */ -#ifdef __cplusplus -extern "C" { -#endif /*__cplusplus */ - -#include -#include - -#include "bhy2.h" -#include "bhy2_pdr_defs.h" - -void bhy2_pdr_parse_frame(const uint8_t *data, struct bhy2_pdr_frame *pdr_frame); - -int8_t bhy2_pdr_reset_full(struct bhy2_dev *dev); - -int8_t bhy2_pdr_reset_position(struct bhy2_dev *dev); - -int8_t bhy2_pdr_set_ref_heading_del(float heading, struct bhy2_dev *dev); - -int8_t bhy2_pdr_set_step_info(float step_length, float step_length_acc, struct bhy2_dev *dev); - -int8_t bhy2_pdr_set_hand(uint8_t right_hand, struct bhy2_dev *dev); - -int8_t bhy2_pdr_get_driver_version(struct bhy2_pdr_ver *version, struct bhy2_dev *dev); - -int8_t bhy2_pdr_get_algo_version(struct bhy2_pdr_ver *version, struct bhy2_dev *dev); - -int8_t bhy2_pdr_get_pdr_variant(uint8_t *variant, struct bhy2_dev *dev); - -int8_t bhy2_pdr_get_device_position(uint8_t *dev_pos, struct bhy2_dev *dev); - -/* End of CPP guard */ -#ifdef __cplusplus -} -#endif /*__cplusplus */ - -#endif diff --git a/bhy2_pdr_defs.h b/bhy2_pdr_defs.h deleted file mode 100644 index 59457de..0000000 --- a/bhy2_pdr_defs.h +++ /dev/null @@ -1,108 +0,0 @@ -/** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. -* -* BSD-3-Clause -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* -* 3. Neither the name of the copyright holder nor the names of its -* contributors may be used to endorse or promote products derived from -* this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -* -* @file bhy2_pdr_defs.h -* @date 2023-02-10 -* @version v1.5.0 -* -*/ - -#ifndef __BHY2_PDR_DEFS_H__ -#define __BHY2_PDR_DEFS_H__ - -/* Start of CPP guard */ -#ifdef __cplusplus -extern "C" { -#endif /*__cplusplus */ - -#include - -#define BHY2_SENSOR_ID_PDR UINT8_C(113) -#define BHY2_SENSOR_ID_PDR_LOG UINT8_C(119) - -#define BHY2_PDR_PAGE UINT16_C(10) -#define BHY2_PDR_PARAM(id) (((BHY2_PDR_PAGE) << 8) | (id)) - -#define BHY2_PDR_PARAM_FULL_RESET UINT8_C(1) -#define BHY2_PDR_PARAM_POS_RESET UINT8_C(2) -#define BHY2_PDR_PARAM_REF_HEAD_DELTA UINT8_C(32) -#define BHY2_PDR_PARAM_STEP_LENGTH UINT8_C(46) -#define BHY2_PDR_PARAM_HANDEDNESS UINT8_C(64) -#define BHY2_PDR_PARAM_DRIVER_VER UINT8_C(66) -#define BHY2_PDR_PARAM_ALGO_VER UINT8_C(67) -#define BHY2_PDR_PARAM_PDR_VARIANT UINT8_C(68) -#define BHY2_PDR_PARAM_DEVICE_POS UINT8_C(69) - -#define BHY2_PDR_VAR_6DOF UINT8_C(0x00) -#define BHY2_PDR_VAR_9DOF UINT8_C(0x01) - -#define BHY2_PDR_DEV_POS_WRIST UINT8_C(0x00) -#define BHY2_PDR_DEV_POS_HEAD UINT8_C(0x01) -#define BHY2_PDR_DEV_POS_SHOE UINT8_C(0x02) -#define BHY2_PDR_DEV_POS_BACKPACK UINT8_C(0x03) - -#define BHY2_PDR_FIFO_LEN UINT8_C(16) - -struct bhy2_pdr_frame /* Description; Scaling and format; Range; Comment */ -{ - int32_t pos_x; /* Position X; 0.001m/LSB 24 bit signed int; -8388.. 8388 m; relative to start position */ - int32_t pos_y; /* Position Y; 0.001m/LSB 24 bit signed int; -8388.. 8388 m; relative to start position */ - int16_t hor_acc; /* Horizontal 95% accuracy distribution; 0.1m/LSB 16 bit signed int; 0 .. 3276.7 m; The horizontal - * accuracy is given as radius of a circle, in which the user position is with 95% probability*/ - uint16_t heading; /* Heading; 0.1 degree/LSB 16 bit unsigned int; 0 .. 359.9 degree; Walking direction, measured - * clockwise from North */ - uint16_t heading_acc; /* Heading accuracy distribution; 0.1 degree/LSB 16 bit unsigned int; 0 .. 180.0 degree; */ - uint16_t step_count; /* Step count; 1 step / LSB 16 bit unsigned int; 0 .. 65535 steps; */ - uint8_t status; /* Status/Flags; Bit field; ; Bits: 0: full reset, 1: track reset. The bits are set for only the - * frame immediately after the reset.*/ -}; - -struct bhy2_pdr_ver -{ - uint8_t major, minor, patch; - uint16_t fw_build; -}; - -/* @brief bhy2 pdr sensor log frame*/ -typedef struct -{ - float timestamp; - float accel[3]; - float gyro[3]; -} BHY2_PACKED bhy2_pdr_log_frame_t; - -/* End of CPP guard */ -#ifdef __cplusplus -} -#endif /*__cplusplus */ - -#endif /* __BHY2_PDR_DEFS_H__ */ diff --git a/bhy2_swim.c b/bhy2_swim.c index c67cd12..4b2aa2c 100644 --- a/bhy2_swim.c +++ b/bhy2_swim.c @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhy2_swim.c -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ diff --git a/bhy2_swim.h b/bhy2_swim.h index aacea6b..ab5b197 100644 --- a/bhy2_swim.h +++ b/bhy2_swim.h @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,15 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhy2_swim.h -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ #ifndef _BHY2_SWIM_H_ #define _BHY2_SWIM_H_ -/* Start of CPP guard */ +/* Start of CPP Guard */ #ifdef __cplusplus extern "C" { #endif /*__cplusplus */ @@ -93,7 +93,7 @@ int8_t bhy2_swim_get_version(bhy2_swim_version_t *buffer, struct bhy2_dev *dev); */ int8_t bhy2_swim_set_config(const void *buffer, struct bhy2_dev *dev); -/* End of CPP guard */ +/* End of CPP Guard */ #ifdef __cplusplus } #endif /*__cplusplus */ diff --git a/bhy2_swim_defs.h b/bhy2_swim_defs.h index e3f1651..6811ee8 100644 --- a/bhy2_swim_defs.h +++ b/bhy2_swim_defs.h @@ -1,5 +1,5 @@ /** -* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. +* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved. * * BSD-3-Clause * @@ -31,18 +31,18 @@ * POSSIBILITY OF SUCH DAMAGE. * * @file bhy2_swim_defs.h -* @date 2023-02-10 -* @version v1.5.0 +* @date 2023-03-24 +* @version v1.6.0 * */ #ifndef _BHY2_SWIM_DEFS_H_ #define _BHY2_SWIM_DEFS_H_ -/* Start of CPP guard */ +/* Start of CPP Guard */ #ifdef __cplusplus extern "C" { -#endif +#endif /*__cplusplus */ #include @@ -118,9 +118,9 @@ typedef struct bhy2_swim_version typedef void (*bhy2_swim_algo_callback)(uint32_t seconds, uint32_t nanoseconds, const struct bhy2_swim_data_parse *callback_info); -/* End of CPP guard */ +/* End of CPP Guard */ #ifdef __cplusplus } -#endif +#endif /*__cplusplus */ #endif /* _BHY2_SWIM_DEFS_H_ */ diff --git a/examples/bhy2cli_ble/CHANGELOG.md b/examples/bhy2cli_ble/CHANGELOG.md index d2eae6e..59ffd46 100644 --- a/examples/bhy2cli_ble/CHANGELOG.md +++ b/examples/bhy2cli_ble/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +# v0.4.9 +- Added support HEX streaming mode. +- Added support for listing the schema information of the loaded sensors +- Added support for Head Orientation virtual sensors. +- Added support for Head Orientation Parameter Configuration. +- Removed the support for PDR +- Rectified parsing callback to s16_to_float for Temperature Sensor + +Known Limitations - +- 'gyrogettat' does not return expected output. +- For Head Orientation sensors, for subsequent sensor activation with different ODRs, the ODR change is not reflected. +- For 'dactse' command, parsing flag is not updated. + # v0.4.8 - Optimised the Data Injection feature for generic use by removing Sensor ID dependnecy - Integrated generic file parser for txt/bin files and resolved length dependency, for Data Injection diff --git a/examples/bhy2cli_ble/Makefile b/examples/bhy2cli_ble/Makefile index 3e09f18..df058ee 100644 --- a/examples/bhy2cli_ble/Makefile +++ b/examples/bhy2cli_ble/Makefile @@ -26,7 +26,6 @@ $(API_LOCATION)/bhy2.c \ $(API_LOCATION)/bhy2_hif.c \ $(API_LOCATION)/bhy2_parse.c \ $(API_LOCATION)/bhy2_klio.c \ -$(API_LOCATION)/bhy2_pdr.c \ $(API_LOCATION)/bhy2_swim.c \ $(API_LOCATION)/bhy2_bsec.c \ $(API_LOCATION)/bhi3.c \ diff --git a/examples/bhy2cli_ble/bhy2cli_callbacks.c b/examples/bhy2cli_ble/bhy2cli_callbacks.c index c2de56d..38b3250 100644 --- a/examples/bhy2cli_ble/bhy2cli_callbacks.c +++ b/examples/bhy2cli_ble/bhy2cli_callbacks.c @@ -37,7 +37,7 @@ #define BHY2CLI_VER_MAJOR "0" #define BHY2CLI_VER_MINOR "4" -#define BHY2CLI_VER_BUGFIX "8" +#define BHY2CLI_VER_BUGFIX "9" #ifdef __STDC_ALLOC_LIB__ #define __STDC_WANT_LIB_EXT2__ 1 @@ -70,9 +70,6 @@ #define BHY2CLI_MAX_STRING_LENGTH UINT16_C(32) -#define DATA(format, ...) verbose("[D]"format,##__VA_ARGS__) -#define PRINT_D(format, ...) verbose(format,##__VA_ARGS__) - /* Contains all parameters of the of custom virtual sensors * required for parsing */ typedef struct BHY2_PACKED custom_driver_information @@ -111,14 +108,14 @@ struct data_inject dinject; /*! * @brief To convert string input to int */ -uint16_t string_to_int(const char *str) +uint32_t string_to_int(const char *str) { - char int_str[16] = { 0 }; + char int_str[32] = { 0 }; strncpy(int_str, str, strlen(str)); int_str[strlen(str)] = '\0'; - return (uint16_t)strtol(int_str, NULL, 0); + return (uint32_t)strtol(int_str, NULL, 0); } static cli_callback_table_t bhy2_cli_callbacks[] = { @@ -132,6 +129,8 @@ static cli_callback_table_t bhy2_cli_callbacks[] = { { 'a', "addse", 1, addse_callback, addse_help }, /* Add a custom sensor */ { 'g', "boot", 1, boot_callback, boot_help }, /* Boot from RAM or Flash */ { 'c', "actse", 1, actse_callback, actse_help }, /* Activate/De-activate a sensor */ + { 0, "schema", 0, schema_callback, schema_help }, /* Get schema information of the loaded sensors */ + { 0, "hexse", 1, hexse_callback, hexse_help }, /* Stream sensor data in hex */ { 0, "dactse", 0, dactse_callback, dactse_help }, /* Deactivate all the active sensors */ { 0, "lsactse", 0, lsactse_callback, lsactse_help }, /* List all the active sensors */ { 0, "dmode", 1, dmode_callback, dmode_help }, /* Switch to Data Injection mode */ @@ -163,15 +162,6 @@ static cli_callback_table_t bhy2_cli_callbacks[] = { { 0, "ksetparam", 2, ksetparam_callback, ksetparam_help }, /* Set Klio parameters */ { 0, "ksimscore", 2, ksimscore_callback, ksimscore_help }, /* Get Klio Similarity score */ { 0, "kmsimscore", 2, kmsimscore_callback, kmsimscore_help }, /* Get Multiple Klio Similarity score */ - { 0, "pfullreset", 0, pfullreset_callback, pfullreset_help }, /* Trigger a PDR reset */ - { 0, "ptrackreset", 0, ptrackreset_callback, ptrackreset_help }, /* Trigger a track reset for the PDR */ - { 0, "prefheaddel", 1, prefheaddel_callback, prefheaddel_help }, /* Set the PDR's reference heading delta */ - { 0, "pstepinfo", 2, pstepinfo_callback, pstepinfo_help }, /* Set the PDR's Step length */ - { 0, "psethand", 1, psethand_callback, psethand_help }, /* Set the hand for the PDR */ - { 0, "pdrver", 0, pdrver_callback, pdrver_help }, /* Get the PDR driver version*/ - { 0, "palver", 0, palver_callback, palver_help }, /* Get the PDR algo version */ - { 0, "pvariant", 0, pvariant_callback, pvariant_help }, /* Get the PDR variant */ - { 0, "pdevpos", 0, pdevpos_callback, pdevpos_help }, /* Get the PDR device position */ { 0, "swim", 3, swim_callback, swim_help }, /* Configure the Swim recognition */ { 0, "swimver", 0, swimver_callback, swimver_help }, /* Get the Swim Version */ { 0, "swimgetfreq", 0, swimgetfreq_callback, swimgetfreq_help }, /* Get the Swim frequency */ @@ -206,6 +196,27 @@ static cli_callback_table_t bhy2_cli_callbacks[] = { { 0, "nmgetcnfg", 0, nmgetcnfg_callback, nmgetcnfg_help }, /* Get the No Motion Configuration */ { 0, "wgdsetcnfg", 10, wgdsetcnfg_callback, wgdsetcnfg_help }, /* Set the Wrist Gesture Detection Configuration */ { 0, "wgdgetcnfg", 0, wgdgetcnfg_callback, wgdgetcnfg_help }, /* Get the Wrist Gesture Detection Configuration */ + { 0, "hmctrig", 0, hmctrig_callback, hmctrig_help }, /* Trigger Head Misalignment Calibration */ + { 0, "hmcsetcnfg", 4, hmcsetcnfg_callback, hmcsetcnfg_help }, /* Set Head Misalignment Configuration */ + { 0, "hmcgetcnfg", 0, hmcgetcnfg_callback, hmcgetcnfg_help }, /* Get Head Misalignment Configuration */ + { 0, "hmcsetdefcnfg", 0, hmcsetdefcnfg_callback, hmcsetdefcnfg_help }, /* Set Default Head Misalignment + * Configuration */ + { 0, "hmcver", 0, hmcver_callback, hmcver_help }, /* Get Head Misalignment Calibrator Version */ + { 0, "hmcsetcalcorrq", 4, hmcsetcalcorrq_callback, hmcsetcalcorrq_help }, /* Set Head Misalignment Quaternion + * Calibration Correction */ + { 0, "hmcgetcalcorrq", 0, hmcgetcalcorrq_callback, hmcgetcalcorrq_help }, /* Get Head Misalignment Quaternion + * Calibration Correction */ + { 0, "hosetheadcorrq", 1, hosetheadcorrq_callback, hosetheadcorrq_help }, /* Get Head Orientation + * Quaternion Initial Head + * Correction */ + { 0, "hogetheadcorrq", 0, hogetheadcorrq_callback, hogetheadcorrq_help }, /* Get Head Orientation + * Quaternion Initial Head + * Correction */ + { 0, "hover", 0, hover_callback, hover_help }, /* Get Head Orientation Version */ + { 0, "hosetheadcorre", 1, hosetheadcorre_callback, hosetheadcorre_help }, /* Get Head Orientation Euler + * Initial Head Correction */ + { 0, "hogetheadcorre", 0, hogetheadcorre_callback, hogetheadcorre_help }, /* Get Head Orientation Euler Initial Head + * Correction */ #ifndef PC { 0, "echo", 1, echo_callback, echo_help }, /* Toggle the echo setting */ { 0, "heart", 1, heartbeat_callback, heartbeat_help }, /* Toggle the heartbeat message setting */ @@ -251,15 +262,18 @@ static void klio_similarity_score_multiple(const char *arg1, const char *arg2, s static void klio_pattern_state_operation(const uint8_t enable, const char *arg1, struct bhy2_dev *bhy2); void parse_klio(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref); void parse_klio_log(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref); -void parse_pdr(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref); -void parse_pdr_log(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref); void parse_swim(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref); void parse_acc_gyro(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref); void parse_multitap(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref); void parse_wrist_gesture_detect(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref); void parse_air_quality(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref); +void parse_hmc(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref); +void parse_oc(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref); +void parse_ec(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref); static void log_data(uint8_t sid, uint64_t tns, uint8_t event_size, uint8_t *event_payload, struct logbin_dev *logdev); static void write_meta_info(struct logbin_dev *log, struct bhy2_dev *bhy2); +static void stream_hex_data(uint8_t sid, uint32_t ts, uint32_t tns, uint8_t event_size, uint8_t *event_payload); +static void schema_info(struct bhy2_dev *bhy2); cli_callback_table_t *bhy2_get_cli_callbacks(void) { @@ -431,6 +445,8 @@ bhy2_fifo_parse_callback_t bhy2_get_callback(uint8_t sensor_id) break; case BHY2_SENSOR_ID_TEMP: case BHY2_SENSOR_ID_TEMP_WU: + callback = parse_s16_as_float; + break; case BHY2_SENSOR_ID_BARO: case BHY2_SENSOR_ID_BARO_WU: callback = parse_u24_as_float; @@ -441,12 +457,6 @@ bhy2_fifo_parse_callback_t bhy2_get_callback(uint8_t sensor_id) case BHY2_SENSOR_ID_KLIO_LOG: callback = parse_klio_log; break; - case BHY2_SENSOR_ID_PDR: - callback = parse_pdr; - break; - case BHY2_SENSOR_ID_PDR_LOG: - callback = parse_pdr_log; - break; case BHY2_SENSOR_ID_SWIM: callback = parse_swim; break; @@ -505,6 +515,17 @@ bhy2_fifo_parse_callback_t bhy2_get_callback(uint8_t sensor_id) case BHY2_SENSOR_ID_AIR_QUALITY: callback = parse_air_quality; break; + case BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG: + callback = parse_hmc; + break; + case BHY2_SENSOR_ID_IMU_HEAD_ORI_Q: + case BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q: + callback = parse_oc; + break; + case BHY2_SENSOR_ID_IMU_HEAD_ORI_E: + case BHY2_SENSOR_ID_NDOF_HEAD_ORI_E: + callback = parse_ec; + break; default: callback = parse_generic; break; @@ -603,7 +624,7 @@ int8_t kdispatt_help(void *ref) int8_t kdisapatt_help(void *ref) { PRINT(" kdisapatt \r\n"); - PRINT(" = Disable pattern adaption for given pattern ids\r\n"); + PRINT(" = Disable pattern adaptation for given pattern ids\r\n"); PRINT(" pattern indices to disable, specified as 0,1,4 etc\r\n"); return CLI_OK; @@ -622,7 +643,7 @@ int8_t kautldpatt_help(void *ref) { PRINT(" kautldpatt \r\n"); PRINT(" = Automatically use learnt patterns for recognition\r\n"); - PRINT(" enable or disable (0/1)\r\n"); + PRINT(" enable or disable (1/0)\r\n"); PRINT(" pattern index to start loading into (normally 0)\r\n"); return CLI_OK; @@ -656,7 +677,7 @@ int8_t kldpatt_callback(uint8_t argc, uint8_t *argv[], void *ref) INFO("Executing %s %s\r\n", argv[0], argv[1]); klio_enable(&cli_ref->bhy2); klio_load_pattern((char *)argv[1], (char *)argv[2], &cli_ref->bhy2); - PRINT("\r\n\r\n"); + PRINT("Loaded pattern %s for recognition\r\n", argv[1]); return CLI_OK; } @@ -668,7 +689,7 @@ int8_t kenpatt_callback(uint8_t argc, uint8_t *argv[], void *ref) INFO("Executing %s %s\r\n", argv[0], argv[1]); klio_enable(&cli_ref->bhy2); klio_pattern_state_operation(KLIO_PATTERN_STATE_ENABLE, (char *)argv[1], &cli_ref->bhy2); - PRINT("\r\n\r\n"); + PRINT("Enabled pattern %s for recognition\r\n", argv[1]); return CLI_OK; } @@ -680,7 +701,7 @@ int8_t kdispatt_callback(uint8_t argc, uint8_t *argv[], void *ref) INFO("Executing %s %s\r\n", argv[0], argv[1]); klio_enable(&cli_ref->bhy2); klio_pattern_state_operation(KLIO_PATTERN_STATE_DISABLE, (char *)argv[1], &cli_ref->bhy2); - PRINT("\r\n\r\n"); + PRINT("Disabled pattern %s from recognition\r\n", argv[1]); return CLI_OK; } @@ -692,7 +713,7 @@ int8_t kdisapatt_callback(uint8_t argc, uint8_t *argv[], void *ref) INFO("Executing %s %s\r\n", argv[0], argv[1]); klio_enable(&cli_ref->bhy2); klio_pattern_state_operation(KLIO_PATTERN_STATE_AP_DISABLE, (char *)argv[1], &cli_ref->bhy2); - PRINT("\r\n\r\n"); + PRINT("Disable adaptation for pattern %s\r\n", argv[1]); return CLI_OK; } @@ -704,7 +725,7 @@ int8_t kswpatt_callback(uint8_t argc, uint8_t *argv[], void *ref) INFO("Executing %s %s\r\n", argv[0], argv[1]); klio_enable(&cli_ref->bhy2); klio_pattern_state_operation(KLIO_PATTERN_STATE_SWITCH_HAND, (char *)argv[1], &cli_ref->bhy2); - PRINT("\r\n\r\n"); + PRINT("Switched pattern to opposite hand for pattern %s\r\n", argv[1]); return CLI_OK; } @@ -717,7 +738,9 @@ int8_t kautldpatt_callback(uint8_t argc, uint8_t *argv[], void *ref) klio_enable(&cli_ref->bhy2); klio_vars.auto_load_pattern = atoi((char *)argv[1]); klio_vars.auto_load_pattern_write_index = atoi((char *)argv[2]); - INFO("Klio auto load pattern set to %s, index is %s\r\n", argv[1], argv[2]); + PRINT("Klio auto load pattern %s, starting from index %s\r\n", + (klio_vars.auto_load_pattern == 0) ? "Disabled" : "Enabled", + argv[2]); PRINT("\r\n\r\n"); return CLI_OK; @@ -742,7 +765,7 @@ int8_t ksetparam_callback(uint8_t argc, uint8_t *argv[], void *ref) INFO("Executing %s %s %s\r\n", argv[0], argv[1], argv[2]); klio_enable(&cli_ref->bhy2); klio_set_parameter((char *)argv[1], (char *)argv[2], &cli_ref->bhy2); - PRINT("\r\n\r\n"); + PRINT("Set value %s for parameter id %s\r\n", argv[2], argv[1]); return CLI_OK; } @@ -1232,6 +1255,49 @@ int8_t actse_callback(uint8_t argc, uint8_t *argv[], void *ref) return CLI_OK; } +int8_t schema_help(void *ref) +{ + PRINT(" schema\t= Show schema information: \r\n"); + PRINT(" \t Sensor ID, Sensor Name, Event Size, Parsing Format, Axis Names, Scaling Factor\r\n"); + + return CLI_OK; +} + +int8_t schema_callback(uint8_t argc, uint8_t *argv[], void *ref) +{ + struct bhy2_cli_ref *cli_ref = (struct bhy2_cli_ref *)ref; + + INFO("Executing %s %s\r\n", argv[0], argv[1]); + schema_info(&cli_ref->bhy2); + PRINT("\r\n\r\n"); + + return CLI_OK; +} + +int8_t hexse_help(void *ref) +{ + PRINT(" hexse :[:]\r\n"); + PRINT(" \t= Stream sensor at specified sample rate , in hex format\r\n"); + PRINT(" \t -latency , duration time