Added missing lib https://github.com/Xinyuan-LilyGO/T-Deck/issues/47
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,479 @@
|
||||
/**
|
||||
* Copyright (c) 2020 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 bmm150.h
|
||||
* @date 2020-06-03
|
||||
* @version v2.0.0
|
||||
*
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @defgroup bmm150 BMM150
|
||||
*/
|
||||
|
||||
#ifndef _BMM150_H
|
||||
#define _BMM150_H
|
||||
|
||||
/*! CPP guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/********************************************************************/
|
||||
/* header files */
|
||||
|
||||
#include "bmm150_defs.h"
|
||||
|
||||
/********************************************************************/
|
||||
/* (extern) variable declarations */
|
||||
/********************************************************************/
|
||||
/* function prototype declarations */
|
||||
|
||||
/**
|
||||
* \ingroup bmm150
|
||||
* \defgroup bmm150ApiInit Initialization
|
||||
* @brief Initialize the sensor and device structure
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmm150ApiInit
|
||||
* \page bmm150_api_bmm150_init bmm150_init
|
||||
* \code
|
||||
* int8_t bmm150_init(struct bmm150_dev *dev);
|
||||
* \endcode
|
||||
* @details This API is the entry point, Call this API before using other APIs.
|
||||
* This API reads the chip-id of the sensor which is the first step to
|
||||
* verify the sensor and also it configures the read mechanism of SPI and
|
||||
* I2C interface.
|
||||
*
|
||||
* @param[in,out] dev : Structure instance of bmm150_dev
|
||||
* @note : Refer user guide for detailed info.
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval >0 -> Warning
|
||||
* @retval <0 -> Fail
|
||||
*/
|
||||
int8_t bmm150_init(struct bmm150_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmm150
|
||||
* \defgroup bmm150ApiRegs Registers
|
||||
* @brief Read / Write data to the given register address of the sensor
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmm150ApiRegs
|
||||
* \page bmm150_api_bmm150_set_regs bmm150_set_regs
|
||||
* \code
|
||||
* int8_t bmm150_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, struct bmm150_dev *dev);
|
||||
* \endcode
|
||||
* @details This API writes the given data to the register address
|
||||
* of the sensor.
|
||||
*
|
||||
* @param[in] reg_addr : Register address from where the data to be written.
|
||||
* @param[in] reg_data : Pointer to data buffer which is to be written
|
||||
* in the reg_addr of sensor.
|
||||
* @param[in] len : No of bytes of data to write..
|
||||
* @param[in] dev : Structure instance of bmm150_dev.
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval >0 -> Warning
|
||||
* @retval <0 -> Fail
|
||||
*/
|
||||
int8_t bmm150_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, struct bmm150_dev *dev);
|
||||
|
||||
/*!
|
||||
* \ingroup bmm150ApiRegs
|
||||
* \page bmm150_api_bmm150_get_regs bmm150_get_regs
|
||||
* \code
|
||||
* int8_t bmm150_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bmm150_dev *dev)
|
||||
* \endcode
|
||||
* @details This API reads the data from the given register address of sensor.
|
||||
*
|
||||
* @param[in] reg_addr : Register address from where the data to be read
|
||||
* @param[out] reg_data : Pointer to data buffer to store the read data.
|
||||
* @param[in] len : No of bytes of data to be read.
|
||||
* @param[in] dev : Structure instance of bmm150_dev.
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval >0 -> Warning
|
||||
* @retval <0 -> Fail
|
||||
*/
|
||||
int8_t bmm150_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bmm150_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmm150
|
||||
* \defgroup bmm150ApiSoftreset Soft reset
|
||||
* @brief Perform soft reset of the sensor
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmm150ApiSoftreset
|
||||
* \page bmm150_api_bmm150_soft_reset bmm150_soft_reset
|
||||
* \code
|
||||
* int8_t bmm150_soft_reset(struct bmm150_dev *dev);
|
||||
* \endcode
|
||||
* @details This API is used to perform soft-reset of the sensor
|
||||
* where all the registers are reset to their default values except 0x4B.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bmm150_dev.
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval >0 -> Warning
|
||||
* @retval <0 -> Fail
|
||||
*/
|
||||
int8_t bmm150_soft_reset(struct bmm150_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmm150
|
||||
* \defgroup bmm150ApiPowermode Power mode
|
||||
* @brief Set / Get power mode of the sensor
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmm150ApiPowermode
|
||||
* \page bmm150_api_bmm150_set_op_mode bmm150_set_op_mode
|
||||
* \code
|
||||
* int8_t bmm150_set_op_mode(const struct bmm150_settings *settings, struct bmm150_dev *dev);
|
||||
* \endcode
|
||||
* @details This API is used to set the power mode of the sensor.
|
||||
*
|
||||
* @param[in] settings : Structure instance of bmm150_settings.
|
||||
* @param[in] dev : Structure instance of bmm150_dev.
|
||||
*
|
||||
*@verbatim
|
||||
* settings->pwr_mode | Power mode
|
||||
* ------------------------|-----------------------
|
||||
* 0x00 | BMM150_POWERMODE_NORMAL
|
||||
* 0x01 | BMM150_POWERMODE_FORCED
|
||||
* 0x03 | BMM150_POWERMODE_SLEEP
|
||||
* 0x04 | BMM150_POWERMODE_SUSPEND
|
||||
*@endverbatim
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval >0 -> Warning
|
||||
* @retval <0 -> Fail
|
||||
*/
|
||||
int8_t bmm150_set_op_mode(const struct bmm150_settings *settings, struct bmm150_dev *dev);
|
||||
|
||||
/*!
|
||||
* \ingroup bmm150ApiPowermode
|
||||
* \page bmm150_api_bmm150_get_op_mode bmm150_get_op_mode
|
||||
* \code
|
||||
* int8_t bmm150_get_op_mode(uint8_t *op_mode, struct bmm150_dev *dev);
|
||||
* \endcode
|
||||
* @details This API is used to get the power mode of the sensor.
|
||||
*
|
||||
* @param[out] op_mode : power mode of the sensor.
|
||||
* @param[in] dev : Structure instance of bmm150_dev.
|
||||
*
|
||||
*@verbatim
|
||||
* op_mode | Power mode
|
||||
* -------------|-----------------------
|
||||
* 0x00 | BMM150_POWERMODE_NORMAL
|
||||
* 0x01 | BMM150_POWERMODE_FORCED
|
||||
* 0x03 | BMM150_POWERMODE_SLEEP
|
||||
* 0x04 | BMM150_POWERMODE_SUSPEND
|
||||
*@endverbatim
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval >0 -> Warning
|
||||
* @retval <0 -> Fail
|
||||
*/
|
||||
int8_t bmm150_get_op_mode(uint8_t *op_mode, struct bmm150_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmm150
|
||||
* \defgroup bmm150ApiPresetmode Preset mode
|
||||
* @brief Set preset mode of the sensor
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmm150ApiPresetmode
|
||||
* \page bmm150_api_bmm150_set_presetmode bmm150_set_presetmode
|
||||
* \code
|
||||
* int8_t bmm150_set_presetmode(struct bmm150_settings *settings, struct bmm150_dev *dev);
|
||||
* \endcode
|
||||
* @details This API is used to set the preset mode of the sensor.
|
||||
*
|
||||
* @param[in] settings : Structure instance of bmm150_settings.
|
||||
* @param[in] dev : Structure instance of bmm150_dev.
|
||||
*
|
||||
*@verbatim
|
||||
* settings->preset_mode | Preset mode
|
||||
* ---------------------------|----------------------------------
|
||||
* 0x01 | BMM150_PRESETMODE_LOWPOWER
|
||||
* 0x02 | BMM150_PRESETMODE_REGULAR
|
||||
* 0x03 | BMM150_PRESETMODE_HIGHACCURACY
|
||||
* 0x04 | BMM150_PRESETMODE_ENHANCED
|
||||
*@endverbatim
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval >0 -> Warning
|
||||
* @retval <0 -> Fail
|
||||
*/
|
||||
int8_t bmm150_set_presetmode(struct bmm150_settings *settings, struct bmm150_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmm150
|
||||
* \defgroup bmm150ApiSensorSettings Sensor Settings
|
||||
* @brief Set / Get sensor settings of the sensor
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmm150ApiSensorSettings
|
||||
* \page bmm150_api_bmm150_set_sensor_settings bmm150_set_sensor_settings
|
||||
* \code
|
||||
* int8_t bmm150_set_sensor_settings(uint16_t desired_settings, const struct bmm150_settings *settings, struct bmm150_dev *dev);
|
||||
* \endcode
|
||||
* @details This API sets the sensor settings based on the desired_settings
|
||||
* and the dev structure configuration
|
||||
*
|
||||
* @param[in] desired_settings : Selection macro for selecting the setting.
|
||||
* @param[in] settings : Structure instance of bmm150_settings.
|
||||
* @param[in] dev : Structure instance of bmm150_dev.
|
||||
*
|
||||
* @note Assign the sensor setting macros (multiple macros can be
|
||||
* set by doing a bitwise-OR operation) to the desired_settings parameter
|
||||
* of this API to perform the corresponding setting.
|
||||
*
|
||||
* @note threshold interrupt for each axes are set by using bitwise AND
|
||||
* operation of the following macros
|
||||
* - BMM150_THRESHOLD_X
|
||||
* - BMM150_THRESHOLD_Y
|
||||
* - BMM150_THRESHOLD_Z
|
||||
*
|
||||
*@verbatim
|
||||
* desired_settings | Selected sensor setting macros
|
||||
* -------------------|--------------------------------
|
||||
* 0x0001 | BMM150_SEL_DATA_RATE
|
||||
* 0x0002 | BMM150_SEL_CONTROL_MEASURE
|
||||
* 0x0004 | BMM150_SEL_XY_REP
|
||||
* 0x0008 | BMM150_SEL_Z_REP
|
||||
* 0x0010 | BMM150_SEL_DRDY_PIN_EN
|
||||
* 0x0020 | BMM150_SEL_INT_PIN_EN
|
||||
* 0x0040 | BMM150_SEL_DRDY_POLARITY
|
||||
* 0x0080 | BMM150_SEL_INT_LATCH
|
||||
* 0x0100 | BMM150_SEL_INT_POLARITY
|
||||
* 0x0200 | BMM150_SEL_DATA_OVERRUN_INT
|
||||
* 0x0400 | BMM150_SEL_OVERFLOW_INT
|
||||
* 0x0800 | BMM150_SEL_HIGH_THRESHOLD_INT
|
||||
* 0x1000 | BMM150_SEL_LOW_THRESHOLD_INT
|
||||
* 0x2000 | BMM150_SEL_LOW_THRESHOLD_SETTING
|
||||
* 0x4000 | BMM150_SEL_HIGH_THRESHOLD_SETTING
|
||||
*@endverbatim
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval >0 -> Warning
|
||||
* @retval <0 -> Fail
|
||||
*/
|
||||
int8_t bmm150_set_sensor_settings(uint16_t desired_settings,
|
||||
const struct bmm150_settings *settings,
|
||||
struct bmm150_dev *dev);
|
||||
|
||||
/*!
|
||||
* \ingroup bmm150ApiSensorSettings
|
||||
* \page bmm150_api_bmm150_get_sensor_settings bmm150_get_sensor_settings
|
||||
* \code
|
||||
* int8_t bmm150_get_sensor_settings(struct bmm150_settings *settings, struct bmm150_dev *dev);
|
||||
* \endcode
|
||||
* @details This API gets all the sensor settings and updates the dev structure
|
||||
*
|
||||
* @param[in] settings : Structure instance of bmm150_settings.
|
||||
* @param[in] dev : Structure instance of bmm150_dev.
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval >0 -> Warning
|
||||
* @retval <0 -> Fail
|
||||
*/
|
||||
int8_t bmm150_get_sensor_settings(struct bmm150_settings *settings, struct bmm150_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmm150
|
||||
* \defgroup bmm150ApiMagData Read magnetometer data
|
||||
* @brief Read magnetometer data
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmm150ApiMagData
|
||||
* \page bmm150_api_bmm150_read_mag_data bmm150_read_mag_data
|
||||
* \code
|
||||
* int8_t bbmm150_read_mag_data(struct bmm150_mag_data *mag_data, struct bmm150_dev *dev);
|
||||
* \endcode
|
||||
* @details This API reads the magnetometer data from registers 0x42 to 0x49
|
||||
* and updates the dev structure with compensated mag data in micro-tesla
|
||||
*
|
||||
* @param[in] mag_data : Structure instance of bmm150_mag_data.
|
||||
* @param[in,out] dev : Structure instance of bmm150_dev.
|
||||
*
|
||||
* @note The output mag data can be obtained either in int16_t or float format
|
||||
* using this API.
|
||||
* @note Enable the macro "BMM150_USE_FLOATING_POINT" in the bmm150_defs.h
|
||||
* file and call this API to get the mag data in float,
|
||||
* disable this macro to get the mag data in int16_t format
|
||||
*
|
||||
*@verbatim
|
||||
* Mag data output(micro-tesla) | Mag data in dev structure(int16_t/float)
|
||||
* --------------------------------|------------------------------------------
|
||||
* X-axis data | mag_data->x
|
||||
* Y-axis data | mag_data->y
|
||||
* Z-axis data | mag_data->z
|
||||
*@endverbatim
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval >0 -> Warning
|
||||
* @retval <0 -> Fail
|
||||
*/
|
||||
int8_t bmm150_read_mag_data(struct bmm150_mag_data *mag_data, struct bmm150_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmm150
|
||||
* \defgroup bmm150ApiSelftest Self test
|
||||
* @brief Perform self test
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmm150ApiSelftest
|
||||
* \page bmm150_api_bmm150_perform_self_test bmm150_perform_self_test
|
||||
* \code
|
||||
* int8_t bmm150_perform_self_test(uint8_t self_test_mode, struct bmm150_dev *dev);
|
||||
* \endcode
|
||||
* @details This API is used to perform the complete self test
|
||||
* (both normal and advanced) for the BMM150 sensor
|
||||
*
|
||||
* @param[in] self_test_mode : The type of self test to be performed
|
||||
* @param[in] dev : Structure instance of bmm150_dev.
|
||||
*
|
||||
*@verbatim
|
||||
* self_test_mode | Self test enabled
|
||||
* --------------------|--------------------------
|
||||
* 0 | BMM150_SELF_TEST_NORMAL
|
||||
* 1 | BMM150_SELF_TEST_ADVANCED
|
||||
*@endverbatim
|
||||
*
|
||||
* @note The return value of this API gives us the result of self test.
|
||||
*
|
||||
* @note Performing advanced self test does soft reset of the sensor, User can
|
||||
* set the desired settings after performing the advanced self test.
|
||||
*
|
||||
* @return Result of API execution status and self test result.
|
||||
* @retval 0 BMM150_OK
|
||||
* @retval 1 BMM150_W_NORMAL_SELF_TEST_YZ_FAIL
|
||||
* @retval 2 BMM150_W_NORMAL_SELF_TEST_XZ_FAIL
|
||||
* @retval 3 BMM150_W_NORMAL_SELF_TEST_Z_FAIL
|
||||
* @retval 4 BMM150_W_NORMAL_SELF_TEST_XY_FAIL
|
||||
* @retval 5 BMM150_W_NORMAL_SELF_TEST_Y_FAIL
|
||||
* @retval 6 BMM150_W_NORMAL_SELF_TEST_X_FAIL
|
||||
* @retval 7 BMM150_W_NORMAL_SELF_TEST_XYZ_FAIL
|
||||
* @retval 8 BMM150_W_ADV_SELF_TEST_FAIL
|
||||
*/
|
||||
int8_t bmm150_perform_self_test(uint8_t self_test_mode, struct bmm150_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmm150
|
||||
* \defgroup bmm150ApiInt Interrupt status
|
||||
* @brief Obtain interrupt staus flags
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmm150ApiInt
|
||||
* \page bmm150_api_bmm150_get_interrupt_status bmm150_get_interrupt_status
|
||||
* \code
|
||||
* int8_t bmm150_get_interrupt_status(struct bmm150_dev *dev);
|
||||
* \endcode
|
||||
* @details This API obtains the status flags of all interrupt
|
||||
* which is used to check for the assertion of interrupts
|
||||
*
|
||||
* @param[in,out] dev : Structure instance of bmm150_dev.
|
||||
*
|
||||
* @note The status flags of all the interrupts are stored in the
|
||||
* dev->int_status.
|
||||
*
|
||||
* @note The value of dev->int_status is performed a bitwise AND operation
|
||||
* with predefined interrupt status macros to find the interrupt status
|
||||
* which is either set or reset.
|
||||
*
|
||||
* Ex.
|
||||
* if (dev->int_status & BMM150_INT_ASSERTED_DRDY)
|
||||
* {
|
||||
* Occurrence of data ready interrupt
|
||||
* } else {
|
||||
* No interrupt occurred
|
||||
* }
|
||||
*
|
||||
* @return Result of API execution status and self test result.
|
||||
* @retval 0 -> Success
|
||||
* @retval >0 -> Warning
|
||||
* @retval <0 -> Fail
|
||||
*/
|
||||
int8_t bmm150_get_interrupt_status(struct bmm150_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmm150
|
||||
* \defgroup bmm150ApiAux Compensate magnetometer data
|
||||
* @brief Compensation of magnetometer data
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmm150ApiAux
|
||||
* \page bmm150_api_bmm150_aux_mag_data bmm150_aux_mag_data
|
||||
* \code
|
||||
* int8_t bmm150_aux_mag_data(uint8_t *aux_data, struct bmm150_mag_data *mag_data, const struct bmm150_dev *dev);
|
||||
* \endcode
|
||||
* @details This API is used to compensate the raw mag data
|
||||
*
|
||||
* @param[in] aux_data : Raw mag data obtained from BMI160 registers
|
||||
* @param[in] mag_data : Structure instance of bmm150_mag_data.
|
||||
* @param[in,out] dev : Structure instance of bmm150_dev.
|
||||
*
|
||||
* @return Result of API execution status and self test result.
|
||||
* @retval 0 -> Success
|
||||
* @retval >0 -> Warning
|
||||
* @retval <0 -> Fail
|
||||
*/
|
||||
int8_t bmm150_aux_mag_data(uint8_t *aux_data, struct bmm150_mag_data *mag_data, const struct bmm150_dev *dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* End of CPP guard */
|
||||
|
||||
#endif /* _BMM150_H */
|
||||
@@ -0,0 +1,643 @@
|
||||
/**
|
||||
* Copyright (c) 2020 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 bmm150_defs.h
|
||||
* @date 2020-06-03
|
||||
* @version v2.0.0
|
||||
*
|
||||
*/
|
||||
|
||||
/*! \file bmm150_defs.h */
|
||||
|
||||
#ifndef _BMM150_DEFS_H
|
||||
#define _BMM150_DEFS_H
|
||||
|
||||
/******************************************************************************/
|
||||
/*! @name Header includes */
|
||||
/******************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#include <linux/types.h>
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
/*! @name Common macros */
|
||||
/******************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#if (LONG_MAX) > 0x7fffffff
|
||||
#define __have_long64 1
|
||||
#elif (LONG_MAX) == 0x7fffffff
|
||||
#define __have_long32 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(UINT8_C)
|
||||
#define INT8_C(x) x
|
||||
#if (INT_MAX) > 0x7f
|
||||
#define UINT8_C(x) x
|
||||
#else
|
||||
#define UINT8_C(x) x##U
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(UINT16_C)
|
||||
#define INT16_C(x) x
|
||||
#if (INT_MAX) > 0x7fff
|
||||
#define UINT16_C(x) x
|
||||
#else
|
||||
#define UINT16_C(x) x##U
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(INT32_C) && !defined(UINT32_C)
|
||||
#if __have_long32
|
||||
#define INT32_C(x) x##L
|
||||
#define UINT32_C(x) x##UL
|
||||
#else
|
||||
#define INT32_C(x) x
|
||||
#define UINT32_C(x) x##U
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(INT64_C) && !defined(UINT64_C)
|
||||
#if __have_long64
|
||||
#define INT64_C(x) x##L
|
||||
#define UINT64_C(x) x##UL
|
||||
#else
|
||||
#define INT64_C(x) x##LL
|
||||
#define UINT64_C(x) x##ULL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*! @name C standard macros */
|
||||
#ifndef NULL
|
||||
#ifdef __cplusplus
|
||||
#define NULL 0
|
||||
#else
|
||||
#define NULL ((void *) 0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
/*! @name Compiler switch macros Definitions */
|
||||
/******************************************************************************/
|
||||
#ifndef BMM150_USE_FLOATING_POINT /*< Check if floating point (using BMM150_USE_FLOATING_POINT) is enabled */
|
||||
#ifndef BMM150_USE_FIXED_POINT /*< If floating point is not enabled then enable BMM150_USE_FIXED_POINT */
|
||||
#define BMM150_USE_FIXED_POINT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
/*! @name General Macro Definitions */
|
||||
/******************************************************************************/
|
||||
/*! @name API success code */
|
||||
#define BMM150_OK INT8_C(0)
|
||||
|
||||
/*! @name To define TRUE or FALSE */
|
||||
#define BMM150_TRUE UINT8_C(1)
|
||||
#define BMM150_FALSE UINT8_C(0)
|
||||
|
||||
/*! @name API error codes */
|
||||
#define BMM150_E_NULL_PTR INT8_C(-1)
|
||||
#define BMM150_E_DEV_NOT_FOUND INT8_C(-2)
|
||||
#define BMM150_E_INVALID_CONFIG INT8_C(-3)
|
||||
#define BMM150_E_COM_FAIL INT8_C(-4)
|
||||
|
||||
/*! @name API warning codes */
|
||||
#define BMM150_W_NORMAL_SELF_TEST_YZ_FAIL INT8_C(1)
|
||||
#define BMM150_W_NORMAL_SELF_TEST_XZ_FAIL INT8_C(2)
|
||||
#define BMM150_W_NORMAL_SELF_TEST_Z_FAIL INT8_C(3)
|
||||
#define BMM150_W_NORMAL_SELF_TEST_XY_FAIL INT8_C(4)
|
||||
#define BMM150_W_NORMAL_SELF_TEST_Y_FAIL INT8_C(5)
|
||||
#define BMM150_W_NORMAL_SELF_TEST_X_FAIL INT8_C(6)
|
||||
#define BMM150_W_NORMAL_SELF_TEST_XYZ_FAIL INT8_C(7)
|
||||
#define BMM150_W_ADV_SELF_TEST_FAIL INT8_C(8)
|
||||
|
||||
/*! @name CHIP ID & SOFT RESET VALUES */
|
||||
#define BMM150_CHIP_ID UINT8_C(0x32)
|
||||
#define BMM150_SET_SOFT_RESET UINT8_C(0x82)
|
||||
|
||||
/*! @name POWER MODE DEFINTIONS */
|
||||
#define BMM150_POWERMODE_NORMAL UINT8_C(0x00)
|
||||
#define BMM150_POWERMODE_FORCED UINT8_C(0x01)
|
||||
#define BMM150_POWERMODE_SLEEP UINT8_C(0x03)
|
||||
#define BMM150_POWERMODE_SUSPEND UINT8_C(0x04)
|
||||
|
||||
/*! @name Power mode settings */
|
||||
#define BMM150_POWER_CNTRL_DISABLE UINT8_C(0x00)
|
||||
#define BMM150_POWER_CNTRL_ENABLE UINT8_C(0x01)
|
||||
|
||||
/*! @name Sensor delay time settings */
|
||||
#define BMM150_DELAY_SOFT_RESET UINT8_C(1000)
|
||||
#define BMM150_DELAY_NORMAL_SELF_TEST UINT8_C(2000)
|
||||
#define BMM150_START_UP_TIME UINT8_C(3000)
|
||||
#define BMM150_DELAY_ADV_SELF_TEST UINT8_C(4000)
|
||||
|
||||
/*! @name ENABLE/DISABLE DEFINITIONS */
|
||||
#define BMM150_XYZ_CHANNEL_ENABLE UINT8_C(0x00)
|
||||
#define BMM150_XYZ_CHANNEL_DISABLE UINT8_C(0x07)
|
||||
|
||||
/*! @name Register Address */
|
||||
#define BMM150_REG_CHIP_ID UINT8_C(0x40)
|
||||
#define BMM150_REG_DATA_X_LSB UINT8_C(0x42)
|
||||
#define BMM150_REG_DATA_READY_STATUS UINT8_C(0x48)
|
||||
#define BMM150_REG_INTERRUPT_STATUS UINT8_C(0x4A)
|
||||
#define BMM150_REG_POWER_CONTROL UINT8_C(0x4B)
|
||||
#define BMM150_REG_OP_MODE UINT8_C(0x4C)
|
||||
#define BMM150_REG_INT_CONFIG UINT8_C(0x4D)
|
||||
#define BMM150_REG_AXES_ENABLE UINT8_C(0x4E)
|
||||
#define BMM150_REG_LOW_THRESHOLD UINT8_C(0x4F)
|
||||
#define BMM150_REG_HIGH_THRESHOLD UINT8_C(0x50)
|
||||
#define BMM150_REG_REP_XY UINT8_C(0x51)
|
||||
#define BMM150_REG_REP_Z UINT8_C(0x52)
|
||||
|
||||
/*! @name Macros to select the sensor settings to be set by the user
|
||||
* These values are internal for API implementation. Don't relate this to
|
||||
* data sheet.
|
||||
*/
|
||||
#define BMM150_SEL_DATA_RATE UINT16_C(1)
|
||||
#define BMM150_SEL_CONTROL_MEASURE UINT16_C(1 << 1)
|
||||
#define BMM150_SEL_XY_REP UINT16_C(1 << 2)
|
||||
#define BMM150_SEL_Z_REP UINT16_C(1 << 3)
|
||||
#define BMM150_SEL_DRDY_PIN_EN UINT16_C(1 << 4)
|
||||
#define BMM150_SEL_INT_PIN_EN UINT16_C(1 << 5)
|
||||
#define BMM150_SEL_DRDY_POLARITY UINT16_C(1 << 6)
|
||||
#define BMM150_SEL_INT_LATCH UINT16_C(1 << 7)
|
||||
#define BMM150_SEL_INT_POLARITY UINT16_C(1 << 8)
|
||||
#define BMM150_SEL_DATA_OVERRUN_INT UINT16_C(1 << 9)
|
||||
#define BMM150_SEL_OVERFLOW_INT UINT16_C(1 << 10)
|
||||
#define BMM150_SEL_HIGH_THRESHOLD_INT UINT16_C(1 << 11)
|
||||
#define BMM150_SEL_LOW_THRESHOLD_INT UINT16_C(1 << 12)
|
||||
#define BMM150_SEL_LOW_THRESHOLD_SETTING UINT16_C(1 << 13)
|
||||
#define BMM150_SEL_HIGH_THRESHOLD_SETTING UINT16_C(1 << 14)
|
||||
|
||||
/*! @name DATA RATE DEFINITIONS */
|
||||
#define BMM150_DATA_RATE_10HZ UINT8_C(0x00)
|
||||
#define BMM150_DATA_RATE_02HZ UINT8_C(0x01)
|
||||
#define BMM150_DATA_RATE_06HZ UINT8_C(0x02)
|
||||
#define BMM150_DATA_RATE_08HZ UINT8_C(0x03)
|
||||
#define BMM150_DATA_RATE_15HZ UINT8_C(0x04)
|
||||
#define BMM150_DATA_RATE_20HZ UINT8_C(0x05)
|
||||
#define BMM150_DATA_RATE_25HZ UINT8_C(0x06)
|
||||
#define BMM150_DATA_RATE_30HZ UINT8_C(0x07)
|
||||
#define BMM150_ODR_MAX UINT8_C(0x07)
|
||||
#define BMM150_ODR_MSK UINT8_C(0x38)
|
||||
#define BMM150_ODR_POS UINT8_C(0x03)
|
||||
|
||||
/*! @name TRIM REGISTERS */
|
||||
/* Trim Extended Registers */
|
||||
#define BMM150_DIG_X1 UINT8_C(0x5D)
|
||||
#define BMM150_DIG_Y1 UINT8_C(0x5E)
|
||||
#define BMM150_DIG_Z4_LSB UINT8_C(0x62)
|
||||
#define BMM150_DIG_Z4_MSB UINT8_C(0x63)
|
||||
#define BMM150_DIG_X2 UINT8_C(0x64)
|
||||
#define BMM150_DIG_Y2 UINT8_C(0x65)
|
||||
#define BMM150_DIG_Z2_LSB UINT8_C(0x68)
|
||||
#define BMM150_DIG_Z2_MSB UINT8_C(0x69)
|
||||
#define BMM150_DIG_Z1_LSB UINT8_C(0x6A)
|
||||
#define BMM150_DIG_Z1_MSB UINT8_C(0x6B)
|
||||
#define BMM150_DIG_XYZ1_LSB UINT8_C(0x6C)
|
||||
#define BMM150_DIG_XYZ1_MSB UINT8_C(0x6D)
|
||||
#define BMM150_DIG_Z3_LSB UINT8_C(0x6E)
|
||||
#define BMM150_DIG_Z3_MSB UINT8_C(0x6F)
|
||||
#define BMM150_DIG_XY2 UINT8_C(0x70)
|
||||
#define BMM150_DIG_XY1 UINT8_C(0x71)
|
||||
|
||||
/*! @name Threshold interrupt setting macros for x,y,z axes selection */
|
||||
#define BMM150_THRESHOLD_X UINT8_C(0x06)
|
||||
#define BMM150_THRESHOLD_Y UINT8_C(0x05)
|
||||
#define BMM150_THRESHOLD_Z UINT8_C(0x03)
|
||||
|
||||
#define BMM150_HIGH_THRESHOLD_INT_MSK UINT8_C(0x38)
|
||||
#define BMM150_HIGH_THRESHOLD_INT_POS UINT8_C(0x03)
|
||||
#define BMM150_LOW_THRESHOLD_INT_MSK UINT8_C(0x07)
|
||||
|
||||
/*! @name User configurable interrupt setting macros */
|
||||
#define BMM150_INT_ENABLE UINT8_C(0x01)
|
||||
#define BMM150_INT_DISABLE UINT8_C(0x00)
|
||||
#define BMM150_ACTIVE_HIGH_POLARITY UINT8_C(0x01)
|
||||
#define BMM150_ACTIVE_LOW_POLARITY UINT8_C(0x00)
|
||||
#define BMM150_LATCHED UINT8_C(0x01)
|
||||
#define BMM150_NON_LATCHED UINT8_C(0x00)
|
||||
|
||||
/*! @name Interrupt status */
|
||||
#define BMM150_INT_THRESHOLD_X_LOW UINT16_C(0x0001)
|
||||
#define BMM150_INT_THRESHOLD_Y_LOW UINT16_C(0x0002)
|
||||
#define BMM150_INT_THRESHOLD_Z_LOW UINT16_C(0x0004)
|
||||
#define BMM150_INT_THRESHOLD_X_HIGH UINT16_C(0x0008)
|
||||
#define BMM150_INT_THRESHOLD_Y_HIGH UINT16_C(0x0010)
|
||||
#define BMM150_INT_THRESHOLD_Z_HIGH UINT16_C(0x0020)
|
||||
#define BMM150_INT_DATA_OVERFLOW UINT16_C(0x0040)
|
||||
#define BMM150_INT_DATA_OVERRUN UINT16_C(0x0080)
|
||||
#define BMM150_INT_DATA_READY UINT16_C(0x0100)
|
||||
|
||||
#define BMM150_DRDY_EN_MSK UINT8_C(0x80)
|
||||
#define BMM150_DRDY_EN_POS UINT8_C(0x07)
|
||||
#define BMM150_DRDY_POLARITY_MSK UINT8_C(0x04)
|
||||
#define BMM150_DRDY_POLARITY_POS UINT8_C(0x02)
|
||||
#define BMM150_INT_PIN_EN_MSK UINT8_C(0x40)
|
||||
#define BMM150_INT_PIN_EN_POS UINT8_C(0x06)
|
||||
#define BMM150_INT_LATCH_MSK UINT8_C(0x02)
|
||||
#define BMM150_INT_LATCH_POS UINT8_C(0x01)
|
||||
#define BMM150_INT_POLARITY_MSK UINT8_C(0x01)
|
||||
#define BMM150_DRDY_STATUS_MSK UINT8_C(0x01)
|
||||
|
||||
/*! @name Interrupt status macros */
|
||||
#define BMM150_INT_ASSERTED_DRDY UINT16_C(0x0100)
|
||||
#define BMM150_INT_ASSERTED_LOW_THRES UINT16_C(0x0007)
|
||||
#define BMM150_INT_ASSERTED_HIGH_THRES UINT16_C(0x0380)
|
||||
|
||||
/*! @name Power control bit macros */
|
||||
#define BMM150_PWR_CNTRL_MSK UINT8_C(0x01)
|
||||
#define BMM150_CONTROL_MEASURE_MSK UINT8_C(0x38)
|
||||
#define BMM150_CONTROL_MEASURE_POS UINT8_C(0x03)
|
||||
#define BMM150_POWER_CONTROL_BIT_MSK UINT8_C(0x01)
|
||||
#define BMM150_POWER_CONTROL_BIT_POS UINT8_C(0x00)
|
||||
|
||||
/*! @name Data macros */
|
||||
#define BMM150_DATA_X_MSK UINT8_C(0xF8)
|
||||
#define BMM150_DATA_X_POS UINT8_C(0x03)
|
||||
|
||||
#define BMM150_DATA_Y_MSK UINT8_C(0xF8)
|
||||
#define BMM150_DATA_Y_POS UINT8_C(0x03)
|
||||
|
||||
#define BMM150_DATA_Z_MSK UINT8_C(0xFE)
|
||||
#define BMM150_DATA_Z_POS UINT8_C(0x01)
|
||||
|
||||
#define BMM150_DATA_RHALL_MSK UINT8_C(0xFC)
|
||||
#define BMM150_DATA_RHALL_POS UINT8_C(0x02)
|
||||
|
||||
#define BMM150_DATA_OVERRUN_INT_MSK UINT8_C(0x80)
|
||||
#define BMM150_DATA_OVERRUN_INT_POS UINT8_C(0x07)
|
||||
|
||||
#define BMM150_OVERFLOW_INT_MSK UINT8_C(0x40)
|
||||
#define BMM150_OVERFLOW_INT_POS UINT8_C(0x06)
|
||||
|
||||
/*! @name OVERFLOW DEFINITIONS */
|
||||
#define BMM150_OVERFLOW_ADCVAL_XYAXES_FLIP INT16_C(-4096)
|
||||
#define BMM150_OVERFLOW_ADCVAL_ZAXIS_HALL INT16_C(-16384)
|
||||
#define BMM150_OVERFLOW_OUTPUT INT16_C(-32768)
|
||||
#define BMM150_NEGATIVE_SATURATION_Z INT16_C(-32767)
|
||||
#define BMM150_POSITIVE_SATURATION_Z INT16_C(32767)
|
||||
#ifdef BMM150_USE_FLOATING_POINT
|
||||
#define BMM150_OVERFLOW_OUTPUT_FLOAT 0.0f
|
||||
#endif
|
||||
|
||||
/*! @name PRESET MODE DEFINITIONS */
|
||||
#define BMM150_PRESETMODE_LOWPOWER UINT8_C(0x01)
|
||||
#define BMM150_PRESETMODE_REGULAR UINT8_C(0x02)
|
||||
#define BMM150_PRESETMODE_HIGHACCURACY UINT8_C(0x03)
|
||||
#define BMM150_PRESETMODE_ENHANCED UINT8_C(0x04)
|
||||
|
||||
#define BMM150_OP_MODE_MSK UINT8_C(0x06)
|
||||
#define BMM150_OP_MODE_POS UINT8_C(0x01)
|
||||
|
||||
/*! @name PRESET MODES - REPETITIONS-XY RATES */
|
||||
#define BMM150_REPXY_LOWPOWER UINT8_C(0x01)
|
||||
#define BMM150_REPXY_REGULAR UINT8_C(0x04)
|
||||
#define BMM150_REPXY_ENHANCED UINT8_C(0x07)
|
||||
#define BMM150_REPXY_HIGHACCURACY UINT8_C(0x17)
|
||||
|
||||
/*! @name PRESET MODES - REPETITIONS-Z RATES */
|
||||
#define BMM150_REPZ_LOWPOWER UINT8_C(0x01)
|
||||
#define BMM150_REPZ_REGULAR UINT8_C(0x07)
|
||||
#define BMM150_REPZ_ENHANCED UINT8_C(0x0D)
|
||||
#define BMM150_REPZ_HIGHACCURACY UINT8_C(0x29)
|
||||
|
||||
/*! @name Self test settings */
|
||||
#define BMM150_DISABLE_XY_AXIS UINT8_C(0x03)
|
||||
#define BMM150_SELF_TEST_REP_Z UINT8_C(0x04)
|
||||
|
||||
/*! @name Self test selection macros */
|
||||
#define BMM150_SELF_TEST_NORMAL UINT8_C(0)
|
||||
#define BMM150_SELF_TEST_ADVANCED UINT8_C(1)
|
||||
|
||||
/*! @name Advanced self-test current settings */
|
||||
#define BMM150_DISABLE_SELF_TEST_CURRENT UINT8_C(0x00)
|
||||
#define BMM150_ENABLE_NEGATIVE_CURRENT UINT8_C(0x02)
|
||||
#define BMM150_ENABLE_POSITIVE_CURRENT UINT8_C(0x03)
|
||||
|
||||
/*! @name Normal self-test status */
|
||||
#define BMM150_SELF_TEST_STATUS_XYZ_FAIL UINT8_C(0x00)
|
||||
#define BMM150_SELF_TEST_STATUS_SUCCESS UINT8_C(0x07)
|
||||
|
||||
#define BMM150_SELF_TEST_MSK UINT8_C(0x01)
|
||||
#define BMM150_ADV_SELF_TEST_MSK UINT8_C(0xC0)
|
||||
#define BMM150_ADV_SELF_TEST_POS UINT8_C(0x06)
|
||||
|
||||
/*! @name Register read lengths */
|
||||
#define BMM150_LEN_SELF_TEST UINT8_C(5)
|
||||
#define BMM150_LEN_SETTING_DATA UINT8_C(8)
|
||||
#define BMM150_LEN_XYZR_DATA UINT8_C(8)
|
||||
|
||||
/*! @name Boundary check macros */
|
||||
#define BMM150_BOUNDARY_MAXIMUM UINT8_C(0)
|
||||
#define BMM150_BOUNDARY_MINIMUM UINT8_C(1)
|
||||
|
||||
/*! @name Macro to SET and GET BITS of a register*/
|
||||
#define BMM150_SET_BITS(reg_data, bitname, data) \
|
||||
((reg_data & ~(bitname##_MSK)) | \
|
||||
((data << bitname##_POS) & bitname##_MSK))
|
||||
|
||||
#define BMM150_GET_BITS(reg_data, bitname) ((reg_data & (bitname##_MSK)) >> \
|
||||
(bitname##_POS))
|
||||
|
||||
#define BMM150_SET_BITS_POS_0(reg_data, bitname, data) \
|
||||
((reg_data & ~(bitname##_MSK)) | \
|
||||
(data & bitname##_MSK))
|
||||
|
||||
#define BMM150_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
|
||||
|
||||
/********************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Interface selection Enums
|
||||
*/
|
||||
enum bmm150_intf {
|
||||
/*! SPI interface */
|
||||
BMM150_SPI_INTF,
|
||||
/*! I2C interface */
|
||||
BMM150_I2C_INTF
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
/*! @name Function Pointers */
|
||||
/******************************************************************************/
|
||||
#ifndef BMM150_INTF_RET_TYPE
|
||||
#define BMM150_INTF_RET_TYPE int8_t
|
||||
#endif
|
||||
|
||||
#ifndef BMM150_INTF_RET_SUCCESS
|
||||
#define BMM150_INTF_RET_SUCCESS INT8_C(0)
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Bus communication function pointer which should be mapped to
|
||||
* the platform specific read functions of the user
|
||||
*
|
||||
* @param[in] reg_addr : 8bit register address of the sensor
|
||||
* @param[out] reg_data : Data from the specified address
|
||||
* @param[in] length : Length of the reg_data array
|
||||
* @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors
|
||||
* for interface related callbacks
|
||||
* @retval 0 for Success
|
||||
* @retval Non-zero for Failure
|
||||
*/
|
||||
typedef BMM150_INTF_RET_TYPE (*bmm150_read_fptr_t)(uint8_t reg_addr, uint8_t *reg_data, uint32_t length,
|
||||
void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Bus communication function pointer which should be mapped to
|
||||
* the platform specific write functions of the user
|
||||
*
|
||||
* @param[in] reg_addr : 8bit register address of the sensor
|
||||
* @param[out] reg_data : Data to the specified address
|
||||
* @param[in] length : Length of the reg_data array
|
||||
* @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors
|
||||
* for interface related callbacks
|
||||
* @retval 0 for Success
|
||||
* @retval Non-zero for Failure
|
||||
*
|
||||
*/
|
||||
typedef BMM150_INTF_RET_TYPE (*bmm150_write_fptr_t)(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length,
|
||||
void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Delay function pointer which should be mapped to
|
||||
* delay function of the user
|
||||
*
|
||||
* @param period : The time period in microseconds
|
||||
* @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors
|
||||
* for interface related callbacks
|
||||
*/
|
||||
typedef void (*bmm150_delay_us_fptr_t)(uint32_t period, void *intf_ptr);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! @name Structure Declarations */
|
||||
/******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief bmm150 trim data structure
|
||||
*/
|
||||
struct bmm150_trim_registers {
|
||||
/*! trim x1 data */
|
||||
int8_t dig_x1;
|
||||
|
||||
/*! trim y1 data */
|
||||
int8_t dig_y1;
|
||||
|
||||
/*! trim x2 data */
|
||||
int8_t dig_x2;
|
||||
|
||||
/*! trim y2 data */
|
||||
int8_t dig_y2;
|
||||
|
||||
/*! trim z1 data */
|
||||
uint16_t dig_z1;
|
||||
|
||||
/*! trim z2 data */
|
||||
int16_t dig_z2;
|
||||
|
||||
/*! trim z3 data */
|
||||
int16_t dig_z3;
|
||||
|
||||
/*! trim z4 data */
|
||||
int16_t dig_z4;
|
||||
|
||||
/*! trim xy1 data */
|
||||
uint8_t dig_xy1;
|
||||
|
||||
/*! trim xy2 data */
|
||||
int8_t dig_xy2;
|
||||
|
||||
/*! trim xyz1 data */
|
||||
uint16_t dig_xyz1;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief bmm150 interrupt pin settings
|
||||
*/
|
||||
struct bmm150_int_ctrl_settings {
|
||||
/*! Data ready interrupt enable */
|
||||
uint8_t drdy_pin_en;
|
||||
|
||||
/*! Threshold and overflow interrupts enable */
|
||||
uint8_t int_pin_en;
|
||||
|
||||
/*! Data ready interrupt polarity Active high/low */
|
||||
uint8_t drdy_polarity;
|
||||
|
||||
/*! Interrupt pin - Latched or Non-latched */
|
||||
uint8_t int_latch;
|
||||
|
||||
/*! Interrupt polarity Active high/low */
|
||||
uint8_t int_polarity;
|
||||
|
||||
/*! Data overrun interrupt enable */
|
||||
uint8_t data_overrun_en;
|
||||
|
||||
/*! Overflow interrupt enable */
|
||||
uint8_t overflow_int_en;
|
||||
|
||||
/*! high interrupt enable/disable axis selection */
|
||||
uint8_t high_int_en;
|
||||
|
||||
/*! low interrupt enable/disable axis selection */
|
||||
uint8_t low_int_en;
|
||||
|
||||
/*! low threshold limit */
|
||||
uint8_t low_threshold;
|
||||
|
||||
/*! high threshold limit */
|
||||
uint8_t high_threshold;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief bmm150 sensor settings
|
||||
*/
|
||||
struct bmm150_settings {
|
||||
/*! Control measurement of XYZ axes */
|
||||
uint8_t xyz_axes_control;
|
||||
|
||||
/*! Power mode of sensor */
|
||||
uint8_t pwr_mode;
|
||||
|
||||
/*! Data rate value (ODR) */
|
||||
uint8_t data_rate;
|
||||
|
||||
/*! XY Repetitions */
|
||||
uint8_t xy_rep;
|
||||
|
||||
/*! Z Repetitions */
|
||||
uint8_t z_rep;
|
||||
|
||||
/*! Preset mode of sensor */
|
||||
uint8_t preset_mode;
|
||||
|
||||
/*! Interrupt configuration settings */
|
||||
struct bmm150_int_ctrl_settings int_settings;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief bmm150 un-compensated (raw) magnetometer data
|
||||
*/
|
||||
struct bmm150_raw_mag_data {
|
||||
/*! Raw mag X data */
|
||||
int16_t raw_datax;
|
||||
|
||||
/*! Raw mag Y data */
|
||||
int16_t raw_datay;
|
||||
|
||||
/*! Raw mag Z data */
|
||||
int16_t raw_dataz;
|
||||
|
||||
/*! Raw mag resistance value */
|
||||
uint16_t raw_data_r;
|
||||
};
|
||||
|
||||
#ifdef BMM150_USE_FLOATING_POINT
|
||||
|
||||
/*!
|
||||
* @brief bmm150 compensated magnetometer data in float
|
||||
*/
|
||||
struct bmm150_mag_data {
|
||||
/*! compensated mag X data */
|
||||
float x;
|
||||
|
||||
/*! compensated mag Y data */
|
||||
float y;
|
||||
|
||||
/*! compensated mag Z data */
|
||||
float z;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
/*!
|
||||
* @brief bmm150 compensated magnetometer data in int16_t format
|
||||
*/
|
||||
struct bmm150_mag_data {
|
||||
/*! compensated mag X data */
|
||||
int16_t x;
|
||||
|
||||
/*! compensated mag Y data */
|
||||
int16_t y;
|
||||
|
||||
/*! compensated mag Z data */
|
||||
int16_t z;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief bmm150 device structure
|
||||
*/
|
||||
struct bmm150_dev {
|
||||
/*! Chip Id */
|
||||
uint8_t chip_id;
|
||||
|
||||
/*! SPI/I2C Interface */
|
||||
enum bmm150_intf intf;
|
||||
|
||||
/*!
|
||||
* The interface pointer is used to enable the user
|
||||
* to link their interface descriptors for reference during the
|
||||
* implementation of the read and write interfaces to the
|
||||
* hardware.
|
||||
*/
|
||||
void *intf_ptr;
|
||||
|
||||
/*! Variable that holds result of read/write function */
|
||||
BMM150_INTF_RET_TYPE intf_rslt;
|
||||
|
||||
/*! Bus read function pointer */
|
||||
bmm150_read_fptr_t read;
|
||||
|
||||
/*! Bus write function pointer */
|
||||
bmm150_write_fptr_t write;
|
||||
|
||||
/*! delay(in us) function pointer */
|
||||
bmm150_delay_us_fptr_t delay_us;
|
||||
|
||||
/*! Trim registers */
|
||||
struct bmm150_trim_registers trim_data;
|
||||
|
||||
/*! Interrupt status */
|
||||
uint16_t int_status;
|
||||
|
||||
/*! Power control bit value */
|
||||
uint8_t pwr_cntrl_bit;
|
||||
};
|
||||
|
||||
#endif /* BMM150_DEFS_H_ */
|
||||
@@ -0,0 +1,181 @@
|
||||
/**
|
||||
*
|
||||
* @license MIT License
|
||||
*
|
||||
* Copyright (c) 2022 lewis he
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @file BoschParse.cpp
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2023-09-30
|
||||
*
|
||||
*/
|
||||
#include "BoschParse.h"
|
||||
|
||||
std::vector<SensorEventCbList_t> BoschParse::bhyEventVector;
|
||||
std::vector<ParseCallBackList_t> BoschParse::bhyParseEventVector;
|
||||
uint8_t SensorEventCbList::current_id = 1;
|
||||
uint8_t ParseCallBackList::current_id = 1;
|
||||
|
||||
void BoschParse::parseData(const struct bhy2_fifo_parse_data_info *fifo, void *user_data)
|
||||
{
|
||||
int8_t size = fifo->data_size - 1;
|
||||
|
||||
#ifdef LOG_PORT
|
||||
LOG_PORT.print("Sensor: ");
|
||||
LOG_PORT.print(fifo->sensor_id);
|
||||
LOG_PORT.print(" size: ");
|
||||
LOG_PORT.print(fifo->data_size);
|
||||
LOG_PORT.print(" value:");
|
||||
for (uint8_t i = 0; i < size; i++) {
|
||||
LOG_PORT.printf("%04x", fifo->data_ptr[i]);
|
||||
LOG_PORT.print(" ");
|
||||
}
|
||||
LOG_PORT.println();
|
||||
#endif
|
||||
|
||||
for (uint32_t i = 0; i < bhyParseEventVector.size(); i++) {
|
||||
ParseCallBackList_t entry = bhyParseEventVector[i];
|
||||
if (entry.cb ) {
|
||||
if (entry.id == fifo->sensor_id) {
|
||||
if (entry.cb) {
|
||||
entry.cb(fifo->sensor_id, fifo->data_ptr, size, fifo->time_stamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BoschParse::parseMetaEvent(const struct bhy2_fifo_parse_data_info *callback_info, void *user_data)
|
||||
{
|
||||
(void)user_data;
|
||||
|
||||
uint8_t meta_event_type = callback_info->data_ptr[0];
|
||||
uint8_t byte1 = callback_info->data_ptr[1];
|
||||
uint8_t byte2 = callback_info->data_ptr[2];
|
||||
const char *event_text;
|
||||
// Remove warning
|
||||
(void)byte1;
|
||||
(void)byte2;
|
||||
(void)event_text;
|
||||
uint8_t *accuracy = (uint8_t *)user_data;
|
||||
|
||||
if (callback_info->sensor_id == BHY2_SYS_ID_META_EVENT) {
|
||||
event_text = "[META EVENT]";
|
||||
} else if (callback_info->sensor_id == BHY2_SYS_ID_META_EVENT_WU) {
|
||||
event_text = "[META EVENT WAKE UP]";
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (meta_event_type) {
|
||||
case BHY2_META_EVENT_FLUSH_COMPLETE:
|
||||
log_i("%s Flush complete for sensor id %u", event_text, byte1);
|
||||
break;
|
||||
case BHY2_META_EVENT_SAMPLE_RATE_CHANGED:
|
||||
log_i("%s Sample rate changed for sensor id %u", event_text, byte1);
|
||||
break;
|
||||
case BHY2_META_EVENT_POWER_MODE_CHANGED:
|
||||
log_i("%s Power mode changed for sensor id %u", event_text, byte1);
|
||||
break;
|
||||
case BHY2_META_EVENT_ALGORITHM_EVENTS:
|
||||
log_i("%s Algorithm event", event_text);
|
||||
break;
|
||||
case BHY2_META_EVENT_SENSOR_STATUS:
|
||||
log_i("%s Accuracy for sensor id %u changed to %u", event_text, byte1, byte2);
|
||||
if (accuracy) {
|
||||
*accuracy = byte2;
|
||||
}
|
||||
break;
|
||||
case BHY2_META_EVENT_BSX_DO_STEPS_MAIN:
|
||||
log_i("%s BSX event (do steps main)", event_text);
|
||||
break;
|
||||
case BHY2_META_EVENT_BSX_DO_STEPS_CALIB:
|
||||
log_i("%s BSX event (do steps calib)", event_text);
|
||||
break;
|
||||
case BHY2_META_EVENT_BSX_GET_OUTPUT_SIGNAL:
|
||||
log_i("%s BSX event (get output signal)", event_text);
|
||||
break;
|
||||
case BHY2_META_EVENT_SENSOR_ERROR:
|
||||
log_i("%s Sensor id %u reported error 0x%02X", event_text, byte1, byte2);
|
||||
break;
|
||||
case BHY2_META_EVENT_FIFO_OVERFLOW:
|
||||
log_i("%s FIFO overflow", event_text);
|
||||
break;
|
||||
case BHY2_META_EVENT_DYNAMIC_RANGE_CHANGED:
|
||||
log_i("%s Dynamic range changed for sensor id %u", event_text, byte1);
|
||||
break;
|
||||
case BHY2_META_EVENT_FIFO_WATERMARK:
|
||||
log_i("%s FIFO watermark reached", event_text);
|
||||
break;
|
||||
case BHY2_META_EVENT_INITIALIZED:
|
||||
log_i("%s Firmware initialized. Firmware version %u", event_text, ((uint16_t)byte2 << 8) | byte1);
|
||||
break;
|
||||
case BHY2_META_TRANSFER_CAUSE:
|
||||
log_i("%s Transfer cause for sensor id %u", event_text, byte1);
|
||||
break;
|
||||
case BHY2_META_EVENT_SENSOR_FRAMEWORK:
|
||||
log_i("%s Sensor framework event for sensor id %u", event_text, byte1);
|
||||
break;
|
||||
case BHY2_META_EVENT_RESET:
|
||||
log_i("%s Reset event", event_text);
|
||||
break;
|
||||
case BHY2_META_EVENT_SPACER:
|
||||
return;
|
||||
default:
|
||||
log_i("%s Unknown meta event with id: %u", event_text, meta_event_type);
|
||||
break;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < bhyEventVector.size(); i++) {
|
||||
SensorEventCbList_t entry = bhyEventVector[i];
|
||||
if (entry.cb ) {
|
||||
if (entry.event == meta_event_type) {
|
||||
if (entry.cb) {
|
||||
entry.cb(meta_event_type, callback_info->data_ptr, callback_info->data_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BoschParse::parseDebugMessage(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref)
|
||||
{
|
||||
uint32_t s, ns;
|
||||
uint64_t tns;
|
||||
uint8_t msg_length = 0;
|
||||
uint8_t debug_msg[17] = { 0 }; /* Max payload size is 16 bytes, adds a trailing zero if the payload is full */
|
||||
|
||||
if (!callback_info) {
|
||||
log_i("Null reference");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
time_to_s_ns(*callback_info->time_stamp, &s, &ns, &tns);
|
||||
|
||||
msg_length = callback_info->data_ptr[0];
|
||||
|
||||
memcpy(debug_msg, &callback_info->data_ptr[1], msg_length);
|
||||
debug_msg[msg_length] = '\0'; /* Terminate the string */
|
||||
|
||||
log_i("[DEBUG MSG]; T: %lu.%09lu; %s", s, ns, debug_msg);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
*
|
||||
* @license MIT License
|
||||
*
|
||||
* Copyright (c) 2022 lewis he
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @file BoschParse.h
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2023-09-30
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "SensorCommon.tpp"
|
||||
#include "SensorBhy2Define.h"
|
||||
#include "bosch/bhy2_parse.h"
|
||||
#include "bosch/common/common.h"
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
|
||||
enum BoschOrientation {
|
||||
BHY2_DIRECTION_TOP_RIGHT,
|
||||
BHY2_DIRECTION_TOP_LEFT,
|
||||
BHY2_DIRECTION_BOTTOM_LEFT,
|
||||
BHY2_DIRECTION_BOTTOM_RIGHT,
|
||||
};
|
||||
|
||||
class BoschParse
|
||||
{
|
||||
public:
|
||||
static std::vector<SensorEventCbList_t> bhyEventVector;
|
||||
static std::vector<ParseCallBackList_t> bhyParseEventVector;
|
||||
|
||||
static void parseData(const struct bhy2_fifo_parse_data_info *fifo, void *user_data);
|
||||
|
||||
static void parseMetaEvent(const struct bhy2_fifo_parse_data_info *callback_info, void *user_data);
|
||||
|
||||
static void parseDebugMessage(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref);
|
||||
};
|
||||
@@ -0,0 +1,203 @@
|
||||
/**
|
||||
*
|
||||
* @license MIT License
|
||||
*
|
||||
* Copyright (c) 2022 lewis he
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @file SensorBhy2Define.h
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2023-09-30
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define BHI260AP_SLAVE_ADDRESS_L 0x28
|
||||
#define BHI260AP_SLAVE_ADDRESS_H 0x29
|
||||
#define BHY_PROCESS_BUFFER_SIZE 512
|
||||
|
||||
#define BHY2_RLST_CHECK(ret, str, val) \
|
||||
do \
|
||||
{ \
|
||||
if (ret) \
|
||||
{ \
|
||||
log_e(str); \
|
||||
return val; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
typedef void (*BhyEventCb)(uint8_t event, uint8_t *data, uint32_t size);
|
||||
typedef void (*BhyParseDataCallback)(uint8_t sensor_id, uint8_t *data, uint32_t size,uint64_t *timestamp);
|
||||
|
||||
|
||||
|
||||
typedef struct SensorEventCbList {
|
||||
static uint8_t current_id;
|
||||
uint8_t id;
|
||||
BhyEventCb cb;
|
||||
uint8_t event;
|
||||
uint8_t *data;
|
||||
SensorEventCbList() : id(current_id++), cb(NULL), event(0), data(NULL)
|
||||
{
|
||||
}
|
||||
} SensorEventCbList_t;
|
||||
|
||||
|
||||
typedef struct ParseCallBackList {
|
||||
static uint8_t current_id;
|
||||
uint8_t id;
|
||||
BhyParseDataCallback cb;
|
||||
uint32_t data_length;
|
||||
uint8_t *data;
|
||||
ParseCallBackList() : id(current_id++), cb(NULL), data_length(0), data(NULL)
|
||||
{
|
||||
}
|
||||
} ParseCallBackList_t;
|
||||
|
||||
enum BhySensorEvent {
|
||||
BHY2_EVENT_FLUSH_COMPLETE = 1,
|
||||
BHY2_EVENT_SAMPLE_RATE_CHANGED,
|
||||
BHY2_EVENT_POWER_MODE_CHANGED,
|
||||
BHY2_EVENT_ALGORITHM_EVENTS = 5,
|
||||
BHY2_EVENT_SENSOR_STATUS,
|
||||
BHY2_EVENT_BSX_DO_STEPS_MAIN,
|
||||
BHY2_EVENT_BSX_DO_STEPS_CALIB,
|
||||
BHY2_EVENT_BSX_GET_OUTPUT_SIGNAL,
|
||||
BHY2_EVENT_SENSOR_ERROR = 11,
|
||||
BHY2_EVENT_FIFO_OVERFLOW,
|
||||
BHY2_EVENT_DYNAMIC_RANGE_CHANGED,
|
||||
BHY2_EVENT_FIFO_WATERMARK,
|
||||
BHY2_EVENT_INITIALIZED = 16,
|
||||
BHY2_EVENT_TRANSFER_CAUSE,
|
||||
BHY2_EVENT_SENSOR_FRAMEWORK,
|
||||
BHY2_EVENT_RESET,
|
||||
};
|
||||
|
||||
|
||||
enum BhySensorID {
|
||||
SENSOR_ID_ACC_PASS = 1, /* Accelerometer passthrough */
|
||||
SENSOR_ID_ACC_RAW = 3, /* Accelerometer uncalibrated */
|
||||
SENSOR_ID_ACC = 4, /* Accelerometer corrected */
|
||||
SENSOR_ID_ACC_BIAS = 5, /* Accelerometer offset */
|
||||
SENSOR_ID_ACC_WU = 6, /* Accelerometer corrected wake up */
|
||||
SENSOR_ID_ACC_RAW_WU = 7, /* Accelerometer uncalibrated wake up */
|
||||
SENSOR_ID_GYRO_PASS = 10, /* Gyroscope passthrough */
|
||||
SENSOR_ID_GYRO_RAW = 12, /* Gyroscope uncalibrated */
|
||||
SENSOR_ID_GYRO = 13, /* Gyroscope corrected */
|
||||
SENSOR_ID_GYRO_BIAS = 14, /* Gyroscope offset */
|
||||
SENSOR_ID_GYRO_WU = 15, /* Gyroscope wake up */
|
||||
SENSOR_ID_GYRO_RAW_WU = 16, /* Gyroscope uncalibrated wake up */
|
||||
SENSOR_ID_MAG_PASS = 19, /* Magnetometer passthrough */
|
||||
SENSOR_ID_MAG_RAW = 21, /* Magnetometer uncalibrated */
|
||||
SENSOR_ID_MAG = 22, /* Magnetometer corrected */
|
||||
SENSOR_ID_MAG_BIAS = 23, /* Magnetometer offset */
|
||||
SENSOR_ID_MAG_WU = 24, /* Magnetometer wake up */
|
||||
SENSOR_ID_MAG_RAW_WU = 25, /* Magnetometer uncalibrated wake up */
|
||||
SENSOR_ID_GRA = 28, /* Gravity vector */
|
||||
SENSOR_ID_GRA_WU = 29, /* Gravity vector wake up */
|
||||
SENSOR_ID_LACC = 31, /* Linear acceleration */
|
||||
SENSOR_ID_LACC_WU = 32, /* Linear acceleration wake up */
|
||||
SENSOR_ID_RV = 34, /* Rotation vector */
|
||||
SENSOR_ID_RV_WU = 35, /* Rotation vector wake up */
|
||||
SENSOR_ID_GAMERV = 37, /* Game rotation vector */
|
||||
SENSOR_ID_GAMERV_WU = 38, /* Game rotation vector wake up */
|
||||
SENSOR_ID_GEORV = 40, /* Geo-magnetic rotation vector */
|
||||
SENSOR_ID_GEORV_WU = 41, /* Geo-magnetic rotation vector wake up */
|
||||
SENSOR_ID_ORI = 43, /* Orientation */
|
||||
SENSOR_ID_ORI_WU = 44, /* Orientation wake up */
|
||||
SENSOR_ID_TILT_DETECTOR = 48, /* Tilt detector */
|
||||
SENSOR_ID_STD = 50, /* Step detector */
|
||||
SENSOR_ID_STC = 52, /* Step counter */
|
||||
SENSOR_ID_STC_WU = 53, /* Step counter wake up */
|
||||
SENSOR_ID_SIG = 55, /* Significant motion */
|
||||
SENSOR_ID_WAKE_GESTURE = 57, /* Wake gesture */
|
||||
SENSOR_ID_GLANCE_GESTURE = 59, /* Glance gesture */
|
||||
SENSOR_ID_PICKUP_GESTURE = 61, /* Pickup gesture */
|
||||
SENSOR_ID_AR = 63, /* Activity recognition */
|
||||
SENSOR_ID_WRIST_TILT_GESTURE = 67, /* Wrist tilt gesture */
|
||||
SENSOR_ID_DEVICE_ORI = 69, /* Device orientation */
|
||||
SENSOR_ID_DEVICE_ORI_WU = 70, /* Device orientation wake up */
|
||||
SENSOR_ID_STATIONARY_DET = 75, /* Stationary detect */
|
||||
SENSOR_ID_MOTION_DET = 77, /* Motion detect */
|
||||
SENSOR_ID_ACC_BIAS_WU = 91, /* Accelerometer offset wake up */
|
||||
SENSOR_ID_GYRO_BIAS_WU = 92, /* Gyroscope offset wake up */
|
||||
SENSOR_ID_MAG_BIAS_WU = 93, /* Magnetometer offset wake up */
|
||||
SENSOR_ID_STD_WU = 94, /* Step detector wake up */
|
||||
SENSOR_ID_BSEC = 115, /* BSEC 1.x output */
|
||||
SENSOR_ID_TEMP = 128, /* Temperature */
|
||||
SENSOR_ID_BARO = 129, /* Barometer */
|
||||
SENSOR_ID_HUM = 130, /* Humidity */
|
||||
SENSOR_ID_GAS = 131, /* Gas */
|
||||
SENSOR_ID_TEMP_WU = 132, /* Temperature wake up */
|
||||
SENSOR_ID_BARO_WU = 133, /* Barometer wake up */
|
||||
SENSOR_ID_HUM_WU = 134, /* Humidity wake up */
|
||||
SENSOR_ID_GAS_WU = 135, /* Gas wake up */
|
||||
SENSOR_ID_STC_HW = 136, /* Hardware Step counter */
|
||||
SENSOR_ID_STD_HW = 137, /* Hardware Step detector */
|
||||
SENSOR_ID_SIG_HW = 138, /* Hardware Significant motion */
|
||||
SENSOR_ID_STC_HW_WU = 139, /* Hardware Step counter wake up */
|
||||
SENSOR_ID_STD_HW_WU = 140, /* Hardware Step detector wake up */
|
||||
SENSOR_ID_SIG_HW_WU = 141, /* Hardware Significant motion wake up */
|
||||
SENSOR_ID_ANY_MOTION = 142, /* Any motion */
|
||||
SENSOR_ID_ANY_MOTION_WU = 143, /* Any motion wake up */
|
||||
SENSOR_ID_EXCAMERA = 144, /* External camera trigger */
|
||||
SENSOR_ID_GPS = 145, /* GPS */
|
||||
SENSOR_ID_LIGHT = 146, /* Light */
|
||||
SENSOR_ID_PROX = 147, /* Proximity */
|
||||
SENSOR_ID_LIGHT_WU = 148, /* Light wake up */
|
||||
SENSOR_ID_PROX_WU = 149, /* Proximity wake up */
|
||||
SENSOR_ID_BSEC_LEGACY = 171, /* BSEC 1.x output (legacy, deprecated) */
|
||||
SENSOR_DEBUG_DATA_EVENT = 250, /* Binary or string debug data */
|
||||
SENSOR_TIMESTAMP_SMALL_DELTA = 251, /* Incremental time change from previous read */
|
||||
SENSOR_TIMESTAMP_SMALL_DELTA_WU = 245, /* Incremental time change from previous read wake up */
|
||||
SENSOR_TIMESTAMP_LARGE_DELTA = 252, /* Incremental time change from previous read */
|
||||
SENSOR_TIMESTAMP_LARGE_DELTA_WU = 246, /* Incremental time change from previous read wake up */
|
||||
SENSOR_TIMESTAMP_FULL = 253, /* Incremental time change from previous read */
|
||||
SENSOR_TIMESTAMP_FULL_WU = 247, /* Incremental time change from previous read wake up */
|
||||
SENSOR_ALL_ID = 255 /* All Sensor parse event*/
|
||||
};
|
||||
|
||||
|
||||
#define SENSOR_EULER_ID SENSOR_ID_ORI_WU
|
||||
#define QUAT_SENSOR_ID SENSOR_ID_RV
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,730 @@
|
||||
/**
|
||||
* 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 bhi3.c
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************************************************************/
|
||||
/* system header files */
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*********************************************************************/
|
||||
/* BHI3 SensorAPI header files */
|
||||
#include "bhi3.h"
|
||||
|
||||
/*************************Private Functions***************************/
|
||||
|
||||
/*!
|
||||
* @brief To set the Physical Sensor Control Parameters
|
||||
*/
|
||||
int8_t bhi3_physical_sensor_control_set_config(uint8_t sensor_id,
|
||||
const uint8_t *payload,
|
||||
uint16_t len,
|
||||
uint8_t control_code,
|
||||
struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
uint16_t cmnd_len = BHY2_LE24MUL(len + 1); /*1 byte added for control code */
|
||||
uint8_t cmnd[cmnd_len];
|
||||
|
||||
memset(cmnd, 0, cmnd_len);
|
||||
cmnd[0] = BHI3_PHY_SENSOR_CTRL_CODE(BHI3_PHY_SENSOR_CTRL_WRITE, control_code);
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (payload == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
cmnd[i + 1] = *(payload + i);
|
||||
}
|
||||
|
||||
rslt = bhy2_set_parameter(BHI3_PHY_SENSOR_CTRL_PARAM(sensor_id), cmnd, cmnd_len, dev);
|
||||
}
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the Physical Sensor Control Parameters
|
||||
*/
|
||||
int8_t bhi3_physical_sensor_control_get_config(uint8_t sensor_id,
|
||||
uint8_t *payload,
|
||||
uint32_t len,
|
||||
uint8_t control_code,
|
||||
struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
uint32_t ret_len = 0;
|
||||
|
||||
uint8_t cmnd[BHY2_COMMAND_HEADER_LEN] = {0};
|
||||
uint8_t rdbck[BHY2_LE24MUL(len)];
|
||||
|
||||
cmnd[0] = BHI3_PHY_SENSOR_CTRL_CODE(BHI3_PHY_SENSOR_CTRL_READ, control_code);
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
rslt = bhy2_set_parameter(BHI3_PHY_SENSOR_CTRL_PARAM(sensor_id), cmnd, BHY2_COMMAND_HEADER_LEN, dev);
|
||||
if (rslt != BHY2_OK)
|
||||
{
|
||||
return rslt;
|
||||
}
|
||||
|
||||
rslt = bhy2_get_parameter(BHI3_PHY_SENSOR_CTRL_PARAM(sensor_id), rdbck, BHY2_LE24MUL(len), &ret_len, dev);
|
||||
if (rslt != BHY2_OK)
|
||||
{
|
||||
return rslt;
|
||||
}
|
||||
|
||||
memcpy(payload, &rdbck[1], len); /*0th element holds control code */
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/**************************Public Functions***************************/
|
||||
|
||||
/*!
|
||||
* @brief To parse Wrist Gesture Detection Data
|
||||
*/
|
||||
int8_t bhi3_wrist_gesture_detect_parse_data(const uint8_t *data, bhi3_wrist_gesture_detect_t *output)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if ((data == NULL) || (output == NULL))
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
output->wrist_gesture = (enum bhi3_wrist_gesture_activity) * (data);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To set the Accelerometer Fast Offset Calibration
|
||||
*/
|
||||
int8_t bhi3_set_acc_foc(const struct bhy2_data_xyz *acc_foc, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Set the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_ACCELEROMETER,
|
||||
(uint8_t *)acc_foc,
|
||||
BHI3_PHY_ACC_FOC_CTRL_LEN,
|
||||
BHI3_PHY_ACC_FOC_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the Accelerometer Fast Offset Calibration
|
||||
*/
|
||||
int8_t bhi3_get_acc_foc(struct bhy2_data_xyz *acc_foc, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Get the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_ACCELEROMETER,
|
||||
(uint8_t *)acc_foc,
|
||||
BHI3_PHY_ACC_FOC_CTRL_LEN,
|
||||
BHI3_PHY_ACC_FOC_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To set the Accelerometer Power Mode
|
||||
*/
|
||||
int8_t bhi3_set_acc_power_mode(const uint8_t *acc_pwm, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Set the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_ACCELEROMETER,
|
||||
acc_pwm,
|
||||
BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_LEN,
|
||||
BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the Accelerometer Power Mode
|
||||
*/
|
||||
int8_t bhi3_get_acc_power_mode(uint8_t *acc_pwm, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Get the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_ACCELEROMETER,
|
||||
acc_pwm,
|
||||
BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_LEN,
|
||||
BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To set the Gyroscope Fast Offset Calibration
|
||||
*/
|
||||
int8_t bhi3_set_gyro_foc(const struct bhy2_data_xyz *gyro_foc, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Set the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
|
||||
(uint8_t *)gyro_foc,
|
||||
BHI3_PHY_GYRO_FOC_CTRL_LEN,
|
||||
BHI3_PHY_GYRO_FOC_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the Gyroscope Fast Offset Calibration
|
||||
*/
|
||||
int8_t bhi3_get_gyro_foc(struct bhy2_data_xyz *gyro_foc, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Get the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
|
||||
(uint8_t *)gyro_foc,
|
||||
BHI3_PHY_GYRO_FOC_CTRL_LEN,
|
||||
BHI3_PHY_GYRO_FOC_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To set the Gyroscope OIS
|
||||
*/
|
||||
int8_t bhi3_set_gyro_ois(const uint8_t *gyro_ois, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Set the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
|
||||
gyro_ois,
|
||||
BHI3_PHY_GYRO_OIS_CTRL_LEN,
|
||||
BHI3_PHY_GYRO_OIS_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the Gyroscope OIS
|
||||
*/
|
||||
int8_t bhi3_get_gyro_ois(uint8_t *gyro_ois, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Get the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
|
||||
gyro_ois,
|
||||
BHI3_PHY_GYRO_OIS_CTRL_LEN,
|
||||
BHI3_PHY_GYRO_OIS_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To set the Gyroscope Fast Startup
|
||||
*/
|
||||
int8_t bhi3_set_gyro_fast_startup(const uint8_t *gyro_fs, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Set the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
|
||||
gyro_fs,
|
||||
BHI3_PHY_GYRO_FAST_STARTUP_CTRL_LEN,
|
||||
BHI3_PHY_GYRO_FAST_STARTUP_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the Gyroscope Fast Startup
|
||||
*/
|
||||
int8_t bhi3_get_gyro_fast_startup(uint8_t *gyro_fs, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Get the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
|
||||
gyro_fs,
|
||||
BHI3_PHY_GYRO_FAST_STARTUP_CTRL_LEN,
|
||||
BHI3_PHY_GYRO_FAST_STARTUP_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To set the Gyroscope CRT
|
||||
*/
|
||||
int8_t bhi3_set_gyro_crt(const uint8_t *gyro_crt, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Set the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
|
||||
gyro_crt,
|
||||
BHI3_PHY_GYRO_CRT_CTRL_LEN,
|
||||
BHI3_PHY_GYRO_CRT_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the Gyroscope CRT
|
||||
*/
|
||||
|
||||
/*lint -e506, -e778 */
|
||||
int8_t bhi3_get_gyro_crt(uint8_t *gyro_crt, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Get the configuration parameter */
|
||||
rslt =
|
||||
bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
|
||||
gyro_crt,
|
||||
BHY2_LE24MUL(BHI3_PHY_GYRO_CRT_CTRL_LEN),
|
||||
BHI3_PHY_GYRO_CRT_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To set the Gyroscope Power Mode
|
||||
*/
|
||||
int8_t bhi3_set_gyro_power_mode(const uint8_t *gyro_pwm, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Set the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
|
||||
gyro_pwm,
|
||||
BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_LEN,
|
||||
BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the Gyroscope Power Mode
|
||||
*/
|
||||
int8_t bhi3_get_gyro_power_mode(uint8_t *gyro_pwm, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Get the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
|
||||
gyro_pwm,
|
||||
BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_LEN,
|
||||
BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To set the Gyroscope Timer Auto Trim state
|
||||
*/
|
||||
int8_t bhi3_set_gyro_timer_auto_trim(const uint8_t *gyro_tat, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Set the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
|
||||
gyro_tat,
|
||||
BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_LEN,
|
||||
BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the Gyroscope Timer Auto Trim Status
|
||||
*/
|
||||
int8_t bhi3_get_gyro_timer_auto_trim(uint8_t *gyro_tat, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Get the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
|
||||
gyro_tat,
|
||||
BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_LEN,
|
||||
BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To set the Wrist Wear Wakeup Configuration
|
||||
*/
|
||||
int8_t bhi3_set_wrist_wear_wakeup_config(const uint8_t *www_cnfg, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Set the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_WRIST_WEAR_WAKEUP,
|
||||
www_cnfg,
|
||||
BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_LEN,
|
||||
BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the Wrist Wear Wakeup Configuration
|
||||
*/
|
||||
int8_t bhi3_get_wrist_wear_wakeup_config(uint8_t *www_cnfg, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Get the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_WRIST_WEAR_WAKEUP,
|
||||
www_cnfg,
|
||||
BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_LEN,
|
||||
BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To set the Any Motion Configuration
|
||||
*/
|
||||
int8_t bhi3_set_anymotion_config(const uint8_t *any_motion_cnfg, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Set the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_PHYS_ANY_MOTION,
|
||||
any_motion_cnfg,
|
||||
BHI3_PHY_ANY_MOTION_CTRL_LEN,
|
||||
BHI3_PHY_ANY_MOTION_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the Any Motion Configuration
|
||||
*/
|
||||
int8_t bhi3_get_anymotion_config(uint8_t *any_motion_cnfg, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Get the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_PHYS_ANY_MOTION,
|
||||
any_motion_cnfg,
|
||||
BHI3_PHY_ANY_MOTION_CTRL_LEN,
|
||||
BHI3_PHY_ANY_MOTION_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To set the No Motion Configuration
|
||||
*/
|
||||
int8_t bhi3_set_nomotion_config(const uint8_t *no_motion_cnfg, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Set the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_PHYS_NO_MOTION,
|
||||
no_motion_cnfg,
|
||||
BHI3_PHY_NO_MOTION_CTRL_LEN,
|
||||
BHI3_PHY_NO_MOTION_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the No Motion Configuration
|
||||
*/
|
||||
int8_t bhi3_get_nomotion_config(uint8_t *no_motion_cnfg, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Get the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_PHYS_NO_MOTION,
|
||||
no_motion_cnfg,
|
||||
BHI3_PHY_NO_MOTION_CTRL_LEN,
|
||||
BHI3_PHY_NO_MOTION_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To set the Wrist Gesture Detect Configuration
|
||||
*/
|
||||
int8_t bhi3_set_wrist_gesture_detect_config(const uint8_t *wgd_cnfg, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Set the configuration parameter */
|
||||
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_WRIST_GESTURE_DETECT,
|
||||
wgd_cnfg,
|
||||
BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_LEN,
|
||||
BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the Wrist Gesture Detect Configuration
|
||||
*/
|
||||
int8_t bhi3_get_wrist_gesture_detect_config(uint8_t *wgd_cnfg, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_WRIST_GESTURE_DETECT,
|
||||
wgd_cnfg,
|
||||
BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_LEN,
|
||||
BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_CODE,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
/**
|
||||
* 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 bhi3.h
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __BHI3_H__
|
||||
#define __BHI3_H__
|
||||
|
||||
/* Start of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#include "bhy2.h"
|
||||
#include "bhi3_defs.h"
|
||||
|
||||
/*!
|
||||
* @brief To parse Wrist Gesture Detection Data
|
||||
*
|
||||
* @param[in] Wrist Gesture Detection Data
|
||||
* @param[in] Wrist Gesture Detection Output Structure
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_wrist_gesture_detect_parse_data(const uint8_t *data, bhi3_wrist_gesture_detect_t *output);
|
||||
|
||||
/*!
|
||||
* @brief To set the Accelerometer Fast Offset Calibration
|
||||
*
|
||||
* @param[in] Physical Accelerometer FOC data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_set_acc_foc(const struct bhy2_data_xyz *acc_foc, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To get the Accelerometer Fast Offset Calibration
|
||||
*
|
||||
* @param[out] Physical Accelerometer FOC data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_get_acc_foc(struct bhy2_data_xyz *acc_foc, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To set the Accelerometer Power Mode
|
||||
*
|
||||
* @param[in] Physical Accelerometer Power Mode data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_set_acc_power_mode(const uint8_t *acc_pwm, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To get the Accelerometer Power Mode
|
||||
*
|
||||
* @param[out] Physical Accelerometer Power Mode data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_get_acc_power_mode(uint8_t *acc_pwm, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To set the Gyroscope Fast Offset Calibration
|
||||
*
|
||||
* @param[in] Physical Gyroscope FOC data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_set_gyro_foc(const struct bhy2_data_xyz *gyro_foc, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To get the Gyroscope Fast Offset Calibration
|
||||
*
|
||||
* @param[out] Physical Gyroscope FOC data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_get_gyro_foc(struct bhy2_data_xyz *gyro_foc, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To set the Gyroscope OIS
|
||||
*
|
||||
* @param[in] Physical Gyroscope OIS data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_set_gyro_ois(const uint8_t *gyro_ois, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To get the Gyroscope OIS
|
||||
*
|
||||
* @param[out] Physical Gyroscope OIS data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_get_gyro_ois(uint8_t *gyro_ois, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To set the Gyroscope Fast Startup
|
||||
*
|
||||
* @param[in] Physical Gyroscope Fast Startup data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_set_gyro_fast_startup(const uint8_t *gyro_fs, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To get the Gyroscope Fast Startup
|
||||
*
|
||||
* @param[out] Physical Gyroscope Fast Startup data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_get_gyro_fast_startup(uint8_t *gyro_fs, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To set the Gyroscope CRT
|
||||
*
|
||||
* @param[in] Physical Gyroscope CRT data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_set_gyro_crt(const uint8_t *gyro_crt, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To get the Gyroscope CRT
|
||||
*
|
||||
* @param[out] Physical Gyroscope CRT data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_get_gyro_crt(uint8_t *gyro_crt, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To set the Gyroscope Power Mode
|
||||
*
|
||||
* @param[in] Physical Gyroscope Power Mode data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_set_gyro_power_mode(const uint8_t *gyro_pwm, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To get the Gyroscope Power Mode
|
||||
*
|
||||
* @param[out] Physical Gyroscope Power Mode data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_get_gyro_power_mode(uint8_t *gyro_pwm, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To set the Gyroscope Timer Auto Trim state
|
||||
*
|
||||
* @param[in] Physical Gyroscope Timer Auto Trim state
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_set_gyro_timer_auto_trim(const uint8_t *gyro_tat, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To get the Gyroscope Timer Auto Trim status
|
||||
*
|
||||
* @param[out] Physical Gyroscope Timer Auto Trim state
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_get_gyro_timer_auto_trim(uint8_t *gyro_tat, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To set the Wrist Wear Wakeup Configuration
|
||||
*
|
||||
* @param[in] Wrist Wear Wakeup Configuration
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_set_wrist_wear_wakeup_config(const uint8_t *www_cnfg, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To get the Wrist Wear Wakeup Configuration
|
||||
*
|
||||
* @param[out] Wrist Wear Wakeup Configuration
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_get_wrist_wear_wakeup_config(uint8_t *www_cnfg, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To set the Any Motion Configuration
|
||||
*
|
||||
* @param[in] Any Motion Configuration
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_set_anymotion_config(const uint8_t *any_motion_cnfg, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To get the Any Motion Configuration
|
||||
*
|
||||
* @param[out] Any Motion Configuration
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_get_anymotion_config(uint8_t *any_motion_cnfg, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To set the No Motion Configuration
|
||||
*
|
||||
* @param[in] No Motion Configuration
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_set_nomotion_config(const uint8_t *no_motion_cnfg, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To get the No Motion Configuration
|
||||
*
|
||||
* @param[out] No Motion Configuration
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_get_nomotion_config(uint8_t *no_motion_cnfg, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To set the Wrist Gesture Detection Configuration
|
||||
*
|
||||
* @param[in] Wrist Gesture Detection Configuration
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_set_wrist_gesture_detect_config(const uint8_t *wgd_cnfg, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To get the Wrist Gesture Detection Configuration
|
||||
*
|
||||
* @param[out] Wrist Gesture Detection Configuration
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_get_wrist_gesture_detect_config(uint8_t *wgd_cnfg, struct bhy2_dev *dev);
|
||||
|
||||
/* End of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#endif /* __BHI3_H__ */
|
||||
@@ -0,0 +1,204 @@
|
||||
/**
|
||||
* 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 bhi3_defs.h
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __BHI3_DEFS_H__
|
||||
#define __BHI3_DEFS_H__
|
||||
|
||||
/* Start of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#include "bhy2_defs.h"
|
||||
|
||||
/*! The Product ID needs to be replaced with Chip ID for explicit HW specific Identification*/
|
||||
#define BHI3_PRODUCT_ID BHY2_PRODUCT_ID
|
||||
|
||||
/*! Firmware header identifier */
|
||||
/*#define BHY2_FW_MAGIC UINT16_C(0x662B) */
|
||||
|
||||
/*! BHI3 Variant IDs */
|
||||
#define BHI3_VARIANT_ID_BHI360 UINT32_C(0x18BC5434)
|
||||
#define BHI3_VARIANT_ID_BHI380 UINT32_C(0x6E6D6CA6)
|
||||
|
||||
/*! BHI3 Specifc Sensor IDs */
|
||||
#define BHI3_SENSOR_ID_AR_WEAR_WU UINT8_C(154) /* Activity Recognition (wear/hear) */
|
||||
#define BHI3_SENSOR_ID_WRIST_GEST_DETECT_LP_WU UINT8_C(156) /* Wrist Gesture Detector Low Power Wakeup*/
|
||||
#define BHI3_SENSOR_ID_WRIST_WEAR_LP_WU UINT8_C(158) /* Wrist Wear Low Power Wakeup */
|
||||
#define BHI3_SENSOR_ID_NO_MOTION_LP_WU UINT8_C(159) /* No motion Low Power */
|
||||
|
||||
/*! Physical Sensor Control Parameter Page Base Address*/
|
||||
#define BHI3_PHY_SENSOR_CTRL_PAGE UINT16_C(0x0E)
|
||||
|
||||
/*! Physical Sensor Control pages
|
||||
* Here the 'id' refers to the Sensor ID of requisite Physical Sensors (Acc/Gyro)
|
||||
* */
|
||||
#define BHI3_PHY_SENSOR_CTRL_PARAM(id) (((BHI3_PHY_SENSOR_CTRL_PAGE) << 8) | (id))
|
||||
#define BHI3_PHY_SENSOR_CTRL_CODE(dir, code) ((dir << 7) | (code))
|
||||
|
||||
#define BHI3_PHY_SENSOR_CTRL_WRITE UINT8_C(0x00)
|
||||
#define BHI3_PHY_SENSOR_CTRL_READ UINT8_C(0x01)
|
||||
|
||||
#define BHI3_PHY_ACC_FOC_CTRL_CODE UINT8_C(0x01)
|
||||
#define BHI3_PHY_ACC_FOC_CTRL_LEN 6
|
||||
|
||||
#define BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_CODE UINT8_C(0x05)
|
||||
#define BHI3_PHY_ACC_NORMAL_POWER_MODE UINT8_C(0x00)
|
||||
#define BHI3_PHY_ACC_LOW_POWER_MODE UINT8_C(0x02)
|
||||
#define BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_LEN 1
|
||||
|
||||
#define BHI3_PHY_GYRO_FOC_CTRL_CODE UINT8_C(0x01)
|
||||
#define BHI3_PHY_GYRO_FOC_CTRL_LEN 6
|
||||
|
||||
#define BHI3_PHY_GYRO_OIS_CTRL_CODE UINT8_C(0x02)
|
||||
#define BHI3_PHY_GYRO_DISABLE_OIS UINT8_C(0x00)
|
||||
#define BHI3_PHY_GYRO_ENABLE_OIS UINT8_C(0x01)
|
||||
#define BHI3_PHY_GYRO_OIS_CTRL_LEN 1
|
||||
|
||||
#define BHI3_PHY_GYRO_FAST_STARTUP_CTRL_CODE UINT8_C(0x03)
|
||||
#define BHI3_PHY_GYRO_DISABLE_FAST_STARTUP UINT8_C(0x00)
|
||||
#define BHI3_PHY_GYRO_ENABLE_FAST_STARTUP UINT8_C(0x01)
|
||||
#define BHI3_PHY_GYRO_FAST_STARTUP_CTRL_LEN 1
|
||||
|
||||
#define BHI3_PHY_GYRO_CRT_CTRL_CODE UINT8_C(0x04)
|
||||
#define BHI3_PHY_GYRO_CRT_STATUS_SUCCESS UINT8_C(0x00)
|
||||
#define BHI3_PHY_GYRO_ENABLE_CRT UINT8_C(0x01)
|
||||
#define BHI3_PHY_GYRO_CRT_CTRL_LEN 1
|
||||
|
||||
#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
|
||||
|
||||
#define BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_CODE UINT8_C(0x06)
|
||||
#define BHI3_PHY_GYRO_DISABLE_TIMER_AUTO_TRIM UINT8_C(0x00)
|
||||
#define BHI3_PHY_GYRO_ENABLE_TIMER_AUTO_TRIM UINT8_C(0x01)
|
||||
#define BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_LEN 1
|
||||
|
||||
#define BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_CODE UINT8_C(0x01)
|
||||
#define BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_LEN 10
|
||||
|
||||
#define BHI3_PHY_ANY_MOTION_CTRL_CODE UINT8_C(0x01)
|
||||
#define BHI3_PHY_ANY_MOTION_CTRL_LEN 4
|
||||
|
||||
#define BHI3_PHY_NO_MOTION_CTRL_CODE UINT8_C(0x01)
|
||||
#define BHI3_PHY_NO_MOTION_CTRL_LEN 4
|
||||
|
||||
#define BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_CODE UINT8_C(0x07)
|
||||
#define BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_LEN 19
|
||||
|
||||
typedef struct bhi3_wrist_wear_wakeup_config_param {
|
||||
uint16_t min_angle_focus;
|
||||
uint16_t min_angle_nonfocus;
|
||||
uint8_t angle_landscape_right;
|
||||
uint8_t angle_landscape_left;
|
||||
uint8_t angle_portrait_down;
|
||||
uint8_t angle_portrait_up;
|
||||
uint8_t min_dur_moved;
|
||||
uint8_t min_dur_quite;
|
||||
} __attribute__ ((packed)) bhi3_wrist_wear_wakeup_config_param_t;
|
||||
|
||||
typedef struct bhi3_any_no_motion_config_param {
|
||||
uint16_t duration;
|
||||
uint8_t axis;
|
||||
uint16_t threshold;
|
||||
} __attribute__ ((packed)) bhi3_any_no_motion_config_param_t;
|
||||
|
||||
typedef struct bhi3_wrist_gesture_detect_config_param {
|
||||
uint16_t min_flick_peak_y_threshold;
|
||||
uint16_t min_flick_peak_z_threshold;
|
||||
uint16_t gravity_bounds_x_pos;
|
||||
uint16_t gravity_bounds_x_neg;
|
||||
uint16_t gravity_bounds_y_neg;
|
||||
uint16_t gravity_bounds_z_neg;
|
||||
uint16_t flick_peak_decay_coeff;
|
||||
uint16_t lp_mean_filter_coeff;
|
||||
uint16_t max_duration_jiggle_peaks;
|
||||
uint8_t device_position;
|
||||
} __attribute__ ((packed)) bhi3_wrist_gesture_detect_config_param_t;
|
||||
|
||||
enum bhi3_wrist_gesture_activity {
|
||||
NO_GESTURE,
|
||||
WRIST_SHAKE_JIGGLE = 0x03,
|
||||
FLICK_IN,
|
||||
FLICK_OUT
|
||||
};
|
||||
|
||||
typedef struct bhi3_wrist_gesture_detect {
|
||||
enum bhi3_wrist_gesture_activity wrist_gesture;
|
||||
} __attribute__ ((packed)) bhi3_wrist_gesture_detect_t;
|
||||
|
||||
static const char *const bhi3_wrist_gesture_detect_output[] = {
|
||||
[NO_GESTURE] = "NO_GESTURE",
|
||||
[1] = "",
|
||||
[2] = "",
|
||||
[WRIST_SHAKE_JIGGLE] = "WRIST_SHAKE_JIGGLE",
|
||||
[FLICK_IN] = "FLICK_IN",
|
||||
[FLICK_OUT] = "FLICK_OUT"
|
||||
}; /*lint -e528 */
|
||||
|
||||
enum bhi3_phy_sensor_acc_power_mode {
|
||||
ACC_NORMAL,
|
||||
ACC_LOW_POWER = 0x02
|
||||
};
|
||||
|
||||
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",
|
||||
[1] = "",
|
||||
[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 */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#endif /* __BHI3_DEFS_H__ */
|
||||
@@ -0,0 +1,211 @@
|
||||
/**
|
||||
* 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 bhi3_multi_tap.c
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************************************************************/
|
||||
/* system header files */
|
||||
/*********************************************************************/
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*********************************************************************/
|
||||
/* BHI3 SensorAPI header files */
|
||||
/*********************************************************************/
|
||||
#include "bhi3.h"
|
||||
|
||||
/*********************************************************************/
|
||||
/* own header files */
|
||||
/*********************************************************************/
|
||||
#include "bhi3_multi_tap.h"
|
||||
|
||||
/*lint -e506, -e778*/
|
||||
|
||||
/*!
|
||||
* @brief This API writes to the configuration parameter
|
||||
*
|
||||
* @param[in] buffer to store Multi Tap configuration
|
||||
* @param[out] dev hub handle.
|
||||
*
|
||||
* @return rslt execution result.
|
||||
*/
|
||||
int8_t bhi3_multi_tap_set_config(const void *buffer, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Set the Multi Tap configuration parameter */
|
||||
rslt = bhy2_set_parameter(BHI3_MULTI_TAP_PARAM(BHI3_MULTI_TAP_ENABLE_PARAM),
|
||||
(uint8_t*)buffer,
|
||||
BHI3_MULTI_TAP_ENABLE_LENGTH,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the MULTI-TAP configuration parameters
|
||||
*
|
||||
* @param[out] buffer to store Multi Tap configuration
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return status code, BHY_HIF_E_SUCCESS in case of success
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_multi_tap_get_config(const void *buffer, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
uint32_t ret_length;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Get the Multi Tap configuration from the parameter page*/
|
||||
rslt =
|
||||
bhy2_get_parameter(BHI3_MULTI_TAP_PARAM(BHI3_MULTI_TAP_ENABLE_PARAM),
|
||||
(uint8_t *)buffer,
|
||||
BHY2_LE24MUL(BHI3_MULTI_TAP_ENABLE_LENGTH),
|
||||
&ret_length,
|
||||
dev);
|
||||
|
||||
if (rslt != BHY2_OK)
|
||||
{
|
||||
/*! Invalid number of parameters readout */
|
||||
rslt = BHY2_E_INVALID_EVENT_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief This API writes to the tap detector configuration parameter
|
||||
*
|
||||
* @param[in] buffer to store Multi Tap Detector configuration
|
||||
* @param[out] dev hub handle.
|
||||
*
|
||||
* @return rslt execution result.
|
||||
*/
|
||||
int8_t bhi3_multi_tap_detector_set_config(const void *buffer, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Set the Multi Tap configuration parameter */
|
||||
rslt = bhy2_set_parameter(BHI3_MULTI_TAP_PARAM(BHI3_MULTI_TAP_DETECTOR_CONFIG_PARAM),
|
||||
(uint8_t*)buffer,
|
||||
BHI3_MULTI_TAP_DETECTOR_CONFIG_LENGTH,
|
||||
dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the MULTI-TAP Detector configuration parameters
|
||||
*
|
||||
* @param[out] buffer to store Multi Tap Detector configuration
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return status code, BHY_HIF_E_SUCCESS in case of success
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_multi_tap_detector_get_config(const void *buffer, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
uint32_t ret_length;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Get the Multi Tap configuration from the parameter page*/
|
||||
rslt = bhy2_get_parameter(BHI3_MULTI_TAP_PARAM(BHI3_MULTI_TAP_DETECTOR_CONFIG_PARAM),
|
||||
(uint8_t *)buffer,
|
||||
BHY2_LE24MUL(BHI3_MULTI_TAP_DETECTOR_CONFIG_LENGTH),
|
||||
&ret_length,
|
||||
dev);
|
||||
|
||||
if (rslt != BHY2_OK)
|
||||
{
|
||||
/*! Invalid number of parameters readout */
|
||||
rslt = BHY2_E_INVALID_EVENT_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Parsing the fifo data to Multi Tap output format
|
||||
*
|
||||
* @param[in] Multi Tap data
|
||||
* @param[out] buffer to store parameter data
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_multi_tap_parse_data(const uint8_t *data, uint8_t* output)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if ((data == NULL) || (output == NULL))
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
*output = *data;
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* 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 bhi3_multi_tap.h
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _BHY2_MULTI_TAP_H_
|
||||
#define _BHY2_MULTI_TAP_H_
|
||||
|
||||
/* Start of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "bhi3.h"
|
||||
#include "bhi3_multi_tap_defs.h"
|
||||
|
||||
/*!
|
||||
* @brief Parsing the fifo data to MULTI_TAP output structure format
|
||||
*
|
||||
* @param[in] Multi Tap data
|
||||
* @param[out] buffer to store parameter data
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_multi_tap_parse_data(const uint8_t *data, uint8_t *output);
|
||||
|
||||
/*!
|
||||
* @brief To set the MULTI_TAP configuration parameters
|
||||
* @param[out] buffer to store parameter data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return status code, BHY_HIF_E_SUCCESS in case of success
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_multi_tap_set_config(const void *buffer, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To get the MULTI_TAP configuration parameters
|
||||
*
|
||||
* @param[out] buffer to store parameter data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return status code, BHY_HIF_E_SUCCESS in case of success
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_multi_tap_get_config(const void *buffer, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To set the MULTI_TAP Detector configuration parameters
|
||||
* @param[out] buffer to store parameter data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return status code, BHY_HIF_E_SUCCESS in case of success
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_multi_tap_detector_set_config(const void *buffer, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To get the MULTI_TAP Detector configuration parameters
|
||||
*
|
||||
* @param[out] buffer to store parameter data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return status code, BHY_HIF_E_SUCCESS in case of success
|
||||
*
|
||||
*/
|
||||
int8_t bhi3_multi_tap_detector_get_config(const void *buffer, struct bhy2_dev *dev);
|
||||
|
||||
/* End of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#endif /* _BHY2_MULTI_TAP_H_ */
|
||||
@@ -0,0 +1,189 @@
|
||||
/**
|
||||
* 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 bhi3_multi_tap_defs.h
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _BHI3_MULTI_TAP_DEFS_H_
|
||||
#define _BHI3_MULTI_TAP_DEFS_H_
|
||||
|
||||
/* Start of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
/*! Sensor ID for Multi-Tap */
|
||||
#define BHI3_SENSOR_ID_MULTI_TAP UINT8_C(153)
|
||||
|
||||
/*! Multi-Tap Parameter Page Base Address*/
|
||||
#define BHI3_MULTI_TAP_PAGE UINT16_C(0x0D)
|
||||
|
||||
/*! Multi-Tap Configuration pages */
|
||||
#define BHI3_MULTI_TAP_ENABLE_PARAM 0x01
|
||||
#define BHI3_MULTI_TAP_DETECTOR_CONFIG_PARAM 0x02
|
||||
#define BHI3_MULTI_TAP_PARAM(id) (((BHI3_MULTI_TAP_PAGE) << 8) | (id))
|
||||
|
||||
#define BHI3_MULTI_TAP_ENABLE_LENGTH UINT8_C(4)
|
||||
#define BHI3_MULTI_TAP_DETECTOR_CONFIG_LENGTH UINT8_C(6)
|
||||
|
||||
#define BHI3_MULTI_TAP_AXIS_SEL_X UINT8_C(0)
|
||||
#define BHI3_MULTI_TAP_AXIS_SEL_Y UINT8_C(1)
|
||||
#define BHI3_MULTI_TAP_AXIS_SEL_Z UINT8_C(2)
|
||||
|
||||
#define BHI3_MULTI_TAP_WAIT_TIMEOUT_DISABLE UINT8_C(0)
|
||||
#define BHI3_MULTI_TAP_WAIT_TIMEOUT_ENABLE UINT8_C(1)
|
||||
|
||||
#define BHI3_MULTI_TAP_FILTER_MODE_SENSITIVE UINT8_C(0)
|
||||
#define BHI3_MULTI_TAP_FILTER_MODE_NORMAL UINT8_C(1)
|
||||
#define BHI3_MULTI_TAP_FILTER_MODE_ROBUST UINT8_C(2)
|
||||
|
||||
#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 0x38
|
||||
#define BHI3_SINGLE_TAP_FILTER_MODE_MASK 0xC0
|
||||
|
||||
#define BHI3_DOUBLE_TAP_TAP_PEAK_DUR_MASK 0x03FF
|
||||
#define BHI3_DOUBLE_TAP_MAX_GES_DUR_MASK 0xFC00
|
||||
|
||||
#define BHI3_TRIPLE_TAP_MAX_DUR_BW_PEAKS_MASK 0x0F
|
||||
#define BHI3_TRIPLE_TAP_TAP_SHOCK_SETL_DUR_MASK 0xF0
|
||||
#define BHI3_TRIPLE_TAP_MIN_QT_DUR_BW_PEAKS_MASK 0x0F
|
||||
#define BHI3_TRIPLE_TAP_QT_TM_AFTER_GESTURE_MASK 0xF0
|
||||
|
||||
#define BHI3_SINGLE_TAP_AXIS_SEL_SHIFT UINT8_C(0)
|
||||
#define BHI3_SINGLE_TAP_WAIT_TIMEOUT_SHIFT UINT8_C(2)
|
||||
#define BHI3_SINGLE_TAP_MAX_PEAKS_FOR_TAP_SHIFT UINT8_C(3)
|
||||
#define BHI3_SINGLE_TAP_FILTER_MODE_SHIFT UINT8_C(6)
|
||||
|
||||
#define BHI3_DOUBLE_TAP_TAP_PEAK_DUR_SHIFT UINT8_C(0)
|
||||
#define BHI3_DOUBLE_TAP_MAX_GES_DUR_SHIFT UINT8_C(10)
|
||||
|
||||
#define BHI3_TRIPLE_TAP_MAX_DUR_BW_PEAKS_SHIFT UINT8_C(0)
|
||||
#define BHI3_TRIPLE_TAP_TAP_SHOCK_SETL_DUR_SHIFT UINT8_C(4)
|
||||
#define BHI3_TRIPLE_TAP_MIN_QT_DUR_BW_PEAKS_SHIFT UINT8_C(0)
|
||||
#define BHI3_TRIPLE_TAP_QT_TM_AFTER_GESTURE_SHIFT UINT8_C(4)
|
||||
|
||||
/*!
|
||||
* Single Tap Configuration.
|
||||
*/
|
||||
typedef union bhi3_singletap_detector_settings
|
||||
{
|
||||
uint16_t as_uint16;
|
||||
struct
|
||||
{
|
||||
uint16_t axis_sel : 2; /* Tap axis selection */
|
||||
uint16_t wait_for_timeout : 1; /* Wait for gesture confirmation */
|
||||
uint16_t max_peaks_for_tap : 3; /* Maximum number of peaks that can occur when a tap is done
|
||||
* */
|
||||
uint16_t mode : 2; /* Filter configuration for various detection mode: SENSITIVE, NORMAL and
|
||||
* ROBUST */
|
||||
uint16_t reserved8 : 8;
|
||||
} as_s;
|
||||
} __attribute__ ((packed)) bhi3_singletap_detector_settings_t;
|
||||
|
||||
/*!
|
||||
* Double Tap Configuration.
|
||||
*/
|
||||
typedef union bhi3_doubletap_detector_settings
|
||||
{
|
||||
uint16_t as_uint16;
|
||||
struct
|
||||
{
|
||||
uint16_t tap_peak_thres : 10; /* Minimum threshold for peak detection */
|
||||
uint16_t max_gesture_dur : 6; /* Maximum time duration from first tap within which matching
|
||||
* tap/s should happen to be detected as double/triple tap */
|
||||
} as_s;
|
||||
} __attribute__ ((packed)) bhi3_doubletap_detector_settings_t;
|
||||
|
||||
/*!
|
||||
* Triple Tap Configuration.
|
||||
*/
|
||||
typedef union bhi3_tripletap_detector_settings
|
||||
{
|
||||
uint16_t as_uint16;
|
||||
struct
|
||||
{
|
||||
uint16_t max_dur_between_peaks : 4; /* Maximum time duration within which matching peaks of tap
|
||||
* should occur */
|
||||
uint16_t tap_shock_settling_dur : 4; /* Maximum duration to wait for tap shock settling */
|
||||
uint16_t min_quite_dur_between_taps : 4; /* Minimum quite time between detection of consecutive taps
|
||||
* of double/triple taps*/
|
||||
uint16_t quite_time_after_gesture : 4; /* Minimum quite time between detection of 2 consecutive
|
||||
* selected gesture */
|
||||
} as_s;
|
||||
} __attribute__ ((packed)) bhi3_tripletap_detector_settings_t;
|
||||
|
||||
/*!
|
||||
* Multi Tap Configuration.
|
||||
*/
|
||||
typedef struct bhi3_multi_tap_detector
|
||||
{
|
||||
bhi3_singletap_detector_settings_t stap_setting;
|
||||
bhi3_doubletap_detector_settings_t dtap_setting;
|
||||
bhi3_tripletap_detector_settings_t ttap_setting;
|
||||
} __attribute__ ((packed)) bhi3_multi_tap_detector_t;
|
||||
|
||||
/*!
|
||||
* Multi Tap Setting.
|
||||
*/
|
||||
enum bhi3_multi_tap_val {
|
||||
NO_TAP,
|
||||
SINGLE_TAP,
|
||||
DOUBLE_TAP,
|
||||
DOUBLE_SINGLE_TAP,
|
||||
TRIPLE_TAP,
|
||||
TRIPLE_SINGLE_TAP,
|
||||
TRIPLE_DOUBLE_TAP,
|
||||
TRIPLE_DOUBLE_SINGLE_TAP
|
||||
};
|
||||
|
||||
/*!
|
||||
* Multi Tap Output.
|
||||
*/
|
||||
static const char * const bhi3_multi_tap_string_out[] = {
|
||||
[NO_TAP] = "NO_TAP", [SINGLE_TAP] = "SINGLE_TAP", [DOUBLE_TAP] = "DOUBLE_TAP",
|
||||
[DOUBLE_SINGLE_TAP] = "DOUBLE_SINGLE_TAP", [TRIPLE_TAP] = "TRIPLE_TAP", [TRIPLE_SINGLE_TAP] = "TRIPLE_SINGLE_TAP",
|
||||
[TRIPLE_DOUBLE_TAP] = "TRIPLE_DOUBLE_TAP", [TRIPLE_DOUBLE_SINGLE_TAP] = "TRIPLE_DOUBLE_SINGLE_TAP"
|
||||
}; /*lint -e528 */
|
||||
|
||||
/* End of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#endif /* _BHI3_MULTI_TAP_DEFS_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,664 @@
|
||||
/**
|
||||
* 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.h
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __BHY2_H__
|
||||
#define __BHY2_H__
|
||||
|
||||
/* Start of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#include "bhy2_defs.h"
|
||||
|
||||
/**
|
||||
* @brief Function to link the callback interfaces
|
||||
* @param[in] intf : Physical communication interface
|
||||
* @param[in] read : Read function pointer
|
||||
* @param[in] write : Write function pointer
|
||||
* @param[in] delay_us : Microsecond delay function pointer
|
||||
* @param[in] read_write_len : Maximum read/write lengths supported
|
||||
* @param[in] intf_ptr : Reference to the interface. Can be NULL
|
||||
* @param[out] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_init(enum bhy2_intf intf,
|
||||
bhy2_read_fptr_t read,
|
||||
bhy2_write_fptr_t write,
|
||||
bhy2_delay_us_fptr_t delay_us,
|
||||
uint32_t read_write_len,
|
||||
void *intf_ptr,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get data from registers
|
||||
* @param[in] reg_addr : Register address to be read from
|
||||
* @param[out] reg_data : Reference to the data buffer
|
||||
* @param[in] length : Length of the data buffer
|
||||
* @param[in] dev : Device reference
|
||||
* @return API Error codes
|
||||
*/
|
||||
int8_t bhy2_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t length, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to set data to registers
|
||||
* @param[in] reg_addr : Register address to write to
|
||||
* @param[in] reg_data : Reference to the data buffer
|
||||
* @param[in] length : Length of the data buffer
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint16_t length, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the product ID
|
||||
* @param[out] product_id : Reference to data buffer to store the product ID
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_product_id(uint8_t *product_id, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the chip ID
|
||||
* @param[out] chip_id : Reference to data buffer to store the chip ID
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_chip_id(uint8_t *chip_id, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the revision ID
|
||||
* @param[out] revision_id : Reference to data buffer to store the revision ID
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_revision_id(uint8_t *revision_id, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the ROM version
|
||||
* @param[out] rom_version : Reference to the data buffer to store the ROM version
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_rom_version(uint16_t *rom_version, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the kernel version
|
||||
* @param[out] kernel_version : Reference to the data buffer to store the kernel version
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_kernel_version(uint16_t *kernel_version, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the user version
|
||||
* @param[out] user_version : Reference to the data buffer to store the user version
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_user_version(uint16_t *user_version, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the boot status
|
||||
* @param[out] boot_status : Reference to the data buffer to store the boot status
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_boot_status(uint8_t *boot_status, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the host status
|
||||
* @param[out] host_status : Reference to the data buffer to store the host status
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_host_status(uint8_t *host_status, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the feature status
|
||||
* @param[out] feat_status : Reference to the data buffer to store the feature status
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_feature_status(uint8_t *feat_status, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the virtual sensor list and store in the device structure
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_virt_sensor_list(struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the virtual sensor configuration
|
||||
* @param[in] sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[out] virt_sensor_conf : Reference to the data buffer to store the virtual sensor configuration
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_virt_sensor_cfg(uint8_t sensor_id, struct bhy2_virt_sensor_conf *virt_sensor_conf,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to set the sample rate and latency of the virtual sensor
|
||||
* @param[in] sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[in] sample_rate : Sample rate in Hz
|
||||
* @param[in] latency : Report latency in milliseconds
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_set_virt_sensor_cfg(uint8_t sensor_id, bhy2_float sample_rate, uint32_t latency, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function set the range of the virtual sensor
|
||||
* @param[in] sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[in] range : Range of the virtual sensor
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_set_virt_sensor_range(uint8_t sensor_id, uint16_t range, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get and process the FIFOs
|
||||
* @param[in] work_buffer : Reference to the data buffer where the FIFO data is copied to before parsing
|
||||
* @param[in] buffer_size : Size of the data buffer
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_and_process_fifo(uint8_t *work_buffer, uint32_t buffer_size, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function get the FIFO control register
|
||||
* @param[out] fifo_ctrl : Reference to the data buffer to store the FIFO control
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_fifo_ctrl(uint32_t *fifo_ctrl, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to set the Wake up FIFO watermark
|
||||
* @param[in] watermark : Size of the watermark
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_set_fifo_wmark_wkup(uint32_t watermark, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the Wake up FIFO watermark
|
||||
* @param[out] watermark : Reference to the data buffer to store the FIFO watermark size
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_fifo_wmark_wkup(uint32_t *watermark, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to set the Non wake up FIFO watermark
|
||||
* @param[in] watermark : Size of the watermark
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_set_fifo_wmark_nonwkup(uint32_t watermark, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the Non wake up FIFO watermark
|
||||
* @param[out] watermark : Reference to the data buffer to store the FIFO watermark size
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_fifo_wmark_nonwkup(uint32_t *watermark, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to flush data of a virtual sensor from the FIFOs
|
||||
* @param[in] sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_flush_fifo(uint8_t sensor_id, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to set the FIFO format
|
||||
* @param[in] param : FIFO format settings
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_set_fifo_format_ctrl(uint8_t param, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to upload firmware to RAM
|
||||
* @param[in] firmware : Reference to the data buffer containing the firmware
|
||||
* @param[in] length : Size of the firmware
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_upload_firmware_to_ram(const uint8_t *firmware, uint32_t length, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to upload part of the firmware to RAM
|
||||
* @param[in] firmware : Reference to the data buffer containing the current firmware section
|
||||
* @param[in] total_size : Total size of the firmware
|
||||
* @param[in] cur_pos : Current position of the part being loaded
|
||||
* @param[in] packet_len : Size of the part being loaded
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_upload_firmware_to_ram_partly(const uint8_t *firmware,
|
||||
uint32_t total_size,
|
||||
uint32_t cur_pos,
|
||||
uint32_t packet_len,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to boot firmware from RAM
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_boot_from_ram(struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to erase the flash
|
||||
* @param[in] start_addr : Start address
|
||||
* @param[in] end_addr : End address
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_erase_flash(uint32_t start_address, uint32_t end_addr, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to upload firmware to Flash
|
||||
* @param[in] firmware : Reference to the data buffer containing the firmware
|
||||
* @param[in] length : Size of the firwmare
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_upload_firmware_to_flash(const uint8_t *firmware, uint32_t length, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to upload part of the firmware to Flash
|
||||
* @param[in] firmware : Reference to the data buffer containing the current firmware section
|
||||
* @param[in] cur_pos : Current position of the part being loaded
|
||||
* @param[in] packet_len : Size of the part being loaded
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_upload_firmware_to_flash_partly(const uint8_t *firmware,
|
||||
uint32_t cur_pos,
|
||||
uint32_t packet_len,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to boot from Flash
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_boot_from_flash(struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to set the host interrupt control register
|
||||
* @param[in] hintr_ctrl : Host interrupt control configuration
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_set_host_interrupt_ctrl(uint8_t hintr_ctrl, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the host interrupt control register
|
||||
* @param[out] hintr_ctrl : Reference to the data buffer to store the configuration
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_host_interrupt_ctrl(uint8_t *hintr_ctrl, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the interrupt status register
|
||||
* @param[out] int_status : Reference to the data buffer to store the interrupt status
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_interrupt_status(uint8_t *int_status, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to set the host interface control register
|
||||
* @param[in] hintf_ctrl : Host interface control configuration
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_set_host_intf_ctrl(uint8_t hintf_ctrl, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the host interface control register
|
||||
* @param[out] hintf_ctrl : Reference to the data buffer to store the configuration
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_host_intf_ctrl(uint8_t *hintf_ctrl, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to trigger a timestamp event
|
||||
* @param[in] ts_ev_req : Pass a non-zero value to trigger a timestamp event
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_set_timestamp_event_req(uint8_t ts_ev_req, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the timestamp of the sensor in nanoseconds
|
||||
* @param[out] timestamp_ns : Reference to the data buffer to store the timestamp in nanoseconds
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_hw_timestamp_ns(uint64_t *timestamp_ns, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the host control register
|
||||
* @param[in] host_ctrl : Host control configuration
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_set_host_ctrl(uint8_t host_ctrl, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the host control register
|
||||
* @param[out] host_ctrl : Reference to the data buffer to store the host control configuration
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_host_ctrl(uint8_t *host_ctrl, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to trigger a soft reset
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_soft_reset(struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to perform a self test of a virtual sensor
|
||||
* @param[in] phys_sensor_id : Physical sensor ID of the virtual sensor
|
||||
* @param[out] self_test_resp : Reference to the data buffer to store the self test response from the virtual sensor
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_perform_self_test(uint8_t phys_sensor_id, struct bhy2_self_test_resp *self_test_resp, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to perform a fast offset compensation of a virtual sensor
|
||||
* @param[in] phys_sensor_id : Physical Sensor ID of the virtual sensor
|
||||
* @param[out] self_test_resp : Reference to the data buffer to store the FOC response from the virtual sensor
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_perform_foc(uint8_t phys_sensor_id, struct bhy2_foc_resp *foc_resp, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to set the orientation matrix of a physical sensor
|
||||
* @param[in] phys_sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[in] orient_matrix : Orientation matrix
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_set_orientation_matrix(uint8_t phys_sensor_id, struct bhy2_orient_matrix orient_matrix,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the physical sensor information
|
||||
* @param[in] phys_sensor_id : Sensor ID of the physical sensor
|
||||
* @param[out] phy_sen_info : Reference to the data buffer to the store the physical sensor information
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_phys_sensor_info(uint8_t phys_sensor_id,
|
||||
struct bhy2_phys_sensor_info *phy_sen_info,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the orientation matrix of a physical sensor
|
||||
* @param[in] phys_sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[out] orient_matrix : Reference to the data buffer to the store the orientation matrix
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_orientation_matrix(uint8_t phys_sensor_id,
|
||||
struct bhy2_orient_matrix *orient_matrix,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to set the Soft Iron Correction matrix
|
||||
* @param[in] sic_matrix : Reference to the data buffer storing the Soft Iron Correction matrix
|
||||
* @param[in] matrix_len : Length of the matrix
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_set_sic_matrix(const uint8_t *sic_matrix, uint16_t matrix_len, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the Soft Iron Correction matrix
|
||||
* @param[out] sic_matrix : Reference to the data buffer to store the Soft Iron Correction matrix
|
||||
* @param[in] matrix_len : Length of data buffer
|
||||
* @param[out] actual_len : Actual length of the Soft Iron Correction matrix
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_sic_matrix(uint8_t *sic_matrix, uint16_t matrix_len, uint32_t *actual_len, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the calibration profile of a BSX virtual sensor
|
||||
* @param[in] phys_sensor_id: Physical Sensor ID of the virtual sensor
|
||||
* @param[out] calib_prof : Reference to the data buffer to store the calibration profile
|
||||
* @param[in] prof_len : Length of the data buffer
|
||||
* @param[out] actual_len : Actual length of the calibration profile
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_calibration_profile(uint8_t phys_sensor_id,
|
||||
uint8_t *calib_prof,
|
||||
uint16_t prof_len,
|
||||
uint32_t *actual_len,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to set the calibration profile of a BSX virtual sensor
|
||||
* @param[in] phys_sensor_id: Physical Sensor ID of the virtual sensor
|
||||
* @param[in] calib_prof : Reference to the data buffer storing the calibration profile
|
||||
* @param[in] prof_len : Length of the profil
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_set_calibration_profile(uint8_t phys_sensor_idv,
|
||||
const uint8_t *calib_prof,
|
||||
uint16_t prof_len,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the post mortem data
|
||||
* @param[out] post_mortem : Reference to the data buffer to store the post mortem data
|
||||
* @param[in] buffer_len : Length of the data buffer
|
||||
* @param[out] actual_len : Actual length of the post mortem data
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_post_mortem_data(uint8_t *post_mortem, uint32_t buffer_len, uint32_t *actual_len, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to link a callback and relevant reference when the sensor event is available in the FIFO
|
||||
* @param[in] sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[in] callback : Reference of the callback function
|
||||
* @param[in] callback_ref : Reference needed inside the callback function. Can be NULL
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_register_fifo_parse_callback(uint8_t sensor_id,
|
||||
bhy2_fifo_parse_callback_t callback,
|
||||
void *callback_ref,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to unlink a callback and relevant reference
|
||||
* @param[in] sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_deregister_fifo_parse_callback(uint8_t sensor_id, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to update the callback table's information
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_update_virtual_sensor_list(struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get information of a virtual sensor
|
||||
* @param[in] sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[out] info : Reference to the data buffer to store the virtual sensor information
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_sensor_info(uint8_t sensor_id, struct bhy2_sensor_info *info, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to set a parameter
|
||||
* @param[in] param : Parameter ID
|
||||
* @param[in] payload : Reference to the data buffer storing the parameter's payload
|
||||
* @param[in] length : Length of the payload
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_set_parameter(uint16_t param, const uint8_t *payload, uint32_t length, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get a parameter
|
||||
* @param[in] param : Parameter ID
|
||||
* @param[out] payload : Reference to the data buffer to store the parameter's payload
|
||||
* @param[in] payload_len : Length of the data buffer
|
||||
* @param[out] actual_len : Actual length of the payload
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_parameter(uint16_t param,
|
||||
uint8_t *payload,
|
||||
uint32_t payload_len,
|
||||
uint32_t *actual_len,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the error value register
|
||||
* @param[out] error_value : Reference to the data buffer to store the error value
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_get_error_value(uint8_t *error_value, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to directly communicate with the sensor
|
||||
* @param[in] conf : The configuration of the transfer
|
||||
* @param[in] reg_addr : Register address to write to
|
||||
* @param[in] length : Length of the data buffer to be transferred
|
||||
* @param[in/out] reg_data : Reference to the data buffer
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_soft_passthrough_transfer(union bhy2_soft_passthrough_conf *conf,
|
||||
uint8_t reg_addr,
|
||||
uint8_t length,
|
||||
uint8_t *reg_data,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to check if a virtual sensor is available
|
||||
* @param[in] sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[in] dev : Device reference
|
||||
* @return 1 if the sensor is available. 0 otherwise
|
||||
*/
|
||||
uint8_t bhy2_is_sensor_available(uint8_t sensor_id, const struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to get the BHy260 variant ID
|
||||
*
|
||||
* @param[in] variant_id : Reference to store the variant ID
|
||||
* @param[in] dev : Device reference
|
||||
* @return int8_t API error codes
|
||||
*/
|
||||
int8_t bhy2_get_variant_id(uint32_t *variant_id, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to inject data
|
||||
* @param[in] payload : Reference to the data buffer
|
||||
* @param[in] payload_len : Length of the data buffer
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
|
||||
int8_t bhy2_inject_data(const uint8_t *payload, uint32_t payload_len, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to set inject mode
|
||||
* @param[in] mode : Type of data inject mode
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_set_data_injection_mode(enum bhy2_data_inj_mode mode, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to clear the FIFO
|
||||
* @param[in] flush_cfg : Type of FIFO Flush
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_clear_fifo(uint8_t flush_cfg, struct bhy2_dev *dev);
|
||||
|
||||
/**
|
||||
* @brief Function to read the status FIFO
|
||||
* @param[out] status_code : Status Code
|
||||
* @param[in] status_buff : Buffer for reading Status Response
|
||||
* @param[in] status_len : Length of the Response
|
||||
* @param[out] actual_len : Length of Data read
|
||||
* @param[in] dev : Device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_read_status(uint16_t *status_code,
|
||||
uint8_t *status_buff,
|
||||
uint32_t status_len,
|
||||
uint32_t *actual_len,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/* End of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#endif /* __BHY2_H__ */
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* 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_bsec.c
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************************************************************/
|
||||
/* system header files */
|
||||
/*********************************************************************/
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*********************************************************************/
|
||||
/* BHY2 SensorAPI header files */
|
||||
/*********************************************************************/
|
||||
#include "bhy2.h"
|
||||
|
||||
/*********************************************************************/
|
||||
/* own header files */
|
||||
/*********************************************************************/
|
||||
#include "bhy2_bsec.h"
|
||||
|
||||
void bhy2_bsec_parse_air_quality(const uint8_t *payload, struct bhy2_bsec_air_quality *data)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
|
||||
if ((payload != NULL) && (data != NULL))
|
||||
{
|
||||
data->comp_temp = BHY2_LE2U32(payload + i);
|
||||
i += 4;
|
||||
data->comp_hum = BHY2_LE2U32(payload + i);
|
||||
i += 4;
|
||||
data->comp_gas = BHY2_LE2U32(payload + i);
|
||||
i += 4;
|
||||
data->iaq = BHY2_LE2U32(payload + i);
|
||||
i += 4;
|
||||
data->static_iaq = BHY2_LE2U32(payload + i);
|
||||
i += 4;
|
||||
data->e_co2 = BHY2_LE2U32(payload + i);
|
||||
i += 4;
|
||||
data->voc = BHY2_LE2U32(payload + i);
|
||||
i += 4;
|
||||
data->iaq_accuracy = payload[i];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* 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_bsec.h
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _BHY2_BSEC_H_
|
||||
#define _BHY2_BSEC_H_
|
||||
|
||||
/* Start of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "bhy2.h"
|
||||
|
||||
#define BHY2_SENSOR_ID_AIR_QUALITY UINT8_C(115)
|
||||
|
||||
struct bhy2_bsec_air_quality
|
||||
{
|
||||
float comp_temp; /* Sensor heat compensated temperature (deg C) */
|
||||
float comp_hum; /* Sensor heat compensated humidity (%rH) */
|
||||
float comp_gas; /* Compensated gas resistance (ohms) */
|
||||
float iaq; /* Indoor Air Quality index */
|
||||
float static_iaq; /* Static IAQ index */
|
||||
float e_co2; /* Equivalent CO2 (ppm) */
|
||||
float voc; /* Volatile organic compounds (ppb) */
|
||||
uint8_t iaq_accuracy; /* IAQ index accuracy (0-3) */
|
||||
};
|
||||
|
||||
void bhy2_bsec_parse_air_quality(const uint8_t *payload, struct bhy2_bsec_air_quality *data);
|
||||
|
||||
/* End of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#endif /* _BHY2_BSEC_H_ */
|
||||
@@ -0,0 +1,789 @@
|
||||
/**
|
||||
* 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_defs.h
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __BHY2_DEFS_H__
|
||||
#define __BHY2_DEFS_H__
|
||||
|
||||
/* Start of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#ifdef __KERNEL__
|
||||
#include <linux/string.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/types.h>
|
||||
#else
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#endif /*~ __KERNEL__ */
|
||||
|
||||
#ifndef UNUSED
|
||||
#define UNUSED(__x__) ((void)(__x__))
|
||||
#endif /*~ UNUSED */
|
||||
|
||||
#ifdef __KERNEL__
|
||||
#define bhy2_float u32
|
||||
#else
|
||||
#define bhy2_float float
|
||||
#endif /*~ __KERNEL__ */
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
#if !defined(UINT8_C) && !defined(INT8_C)
|
||||
#define INT8_C(x) S8_C(x)
|
||||
#define UINT8_C(x) U8_C(x)
|
||||
#endif
|
||||
|
||||
#if !defined(UINT16_C) && !defined(INT16_C)
|
||||
#define INT16_C(x) S16_C(x)
|
||||
#define UINT16_C(x) U16_C(x)
|
||||
#endif
|
||||
|
||||
#if !defined(INT32_C) && !defined(UINT32_C)
|
||||
#define INT32_C(x) S32_C(x)
|
||||
#define UINT32_C(x) U32_C(x)
|
||||
#endif
|
||||
|
||||
#if !defined(INT64_C) && !defined(UINT64_C)
|
||||
#define INT64_C(x) S64_C(x)
|
||||
#define UINT64_C(x) U64_C(x)
|
||||
#endif
|
||||
|
||||
#else /* __KERNEL__ */
|
||||
|
||||
#if !defined(UINT8_C) && !defined(INT8_C)
|
||||
#define INT8_C(x) (x)
|
||||
#define UINT8_C(x) (x##U)
|
||||
#endif
|
||||
|
||||
#if !defined(UINT16_C) && !defined(INT16_C)
|
||||
#define INT16_C(x) (x)
|
||||
#define UINT16_C(x) (x##U)
|
||||
#endif
|
||||
|
||||
#if !defined(INT32_C) && !defined(UINT32_C)
|
||||
#define INT32_C(x) (x)
|
||||
#define UINT32_C(x) (x##U)
|
||||
#endif
|
||||
|
||||
#if !defined(INT64_C) && !defined(UINT64_C)
|
||||
#define INT64_C(x) (x##LL)
|
||||
#define UINT64_C(x) (x##ULL)
|
||||
#endif
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
#ifndef NULL
|
||||
#ifdef __cplusplus
|
||||
#define NULL 0
|
||||
#else
|
||||
#define NULL ((void *) 0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef BHY2_PACKED
|
||||
#define BHY2_PACKED __attribute__ ((__packed__))
|
||||
#endif
|
||||
|
||||
/** API error codes */
|
||||
#define BHY2_OK INT8_C(0)
|
||||
#define BHY2_E_NULL_PTR INT8_C(-1)
|
||||
#define BHY2_E_INVALID_PARAM INT8_C(-2)
|
||||
#define BHY2_E_IO INT8_C(-3)
|
||||
#define BHY2_E_MAGIC INT8_C(-4)
|
||||
#define BHY2_E_TIMEOUT INT8_C(-5)
|
||||
#define BHY2_E_BUFFER INT8_C(-6)
|
||||
#define BHY2_E_INVALID_FIFO_TYPE INT8_C(-7)
|
||||
#define BHY2_E_INVALID_EVENT_SIZE INT8_C(-8)
|
||||
#define BHY2_E_PARAM_NOT_SET INT8_C(-9)
|
||||
#define BHy2_E_INSUFFICIENT_MAX_SIMUL_SENSORS INT8_C(-10)
|
||||
|
||||
#ifndef BHY2_COMMAND_PACKET_LEN
|
||||
#define BHY2_COMMAND_PACKET_LEN UINT16_C(256)
|
||||
#endif
|
||||
|
||||
#ifndef BHY2_COMMAND_HEADER_LEN
|
||||
#define BHY2_COMMAND_HEADER_LEN UINT16_C(4)
|
||||
#endif
|
||||
|
||||
#if (BHY2_COMMAND_PACKET_LEN < BHY2_COMMAND_HEADER_LEN)
|
||||
#error "BHY2_COMMAND_PACKET_LEN should be at least 4 bytes"
|
||||
#endif
|
||||
|
||||
#define BHY2_PRODUCT_ID UINT8_C(0x89)
|
||||
|
||||
/*! Register map */
|
||||
#define BHY2_REG_CHAN_CMD UINT8_C(0x00)
|
||||
#define BHY2_REG_CHAN_FIFO_W UINT8_C(0x01)
|
||||
#define BHY2_REG_CHAN_FIFO_NW UINT8_C(0x02)
|
||||
#define BHY2_REG_CHAN_STATUS UINT8_C(0x03)
|
||||
#define BHY2_REG_CHIP_CTRL UINT8_C(0x05)
|
||||
#define BHY2_REG_HOST_INTERFACE_CTRL UINT8_C(0x06)
|
||||
#define BHY2_REG_HOST_INTERRUPT_CTRL UINT8_C(0x07)
|
||||
#define BHY2_REG_RESET_REQ UINT8_C(0x14)
|
||||
#define BHY2_REG_TIME_EV_REQ UINT8_C(0x15)
|
||||
#define BHY2_REG_HOST_CTRL UINT8_C(0x16)
|
||||
#define BHY2_REG_HOST_STATUS UINT8_C(0x17)
|
||||
#define BHY2_REG_CRC_0 UINT8_C(0x18) /* Totally 4 */
|
||||
#define BHY2_REG_PRODUCT_ID UINT8_C(0x1C)
|
||||
#define BHY2_REG_REVISION_ID UINT8_C(0x1D)
|
||||
#define BHY2_REG_ROM_VERSION_0 UINT8_C(0x1E) /* Totally 2 */
|
||||
#define BHY2_REG_KERNEL_VERSION_0 UINT8_C(0x20) /* Totally 2 */
|
||||
#define BHY2_REG_USER_VERSION_0 UINT8_C(0x22) /* Totally 2 */
|
||||
#define BHY2_REG_FEATURE_STATUS UINT8_C(0x24)
|
||||
#define BHY2_REG_BOOT_STATUS UINT8_C(0x25)
|
||||
#define BHY2_REG_HOST_INTR_TIME_0 UINT8_C(0x26) /* Totally 5 */
|
||||
#define BHY2_REG_CHIP_ID UINT8_C(0x2B)
|
||||
#define BHY2_REG_INT_STATUS UINT8_C(0x2D)
|
||||
#define BHY2_REG_ERROR_VALUE UINT8_C(0x2E)
|
||||
#define BHY2_REG_ERROR_AUX UINT8_C(0x2F)
|
||||
#define BHY2_REG_DEBUG_VALUE UINT8_C(0x30)
|
||||
#define BHY2_REG_DEBUG_STATE UINT8_C(0x31)
|
||||
#define BHY2_REG_GP_5 UINT8_C(0x32)
|
||||
#define BHY2_REG_GP_6 UINT8_C(0x36)
|
||||
#define BHY2_REG_GP_7 UINT8_C(0x3A)
|
||||
|
||||
/*! Command packets */
|
||||
#define BHY2_CMD_REQ_POST_MORTEM_DATA UINT16_C(0x0001)
|
||||
#define BHY2_CMD_UPLOAD_TO_PROGRAM_RAM UINT16_C(0x0002)
|
||||
#define BHY2_CMD_BOOT_PROGRAM_RAM UINT16_C(0x0003)
|
||||
#define BHY2_CMD_ERASE_FLASH UINT16_C(0x0004)
|
||||
#define BHY2_CMD_WRITE_FLASH UINT16_C(0x0005)
|
||||
#define BHY2_CMD_BOOT_FLASH UINT16_C(0x0006)
|
||||
#define BHY2_CMD_SET_INJECT_MODE UINT16_C(0x0007)
|
||||
#define BHY2_CMD_INJECT_DATA UINT16_C(0x0008)
|
||||
#define BHY2_CMD_FIFO_FLUSH UINT16_C(0x0009)
|
||||
#define BHY2_CMD_SW_PASSTHROUGH UINT16_C(0x000A)
|
||||
#define BHY2_CMD_REQ_SELF_TEST UINT16_C(0x000B)
|
||||
#define BHY2_CMD_REQ_FOC UINT16_C(0x000C)
|
||||
#define BHY2_CMD_CONFIG_SENSOR UINT16_C(0x000D)
|
||||
#define BHY2_CMD_CHANGE_RANGE UINT16_C(0x000E)
|
||||
#define BHY2_CMD_FIFO_FORMAT_CTRL UINT16_C(0x0015)
|
||||
|
||||
/*! Soft passthrough feature */
|
||||
#define BHY2_SPASS_READ UINT8_C(0)
|
||||
#define BHY2_SPASS_WRITE UINT8_C(1)
|
||||
#define BHY2_SPASS_SINGLE_TRANS UINT8_C(0)
|
||||
#define BHY2_SPASS_MULTI_TRANS UINT8_C(1)
|
||||
#define BHY2_SPASS_DELAY_DIS UINT8_C(0)
|
||||
#define BHY2_SPASS_DELAY_EN UINT8_C(1)
|
||||
#define BHY2_SPASS_SIF1 UINT8_C(1)
|
||||
#define BHY2_SPASS_SIF2 UINT8_C(2)
|
||||
#define BHY2_SPASS_SIF3 UINT8_C(3)
|
||||
#define BHY2_SPASS_SPI_4_WIRE UINT8_C(0)
|
||||
#define BHY2_SPASS_SPI_3_WIRE UINT8_C(1)
|
||||
#define BHY2_SPASS_SPI_CPOL_0 UINT8_C(0)
|
||||
#define BHY2_SPASS_SPI_CPOL_1 UINT8_C(1)
|
||||
#define BHY2_SPASS_SPI_CPHA_0 UINT8_C(0)
|
||||
#define BHY2_SPASS_SPI_CPHA_1 UINT8_C(1)
|
||||
#define BHY2_SPASS_SPI_CS_LOW UINT8_C(0)
|
||||
#define BHY2_SPASS_SPI_CS_HIGH UINT8_C(1)
|
||||
#define BHY2_SPASS_SPI_LSB_FIRST_DIS UINT8_C(0)
|
||||
#define BHY2_SPASS_SPI_LSB_FIRST_EN UINT8_C(1)
|
||||
#define BHY2_SPASS_SPI_READ_BIT_POL_LOW UINT8_C(0)
|
||||
#define BHY2_SPASS_SPI_READ_BIT_POL_HIGH UINT8_C(1)
|
||||
#define BHY2_SPASS_SPI_READ_BIT_POS_0 UINT8_C(0)
|
||||
#define BHY2_SPASS_SPI_READ_BIT_POS_1 UINT8_C(1)
|
||||
#define BHY2_SPASS_SPI_READ_BIT_POS_2 UINT8_C(2)
|
||||
#define BHY2_SPASS_SPI_READ_BIT_POS_3 UINT8_C(3)
|
||||
#define BHY2_SPASS_SPI_READ_BIT_POS_4 UINT8_C(4)
|
||||
#define BHY2_SPASS_SPI_READ_BIT_POS_5 UINT8_C(5)
|
||||
#define BHY2_SPASS_SPI_READ_BIT_POS_6 UINT8_C(6)
|
||||
#define BHY2_SPASS_SPI_READ_BIT_POS_7 UINT8_C(7)
|
||||
#define BHY2_SPASS_READ_PACKET_LEN UINT8_C(0x13)
|
||||
#define BHY2_SPASS_WRITE_RESP_PACKET_LEN UINT8_C(16)
|
||||
|
||||
/*! Helper macros */
|
||||
#define BHY2_CHK_BIT(data, bit) (((uint32_t)data >> bit) & 0x01)
|
||||
#define BHY2_ROUND_WORD_LOWER(x) ((x >> 2) << 2)
|
||||
#define BHY2_ROUND_WORD_HIGHER(x) (((x >> 2) + 1) << 2)
|
||||
|
||||
#define BHY2_COUNTOF(__BUFFER__) (sizeof(__BUFFER__) / sizeof(*(__BUFFER__)))
|
||||
#define BHY2_DATA_INJECT_MODE_PAYLOAD_LEN UINT8_C(0x04)
|
||||
|
||||
/*! Firmware header identifier */
|
||||
#define BHY2_FW_MAGIC UINT16_C(0x662B)
|
||||
|
||||
/*! BHy260 Variant IDs */
|
||||
#define BHY2_VARIANT_ID_BHA260AB UINT32_C(0x2838C2C2)
|
||||
#define BHY2_VARIANT_ID_BHI260AB UINT32_C(0x266EB6E7)
|
||||
#define BHY2_VARIANT_ID_BHI260AP UINT32_C(0x98D7A5D1)
|
||||
|
||||
/*! Boot status */
|
||||
#define BHY2_BST_FLASH_DETECTED UINT8_C(0x01)
|
||||
#define BHY2_BST_FLASH_VERIFY_DONE UINT8_C(0x02)
|
||||
#define BHY2_BST_FLASH_VERIFY_ERROR UINT8_C(0x04)
|
||||
#define BHY2_BST_NO_FLASH UINT8_C(0x08)
|
||||
#define BHY2_BST_HOST_INTERFACE_READY UINT8_C(0x10)
|
||||
#define BHY2_BST_HOST_FW_VERIFY_DONE UINT8_C(0x20)
|
||||
#define BHY2_BST_HOST_FW_VERIFY_ERROR UINT8_C(0x40)
|
||||
#define BHY2_BST_HOST_FW_IDLE UINT8_C(0x80)
|
||||
#define BHY2_BST_CHECK_RETRY UINT8_C(100)
|
||||
|
||||
/*! Host status */
|
||||
#define BHY2_HST_POWER_STATE UINT8_C(0x01)
|
||||
#define BHY2_HST_HOST_PROTOCOL UINT8_C(0x02)
|
||||
#define BHY2_HST_HOST_CHANNEL_0 UINT8_C(0x10)
|
||||
#define BHY2_HST_HOST_CHANNEL_1 UINT8_C(0x20)
|
||||
#define BHY2_HST_HOST_CHANNEL_2 UINT8_C(0x40)
|
||||
#define BHY2_HST_HOST_CHANNEL_3 UINT8_C(0x80)
|
||||
|
||||
/*! Interrupt status masks */
|
||||
#define BHY2_IST_MASK_ASSERTED (0x1)
|
||||
#define BHY2_IST_MASK_FIFO_W (0x6)
|
||||
#define BHY2_IST_MASK_FIFO_NW (0x18)
|
||||
#define BHY2_IST_MASK_STATUS (0x20)
|
||||
#define BHY2_IST_MASK_DEBUG (0x40)
|
||||
#define BHY2_IST_MASK_RESET_FAULT (0x80)
|
||||
#define BHY2_IST_FIFO_W_DRDY UINT8_C(0x2)
|
||||
#define BHY2_IST_FIFO_W_LTCY UINT8_C(0x4)
|
||||
#define BHY2_IST_FIFO_W_WM UINT8_C(0x6)
|
||||
#define BHY2_IST_FIFO_NW_DRDY UINT8_C(0x8)
|
||||
#define BHY2_IST_FIFO_NW_LTCY UINT8_C(0x10)
|
||||
#define BHY2_IST_FIFO_NW_WM UINT8_C(0x18)
|
||||
#define BHY2_IS_INT_FIFO_W(status) (status & BHY2_IST_MASK_FIFO_W)
|
||||
#define BHY2_IS_INT_FIFO_NW(status) (status & BHY2_IST_MASK_FIFO_NW)
|
||||
#define BHY2_IS_INT_STATUS(status) (status & BHY2_IST_MASK_STATUS)
|
||||
#define BHY2_IS_INT_ASYNC_STATUS(status) (status & BHY2_IST_MASK_DEBUG)
|
||||
#define BHY2_IS_INT_RESET(status) (status & BHY2_IST_MASK_RESET_FAULT)
|
||||
#define BHY2_IST_MASK_FIFO (BHY2_IST_MASK_FIFO_W | BHY2_IST_MASK_FIFO_NW)
|
||||
#define BHY2_IS_INT_FIFO(status) (status & BHY2_IST_MASK_FIFO)
|
||||
|
||||
/*! Chip control bits */
|
||||
#define BHY2_CHIP_CTRL_DISABLE UINT8_C(0x00)
|
||||
#define BHY2_CHIP_CTRL_TURBO_ENABLE UINT8_C(0x01)
|
||||
#define BHY2_CHIP_CTRL_CLR_ERR_REG UINT8_C(0x02)
|
||||
|
||||
/*! Host interface control bits */
|
||||
#define BHY2_HIF_CTRL_ABORT_TRANSFER_CHANNEL_0 UINT8_C(0x01)
|
||||
#define BHY2_HIF_CTRL_ABORT_TRANSFER_CHANNEL_1 UINT8_C(0x02)
|
||||
#define BHY2_HIF_CTRL_ABORT_TRANSFER_CHANNEL_2 UINT8_C(0x04)
|
||||
#define BHY2_HIF_CTRL_ABORT_TRANSFER_CHANNEL_3 UINT8_C(0x08)
|
||||
#define BHY2_HIF_CTRL_AP_SUSPENDED UINT8_C(0x10)
|
||||
#define BHY2_HIF_CTRL_TIMESTAMP_EV_CTRL UINT8_C(0x40)
|
||||
#define BHY2_HIF_CTRL_ASYNC_STATUS_CHANNEL UINT8_C(0x80)
|
||||
|
||||
/*! Interrupt control bits */
|
||||
#define BHY2_ICTL_DISABLE_FIFO_W UINT8_C(0x01)
|
||||
#define BHY2_ICTL_DISABLE_FIFO_NW UINT8_C(0x02)
|
||||
#define BHY2_ICTL_DISABLE_STATUS_FIFO UINT8_C(0x04)
|
||||
#define BHY2_ICTL_DISABLE_DEBUG UINT8_C(0x08)
|
||||
#define BHY2_ICTL_DISABLE_FAULT UINT8_C(0x10)
|
||||
#define BHY2_ICTL_ACTIVE_LOW UINT8_C(0x20)
|
||||
#define BHY2_ICTL_EDGE UINT8_C(0x40)
|
||||
#define BHY2_ICTL_OPEN_DRAIN UINT8_C(0x80)
|
||||
|
||||
/*! Reset command */
|
||||
#define BHY2_REQUEST_RESET UINT8_C(0x01)
|
||||
|
||||
/*! FIFO Format bit */
|
||||
#define BHY2_FIFO_FORMAT_CTRL_MASK UINT8_C(0x03)
|
||||
#define BHY2_FIFO_FORMAT_CTRL_DIS_DELTA_TS UINT8_C(0x01)
|
||||
#define BHY2_FIFO_FORMAT_CTRL_DIS_FULL_TS UINT8_C(0x02)
|
||||
#define BHY2_FIFO_FORMAT_CTRL_DIS_ALL_TS UINT8_C(0x03)
|
||||
|
||||
/*! System parameters */
|
||||
#define BHY2_PARAM_READ_MASK UINT16_C(0x1000)
|
||||
#define BHY2_PARAM_FIFO_CTRL UINT16_C(0x103)
|
||||
#define BHY2_PARAM_SYS_VIRT_SENSOR_PRESENT UINT16_C(0x11F)
|
||||
#define BHY2_PARAM_SYS_PHYS_SENSOR_PRESENT UINT16_C(0x120)
|
||||
#define BHY2_PARAM_PHYSICAL_SENSOR_BASE UINT16_C(0x120)
|
||||
#define BHY2_PARAM_BSX_CALIB_STATE_BASE UINT16_C(0x200)
|
||||
#define BHY2_PARAM_BSX_CALIB_STATE_ACCEL UINT16_C(0x201)
|
||||
#define BHY2_PARAM_BSX_CALIB_STATE_GYRO UINT16_C(0x203)
|
||||
#define BHY2_PARAM_BSX_CALIB_STATE_MAG UINT16_C(0x205)
|
||||
#define BHY2_PARAM_BSX_SIC UINT16_C(0x27D)
|
||||
#define BHY2_PARAM_BSX_VERSION UINT16_C(0x27E)
|
||||
#define BHY2_PARAM_SET_SENSOR_CTRL UINT16_C(0x0E00)
|
||||
#define BHY2_PARAM_GET_SENSOR_CTRL UINT16_C(0x1E00)
|
||||
#define BHY2_PARAM_SENSOR_CTRL_FOC UINT8_C(0x1)
|
||||
#define BHY2_PARAM_SENSOR_CTRL_OIS UINT8_C(0x2)
|
||||
#define BHY2_PARAM_SENSOR_CTRL_FST UINT8_C(0x3)
|
||||
#define BHY2_PARAM_SENSOR_CTRL_READ UINT8_C(0x80)
|
||||
#define BHY2_PARAM_SENSOR_INFO_0 UINT16_C(0x300)
|
||||
#define BHY2_PARAM_SENSOR_CONF_0 UINT16_C(0x500)
|
||||
|
||||
#define BHY2_BSX_STATE_TRANSFER_COMPLETE UINT8_C(0x80)
|
||||
#define BHY2_BSX_STATE_BLOCK_NUM_MSK UINT8_C(0x7F)
|
||||
#define BHY2_BSX_STATE_BLOCK_LEN UINT8_C(64)
|
||||
#define BHY2_BSX_STATE_STRUCT_LEN UINT8_C(68)
|
||||
|
||||
#define BHY2_QUERY_PARAM_STATUS_READY_MAX_RETRY UINT16_C(1000)
|
||||
#define BHY2_QUERY_FLASH_MAX_RETRY UINT16_C(1200)
|
||||
|
||||
/*! Meta event definitions */
|
||||
#define BHY2_META_EVENT_FLUSH_COMPLETE (1)
|
||||
#define BHY2_META_EVENT_SAMPLE_RATE_CHANGED (2)
|
||||
#define BHY2_META_EVENT_POWER_MODE_CHANGED (3)
|
||||
#define BHY2_META_EVENT_ALGORITHM_EVENTS (5)
|
||||
#define BHY2_META_EVENT_SENSOR_STATUS (6)
|
||||
#define BHY2_META_EVENT_BSX_DO_STEPS_MAIN (7)
|
||||
#define BHY2_META_EVENT_BSX_DO_STEPS_CALIB (8)
|
||||
#define BHY2_META_EVENT_BSX_GET_OUTPUT_SIGNAL (9)
|
||||
#define BHY2_META_EVENT_RESERVED1 (10)
|
||||
#define BHY2_META_EVENT_SENSOR_ERROR (11)
|
||||
#define BHY2_META_EVENT_FIFO_OVERFLOW (12)
|
||||
#define BHY2_META_EVENT_DYNAMIC_RANGE_CHANGED (13)
|
||||
#define BHY2_META_EVENT_FIFO_WATERMARK (14)
|
||||
#define BHY2_META_EVENT_RESERVED2 (15)
|
||||
#define BHY2_META_EVENT_INITIALIZED (16)
|
||||
#define BHY2_META_TRANSFER_CAUSE (17)
|
||||
#define BHY2_META_EVENT_SENSOR_FRAMEWORK (18)
|
||||
#define BHY2_META_EVENT_RESET (19)
|
||||
#define BHY2_META_EVENT_SPACER (20)
|
||||
|
||||
/* Flash start address in memory */
|
||||
#define BHY2_FLASH_SECTOR_START_ADDR UINT32_C(0x1F84)
|
||||
#define BHY2_FLASH_BULK_ERASE UINT32_C(0xFFFFFFFF)
|
||||
|
||||
/* End address for common flash sizes */
|
||||
#define BHY2_FLASH_SIZE_0_5MB UINT32_C(0x7FFFF)
|
||||
#define BHY2_FLASH_SIZE_1MB UINT32_C(0xFFFFF)
|
||||
#define BHY2_FLASH_SIZE_2MB UINT32_C(0x1FFFFF)
|
||||
#define BHY2_FLASH_SIZE_4MB UINT32_C(0x3FFFFF)
|
||||
#define BHY2_FLASH_SIZE_8MB UINT32_C(0x7FFFFF)
|
||||
|
||||
/* Sensor IDs */
|
||||
#define BHY2_SENSOR_ID_CUSTOM_START UINT8_C(160)
|
||||
#define BHY2_SENSOR_ID_CUSTOM_END UINT8_C(191)
|
||||
|
||||
#define BHY2_SENSOR_ID_MAX UINT8_C(200)
|
||||
#define BHY2_SENSOR_ID_TBD UINT8_C(BHY2_SENSOR_ID_MAX - 1)
|
||||
|
||||
/* Virtual Sensor IDs */
|
||||
#define BHY2_SENSOR_ID_ACC_PASS UINT8_C(1) /* Accelerometer passthrough */
|
||||
#define BHY2_SENSOR_ID_ACC_RAW UINT8_C(3) /* Accelerometer uncalibrated */
|
||||
#define BHY2_SENSOR_ID_ACC UINT8_C(4) /* Accelerometer corrected */
|
||||
#define BHY2_SENSOR_ID_ACC_BIAS UINT8_C(5) /* Accelerometer offset */
|
||||
#define BHY2_SENSOR_ID_ACC_WU UINT8_C(6) /* Accelerometer corrected wake up */
|
||||
#define BHY2_SENSOR_ID_ACC_RAW_WU UINT8_C(7) /* Accelerometer uncalibrated wake up */
|
||||
#define BHY2_SENSOR_ID_SI_ACCEL UINT8_C(8) /* Virtual Sensor ID for Accelerometer */
|
||||
#define BHY2_SENSOR_ID_GYRO_PASS UINT8_C(10) /* Gyroscope passthrough */
|
||||
#define BHY2_SENSOR_ID_GYRO_RAW UINT8_C(12) /* Gyroscope uncalibrated */
|
||||
#define BHY2_SENSOR_ID_GYRO UINT8_C(13) /* Gyroscope corrected */
|
||||
#define BHY2_SENSOR_ID_GYRO_BIAS UINT8_C(14) /* Gyroscope offset */
|
||||
#define BHY2_SENSOR_ID_GYRO_WU UINT8_C(15) /* Gyroscope wake up */
|
||||
#define BHY2_SENSOR_ID_GYRO_RAW_WU UINT8_C(16) /* Gyroscope uncalibrated wake up */
|
||||
#define BHY2_SENSOR_ID_SI_GYROS UINT8_C(17) /* Virtual Sensor ID for Gyroscope */
|
||||
#define BHY2_SENSOR_ID_MAG_PASS UINT8_C(19) /* Magnetometer passthrough */
|
||||
#define BHY2_SENSOR_ID_MAG_RAW UINT8_C(21) /* Magnetometer uncalibrated */
|
||||
#define BHY2_SENSOR_ID_MAG UINT8_C(22) /* Magnetometer corrected */
|
||||
#define BHY2_SENSOR_ID_MAG_BIAS UINT8_C(23) /* Magnetometer offset */
|
||||
#define BHY2_SENSOR_ID_MAG_WU UINT8_C(24) /* Magnetometer wake up */
|
||||
#define BHY2_SENSOR_ID_MAG_RAW_WU UINT8_C(25) /* Magnetometer uncalibrated wake up */
|
||||
#define BHY2_SENSOR_ID_GRA UINT8_C(28) /* Gravity vector */
|
||||
#define BHY2_SENSOR_ID_GRA_WU UINT8_C(29) /* Gravity vector wake up */
|
||||
#define BHY2_SENSOR_ID_LACC UINT8_C(31) /* Linear acceleration */
|
||||
#define BHY2_SENSOR_ID_LACC_WU UINT8_C(32) /* Linear acceleration wake up */
|
||||
#define BHY2_SENSOR_ID_RV UINT8_C(34) /* Rotation vector */
|
||||
#define BHY2_SENSOR_ID_RV_WU UINT8_C(35) /* Rotation vector wake up */
|
||||
#define BHY2_SENSOR_ID_GAMERV UINT8_C(37) /* Game rotation vector */
|
||||
#define BHY2_SENSOR_ID_GAMERV_WU UINT8_C(38) /* Game rotation vector wake up */
|
||||
#define BHY2_SENSOR_ID_GEORV UINT8_C(40) /* Geo-magnetic rotation vector */
|
||||
#define BHY2_SENSOR_ID_GEORV_WU UINT8_C(41) /* Geo-magnetic rotation vector wake up */
|
||||
#define BHY2_SENSOR_ID_ORI UINT8_C(43) /* Orientation */
|
||||
#define BHY2_SENSOR_ID_ORI_WU UINT8_C(44) /* Orientation wake up */
|
||||
#define BHY2_SENSOR_ID_TILT_DETECTOR UINT8_C(48) /* Tilt detector */
|
||||
#define BHY2_SENSOR_ID_STD UINT8_C(50) /* Step detector */
|
||||
#define BHY2_SENSOR_ID_STC UINT8_C(52) /* Step counter */
|
||||
#define BHY2_SENSOR_ID_STC_WU UINT8_C(53) /* Step counter wake up */
|
||||
#define BHY2_SENSOR_ID_SIG UINT8_C(55) /* Significant motion */
|
||||
#define BHY2_SENSOR_ID_WAKE_GESTURE UINT8_C(57) /* Wake gesture */
|
||||
#define BHY2_SENSOR_ID_GLANCE_GESTURE UINT8_C(59) /* Glance gesture */
|
||||
#define BHY2_SENSOR_ID_PICKUP_GESTURE UINT8_C(61) /* Pickup gesture */
|
||||
#define BHY2_SENSOR_ID_AR UINT8_C(63) /* Activity recognition */
|
||||
#define BHY2_SENSOR_ID_WRIST_TILT_GESTURE UINT8_C(67) /* Wrist tilt gesture */
|
||||
#define BHY2_SENSOR_ID_DEVICE_ORI UINT8_C(69) /* Device orientation */
|
||||
#define BHY2_SENSOR_ID_DEVICE_ORI_WU UINT8_C(70) /* Device orientation wake up */
|
||||
#define BHY2_SENSOR_ID_STATIONARY_DET UINT8_C(75) /* Stationary detect */
|
||||
#define BHY2_SENSOR_ID_MOTION_DET UINT8_C(77) /* Motion detect */
|
||||
#define BHY2_SENSOR_ID_ACC_BIAS_WU UINT8_C(91) /* Accelerometer offset wake up */
|
||||
#define BHY2_SENSOR_ID_GYRO_BIAS_WU UINT8_C(92) /* Gyroscope offset wake up */
|
||||
#define BHY2_SENSOR_ID_MAG_BIAS_WU UINT8_C(93) /* Magnetometer offset wake up */
|
||||
#define BHY2_SENSOR_ID_STD_WU UINT8_C(94) /* Step detector wake up */
|
||||
#define BHY2_SENSOR_ID_TEMP UINT8_C(128) /* Temperature */
|
||||
#define BHY2_SENSOR_ID_BARO UINT8_C(129) /* Barometer */
|
||||
#define BHY2_SENSOR_ID_HUM UINT8_C(130) /* Humidity */
|
||||
#define BHY2_SENSOR_ID_GAS UINT8_C(131) /* Gas */
|
||||
#define BHY2_SENSOR_ID_TEMP_WU UINT8_C(132) /* Temperature wake up */
|
||||
#define BHY2_SENSOR_ID_BARO_WU UINT8_C(133) /* Barometer wake up */
|
||||
#define BHY2_SENSOR_ID_HUM_WU UINT8_C(134) /* Humidity wake up */
|
||||
#define BHY2_SENSOR_ID_GAS_WU UINT8_C(135) /* Gas wake up */
|
||||
#define BHY2_SENSOR_ID_STC_LP UINT8_C(136) /* Step counter Low Power */
|
||||
#define BHY2_SENSOR_ID_STD_LP UINT8_C(137) /* Step detector Low Power */
|
||||
#define BHY2_SENSOR_ID_SIG_LP UINT8_C(138) /* Significant motion Low Power */
|
||||
#define BHY2_SENSOR_ID_STC_LP_WU UINT8_C(139) /* Step counter Low Power wake up */
|
||||
#define BHY2_SENSOR_ID_STD_LP_WU UINT8_C(140) /* Step detector Low Power wake up */
|
||||
#define BHY2_SENSOR_ID_SIG_LP_WU UINT8_C(141) /* Significant motion Low Power wake up */
|
||||
#define BHY2_SENSOR_ID_ANY_MOTION_LP UINT8_C(142) /* Any motion Low Power */
|
||||
#define BHY2_SENSOR_ID_ANY_MOTION_LP_WU UINT8_C(143) /* Any motion Low Power wake up */
|
||||
#define BHY2_SENSOR_ID_EXCAMERA UINT8_C(144) /* External camera trigger */
|
||||
#define BHY2_SENSOR_ID_GPS UINT8_C(145) /* GPS */
|
||||
#define BHY2_SENSOR_ID_LIGHT UINT8_C(146) /* Light */
|
||||
#define BHY2_SENSOR_ID_PROX UINT8_C(147) /* Proximity */
|
||||
#define BHY2_SENSOR_ID_LIGHT_WU UINT8_C(148) /* Light wake up */
|
||||
#define BHY2_SENSOR_ID_PROX_WU UINT8_C(149) /* Proximity wake up */
|
||||
|
||||
/*! Physical sensor IDs*/
|
||||
#define BHY2_PHYS_SENSOR_ID_ACCELEROMETER UINT8_C(1)
|
||||
#define BHY2_PHYS_SENSOR_ID_GYROSCOPE UINT8_C(3)
|
||||
#define BHY2_PHYS_SENSOR_ID_MAGNETOMETER UINT8_C(5)
|
||||
#define BHY2_PHYS_SENSOR_ID_TEMP_GYRO UINT8_C(7)
|
||||
#define BHY2_PHYS_SENSOR_ID_ANY_MOTION UINT8_C(9)
|
||||
#define BHY2_PHYS_SENSOR_ID_PRESSURE UINT8_C(11)
|
||||
#define BHY2_PHYS_SENSOR_ID_POSITION UINT8_C(13)
|
||||
#define BHY2_PHYS_SENSOR_ID_HUMIDITY UINT8_C(15)
|
||||
#define BHY2_PHYS_SENSOR_ID_TEMPERATURE UINT8_C(17)
|
||||
#define BHY2_PHYS_SENSOR_ID_GAS_RESISTOR UINT8_C(19)
|
||||
#define BHY2_PHYS_SENSOR_ID_PHYS_STEP_COUNTER UINT8_C(32)
|
||||
#define BHY2_PHYS_SENSOR_ID_PHYS_STEP_DETECTOR UINT8_C(33)
|
||||
#define BHY2_PHYS_SENSOR_ID_PHYS_SIGN_MOTION UINT8_C(34)
|
||||
#define BHY2_PHYS_SENSOR_ID_PHYS_ANY_MOTION UINT8_C(35)
|
||||
#define BHY2_PHYS_SENSOR_ID_EX_CAMERA_INPUT UINT8_C(36)
|
||||
#define BHY2_PHYS_SENSOR_ID_GPS UINT8_C(48)
|
||||
#define BHY2_PHYS_SENSOR_ID_LIGHT UINT8_C(49)
|
||||
#define BHY2_PHYS_SENSOR_ID_PROXIMITY UINT8_C(50)
|
||||
#define BHY2_PHYS_SENSOR_ID_PHYS_NO_MOTION UINT8_C(55)
|
||||
#define BHY2_PHYS_SENSOR_ID_WRIST_GESTURE_DETECT UINT8_C(56)
|
||||
#define BHY2_PHYS_SENSOR_ID_WRIST_WEAR_WAKEUP UINT8_C(57)
|
||||
|
||||
/*! System data IDs */
|
||||
#define BHY2_IS_SYS_ID(sid) ((sid) >= 224)
|
||||
|
||||
#define BHY2_SYS_ID_PADDING UINT8_C(0)
|
||||
#define BHY2_SYS_ID_TS_SMALL_DELTA UINT8_C(251)
|
||||
#define BHY2_SYS_ID_TS_LARGE_DELTA UINT8_C(252)
|
||||
#define BHY2_SYS_ID_TS_FULL UINT8_C(253)
|
||||
#define BHY2_SYS_ID_META_EVENT UINT8_C(254)
|
||||
#define BHY2_SYS_ID_TS_SMALL_DELTA_WU UINT8_C(245)
|
||||
#define BHY2_SYS_ID_TS_LARGE_DELTA_WU UINT8_C(246)
|
||||
#define BHY2_SYS_ID_TS_FULL_WU UINT8_C(247)
|
||||
#define BHY2_SYS_ID_META_EVENT_WU UINT8_C(248)
|
||||
#define BHY2_SYS_ID_FILLER UINT8_C(255)
|
||||
#define BHY2_SYS_ID_DEBUG_MSG UINT8_C(250)
|
||||
#define BHY2_SYS_ID_BHY2_LOG_UPDATE_SUB UINT8_C(243)
|
||||
#define BHY2_SYS_ID_BHY2_LOG_DOSTEP UINT8_C(244)
|
||||
|
||||
/*! Status code definitions */
|
||||
#define BHY2_STATUS_INITIALIZED UINT8_C(0x1)
|
||||
#define BHY2_STATUS_DEBUG_OUTPUT UINT8_C(0x2)
|
||||
#define BHY2_STATUS_CRASH_DUMP UINT8_C(0x3)
|
||||
#define BHY2_STATUS_INJECT_SENSOR_CONF_REQ UINT8_C(0x4)
|
||||
#define BHY2_STATUS_SW_PASS_THRU_RES UINT8_C(0x5)
|
||||
#define BHY2_STATUS_SELF_TEST_RES UINT8_C(0x6)
|
||||
#define BHY2_STATUS_FOC_RES UINT8_C(0x7)
|
||||
#define BHY2_STATUS_SYSTEM_ERROR UINT8_C(0x8)
|
||||
#define BHY2_STATUS_SENSOR_ERROR UINT8_C(0x9)
|
||||
#define BHY2_STATUS_FLASH_ERASE_COMPLETE UINT8_C(0xA)
|
||||
#define BHY2_STATUS_FLASH_WRITE_COMPLETE UINT8_C(0xB)
|
||||
#define BHY2_STATUS_FLASH_CONTINUE_UPLOAD UINT8_C(0xC)
|
||||
#define BHY2_STATUS_HOST_EV_TIMESTAMP UINT8_C(0xD)
|
||||
#define BHY2_STATUS_DUT_TEST_RES UINT8_C(0xE)
|
||||
#define BHY2_STATUS_CMD_ERR UINT8_C(0xF)
|
||||
|
||||
#define BHY2_IS_STATUS_GET_PARAM_OUTPUT(status) ((status) >= 0x100 && (status) <= 0xFFF)
|
||||
|
||||
/*! Activity bits */
|
||||
#define BHY2_STILL_ACTIVITY_ENDED (0x0001)
|
||||
#define BHY2_WALKING_ACTIVITY_ENDED (0x0002)
|
||||
#define BHY2_RUNNING_ACTIVITY_ENDED (0x0004)
|
||||
#define BHY2_ON_BICYCLE_ACTIVITY_ENDED (0x0008)
|
||||
#define BHY2_IN_VEHICLE_ACTIVITY_ENDED (0x0010)
|
||||
#define BHY2_TILTING_ACTIVITY_ENDED (0x0020)
|
||||
|
||||
#define BHY2_STILL_ACTIVITY_STARTED (0x0100)
|
||||
#define BHY2_WALKING_ACTIVITY_STARTED (0x0200)
|
||||
#define BHY2_RUNNING_ACTIVITY_STARTED (0x0400)
|
||||
#define BHY2_ON_BICYCLE_ACTIVITY_STARTED (0x0800)
|
||||
#define BHY2_IN_VEHICLE_ACTIVITY_STARTED (0x1000)
|
||||
#define BHY2_TILTING_ACTIVITY_STARTED (0x2000)
|
||||
|
||||
/*! Feature status */
|
||||
#define BHY2_FEAT_STATUS_FLASH_DESC_MSK UINT8_C(0x01)
|
||||
#define BHY2_FEAT_STATUS_OPEN_RTOS_MSK UINT8_C(0x02)
|
||||
#define BHY2_FEAT_STATUS_OPEN_RTOS_POS (1)
|
||||
#define BHY2_FEAT_STATUS_HOST_ID_MSK UINT8_C(0x1C)
|
||||
#define BHY2_FEAT_STATUS_HOST_ID_POS (2)
|
||||
#define BHY2_FEAT_STATUS_ALGO_ID_MSK UINT8_C(0xE0)
|
||||
#define BHY2_FEAT_STATUS_ALGO_ID_POS (5)
|
||||
|
||||
/*! Fast offset compensation status codes */
|
||||
#define BHY2_FOC_PASS UINT8_C(0x00)
|
||||
#define BHY2_FOC_FAILED UINT8_C(0x65)
|
||||
#define BHY2_FOC_UNKNOWN_FAILURE UINT8_C(0x23)
|
||||
|
||||
/*! Self test status codes */
|
||||
#define BHY2_ST_PASSED UINT8_C(0x00)
|
||||
#define BHY2_ST_X_AXIS_FAILED UINT8_C(0x01)
|
||||
#define BHY2_ST_Y_AXIS_FAILED UINT8_C(0x02)
|
||||
#define BHY2_ST_Z_AXIS_FAILED UINT8_C(0x04)
|
||||
#define BHY2_ST_MULTI_AXIS_FAILURE UINT8_C(0x07)
|
||||
#define BHY2_ST_NOT_SUPPORTED UINT8_C(0x08)
|
||||
#define BHY2_ST_INVALID_PHYS_ID UINT8_C(0x09)
|
||||
|
||||
#define BHY2_LE2U16(x) ((uint16_t)((x)[0] | (x)[1] << 8))
|
||||
#define BHY2_LE2S16(x) ((int16_t)BHY2_LE2U16(x))
|
||||
#define BHY2_LE2U24(x) ((uint32_t)((x)[0] | (uint32_t)(x)[1] << 8 | (uint32_t)(x)[2] << 16))
|
||||
#define BHY2_LE2S24(x) ((int32_t)(BHY2_LE2U24(x) << 8) >> 8)
|
||||
#define BHY2_LE2U32(x) ((uint32_t)((x)[0] | (uint32_t)(x)[1] << 8 | (uint32_t)(x)[2] << 16 | \
|
||||
(uint32_t)(x)[3] << 24))
|
||||
#define BHY2_LE2S32(x) ((int32_t)BHY2_LE2U32(x))
|
||||
#define BHY2_LE2U40(x) (BHY2_LE2U32(x) | (uint64_t)(x)[4] << 32)
|
||||
#define BHY2_LE2U64(x) (BHY2_LE2U32(x) | (uint64_t)BHY2_LE2U32(&(x)[4]) << 32)
|
||||
|
||||
#define BHY2_LE24MUL(x) (((x) % 4) ? (uint16_t)((((x) / 4) + 1) * 4) : (uint16_t)((x) + 4))
|
||||
|
||||
/*! Maximum no of available virtual sensor */
|
||||
#define BHY2_N_VIRTUAL_SENSOR_MAX UINT8_C(256)
|
||||
|
||||
#ifndef BHY2_MAX_SIMUL_SENSORS
|
||||
#define BHY2_MAX_SIMUL_SENSORS 48
|
||||
#endif
|
||||
|
||||
/* Special & debug virtual sensor id starts at 245 */
|
||||
#define BHY2_SPECIAL_SENSOR_ID_OFFSET UINT8_C(245)
|
||||
|
||||
#ifndef BHY2_INTF_RET_TYPE
|
||||
#define BHY2_INTF_RET_TYPE int8_t
|
||||
#endif
|
||||
|
||||
#ifndef BHY2_INTF_RET_SUCCESS
|
||||
#define BHY2_INTF_RET_SUCCESS 0
|
||||
#endif
|
||||
|
||||
/* Type definitions for the function pointers */
|
||||
typedef BHY2_INTF_RET_TYPE (*bhy2_read_fptr_t)(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr);
|
||||
typedef BHY2_INTF_RET_TYPE (*bhy2_write_fptr_t)(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length,
|
||||
void *intf_ptr);
|
||||
typedef void (*bhy2_delay_us_fptr_t)(uint32_t period_us, void *intf_ptr);
|
||||
|
||||
enum bhy2_intf {
|
||||
BHY2_SPI_INTERFACE = 1,
|
||||
BHY2_I2C_INTERFACE
|
||||
};
|
||||
|
||||
/* HIF device structure */
|
||||
struct bhy2_hif_dev {
|
||||
bhy2_read_fptr_t read;
|
||||
bhy2_write_fptr_t write;
|
||||
bhy2_delay_us_fptr_t delay_us;
|
||||
enum bhy2_intf intf;
|
||||
void *intf_ptr;
|
||||
BHY2_INTF_RET_TYPE intf_rslt;
|
||||
uint32_t read_write_len;
|
||||
};
|
||||
|
||||
enum bhy2_fifo_type {
|
||||
BHY2_FIFO_TYPE_WAKEUP,
|
||||
BHY2_FIFO_TYPE_NON_WAKEUP,
|
||||
BHY2_FIFO_TYPE_STATUS,
|
||||
BHY2_FIFO_TYPE_MAX
|
||||
};
|
||||
|
||||
struct BHY2_PACKED bhy2_fifo_parse_data_info {
|
||||
uint8_t sensor_id;
|
||||
enum bhy2_fifo_type fifo_type;
|
||||
uint8_t data_size;
|
||||
uint8_t *data_ptr;
|
||||
uint64_t *time_stamp;
|
||||
};
|
||||
|
||||
typedef void (*bhy2_fifo_parse_callback_t)(const struct bhy2_fifo_parse_data_info *callback_info, void *private_data);
|
||||
|
||||
struct BHY2_PACKED bhy2_fifo_parse_callback_table {
|
||||
uint8_t sensor_id;
|
||||
bhy2_fifo_parse_callback_t callback;
|
||||
void *callback_ref;
|
||||
};
|
||||
|
||||
/* Device structure */
|
||||
struct bhy2_dev {
|
||||
struct bhy2_hif_dev hif;
|
||||
struct bhy2_fifo_parse_callback_table table[BHY2_MAX_SIMUL_SENSORS];
|
||||
uint8_t event_size[BHY2_N_VIRTUAL_SENSOR_MAX];
|
||||
uint64_t last_time_stamp[BHY2_FIFO_TYPE_MAX];
|
||||
uint8_t present_buff[32];
|
||||
};
|
||||
|
||||
struct bhy2_fifo_buffer {
|
||||
uint32_t read_pos;
|
||||
uint32_t read_length;
|
||||
uint32_t remain_length;
|
||||
uint32_t buffer_size;
|
||||
uint8_t *buffer;
|
||||
};
|
||||
|
||||
typedef int16_t (*bhy2_frame_parse_func_t)(struct bhy2_fifo_buffer *p_fifo_buffer, struct bhy2_dev *bhy2_p);
|
||||
|
||||
struct bhy2_virt_sensor_conf {
|
||||
uint16_t sensitivity;
|
||||
uint16_t range;
|
||||
uint32_t latency;
|
||||
bhy2_float sample_rate;
|
||||
};
|
||||
|
||||
struct bhy2_data_xyz {
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int16_t z;
|
||||
};
|
||||
|
||||
struct bhy2_data_quaternion {
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int16_t z;
|
||||
int16_t w;
|
||||
uint16_t accuracy;
|
||||
};
|
||||
|
||||
struct bhy2_data_orientation {
|
||||
int16_t heading;
|
||||
int16_t pitch;
|
||||
int16_t roll;
|
||||
};
|
||||
|
||||
union BHY2_PACKED bhy2_spt_dev_id {
|
||||
uint8_t slave_address;
|
||||
uint8_t cs_pin;
|
||||
};
|
||||
|
||||
struct BHY2_PACKED bhy2_spt_bits {
|
||||
/*! byte 1 */
|
||||
uint8_t direction : 1; /**< 0: read; 1: write. */
|
||||
uint8_t trans_type : 1; /**< 0: single burst; 1:multi single transfers. */
|
||||
uint8_t delay_ctrl : 1; /**< 0: none; 1: delay between bytes. */
|
||||
uint8_t master_bus : 2; /**< 1: SIF1; 2: SIF2; 3:SIF3. */
|
||||
uint8_t spi_mode : 1; /**< 0: 4 wire; 1: 3 wire. */
|
||||
uint8_t cpol : 1; /**< spi clock polarity. */
|
||||
uint8_t cpha : 1; /**< spi clock phase. */
|
||||
/*! byte 2 */
|
||||
uint8_t delay_val : 6; /**< multiples of 50us. min is 200us (4LSB) */
|
||||
uint8_t cs_level : 1; /**< chip select level. */
|
||||
uint8_t lsb_first : 1; /**< least significant byte first. */
|
||||
/*! byte 3~4 */
|
||||
uint16_t trans_rate; /**< spi clock rate. */
|
||||
/*! byte 5 */
|
||||
uint8_t address_shift : 4; /**< number of bits to shift register address. */
|
||||
uint8_t read_bit_pol : 1; /**< 0: active low; 1: active high. */
|
||||
uint8_t read_bit_pos : 3; /**< bit number of read bit in command byte. */
|
||||
/*! byte 6 */
|
||||
union bhy2_spt_dev_id func_set;
|
||||
|
||||
/*! byte 7 */
|
||||
uint8_t trans_count;
|
||||
|
||||
/*! byte 8 */
|
||||
uint8_t reg;
|
||||
};
|
||||
|
||||
union bhy2_soft_passthrough_conf {
|
||||
struct bhy2_spt_bits conf;
|
||||
uint8_t data[8];
|
||||
};
|
||||
|
||||
union bhy2_u16_conv {
|
||||
uint16_t u16_val;
|
||||
uint8_t bytes[2];
|
||||
};
|
||||
union bhy2_u32_conv {
|
||||
uint32_t u32_val;
|
||||
uint8_t bytes[4];
|
||||
};
|
||||
union bhy2_float_conv {
|
||||
bhy2_float f_val;
|
||||
uint32_t u32_val;
|
||||
uint8_t bytes[4];
|
||||
};
|
||||
struct bhy2_sensor_info {
|
||||
uint8_t sensor_type;
|
||||
uint8_t driver_id;
|
||||
uint8_t driver_version;
|
||||
uint8_t power;
|
||||
union bhy2_u16_conv max_range;
|
||||
union bhy2_u16_conv resolution;
|
||||
union bhy2_float_conv max_rate;
|
||||
union bhy2_u32_conv fifo_reserved;
|
||||
union bhy2_u32_conv fifo_max;
|
||||
uint8_t event_size;
|
||||
union bhy2_float_conv min_rate;
|
||||
};
|
||||
|
||||
struct bhy2_phys_sensor_info {
|
||||
uint8_t sensor_type;
|
||||
uint8_t driver_id;
|
||||
uint8_t driver_version;
|
||||
uint8_t power_current;
|
||||
union bhy2_u16_conv curr_range;
|
||||
uint8_t flags;
|
||||
uint8_t slave_address;
|
||||
uint8_t gpio_assignment;
|
||||
union bhy2_float_conv curr_rate;
|
||||
uint8_t num_axis;
|
||||
uint8_t orientation_matrix[5];
|
||||
uint8_t reserved;
|
||||
};
|
||||
|
||||
struct bhy2_self_test_resp {
|
||||
uint8_t test_status;
|
||||
int16_t x_offset, y_offset, z_offset;
|
||||
};
|
||||
|
||||
struct bhy2_foc_resp {
|
||||
uint8_t foc_status;
|
||||
int16_t x_offset, y_offset, z_offset;
|
||||
};
|
||||
|
||||
struct bhy2_orient_matrix {
|
||||
int8_t c[9];
|
||||
};
|
||||
|
||||
enum bhy2_data_inj_mode {
|
||||
BHY2_NORMAL_MODE = 0,
|
||||
BHY2_REAL_TIME_INJECTION = 1,
|
||||
BHY2_STEP_BY_STEP_INJECTION = 2
|
||||
};
|
||||
|
||||
#define BHY2_BYTE_TO_NIBBLE(X) (((uint8_t)(X)[0] & 0x0F) | (((uint8_t)(X)[1] << 4) & 0xF0))
|
||||
|
||||
/* End of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#endif /* __BHY2_DEFS_H__ */
|
||||
@@ -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 <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*********************************************************************/
|
||||
/* 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;
|
||||
}
|
||||
@@ -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 <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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_ */
|
||||
@@ -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 <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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_ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,576 @@
|
||||
/**
|
||||
* 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_hif.h
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __BHY2_HIF_H__
|
||||
#define __BHY2_HIF_H__
|
||||
|
||||
/* Start of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#include "bhy2_defs.h"
|
||||
|
||||
/**
|
||||
* @brief Function to link the callback interfaces
|
||||
* @param[in] intf : Physical communication interface
|
||||
* @param[in] read : Read function pointer
|
||||
* @param[in] write : Write function pointer
|
||||
* @param[in] delay_us : Microsecond delay function pointer
|
||||
* @param[in] read_write_len : Maximum read/write lengths supported
|
||||
* @param[in] intf_ptr : Reference to the interface. Can be NULL
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_init(enum bhy2_intf intf,
|
||||
bhy2_read_fptr_t read,
|
||||
bhy2_write_fptr_t write,
|
||||
bhy2_delay_us_fptr_t delay_us,
|
||||
uint32_t read_write_len,
|
||||
void *intf_ptr,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get data from registers
|
||||
* @param[in] reg_addr : Register address to be read from
|
||||
* @param[out] reg_data : Reference to the data buffer
|
||||
* @param[in] length : Length of the data buffer
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to set data to registers
|
||||
* @param[in] reg_addr : Register address to write to
|
||||
* @param[in] reg_data : Reference to the data buffer
|
||||
* @param[in] length : Length of the data buffer
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to delay in microseconds
|
||||
* @param[in] period_us : Period to delay in microseconds
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_delay_us(uint32_t period_us, const struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* Function to execute a command
|
||||
* @param[in] cmd : Command code
|
||||
* @param[in] payload : Reference to the data buffer containing the command's payload
|
||||
* @param[in] length : Length of the data buffer
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_exec_cmd(uint16_t cmd, const uint8_t *payload, uint32_t length, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get a parameter
|
||||
* @param[in] param : Parameter ID
|
||||
* @param[out] payload : Reference to the data buffer to store the parameter's payload
|
||||
* @param[in] payload_len : Length of the data buffer
|
||||
* @param[out] actual_len : Actual length of the payload
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_parameter(uint16_t param,
|
||||
uint8_t *payload,
|
||||
uint32_t payload_len,
|
||||
uint32_t *actual_len,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to set a parameter
|
||||
* @param[in] param : Parameter ID
|
||||
* @param[in] payload : Reference to the data buffer storing the parameter's payload
|
||||
* @param[in] length : Length of the data buffer
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_set_parameter(uint16_t param, const uint8_t *payload, uint32_t length, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to erase the flash
|
||||
* @param[in] start_addr : Start address
|
||||
* @param[in] end_addr : End address
|
||||
* @param[in] hif : HIF device address
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_erase_flash(uint32_t start_addr, uint32_t end_addr, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to upload data to flash
|
||||
* @param[in] firmware : Reference to the data buffer storing the firmware
|
||||
* @param[in] length : Length of the data buffer
|
||||
* @param[in/out] work_buffer : Reference to the work buffer
|
||||
* @param[in] work_buf_len : Length of the work buffer
|
||||
* @param[out] exp_size : Expected size of the work buffer if insufficient size
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_upload_to_flash(const uint8_t *firmware,
|
||||
uint32_t length,
|
||||
uint8_t *work_buffer,
|
||||
uint32_t work_buf_len,
|
||||
uint32_t *exp_size,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to upload data to flash partly
|
||||
* @param[in] firmware : Reference cur_pos of the data buffer storing the firmware
|
||||
* @param[in] cur_pos : Current position of the firmware
|
||||
* @param[in] packet_len : Length of the firmware packet to be transferred
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_upload_to_flash_partly(const uint8_t *firmware,
|
||||
uint32_t cur_pos,
|
||||
uint32_t packet_len,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to boot from flash
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_boot_from_flash(struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get the product ID
|
||||
* @param[out] product_id : Reference to the data buffer to store the product ID
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_product_id(uint8_t *product_id, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get the chip ID
|
||||
* @param[out] chip_id : Reference to the data buffer to store the chip ID
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_chip_id(uint8_t *chip_id, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get the ROM version
|
||||
* @param[out] rom_version : Reference to the data buffer to store the ROM version
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_rom_version(uint16_t *rom_version, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get the kernel version
|
||||
* @param[out] kernel_version : Reference to the data buffer to store the kernel version
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_kernel_version(uint16_t *kernel_version, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get the user version
|
||||
* @param[out] user_version : Reference to the data buffer to store the user version
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_user_version(uint16_t *user_version, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get the boot status
|
||||
* @param[out] boot_status : Reference to the data buffer to store the boot status
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_boot_status(uint8_t *boot_status, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get the host status
|
||||
* @param[out] host_status : Reference to the data buffer to store the host status
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_host_status(uint8_t *host_status, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get the feature status
|
||||
* @param[out] feat_status : Reference to the data buffer to store the feature status
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_feature_status(uint8_t *feat_status, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function get the interrupt status
|
||||
* @param[out] int_status : Reference to the data buffer to store the interrupt status
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_interrupt_status(uint8_t *int_status, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function get the firmware error code
|
||||
* @param[out] fw_error : Reference to the data buffer to store the firmware error code
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error code
|
||||
*/
|
||||
int8_t bhy2_hif_get_fw_error(uint8_t *fw_error, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to trigger a soft reset
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_reset(struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to upload a firmware to RAM
|
||||
* @param[in] firmware : Reference to the data buffer storing the firmware
|
||||
* @param[in] length : Length of the firmware
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_upload_firmware_to_ram(const uint8_t *firmware, uint32_t length, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to upload a part of the firmware to RAM
|
||||
* @param[in] firmware : Reference to the data buffer storing the current part of firmware
|
||||
* @param[in] total_size : Total size of the firmware
|
||||
* @param[in] cur_pos : Current position of the firmware
|
||||
* @param[in] packet_len : Size of firmware part to be uploaded
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_upload_firmware_to_ram_partly(const uint8_t *firmware,
|
||||
uint32_t total_size,
|
||||
uint32_t cur_pos,
|
||||
uint32_t packet_len,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to boot from RAM
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_boot_program_ram(struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get data from the Wake-up FIFO
|
||||
* @param[out] fifo : Reference to the data buffer to store data from the FIFO
|
||||
* @param[in] fifo_len : Length of the data buffer
|
||||
* @param[out] bytes_read : Number of bytes read into the data buffer
|
||||
* @param[out] bytes_remain : Bytes remaining in the sensor FIFO
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_wakeup_fifo(uint8_t *fifo,
|
||||
uint32_t fifo_len,
|
||||
uint32_t *bytes_read,
|
||||
uint32_t *bytes_remain,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get data from the Non-wake-up FIFO
|
||||
* @param[out] fifo : Reference to the data buffer to store data from the FIFO
|
||||
* @param[in] fifo_len : Length of the data buffer
|
||||
* @param[out] bytes_read : Number of bytes read into the data buffer
|
||||
* @param[out] bytes_remain : Bytes remaining in the sensor FIFO
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_nonwakeup_fifo(uint8_t *fifo,
|
||||
uint32_t fifo_len,
|
||||
uint32_t *bytes_read,
|
||||
uint32_t *bytes_remain,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get synchronous data from the Status FIFO
|
||||
* @param[out] status_code : Status code received
|
||||
* @param[out] fifo : Reference to the data buffer to store the payload of the status code
|
||||
* @param[in] fifo_len : Length of the data buffer
|
||||
* @param[out] bytes_remain : Number of bytes in the payload
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_status_fifo(uint16_t *status_code,
|
||||
uint8_t *fifo,
|
||||
uint32_t fifo_len,
|
||||
uint32_t *bytes_remain,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get asynchronous data from the Status FIFO
|
||||
* @param[out] fifo : Reference to the data buffer to store data from the FIFO
|
||||
* @param[in] fifo_len : Length of the data buffer
|
||||
* @param[out] bytes_read : Number of bytes read into the data buffer
|
||||
* @param[out] bytes_remain : Bytes remaining in the sensor FIFO
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_status_fifo_async(uint8_t *fifo,
|
||||
uint32_t fifo_len,
|
||||
uint32_t *bytes_read,
|
||||
uint32_t *bytes_remain,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to configure a virtual sensor
|
||||
* @param[in] sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[in] sample_rate : Sample rate in Hz
|
||||
* @param[in] latency : Report latency in milliseconds
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_exec_sensor_conf_cmd(uint8_t sensor_id,
|
||||
bhy2_float sample_rate,
|
||||
uint32_t latency,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to flush data of a virtual sensor from the FIFOs
|
||||
* @param[in] sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_set_fifo_flush(uint8_t sensor_id, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to perform a self-test for a particular virtual sensor
|
||||
* @param[in] phys_sensor_id : Physical sensor ID of the virtual sensor
|
||||
* @param[out] self_test_resp : Reference to the data buffer to store the self-test response
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_do_self_test(uint8_t phys_sensor_id,
|
||||
struct bhy2_self_test_resp *self_test_resp,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to perform a fast offset compensation for a particular virtual sensor
|
||||
* @param[in] phys_sensor_id : Physical Sensor ID of the virtual sensor
|
||||
* @param[out] foc_resp : Reference to the data buffer to store the FOC response
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_do_foc(uint8_t phys_sensor_id, struct bhy2_foc_resp *foc_resp, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get the sensor control configuration of a virtual sensor
|
||||
* @param[in] sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[in] ctrl_code : Sensor control code
|
||||
* @param[out] payload : Reference to the data buffer to store the sensor control
|
||||
* @param[in] payload_len : Length of the data buffer
|
||||
* @param[out] actual_len : Actual length of the sensor control configuration
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_sensor_ctrl(uint8_t sensor_id,
|
||||
uint8_t ctrl_code,
|
||||
uint8_t *payload,
|
||||
uint32_t payload_len,
|
||||
uint32_t *actual_len,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to set the sensor control configuration of a virtual sensor
|
||||
* @param[in] sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[in] ctrl_code : Sensor control code
|
||||
* @param[in] payload : Reference to the data buffer storing the sensor control
|
||||
* @param[in] payload_len : Length of the sensor control configuration
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_set_sensor_ctrl(uint8_t sensor_id,
|
||||
uint8_t ctrl_code,
|
||||
const uint8_t *payload,
|
||||
uint32_t payload_len,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get the BSX state of a BSX parameter
|
||||
* @param[in] param_id : Parameter ID of the BSX parameter
|
||||
* @param[out] bsx_state : Reference to teh data buffer to store the BSX state
|
||||
* @param[in] state_len : Length of the buffer
|
||||
* @param[out] actual_len : Actual length of the BSX state
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_bsx_state(uint16_t param_id,
|
||||
uint8_t *bsx_state,
|
||||
uint32_t state_len,
|
||||
uint32_t *actual_len,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to the BSX state of a BSX parameter
|
||||
* @param[in] param_id : Parameter ID of the BSX parameter
|
||||
* @param[in] bsx_state : Reference to the data buffer storing the BSX state
|
||||
* @param[in] state_len : Length of the BSX state
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_set_bsx_state(uint16_t param_id, const uint8_t *bsx_state, uint32_t state_len,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to request a timestamp event
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_request_hw_timestamp(struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get the hardware timestamp
|
||||
* @param[out] ts_ticks : Reference to the data buffer to store the timestamp in ticks
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_hw_timestamp(uint64_t *ts_ticks, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to request and get the hardware timestamp
|
||||
* @param[out] ts_ticks : Reference to the data buffer to store the timestamp in ticks
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_req_and_get_hw_timestamp(uint64_t *ts_ticks, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to communicate with connected sensors
|
||||
* @param[in] payload : Command payload
|
||||
* @param[in] payload_len : Payload length
|
||||
* @param[in/out] reg_data : Reference to the data buffer storing the register data
|
||||
* @param[in] length : Length of the data buffer
|
||||
* @param[out] actual_len : Registers actually read
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_exec_soft_passthrough(const uint8_t *payload,
|
||||
uint32_t payload_len,
|
||||
uint8_t *reg_data,
|
||||
uint32_t length,
|
||||
uint32_t *actual_len,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get the post-mortem data dump
|
||||
* @param[out] code : Post-mortem status code
|
||||
* @param[out] actual_len : Actual length of the post-mortem data dump
|
||||
* @param[out] post_mortem : Reference to the data buffer to store the data dump
|
||||
* @param[in] buffer_len : Length of the data buffer
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_post_mortem(uint16_t *code,
|
||||
uint32_t *actual_len,
|
||||
uint8_t *post_mortem,
|
||||
uint32_t buffer_len,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function get information of a virtual sensor
|
||||
* @param[in] sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[out] info : Reference to the data buffer to store the sensor info
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_sensor_info(uint8_t sensor_id, struct bhy2_sensor_info *info, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get the physical sensor information of a virtual sensor
|
||||
* @param[in] sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[out] info : Reference to the data buffer to store the physical sensor info
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_get_phys_sensor_info(uint8_t sensor_id, struct bhy2_phys_sensor_info *info, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to get the orientation matrix of a virtual sensor
|
||||
* @param[in] sensor_id : Sensor ID of the virtual sensor
|
||||
* @param[out] orient_matrix : Reference to the data buffer to store the orientation matrix
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_set_orientation_matrix(uint8_t sensor_id,
|
||||
struct bhy2_orient_matrix orient_matrix,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to set the data injection mode
|
||||
* @param[in] payload : Reference to the data buffer containing the host injection mode
|
||||
* @param[in] payload_len : Length of the data buffer
|
||||
* @param[in/out] work_buf : Reference to the work buffer
|
||||
* @param[in] work_buf_len : Length of the work buffer
|
||||
* @param[out] actual_len : Expected length of the work buffer
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_set_inject_data_mode(const uint8_t *payload,
|
||||
uint8_t payload_len,
|
||||
const uint8_t *work_buf,
|
||||
uint32_t work_buf_len,
|
||||
const uint32_t *actual_len,
|
||||
struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to inject data
|
||||
* @param[in] payload : Reference to the data buffer
|
||||
* @param[in] payload_len : Length of the data buffer
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_inject_data(const uint8_t *payload, uint32_t payload_len, struct bhy2_hif_dev *hif);
|
||||
|
||||
/**
|
||||
* @brief Function to wait till status is ready
|
||||
* @param[in] hif : HIF device reference
|
||||
* @return API error codes
|
||||
*/
|
||||
int8_t bhy2_hif_wait_status_ready(struct bhy2_hif_dev *hif);
|
||||
|
||||
/* End of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#endif /* __BHY2_HIF_H__ */
|
||||
@@ -0,0 +1,373 @@
|
||||
/**
|
||||
* 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_klio.c
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************************************************************/
|
||||
/* system header files */
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*********************************************************************/
|
||||
/* BHY2 SensorAPI header files */
|
||||
#include "bhy2.h"
|
||||
|
||||
/*********************************************************************/
|
||||
/* own header files */
|
||||
#include "bhy2_klio.h"
|
||||
|
||||
int8_t bhy2_klio_read_pattern(const uint8_t id, uint8_t *buffer, uint16_t *length, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt;
|
||||
uint32_t ret_len;
|
||||
bhy2_klio_pattern_transfer_t pattern = { 0 };
|
||||
|
||||
if (!buffer || !length || !dev)
|
||||
{
|
||||
return BHY2_E_NULL_PTR;
|
||||
}
|
||||
|
||||
if (id != 0 || *length < sizeof(pattern.pattern_data))
|
||||
{
|
||||
return BHY2_E_INVALID_PARAM;
|
||||
}
|
||||
|
||||
rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN), (uint8_t*)&pattern, sizeof(pattern), &ret_len, dev);
|
||||
|
||||
if (rslt != BHY2_OK)
|
||||
{
|
||||
return rslt;
|
||||
}
|
||||
|
||||
if (ret_len != sizeof(pattern))
|
||||
{
|
||||
return BHY2_E_INVALID_PARAM;
|
||||
}
|
||||
|
||||
memcpy(buffer, pattern.pattern_data, pattern.full_size);
|
||||
*length = pattern.full_size;
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
int8_t bhy2_klio_read_reset_driver_status(uint32_t *klio_driver_status, struct bhy2_dev *dev)
|
||||
{
|
||||
uint32_t ret_len = 0;
|
||||
int8_t rslt;
|
||||
|
||||
if (!klio_driver_status || !dev)
|
||||
{
|
||||
return BHY2_E_NULL_PTR;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
rslt =
|
||||
bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_DRIVER_STATUS),
|
||||
(uint8_t*)klio_driver_status,
|
||||
sizeof(*klio_driver_status),
|
||||
&ret_len,
|
||||
dev);
|
||||
|
||||
if (rslt != BHY2_OK)
|
||||
{
|
||||
return rslt;
|
||||
}
|
||||
} while (*klio_driver_status == KLIO_DRIVER_ERROR_OPERATION_PENDING);
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
int8_t bhy2_klio_write_pattern(const uint8_t idx, const uint8_t *pattern_data, const uint16_t size,
|
||||
struct bhy2_dev *dev)
|
||||
{
|
||||
bhy2_klio_pattern_transfer_t pattern = {
|
||||
.block_id = 0, .block_size = (uint8_t)size, .full_size = size, .pattern_id = idx, .pattern_data = { 0 }
|
||||
};
|
||||
|
||||
if (!dev || size > sizeof(pattern.pattern_data))
|
||||
{
|
||||
return BHY2_E_INVALID_PARAM;
|
||||
}
|
||||
|
||||
memcpy(pattern.pattern_data, pattern_data, size);
|
||||
|
||||
return bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN), (const uint8_t*)&pattern, sizeof(pattern), dev);
|
||||
}
|
||||
|
||||
int8_t bhy2_klio_set_pattern_states(const bhy2_klio_pattern_state_t operation,
|
||||
const uint8_t *pattern_ids,
|
||||
const uint16_t count,
|
||||
struct bhy2_dev *dev)
|
||||
{
|
||||
uint32_t buffer_size = sizeof(bhy2_klio_pattern_state_op_t) + count;
|
||||
uint8_t buffer[buffer_size];
|
||||
|
||||
if (!dev || count == 0)
|
||||
{
|
||||
return BHY2_E_INVALID_PARAM;
|
||||
}
|
||||
|
||||
buffer[1] = (uint8_t)count;
|
||||
buffer[0] = operation;
|
||||
|
||||
for (uint8_t i = 0; i < count; i++)
|
||||
{
|
||||
buffer[i + 2] = pattern_ids[i];
|
||||
}
|
||||
|
||||
return bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_STATE), buffer, buffer_size, dev);
|
||||
}
|
||||
|
||||
int8_t bhy2_klio_set_state(const bhy2_klio_sensor_state_t *state, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
uint8_t buffer[4];
|
||||
|
||||
if (!dev || !state)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[0] = state->learning_enabled;
|
||||
buffer[1] = state->learning_reset;
|
||||
buffer[2] = state->recognition_enabled;
|
||||
buffer[3] = state->recognition_reset;
|
||||
|
||||
rslt = bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_ALGORITHM_STATE), buffer, sizeof(buffer), dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
int8_t bhy2_klio_get_state(bhy2_klio_sensor_state_t *state, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if (!dev || !state)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t buffer[4];
|
||||
uint32_t ret_len;
|
||||
|
||||
rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_ALGORITHM_STATE), buffer, sizeof(buffer), &ret_len, dev);
|
||||
if (rslt == BHY2_OK && ret_len == sizeof(buffer))
|
||||
{
|
||||
state->learning_enabled = buffer[0];
|
||||
state->learning_reset = buffer[1];
|
||||
state->recognition_enabled = buffer[2];
|
||||
state->recognition_reset = buffer[3];
|
||||
}
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
int8_t bhy2_klio_similarity_score(const uint8_t *first_pattern,
|
||||
const uint8_t *second_pattern,
|
||||
const uint16_t size,
|
||||
float *similarity,
|
||||
struct bhy2_dev *dev)
|
||||
{
|
||||
uint32_t klio_driver_status = 0;
|
||||
int8_t rslt;
|
||||
uint32_t ret_len;
|
||||
bhy2_klio_pattern_transfer_t pattern1 = { 0 }, pattern2 = { 0 };
|
||||
uint8_t buffer[4];
|
||||
|
||||
if (!dev || size > sizeof(pattern1.pattern_data))
|
||||
{
|
||||
return BHY2_E_INVALID_PARAM;
|
||||
}
|
||||
|
||||
pattern1.block_size = pattern2.block_size = (uint8_t)size;
|
||||
pattern1.full_size = pattern2.full_size = size;
|
||||
memcpy(pattern1.pattern_data, first_pattern, size);
|
||||
memcpy(pattern2.pattern_data, second_pattern, size);
|
||||
|
||||
rslt =
|
||||
bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_SIMILARITY), (uint8_t*)&pattern1, sizeof(pattern1), dev);
|
||||
if (rslt != BHY2_OK)
|
||||
{
|
||||
return rslt;
|
||||
}
|
||||
|
||||
rslt =
|
||||
bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_SIMILARITY), (uint8_t*)&pattern2, sizeof(pattern2), dev);
|
||||
if (rslt != BHY2_OK)
|
||||
{
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/* Wait for similarity calculation to complete. */
|
||||
rslt = bhy2_klio_read_reset_driver_status(&klio_driver_status, dev);
|
||||
if (rslt != BHY2_OK || klio_driver_status != KLIO_DRIVER_ERROR_NONE)
|
||||
{
|
||||
return BHY2_E_INVALID_PARAM;
|
||||
}
|
||||
|
||||
rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_SIMILARITY), buffer, sizeof(buffer), &ret_len, dev);
|
||||
if (rslt != BHY2_OK)
|
||||
{
|
||||
return rslt;
|
||||
}
|
||||
|
||||
if (ret_len != sizeof(buffer))
|
||||
{
|
||||
return BHY2_E_INVALID_PARAM;
|
||||
}
|
||||
|
||||
memcpy(similarity, buffer, sizeof(*similarity));
|
||||
|
||||
return BHY2_OK;
|
||||
}
|
||||
|
||||
int8_t bhy2_klio_similarity_score_multiple(const uint8_t idx,
|
||||
const uint8_t *indexes,
|
||||
const uint8_t count,
|
||||
float *similarity,
|
||||
struct bhy2_dev *dev)
|
||||
{
|
||||
uint32_t klio_driver_status;
|
||||
int8_t rslt;
|
||||
uint32_t ret_len;
|
||||
uint32_t buffer_size = sizeof(bhy2_klio_similarity_calculation_t) + count;
|
||||
|
||||
buffer_size = BHY2_ROUND_WORD_HIGHER(buffer_size);
|
||||
uint8_t buffer[256] = { 0 };
|
||||
|
||||
if (!indexes || !similarity || !dev)
|
||||
{
|
||||
return BHY2_E_NULL_PTR;
|
||||
}
|
||||
|
||||
/* buffer[0-3] values are initialized to zero's to distinguish from regular pattern comparison*/
|
||||
buffer[4] = idx;
|
||||
buffer[5] = count;
|
||||
for (uint8_t i = 0; i < count; i++)
|
||||
{
|
||||
buffer[i + 6] = indexes[i];
|
||||
}
|
||||
|
||||
/* Start similarity calculations. */
|
||||
rslt = bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_SIMILARITY), (uint8_t*)buffer, buffer_size, dev);
|
||||
if (rslt != BHY2_OK)
|
||||
{
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/* Wait for similarity calculation to complete. */
|
||||
rslt = bhy2_klio_read_reset_driver_status(&klio_driver_status, dev);
|
||||
if (rslt != BHY2_OK || klio_driver_status != KLIO_DRIVER_ERROR_NONE)
|
||||
{
|
||||
return BHY2_E_INVALID_PARAM;
|
||||
}
|
||||
|
||||
/* Read similarity results. */
|
||||
rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_SIMILARITY),
|
||||
(uint8_t *)similarity,
|
||||
sizeof(float) * count,
|
||||
&ret_len,
|
||||
dev);
|
||||
if (rslt != BHY2_OK)
|
||||
{
|
||||
return rslt;
|
||||
}
|
||||
|
||||
return BHY2_OK;
|
||||
}
|
||||
|
||||
int8_t bhy2_klio_set_parameter(const bhy2_klio_parameter_t id,
|
||||
const void *parameter_data,
|
||||
const uint16_t size,
|
||||
struct bhy2_dev *dev)
|
||||
{
|
||||
bhy2_klio_parameter_wrapper_t buffer;
|
||||
|
||||
buffer.id = id;
|
||||
buffer.flags = 0;
|
||||
buffer.size = (uint8_t)size;
|
||||
memcpy(buffer.payload.data, parameter_data, size);
|
||||
|
||||
/* Size is 3 bytes header and buffer.size then rounded up to a four byte multiple. */
|
||||
return bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_ALGO_DRIVER_PARAMETER),
|
||||
(uint8_t*)&buffer,
|
||||
(3 + buffer.size + 3) & ~3,
|
||||
dev);
|
||||
}
|
||||
|
||||
int8_t bhy2_klio_get_parameter(const bhy2_klio_parameter_t id,
|
||||
uint8_t *parameter_data,
|
||||
uint16_t *size,
|
||||
struct bhy2_dev *dev)
|
||||
{
|
||||
uint32_t ret_len;
|
||||
uint8_t buffer[260] = { 0 };
|
||||
|
||||
buffer[0] = id;
|
||||
int8_t rslt;
|
||||
|
||||
/* Size is 3 bytes header and buffer.size then rounded up to a four byte multiple. */
|
||||
rslt = bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_ALGO_DRIVER_PARAMETER), buffer, (3 + buffer[2] + 3) & ~3, dev);
|
||||
if (rslt != BHY2_OK)
|
||||
{
|
||||
return rslt;
|
||||
}
|
||||
|
||||
rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_ALGO_DRIVER_PARAMETER), buffer, sizeof(buffer), &ret_len, dev);
|
||||
if (rslt != BHY2_OK)
|
||||
{
|
||||
return rslt;
|
||||
}
|
||||
|
||||
if (ret_len < 3 || buffer[2] > *size)
|
||||
{
|
||||
return BHY2_E_INVALID_PARAM;
|
||||
}
|
||||
|
||||
for (uint16_t i = 3, j = 0; i < buffer[2] + 3; i++, j++)
|
||||
{
|
||||
parameter_data[j] = buffer[i];
|
||||
}
|
||||
|
||||
*size = buffer[2];
|
||||
|
||||
return BHY2_OK;
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
/**
|
||||
* 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_klio.h
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __BHY2_KLIO_H__
|
||||
#define __BHY2_KLIO_H__
|
||||
|
||||
/* Start of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "bhy2.h"
|
||||
#include "bhy2_klio_defs.h"
|
||||
|
||||
/*!
|
||||
* @brief Reads and resets current driver status.
|
||||
*
|
||||
* The driver_status will be set to one of the values in
|
||||
* @ref bhy2_klio_driver_error_state_t. This function will not return a driver
|
||||
* status of
|
||||
* @ref bhy2_klio_driver_error_state_t::KLIO_DRIVER_ERROR_OPERATION_PENDING.
|
||||
* but will retry until the pending operation is finished.
|
||||
*
|
||||
* @param[out] driver_status Pointer to uint32_t
|
||||
* @param[in] dev Device reference.
|
||||
*
|
||||
* @return BHY2 API error codes.
|
||||
*/
|
||||
int8_t bhy2_klio_read_reset_driver_status(uint32_t *driver_status, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief Read learnt pattern.
|
||||
*
|
||||
* @param[in] id pattern id (only 0 supported now)
|
||||
* @param[out] buffer buffer big enough to fit complete pattern fingerprint data
|
||||
* @param[in,out] length size of buffer, return size of actual pattern data
|
||||
* @param[in] dev Device reference
|
||||
*
|
||||
* @return BHY2 API error codes.
|
||||
*
|
||||
* After learning of a new pattern has been signaled by a sensor data event,
|
||||
* call this function to retrieve the learnt pattern.
|
||||
*/
|
||||
int8_t bhy2_klio_read_pattern(const uint8_t id, uint8_t *buffer, uint16_t *length, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief Set KLIO algorithm learning and recognition state.
|
||||
*
|
||||
* @param[in] state new state for algorithm
|
||||
* @param[in] dev Device reference
|
||||
*
|
||||
* @return BHY2 API error codes.
|
||||
*
|
||||
* Writing 1 to the reset fields resets all internal algorithm state and
|
||||
* removes any patterns loaded for recognition.
|
||||
*/
|
||||
int8_t bhy2_klio_set_state(const bhy2_klio_sensor_state_t *state, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief Get KLIO algorithm learning and recognition state.
|
||||
*
|
||||
* @param[out] state current state for algorithm
|
||||
* @param[in] dev Device reference
|
||||
*
|
||||
* @return BHY2 API error codes.
|
||||
*
|
||||
* The resets are always read as 0.
|
||||
*/
|
||||
int8_t bhy2_klio_get_state(bhy2_klio_sensor_state_t *state, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief Write pattern to recognition algorithm.
|
||||
*
|
||||
* @param[in] idx pattern index
|
||||
* @param[in] pattern_data containing pattern
|
||||
* @param[in] size pattern size
|
||||
* @param[in] dev Device reference
|
||||
*
|
||||
* @return BHY2 API error codes.
|
||||
*
|
||||
* Write a pattern to the specified recognition index. The allowed number of
|
||||
* recognition patterns may be retrieved using the
|
||||
* @ref bhy2_klio_parameter::KLIO_PARAM_RECOGNITION_MAX_PATTERNS parameter.
|
||||
*
|
||||
* After a pattern is written, it is in disabled state and not used. It must
|
||||
* be enabled using @ref bhy2_klio_set_pattern_states() before it will be used
|
||||
* by the recognition algorithm.
|
||||
*/
|
||||
int8_t bhy2_klio_write_pattern(const uint8_t idx, const uint8_t *pattern_data, const uint16_t size,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief Sets the specified state for the specified pattern ids.
|
||||
*
|
||||
* @param[in] operation operation to perform
|
||||
* @param[in] pattern_ids ids of pattern(s) to perform operation on
|
||||
* @param[in] size size of pattern_ids array
|
||||
* @param[in] dev Device reference
|
||||
*
|
||||
* @return BHY2 API error codes.
|
||||
*/
|
||||
int8_t bhy2_klio_set_pattern_states(const bhy2_klio_pattern_state_t operation,
|
||||
const uint8_t *pattern_ids,
|
||||
const uint16_t size,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief Calculates similarity score between two patterns.
|
||||
*
|
||||
* The similariy between patterns is a meassure of the similarity between the
|
||||
* performed activities or exercises. If the two patterns represent the same
|
||||
* excercise the similarity will be close to 1.0, and if they are for very
|
||||
* different excercises, the similarity will be negative.
|
||||
*
|
||||
* @param[in] first_pattern Buffer containing first pattern.
|
||||
* @param[in] second_pattern Buffer containing second pattern.
|
||||
* @param[in] size Pattern size.
|
||||
* @param[out] similarity Similarity score.
|
||||
* @param[in] dev Device reference.
|
||||
*
|
||||
* @return BHY2 API error codes.
|
||||
*/
|
||||
int8_t bhy2_klio_similarity_score(const uint8_t *first_pattern,
|
||||
const uint8_t *second_pattern,
|
||||
const uint16_t size,
|
||||
float *similarity,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief Calculates similarity score between multiple patterns.
|
||||
*
|
||||
* This is more efficient than bhy2_klio_similarity_score() since if the patterns
|
||||
* are already available on the bhy2, they need not be uploaded again to
|
||||
* perform the comparison. And several comparisons may be performed with one
|
||||
* API call.
|
||||
*
|
||||
* @param[in] idx Reference pattern.
|
||||
* @param[in] indexes Buffer containing indexes of patterns to compare reference pattern with.
|
||||
* @param[in] count Number of patterns in indexes buffer.
|
||||
* @param[out] similarity Similarity scores (one score for each pattern in indexes buffer).
|
||||
* @param[in] dev Device reference.
|
||||
*
|
||||
* @return BHY2 API error codes.
|
||||
*/
|
||||
int8_t bhy2_klio_similarity_score_multiple(const uint8_t idx,
|
||||
const uint8_t *indexes,
|
||||
const uint8_t count,
|
||||
float *similarity,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief Set KLIO algorithm parameter
|
||||
*
|
||||
* @param[in] id Parameter to set.
|
||||
* @param[in] parameter_data Buffer containing new parameter value.
|
||||
* @param[in] size Parameter size.
|
||||
* @param[in] dev Device reference.
|
||||
*
|
||||
* @return BHY2 API error codes.
|
||||
*/
|
||||
int8_t bhy2_klio_set_parameter(const bhy2_klio_parameter_t id,
|
||||
const void *parameter_data,
|
||||
const uint16_t size,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief Get KLIO algorithm parameter
|
||||
*
|
||||
* @param[in] id Parameter id.
|
||||
* @param[out] parameter_data Buffer to store parameter data.
|
||||
* @param[in,out] size Parameter data size.
|
||||
* @param[in] dev Device reference.
|
||||
*
|
||||
* @return BHY2 API error codes.
|
||||
*
|
||||
* The expected type or buffer size of parameter_data for respective parameter
|
||||
* id is specified in the @ref bhy2_klio_parameter_t enum.
|
||||
*/
|
||||
int8_t bhy2_klio_get_parameter(const bhy2_klio_parameter_t id,
|
||||
uint8_t *parameter_data,
|
||||
uint16_t *size,
|
||||
struct bhy2_dev *dev);
|
||||
|
||||
/* End of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,349 @@
|
||||
/**
|
||||
* 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_klio_defs.h
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __BHY2_KLIO_DEFS_H__
|
||||
#define __BHY2_KLIO_DEFS_H__
|
||||
|
||||
/* Start of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define BHY2_SENSOR_ID_KLIO UINT8_C(112)
|
||||
#define BHY2_SENSOR_ID_KLIO_LOG UINT8_C(127)
|
||||
|
||||
#ifndef BHY2_KLIO_PAGE
|
||||
#define BHY2_KLIO_PAGE UINT16_C(9)
|
||||
#endif
|
||||
#define KLIO_PARAM(id) (((BHY2_KLIO_PAGE) << 8) | (id))
|
||||
|
||||
/*!
|
||||
* @enum bhy2_klio_parameter
|
||||
*
|
||||
* KLIO algorithm parameters
|
||||
*
|
||||
* @var bhy2_klio_parameter::KLIO_PARAM_ALGORITHM_VERSION
|
||||
* Algorithm version. (read)
|
||||
* @code{.c} char version[244]; @endcode
|
||||
*
|
||||
* @var bhy2_klio_parameter::KLIO_PARAM_RECOGNITION_RESPONSIVNESS
|
||||
* The approximate number of cycles / repetitions for recognition to recognize
|
||||
* an activity. (read / write)
|
||||
* @code{.c} float cycle_fraction; @endcode
|
||||
*
|
||||
* @var bhy2_klio_parameter::KLIO_PARAM_PATTERN_BLOB_SIZE
|
||||
* Pattern blob size in bytes. (read)
|
||||
* @code{.c} uint16_t pattern_blob_size; @endcode
|
||||
*
|
||||
* @var bhy2_klio_parameter::KLIO_PARAM_RECOGNITION_MAX_PATTERNS
|
||||
* Read Maximum number of patterns. (read)
|
||||
* @code{.c} uint16_t recognition_max_patterns; @endcode
|
||||
*
|
||||
* @var bhy2_klio_parameter::KLIO_PARAM_LEARNING_IGNORE_INSIG_MOVEMENT
|
||||
* Flag if insignificant movements should be ignored in learning. Value 0 or 1. (read / write)
|
||||
* @code{.c} uint8_t ignore_insig_movement; @endcode
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
KLIO_PARAM_ALGORITHM_VERSION = 0,
|
||||
KLIO_PARAM_RECOGNITION_SENSITIVITY = 1,
|
||||
KLIO_PARAM_RECOGNITION_RESPONSIVNESS = 2,
|
||||
KLIO_PARAM_LEARNING_SPEED = 3,
|
||||
KLIO_PARAM_LEARNING_SIMILARITY_THRESHOLD = 4,
|
||||
KLIO_PARAM_LEARNING_FREQUENCIES = 5,
|
||||
KLIO_PARAM_LEARNING_PROGRESS = 6,
|
||||
KLIO_PARAM_PATTERN_BLOB_SIZE = 7,
|
||||
KLIO_PARAM_RECOGNITION_MAX_PATTERNS = 8,
|
||||
KLIO_PARAM_INPUT_SENSORS = 9,
|
||||
KLIO_PARAM_LEARNING_IGNORE_INSIG_MOVEMENT = 10
|
||||
} bhy2_klio_parameter_t;
|
||||
|
||||
/*!
|
||||
*
|
||||
* @brief Convenience wrapper used in bhy2_klio.c algo parameter wrapper.
|
||||
*
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t id;
|
||||
uint8_t flags;
|
||||
uint8_t size;
|
||||
union
|
||||
{
|
||||
uint8_t data[244];
|
||||
char version[244];
|
||||
float cycle_fraction;
|
||||
uint16_t pattern_blob_size;
|
||||
uint16_t recognition_max_patterns;
|
||||
uint8_t ignore_insig_movement;
|
||||
} BHY2_PACKED payload;
|
||||
} BHY2_PACKED bhy2_klio_parameter_wrapper_t;
|
||||
|
||||
/*!
|
||||
*
|
||||
* @brief bhy2 klio state structure
|
||||
*
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t learning_enabled; /*!< 0 - disable learning, 1 - enable learning. */
|
||||
uint8_t learning_reset; /*!< 0 - nop, 1 - reset learning. Always read as 0. */
|
||||
uint8_t recognition_enabled; /*!< 0 - disable recognition, 1 - enable recognition. */
|
||||
uint8_t recognition_reset; /*!< 0 - nop, 1 - reset learning. Always read as 0. */
|
||||
} BHY2_PACKED bhy2_klio_sensor_state_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t instance;
|
||||
|
||||
/*!
|
||||
* A value of -1 means no new learning has occurred. If the value is >= 0,
|
||||
* then a new pattern has been learnt, and reading of this pattern may be
|
||||
* performed.
|
||||
*/
|
||||
int8_t index;
|
||||
|
||||
/*!
|
||||
* While learning a new pattern, this field counts from 0 to 100. When 100 is
|
||||
* reached a new pattern will be learnt. If learning is interrupted, this
|
||||
* progress will return to 0, and change reason will be set to indicate
|
||||
* why learning was interrupted.
|
||||
*/
|
||||
uint8_t progress;
|
||||
|
||||
/*!
|
||||
* | Value | Description |
|
||||
* |:-----:|:-----------------------------------------------------------------------|
|
||||
* | 0 | Learning is progressing. |
|
||||
* | 1 | Learning was interrupted by a non-repetitive activity. |
|
||||
* | 2 | Learning was interrupted because no significant movement was detected. |
|
||||
*/
|
||||
uint8_t change_reason;
|
||||
} BHY2_PACKED bhy2_klio_sensor_frame_learning_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t instance;
|
||||
|
||||
/*! The index of the recognized activity. 255 means no activity was
|
||||
* recognized. */
|
||||
uint8_t index;
|
||||
|
||||
/*! The current repetition count of the recognized activity. */
|
||||
float count;
|
||||
} BHY2_PACKED bhy2_klio_sensor_frame_recognition_t;
|
||||
|
||||
/*!
|
||||
*
|
||||
* @brief bhy2 klio combined data structure
|
||||
*
|
||||
* When the algorithm generates a new data frame, it is sent in this structure.
|
||||
*
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
bhy2_klio_sensor_frame_learning_t learn;
|
||||
bhy2_klio_sensor_frame_recognition_t recognize;
|
||||
} BHY2_PACKED bhy2_klio_sensor_frame_t;
|
||||
|
||||
/*!
|
||||
*
|
||||
* @brief bhy2 klio sensor log frame
|
||||
*
|
||||
* When the algorithm consumes a new set of samples, it is sent in this structure.
|
||||
*
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
float timestamp;
|
||||
float accel[3];
|
||||
float gyro[3];
|
||||
} BHY2_PACKED bhy2_klio_log_frame_t;
|
||||
|
||||
/*!
|
||||
*
|
||||
* @brief bhy2 klio pattern transfer format
|
||||
*
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t block_id; /*!< Write as 0. */
|
||||
uint8_t block_size; /*!< Write as 0. */
|
||||
|
||||
/*! Size of pattern_data in bytes. The size of patterns may be obtained
|
||||
using the @ref bhy2_klio_parameter::KLIO_PARAM_PATTERN_BLOB_SIZE
|
||||
parameter. */
|
||||
uint16_t full_size;
|
||||
|
||||
/*! Id of pattern to write. */
|
||||
uint8_t pattern_id;
|
||||
|
||||
/*! Actual pattern data describing the exercise. */
|
||||
uint8_t pattern_data[244];
|
||||
} BHY2_PACKED bhy2_klio_pattern_transfer_t;
|
||||
|
||||
/*!
|
||||
*
|
||||
* @brief Convenience wrapper used by @ref bhy2_klio_similarity_score_multiple().
|
||||
*
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t zero;
|
||||
uint8_t index;
|
||||
uint8_t count;
|
||||
uint8_t *indexes;
|
||||
} BHY2_PACKED bhy2_klio_similarity_calculation_t;
|
||||
|
||||
/*!
|
||||
*
|
||||
* @brief Convenience wrapper used by @ref bhy2_klio_set_pattern_states().
|
||||
*
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t operation;
|
||||
uint8_t count;
|
||||
uint8_t *indexes;
|
||||
} BHY2_PACKED bhy2_klio_pattern_state_op_t;
|
||||
|
||||
/*!
|
||||
* KLIO pattern state
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*!< disable pattern */
|
||||
KLIO_PATTERN_STATE_DISABLE = 0,
|
||||
|
||||
/*!< enable pattern */
|
||||
KLIO_PATTERN_STATE_ENABLE = 1,
|
||||
|
||||
/*!< switch hand */
|
||||
KLIO_PATTERN_STATE_SWITCH_HAND = 2,
|
||||
|
||||
/*!< disable adaptive pattern */
|
||||
KLIO_PATTERN_STATE_AP_DISABLE = 3
|
||||
} bhy2_klio_pattern_state_t;
|
||||
|
||||
/*!
|
||||
* @brief KLIO host interface parameter identifiers.
|
||||
*
|
||||
* The parameter id used when calling the BHY2 functions directly. E.g. to read the driver status this may be used.
|
||||
*
|
||||
* ~~~{.c}
|
||||
* uint32_t klio_driver_status = 0;
|
||||
* uint32_t ret_len = 0;
|
||||
* int8_t rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_DRIVER_STATUS),
|
||||
* (uint8_t*)&klio_driver_status,
|
||||
* sizeof(klio_driver_status),
|
||||
* &ret_len,
|
||||
* dev);
|
||||
* if (rslt != BHY2_OK)
|
||||
* {
|
||||
* return rslt;
|
||||
* }
|
||||
* ~~~
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*!< Read and write algorighm state. */
|
||||
KLIO_HIF_PARAM_ALGORITHM_STATE = 0,
|
||||
|
||||
/*!< Read and write patterns. */
|
||||
KLIO_HIF_PARAM_PATTERN = 1,
|
||||
|
||||
/*!< Read and write algorithm parameters. */
|
||||
KLIO_HIF_PARAM_ALGO_DRIVER_PARAMETER = 2,
|
||||
KLIO_HIF_PARAM_STATISTIC = 3,
|
||||
KLIO_HIF_PARAM_PATTERN_STATE = 4,
|
||||
|
||||
/*!< Perform pattern similarity. */
|
||||
KLIO_HIF_PARAM_PATTERN_SIMILARITY = 5,
|
||||
KLIO_HIF_PARAM_PATTERN_COMBINING = 6,
|
||||
|
||||
/*!< Read driver status. */
|
||||
KLIO_HIF_PARAM_DRIVER_STATUS = 7
|
||||
} bhy2_klio_hif_parameter_t;
|
||||
|
||||
/*!
|
||||
* KLIO driver error codes
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/*!< No error. */
|
||||
KLIO_DRIVER_ERROR_NONE = 0,
|
||||
|
||||
/*!< Invalid parameter. */
|
||||
KLIO_DRIVER_ERROR_INVALID_PARAMETER = 1,
|
||||
|
||||
/*!< Parameter out of range. */
|
||||
KLIO_DRIVER_ERROR_PARAMETER_OUT_OF_RANGE = 2,
|
||||
|
||||
/*!
|
||||
* Invalid pattern operation. E.g. trying to read a learnt pattern when no
|
||||
* pattern has been learnt, or trying to write an invalid pattern.
|
||||
*/
|
||||
KLIO_DRIVER_ERROR_INVALID_PATTERN_OPERATION = 3,
|
||||
|
||||
/*!< Not implemented. */
|
||||
KLIO_DRIVER_ERROR_NOT_IMPLEMENTED = 4,
|
||||
|
||||
/*!< Insufficient buffer size */
|
||||
KLIO_DRIVER_ERROR_BUFSIZE = 5,
|
||||
|
||||
/*!< Internal error. */
|
||||
KLIO_DRIVER_ERROR_INTERNAL = 6,
|
||||
|
||||
/*!< Undefined error */
|
||||
KLIO_DRIVER_ERROR_UNDEFINED = 7,
|
||||
|
||||
/*!
|
||||
* Previous operation is still progressing. Read driver status again until
|
||||
* operation is finished.
|
||||
*/
|
||||
KLIO_DRIVER_ERROR_OPERATION_PENDING = 8
|
||||
} bhy2_klio_driver_error_state_t;
|
||||
|
||||
/* End of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#endif /* __BHY2_KLIO_DEFS_H__ */
|
||||
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* 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_parse.c
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
#include "bhy2.h"
|
||||
#include "bhy2_parse.h"
|
||||
|
||||
void bhy2_parse_temperature_celsius(const uint8_t *data, bhy2_float *temperature)
|
||||
{
|
||||
/* 1 LSB = 1/100 degC */
|
||||
float scale_factor = (float)1 / 100;
|
||||
|
||||
*temperature = BHY2_LE2S16(data) * scale_factor;
|
||||
}
|
||||
|
||||
void bhy2_parse_humidity(const uint8_t *data, bhy2_float *humidity)
|
||||
{
|
||||
float scale_factor = (float)1;
|
||||
|
||||
*humidity = data[0] * scale_factor;
|
||||
}
|
||||
|
||||
void bhy2_parse_pressure(const uint8_t *data, bhy2_float *pressure)
|
||||
{
|
||||
/* 1 LSB = 1/128 Pa */
|
||||
float scale_factor = (float)1 / 128;
|
||||
|
||||
*pressure = (float)BHY2_LE2U24(data) * scale_factor;
|
||||
}
|
||||
|
||||
void bhy2_parse_altitude(const uint8_t *data, bhy2_float *altitude)
|
||||
{
|
||||
*altitude = (float)(data[0] | ((uint32_t)data[1] << 8) | ((uint32_t)data[2] << 16) | ((uint32_t)data[3] << 24));
|
||||
}
|
||||
|
||||
void bhy2_parse_quaternion(const uint8_t *data, struct bhy2_data_quaternion *quaternion)
|
||||
{
|
||||
quaternion->x = BHY2_LE2S16(data);
|
||||
quaternion->y = BHY2_LE2S16(data + 2);
|
||||
quaternion->z = BHY2_LE2S16(data + 4);
|
||||
quaternion->w = BHY2_LE2S16(data + 6);
|
||||
quaternion->accuracy = BHY2_LE2U16(data + 8);
|
||||
}
|
||||
|
||||
void bhy2_parse_xyz(const uint8_t *data, struct bhy2_data_xyz *vector)
|
||||
{
|
||||
vector->x = BHY2_LE2S16(data);
|
||||
vector->y = BHY2_LE2S16(data + 2);
|
||||
vector->z = BHY2_LE2S16(data + 4);
|
||||
}
|
||||
|
||||
void bhy2_parse_orientation(const uint8_t *data, struct bhy2_data_orientation *orientation)
|
||||
{
|
||||
orientation->heading = BHY2_LE2S16(data);
|
||||
orientation->pitch = BHY2_LE2S16(data + 2);
|
||||
orientation->roll = BHY2_LE2S16(data + 4);
|
||||
}
|
||||
|
||||
uint32_t bhy2_parse_step_counter(const uint8_t *data)
|
||||
{
|
||||
return (uint32_t)(data[0] | ((uint32_t)data[1] << 8) | ((uint32_t)data[2] << 16) | ((uint32_t)data[3] << 24));
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* 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_parse.h
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
#ifndef __BHY2_PARSE_H__
|
||||
#define __BHY2_PARSE_H__
|
||||
|
||||
/* Start of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#include "bhy2.h"
|
||||
|
||||
/**
|
||||
* @brief Function to parse FIFO frame data into temperature
|
||||
* @param[in] data : Reference to the data buffer storing data from the FIFO
|
||||
* @param[out] temperature : Reference to the data buffer to store temperature in degree C
|
||||
*/
|
||||
void bhy2_parse_temperature_celsius(const uint8_t *data, bhy2_float *temperature);
|
||||
|
||||
/**
|
||||
* @brief Function to parse FIFO frame data into humidity
|
||||
* @param[in] data : Reference to the data buffer storing data from the FIFO
|
||||
* @param[out] humidity : Reference to the data buffer to store humidity in %
|
||||
*/
|
||||
void bhy2_parse_humidity(const uint8_t *data, bhy2_float *humidity);
|
||||
|
||||
/**
|
||||
* @brief Function to parse FIFO frame data into barometric pressure
|
||||
* @param[in] data : Reference to the data buffer storing data from the FIFO
|
||||
* @param[out] pressure : Reference to the data buffer to store pressure in Pascals
|
||||
*/
|
||||
void bhy2_parse_pressure(const uint8_t *data, bhy2_float *pressure);
|
||||
|
||||
/**
|
||||
* @brief Function to parse FIFO frame data into altitude
|
||||
* @param[in] data : Reference to the data buffer storing data from the FIFO
|
||||
* @param[out] altitude : Reference to the data buffer to store altitude
|
||||
*/
|
||||
void bhy2_parse_altitude(const uint8_t *data, bhy2_float *altitude);
|
||||
|
||||
/**
|
||||
* @brief Function to parse FIFO frame data into quaternion
|
||||
* @param[in] data : Reference to the data buffer storing data from the FIFO
|
||||
* @param[out] quaternion : Reference to the data buffer to store quaternion
|
||||
*/
|
||||
void bhy2_parse_quaternion(const uint8_t *data, struct bhy2_data_quaternion *quaternion);
|
||||
|
||||
/**
|
||||
* @brief Function to parse FIFO frame data into orientation
|
||||
* @param[in] data : Reference to the data buffer storing data from the FIFO
|
||||
* @param[out] orientation : Reference to the data buffer to store orientation
|
||||
*/
|
||||
void bhy2_parse_orientation(const uint8_t *data, struct bhy2_data_orientation *orientation);
|
||||
|
||||
/**
|
||||
* @brief Function to parse FIFO frame data into 3 axes vector
|
||||
* @param[in] data : Reference to the data buffer storing data from the FIFO
|
||||
* @param[out] vector : Reference to the data buffer to store vector
|
||||
*/
|
||||
void bhy2_parse_xyz(const uint8_t *data, struct bhy2_data_xyz *vector);
|
||||
|
||||
/**
|
||||
* @brief Function to parse FIFO frame data into step counter
|
||||
* @param[in] data : Reference to the data buffer storing data from the FIFO
|
||||
* @return[out] : Reference to the data buffer to step counter
|
||||
*/
|
||||
uint32_t bhy2_parse_step_counter(const uint8_t *data);
|
||||
|
||||
/* End of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#endif /* __BHY2_PARSE_H__ */
|
||||
@@ -0,0 +1,203 @@
|
||||
/**
|
||||
* 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_swim.c
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************************************************************/
|
||||
/* system header files */
|
||||
/*********************************************************************/
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*********************************************************************/
|
||||
/* BHY2 SensorAPI header files */
|
||||
/*********************************************************************/
|
||||
#include "bhy2.h"
|
||||
|
||||
/*********************************************************************/
|
||||
/* own header files */
|
||||
/*********************************************************************/
|
||||
#include "bhy2_swim.h"
|
||||
|
||||
/*!
|
||||
* @brief This API writes to the configuration parameter
|
||||
* Config parameters are pool length and handedness
|
||||
*
|
||||
* @param[in] buffer to store swim configuration
|
||||
* @param[out] dev hub handle.
|
||||
*
|
||||
* @return rslt execution result.
|
||||
*/
|
||||
int8_t bhy2_swim_set_config(const void *buffer, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
/*! Length of the configuration is 4 bytes */
|
||||
uint32_t length = BHY2_SWIM_DATA_LENGTH;
|
||||
|
||||
/*! Swim Parameter page with offset 0 used for swim configuration*/
|
||||
uint16_t param = BHY2_SWIM_CONFIG_PARAM;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Set the swim configuration parameter */
|
||||
rslt = bhy2_set_parameter(param, (uint8_t *)buffer, length, dev);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the SWIM configuration parameters like swim length and handedness
|
||||
*
|
||||
* @param[out] buffer to store swim configuration
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return status code, BHY_HIF_E_SUCCESS in case of success
|
||||
*
|
||||
*/
|
||||
int8_t bhy2_swim_get_config(void *buffer, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
/*! Length of the configuration is 4 bytes */
|
||||
uint32_t length = BHY2_SWIM_DATA_LENGTH;
|
||||
uint32_t ret_length;
|
||||
|
||||
/*! Swim Parameter page with offset 0 used to store swim configuration*/
|
||||
uint16_t param = BHY2_SWIM_CONFIG_PARAM;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Get the swim configuration from the parameter page*/
|
||||
rslt = bhy2_get_parameter(param, buffer, length, &ret_length, dev);
|
||||
|
||||
if ((rslt == BHY2_OK) && (ret_length != BHY2_SWIM_DATA_LENGTH))
|
||||
{
|
||||
/*! Invalid number of parameters readout */
|
||||
rslt = BHY2_E_INVALID_EVENT_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief To get the SWIM Algorithm version
|
||||
*
|
||||
* @param[out] buffer to store version data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return status code, BHY_HIF_E_SUCCESS in case of success
|
||||
*
|
||||
*/
|
||||
int8_t bhy2_swim_get_version(bhy2_swim_version_t *version, struct bhy2_dev *dev)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
/*! Buffer to store the swim version */
|
||||
uint8_t buffer[4];
|
||||
|
||||
/*! Length of the configuration is 4 */
|
||||
uint32_t length = BHY2_SWIM_DATA_LENGTH;
|
||||
uint32_t ret_length;
|
||||
|
||||
/*! Swim Parameter page with offset 1 used to store swim algorithm version*/
|
||||
uint16_t param = BHY2_SWIM_VERSION;
|
||||
|
||||
if (dev == NULL)
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*! Get the swim version from the parameter page */
|
||||
rslt = bhy2_get_parameter(param, buffer, length, &ret_length, dev);
|
||||
|
||||
if ((rslt == BHY2_OK) && (ret_length != BHY2_SWIM_DATA_LENGTH))
|
||||
{
|
||||
/*! Invalid number of parameters readout */
|
||||
rslt = BHY2_E_INVALID_EVENT_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
version->improvement = buffer[0];
|
||||
version->platform = buffer[1];
|
||||
version->bugfix = buffer[2];
|
||||
}
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Parsing the fifo data to SWIM output structure format
|
||||
*
|
||||
* @param[in] Swim data
|
||||
* @param[out] bhy2_swim_aglo_output to store parameter data
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhy2_swim_parse_data(const uint8_t *data, struct bhy2_swim_algo_output* output)
|
||||
{
|
||||
int8_t rslt = BHY2_OK;
|
||||
|
||||
if ((data == NULL) || (output == NULL))
|
||||
{
|
||||
rslt = BHY2_E_NULL_PTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
output->total_distance = BHY2_LE2U16(data);
|
||||
output->length_count = BHY2_LE2U16(data + 2);
|
||||
output->lengths_freestyle = BHY2_LE2U16(data + 4);
|
||||
output->lengths_breaststroke = BHY2_LE2U16(data + 6);
|
||||
output->lengths_butterfly = BHY2_LE2U16(data + 8);
|
||||
output->lengths_backstroke = BHY2_LE2U16(data + 10);
|
||||
output->stroke_count = BHY2_LE2U16(data + 12);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* 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_swim.h
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _BHY2_SWIM_H_
|
||||
#define _BHY2_SWIM_H_
|
||||
|
||||
/* Start of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "bhy2.h"
|
||||
#include "bhy2_swim_defs.h"
|
||||
|
||||
/*!
|
||||
* @brief Parsing the fifo data to SWIM output structure format
|
||||
*
|
||||
* @param[in] data parameter
|
||||
* @param[out] bhy2_swim_aglo_output to store parameter data
|
||||
*
|
||||
* @return API error codes
|
||||
*
|
||||
*/
|
||||
int8_t bhy2_swim_parse_data(const uint8_t *data, struct bhy2_swim_algo_output *output);
|
||||
|
||||
/*!
|
||||
* @brief To get the SWIM configuration parameters like swim length and handedness
|
||||
*
|
||||
* @param[out] buffer to store parameter data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return status code, BHY_HIF_E_SUCCESS in case of success
|
||||
*
|
||||
*/
|
||||
int8_t bhy2_swim_get_config(void *buffer, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To get the SWIM Algorithm version
|
||||
*
|
||||
* @param[out] buffer to store version data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return status code, BHY_HIF_E_SUCCESS in case of success
|
||||
*
|
||||
*/
|
||||
int8_t bhy2_swim_get_version(bhy2_swim_version_t *buffer, struct bhy2_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief To set the SWIM configuration parameters like swim length and handedness
|
||||
* @param[out] buffer to store parameter data
|
||||
* @param[in] dev hub handle
|
||||
*
|
||||
* @return status code, BHY_HIF_E_SUCCESS in case of success
|
||||
*
|
||||
*/
|
||||
int8_t bhy2_swim_set_config(const void *buffer, struct bhy2_dev *dev);
|
||||
|
||||
/* End of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#endif /* _BHY2_SWIM_H_ */
|
||||
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* 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_swim_defs.h
|
||||
* @date 2023-03-24
|
||||
* @version v1.6.0
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _BHY2_SWIM_DEFS_H_
|
||||
#define _BHY2_SWIM_DEFS_H_
|
||||
|
||||
/* Start of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*! Sensor ID for Swim */
|
||||
#define BHY2_SENSOR_ID_SWIM UINT8_C(114)
|
||||
|
||||
/*! Swim Parameter Page Base Address*/
|
||||
#define BHY2_SWIM_PAGE UINT16_C(0x0B)
|
||||
|
||||
/*! Swim Configuration pages */
|
||||
#define BHY2_SWIM_CONFIG_PARAM (BHY2_SWIM_PAGE << 8)
|
||||
#define BHY2_SWIM_VERSION ((BHY2_SWIM_PAGE << 8) | 1)
|
||||
|
||||
/*! Swim configurations enable/ disable from parameter page */
|
||||
#define BHY2_SWIM_ENABLE_CONFIG UINT8_C(1)
|
||||
#define BHY2_SWIM_DISABLE_CONFIG UINT8_C(0)
|
||||
|
||||
/*! Device in left/right hand */
|
||||
#define BHY2_SWIM_DEVICE_ON_LEFT_HAND UINT8_C(1)
|
||||
#define BHY2_SWIM_DEVICE_ON_RIGHT_HAND UINT8_C(0)
|
||||
|
||||
/*! Pool length */
|
||||
#define BHY2_SWIM_POOL_LENGTH_25M UINT8_C(25)
|
||||
#define BHY2_SWIM_POOL_LENGTH_50M UINT8_C(50)
|
||||
|
||||
#define BHY2_SWIM_DATA_LENGTH UINT8_C(4)
|
||||
|
||||
/*!
|
||||
* bhy2 swim algo parameter.
|
||||
*/
|
||||
typedef struct bhy2_swim_config_param
|
||||
{
|
||||
uint8_t update_swim_config;
|
||||
uint8_t dev_on_left_hand;
|
||||
uint8_t pool_length_integral;
|
||||
uint8_t pool_length_floating;
|
||||
} __attribute__ ((packed)) bhy2_swim_config_param_t;
|
||||
|
||||
/*!
|
||||
* swim output structure
|
||||
*/
|
||||
typedef struct bhy2_swim_algo_output
|
||||
{
|
||||
uint16_t total_distance;
|
||||
uint16_t length_count;
|
||||
uint16_t lengths_freestyle;
|
||||
uint16_t lengths_breaststroke;
|
||||
uint16_t lengths_butterfly;
|
||||
uint16_t lengths_backstroke;
|
||||
uint16_t stroke_count;
|
||||
} __attribute__ ((packed)) bhy2_swim_algo_output_t;
|
||||
|
||||
/*!
|
||||
* callback data capturing structure
|
||||
*/
|
||||
typedef struct bhy2_swim_data_parse
|
||||
{
|
||||
uint8_t sensor_id;
|
||||
uint8_t data_size;
|
||||
uint8_t *data_ptr;
|
||||
uint64_t *time_stamp;
|
||||
} bhy2_swim_data_parse_t;
|
||||
|
||||
/*! @brief structure definition to hold the version information of the software */
|
||||
typedef struct bhy2_swim_version
|
||||
{
|
||||
uint8_t improvement;
|
||||
uint8_t platform;
|
||||
uint8_t bugfix;
|
||||
uint8_t optional;
|
||||
} bhy2_swim_version_t;
|
||||
|
||||
typedef void (*bhy2_swim_algo_callback)(uint32_t seconds, uint32_t nanoseconds,
|
||||
const struct bhy2_swim_data_parse *callback_info);
|
||||
|
||||
/* End of CPP Guard */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#endif /* _BHY2_SWIM_DEFS_H_ */
|
||||
@@ -0,0 +1,161 @@
|
||||
/**
|
||||
*
|
||||
* @license MIT License
|
||||
*
|
||||
* Copyright (c) 2022 lewis he
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @file bosch_interfaces.cpp
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2023-10-09
|
||||
*
|
||||
*/
|
||||
#include "bosch_interfaces.h"
|
||||
|
||||
#if defined(ARDUINO)
|
||||
|
||||
#if defined(ARDUINO_ARCH_RP2040)
|
||||
SPISettings SensorInterfaces::__spiSetting = SPISettings();
|
||||
#else
|
||||
SPISettings SensorInterfaces::__spiSetting = SPISettings(4000000, SPI_DATA_ORDER, SPI_MODE0);
|
||||
#endif
|
||||
|
||||
void SensorInterfaces::close_interfaces(SensorLibConfigure config)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool SensorInterfaces::setup_interfaces(SensorLibConfigure config)
|
||||
{
|
||||
if (config.irq != SENSOR_PIN_NONE) {
|
||||
pinMode(config.irq, INPUT_PULLDOWN);
|
||||
}
|
||||
switch (config.intf) {
|
||||
case SENSORLIB_I2C_INTERFACE:
|
||||
#if defined(ARDUINO_ARCH_RP2040)
|
||||
config.u.i2c_dev.wire->end();
|
||||
config.u.i2c_dev.wire->setSDA(config.u.i2c_dev.sda);
|
||||
config.u.i2c_dev.wire->setSCL(config.u.i2c_dev.scl);
|
||||
config.u.i2c_dev.wire->begin();
|
||||
#elif defined(NRF52840_XXAA) || defined(NRF52832_XXAA)
|
||||
config.u.i2c_dev.wire->end();
|
||||
config.u.i2c_dev.wire->setPins(config.u.i2c_dev.sda,config.u.i2c_dev.scl);
|
||||
config.u.i2c_dev.wire->begin();
|
||||
#else
|
||||
config.u.i2c_dev.wire->begin(config.u.i2c_dev.sda, config.u.i2c_dev.scl);
|
||||
#endif
|
||||
config.u.i2c_dev.wire->beginTransmission(config.u.i2c_dev.addr);
|
||||
if (config.u.i2c_dev.wire->endTransmission() != 0) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case SENSORLIB_SPI_INTERFACE:
|
||||
pinMode(config.u.spi_dev.cs, OUTPUT);
|
||||
digitalWrite(config.u.spi_dev.cs, HIGH);
|
||||
#if defined(ARDUINO_ARCH_RP2040)
|
||||
config.u.spi_dev.spi->setSCK(config.u.spi_dev.sck);
|
||||
config.u.spi_dev.spi->setRX(config.u.spi_dev.miso);
|
||||
config.u.spi_dev.spi->setTX(config.u.spi_dev.mosi);
|
||||
config.u.spi_dev.spi->begin();
|
||||
#elif defined(NRF52840_XXAA) || defined(NRF52832_XXAA)
|
||||
config.u.spi_dev.spi->setPins(config.u.spi_dev.miso,config.u.spi_dev.sck, config.u.spi_dev.mosi);
|
||||
config.u.spi_dev.spi->begin();
|
||||
#else
|
||||
config.u.spi_dev.spi->begin(config.u.spi_dev.sck, config.u.spi_dev.miso, config.u.spi_dev.mosi);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int8_t SensorInterfaces::bhy2_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
|
||||
{
|
||||
SensorLibConfigure *pConfig = (SensorLibConfigure *)intf_ptr;
|
||||
if (!pConfig) {
|
||||
return DEV_WIRE_ERR;
|
||||
}
|
||||
digitalWrite(pConfig->u.spi_dev.cs, LOW);
|
||||
pConfig->u.spi_dev.spi->beginTransaction(__spiSetting);
|
||||
pConfig->u.spi_dev.spi->transfer((reg_addr));
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
reg_data[i] = pConfig->u.spi_dev.spi->transfer(0x00);
|
||||
}
|
||||
pConfig->u.spi_dev.spi->endTransaction();
|
||||
digitalWrite(pConfig->u.spi_dev.cs, HIGH);
|
||||
|
||||
return DEV_WIRE_NONE;
|
||||
}
|
||||
|
||||
int8_t SensorInterfaces::bhy2_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
|
||||
{
|
||||
SensorLibConfigure *pConfig = (SensorLibConfigure *)intf_ptr;
|
||||
if (!pConfig) {
|
||||
return DEV_WIRE_ERR;
|
||||
}
|
||||
digitalWrite(pConfig->u.spi_dev.cs, LOW);
|
||||
pConfig->u.spi_dev.spi->beginTransaction(__spiSetting);
|
||||
pConfig->u.spi_dev.spi->transfer(reg_addr);
|
||||
pConfig->u.spi_dev.spi->transfer((uint8_t *)reg_data, length);
|
||||
pConfig->u.spi_dev.spi->endTransaction();
|
||||
digitalWrite(pConfig->u.spi_dev.cs, HIGH);
|
||||
return DEV_WIRE_NONE;
|
||||
}
|
||||
|
||||
int8_t SensorInterfaces::bhy2_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
|
||||
{
|
||||
SensorLibConfigure *pConfig = (SensorLibConfigure *)intf_ptr;
|
||||
if (!pConfig) {
|
||||
return DEV_WIRE_ERR;
|
||||
}
|
||||
pConfig->u.i2c_dev.wire->beginTransmission(pConfig->u.i2c_dev.addr);
|
||||
pConfig->u.i2c_dev.wire->write(reg_addr);
|
||||
if (pConfig->u.i2c_dev.wire->endTransmission() != 0) {
|
||||
return DEV_WIRE_ERR;
|
||||
}
|
||||
pConfig->u.i2c_dev.wire->requestFrom(pConfig->u.i2c_dev.addr, length);
|
||||
return pConfig->u.i2c_dev.wire->readBytes(reg_data, length) == length ? DEV_WIRE_NONE : DEV_WIRE_ERR;
|
||||
}
|
||||
|
||||
int8_t SensorInterfaces::bhy2_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
|
||||
{
|
||||
SensorLibConfigure *pConfig = (SensorLibConfigure *)intf_ptr;
|
||||
if (!pConfig) {
|
||||
return DEV_WIRE_ERR;
|
||||
}
|
||||
pConfig->u.i2c_dev.wire->beginTransmission(pConfig->u.i2c_dev.addr);
|
||||
pConfig->u.i2c_dev.wire->write(reg_addr);
|
||||
pConfig->u.i2c_dev.wire->write(reg_data, length);
|
||||
return (pConfig->u.i2c_dev.wire->endTransmission() == 0) ? 0 : DEV_WIRE_ERR;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SensorInterfaces::bhy2_delay_us(uint32_t us, void *private_data)
|
||||
{
|
||||
(void)private_data;
|
||||
delayMicroseconds(us);
|
||||
}
|
||||
|
||||
#endif /*Arduino */
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
*
|
||||
* @license MIT License
|
||||
*
|
||||
* Copyright (c) 2022 lewis he
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @file bosch_interfaces.h
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2023-10-09
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "SensorLib.h"
|
||||
|
||||
#if defined(ARDUINO)
|
||||
class SensorInterfaces
|
||||
{
|
||||
public:
|
||||
static bool setup_interfaces(SensorLibConfigure config);
|
||||
static void close_interfaces(SensorLibConfigure config);
|
||||
static int8_t bhy2_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr);
|
||||
static int8_t bhy2_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr);
|
||||
static int8_t bhy2_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr);
|
||||
static int8_t bhy2_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr);
|
||||
static void bhy2_delay_us(uint32_t us, void *private_data);
|
||||
|
||||
private:
|
||||
static SPISettings __spiSetting;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,987 @@
|
||||
/**
|
||||
* 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 common.c
|
||||
* @brief Common source file for the BHy260 examples
|
||||
* @note Adapting Arduino based on BHY2-Sensor-API by lewis
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "bosch/bhy2_parse.h"
|
||||
#include "bosch/bhy2.h"
|
||||
|
||||
|
||||
void time_to_s_ns(uint64_t time_ticks, uint32_t *s, uint32_t *ns, uint64_t *tns)
|
||||
{
|
||||
*tns = time_ticks * 15625; /* timestamp is now in nanoseconds */
|
||||
*s = (uint32_t)(*tns / UINT64_C(1000000000));
|
||||
*ns = (uint32_t)(*tns - ((*s) * UINT64_C(1000000000)));
|
||||
}
|
||||
|
||||
const char *get_api_error(int8_t error_code)
|
||||
{
|
||||
const char *ret;
|
||||
|
||||
switch (error_code) {
|
||||
case BHY2_OK:
|
||||
ret = "[API Success]";
|
||||
break;
|
||||
case BHY2_E_NULL_PTR:
|
||||
ret = "[API Error] Null pointer";
|
||||
break;
|
||||
case BHY2_E_INVALID_PARAM:
|
||||
ret = "[API Error] Invalid parameter";
|
||||
break;
|
||||
case BHY2_E_IO:
|
||||
ret = "[API Error] IO error";
|
||||
break;
|
||||
case BHY2_E_MAGIC:
|
||||
ret = "[API Error] Invalid firmware";
|
||||
break;
|
||||
case BHY2_E_TIMEOUT:
|
||||
ret = "[API Error] Timed out";
|
||||
break;
|
||||
case BHY2_E_BUFFER:
|
||||
ret = "[API Error] Invalid buffer";
|
||||
break;
|
||||
case BHY2_E_INVALID_FIFO_TYPE:
|
||||
ret = "[API Error] Invalid FIFO type";
|
||||
break;
|
||||
case BHY2_E_INVALID_EVENT_SIZE:
|
||||
ret = "[API Error] Invalid Event size";
|
||||
break;
|
||||
case BHY2_E_PARAM_NOT_SET:
|
||||
ret = "[API Error] Parameter not set";
|
||||
break;
|
||||
default:
|
||||
ret = "[API Error] Unknown API error code";
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char *get_sensor_error_text(uint8_t sensor_error)
|
||||
{
|
||||
const char *ret;
|
||||
|
||||
switch (sensor_error) {
|
||||
case 0x00:
|
||||
break;
|
||||
case 0x10:
|
||||
ret = "[Sensor error] Bootloader reports: Firmware Expected Version Mismatch";
|
||||
break;
|
||||
case 0x11:
|
||||
ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: Bad Header CRC";
|
||||
break;
|
||||
case 0x12:
|
||||
ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: SHA Hash Mismatch";
|
||||
break;
|
||||
case 0x13:
|
||||
ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: Bad Image CRC";
|
||||
break;
|
||||
case 0x14:
|
||||
ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: ECDSA Signature Verification Failed";
|
||||
break;
|
||||
case 0x15:
|
||||
ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: Bad Public Key CRC";
|
||||
break;
|
||||
case 0x16:
|
||||
ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: Signed Firmware Required";
|
||||
break;
|
||||
case 0x17:
|
||||
ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: FW Header Missing";
|
||||
break;
|
||||
case 0x19:
|
||||
ret = "[Sensor error] Bootloader reports: Unexpected Watchdog Reset";
|
||||
break;
|
||||
case 0x1A:
|
||||
ret = "[Sensor error] ROM Version Mismatch";
|
||||
break;
|
||||
case 0x1B:
|
||||
ret = "[Sensor error] Bootloader reports: Fatal Firmware Error";
|
||||
break;
|
||||
case 0x1C:
|
||||
ret = "[Sensor error] Chained Firmware Error: Next Payload Not Found";
|
||||
break;
|
||||
case 0x1D:
|
||||
ret = "[Sensor error] Chained Firmware Error: Payload Not Valid";
|
||||
break;
|
||||
case 0x1E:
|
||||
ret = "[Sensor error] Chained Firmware Error: Payload Entries Invalid";
|
||||
break;
|
||||
case 0x1F:
|
||||
ret = "[Sensor error] Bootloader reports: Bootloader Error: OTP CRC Invalid";
|
||||
break;
|
||||
case 0x20:
|
||||
ret = "[Sensor error] Firmware Init Failed";
|
||||
break;
|
||||
case 0x21:
|
||||
ret = "[Sensor error] Sensor Init Failed: Unexpected Device ID";
|
||||
break;
|
||||
case 0x22:
|
||||
ret = "[Sensor error] Sensor Init Failed: No Response from Device";
|
||||
break;
|
||||
case 0x23:
|
||||
ret = "[Sensor error] Sensor Init Failed: Unknown";
|
||||
break;
|
||||
case 0x24:
|
||||
ret = "[Sensor error] Sensor Error: No Valid Data";
|
||||
break;
|
||||
case 0x25:
|
||||
ret = "[Sensor error] Slow Sample Rate";
|
||||
break;
|
||||
case 0x26:
|
||||
ret = "[Sensor error] Data Overflow (saturated sensor data)";
|
||||
break;
|
||||
case 0x27:
|
||||
ret = "[Sensor error] Stack Overflow";
|
||||
break;
|
||||
case 0x28:
|
||||
ret = "[Sensor error] Insufficient Free RAM";
|
||||
break;
|
||||
case 0x29:
|
||||
ret = "[Sensor error] Sensor Init Failed: Driver Parsing Error";
|
||||
break;
|
||||
case 0x2A:
|
||||
ret = "[Sensor error] Too Many RAM Banks Required";
|
||||
break;
|
||||
case 0x2B:
|
||||
ret = "[Sensor error] Invalid Event Specified";
|
||||
break;
|
||||
case 0x2C:
|
||||
ret = "[Sensor error] More than 32 On Change";
|
||||
break;
|
||||
case 0x2D:
|
||||
ret = "[Sensor error] Firmware Too Large";
|
||||
break;
|
||||
case 0x2F:
|
||||
ret = "[Sensor error] Invalid RAM Banks";
|
||||
break;
|
||||
case 0x30:
|
||||
ret = "[Sensor error] Math Error";
|
||||
break;
|
||||
case 0x40:
|
||||
ret = "[Sensor error] Memory Error";
|
||||
break;
|
||||
case 0x41:
|
||||
ret = "[Sensor error] SWI3 Error";
|
||||
break;
|
||||
case 0x42:
|
||||
ret = "[Sensor error] SWI4 Error";
|
||||
break;
|
||||
case 0x43:
|
||||
ret = "[Sensor error] Illegal Instruction Error";
|
||||
break;
|
||||
case 0x44:
|
||||
ret = "[Sensor error] Bootloader reports: Unhandled Interrupt Error / Exception / Postmortem Available";
|
||||
break;
|
||||
case 0x45:
|
||||
ret = "[Sensor error] Invalid Memory Access";
|
||||
break;
|
||||
case 0x50:
|
||||
ret = "[Sensor error] Algorithm Error: BSX Init";
|
||||
break;
|
||||
case 0x51:
|
||||
ret = "[Sensor error] Algorithm Error: BSX Do Step";
|
||||
break;
|
||||
case 0x52:
|
||||
ret = "[Sensor error] Algorithm Error: Update Sub";
|
||||
break;
|
||||
case 0x53:
|
||||
ret = "[Sensor error] Algorithm Error: Get Sub";
|
||||
break;
|
||||
case 0x54:
|
||||
ret = "[Sensor error] Algorithm Error: Get Phys";
|
||||
break;
|
||||
case 0x55:
|
||||
ret = "[Sensor error] Algorithm Error: Unsupported Phys Rate";
|
||||
break;
|
||||
case 0x56:
|
||||
ret = "[Sensor error] Algorithm Error: Cannot find BSX Driver";
|
||||
break;
|
||||
case 0x60:
|
||||
ret = "[Sensor error] Sensor Self-Test Failure";
|
||||
break;
|
||||
case 0x61:
|
||||
ret = "[Sensor error] Sensor Self-Test X Axis Failure";
|
||||
break;
|
||||
case 0x62:
|
||||
ret = "[Sensor error] Sensor Self-Test Y Axis Failure";
|
||||
break;
|
||||
case 0x64:
|
||||
ret = "[Sensor error] Sensor Self-Test Z Axis Failure";
|
||||
break;
|
||||
case 0x65:
|
||||
ret = "[Sensor error] FOC Failure";
|
||||
break;
|
||||
case 0x66:
|
||||
ret = "[Sensor error] Sensor Busy";
|
||||
break;
|
||||
case 0x6F:
|
||||
ret = "[Sensor error] Self-Test or FOC Test Unsupported";
|
||||
break;
|
||||
case 0x72:
|
||||
ret = "[Sensor error] No Host Interrupt Set";
|
||||
break;
|
||||
case 0x73:
|
||||
ret = "[Sensor error] Event ID Passed to Host Interface Has No Known Size";
|
||||
break;
|
||||
case 0x75:
|
||||
ret = "[Sensor error] Host Download Channel Underflow (Host Read Too Fast)";
|
||||
break;
|
||||
case 0x76:
|
||||
ret = "[Sensor error] Host Upload Channel Overflow (Host Wrote Too Fast)";
|
||||
break;
|
||||
case 0x77:
|
||||
ret = "[Sensor error] Host Download Channel Empty";
|
||||
break;
|
||||
case 0x78:
|
||||
ret = "[Sensor error] DMA Error";
|
||||
break;
|
||||
case 0x79:
|
||||
ret = "[Sensor error] Corrupted Input Block Chain";
|
||||
break;
|
||||
case 0x7A:
|
||||
ret = "[Sensor error] Corrupted Output Block Chain";
|
||||
break;
|
||||
case 0x7B:
|
||||
ret = "[Sensor error] Buffer Block Manager Error";
|
||||
break;
|
||||
case 0x7C:
|
||||
ret = "[Sensor error] Input Channel Not Word Aligned";
|
||||
break;
|
||||
case 0x7D:
|
||||
ret = "[Sensor error] Too Many Flush Events";
|
||||
break;
|
||||
case 0x7E:
|
||||
ret = "[Sensor error] Unknown Host Channel Error";
|
||||
break;
|
||||
case 0x81:
|
||||
ret = "[Sensor error] Decimation Too Large";
|
||||
break;
|
||||
case 0x90:
|
||||
ret = "[Sensor error] Master SPI/I2C Queue Overflow";
|
||||
break;
|
||||
case 0x91:
|
||||
ret = "[Sensor error] SPI/I2C Callback Error";
|
||||
break;
|
||||
case 0xA0:
|
||||
ret = "[Sensor error] Timer Scheduling Error";
|
||||
break;
|
||||
case 0xB0:
|
||||
ret = "[Sensor error] Invalid GPIO for Host IRQ";
|
||||
break;
|
||||
case 0xB1:
|
||||
ret = "[Sensor error] Error Sending Initialized Meta Events";
|
||||
break;
|
||||
case 0xC0:
|
||||
ret = "[Sensor error] Bootloader reports: Command Error";
|
||||
break;
|
||||
case 0xC1:
|
||||
ret = "[Sensor error] Bootloader reports: Command Too Long";
|
||||
break;
|
||||
case 0xC2:
|
||||
ret = "[Sensor error] Bootloader reports: Command Buffer Overflow";
|
||||
break;
|
||||
case 0xD0:
|
||||
ret = "[Sensor error] User Mode Error: Sys Call Invalid";
|
||||
break;
|
||||
case 0xD1:
|
||||
ret = "[Sensor error] User Mode Error: Trap Invalid";
|
||||
break;
|
||||
case 0xE1:
|
||||
ret = "[Sensor error] Firmware Upload Failed: Firmware header corrupt";
|
||||
break;
|
||||
case 0xE2:
|
||||
ret = "[Sensor error] Sensor Data Injection: Invalid input stream";
|
||||
break;
|
||||
default:
|
||||
ret = "[Sensor error] Unknown error code";
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char *get_sensor_name(uint8_t sensor_id)
|
||||
{
|
||||
const char *ret;
|
||||
|
||||
switch (sensor_id) {
|
||||
case BHY2_SENSOR_ID_ACC_PASS:
|
||||
ret = "Accelerometer passthrough";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_ACC_RAW:
|
||||
ret = "Accelerometer uncalibrated";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_ACC:
|
||||
ret = "Accelerometer corrected";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_ACC_BIAS:
|
||||
ret = "Accelerometer offset";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_ACC_WU:
|
||||
ret = "Accelerometer corrected wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_ACC_RAW_WU:
|
||||
ret = "Accelerometer uncalibrated wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GYRO_PASS:
|
||||
ret = "Gyroscope passthrough";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GYRO_RAW:
|
||||
ret = "Gyroscope uncalibrated";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GYRO:
|
||||
ret = "Gyroscope corrected";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GYRO_BIAS:
|
||||
ret = "Gyroscope offset";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GYRO_WU:
|
||||
ret = "Gyroscope wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GYRO_RAW_WU:
|
||||
ret = "Gyroscope uncalibrated wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_MAG_PASS:
|
||||
ret = "Magnetometer passthrough";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_MAG_RAW:
|
||||
ret = "Magnetometer uncalibrated";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_MAG:
|
||||
ret = "Magnetometer corrected";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_MAG_BIAS:
|
||||
ret = "Magnetometer offset";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_MAG_WU:
|
||||
ret = "Magnetometer wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_MAG_RAW_WU:
|
||||
ret = "Magnetometer uncalibrated wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GRA:
|
||||
ret = "Gravity vector";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GRA_WU:
|
||||
ret = "Gravity vector wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_LACC:
|
||||
ret = "Linear acceleration";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_LACC_WU:
|
||||
ret = "Linear acceleration wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_RV:
|
||||
ret = "Rotation vector";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_RV_WU:
|
||||
ret = "Rotation vector wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GAMERV:
|
||||
ret = "Game rotation vector";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GAMERV_WU:
|
||||
ret = "Game rotation vector wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GEORV:
|
||||
ret = "Geo-magnetic rotation vector";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GEORV_WU:
|
||||
ret = "Geo-magnetic rotation vector wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_ORI:
|
||||
ret = "Orientation";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_ORI_WU:
|
||||
ret = "Orientation wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_ACC_BIAS_WU:
|
||||
ret = "Accelerometer offset wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GYRO_BIAS_WU:
|
||||
ret = "Gyroscope offset wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_MAG_BIAS_WU:
|
||||
ret = "Magnetometer offset wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_TEMP:
|
||||
ret = "Temperature";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_BARO:
|
||||
ret = "Barometer";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_HUM:
|
||||
ret = "Humidity";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GAS:
|
||||
ret = "Gas";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_TEMP_WU:
|
||||
ret = "Temperature wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_BARO_WU:
|
||||
ret = "Barometer wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_HUM_WU:
|
||||
ret = "Humidity wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GAS_WU:
|
||||
ret = "Gas wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_KLIO:
|
||||
ret = "Klio";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_KLIO_LOG:
|
||||
ret = "Klio log";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_SWIM:
|
||||
ret = "Swim recognition";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_SI_ACCEL:
|
||||
ret = "SI Accel";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_SI_GYROS:
|
||||
ret = "SI Gyro";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_LIGHT:
|
||||
ret = "Light";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_LIGHT_WU:
|
||||
ret = "Light wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_PROX:
|
||||
ret = "Proximity";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_PROX_WU:
|
||||
ret = "Proximity wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_STC:
|
||||
ret = "Step counter";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_STC_WU:
|
||||
ret = "Step counter wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_STC_LP:
|
||||
ret = "Low Power Step counter";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_STC_LP_WU:
|
||||
ret = "Low Power Step counter wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_SIG:
|
||||
ret = "Significant motion";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_STD:
|
||||
ret = "Step detector";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_STD_WU:
|
||||
ret = "Step detector wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_TILT_DETECTOR:
|
||||
ret = "Tilt detector";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_WAKE_GESTURE:
|
||||
ret = "Wake gesture";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GLANCE_GESTURE:
|
||||
ret = "Glance gesture";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_PICKUP_GESTURE:
|
||||
ret = "Pickup gesture";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_SIG_LP:
|
||||
ret = "Low Power Significant motion";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_SIG_LP_WU:
|
||||
ret = "Low Power Significant motion wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_STD_LP:
|
||||
ret = "Low Power Step detector";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_STD_LP_WU:
|
||||
ret = "Low Power Step detector wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_AR:
|
||||
ret = "Activity recognition";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_EXCAMERA:
|
||||
ret = "External camera trigger";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GPS:
|
||||
ret = "GPS";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_WRIST_TILT_GESTURE:
|
||||
ret = "Wrist tilt gesture";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_DEVICE_ORI:
|
||||
ret = "Device orientation";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_DEVICE_ORI_WU:
|
||||
ret = "Device orientation wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_STATIONARY_DET:
|
||||
ret = "Stationary detect";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_ANY_MOTION_LP:
|
||||
ret = "Low Power Any motion";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_ANY_MOTION_LP_WU:
|
||||
ret = "Low Power Any motion wake up";
|
||||
break;
|
||||
case BHI3_SENSOR_ID_NO_MOTION_LP_WU:
|
||||
ret = "Low Power No Motion wake up";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_MOTION_DET:
|
||||
ret = "Motion detect";
|
||||
break;
|
||||
case BHI3_SENSOR_ID_AR_WEAR_WU:
|
||||
ret = "Activity recognition for Wearables";
|
||||
break;
|
||||
case BHI3_SENSOR_ID_WRIST_WEAR_LP_WU:
|
||||
ret = "Low Power Wrist Wear wake up";
|
||||
break;
|
||||
case BHI3_SENSOR_ID_WRIST_GEST_DETECT_LP_WU:
|
||||
ret = "Low Power Wrist Gesture wake up";
|
||||
break;
|
||||
case BHI3_SENSOR_ID_MULTI_TAP:
|
||||
ret = "Multi Tap Detector";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_AIR_QUALITY:
|
||||
ret = "Air Quality";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG:
|
||||
ret = "Head Misalignment Calibrator";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_IMU_HEAD_ORI_Q:
|
||||
ret = "IMU Head Orientation Quaternion";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q:
|
||||
ret = "NDOF Head Orientation Quaternion";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_IMU_HEAD_ORI_E:
|
||||
ret = "IMU Head Orientation Euler";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_E:
|
||||
ret = "NDOF Head Orientation Euler";
|
||||
break;
|
||||
default:
|
||||
if ((sensor_id >= BHY2_SENSOR_ID_CUSTOM_START) && (sensor_id <= BHY2_SENSOR_ID_CUSTOM_END)) {
|
||||
ret = "Custom sensor ID ";
|
||||
} else {
|
||||
ret = "Undefined sensor ID ";
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
float get_sensor_default_scaling(uint8_t sensor_id)
|
||||
{
|
||||
float scaling = -1.0f;
|
||||
|
||||
switch (sensor_id) {
|
||||
case BHY2_SENSOR_ID_ACC_PASS:
|
||||
case BHY2_SENSOR_ID_ACC_RAW:
|
||||
case BHY2_SENSOR_ID_ACC:
|
||||
case BHY2_SENSOR_ID_ACC_BIAS:
|
||||
case BHY2_SENSOR_ID_ACC_WU:
|
||||
case BHY2_SENSOR_ID_ACC_RAW_WU:
|
||||
case BHY2_SENSOR_ID_GRA:
|
||||
case BHY2_SENSOR_ID_GRA_WU:
|
||||
case BHY2_SENSOR_ID_LACC:
|
||||
case BHY2_SENSOR_ID_LACC_WU:
|
||||
case BHY2_SENSOR_ID_ACC_BIAS_WU:
|
||||
scaling = 1.0f / 4096.0f;
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GYRO_PASS:
|
||||
case BHY2_SENSOR_ID_GYRO_RAW:
|
||||
case BHY2_SENSOR_ID_GYRO:
|
||||
case BHY2_SENSOR_ID_GYRO_BIAS:
|
||||
case BHY2_SENSOR_ID_GYRO_WU:
|
||||
case BHY2_SENSOR_ID_GYRO_RAW_WU:
|
||||
case BHY2_SENSOR_ID_GYRO_BIAS_WU:
|
||||
scaling = 2000.0f / 32768.0f;
|
||||
break;
|
||||
case BHY2_SENSOR_ID_MAG_PASS:
|
||||
case BHY2_SENSOR_ID_MAG_RAW:
|
||||
case BHY2_SENSOR_ID_MAG:
|
||||
case BHY2_SENSOR_ID_MAG_BIAS:
|
||||
case BHY2_SENSOR_ID_MAG_WU:
|
||||
case BHY2_SENSOR_ID_MAG_RAW_WU:
|
||||
case BHY2_SENSOR_ID_MAG_BIAS_WU:
|
||||
scaling = 2500.0f / 32768.0f;
|
||||
break;
|
||||
case BHY2_SENSOR_ID_RV:
|
||||
case BHY2_SENSOR_ID_RV_WU:
|
||||
case BHY2_SENSOR_ID_GAMERV:
|
||||
case BHY2_SENSOR_ID_GAMERV_WU:
|
||||
case BHY2_SENSOR_ID_GEORV:
|
||||
case BHY2_SENSOR_ID_GEORV_WU:
|
||||
scaling = 1.0f / 16384.0f;
|
||||
break;
|
||||
case BHY2_SENSOR_ID_ORI:
|
||||
case BHY2_SENSOR_ID_ORI_WU:
|
||||
scaling = 360.0f / 32768.0f;
|
||||
break;
|
||||
case BHY2_SENSOR_ID_TEMP:
|
||||
case BHY2_SENSOR_ID_TEMP_WU:
|
||||
scaling = 1.0f / 100.0f;
|
||||
break;
|
||||
case BHY2_SENSOR_ID_BARO:
|
||||
case BHY2_SENSOR_ID_BARO_WU:
|
||||
scaling = 100.0f / 128.0f;
|
||||
break;
|
||||
case BHY2_SENSOR_ID_HUM:
|
||||
case BHY2_SENSOR_ID_HUM_WU:
|
||||
scaling = 1.0f;
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GAS:
|
||||
case BHY2_SENSOR_ID_GAS_WU:
|
||||
scaling = 1.0f;
|
||||
break;
|
||||
case BHY2_SENSOR_ID_LIGHT:
|
||||
case BHY2_SENSOR_ID_LIGHT_WU:
|
||||
scaling = 10000.0f / 216.0f;
|
||||
break;
|
||||
case BHY2_SENSOR_ID_PROX:
|
||||
case BHY2_SENSOR_ID_PROX_WU:
|
||||
scaling = 1.0f;
|
||||
break;
|
||||
case BHY2_SENSOR_ID_SI_ACCEL:
|
||||
case BHY2_SENSOR_ID_SI_GYROS:
|
||||
|
||||
/* Scaling factor already applied in firmware*/
|
||||
break;
|
||||
case BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG:
|
||||
case BHY2_SENSOR_ID_IMU_HEAD_ORI_Q:
|
||||
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q:
|
||||
scaling = 1.0f / 16384.0f; /*2^14 -> 16384*/
|
||||
break;
|
||||
case BHY2_SENSOR_ID_IMU_HEAD_ORI_E:
|
||||
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_E:
|
||||
scaling = 360.0f / 32768.0f; /*2^15 -> 32768*/
|
||||
break;
|
||||
default:
|
||||
scaling = -1.0f; /* Do not apply the scaling factor */
|
||||
}
|
||||
|
||||
return scaling;
|
||||
}
|
||||
|
||||
const char *get_sensor_parse_format(uint8_t sensor_id)
|
||||
{
|
||||
const char *ret;
|
||||
|
||||
switch (sensor_id) {
|
||||
case BHY2_SENSOR_ID_ACC_PASS:
|
||||
case BHY2_SENSOR_ID_ACC_RAW:
|
||||
case BHY2_SENSOR_ID_ACC:
|
||||
case BHY2_SENSOR_ID_ACC_BIAS:
|
||||
case BHY2_SENSOR_ID_ACC_BIAS_WU:
|
||||
case BHY2_SENSOR_ID_ACC_WU:
|
||||
case BHY2_SENSOR_ID_ACC_RAW_WU:
|
||||
case BHY2_SENSOR_ID_GYRO_PASS:
|
||||
case BHY2_SENSOR_ID_GYRO_RAW:
|
||||
case BHY2_SENSOR_ID_GYRO:
|
||||
case BHY2_SENSOR_ID_GYRO_BIAS:
|
||||
case BHY2_SENSOR_ID_GYRO_BIAS_WU:
|
||||
case BHY2_SENSOR_ID_GYRO_WU:
|
||||
case BHY2_SENSOR_ID_GYRO_RAW_WU:
|
||||
case BHY2_SENSOR_ID_MAG_PASS:
|
||||
case BHY2_SENSOR_ID_MAG_RAW:
|
||||
case BHY2_SENSOR_ID_MAG:
|
||||
case BHY2_SENSOR_ID_MAG_BIAS:
|
||||
case BHY2_SENSOR_ID_MAG_BIAS_WU:
|
||||
case BHY2_SENSOR_ID_MAG_WU:
|
||||
case BHY2_SENSOR_ID_MAG_RAW_WU:
|
||||
case BHY2_SENSOR_ID_GRA:
|
||||
case BHY2_SENSOR_ID_GRA_WU:
|
||||
case BHY2_SENSOR_ID_LACC:
|
||||
case BHY2_SENSOR_ID_LACC_WU:
|
||||
ret = "s16,s16,s16";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_RV:
|
||||
case BHY2_SENSOR_ID_RV_WU:
|
||||
case BHY2_SENSOR_ID_GAMERV:
|
||||
case BHY2_SENSOR_ID_GAMERV_WU:
|
||||
case BHY2_SENSOR_ID_GEORV:
|
||||
case BHY2_SENSOR_ID_GEORV_WU:
|
||||
ret = "s16,s16,s16,s16,u16";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_ORI:
|
||||
case BHY2_SENSOR_ID_ORI_WU:
|
||||
ret = "s16,s16,s16";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_DEVICE_ORI:
|
||||
case BHY2_SENSOR_ID_DEVICE_ORI_WU:
|
||||
case BHY2_SENSOR_ID_HUM:
|
||||
case BHY2_SENSOR_ID_HUM_WU:
|
||||
case BHY2_SENSOR_ID_PROX:
|
||||
case BHY2_SENSOR_ID_PROX_WU:
|
||||
case BHY2_SENSOR_ID_EXCAMERA:
|
||||
case BHI3_SENSOR_ID_MULTI_TAP:
|
||||
ret = "u8";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_TEMP:
|
||||
case BHY2_SENSOR_ID_TEMP_WU:
|
||||
ret = "s16";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_BARO:
|
||||
case BHY2_SENSOR_ID_BARO_WU:
|
||||
ret = "u24";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GAS:
|
||||
case BHY2_SENSOR_ID_GAS_WU:
|
||||
case BHY2_SENSOR_ID_STC:
|
||||
case BHY2_SENSOR_ID_STC_WU:
|
||||
case BHY2_SENSOR_ID_STC_LP:
|
||||
case BHY2_SENSOR_ID_STC_LP_WU:
|
||||
ret = "u32";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_KLIO:
|
||||
ret = "u8,u8,u8,u8,u8,u8,f";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_SWIM:
|
||||
ret = "u16,u16,u16,u16,u16,u16,u16";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_SI_ACCEL:
|
||||
case BHY2_SENSOR_ID_SI_GYROS:
|
||||
ret = "f,f,f";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_LIGHT:
|
||||
case BHY2_SENSOR_ID_LIGHT_WU:
|
||||
ret = "s16";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_SIG:
|
||||
case BHY2_SENSOR_ID_STD:
|
||||
case BHY2_SENSOR_ID_STD_WU:
|
||||
case BHY2_SENSOR_ID_TILT_DETECTOR:
|
||||
case BHY2_SENSOR_ID_WAKE_GESTURE:
|
||||
case BHY2_SENSOR_ID_GLANCE_GESTURE:
|
||||
case BHY2_SENSOR_ID_PICKUP_GESTURE:
|
||||
case BHY2_SENSOR_ID_SIG_LP:
|
||||
case BHY2_SENSOR_ID_SIG_LP_WU:
|
||||
case BHY2_SENSOR_ID_STD_LP:
|
||||
case BHY2_SENSOR_ID_STD_LP_WU:
|
||||
case BHY2_SENSOR_ID_WRIST_TILT_GESTURE:
|
||||
case BHY2_SENSOR_ID_STATIONARY_DET:
|
||||
case BHY2_SENSOR_ID_ANY_MOTION_LP:
|
||||
case BHY2_SENSOR_ID_ANY_MOTION_LP_WU:
|
||||
case BHI3_SENSOR_ID_NO_MOTION_LP_WU:
|
||||
case BHY2_SENSOR_ID_MOTION_DET:
|
||||
case BHI3_SENSOR_ID_WRIST_WEAR_LP_WU:
|
||||
ret = "";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_AR:
|
||||
case BHI3_SENSOR_ID_AR_WEAR_WU:
|
||||
ret = "u16";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GPS:
|
||||
ret = "st";
|
||||
break;
|
||||
case BHI3_SENSOR_ID_WRIST_GEST_DETECT_LP_WU:
|
||||
ret = "u8";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_AIR_QUALITY:
|
||||
ret = "f32,f32,f32,f32,f32,f32,f32,u8";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG:
|
||||
case BHY2_SENSOR_ID_IMU_HEAD_ORI_Q:
|
||||
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q:
|
||||
ret = "s16,s16,s16,s16,u8";
|
||||
break;
|
||||
|
||||
case BHY2_SENSOR_ID_IMU_HEAD_ORI_E:
|
||||
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_E:
|
||||
ret = "s16,s16,s16,u8";
|
||||
break;
|
||||
default:
|
||||
ret = "";
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char *get_sensor_axis_names(uint8_t sensor_id)
|
||||
{
|
||||
const char *ret;
|
||||
|
||||
switch (sensor_id) {
|
||||
case BHY2_SENSOR_ID_ACC_PASS:
|
||||
case BHY2_SENSOR_ID_ACC_RAW:
|
||||
case BHY2_SENSOR_ID_ACC:
|
||||
case BHY2_SENSOR_ID_ACC_BIAS:
|
||||
case BHY2_SENSOR_ID_ACC_BIAS_WU:
|
||||
case BHY2_SENSOR_ID_ACC_WU:
|
||||
case BHY2_SENSOR_ID_ACC_RAW_WU:
|
||||
case BHY2_SENSOR_ID_GYRO_PASS:
|
||||
case BHY2_SENSOR_ID_GYRO_RAW:
|
||||
case BHY2_SENSOR_ID_GYRO:
|
||||
case BHY2_SENSOR_ID_GYRO_BIAS:
|
||||
case BHY2_SENSOR_ID_GYRO_BIAS_WU:
|
||||
case BHY2_SENSOR_ID_GYRO_WU:
|
||||
case BHY2_SENSOR_ID_GYRO_RAW_WU:
|
||||
case BHY2_SENSOR_ID_MAG_PASS:
|
||||
case BHY2_SENSOR_ID_MAG_RAW:
|
||||
case BHY2_SENSOR_ID_MAG:
|
||||
case BHY2_SENSOR_ID_MAG_BIAS:
|
||||
case BHY2_SENSOR_ID_MAG_BIAS_WU:
|
||||
case BHY2_SENSOR_ID_MAG_WU:
|
||||
case BHY2_SENSOR_ID_MAG_RAW_WU:
|
||||
case BHY2_SENSOR_ID_GRA:
|
||||
case BHY2_SENSOR_ID_GRA_WU:
|
||||
case BHY2_SENSOR_ID_LACC:
|
||||
case BHY2_SENSOR_ID_LACC_WU:
|
||||
case BHY2_SENSOR_ID_SI_ACCEL:
|
||||
case BHY2_SENSOR_ID_SI_GYROS:
|
||||
ret = "x,y,z";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_RV:
|
||||
case BHY2_SENSOR_ID_RV_WU:
|
||||
case BHY2_SENSOR_ID_GAMERV:
|
||||
case BHY2_SENSOR_ID_GAMERV_WU:
|
||||
case BHY2_SENSOR_ID_GEORV:
|
||||
case BHY2_SENSOR_ID_GEORV_WU:
|
||||
ret = "x,y,z,w,ar";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_ORI:
|
||||
case BHY2_SENSOR_ID_ORI_WU:
|
||||
ret = "h,p,r";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_DEVICE_ORI:
|
||||
case BHY2_SENSOR_ID_DEVICE_ORI_WU:
|
||||
ret = "o";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_TEMP:
|
||||
case BHY2_SENSOR_ID_TEMP_WU:
|
||||
ret = "t";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_BARO:
|
||||
case BHY2_SENSOR_ID_BARO_WU:
|
||||
ret = "p";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_HUM:
|
||||
case BHY2_SENSOR_ID_HUM_WU:
|
||||
ret = "h";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GAS:
|
||||
case BHY2_SENSOR_ID_GAS_WU:
|
||||
ret = "g";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_KLIO:
|
||||
ret = "lin,lid,lpr,lcr,rin,rid,rc";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_SWIM:
|
||||
ret = "d,lc,f,br,bu,ba,sc";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_LIGHT:
|
||||
case BHY2_SENSOR_ID_LIGHT_WU:
|
||||
ret = "l";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_PROX:
|
||||
case BHY2_SENSOR_ID_PROX_WU:
|
||||
ret = "p";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_STC:
|
||||
case BHY2_SENSOR_ID_STC_WU:
|
||||
case BHY2_SENSOR_ID_STC_LP:
|
||||
case BHY2_SENSOR_ID_STC_LP_WU:
|
||||
case BHY2_SENSOR_ID_EXCAMERA:
|
||||
ret = "c";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_SIG:
|
||||
case BHY2_SENSOR_ID_STD:
|
||||
case BHY2_SENSOR_ID_STD_WU:
|
||||
case BHY2_SENSOR_ID_TILT_DETECTOR:
|
||||
case BHY2_SENSOR_ID_WAKE_GESTURE:
|
||||
case BHY2_SENSOR_ID_GLANCE_GESTURE:
|
||||
case BHY2_SENSOR_ID_PICKUP_GESTURE:
|
||||
case BHY2_SENSOR_ID_SIG_LP:
|
||||
case BHY2_SENSOR_ID_SIG_LP_WU:
|
||||
case BHY2_SENSOR_ID_STD_LP:
|
||||
case BHY2_SENSOR_ID_STD_LP_WU:
|
||||
case BHY2_SENSOR_ID_WRIST_TILT_GESTURE:
|
||||
case BHY2_SENSOR_ID_STATIONARY_DET:
|
||||
case BHY2_SENSOR_ID_ANY_MOTION_LP:
|
||||
case BHY2_SENSOR_ID_ANY_MOTION_LP_WU:
|
||||
case BHI3_SENSOR_ID_NO_MOTION_LP_WU:
|
||||
case BHY2_SENSOR_ID_MOTION_DET:
|
||||
case BHI3_SENSOR_ID_WRIST_WEAR_LP_WU:
|
||||
ret = "e";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_AR:
|
||||
case BHI3_SENSOR_ID_AR_WEAR_WU:
|
||||
ret = "a";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_GPS:
|
||||
ret = "g";
|
||||
break;
|
||||
case BHI3_SENSOR_ID_WRIST_GEST_DETECT_LP_WU:
|
||||
ret = "wrist_gesture";
|
||||
break;
|
||||
case BHI3_SENSOR_ID_MULTI_TAP:
|
||||
ret = "taps";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_AIR_QUALITY:
|
||||
ret = "t,h,g,i,si,c,v,a";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG:
|
||||
case BHY2_SENSOR_ID_IMU_HEAD_ORI_Q:
|
||||
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q:
|
||||
ret = "x,y,z,w,a";
|
||||
break;
|
||||
case BHY2_SENSOR_ID_IMU_HEAD_ORI_E:
|
||||
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_E:
|
||||
ret = "h,p,r,a";
|
||||
break;
|
||||
default:
|
||||
ret = "";
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void check_bhy2_api(unsigned int line, const char *func, int8_t val)
|
||||
{
|
||||
int i = 3;
|
||||
while (i--) {
|
||||
|
||||
Serial.printf("BHI260 API failed at line %u. The function %s returned error code %d. %s\r\n",
|
||||
line,
|
||||
func,
|
||||
val,
|
||||
get_api_error(val));
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* 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 common.h
|
||||
* @brief Common header file for the BHI260/BHA260 examples
|
||||
* @note Adapting Arduino based on BHY2-Sensor-API by lewis
|
||||
*/
|
||||
|
||||
#ifndef _COMMON_H_
|
||||
#define _COMMON_H_
|
||||
|
||||
#include "bosch_interfaces.h"
|
||||
#include "bosch/bhy2.h"
|
||||
#include "bosch/bhi3.h"
|
||||
#include "bosch/bhi3_multi_tap.h"
|
||||
#include "bosch/bhy2_klio.h"
|
||||
#include "bosch/bhy2_swim.h"
|
||||
#include "bosch/bhy2_bsec.h"
|
||||
#include "bosch/bhy2_head_tracker.h"
|
||||
|
||||
|
||||
#define BHY2_ASSERT(x) if (x) check_bhy2_api(__LINE__, __FUNCTION__, x)
|
||||
|
||||
|
||||
|
||||
void check_bhy2_api(unsigned int line, const char *func, int8_t val);
|
||||
void time_to_s_ns(uint64_t time_ticks, uint32_t *s, uint32_t *ns, uint64_t *tns);
|
||||
const char *get_api_error(int8_t error_code);
|
||||
const char *get_sensor_error_text(uint8_t sensor_error);
|
||||
const char *get_sensor_name(uint8_t sensor_id);
|
||||
float get_sensor_default_scaling(uint8_t sensor_id);
|
||||
const char *get_sensor_parse_format(uint8_t sensor_id);
|
||||
const char *get_sensor_axis_names(uint8_t sensor_id);
|
||||
|
||||
|
||||
#endif /* _COMMON_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user