diff --git a/LICENSE b/LICENSE index df241f2..315dfa2 100644 --- a/LICENSE +++ b/LICENSE @@ -6,15 +6,15 @@ 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. + 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. + 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. + 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 diff --git a/README.md b/README.md index fef3574..c73b656 100644 --- a/README.md +++ b/README.md @@ -25,4 +25,3 @@ For more information, please refer to: - [Community support page](https://community.bosch-sensortec.com) ------------ -#### Copyright (C) 2019 Bosch Sensortec GmbH \ No newline at end of file diff --git a/bma400.c b/bma400.c index 96fd124..d6460f4 100644 --- a/bma400.c +++ b/bma400.c @@ -30,9 +30,9 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * -* @file bma400.c -* @date 10/01/2020 -* @version 1.5.6 +* @file bma400.c +* @date 2020-06-05 +* @version v1.5.8 * */ @@ -41,7 +41,7 @@ /* * @brief Accel self test diff xyz data structure */ -struct selftest_delta_limit +struct bma400_selftest_delta_limit { /* Accel X data */ int32_t x; @@ -53,40 +53,50 @@ struct selftest_delta_limit int32_t z; }; +/************************************************************************************/ +/*********************** Static function declarations *******************************/ +/************************************************************************************/ + /* - * @brief This API is used to calculate the power of given - * base value. + * @brief This internal API is used to validate the device pointer for + * null conditions. * - * @param[in] base : value of base - * @param[in] resolution : resolution of the sensor + * @param[in] dev : Structure instance of bma400_dev. * - * @return : return the value of base^resolution + * @return Result of API execution status + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int32_t power(int16_t base, uint8_t resolution); +static int8_t null_ptr_check(const struct bma400_dev *dev); /* - * @brief This API converts lsb value of axes to mg for self-test + * @brief This internal API is used to set sensor configurations * - * @param[in] accel_data_diff : Pointer variable used to pass accel difference - * values in g - * @param[out] accel_data_diff_mg : Pointer variable used to store accel - * difference values in mg + * @param[in] data : Data to be mapped with interrupt + * @param[in] conf : Sensor configurations to be set + * @param[in] dev : Structure instance of bma400_dev * - * @return None * + * @return Result of API execution status + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static void convert_lsb_g(const struct selftest_delta_limit *accel_data_diff, - struct selftest_delta_limit *accel_data_diff_mg); +static int8_t set_sensor_conf(uint8_t *data, const struct bma400_sensor_conf *conf, struct bma400_dev *dev); /* - * @brief This internal API is used to validate the device pointer for - * null conditions. + * @brief This internal API is used to get sensor configurations * - * @param[in] dev : Structure instance of bma400_dev. + * @param[in] data : Data to be mapped with interrupt + * @param[in] conf : Sensor configurations to be set + * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t null_ptr_check(const struct bma400_dev *dev); +static int8_t get_sensor_conf(const uint8_t *data, struct bma400_sensor_conf *conf, struct bma400_dev *dev); /* * @brief This internal API is used to set the accel configurations in sensor @@ -95,9 +105,11 @@ static int8_t null_ptr_check(const struct bma400_dev *dev); * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t set_accel_conf(const struct bma400_acc_conf *accel_conf, const struct bma400_dev *dev); +static int8_t set_accel_conf(const struct bma400_acc_conf *accel_conf, struct bma400_dev *dev); /* * @brief This API reads accel data along with sensor time @@ -111,9 +123,11 @@ static int8_t set_accel_conf(const struct bma400_acc_conf *accel_conf, const str * - BMA400_DATA_SENSOR_TIME * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, const struct bma400_dev *dev); +static int8_t get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, struct bma400_dev *dev); /* * @brief This API enables the auto-wakeup feature @@ -123,9 +137,11 @@ static int8_t get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t set_autowakeup_timeout(const struct bma400_auto_wakeup_conf *wakeup_conf, const struct bma400_dev *dev); +static int8_t set_autowakeup_timeout(const struct bma400_auto_wakeup_conf *wakeup_conf, struct bma400_dev *dev); /* * @brief This API enables the auto-wakeup feature of the sensor @@ -135,9 +151,11 @@ static int8_t set_autowakeup_timeout(const struct bma400_auto_wakeup_conf *wakeu * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t set_auto_wakeup(uint8_t conf, const struct bma400_dev *dev); +static int8_t set_auto_wakeup(uint8_t conf, struct bma400_dev *dev); /* * @brief This API sets the parameters for auto-wakeup feature @@ -147,9 +165,11 @@ static int8_t set_auto_wakeup(uint8_t conf, const struct bma400_dev *dev); * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t set_autowakeup_interrupt(const struct bma400_wakeup_conf *wakeup_conf, const struct bma400_dev *dev); +static int8_t set_autowakeup_interrupt(const struct bma400_wakeup_conf *wakeup_conf, struct bma400_dev *dev); /* * @brief This API sets the sensor to enter low power mode @@ -159,9 +179,11 @@ static int8_t set_autowakeup_interrupt(const struct bma400_wakeup_conf *wakeup_c * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t set_auto_low_power(const struct bma400_auto_lp_conf *auto_lp_conf, const struct bma400_dev *dev); +static int8_t set_auto_low_power(const struct bma400_auto_lp_conf *auto_lp_conf, struct bma400_dev *dev); /* * @brief This API sets the tap setting parameters @@ -170,9 +192,11 @@ static int8_t set_auto_low_power(const struct bma400_auto_lp_conf *auto_lp_conf, * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t set_tap_conf(const struct bma400_tap_conf *tap_set, const struct bma400_dev *dev); +static int8_t set_tap_conf(const struct bma400_tap_conf *tap_set, struct bma400_dev *dev); /* * @brief This API sets the parameters for activity change detection @@ -182,9 +206,11 @@ static int8_t set_tap_conf(const struct bma400_tap_conf *tap_set, const struct b * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t set_activity_change_conf(const struct bma400_act_ch_conf *act_ch_set, const struct bma400_dev *dev); +static int8_t set_activity_change_conf(const struct bma400_act_ch_conf *act_ch_set, struct bma400_dev *dev); /* * @brief This API sets the parameters for generic interrupt1 configuration @@ -194,9 +220,11 @@ static int8_t set_activity_change_conf(const struct bma400_act_ch_conf *act_ch_s * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t set_gen1_int(const struct bma400_gen_int_conf *gen_int_set, const struct bma400_dev *dev); +static int8_t set_gen1_int(const struct bma400_gen_int_conf *gen_int_set, struct bma400_dev *dev); /* * @brief This API sets the parameters for generic interrupt2 configuration @@ -206,9 +234,11 @@ static int8_t set_gen1_int(const struct bma400_gen_int_conf *gen_int_set, const * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t set_gen2_int(const struct bma400_gen_int_conf *gen_int_set, const struct bma400_dev *dev); +static int8_t set_gen2_int(const struct bma400_gen_int_conf *gen_int_set, struct bma400_dev *dev); /* * @brief This API sets the parameters for orientation interrupt @@ -218,9 +248,11 @@ static int8_t set_gen2_int(const struct bma400_gen_int_conf *gen_int_set, const * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t set_orient_int(const struct bma400_orient_int_conf *orient_conf, const struct bma400_dev *dev); +static int8_t set_orient_int(const struct bma400_orient_int_conf *orient_conf, struct bma400_dev *dev); /* * @brief This internal API is used to get the accel configurations in sensor @@ -230,9 +262,11 @@ static int8_t set_orient_int(const struct bma400_orient_int_conf *orient_conf, c * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t get_accel_conf(struct bma400_acc_conf *accel_conf, const struct bma400_dev *dev); +static int8_t get_accel_conf(struct bma400_acc_conf *accel_conf, struct bma400_dev *dev); /* * @brief This API gets the set sensor settings for auto-wakeup timeout feature @@ -241,9 +275,11 @@ static int8_t get_accel_conf(struct bma400_acc_conf *accel_conf, const struct bm * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t get_autowakeup_timeout(struct bma400_auto_wakeup_conf *wakeup_conf, const struct bma400_dev *dev); +static int8_t get_autowakeup_timeout(struct bma400_auto_wakeup_conf *wakeup_conf, struct bma400_dev *dev); /* * @brief This API gets the set sensor settings for @@ -253,9 +289,11 @@ static int8_t get_autowakeup_timeout(struct bma400_auto_wakeup_conf *wakeup_conf * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t get_autowakeup_interrupt(struct bma400_wakeup_conf *wakeup_conf, const struct bma400_dev *dev); +static int8_t get_autowakeup_interrupt(struct bma400_wakeup_conf *wakeup_conf, struct bma400_dev *dev); /* * @brief This API gets the sensor to get the auto-low @@ -266,9 +304,11 @@ static int8_t get_autowakeup_interrupt(struct bma400_wakeup_conf *wakeup_conf, c * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t get_auto_low_power(struct bma400_auto_lp_conf *auto_lp_conf, const struct bma400_dev *dev); +static int8_t get_auto_low_power(struct bma400_auto_lp_conf *auto_lp_conf, struct bma400_dev *dev); /* * @brief This API sets the tap setting parameters @@ -277,9 +317,11 @@ static int8_t get_auto_low_power(struct bma400_auto_lp_conf *auto_lp_conf, const * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t get_tap_conf(struct bma400_tap_conf *tap_set, const struct bma400_dev *dev); +static int8_t get_tap_conf(struct bma400_tap_conf *tap_set, struct bma400_dev *dev); /* * @brief This API gets the parameters for activity change detection @@ -289,9 +331,11 @@ static int8_t get_tap_conf(struct bma400_tap_conf *tap_set, const struct bma400_ * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t get_activity_change_conf(struct bma400_act_ch_conf *act_ch_set, const struct bma400_dev *dev); +static int8_t get_activity_change_conf(struct bma400_act_ch_conf *act_ch_set, struct bma400_dev *dev); /* * @brief This API gets the generic interrupt1 configuration @@ -301,9 +345,11 @@ static int8_t get_activity_change_conf(struct bma400_act_ch_conf *act_ch_set, co * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t get_gen1_int(struct bma400_gen_int_conf *gen_int_set, const struct bma400_dev *dev); +static int8_t get_gen1_int(struct bma400_gen_int_conf *gen_int_set, struct bma400_dev *dev); /* * @brief This API gets the generic interrupt2 configuration @@ -313,9 +359,11 @@ static int8_t get_gen1_int(struct bma400_gen_int_conf *gen_int_set, const struct * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t get_gen2_int(struct bma400_gen_int_conf *gen_int_set, const struct bma400_dev *dev); +static int8_t get_gen2_int(struct bma400_gen_int_conf *gen_int_set, struct bma400_dev *dev); /* * @brief This API gets the parameters for orientation interrupt @@ -325,9 +373,11 @@ static int8_t get_gen2_int(struct bma400_gen_int_conf *gen_int_set, const struct * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t get_orient_int(struct bma400_orient_int_conf *orient_conf, const struct bma400_dev *dev); +static int8_t get_orient_int(struct bma400_orient_int_conf *orient_conf, struct bma400_dev *dev); /* * @brief This API sets the selected interrupt to be mapped to @@ -375,9 +425,11 @@ static void get_int_pin_map(const uint8_t *data_array, uint8_t int_enable, enum * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t set_int_pin_conf(struct bma400_int_pin_conf int_conf, const struct bma400_dev *dev); +static int8_t set_int_pin_conf(struct bma400_int_pin_conf int_conf, struct bma400_dev *dev); /* * @brief This API is used to set the interrupt pin configurations @@ -386,9 +438,11 @@ static int8_t set_int_pin_conf(struct bma400_int_pin_conf int_conf, const struct * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t get_int_pin_conf(struct bma400_int_pin_conf *int_conf, const struct bma400_dev *dev); +static int8_t get_int_pin_conf(struct bma400_int_pin_conf *int_conf, struct bma400_dev *dev); /* * @brief This API is used to set the FIFO configurations @@ -398,9 +452,11 @@ static int8_t get_int_pin_conf(struct bma400_int_pin_conf *int_conf, const struc * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t set_fifo_conf(const struct bma400_fifo_conf *fifo_conf, const struct bma400_dev *dev); +static int8_t set_fifo_conf(const struct bma400_fifo_conf *fifo_conf, struct bma400_dev *dev); /* * @brief This API is used to get the FIFO configurations @@ -412,7 +468,7 @@ static int8_t set_fifo_conf(const struct bma400_fifo_conf *fifo_conf, const stru * @return Result of API execution status * @retval zero -> Success / +ve value -> Warning / -ve value -> Error */ -static int8_t get_fifo_conf(struct bma400_fifo_conf *fifo_conf, const struct bma400_dev *dev); +static int8_t get_fifo_conf(struct bma400_fifo_conf *fifo_conf, struct bma400_dev *dev); /* * @brief This API is used to get the number of bytes filled in FIFO @@ -422,9 +478,11 @@ static int8_t get_fifo_conf(struct bma400_fifo_conf *fifo_conf, const struct bma * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t get_fifo_length(uint16_t *fifo_byte_cnt, const struct bma400_dev *dev); +static int8_t get_fifo_length(uint16_t *fifo_byte_cnt, struct bma400_dev *dev); /* * @brief This API is used to read the FIFO of BMA400 @@ -434,9 +492,11 @@ static int8_t get_fifo_length(uint16_t *fifo_byte_cnt, const struct bma400_dev * * @param[in] dev : Structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -static int8_t read_fifo(const struct bma400_fifo_data *fifo, const struct bma400_dev *dev); +static int8_t read_fifo(struct bma400_fifo_data *fifo, struct bma400_dev *dev); /* * @brief This API is used to unpack the accelerometer frames from the FIFO @@ -511,7 +571,9 @@ static void unpack_sensortime_frame(struct bma400_fifo_data *fifo, uint16_t *dat *@param[in] dev : structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error / +ve value -> Self test fail + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ static int8_t validate_accel_self_test(const struct bma400_sensor_data *accel_pos, const struct bma400_sensor_data *accel_neg); @@ -524,9 +586,10 @@ static int8_t validate_accel_self_test(const struct bma400_sensor_data *accel_po * @param[in] dev : structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error + * @retval zero -> Success + * @retval -ve value -> Error */ -static int8_t positive_excited_accel(struct bma400_sensor_data *accel_pos, const struct bma400_dev *dev); +static int8_t positive_excited_accel(struct bma400_sensor_data *accel_pos, struct bma400_dev *dev); /* * @brief This API performs self test with negative excitation @@ -536,9 +599,10 @@ static int8_t positive_excited_accel(struct bma400_sensor_data *accel_pos, const * @param[in] dev : structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error + * @retval zero -> Success + * @retval -ve value -> Error */ -static int8_t negative_excited_accel(struct bma400_sensor_data *accel_neg, const struct bma400_dev *dev); +static int8_t negative_excited_accel(struct bma400_sensor_data *accel_neg, struct bma400_dev *dev); /* * @brief This API performs the pre-requisites needed to perform the self test @@ -546,9 +610,14 @@ static int8_t negative_excited_accel(struct bma400_sensor_data *accel_neg, const * @param[in] dev : structure instance of bma400_dev * * @return Result of API execution status - * @retval zero -> Success / -ve value -> Error + * @retval zero -> Success + * @retval -ve value -> Error */ -static int8_t enable_self_test(const struct bma400_dev *dev); +static int8_t enable_self_test(struct bma400_dev *dev); + +/************************************************************************************/ +/*********************** User function definitions **********************************/ +/************************************************************************************/ int8_t bma400_init(struct bma400_dev *dev) { @@ -562,7 +631,7 @@ int8_t bma400_init(struct bma400_dev *dev) if (rslt == BMA400_OK) { /* Initial power-up time */ - dev->delay_ms(5); + dev->delay_us(5000, dev->intf_ptr); /* Assigning dummy byte value */ if (dev->intf == BMA400_SPI_INTF) @@ -571,16 +640,17 @@ int8_t bma400_init(struct bma400_dev *dev) dev->dummy_byte = 1; /* Dummy read of Chip-ID in SPI mode */ - rslt = bma400_get_regs(BMA400_CHIP_ID_ADDR, &chip_id, 1, dev); + rslt = bma400_get_regs(BMA400_REG_CHIP_ID, &chip_id, 1, dev); } else { dev->dummy_byte = 0; } + if (rslt == BMA400_OK) { /* Chip ID of the sensor is read */ - rslt = bma400_get_regs(BMA400_CHIP_ID_ADDR, &chip_id, 1, dev); + rslt = bma400_get_regs(BMA400_REG_CHIP_ID, &chip_id, 1, dev); /* Proceed if everything is fine until now */ if (rslt == BMA400_OK) @@ -602,7 +672,7 @@ int8_t bma400_init(struct bma400_dev *dev) return rslt; } -int8_t bma400_set_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const struct bma400_dev *dev) +int8_t bma400_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, struct bma400_dev *dev) { int8_t rslt; uint8_t count; @@ -620,8 +690,8 @@ int8_t bma400_set_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const s */ if (len == 1) { - rslt = dev->write(dev->dev_id, reg_addr, reg_data, len); - if (rslt != BMA400_OK) + dev->intf_rslt = dev->write(reg_addr, reg_data, len, dev->intf_ptr); + if (dev->intf_rslt != BMA400_INTF_RET_SUCCESS) { /* Failure case */ rslt = BMA400_E_COM_FAIL; @@ -634,10 +704,15 @@ int8_t bma400_set_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const s */ if (len > 1) { - for (count = 0; count < len; count++) + for (count = 0; (count < len) && (rslt == BMA400_OK); count++) { - rslt = dev->write(dev->dev_id, reg_addr, ®_data[count], 1); + dev->intf_rslt = dev->write(reg_addr, ®_data[count], 1, dev->intf_ptr); reg_addr++; + if (dev->intf_rslt != BMA400_INTF_RET_SUCCESS) + { + /* Failure case */ + rslt = BMA400_E_COM_FAIL; + } } } } @@ -649,12 +724,10 @@ int8_t bma400_set_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const s return rslt; } -int8_t bma400_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const struct bma400_dev *dev) +int8_t bma400_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bma400_dev *dev) { int8_t rslt; uint16_t index; - uint16_t temp_len = len + dev->dummy_byte; - uint8_t temp_buff[temp_len]; /* Check for null pointer in the device structure */ rslt = null_ptr_check(dev); @@ -662,6 +735,9 @@ int8_t bma400_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const s /* Proceed if null check is fine */ if ((rslt == BMA400_OK) && (reg_data != NULL)) { + uint32_t temp_len = len + dev->dummy_byte; + uint8_t temp_buff[temp_len]; + if (dev->intf != BMA400_I2C_INTF) { /* If interface selected is SPI */ @@ -669,8 +745,8 @@ int8_t bma400_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const s } /* Read the data from the reg_addr */ - rslt = dev->read(dev->dev_id, reg_addr, temp_buff, temp_len); - if (rslt == BMA400_OK) + dev->intf_rslt = dev->read(reg_addr, temp_buff, temp_len, dev->intf_ptr); + if (dev->intf_rslt == BMA400_INTF_RET_SUCCESS) { for (index = 0; index < len; index++) { @@ -681,7 +757,7 @@ int8_t bma400_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const s reg_data[index] = temp_buff[index + dev->dummy_byte]; } } - if (rslt != BMA400_OK) + else { /* Failure case */ rslt = BMA400_E_COM_FAIL; @@ -695,7 +771,7 @@ int8_t bma400_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const s return rslt; } -int8_t bma400_soft_reset(const struct bma400_dev *dev) +int8_t bma400_soft_reset(struct bma400_dev *dev) { int8_t rslt; uint8_t data = BMA400_SOFT_RESET_CMD; @@ -705,8 +781,8 @@ int8_t bma400_soft_reset(const struct bma400_dev *dev) if (rslt == BMA400_OK) { /* Reset the device */ - rslt = bma400_set_regs(BMA400_COMMAND_REG_ADDR, &data, 1, dev); - dev->delay_ms(BMA400_SOFT_RESET_DELAY_MS); + rslt = bma400_set_regs(BMA400_REG_COMMAND, &data, 1, dev); + dev->delay_us(BMA400_DELAY_US_SOFT_RESET, dev->intf_ptr); if ((rslt == BMA400_OK) && (dev->intf == BMA400_SPI_INTF)) { /* Dummy read of 0x7F register to enable SPI Interface @@ -719,7 +795,7 @@ int8_t bma400_soft_reset(const struct bma400_dev *dev) return rslt; } -int8_t bma400_set_power_mode(uint8_t power_mode, const struct bma400_dev *dev) +int8_t bma400_set_power_mode(uint8_t power_mode, struct bma400_dev *dev) { int8_t rslt; uint8_t reg_data = 0; @@ -727,32 +803,33 @@ int8_t bma400_set_power_mode(uint8_t power_mode, const struct bma400_dev *dev) rslt = null_ptr_check(dev); if (rslt == BMA400_OK) { - rslt = bma400_get_regs(BMA400_ACCEL_CONFIG_0_ADDR, ®_data, 1, dev); + rslt = bma400_get_regs(BMA400_REG_ACCEL_CONFIG_0, ®_data, 1, dev); } + if (rslt == BMA400_OK) { reg_data = BMA400_SET_BITS_POS_0(reg_data, BMA400_POWER_MODE, power_mode); /* Set the power mode of sensor */ - rslt = bma400_set_regs(BMA400_ACCEL_CONFIG_0_ADDR, ®_data, 1, dev); - if (power_mode == BMA400_LOW_POWER_MODE) + rslt = bma400_set_regs(BMA400_REG_ACCEL_CONFIG_0, ®_data, 1, dev); + if (power_mode == BMA400_MODE_LOW_POWER) { /* A delay of 1/ODR is required to switch power modes * Low power mode has 25Hz frequency and hence it needs * 40ms delay to enter low power mode */ - dev->delay_ms(40); + dev->delay_us(40000, dev->intf_ptr); } else { - dev->delay_ms(10); /* TBC */ + dev->delay_us(10000, dev->intf_ptr); /* TBC */ } } return rslt; } -int8_t bma400_get_power_mode(uint8_t *power_mode, const struct bma400_dev *dev) +int8_t bma400_get_power_mode(uint8_t *power_mode, struct bma400_dev *dev) { int8_t rslt; uint8_t reg_data; @@ -761,16 +838,20 @@ int8_t bma400_get_power_mode(uint8_t *power_mode, const struct bma400_dev *dev) rslt = null_ptr_check(dev); /* Proceed if null check is fine */ - if (rslt == BMA400_OK) + if ((rslt == BMA400_OK) && (power_mode != NULL)) { - rslt = bma400_get_regs(BMA400_STATUS_ADDR, ®_data, 1, dev); + rslt = bma400_get_regs(BMA400_REG_STATUS, ®_data, 1, dev); *power_mode = BMA400_GET_BITS(reg_data, BMA400_POWER_MODE_STATUS); } + else + { + rslt = BMA400_E_NULL_PTR; + } return rslt; } -int8_t bma400_get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, const struct bma400_dev *dev) +int8_t bma400_get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, struct bma400_dev *dev) { int8_t rslt; @@ -778,7 +859,7 @@ int8_t bma400_get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, rslt = null_ptr_check(dev); /* Proceed if null check is fine */ - if ((rslt == BMA400_OK) || (accel != NULL)) + if ((rslt == BMA400_OK) && (accel != NULL)) { /* Read and store the accel data */ rslt = get_accel_data(data_sel, accel, dev); @@ -791,7 +872,7 @@ int8_t bma400_get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, return rslt; } -int8_t bma400_set_sensor_conf(const struct bma400_sensor_conf *conf, uint16_t n_sett, const struct bma400_dev *dev) +int8_t bma400_set_sensor_conf(const struct bma400_sensor_conf *conf, uint16_t n_sett, struct bma400_dev *dev) { int8_t rslt; uint16_t idx = 0; @@ -801,252 +882,131 @@ int8_t bma400_set_sensor_conf(const struct bma400_sensor_conf *conf, uint16_t n_ rslt = null_ptr_check(dev); /* Proceed if null check is fine */ - if (rslt == BMA400_OK) + if ((rslt == BMA400_OK) && (conf != NULL)) { /* Read the interrupt pin mapping configurations */ - rslt = bma400_get_regs(BMA400_INT_MAP_ADDR, data_array, 3, dev); + rslt = bma400_get_regs(BMA400_REG_INT_MAP, data_array, 3, dev); if (rslt == BMA400_OK) { - for (idx = 0; idx < n_sett; idx++) + for (idx = 0; (idx < n_sett) && (rslt == BMA400_OK); idx++) { - switch (conf[idx].type) - { - case BMA400_ACCEL: - - /* Setting Accel configurations */ - rslt = set_accel_conf(&conf[idx].param.accel, dev); - if (rslt == BMA400_OK) - { - /* Int pin mapping settings */ - map_int_pin(data_array, BMA400_DATA_READY_INT_MAP, conf[idx].param.accel.int_chan); - } - break; - case BMA400_TAP_INT: - - /* Setting TAP configurations */ - rslt = set_tap_conf(&conf[idx].param.tap, dev); - if (rslt == BMA400_OK) - { - /* Int pin mapping settings */ - map_int_pin(data_array, BMA400_TAP_INT_MAP, conf[idx].param.tap.int_chan); - } - break; - case BMA400_ACTIVITY_CHANGE_INT: - - /* Setting activity change config */ - rslt = set_activity_change_conf(&conf[idx].param.act_ch, dev); - if (rslt == BMA400_OK) - { - /* Int pin mapping settings */ - map_int_pin(data_array, BMA400_ACT_CH_INT_MAP, conf[idx].param.act_ch.int_chan); - } - break; - case BMA400_GEN1_INT: - - /* Setting Generic int 1 config */ - rslt = set_gen1_int(&conf[idx].param.gen_int, dev); - if (rslt == BMA400_OK) - { - /* Int pin mapping settings */ - map_int_pin(data_array, BMA400_GEN1_INT_MAP, conf[idx].param.gen_int.int_chan); - } - break; - case BMA400_GEN2_INT: - - /* Setting Generic int 2 config */ - rslt = set_gen2_int(&conf[idx].param.gen_int, dev); - if (rslt == BMA400_OK) - { - /* Int pin mapping settings */ - map_int_pin(data_array, BMA400_GEN2_INT_MAP, conf[idx].param.gen_int.int_chan); - } - break; - case BMA400_ORIENT_CHANGE_INT: - - /* Setting orient int config */ - rslt = set_orient_int(&conf[idx].param.orient, dev); - if (rslt == BMA400_OK) - { - /* Int pin mapping settings */ - map_int_pin(data_array, BMA400_ORIENT_CH_INT_MAP, conf[idx].param.orient.int_chan); - } - break; - case BMA400_STEP_COUNTER_INT: - - /* Int pin mapping settings */ - map_int_pin(data_array, BMA400_STEP_INT_MAP, conf[idx].param.step_cnt.int_chan); - break; - } + rslt = set_sensor_conf(data_array, conf + idx, dev); } + if (rslt == BMA400_OK) { /* Set the interrupt pin mapping configurations */ - rslt = bma400_set_regs(BMA400_INT_MAP_ADDR, data_array, 3, dev); + rslt = bma400_set_regs(BMA400_REG_INT_MAP, data_array, 3, dev); } } } + else + { + rslt = BMA400_E_NULL_PTR; + } return rslt; } -int8_t bma400_get_sensor_conf(struct bma400_sensor_conf *conf, uint16_t n_sett, const struct bma400_dev *dev) +int8_t bma400_get_sensor_conf(struct bma400_sensor_conf *conf, uint16_t n_sett, struct bma400_dev *dev) { int8_t rslt; uint16_t idx; uint8_t data_array[3] = { 0 }; - if (conf == NULL) - { - rslt = BMA400_E_NULL_PTR; - - return rslt; - } - - /* Read the interrupt pin mapping configurations */ - rslt = bma400_get_regs(BMA400_INT_MAP_ADDR, data_array, 3, dev); + /* Check for null pointer in the device structure */ + rslt = null_ptr_check(dev); - for (idx = 0; (idx < n_sett) && (rslt == BMA400_OK); idx++) + if ((rslt == BMA400_OK) && (conf != NULL)) { - switch (conf[idx].type) - { - case BMA400_ACCEL: - - /* Accel configuration settings */ - rslt = get_accel_conf(&conf[idx].param.accel, dev); - if (rslt == BMA400_OK) - { - /* Get the INT pin mapping */ - get_int_pin_map(data_array, BMA400_DATA_READY_INT_MAP, &conf[idx].param.accel.int_chan); - } - break; - case BMA400_TAP_INT: - - /* TAP configuration settings */ - rslt = get_tap_conf(&conf[idx].param.tap, dev); - if (rslt == BMA400_OK) - { - /* Get the INT pin mapping */ - get_int_pin_map(data_array, BMA400_TAP_INT_MAP, &conf[idx].param.tap.int_chan); - } - break; - case BMA400_ACTIVITY_CHANGE_INT: - - /* Activity change configurations */ - rslt = get_activity_change_conf(&conf[idx].param.act_ch, dev); - if (rslt == BMA400_OK) - { - /* Get the INT pin mapping */ - get_int_pin_map(data_array, BMA400_ACT_CH_INT_MAP, &conf[idx].param.act_ch.int_chan); - } - break; - case BMA400_GEN1_INT: - - /* Generic int1 configurations */ - rslt = get_gen1_int(&conf[idx].param.gen_int, dev); - if (rslt == BMA400_OK) - { - /* Get the INT pin mapping */ - get_int_pin_map(data_array, BMA400_GEN1_INT_MAP, &conf[idx].param.gen_int.int_chan); - } - break; - case BMA400_GEN2_INT: - - /* Generic int2 configurations */ - rslt = get_gen2_int(&conf[idx].param.gen_int, dev); - if (rslt == BMA400_OK) - { - /* Get the INT pin mapping */ - get_int_pin_map(data_array, BMA400_GEN2_INT_MAP, &conf[idx].param.gen_int.int_chan); - } - break; - case BMA400_ORIENT_CHANGE_INT: - - /* Orient int configurations */ - rslt = get_orient_int(&conf[idx].param.orient, dev); - if (rslt == BMA400_OK) - { - /* Get the INT pin mapping */ - get_int_pin_map(data_array, BMA400_ORIENT_CH_INT_MAP, &conf[idx].param.orient.int_chan); - } - break; - case BMA400_STEP_COUNTER_INT: + /* Read the interrupt pin mapping configurations */ + rslt = bma400_get_regs(BMA400_REG_INT_MAP, data_array, 3, dev); - /* Get int pin mapping settings */ - get_int_pin_map(data_array, BMA400_STEP_INT_MAP, &conf[idx].param.step_cnt.int_chan); - break; - default: - rslt = BMA400_E_INVALID_CONFIG; + for (idx = 0; (idx < n_sett) && (rslt == BMA400_OK); idx++) + { + rslt = get_sensor_conf(data_array, conf + idx, dev); } } + else + { + rslt = BMA400_E_NULL_PTR; + } return rslt; } -int8_t bma400_set_device_conf(const struct bma400_device_conf *conf, uint8_t n_sett, const struct bma400_dev *dev) +int8_t bma400_set_device_conf(const struct bma400_device_conf *conf, uint8_t n_sett, struct bma400_dev *dev) { - int8_t rslt = BMA400_OK; + int8_t rslt; uint16_t idx; uint8_t data_array[3] = { 0 }; - if (conf == NULL) - { - rslt = BMA400_E_NULL_PTR; + /* Check for null pointer in the device structure */ + rslt = null_ptr_check(dev); - return rslt; - } + if ((rslt == BMA400_OK) && (conf != NULL)) + { - /* Read the interrupt pin mapping configurations */ - rslt = bma400_get_regs(BMA400_INT_MAP_ADDR, data_array, 3, dev); + /* Read the interrupt pin mapping configurations */ + rslt = bma400_get_regs(BMA400_REG_INT_MAP, data_array, 3, dev); - for (idx = 0; (idx < n_sett) && (rslt == BMA400_OK); idx++) - { - switch (conf[idx].type) + for (idx = 0; (idx < n_sett) && (rslt == BMA400_OK); idx++) { - case BMA400_AUTOWAKEUP_TIMEOUT: - rslt = set_autowakeup_timeout(&conf[idx].param.auto_wakeup, dev); - break; - case BMA400_AUTOWAKEUP_INT: - rslt = set_autowakeup_interrupt(&conf[idx].param.wakeup, dev); - if (rslt == BMA400_OK) - { - /* Interrupt pin mapping */ - map_int_pin(data_array, BMA400_WAKEUP_INT_MAP, conf[idx].param.wakeup.int_chan); - } - break; - case BMA400_AUTO_LOW_POWER: - rslt = set_auto_low_power(&conf[idx].param.auto_lp, dev); - break; - case BMA400_INT_PIN_CONF: - rslt = set_int_pin_conf(conf[idx].param.int_conf, dev); - break; - case BMA400_INT_OVERRUN_CONF: + switch (conf[idx].type) + { + case BMA400_AUTOWAKEUP_TIMEOUT: + rslt = set_autowakeup_timeout(&conf[idx].param.auto_wakeup, dev); + break; + case BMA400_AUTOWAKEUP_INT: + rslt = set_autowakeup_interrupt(&conf[idx].param.wakeup, dev); + if (rslt == BMA400_OK) + { + /* Interrupt pin mapping */ + map_int_pin(data_array, BMA400_WAKEUP_INT_MAP, conf[idx].param.wakeup.int_chan); + } + + break; + case BMA400_AUTO_LOW_POWER: + rslt = set_auto_low_power(&conf[idx].param.auto_lp, dev); + break; + case BMA400_INT_PIN_CONF: + rslt = set_int_pin_conf(conf[idx].param.int_conf, dev); + break; + case BMA400_INT_OVERRUN_CONF: - /* Interrupt pin mapping */ - map_int_pin(data_array, BMA400_INT_OVERRUN_MAP, conf[idx].param.overrun_int.int_chan); - break; - case BMA400_FIFO_CONF: - rslt = set_fifo_conf(&conf[idx].param.fifo_conf, dev); - if (rslt == BMA400_OK) - { /* Interrupt pin mapping */ - map_int_pin(data_array, BMA400_FIFO_WM_INT_MAP, conf[idx].param.fifo_conf.fifo_wm_channel); - map_int_pin(data_array, BMA400_FIFO_FULL_INT_MAP, conf[idx].param.fifo_conf.fifo_full_channel); - } - break; - default: - rslt = BMA400_E_INVALID_CONFIG; + map_int_pin(data_array, BMA400_INT_OVERRUN_MAP, conf[idx].param.overrun_int.int_chan); + break; + case BMA400_FIFO_CONF: + rslt = set_fifo_conf(&conf[idx].param.fifo_conf, dev); + if (rslt == BMA400_OK) + { + /* Interrupt pin mapping */ + map_int_pin(data_array, BMA400_FIFO_WM_INT_MAP, conf[idx].param.fifo_conf.fifo_wm_channel); + map_int_pin(data_array, BMA400_FIFO_FULL_INT_MAP, conf[idx].param.fifo_conf.fifo_full_channel); + } + + break; + default: + rslt = BMA400_E_INVALID_CONFIG; + } + } + + if (rslt == BMA400_OK) + { + /* Set the interrupt pin mapping configurations */ + rslt = bma400_set_regs(BMA400_REG_INT_MAP, data_array, 3, dev); } } - if (rslt == BMA400_OK) + else { - /* Set the interrupt pin mapping configurations */ - rslt = bma400_set_regs(BMA400_INT_MAP_ADDR, data_array, 3, dev); + rslt = BMA400_E_NULL_PTR; } return rslt; } -int8_t bma400_get_device_conf(struct bma400_device_conf *conf, uint8_t n_sett, const struct bma400_dev *dev) +int8_t bma400_get_device_conf(struct bma400_device_conf *conf, uint8_t n_sett, struct bma400_dev *dev) { int8_t rslt; uint16_t idx = 0; @@ -1056,57 +1016,59 @@ int8_t bma400_get_device_conf(struct bma400_device_conf *conf, uint8_t n_sett, c rslt = null_ptr_check(dev); /* Proceed if null check is fine */ - if (rslt == BMA400_OK) + if ((rslt == BMA400_OK) && (conf != NULL)) { /* Read the interrupt pin mapping configurations */ - rslt = bma400_get_regs(BMA400_INT_MAP_ADDR, data_array, 3, dev); - if (rslt == BMA400_OK) + rslt = bma400_get_regs(BMA400_REG_INT_MAP, data_array, 3, dev); + + for (idx = 0; (idx < n_sett) && (rslt == BMA400_OK); idx++) { - for (idx = 0; idx < n_sett; idx++) - { - switch (conf[idx].type) - { - case BMA400_AUTOWAKEUP_TIMEOUT: - rslt = get_autowakeup_timeout(&conf[idx].param.auto_wakeup, dev); - break; - case BMA400_AUTOWAKEUP_INT: - rslt = get_autowakeup_interrupt(&conf[idx].param.wakeup, dev); - if (rslt == BMA400_OK) - { - /* Get the INT pin mapping */ - get_int_pin_map(data_array, BMA400_WAKEUP_INT_MAP, &conf[idx].param.wakeup.int_chan); - } - break; - case BMA400_AUTO_LOW_POWER: - rslt = get_auto_low_power(&conf[idx].param.auto_lp, dev); - break; - case BMA400_INT_PIN_CONF: - rslt = get_int_pin_conf(&conf[idx].param.int_conf, dev); - break; - case BMA400_INT_OVERRUN_CONF: - get_int_pin_map(data_array, BMA400_INT_OVERRUN_MAP, &conf[idx].param.overrun_int.int_chan); - break; - case BMA400_FIFO_CONF: - rslt = get_fifo_conf(&conf[idx].param.fifo_conf, dev); - if (rslt == BMA400_OK) - { - get_int_pin_map(data_array, - BMA400_FIFO_FULL_INT_MAP, - &conf[idx].param.fifo_conf.fifo_full_channel); - get_int_pin_map(data_array, - BMA400_FIFO_WM_INT_MAP, - &conf[idx].param.fifo_conf.fifo_wm_channel); - } - break; - } + switch (conf[idx].type) + { + case BMA400_AUTOWAKEUP_TIMEOUT: + rslt = get_autowakeup_timeout(&conf[idx].param.auto_wakeup, dev); + break; + case BMA400_AUTOWAKEUP_INT: + rslt = get_autowakeup_interrupt(&conf[idx].param.wakeup, dev); + if (rslt == BMA400_OK) + { + /* Get the INT pin mapping */ + get_int_pin_map(data_array, BMA400_WAKEUP_INT_MAP, &conf[idx].param.wakeup.int_chan); + } + + break; + case BMA400_AUTO_LOW_POWER: + rslt = get_auto_low_power(&conf[idx].param.auto_lp, dev); + break; + case BMA400_INT_PIN_CONF: + rslt = get_int_pin_conf(&conf[idx].param.int_conf, dev); + break; + case BMA400_INT_OVERRUN_CONF: + get_int_pin_map(data_array, BMA400_INT_OVERRUN_MAP, &conf[idx].param.overrun_int.int_chan); + break; + case BMA400_FIFO_CONF: + rslt = get_fifo_conf(&conf[idx].param.fifo_conf, dev); + if (rslt == BMA400_OK) + { + get_int_pin_map(data_array, + BMA400_FIFO_FULL_INT_MAP, + &conf[idx].param.fifo_conf.fifo_full_channel); + get_int_pin_map(data_array, BMA400_FIFO_WM_INT_MAP, &conf[idx].param.fifo_conf.fifo_wm_channel); + } + + break; } } } + else + { + rslt = BMA400_E_NULL_PTR; + } return rslt; } -int8_t bma400_get_interrupt_status(uint16_t *int_status, const struct bma400_dev *dev) +int8_t bma400_get_interrupt_status(uint16_t *int_status, struct bma400_dev *dev) { int8_t rslt; uint8_t reg_data[3]; @@ -1115,20 +1077,24 @@ int8_t bma400_get_interrupt_status(uint16_t *int_status, const struct bma400_dev rslt = null_ptr_check(dev); /* Proceed if null check is fine */ - if (rslt == BMA400_OK) + if ((rslt == BMA400_OK) && (int_status != NULL)) { /* Read the interrupt status registers */ - rslt = bma400_get_regs(BMA400_INT_STAT0_ADDR, reg_data, 3, dev); + rslt = bma400_get_regs(BMA400_REG_INT_STAT0, reg_data, 3, dev); reg_data[1] = BMA400_SET_BITS(reg_data[1], BMA400_INT_STATUS, reg_data[2]); /* Concatenate the interrupt status to the output */ *int_status = ((uint16_t)reg_data[1] << 8) | reg_data[0]; } + else + { + rslt = BMA400_E_NULL_PTR; + } return rslt; } -int8_t bma400_set_step_counter_param(uint8_t *sccr_conf, const struct bma400_dev *dev) +int8_t bma400_set_step_counter_param(const uint8_t *sccr_conf, struct bma400_dev *dev) { int8_t rslt; @@ -1136,35 +1102,52 @@ int8_t bma400_set_step_counter_param(uint8_t *sccr_conf, const struct bma400_dev rslt = null_ptr_check(dev); /* Proceed if null check is fine */ - if (rslt == BMA400_OK) + if ((rslt == BMA400_OK) && (sccr_conf != NULL)) { /* Set the step counter parameters in the sensor */ - rslt = bma400_set_regs(0x59, sccr_conf, 25, dev); + rslt = bma400_set_regs(0x59, sccr_conf, 24, dev); + } + else + { + rslt = BMA400_E_NULL_PTR; } return rslt; } -int8_t bma400_get_steps_counted(uint32_t *step_count, uint8_t *activity_data, const struct bma400_dev *dev) +int8_t bma400_get_steps_counted(uint32_t *step_count, uint8_t *activity_data, struct bma400_dev *dev) { int8_t rslt; - uint8_t data_arrray[4]; + uint8_t data_array[4]; + + uint32_t step_count_0 = 0; + uint32_t step_count_1 = 0; + uint32_t step_count_2 = 0; /* Check for null pointer in the device structure*/ rslt = null_ptr_check(dev); /* Proceed if null check is fine */ - if (rslt == BMA400_OK) + if ((rslt == BMA400_OK) && (step_count != NULL) && (activity_data != NULL)) { - rslt = bma400_get_regs(BMA400_STEP_CNT_0_ADDR, data_arrray, 4, dev); - *step_count = ((uint32_t)data_arrray[2] << 16) | ((uint16_t)data_arrray[1] << 8) | data_arrray[0]; - *activity_data = data_arrray[3]; + rslt = bma400_get_regs(BMA400_REG_STEP_CNT_0, data_array, 4, dev); + + step_count_0 = (uint32_t)data_array[0]; + step_count_1 = (uint32_t)data_array[1] << 8; + step_count_2 = (uint32_t)data_array[2] << 16; + *step_count = step_count_0 | step_count_1 | step_count_2; + + *activity_data = data_array[3]; + } + else + { + rslt = BMA400_E_NULL_PTR; } return rslt; } -int8_t bma400_get_temperature_data(int16_t *temperature_data, const struct bma400_dev *dev) +int8_t bma400_get_temperature_data(int16_t *temperature_data, struct bma400_dev *dev) { int8_t rslt; uint8_t reg_data; @@ -1173,18 +1156,22 @@ int8_t bma400_get_temperature_data(int16_t *temperature_data, const struct bma40 rslt = null_ptr_check(dev); /* Proceed if null check is fine */ - if (rslt == BMA400_OK) + if ((rslt == BMA400_OK) && (temperature_data != NULL)) { - rslt = bma400_get_regs(BMA400_TEMP_DATA_ADDR, ®_data, 1, dev); + rslt = bma400_get_regs(BMA400_REG_TEMP_DATA, ®_data, 1, dev); /* Temperature data calculations */ - *temperature_data = (((int16_t)((int8_t)reg_data)) - 2) * 5 + 250; + *temperature_data = (int16_t)(((int8_t)reg_data) * 5) + 230; + } + else + { + rslt = BMA400_E_NULL_PTR; } return rslt; } -int8_t bma400_get_interrupts_enabled(struct bma400_int_enable *int_select, uint8_t n_sett, const struct bma400_dev *dev) +int8_t bma400_get_interrupts_enabled(struct bma400_int_enable *int_select, uint8_t n_sett, struct bma400_dev *dev) { int8_t rslt; uint8_t idx = 0; @@ -1195,9 +1182,9 @@ int8_t bma400_get_interrupts_enabled(struct bma400_int_enable *int_select, uint8 rslt = null_ptr_check(dev); /* Proceed if null check is fine */ - if (rslt == BMA400_OK) + if ((rslt == BMA400_OK) && (int_select != NULL)) { - rslt = bma400_get_regs(BMA400_INT_CONF_0_ADDR, reg_data, 2, dev); + rslt = bma400_get_regs(BMA400_REG_INT_CONF_0, reg_data, 2, dev); if (rslt == BMA400_OK) { for (idx = 0; idx < n_sett; idx++) @@ -1241,12 +1228,13 @@ int8_t bma400_get_interrupts_enabled(struct bma400_int_enable *int_select, uint8 int_select[idx].conf = BMA400_GET_BITS_POS_0(reg_data[1], BMA400_EN_STEP_INT); break; case BMA400_AUTO_WAKEUP_EN: - rslt = bma400_get_regs(BMA400_AUTOWAKEUP_1_ADDR, &wkup_int, 1, dev); + rslt = bma400_get_regs(BMA400_REG_AUTOWAKEUP_1, &wkup_int, 1, dev); if (rslt == BMA400_OK) { /* Auto-Wakeup int status */ int_select[idx].conf = BMA400_GET_BITS(wkup_int, BMA400_WAKEUP_INTERRUPT); } + break; default: rslt = BMA400_E_INVALID_CONFIG; @@ -1255,11 +1243,15 @@ int8_t bma400_get_interrupts_enabled(struct bma400_int_enable *int_select, uint8 } } } + else + { + rslt = BMA400_E_NULL_PTR; + } return rslt; } -int8_t bma400_enable_interrupt(const struct bma400_int_enable *int_select, uint8_t n_sett, const struct bma400_dev *dev) +int8_t bma400_enable_interrupt(const struct bma400_int_enable *int_select, uint8_t n_sett, struct bma400_dev *dev) { int8_t rslt; uint8_t conf, idx = 0; @@ -1269,9 +1261,9 @@ int8_t bma400_enable_interrupt(const struct bma400_int_enable *int_select, uint8 rslt = null_ptr_check(dev); /* Proceed if null check is fine */ - if (rslt == BMA400_OK) + if ((rslt == BMA400_OK) && (int_select != NULL)) { - rslt = bma400_get_regs(BMA400_INT_CONF_0_ADDR, reg_data, 2, dev); + rslt = bma400_get_regs(BMA400_REG_INT_CONF_0, reg_data, 2, dev); if (rslt == BMA400_OK) { for (idx = 0; idx < n_sett; idx++) @@ -1322,18 +1314,23 @@ int8_t bma400_enable_interrupt(const struct bma400_int_enable *int_select, uint8 break; } } + if (rslt == BMA400_OK) { /* Set the configurations in the sensor */ - rslt = bma400_set_regs(BMA400_INT_CONF_0_ADDR, reg_data, 2, dev); + rslt = bma400_set_regs(BMA400_REG_INT_CONF_0, reg_data, 2, dev); } } } + else + { + rslt = BMA400_E_NULL_PTR; + } return rslt; } -int8_t bma400_get_fifo_data(struct bma400_fifo_data *fifo, const struct bma400_dev *dev) +int8_t bma400_get_fifo_data(struct bma400_fifo_data *fifo, struct bma400_dev *dev) { int8_t rslt; uint8_t data; @@ -1344,7 +1341,7 @@ int8_t bma400_get_fifo_data(struct bma400_fifo_data *fifo, const struct bma400_d rslt = null_ptr_check(dev); /* Proceed if null check is fine */ - if (rslt == BMA400_OK) + if ((rslt == BMA400_OK) && (fifo != NULL)) { /* Resetting the FIFO data byte index */ fifo->accel_byte_start_idx = 0; @@ -1355,7 +1352,7 @@ int8_t bma400_get_fifo_data(struct bma400_fifo_data *fifo, const struct bma400_d { /* Get the FIFO configurations * from the sensor */ - rslt = bma400_get_regs(BMA400_FIFO_CONFIG_0_ADDR, &data, 1, dev); + rslt = bma400_get_regs(BMA400_REG_FIFO_CONFIG_0, &data, 1, dev); if (rslt == BMA400_OK) { /* Get the data from FIFO_CONFIG0 register */ @@ -1388,6 +1385,10 @@ int8_t bma400_get_fifo_data(struct bma400_fifo_data *fifo, const struct bma400_d } } } + else + { + rslt = BMA400_E_NULL_PTR; + } return rslt; } @@ -1403,16 +1404,20 @@ int8_t bma400_extract_accel(struct bma400_fifo_data *fifo, rslt = null_ptr_check(dev); /* Proceed if null check is fine */ - if (rslt == BMA400_OK) + if ((rslt == BMA400_OK) && (fifo != NULL) && (accel_data != NULL) && (frame_count != NULL)) { /* Parse the FIFO data */ unpack_accel_frame(fifo, accel_data, frame_count, dev); } + else + { + rslt = BMA400_E_NULL_PTR; + } return rslt; } -int8_t bma400_set_fifo_flush(const struct bma400_dev *dev) +int8_t bma400_set_fifo_flush(struct bma400_dev *dev) { int8_t rslt; uint8_t data = BMA400_FIFO_FLUSH_CMD; @@ -1424,13 +1429,13 @@ int8_t bma400_set_fifo_flush(const struct bma400_dev *dev) if (rslt == BMA400_OK) { /* FIFO flush command is set */ - rslt = bma400_set_regs(BMA400_COMMAND_REG_ADDR, &data, 1, dev); + rslt = bma400_set_regs(BMA400_REG_COMMAND, &data, 1, dev); } return rslt; } -int8_t bma400_perform_self_test(const struct bma400_dev *dev) +int8_t bma400_perform_self_test(struct bma400_dev *dev) { int8_t rslt; int8_t self_test_rslt = 0; @@ -1460,7 +1465,7 @@ int8_t bma400_perform_self_test(const struct bma400_dev *dev) } /* Check to ensure bus error does not occur */ - if (rslt >= BMA400_OK) + if (rslt <= BMA400_OK) { /* Store the status of self test result */ self_test_rslt = rslt; @@ -1479,12 +1484,15 @@ int8_t bma400_perform_self_test(const struct bma400_dev *dev) return rslt; } -/*****************************INTERNAL APIs***********************************************/ +/************************************************************************************/ +/*********************** Static function definitions **********************************/ +/************************************************************************************/ + static int8_t null_ptr_check(const struct bma400_dev *dev) { int8_t rslt; - if ((dev == NULL) || (dev->read == NULL) || (dev->write == NULL) || (dev->delay_ms == NULL)) + if ((dev == NULL) || (dev->read == NULL) || (dev->write == NULL) || (dev->intf_ptr == NULL)) { /* Device structure pointer is not valid */ rslt = BMA400_E_NULL_PTR; @@ -1498,7 +1506,147 @@ static int8_t null_ptr_check(const struct bma400_dev *dev) return rslt; } -static int8_t set_accel_conf(const struct bma400_acc_conf *accel_conf, const struct bma400_dev *dev) +static int8_t set_sensor_conf(uint8_t *data, const struct bma400_sensor_conf *conf, struct bma400_dev *dev) +{ + int8_t rslt = BMA400_E_INVALID_CONFIG; + uint8_t int_enable = 0; + enum bma400_int_chan int_map = BMA400_UNMAP_INT_PIN; + + if (BMA400_ACCEL == conf->type) + { + /* Setting Accel configurations */ + rslt = set_accel_conf(&conf->param.accel, dev); + int_enable = BMA400_DATA_READY_INT_MAP; + int_map = conf->param.accel.int_chan; + } + + if (BMA400_TAP_INT == conf->type) + { + /* Setting tap configurations */ + rslt = set_tap_conf(&conf->param.tap, dev); + int_enable = BMA400_TAP_INT_MAP; + int_map = conf->param.tap.int_chan; + } + + if (BMA400_ACTIVITY_CHANGE_INT == conf->type) + { + /* Setting activity change configurations */ + rslt = set_activity_change_conf(&conf->param.act_ch, dev); + int_enable = BMA400_ACT_CH_INT_MAP; + int_map = conf->param.act_ch.int_chan; + } + + if (BMA400_GEN1_INT == conf->type) + { + /* Setting generic int 1 configurations */ + rslt = set_gen1_int(&conf->param.gen_int, dev); + int_enable = BMA400_GEN1_INT_MAP; + int_map = conf->param.gen_int.int_chan; + } + + if (BMA400_GEN2_INT == conf->type) + { + /* Setting generic int 2 configurations */ + rslt = set_gen2_int(&conf->param.gen_int, dev); + int_enable = BMA400_GEN2_INT_MAP; + int_map = conf->param.gen_int.int_chan; + } + + if (BMA400_ORIENT_CHANGE_INT == conf->type) + { + /* Setting orient int configurations */ + rslt = set_orient_int(&conf->param.orient, dev); + int_enable = BMA400_ORIENT_CH_INT_MAP; + int_map = conf->param.orient.int_chan; + } + + if (BMA400_STEP_COUNTER_INT == conf->type) + { + rslt = BMA400_OK; + int_enable = BMA400_STEP_INT_MAP; + int_map = conf->param.step_cnt.int_chan; + } + + if (rslt == BMA400_OK) + { + /* Int pin mapping settings */ + map_int_pin(data, int_enable, int_map); + } + + return rslt; +} + +static int8_t get_sensor_conf(const uint8_t *data, struct bma400_sensor_conf *conf, struct bma400_dev *dev) +{ + int8_t rslt = BMA400_E_INVALID_CONFIG; + uint8_t int_enable = 0; + enum bma400_int_chan int_map = BMA400_UNMAP_INT_PIN; + + if (BMA400_ACCEL == conf->type) + { + /* Get Accel configurations */ + rslt = get_accel_conf(&conf->param.accel, dev); + int_enable = BMA400_DATA_READY_INT_MAP; + int_map = conf->param.accel.int_chan; + } + + if (BMA400_TAP_INT == conf->type) + { + /* Get tap configurations */ + rslt = get_tap_conf(&conf->param.tap, dev); + int_enable = BMA400_TAP_INT_MAP; + int_map = conf->param.tap.int_chan; + } + + if (BMA400_ACTIVITY_CHANGE_INT == conf->type) + { + /* Get activity change configurations */ + rslt = get_activity_change_conf(&conf->param.act_ch, dev); + int_enable = BMA400_ACT_CH_INT_MAP; + int_map = conf->param.act_ch.int_chan; + } + + if (BMA400_GEN1_INT == conf->type) + { + /* Get generic int 1 configurations */ + rslt = get_gen1_int(&conf->param.gen_int, dev); + int_enable = BMA400_GEN1_INT_MAP; + int_map = conf->param.gen_int.int_chan; + } + + if (BMA400_GEN2_INT == conf->type) + { + /* Get generic int 2 configurations */ + rslt = get_gen2_int(&conf->param.gen_int, dev); + int_enable = BMA400_GEN2_INT_MAP; + int_map = conf->param.gen_int.int_chan; + } + + if (BMA400_ORIENT_CHANGE_INT == conf->type) + { + /* Get orient int configurations */ + rslt = get_orient_int(&conf->param.orient, dev); + int_enable = BMA400_ORIENT_CH_INT_MAP; + int_map = conf->param.orient.int_chan; + } + + if (BMA400_STEP_COUNTER_INT == conf->type) + { + rslt = BMA400_OK; + int_enable = BMA400_STEP_INT_MAP; + int_map = conf->param.step_cnt.int_chan; + } + + if (rslt == BMA400_OK) + { + /* Int pin mapping settings */ + get_int_pin_map(data, int_enable, &int_map); + } + + return rslt; +} + +static int8_t set_accel_conf(const struct bma400_acc_conf *accel_conf, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[3] = { 0, 0, 0xE0 }; @@ -1506,7 +1654,7 @@ static int8_t set_accel_conf(const struct bma400_acc_conf *accel_conf, const str /* Update the accel configurations from the user structure * accel_conf */ - rslt = bma400_get_regs(BMA400_ACCEL_CONFIG_0_ADDR, data_array, 3, dev); + rslt = bma400_get_regs(BMA400_REG_ACCEL_CONFIG_0, data_array, 3, dev); if (rslt == BMA400_OK) { data_array[0] = BMA400_SET_BITS(data_array[0], BMA400_FILT_1_BW, accel_conf->filt1_bw); @@ -1517,18 +1665,18 @@ static int8_t set_accel_conf(const struct bma400_acc_conf *accel_conf, const str data_array[2] = BMA400_SET_BITS(data_array[2], BMA400_DATA_FILTER, accel_conf->data_src); /* Set the accel configurations in the sensor */ - rslt = bma400_set_regs(BMA400_ACCEL_CONFIG_0_ADDR, data_array, 3, dev); + rslt = bma400_set_regs(BMA400_REG_ACCEL_CONFIG_0, data_array, 3, dev); } return rslt; } -static int8_t get_accel_conf(struct bma400_acc_conf *accel_conf, const struct bma400_dev *dev) +static int8_t get_accel_conf(struct bma400_acc_conf *accel_conf, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[3]; - rslt = bma400_get_regs(BMA400_ACCEL_CONFIG_0_ADDR, data_array, 3, dev); + rslt = bma400_get_regs(BMA400_REG_ACCEL_CONFIG_0, data_array, 3, dev); if (rslt == BMA400_OK) { accel_conf->filt1_bw = BMA400_GET_BITS(data_array[0], BMA400_FILT_1_BW); @@ -1542,7 +1690,7 @@ static int8_t get_accel_conf(struct bma400_acc_conf *accel_conf, const struct bm return rslt; } -static int8_t get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, const struct bma400_dev *dev) +static int8_t get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[9] = { 0 }; @@ -1555,18 +1703,19 @@ static int8_t get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, if (data_sel == BMA400_DATA_ONLY) { /* Read the sensor data registers only */ - rslt = bma400_get_regs(BMA400_ACCEL_DATA_ADDR, data_array, 6, dev); + rslt = bma400_get_regs(BMA400_REG_ACCEL_DATA, data_array, 6, dev); } else if (data_sel == BMA400_DATA_SENSOR_TIME) { /* Read the sensor data along with sensor time */ - rslt = bma400_get_regs(BMA400_ACCEL_DATA_ADDR, data_array, 9, dev); + rslt = bma400_get_regs(BMA400_REG_ACCEL_DATA, data_array, 9, dev); } else { /* Invalid use of "data_sel" */ rslt = BMA400_E_INVALID_CONFIG; } + if (rslt == BMA400_OK) { lsb = data_array[0]; @@ -1579,6 +1728,7 @@ static int8_t get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, /* Computing accel data negative value */ accel->x = accel->x - 4096; } + lsb = data_array[2]; msb = data_array[3]; @@ -1589,6 +1739,7 @@ static int8_t get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, /* Computing accel data negative value */ accel->y = accel->y - 4096; } + lsb = data_array[4]; msb = data_array[5]; @@ -1599,11 +1750,13 @@ static int8_t get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, /* Computing accel data negative value */ accel->z = accel->z - 4096; } + if (data_sel == BMA400_DATA_ONLY) { /* Update sensortime as 0 */ accel->sensortime = 0; } + if (data_sel == BMA400_DATA_SENSOR_TIME) { /* Sensor-time data*/ @@ -1617,14 +1770,14 @@ static int8_t get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, return rslt; } -static int8_t set_autowakeup_timeout(const struct bma400_auto_wakeup_conf *wakeup_conf, const struct bma400_dev *dev) +static int8_t set_autowakeup_timeout(const struct bma400_auto_wakeup_conf *wakeup_conf, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[2]; uint8_t lsb; uint8_t msb; - rslt = bma400_get_regs(BMA400_AUTOWAKEUP_1_ADDR, &data_array[1], 1, dev); + rslt = bma400_get_regs(BMA400_REG_AUTOWAKEUP_1, &data_array[1], 1, dev); if (rslt == BMA400_OK) { data_array[1] = BMA400_SET_BITS(data_array[1], BMA400_WAKEUP_TIMEOUT, wakeup_conf->wakeup_timeout); @@ -1638,20 +1791,20 @@ static int8_t set_autowakeup_timeout(const struct bma400_auto_wakeup_conf *wakeu /* Set the value in the data_array */ data_array[0] = msb; data_array[1] = BMA400_SET_BITS(data_array[1], BMA400_WAKEUP_TIMEOUT_THRES, lsb); - rslt = bma400_set_regs(BMA400_AUTOWAKEUP_0_ADDR, data_array, 2, dev); + rslt = bma400_set_regs(BMA400_REG_AUTOWAKEUP_0, data_array, 2, dev); } return rslt; } -static int8_t get_autowakeup_timeout(struct bma400_auto_wakeup_conf *wakeup_conf, const struct bma400_dev *dev) +static int8_t get_autowakeup_timeout(struct bma400_auto_wakeup_conf *wakeup_conf, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[2]; uint8_t lsb; uint8_t msb; - rslt = bma400_get_regs(BMA400_AUTOWAKEUP_0_ADDR, data_array, 2, dev); + rslt = bma400_get_regs(BMA400_REG_AUTOWAKEUP_0, data_array, 2, dev); if (rslt == BMA400_OK) { wakeup_conf->wakeup_timeout = BMA400_GET_BITS(data_array[1], BMA400_WAKEUP_TIMEOUT); @@ -1665,24 +1818,24 @@ static int8_t get_autowakeup_timeout(struct bma400_auto_wakeup_conf *wakeup_conf return rslt; } -static int8_t set_auto_wakeup(uint8_t conf, const struct bma400_dev *dev) +static int8_t set_auto_wakeup(uint8_t conf, struct bma400_dev *dev) { int8_t rslt; uint8_t reg_data; - rslt = bma400_get_regs(BMA400_AUTOWAKEUP_1_ADDR, ®_data, 1, dev); + rslt = bma400_get_regs(BMA400_REG_AUTOWAKEUP_1, ®_data, 1, dev); if (rslt == BMA400_OK) { reg_data = BMA400_SET_BITS(reg_data, BMA400_WAKEUP_INTERRUPT, conf); /* Enabling the Auto wakeup interrupt */ - rslt = bma400_set_regs(BMA400_AUTOWAKEUP_1_ADDR, ®_data, 1, dev); + rslt = bma400_set_regs(BMA400_REG_AUTOWAKEUP_1, ®_data, 1, dev); } return rslt; } -static int8_t set_autowakeup_interrupt(const struct bma400_wakeup_conf *wakeup_conf, const struct bma400_dev *dev) +static int8_t set_autowakeup_interrupt(const struct bma400_wakeup_conf *wakeup_conf, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[5] = { 0 }; @@ -1709,17 +1862,17 @@ static int8_t set_autowakeup_interrupt(const struct bma400_wakeup_conf *wakeup_c data_array[4] = wakeup_conf->int_wkup_ref_z; /* Set the wakeup interrupt configurations in the sensor */ - rslt = bma400_set_regs(BMA400_WAKEUP_INT_CONF_0_ADDR, data_array, 5, dev); + rslt = bma400_set_regs(BMA400_REG_WAKEUP_INT_CONF_0, data_array, 5, dev); return rslt; } -static int8_t get_autowakeup_interrupt(struct bma400_wakeup_conf *wakeup_conf, const struct bma400_dev *dev) +static int8_t get_autowakeup_interrupt(struct bma400_wakeup_conf *wakeup_conf, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[5]; - rslt = bma400_get_regs(BMA400_WAKEUP_INT_CONF_0_ADDR, data_array, 5, dev); + rslt = bma400_get_regs(BMA400_REG_WAKEUP_INT_CONF_0, data_array, 5, dev); if (rslt == BMA400_OK) { /* get the wakeup reference update */ @@ -1747,14 +1900,14 @@ static int8_t get_autowakeup_interrupt(struct bma400_wakeup_conf *wakeup_conf, c return rslt; } -static int8_t set_auto_low_power(const struct bma400_auto_lp_conf *auto_lp_conf, const struct bma400_dev *dev) +static int8_t set_auto_low_power(const struct bma400_auto_lp_conf *auto_lp_conf, struct bma400_dev *dev) { int8_t rslt; uint8_t reg_data; uint8_t timeout_msb; uint8_t timeout_lsb; - rslt = bma400_get_regs(BMA400_AUTO_LOW_POW_1_ADDR, ®_data, 1, dev); + rslt = bma400_get_regs(BMA400_REG_AUTO_LOW_POW_1, ®_data, 1, dev); if (rslt == BMA400_OK) { reg_data = BMA400_SET_BITS_POS_0(reg_data, BMA400_AUTO_LOW_POW, auto_lp_conf->auto_low_power_trigger); @@ -1762,7 +1915,7 @@ static int8_t set_auto_low_power(const struct bma400_auto_lp_conf *auto_lp_conf, /* If auto Low power timeout threshold is enabled */ if (auto_lp_conf->auto_low_power_trigger & 0x0C) { - rslt = bma400_get_regs(BMA400_AUTO_LOW_POW_0_ADDR, &timeout_msb, 1, dev); + rslt = bma400_get_regs(BMA400_REG_AUTO_LOW_POW_0, &timeout_msb, 1, dev); if (rslt == BMA400_OK) { /* Compute the timeout threshold MSB value */ @@ -1773,27 +1926,28 @@ static int8_t set_auto_low_power(const struct bma400_auto_lp_conf *auto_lp_conf, reg_data = BMA400_SET_BITS(reg_data, BMA400_AUTO_LP_TIMEOUT_LSB, timeout_lsb); /* Set the timeout threshold MSB value */ - rslt = bma400_set_regs(BMA400_AUTO_LOW_POW_0_ADDR, &timeout_msb, 1, dev); + rslt = bma400_set_regs(BMA400_REG_AUTO_LOW_POW_0, &timeout_msb, 1, dev); } } + if (rslt == BMA400_OK) { /* Set the Auto low power configurations */ - rslt = bma400_set_regs(BMA400_AUTO_LOW_POW_1_ADDR, ®_data, 1, dev); + rslt = bma400_set_regs(BMA400_REG_AUTO_LOW_POW_1, ®_data, 1, dev); } } return rslt; } -static int8_t get_auto_low_power(struct bma400_auto_lp_conf *auto_lp_conf, const struct bma400_dev *dev) +static int8_t get_auto_low_power(struct bma400_auto_lp_conf *auto_lp_conf, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[2]; uint8_t timeout_msb; uint8_t timeout_lsb; - rslt = bma400_get_regs(BMA400_AUTO_LOW_POW_0_ADDR, data_array, 2, dev); + rslt = bma400_get_regs(BMA400_REG_AUTO_LOW_POW_0, data_array, 2, dev); if (rslt == BMA400_OK) { /* Get the auto low power trigger */ @@ -1808,12 +1962,12 @@ static int8_t get_auto_low_power(struct bma400_auto_lp_conf *auto_lp_conf, const return rslt; } -static int8_t set_tap_conf(const struct bma400_tap_conf *tap_set, const struct bma400_dev *dev) +static int8_t set_tap_conf(const struct bma400_tap_conf *tap_set, struct bma400_dev *dev) { int8_t rslt; uint8_t reg_data[2] = { 0, 0 }; - rslt = bma400_get_regs(BMA400_TAP_CONFIG_ADDR, reg_data, 2, dev); + rslt = bma400_get_regs(BMA400_REG_TAP_CONFIG, reg_data, 2, dev); if (rslt == BMA400_OK) { /* Set the axis to sense for tap */ @@ -1832,18 +1986,18 @@ static int8_t set_tap_conf(const struct bma400_tap_conf *tap_set, const struct b reg_data[1] = BMA400_SET_BITS_POS_0(reg_data[1], BMA400_TAP_TICS_TH, tap_set->tics_th); /* Set the TAP configuration in the sensor*/ - rslt = bma400_set_regs(BMA400_TAP_CONFIG_ADDR, reg_data, 2, dev); + rslt = bma400_set_regs(BMA400_REG_TAP_CONFIG, reg_data, 2, dev); } return rslt; } -static int8_t get_tap_conf(struct bma400_tap_conf *tap_set, const struct bma400_dev *dev) +static int8_t get_tap_conf(struct bma400_tap_conf *tap_set, struct bma400_dev *dev) { int8_t rslt; uint8_t reg_data[2]; - rslt = bma400_get_regs(BMA400_TAP_CONFIG_ADDR, reg_data, 2, dev); + rslt = bma400_get_regs(BMA400_REG_TAP_CONFIG, reg_data, 2, dev); if (rslt == BMA400_OK) { /* Get the axis enabled for tap sensing */ @@ -1865,7 +2019,7 @@ static int8_t get_tap_conf(struct bma400_tap_conf *tap_set, const struct bma400_ return rslt; } -static int8_t set_activity_change_conf(const struct bma400_act_ch_conf *act_ch_set, const struct bma400_dev *dev) +static int8_t set_activity_change_conf(const struct bma400_act_ch_conf *act_ch_set, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[2] = { 0 }; @@ -1885,17 +2039,17 @@ static int8_t set_activity_change_conf(const struct bma400_act_ch_conf *act_ch_s data_array[1] = BMA400_SET_BITS_POS_0(data_array[1], BMA400_ACT_CH_NPTS, act_ch_set->act_ch_ntps); /* Set the Activity change configuration in the sensor*/ - rslt = bma400_set_regs(BMA400_ACT_CH_CONFIG_0_ADDR, data_array, 2, dev); + rslt = bma400_set_regs(BMA400_REG_ACT_CH_CONFIG_0, data_array, 2, dev); return rslt; } -static int8_t get_activity_change_conf(struct bma400_act_ch_conf *act_ch_set, const struct bma400_dev *dev) +static int8_t get_activity_change_conf(struct bma400_act_ch_conf *act_ch_set, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[2]; - rslt = bma400_get_regs(BMA400_ACT_CH_CONFIG_0_ADDR, data_array, 2, dev); + rslt = bma400_get_regs(BMA400_REG_ACT_CH_CONFIG_0, data_array, 2, dev); if (rslt == BMA400_OK) { /* Get the activity change threshold */ @@ -1916,7 +2070,7 @@ static int8_t get_activity_change_conf(struct bma400_act_ch_conf *act_ch_set, co return rslt; } -static int8_t set_gen1_int(const struct bma400_gen_int_conf *gen_int_set, const struct bma400_dev *dev) +static int8_t set_gen1_int(const struct bma400_gen_int_conf *gen_int_set, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[11] = { 0 }; @@ -1953,7 +2107,7 @@ static int8_t set_gen1_int(const struct bma400_gen_int_conf *gen_int_set, const data_array[4] = BMA400_GET_LSB(gen_int_set->gen_int_dur); /* Handling case of manual reference update */ - if (gen_int_set->ref_update == BMA400_MANUAL_UPDATE) + if (gen_int_set->ref_update == BMA400_UPDATE_MANUAL) { /* Set the LSB of reference x threshold */ data_array[5] = BMA400_GET_LSB(gen_int_set->int_thres_ref_x); @@ -1974,23 +2128,23 @@ static int8_t set_gen1_int(const struct bma400_gen_int_conf *gen_int_set, const data_array[10] = BMA400_GET_MSB(gen_int_set->int_thres_ref_z); /* Set the GEN1 INT configuration in the sensor */ - rslt = bma400_set_regs(BMA400_GEN1_INT_CONFIG_ADDR, data_array, 11, dev); + rslt = bma400_set_regs(BMA400_REG_GEN1_INT_CONFIG, data_array, 11, dev); } else { /* Set the GEN1 INT configuration in the sensor */ - rslt = bma400_set_regs(BMA400_GEN1_INT_CONFIG_ADDR, data_array, 5, dev); + rslt = bma400_set_regs(BMA400_REG_GEN1_INT_CONFIG, data_array, 5, dev); } return rslt; } -static int8_t get_gen1_int(struct bma400_gen_int_conf *gen_int_set, const struct bma400_dev *dev) +static int8_t get_gen1_int(struct bma400_gen_int_conf *gen_int_set, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[11]; - rslt = bma400_get_regs(BMA400_GEN1_INT_CONFIG_ADDR, data_array, 11, dev); + rslt = bma400_get_regs(BMA400_REG_GEN1_INT_CONFIG, data_array, 11, dev); if (rslt == BMA400_OK) { /* Get the axes to sense for interrupt */ @@ -2029,7 +2183,7 @@ static int8_t get_gen1_int(struct bma400_gen_int_conf *gen_int_set, const struct return rslt; } -static int8_t set_gen2_int(const struct bma400_gen_int_conf *gen_int_set, const struct bma400_dev *dev) +static int8_t set_gen2_int(const struct bma400_gen_int_conf *gen_int_set, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[11] = { 0 }; @@ -2066,7 +2220,7 @@ static int8_t set_gen2_int(const struct bma400_gen_int_conf *gen_int_set, const data_array[4] = BMA400_GET_LSB(gen_int_set->gen_int_dur); /* Handling case of manual reference update */ - if (gen_int_set->ref_update == BMA400_MANUAL_UPDATE) + if (gen_int_set->ref_update == BMA400_UPDATE_MANUAL) { /* Set the LSB of reference x threshold */ data_array[5] = BMA400_GET_LSB(gen_int_set->int_thres_ref_x); @@ -2087,23 +2241,23 @@ static int8_t set_gen2_int(const struct bma400_gen_int_conf *gen_int_set, const data_array[10] = BMA400_GET_MSB(gen_int_set->int_thres_ref_z); /* Set the GEN2 INT configuration in the sensor */ - rslt = bma400_set_regs(BMA400_GEN2_INT_CONFIG_ADDR, data_array, 11, dev); + rslt = bma400_set_regs(BMA400_REG_GEN2_INT_CONFIG, data_array, 11, dev); } else { /* Set the GEN2 INT configuration in the sensor */ - rslt = bma400_set_regs(BMA400_GEN2_INT_CONFIG_ADDR, data_array, 5, dev); + rslt = bma400_set_regs(BMA400_REG_GEN2_INT_CONFIG, data_array, 5, dev); } return rslt; } -static int8_t get_gen2_int(struct bma400_gen_int_conf *gen_int_set, const struct bma400_dev *dev) +static int8_t get_gen2_int(struct bma400_gen_int_conf *gen_int_set, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[11]; - rslt = bma400_get_regs(BMA400_GEN2_INT_CONFIG_ADDR, data_array, 11, dev); + rslt = bma400_get_regs(BMA400_REG_GEN2_INT_CONFIG, data_array, 11, dev); if (rslt == BMA400_OK) { /* Get the axes to sense for interrupt */ @@ -2142,7 +2296,7 @@ static int8_t get_gen2_int(struct bma400_gen_int_conf *gen_int_set, const struct return rslt; } -static int8_t set_orient_int(const struct bma400_orient_int_conf *orient_conf, const struct bma400_dev *dev) +static int8_t set_orient_int(const struct bma400_orient_int_conf *orient_conf, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[10] = { 0 }; @@ -2156,9 +2310,6 @@ static int8_t set_orient_int(const struct bma400_orient_int_conf *orient_conf, c /* Set the reference update mode */ data_array[0] = BMA400_SET_BITS(data_array[0], BMA400_INT_REFU, orient_conf->ref_update); - /* Set the stability_mode for interrupt calculation */ - data_array[0] = BMA400_SET_BITS_POS_0(data_array[0], BMA400_STABILITY_MODE, orient_conf->stability_mode); - /* Set the threshold for interrupt calculation */ data_array[1] = orient_conf->orient_thres; @@ -2169,7 +2320,7 @@ static int8_t set_orient_int(const struct bma400_orient_int_conf *orient_conf, c data_array[3] = orient_conf->orient_int_dur; /* Handling case of manual reference update */ - if (orient_conf->ref_update == BMA400_MANUAL_UPDATE) + if (orient_conf->ref_update == BMA400_UPDATE_MANUAL) { /* Set the LSB of reference x threshold */ data_array[4] = BMA400_GET_LSB(orient_conf->orient_ref_x); @@ -2190,25 +2341,25 @@ static int8_t set_orient_int(const struct bma400_orient_int_conf *orient_conf, c data_array[9] = BMA400_GET_MSB(orient_conf->orient_ref_z); /* Set the orient configurations in the sensor */ - rslt = bma400_set_regs(BMA400_ORIENTCH_INT_CONFIG_ADDR, data_array, 10, dev); + rslt = bma400_set_regs(BMA400_REG_ORIENTCH_INT_CONFIG, data_array, 10, dev); } else { /* Set the orient configurations in the sensor excluding * reference values of x,y,z */ - rslt = bma400_set_regs(BMA400_ORIENTCH_INT_CONFIG_ADDR, data_array, 4, dev); + rslt = bma400_set_regs(BMA400_REG_ORIENTCH_INT_CONFIG, data_array, 4, dev); } return rslt; } -static int8_t get_orient_int(struct bma400_orient_int_conf *orient_conf, const struct bma400_dev *dev) +static int8_t get_orient_int(struct bma400_orient_int_conf *orient_conf, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[10]; - rslt = bma400_get_regs(BMA400_ORIENTCH_INT_CONFIG_ADDR, data_array, 10, dev); + rslt = bma400_get_regs(BMA400_REG_ORIENTCH_INT_CONFIG, data_array, 10, dev); if (rslt == BMA400_OK) { /* Get the axes to sense for interrupt */ @@ -2220,9 +2371,6 @@ static int8_t get_orient_int(struct bma400_orient_int_conf *orient_conf, const s /* Get the reference update mode */ orient_conf->ref_update = BMA400_GET_BITS(data_array[0], BMA400_INT_REFU); - /* Get the stability_mode for interrupt calculation */ - orient_conf->stability_mode = BMA400_GET_BITS_POS_0(data_array[0], BMA400_STABILITY_MODE); - /* Get the threshold for interrupt calculation */ orient_conf->orient_thres = data_array[1]; @@ -2254,21 +2402,25 @@ static void map_int_pin(uint8_t *data_array, uint8_t int_enable, enum bma400_int /* Mapping interrupt to INT pin 1*/ data_array[0] = BMA400_SET_BITS(data_array[0], BMA400_EN_DRDY, BMA400_ENABLE); } + if (int_map == BMA400_INT_CHANNEL_2) { /* Mapping interrupt to INT pin 2*/ data_array[1] = BMA400_SET_BITS(data_array[1], BMA400_EN_DRDY, BMA400_ENABLE); } + if (int_map == BMA400_UNMAP_INT_PIN) { data_array[0] = BMA400_SET_BIT_VAL_0(data_array[0], BMA400_EN_DRDY); data_array[1] = BMA400_SET_BIT_VAL_0(data_array[1], BMA400_EN_DRDY); } + if (int_map == BMA400_MAP_BOTH_INT_PINS) { data_array[0] = BMA400_SET_BITS(data_array[0], BMA400_EN_DRDY, BMA400_ENABLE); data_array[1] = BMA400_SET_BITS(data_array[1], BMA400_EN_DRDY, BMA400_ENABLE); } + break; case BMA400_FIFO_WM_INT_MAP: if (int_map == BMA400_INT_CHANNEL_1) @@ -2276,21 +2428,25 @@ static void map_int_pin(uint8_t *data_array, uint8_t int_enable, enum bma400_int /* Mapping interrupt to INT pin 1*/ data_array[0] = BMA400_SET_BITS(data_array[0], BMA400_EN_FIFO_WM, BMA400_ENABLE); } + if (int_map == BMA400_INT_CHANNEL_2) { /* Mapping interrupt to INT pin 2*/ data_array[1] = BMA400_SET_BITS(data_array[1], BMA400_EN_FIFO_WM, BMA400_ENABLE); } + if (int_map == BMA400_UNMAP_INT_PIN) { data_array[0] = BMA400_SET_BIT_VAL_0(data_array[0], BMA400_EN_FIFO_WM); data_array[1] = BMA400_SET_BIT_VAL_0(data_array[1], BMA400_EN_FIFO_WM); } + if (int_map == BMA400_MAP_BOTH_INT_PINS) { data_array[0] = BMA400_SET_BITS(data_array[0], BMA400_EN_FIFO_WM, BMA400_ENABLE); data_array[1] = BMA400_SET_BITS(data_array[1], BMA400_EN_FIFO_WM, BMA400_ENABLE); } + break; case BMA400_FIFO_FULL_INT_MAP: if (int_map == BMA400_INT_CHANNEL_1) @@ -2298,21 +2454,25 @@ static void map_int_pin(uint8_t *data_array, uint8_t int_enable, enum bma400_int /* Mapping interrupt to INT pin 1 */ data_array[0] = BMA400_SET_BITS(data_array[0], BMA400_EN_FIFO_FULL, BMA400_ENABLE); } + if (int_map == BMA400_INT_CHANNEL_2) { /* Mapping interrupt to INT pin 2 */ data_array[1] = BMA400_SET_BITS(data_array[1], BMA400_EN_FIFO_FULL, BMA400_ENABLE); } + if (int_map == BMA400_UNMAP_INT_PIN) { data_array[0] = BMA400_SET_BIT_VAL_0(data_array[0], BMA400_EN_FIFO_FULL); data_array[1] = BMA400_SET_BIT_VAL_0(data_array[1], BMA400_EN_FIFO_FULL); } + if (int_map == BMA400_MAP_BOTH_INT_PINS) { data_array[0] = BMA400_SET_BITS(data_array[0], BMA400_EN_FIFO_FULL, BMA400_ENABLE); data_array[1] = BMA400_SET_BITS(data_array[1], BMA400_EN_FIFO_FULL, BMA400_ENABLE); } + break; case BMA400_INT_OVERRUN_MAP: if (int_map == BMA400_INT_CHANNEL_1) @@ -2320,21 +2480,25 @@ static void map_int_pin(uint8_t *data_array, uint8_t int_enable, enum bma400_int /* Mapping interrupt to INT pin 1 */ data_array[0] = BMA400_SET_BITS(data_array[0], BMA400_EN_INT_OVERRUN, BMA400_ENABLE); } + if (int_map == BMA400_INT_CHANNEL_2) { /* Mapping interrupt to INT pin 2 */ data_array[1] = BMA400_SET_BITS(data_array[1], BMA400_EN_INT_OVERRUN, BMA400_ENABLE); } + if (int_map == BMA400_UNMAP_INT_PIN) { data_array[0] = BMA400_SET_BIT_VAL_0(data_array[0], BMA400_EN_INT_OVERRUN); data_array[1] = BMA400_SET_BIT_VAL_0(data_array[1], BMA400_EN_INT_OVERRUN); } + if (int_map == BMA400_MAP_BOTH_INT_PINS) { data_array[0] = BMA400_SET_BITS(data_array[0], BMA400_EN_INT_OVERRUN, BMA400_ENABLE); data_array[1] = BMA400_SET_BITS(data_array[1], BMA400_EN_INT_OVERRUN, BMA400_ENABLE); } + break; case BMA400_GEN2_INT_MAP: if (int_map == BMA400_INT_CHANNEL_1) @@ -2342,21 +2506,25 @@ static void map_int_pin(uint8_t *data_array, uint8_t int_enable, enum bma400_int /* Mapping interrupt to INT pin 1 */ data_array[0] = BMA400_SET_BITS(data_array[0], BMA400_EN_GEN2, BMA400_ENABLE); } + if (int_map == BMA400_INT_CHANNEL_2) { /* Mapping interrupt to INT pin 2 */ data_array[1] = BMA400_SET_BITS(data_array[1], BMA400_EN_GEN2, BMA400_ENABLE); } + if (int_map == BMA400_UNMAP_INT_PIN) { data_array[0] = BMA400_SET_BIT_VAL_0(data_array[0], BMA400_EN_GEN2); data_array[1] = BMA400_SET_BIT_VAL_0(data_array[1], BMA400_EN_GEN2); } + if (int_map == BMA400_MAP_BOTH_INT_PINS) { data_array[0] = BMA400_SET_BITS(data_array[0], BMA400_EN_GEN2, BMA400_ENABLE); data_array[1] = BMA400_SET_BITS(data_array[1], BMA400_EN_GEN2, BMA400_ENABLE); } + break; case BMA400_GEN1_INT_MAP: if (int_map == BMA400_INT_CHANNEL_1) @@ -2364,21 +2532,25 @@ static void map_int_pin(uint8_t *data_array, uint8_t int_enable, enum bma400_int /* Mapping interrupt to INT pin 1 */ data_array[0] = BMA400_SET_BITS(data_array[0], BMA400_EN_GEN1, BMA400_ENABLE); } + if (int_map == BMA400_INT_CHANNEL_2) { /* Mapping interrupt to INT pin 2 */ data_array[1] = BMA400_SET_BITS(data_array[1], BMA400_EN_GEN1, BMA400_ENABLE); } + if (int_map == BMA400_UNMAP_INT_PIN) { data_array[0] = BMA400_SET_BIT_VAL_0(data_array[0], BMA400_EN_GEN1); data_array[1] = BMA400_SET_BIT_VAL_0(data_array[1], BMA400_EN_GEN1); } + if (int_map == BMA400_MAP_BOTH_INT_PINS) { data_array[0] = BMA400_SET_BITS(data_array[0], BMA400_EN_GEN1, BMA400_ENABLE); data_array[1] = BMA400_SET_BITS(data_array[1], BMA400_EN_GEN1, BMA400_ENABLE); } + break; case BMA400_ORIENT_CH_INT_MAP: if (int_map == BMA400_INT_CHANNEL_1) @@ -2386,21 +2558,25 @@ static void map_int_pin(uint8_t *data_array, uint8_t int_enable, enum bma400_int /* Mapping interrupt to INT pin 1 */ data_array[0] = BMA400_SET_BITS(data_array[0], BMA400_EN_ORIENT_CH, BMA400_ENABLE); } + if (int_map == BMA400_INT_CHANNEL_2) { /* Mapping interrupt to INT pin 2 */ data_array[1] = BMA400_SET_BITS(data_array[1], BMA400_EN_ORIENT_CH, BMA400_ENABLE); } + if (int_map == BMA400_UNMAP_INT_PIN) { data_array[0] = BMA400_SET_BIT_VAL_0(data_array[0], BMA400_EN_ORIENT_CH); data_array[1] = BMA400_SET_BIT_VAL_0(data_array[1], BMA400_EN_ORIENT_CH); } + if (int_map == BMA400_MAP_BOTH_INT_PINS) { data_array[0] = BMA400_SET_BITS(data_array[0], BMA400_EN_ORIENT_CH, BMA400_ENABLE); data_array[1] = BMA400_SET_BITS(data_array[1], BMA400_EN_ORIENT_CH, BMA400_ENABLE); } + break; case BMA400_WAKEUP_INT_MAP: if (int_map == BMA400_INT_CHANNEL_1) @@ -2408,21 +2584,25 @@ static void map_int_pin(uint8_t *data_array, uint8_t int_enable, enum bma400_int /* Mapping interrupt to INT pin 1 */ data_array[0] = BMA400_SET_BITS_POS_0(data_array[0], BMA400_EN_WAKEUP_INT, BMA400_ENABLE); } + if (int_map == BMA400_INT_CHANNEL_2) { /* Mapping interrupt to INT pin 2 */ data_array[1] = BMA400_SET_BITS_POS_0(data_array[1], BMA400_EN_WAKEUP_INT, BMA400_ENABLE); } + if (int_map == BMA400_UNMAP_INT_PIN) { data_array[0] = BMA400_SET_BIT_VAL_0(data_array[0], BMA400_EN_WAKEUP_INT); data_array[1] = BMA400_SET_BIT_VAL_0(data_array[1], BMA400_EN_WAKEUP_INT); } + if (int_map == BMA400_MAP_BOTH_INT_PINS) { data_array[0] = BMA400_SET_BITS_POS_0(data_array[0], BMA400_EN_WAKEUP_INT, BMA400_ENABLE); data_array[1] = BMA400_SET_BITS_POS_0(data_array[1], BMA400_EN_WAKEUP_INT, BMA400_ENABLE); } + break; case BMA400_ACT_CH_INT_MAP: if (int_map == BMA400_INT_CHANNEL_1) @@ -2430,21 +2610,25 @@ static void map_int_pin(uint8_t *data_array, uint8_t int_enable, enum bma400_int /* Mapping interrupt to INT pin 1 */ data_array[2] = BMA400_SET_BITS(data_array[2], BMA400_ACTCH_MAP_INT1, BMA400_ENABLE); } + if (int_map == BMA400_INT_CHANNEL_2) { /* Mapping interrupt to INT pin 2 */ data_array[2] = BMA400_SET_BITS(data_array[2], BMA400_ACTCH_MAP_INT2, BMA400_ENABLE); } + if (int_map == BMA400_UNMAP_INT_PIN) { data_array[2] = BMA400_SET_BIT_VAL_0(data_array[2], BMA400_ACTCH_MAP_INT1); data_array[2] = BMA400_SET_BIT_VAL_0(data_array[2], BMA400_ACTCH_MAP_INT2); } + if (int_map == BMA400_MAP_BOTH_INT_PINS) { data_array[2] = BMA400_SET_BITS(data_array[2], BMA400_ACTCH_MAP_INT1, BMA400_ENABLE); data_array[2] = BMA400_SET_BITS(data_array[2], BMA400_ACTCH_MAP_INT2, BMA400_ENABLE); } + break; case BMA400_TAP_INT_MAP: if (int_map == BMA400_INT_CHANNEL_1) @@ -2452,21 +2636,25 @@ static void map_int_pin(uint8_t *data_array, uint8_t int_enable, enum bma400_int /* Mapping interrupt to INT pin 1 */ data_array[2] = BMA400_SET_BITS(data_array[2], BMA400_TAP_MAP_INT1, BMA400_ENABLE); } + if (int_map == BMA400_INT_CHANNEL_2) { /* Mapping interrupt to INT pin 2 */ data_array[2] = BMA400_SET_BITS(data_array[2], BMA400_TAP_MAP_INT2, BMA400_ENABLE); } + if (int_map == BMA400_UNMAP_INT_PIN) { data_array[2] = BMA400_SET_BIT_VAL_0(data_array[2], BMA400_TAP_MAP_INT1); data_array[2] = BMA400_SET_BIT_VAL_0(data_array[2], BMA400_TAP_MAP_INT2); } + if (int_map == BMA400_MAP_BOTH_INT_PINS) { data_array[2] = BMA400_SET_BITS(data_array[2], BMA400_TAP_MAP_INT1, BMA400_ENABLE); data_array[2] = BMA400_SET_BITS(data_array[2], BMA400_TAP_MAP_INT2, BMA400_ENABLE); } + break; case BMA400_STEP_INT_MAP: if (int_map == BMA400_INT_CHANNEL_1) @@ -2474,21 +2662,25 @@ static void map_int_pin(uint8_t *data_array, uint8_t int_enable, enum bma400_int /* Mapping interrupt to INT pin 1 */ data_array[2] = BMA400_SET_BITS_POS_0(data_array[2], BMA400_EN_STEP_INT, BMA400_ENABLE); } + if (int_map == BMA400_INT_CHANNEL_2) { /* Mapping interrupt to INT pin 2 */ data_array[2] = BMA400_SET_BITS(data_array[2], BMA400_STEP_MAP_INT2, BMA400_ENABLE); } + if (int_map == BMA400_UNMAP_INT_PIN) { data_array[2] = BMA400_SET_BIT_VAL_0(data_array[2], BMA400_EN_STEP_INT); data_array[2] = BMA400_SET_BIT_VAL_0(data_array[2], BMA400_STEP_MAP_INT2); } + if (int_map == BMA400_MAP_BOTH_INT_PINS) { data_array[2] = BMA400_SET_BITS_POS_0(data_array[2], BMA400_EN_STEP_INT, BMA400_ENABLE); data_array[2] = BMA400_SET_BITS(data_array[2], BMA400_STEP_MAP_INT2, BMA400_ENABLE); } + break; default: break; @@ -2502,16 +2694,19 @@ static void check_mapped_interrupts(uint8_t int_1_map, uint8_t int_2_map, enum b /* INT 1 mapped INT 2 not mapped */ *int_map = BMA400_INT_CHANNEL_1; } + if ((int_1_map == BMA400_DISABLE) && (int_2_map == BMA400_ENABLE)) { /* INT 1 not mapped INT 2 mapped */ *int_map = BMA400_INT_CHANNEL_2; } + if ((int_1_map == BMA400_ENABLE) && (int_2_map == BMA400_ENABLE)) { /* INT 1 ,INT 2 both mapped */ *int_map = BMA400_MAP_BOTH_INT_PINS; } + if ((int_1_map == BMA400_DISABLE) && (int_2_map == BMA400_DISABLE)) { /* INT 1 ,INT 2 not mapped */ @@ -2652,12 +2847,12 @@ static void get_int_pin_map(const uint8_t *data_array, uint8_t int_enable, enum } } -static int8_t set_int_pin_conf(struct bma400_int_pin_conf int_conf, const struct bma400_dev *dev) +static int8_t set_int_pin_conf(struct bma400_int_pin_conf int_conf, struct bma400_dev *dev) { int8_t rslt; uint8_t reg_data; - rslt = bma400_get_regs(BMA400_INT_12_IO_CTRL_ADDR, ®_data, 1, dev); + rslt = bma400_get_regs(BMA400_REG_INT_12_IO_CTRL, ®_data, 1, dev); if (rslt == BMA400_OK) { if (int_conf.int_chan == BMA400_INT_CHANNEL_1) @@ -2665,6 +2860,7 @@ static int8_t set_int_pin_conf(struct bma400_int_pin_conf int_conf, const struct /* Setting interrupt pin configurations */ reg_data = BMA400_SET_BITS(reg_data, BMA400_INT_PIN1_CONF, int_conf.pin_conf); } + if (int_conf.int_chan == BMA400_INT_CHANNEL_2) { /* Setting interrupt pin configurations */ @@ -2672,18 +2868,18 @@ static int8_t set_int_pin_conf(struct bma400_int_pin_conf int_conf, const struct } /* Set the configurations in the sensor */ - rslt = bma400_set_regs(BMA400_INT_12_IO_CTRL_ADDR, ®_data, 1, dev); + rslt = bma400_set_regs(BMA400_REG_INT_12_IO_CTRL, ®_data, 1, dev); } return rslt; } -static int8_t get_int_pin_conf(struct bma400_int_pin_conf *int_conf, const struct bma400_dev *dev) +static int8_t get_int_pin_conf(struct bma400_int_pin_conf *int_conf, struct bma400_dev *dev) { int8_t rslt; uint8_t reg_data; - rslt = bma400_get_regs(BMA400_INT_12_IO_CTRL_ADDR, ®_data, 1, dev); + rslt = bma400_get_regs(BMA400_REG_INT_12_IO_CTRL, ®_data, 1, dev); if (rslt == BMA400_OK) { if (int_conf->int_chan == BMA400_INT_CHANNEL_1) @@ -2691,6 +2887,7 @@ static int8_t get_int_pin_conf(struct bma400_int_pin_conf *int_conf, const struc /* reading Interrupt pin configurations */ int_conf->pin_conf = BMA400_GET_BITS(reg_data, BMA400_INT_PIN1_CONF); } + if (int_conf->int_chan == BMA400_INT_CHANNEL_2) { /* Setting interrupt pin configurations */ @@ -2701,7 +2898,7 @@ static int8_t get_int_pin_conf(struct bma400_int_pin_conf *int_conf, const struc return rslt; } -static int8_t get_fifo_conf(struct bma400_fifo_conf *fifo_conf, const struct bma400_dev *dev) +static int8_t get_fifo_conf(struct bma400_fifo_conf *fifo_conf, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[3]; @@ -2715,7 +2912,7 @@ static int8_t get_fifo_conf(struct bma400_fifo_conf *fifo_conf, const struct bma /* Get the FIFO configurations and water-mark * values from the sensor */ - rslt = bma400_get_regs(BMA400_FIFO_CONFIG_0_ADDR, data_array, 3, dev); + rslt = bma400_get_regs(BMA400_REG_FIFO_CONFIG_0, data_array, 3, dev); if (rslt == BMA400_OK) { /* Get the data of FIFO_CONFIG0 register */ @@ -2732,7 +2929,7 @@ static int8_t get_fifo_conf(struct bma400_fifo_conf *fifo_conf, const struct bma return rslt; } -static int8_t set_fifo_conf(const struct bma400_fifo_conf *fifo_conf, const struct bma400_dev *dev) +static int8_t set_fifo_conf(const struct bma400_fifo_conf *fifo_conf, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[3]; @@ -2747,7 +2944,7 @@ static int8_t set_fifo_conf(const struct bma400_fifo_conf *fifo_conf, const stru /* Get the FIFO configurations and water-mark * values from the sensor */ - rslt = bma400_get_regs(BMA400_FIFO_CONFIG_0_ADDR, sens_data, 3, dev); + rslt = bma400_get_regs(BMA400_REG_FIFO_CONFIG_0, sens_data, 3, dev); if (rslt == BMA400_OK) { /* FIFO configurations */ @@ -2767,12 +2964,12 @@ static int8_t set_fifo_conf(const struct bma400_fifo_conf *fifo_conf, const stru /* Set the FIFO configurations in the * sensor excluding the watermark value */ - rslt = bma400_set_regs(BMA400_FIFO_CONFIG_0_ADDR, data_array, 1, dev); + rslt = bma400_set_regs(BMA400_REG_FIFO_CONFIG_0, data_array, 1, dev); } else { /* Set the FIFO configurations in the sensor*/ - rslt = bma400_set_regs(BMA400_FIFO_CONFIG_0_ADDR, data_array, 3, dev); + rslt = bma400_set_regs(BMA400_REG_FIFO_CONFIG_0, data_array, 3, dev); } } } @@ -2780,12 +2977,12 @@ static int8_t set_fifo_conf(const struct bma400_fifo_conf *fifo_conf, const stru return rslt; } -static int8_t get_fifo_length(uint16_t *fifo_byte_cnt, const struct bma400_dev *dev) +static int8_t get_fifo_length(uint16_t *fifo_byte_cnt, struct bma400_dev *dev) { int8_t rslt; uint8_t data_array[2] = { 0 }; - rslt = bma400_get_regs(BMA400_FIFO_LENGTH_ADDR, data_array, 2, dev); + rslt = bma400_get_regs(BMA400_REG_FIFO_LENGTH, data_array, 2, dev); if (rslt == BMA400_OK) { data_array[1] = BMA400_GET_BITS_POS_0(data_array[1], BMA400_FIFO_BYTES_CNT); @@ -2797,11 +2994,11 @@ static int8_t get_fifo_length(uint16_t *fifo_byte_cnt, const struct bma400_dev * return rslt; } -static int8_t read_fifo(const struct bma400_fifo_data *fifo, const struct bma400_dev *dev) +static int8_t read_fifo(struct bma400_fifo_data *fifo, struct bma400_dev *dev) { int8_t rslt; uint8_t reg_data; - uint8_t fifo_addr = BMA400_FIFO_DATA_ADDR; + uint8_t fifo_addr = BMA400_REG_FIFO_DATA; if (dev->intf == BMA400_SPI_INTF) { @@ -2809,16 +3006,19 @@ static int8_t read_fifo(const struct bma400_fifo_data *fifo, const struct bma400 fifo_addr = fifo_addr | BMA400_SPI_RD_MASK; } + /* This update will take care of dummy byte necessity based on interface selection */ + fifo->length += dev->dummy_byte; + /* Read the FIFO enable bit */ - rslt = bma400_get_regs(BMA400_FIFO_READ_EN_ADDR, ®_data, 1, dev); + rslt = bma400_get_regs(BMA400_REG_FIFO_READ_EN, ®_data, 1, dev); if (rslt == BMA400_OK) { /* FIFO read disable bit */ if (reg_data == 0) { /* Read FIFO Buffer since FIFO read is enabled */ - rslt = dev->read(dev->dev_id, fifo_addr, fifo->data, fifo->length); - if (rslt != 0) + dev->intf_rslt = dev->read(fifo_addr, fifo->data, (uint32_t)fifo->length, dev->intf_ptr); + if (dev->intf_rslt != BMA400_INTF_RET_SUCCESS) { rslt = BMA400_E_COM_FAIL; } @@ -2827,20 +3027,20 @@ static int8_t read_fifo(const struct bma400_fifo_data *fifo, const struct bma400 { /* Enable FIFO reading */ reg_data = 0; - rslt = bma400_set_regs(BMA400_FIFO_READ_EN_ADDR, ®_data, 1, dev); + rslt = bma400_set_regs(BMA400_REG_FIFO_READ_EN, ®_data, 1, dev); if (rslt == BMA400_OK) { /* Delay to enable the FIFO */ - dev->delay_ms(1); + dev->delay_us(1000, dev->intf_ptr); /* Read FIFO Buffer since FIFO read is enabled*/ - rslt = dev->read(dev->dev_id, fifo_addr, fifo->data, fifo->length); + dev->intf_rslt = dev->read(fifo_addr, fifo->data, (uint32_t)fifo->length, dev->intf_ptr); - if (rslt == BMA400_OK) + if (dev->intf_rslt == BMA400_OK) { /* Disable FIFO reading */ reg_data = 1; - rslt = bma400_set_regs(BMA400_FIFO_READ_EN_ADDR, ®_data, 1, dev); + rslt = bma400_set_regs(BMA400_REG_FIFO_READ_EN, ®_data, 1, dev); } } } @@ -2877,6 +3077,7 @@ static void unpack_accel_frame(struct bma400_fifo_data *fifo, /* Dummy byte included */ fifo->accel_byte_start_idx = dev->dummy_byte; } + for (data_index = fifo->accel_byte_start_idx; data_index < fifo->length;) { /*Header byte is stored in the variable frame_header*/ @@ -2900,6 +3101,7 @@ static void unpack_accel_frame(struct bma400_fifo_data *fifo, unpack_accel(fifo, &accel_data[accel_index], &data_index, accel_width, frame_header); accel_index++; } + break; case BMA400_FIFO_X_ENABLE: check_frame_available(fifo, &frame_available, accel_width, BMA400_FIFO_X_ENABLE, &data_index); @@ -2909,6 +3111,7 @@ static void unpack_accel_frame(struct bma400_fifo_data *fifo, unpack_accel(fifo, &accel_data[accel_index], &data_index, accel_width, frame_header); accel_index++; } + break; case BMA400_FIFO_Y_ENABLE: check_frame_available(fifo, &frame_available, accel_width, BMA400_FIFO_Y_ENABLE, &data_index); @@ -2918,6 +3121,7 @@ static void unpack_accel_frame(struct bma400_fifo_data *fifo, unpack_accel(fifo, &accel_data[accel_index], &data_index, accel_width, frame_header); accel_index++; } + break; case BMA400_FIFO_Z_ENABLE: check_frame_available(fifo, &frame_available, accel_width, BMA400_FIFO_Z_ENABLE, &data_index); @@ -2927,6 +3131,7 @@ static void unpack_accel_frame(struct bma400_fifo_data *fifo, unpack_accel(fifo, &accel_data[accel_index], &data_index, accel_width, frame_header); accel_index++; } + break; case BMA400_FIFO_XY_ENABLE: check_frame_available(fifo, &frame_available, accel_width, BMA400_FIFO_XY_ENABLE, &data_index); @@ -2936,6 +3141,7 @@ static void unpack_accel_frame(struct bma400_fifo_data *fifo, unpack_accel(fifo, &accel_data[accel_index], &data_index, accel_width, frame_header); accel_index++; } + break; case BMA400_FIFO_YZ_ENABLE: check_frame_available(fifo, &frame_available, accel_width, BMA400_FIFO_YZ_ENABLE, &data_index); @@ -2945,6 +3151,7 @@ static void unpack_accel_frame(struct bma400_fifo_data *fifo, unpack_accel(fifo, &accel_data[accel_index], &data_index, accel_width, frame_header); accel_index++; } + break; case BMA400_FIFO_XZ_ENABLE: check_frame_available(fifo, &frame_available, accel_width, BMA400_FIFO_YZ_ENABLE, &data_index); @@ -2954,6 +3161,7 @@ static void unpack_accel_frame(struct bma400_fifo_data *fifo, unpack_accel(fifo, &accel_data[accel_index], &data_index, accel_width, frame_header); accel_index++; } + break; case BMA400_FIFO_SENSOR_TIME: check_frame_available(fifo, &frame_available, accel_width, BMA400_FIFO_SENSOR_TIME, &data_index); @@ -2962,6 +3170,7 @@ static void unpack_accel_frame(struct bma400_fifo_data *fifo, /* Unpack and store the sensor time data */ unpack_sensortime_frame(fifo, &data_index); } + break; case BMA400_FIFO_EMPTY_FRAME: @@ -2975,6 +3184,7 @@ static void unpack_accel_frame(struct bma400_fifo_data *fifo, /* Store the configuration change data from FIFO */ fifo->conf_change = fifo->data[data_index++]; } + break; default: @@ -3022,6 +3232,7 @@ static void check_frame_available(const struct bma400_fifo_data *fifo, *data_index = fifo->length; *frame_available = BMA400_DISABLE; } + break; case BMA400_FIFO_X_ENABLE: case BMA400_FIFO_Y_ENABLE: @@ -3043,6 +3254,7 @@ static void check_frame_available(const struct bma400_fifo_data *fifo, *data_index = fifo->length; *frame_available = BMA400_DISABLE; } + break; case BMA400_FIFO_XY_ENABLE: case BMA400_FIFO_YZ_ENABLE: @@ -3064,6 +3276,7 @@ static void check_frame_available(const struct bma400_fifo_data *fifo, *data_index = fifo->length; *frame_available = BMA400_DISABLE; } + break; case BMA400_FIFO_SENSOR_TIME: if ((*data_index + 3) > fifo->length) @@ -3072,6 +3285,7 @@ static void check_frame_available(const struct bma400_fifo_data *fifo, *data_index = fifo->length; *frame_available = BMA400_DISABLE; } + break; case BMA400_FIFO_CONTROL_FRAME: if ((*data_index + 1) > fifo->length) @@ -3080,6 +3294,7 @@ static void check_frame_available(const struct bma400_fifo_data *fifo, *data_index = fifo->length; *frame_available = BMA400_DISABLE; } + break; default: break; @@ -3116,6 +3331,7 @@ static void unpack_accel(const struct bma400_fifo_data *fifo, /* Accel x not available */ accel_data->x = 0; } + if (frame_header & BMA400_FIFO_Y_ENABLE) { /* Accel y data */ @@ -3133,6 +3349,7 @@ static void unpack_accel(const struct bma400_fifo_data *fifo, /* Accel y not available */ accel_data->y = 0; } + if (frame_header & BMA400_FIFO_Z_ENABLE) { /* Accel z data */ @@ -3169,6 +3386,7 @@ static void unpack_accel(const struct bma400_fifo_data *fifo, /* Accel x not available */ accel_data->x = 0; } + if (frame_header & BMA400_FIFO_Y_ENABLE) { /* Accel y data */ @@ -3185,6 +3403,7 @@ static void unpack_accel(const struct bma400_fifo_data *fifo, /* Accel y not available */ accel_data->y = 0; } + if (frame_header & BMA400_FIFO_Z_ENABLE) { /* Accel z data */ @@ -3225,36 +3444,23 @@ static int8_t validate_accel_self_test(const struct bma400_sensor_data *accel_po int8_t rslt; - /* Structure for difference of accel values in g */ - struct selftest_delta_limit accel_data_diff = { 0, 0, 0 }; + /* Structure for difference of accel values */ + struct bma400_selftest_delta_limit accel_data_diff = { 0, 0, 0 }; - /* Structure for difference of accel values in mg */ - struct selftest_delta_limit accel_data_diff_mg = { 0, 0, 0 }; + /* accel x difference value */ + accel_data_diff.x = (accel_pos->x - accel_neg->x); - accel_data_diff.x = accel_pos->x - accel_neg->x; - accel_data_diff.y = accel_pos->y - accel_neg->y; - accel_data_diff.z = accel_pos->z - accel_neg->z; + /* accel y difference value */ + accel_data_diff.y = (accel_pos->y - accel_neg->y); - /* Converting LSB of the differences of accel - * values to mg - */ - convert_lsb_g(&accel_data_diff, &accel_data_diff_mg); + /* accel z difference value */ + accel_data_diff.z = (accel_pos->z - accel_neg->z); - /* Validate the results of self test - * Self test value of x,y axes should be 800mg - * and z axes should be 400 mg - */ - - if (((accel_data_diff_mg.x) > BMA400_ST_ACC_X_AXIS_SIGNAL_DIFF) && - ((accel_data_diff_mg.y) > BMA400_ST_ACC_Y_AXIS_SIGNAL_DIFF) && - ((accel_data_diff_mg.z) > BMA400_ST_ACC_Z_AXIS_SIGNAL_DIFF)) + /* Validate the results of self test */ + if (((accel_data_diff.x) > BMA400_ST_ACC_X_AXIS_SIGNAL_DIFF) && + ((accel_data_diff.y) > BMA400_ST_ACC_Y_AXIS_SIGNAL_DIFF) && + ((accel_data_diff.z) > BMA400_ST_ACC_Z_AXIS_SIGNAL_DIFF)) { - - /* - * if (((accel_pos->x - accel_neg->x) > 205) && ((accel_pos->y - accel_neg->y) > 205) && - * ((accel_pos->z - accel_neg->z) > 103)) - */ - /* Self test pass condition */ rslt = BMA400_OK; } @@ -3267,83 +3473,47 @@ static int8_t validate_accel_self_test(const struct bma400_sensor_data *accel_po return rslt; } -static void convert_lsb_g(const struct selftest_delta_limit *accel_data_diff, - struct selftest_delta_limit *accel_data_diff_mg) -{ - uint32_t lsb_per_g; - - /* Range considered for self-test is 4g */ - uint8_t range = BMA400_4G_RANGE; - - /* lsb_per_g for the respective resolution and 8g range*/ - lsb_per_g = (uint32_t)(power(2, 8) / (2 * range)); - - /* accel x value in mg */ - accel_data_diff_mg->x = (accel_data_diff->x / (int32_t)lsb_per_g) * 1000; - - /* accel y value in mg */ - accel_data_diff_mg->y = (accel_data_diff->y / (int32_t)lsb_per_g) * 1000; - - /* accel z value in mg */ - accel_data_diff_mg->z = (accel_data_diff->z / (int32_t)lsb_per_g) * 1000; -} - -static int32_t power(int16_t base, uint8_t resolution) -{ - uint8_t i = 1; - - /* Initialize variable to store the power of 2 value */ - int32_t value = 1; - - for (; i <= resolution; i++) - { - value = (int32_t)(value * base); - } - - return value; -} - -static int8_t positive_excited_accel(struct bma400_sensor_data *accel_pos, const struct bma400_dev *dev) +static int8_t positive_excited_accel(struct bma400_sensor_data *accel_pos, struct bma400_dev *dev) { int8_t rslt; - uint8_t reg_data = BMA400_ENABLE_POSITIVE_SELF_TEST; + uint8_t reg_data = BMA400_SELF_TEST_ENABLE_POSITIVE; /* Enable positive excitation for all 3 axes */ - rslt = bma400_set_regs(BMA400_SELF_TEST_ADDR, ®_data, 1, dev); + rslt = bma400_set_regs(BMA400_REG_SELF_TEST, ®_data, 1, dev); if (rslt == BMA400_OK) { /* Read accel data after 50ms delay */ - dev->delay_ms(BMA400_SELF_TEST_DATA_READ_MS); + dev->delay_us(BMA400_DELAY_US_SELF_TEST_DATA_READ, dev->intf_ptr); rslt = bma400_get_accel_data(BMA400_DATA_ONLY, accel_pos, dev); } return rslt; } -static int8_t negative_excited_accel(struct bma400_sensor_data *accel_neg, const struct bma400_dev *dev) +static int8_t negative_excited_accel(struct bma400_sensor_data *accel_neg, struct bma400_dev *dev) { int8_t rslt; - uint8_t reg_data = BMA400_ENABLE_NEGATIVE_SELF_TEST; + uint8_t reg_data = BMA400_SELF_TEST_ENABLE_NEGATIVE; /* Enable negative excitation for all 3 axes */ - rslt = bma400_set_regs(BMA400_SELF_TEST_ADDR, ®_data, 1, dev); + rslt = bma400_set_regs(BMA400_REG_SELF_TEST, ®_data, 1, dev); if (rslt == BMA400_OK) { /* Read accel data after 50ms delay */ - dev->delay_ms(BMA400_SELF_TEST_DATA_READ_MS); + dev->delay_us(BMA400_DELAY_US_SELF_TEST_DATA_READ, dev->intf_ptr); rslt = bma400_get_accel_data(BMA400_DATA_ONLY, accel_neg, dev); if (rslt == BMA400_OK) { /* Disable self test */ - reg_data = BMA400_DISABLE_SELF_TEST; - rslt = bma400_set_regs(BMA400_SELF_TEST_ADDR, ®_data, 1, dev); + reg_data = BMA400_SELF_TEST_DISABLE; + rslt = bma400_set_regs(BMA400_REG_SELF_TEST, ®_data, 1, dev); } } return rslt; } -static int8_t enable_self_test(const struct bma400_dev *dev) +static int8_t enable_self_test(struct bma400_dev *dev) { int8_t rslt; @@ -3360,8 +3530,7 @@ static int8_t enable_self_test(const struct bma400_dev *dev) /* Modify to the desired configurations */ accel_setting.param.accel.odr = BMA400_ODR_100HZ; - /*accel_setting.param.accel.range = BMA400_8G_RANGE; */ - accel_setting.param.accel.range = BMA400_4G_RANGE; + accel_setting.param.accel.range = BMA400_RANGE_4G; accel_setting.param.accel.osr = BMA400_ACCEL_OSR_SETTING_3; accel_setting.param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1; @@ -3370,11 +3539,12 @@ static int8_t enable_self_test(const struct bma400_dev *dev) if (rslt == BMA400_OK) { /* self test enabling delay */ - dev->delay_ms(BMA400_SELF_TEST_DELAY_MS); + dev->delay_us(BMA400_DELAY_US_SELF_TEST, dev->intf_ptr); } + if (rslt == BMA400_OK) { - rslt = bma400_set_power_mode(BMA400_NORMAL_MODE, dev); + rslt = bma400_set_power_mode(BMA400_MODE_NORMAL, dev); } } diff --git a/bma400.h b/bma400.h index c913e84..d602dcc 100644 --- a/bma400.h +++ b/bma400.h @@ -30,9 +30,9 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * -* @file bma400.h -* @date 10/01/2020 -* @version 1.5.6 +* @file bma400.h +* @date 2020-06-05 +* @version v1.5.8 * */ @@ -71,9 +71,9 @@ extern "C" { * @param[in,out] dev : Structure instance of bma400_dev * * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ int8_t bma400_init(struct bma400_dev *dev); @@ -106,11 +106,11 @@ int8_t bma400_init(struct bma400_dev *dev); * @note The accelerometer data value is in LSB, based on the range selected. * * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, const struct bma400_dev *dev); +int8_t bma400_get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, struct bma400_dev *dev); /** * \ingroup bma400 @@ -137,11 +137,11 @@ int8_t bma400_get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, * @endcode * * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_set_power_mode(uint8_t power_mode, const struct bma400_dev *dev); +int8_t bma400_set_power_mode(uint8_t power_mode, struct bma400_dev *dev); /*! * \ingroup bma400ApiConfig @@ -161,11 +161,11 @@ int8_t bma400_set_power_mode(uint8_t power_mode, const struct bma400_dev *dev); * @endcode * * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_get_power_mode(uint8_t *power_mode, const struct bma400_dev *dev); +int8_t bma400_get_power_mode(uint8_t *power_mode, struct bma400_dev *dev); /*! * \ingroup bma400ApiConfig @@ -190,11 +190,11 @@ int8_t bma400_get_power_mode(uint8_t *power_mode, const struct bma400_dev *dev); * (Examples are mentioned in the readme.md). * * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_set_sensor_conf(const struct bma400_sensor_conf *conf, uint16_t n_sett, const struct bma400_dev *dev); +int8_t bma400_set_sensor_conf(const struct bma400_sensor_conf *conf, uint16_t n_sett, struct bma400_dev *dev); /*! * \ingroup bma400ApiConfig @@ -213,11 +213,11 @@ int8_t bma400_set_sensor_conf(const struct bma400_sensor_conf *conf, uint16_t n_ * @note Once the API is called, the settings structure will be updated in the settings structure. * * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_get_sensor_conf(struct bma400_sensor_conf *conf, uint16_t n_sett, const struct bma400_dev *dev); +int8_t bma400_get_sensor_conf(struct bma400_sensor_conf *conf, uint16_t n_sett, struct bma400_dev *dev); /*! * \ingroup bma400ApiConfig @@ -242,11 +242,11 @@ int8_t bma400_get_sensor_conf(struct bma400_sensor_conf *conf, uint16_t n_sett, * conf structure(refer Examples). * * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_set_device_conf(const struct bma400_device_conf *conf, uint8_t n_sett, const struct bma400_dev *dev); +int8_t bma400_set_device_conf(const struct bma400_device_conf *conf, uint8_t n_sett, struct bma400_dev *dev); /*! * \ingroup bma400ApiConfig @@ -265,11 +265,11 @@ int8_t bma400_set_device_conf(const struct bma400_device_conf *conf, uint8_t n_s * in the settings structure. * * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_get_device_conf(struct bma400_device_conf *conf, uint8_t n_sett, const struct bma400_dev *dev); +int8_t bma400_get_device_conf(struct bma400_device_conf *conf, uint8_t n_sett, struct bma400_dev *dev); /** * \ingroup bma400 @@ -289,11 +289,11 @@ int8_t bma400_get_device_conf(struct bma400_device_conf *conf, uint8_t n_sett, c * @param[in] dev : Structure instance of bma400_dev. * * @return Result of API execution status - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_set_fifo_flush(const struct bma400_dev *dev); +int8_t bma400_set_fifo_flush(struct bma400_dev *dev); /*! * \ingroup bma400ApiFifo @@ -316,11 +316,11 @@ int8_t bma400_set_fifo_flush(const struct bma400_dev *dev); * @param[in,out] dev : Structure instance of bma400_dev. * * @return Result of API execution status - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_get_fifo_data(struct bma400_fifo_data *fifo, const struct bma400_dev *dev); +int8_t bma400_get_fifo_data(struct bma400_fifo_data *fifo, struct bma400_dev *dev); /*! * \ingroup bma400ApiFifo @@ -350,9 +350,9 @@ int8_t bma400_get_fifo_data(struct bma400_fifo_data *fifo, const struct bma400_d * @param[in] dev : Structure instance of bma400_dev. * * @return Result of API execution status - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ int8_t bma400_extract_accel(struct bma400_fifo_data *fifo, struct bma400_sensor_data *accel_data, @@ -400,11 +400,11 @@ int8_t bma400_extract_accel(struct bma400_fifo_data *fifo, * } *@endcode * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_get_interrupt_status(uint16_t *int_status, const struct bma400_dev *dev); +int8_t bma400_get_interrupt_status(uint16_t *int_status, struct bma400_dev *dev); /*! * \ingroup bma400ApiInterrupt @@ -424,12 +424,11 @@ int8_t bma400_get_interrupt_status(uint16_t *int_status, const struct bma400_dev * output is stored in int_select->conf either as BMA400_ENABLE/BMA400_DISABLE * * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_get_interrupts_enabled(struct bma400_int_enable *int_select, uint8_t n_sett, - const struct bma400_dev *dev); +int8_t bma400_get_interrupts_enabled(struct bma400_int_enable *int_select, uint8_t n_sett, struct bma400_dev *dev); /*! * \ingroup bma400ApiInterrupt @@ -457,12 +456,11 @@ int8_t bma400_get_interrupts_enabled(struct bma400_int_enable *int_select, uint8 * rslt = bma400_enable_interrupt(&int_select, 2, dev); *@endcode * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_enable_interrupt(const struct bma400_int_enable *int_select, uint8_t n_sett, - const struct bma400_dev *dev); +int8_t bma400_enable_interrupt(const struct bma400_int_enable *int_select, uint8_t n_sett, struct bma400_dev *dev); /** * \ingroup bma400 @@ -485,11 +483,11 @@ int8_t bma400_enable_interrupt(const struct bma400_int_enable *int_select, uint8 * @param[in] dev : Structure instance of bma400_dev. * * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_set_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const struct bma400_dev *dev); +int8_t bma400_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, struct bma400_dev *dev); /*! * \ingroup bma400ApiRegister @@ -509,11 +507,11 @@ int8_t bma400_set_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const s * Register address - 0x14(BMA400_FIFO_DATA_ADDR) * * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const struct bma400_dev *dev); +int8_t bma400_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bma400_dev *dev); /** * \ingroup bma400 @@ -532,11 +530,11 @@ int8_t bma400_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const s * @param[in] dev : Structure instance of bma400_dev. * * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_soft_reset(const struct bma400_dev *dev); +int8_t bma400_soft_reset(struct bma400_dev *dev); /*! * \ingroup bma400ApiSystem @@ -553,11 +551,11 @@ int8_t bma400_soft_reset(const struct bma400_dev *dev); * define the required settings after performing the self test. * * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error / failure + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_perform_self_test(const struct bma400_dev *dev); +int8_t bma400_perform_self_test(struct bma400_dev *dev); /*! * \ingroup bma400ApiSystem @@ -565,7 +563,7 @@ int8_t bma400_perform_self_test(const struct bma400_dev *dev); * \code * int8_t bma400_get_temperature_data(int16_t *temperature_data, const struct bma400_dev *dev); * \endcode - * @details This API is used to get the temperature data output. + * @details This API is used to get the raw temperature data output. * * @note Temperature data output must be divided by a factor of 10 * Consider temperature_data = 195 , @@ -575,11 +573,11 @@ int8_t bma400_perform_self_test(const struct bma400_dev *dev); * @param[in] dev : Structure instance of bma400_dev. * * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_get_temperature_data(int16_t *temperature_data, const struct bma400_dev *dev); +int8_t bma400_get_temperature_data(int16_t *temperature_data, struct bma400_dev *dev); /** * \ingroup bma400 @@ -593,17 +591,48 @@ int8_t bma400_get_temperature_data(int16_t *temperature_data, const struct bma40 * \code * int8_t bma400_set_step_counter_param(uint8_t *sccr_conf, const struct bma400_dev *dev); * \endcode - * @details This API is used to set the step counter's configuration parameters from the registers 0x59 to 0x71. + * @details This API is used to set the step counter's configuration parameters from the registers 0x59 to 0x70. + * + *@verbatim + *---------------------------------------------------------------------- + * Register name Address wrist(default) non-wrist + *---------------------------------------------------------------------- + * STEP_COUNTER_CONFIG0 0x59 1 1 + * STEP_COUNTER_CONFIG1 0x5A 45 50 + * STEP_COUNTER_CONFIG2 0x5B 123 120 + * STEP_COUNTER_CONFIG3 0x5C 212 230 + * STEP_COUNTER_CONFIG4 0x5D 68 135 + * STEP_COUNTER_CONFIG5 0x5E 1 0 + * STEP_COUNTER_CONFIG6 0x5F 59 132 + * STEP_COUNTER_CONFIG7 0x60 122 108 + * STEP_COUNTER_CONFIG8 0x61 219 156 + * STEP_COUNTER_CONFIG9 0x62 123 117 + * STEP_COUNTER_CONFIG10 0x63 63 100 + * STEP_COUNTER_CONFIG11 0x64 108 126 + * STEP_COUNTER_CONFIG12 0x65 205 170 + * STEP_COUNTER_CONFIG13 0x66 39 12 + * STEP_COUNTER_CONFIG14 0x67 25 12 + * STEP_COUNTER_CONFIG15 0x68 150 74 + * STEP_COUNTER_CONFIG16 0x69 160 160 + * STEP_COUNTER_CONFIG17 0x6A 195 0 + * STEP_COUNTER_CONFIG18 0x6B 14 0 + * STEP_COUNTER_CONFIG19 0x6C 12 12 + * STEP_COUNTER_CONFIG20 0x6D 60 60 + * STEP_COUNTER_CONFIG21 0x6E 240 240 + * STEP_COUNTER_CONFIG22 0x6F 0 1 + * STEP_COUNTER_CONFIG23 0x70 247 0 + *------------------------------------------------------------------------ + *@endverbatim * * @param[in] sccr_conf : sc config parameter * @param[in] dev : Structure instance of bma400_dev. * * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error / failure + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_set_step_counter_param(uint8_t *sccr_conf, const struct bma400_dev *dev); +int8_t bma400_set_step_counter_param(const uint8_t *sccr_conf, struct bma400_dev *dev); /*! * \ingroup bma400ApiSc @@ -624,20 +653,14 @@ int8_t bma400_set_step_counter_param(uint8_t *sccr_conf, const struct bma400_dev * 0x02 | BMA400_RUN_ACT * * @return Result of API execution status. - * @retval Zero Success - * @retval Postive Warning - * @retval Negative Error + * @retval zero -> Success + * @retval +ve value -> Warning + * @retval -ve value -> Error */ -int8_t bma400_get_steps_counted(uint32_t *step_count, uint8_t *activity_data, const struct bma400_dev *dev); - -/** - * \ingroup bma400 - * \defgroup bma400Examples Examples - * @brief Reference Examples */ +int8_t bma400_get_steps_counted(uint32_t *step_count, uint8_t *activity_data, struct bma400_dev *dev); #ifdef __cplusplus } #endif /* End of CPP guard */ #endif /* BMA400_H__ */ -/** @} */ diff --git a/bma400_defs.h b/bma400_defs.h index 0bc4960..94caa69 100644 --- a/bma400_defs.h +++ b/bma400_defs.h @@ -30,9 +30,9 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * -* @file bma400_defs.h -* @date 10/01/2020 -* @version 1.5.6 +* @file bma400_defs.h +* @date 2020-06-05 +* @version v1.5.8 * */ @@ -50,170 +50,181 @@ #endif #if !defined(UINT8_C) && !defined(INT8_C) -#define INT8_C(x) S8_C(x) -#define UINT8_C(x) U8_C(x) +#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) +#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) +#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) +#define INT64_C(x) S64_C(x) +#define UINT64_C(x) U64_C(x) #endif /* C standard macros */ #ifndef NULL #ifdef __cplusplus -#define NULL 0 +#define NULL 0 #else -#define NULL ((void *) 0) +#define NULL ((void *) 0) #endif #endif #ifndef TRUE -#define TRUE UINT8_C(1) +#define TRUE UINT8_C(1) #endif #ifndef FALSE -#define FALSE UINT8_C(0) +#define FALSE UINT8_C(0) +#endif + +/*! + * BMA400_INTF_RET_TYPE is the read/write interface return type which can be overwritten by the build system. + * The default is set to int8_t. + */ +#ifndef BMA400_INTF_RET_TYPE +#define BMA400_INTF_RET_TYPE int8_t +#endif + +/*! + * BMA400_INTF_RET_SUCCESS is the success return value read/write interface return type which can be + * overwritten by the build system. The default is set to 0. + */ +#ifndef BMA400_INTF_RET_SUCCESS +#define BMA400_INTF_RET_SUCCESS INT8_C(0) #endif /* API success code */ -#define BMA400_OK INT8_C(0) +#define BMA400_OK INT8_C(0) /* API error codes */ -#define BMA400_E_NULL_PTR INT8_C(-1) -#define BMA400_E_COM_FAIL INT8_C(-2) -#define BMA400_E_DEV_NOT_FOUND INT8_C(-3) -#define BMA400_E_INVALID_CONFIG INT8_C(-4) +#define BMA400_E_NULL_PTR INT8_C(-1) +#define BMA400_E_COM_FAIL INT8_C(-2) +#define BMA400_E_DEV_NOT_FOUND INT8_C(-3) +#define BMA400_E_INVALID_CONFIG INT8_C(-4) /* API warning codes */ -#define BMA400_W_SELF_TEST_FAIL INT8_C(1) +#define BMA400_W_SELF_TEST_FAIL INT8_C(1) /* CHIP ID VALUE */ -#define BMA400_CHIP_ID UINT8_C(0x90) +#define BMA400_CHIP_ID UINT8_C(0x90) /* BMA400 I2C address macros */ -#define BMA400_I2C_ADDRESS_SDO_LOW UINT8_C(0x14) -#define BMA400_I2C_ADDRESS_SDO_HIGH UINT8_C(0x15) +#define BMA400_I2C_ADDRESS_SDO_LOW UINT8_C(0x14) +#define BMA400_I2C_ADDRESS_SDO_HIGH UINT8_C(0x15) /* Power mode configurations */ -#define BMA400_NORMAL_MODE UINT8_C(0x02) -#define BMA400_SLEEP_MODE UINT8_C(0x00) -#define BMA400_LOW_POWER_MODE UINT8_C(0x01) +#define BMA400_MODE_NORMAL UINT8_C(0x02) +#define BMA400_MODE_SLEEP UINT8_C(0x00) +#define BMA400_MODE_LOW_POWER UINT8_C(0x01) /* Enable / Disable macros */ -#define BMA400_DISABLE UINT8_C(0) -#define BMA400_ENABLE UINT8_C(1) +#define BMA400_DISABLE UINT8_C(0) +#define BMA400_ENABLE UINT8_C(1) /* Data/sensortime selection macros */ -#define BMA400_DATA_ONLY UINT8_C(0x00) -#define BMA400_DATA_SENSOR_TIME UINT8_C(0x01) +#define BMA400_DATA_ONLY UINT8_C(0x00) +#define BMA400_DATA_SENSOR_TIME UINT8_C(0x01) /* ODR configurations */ -#define BMA400_ODR_12_5HZ UINT8_C(0x05) -#define BMA400_ODR_25HZ UINT8_C(0x06) -#define BMA400_ODR_50HZ UINT8_C(0x07) -#define BMA400_ODR_100HZ UINT8_C(0x08) -#define BMA400_ODR_200HZ UINT8_C(0x09) -#define BMA400_ODR_400HZ UINT8_C(0x0A) -#define BMA400_ODR_800HZ UINT8_C(0x0B) +#define BMA400_ODR_12_5HZ UINT8_C(0x05) +#define BMA400_ODR_25HZ UINT8_C(0x06) +#define BMA400_ODR_50HZ UINT8_C(0x07) +#define BMA400_ODR_100HZ UINT8_C(0x08) +#define BMA400_ODR_200HZ UINT8_C(0x09) +#define BMA400_ODR_400HZ UINT8_C(0x0A) +#define BMA400_ODR_800HZ UINT8_C(0x0B) /* Accel Range configuration */ -#define BMA400_2G_RANGE UINT8_C(0x00) -#define BMA400_4G_RANGE UINT8_C(0x01) -#define BMA400_8G_RANGE UINT8_C(0x02) -#define BMA400_16G_RANGE UINT8_C(0x03) +#define BMA400_RANGE_2G UINT8_C(0x00) +#define BMA400_RANGE_4G UINT8_C(0x01) +#define BMA400_RANGE_8G UINT8_C(0x02) +#define BMA400_RANGE_16G UINT8_C(0x03) /* Accel Axes selection settings for * DATA SAMPLING, WAKEUP, ORIENTATION CHANGE, * GEN1, GEN2 , ACTIVITY CHANGE */ -#define BMA400_X_AXIS_EN UINT8_C(0x01) -#define BMA400_Y_AXIS_EN UINT8_C(0x02) -#define BMA400_Z_AXIS_EN UINT8_C(0x04) -#define BMA400_XYZ_AXIS_EN UINT8_C(0x07) +#define BMA400_AXIS_X_EN UINT8_C(0x01) +#define BMA400_AXIS_Y_EN UINT8_C(0x02) +#define BMA400_AXIS_Z_EN UINT8_C(0x04) +#define BMA400_AXIS_XYZ_EN UINT8_C(0x07) /* Accel filter(data_src_reg) selection settings */ -#define BMA400_DATA_SRC_ACCEL_FILT_1 UINT8_C(0x00) -#define BMA400_DATA_SRC_ACCEL_FILT_2 UINT8_C(0x01) -#define BMA400_DATA_SRC_ACCEL_FILT_LP UINT8_C(0x02) +#define BMA400_DATA_SRC_ACCEL_FILT_1 UINT8_C(0x00) +#define BMA400_DATA_SRC_ACCEL_FILT_2 UINT8_C(0x01) +#define BMA400_DATA_SRC_ACCEL_FILT_LP UINT8_C(0x02) /* Accel OSR (OSR,OSR_LP) settings */ -#define BMA400_ACCEL_OSR_SETTING_0 UINT8_C(0x00) -#define BMA400_ACCEL_OSR_SETTING_1 UINT8_C(0x01) -#define BMA400_ACCEL_OSR_SETTING_2 UINT8_C(0x02) -#define BMA400_ACCEL_OSR_SETTING_3 UINT8_C(0x03) +#define BMA400_ACCEL_OSR_SETTING_0 UINT8_C(0x00) +#define BMA400_ACCEL_OSR_SETTING_1 UINT8_C(0x01) +#define BMA400_ACCEL_OSR_SETTING_2 UINT8_C(0x02) +#define BMA400_ACCEL_OSR_SETTING_3 UINT8_C(0x03) /* Accel filt1_bw settings */ /* Accel filt1_bw = 0.48 * ODR */ -#define BMA400_ACCEL_FILT1_BW_0 UINT8_C(0x00) +#define BMA400_ACCEL_FILT1_BW_0 UINT8_C(0x00) /* Accel filt1_bw = 0.24 * ODR */ -#define BMA400_ACCEL_FILT1_BW_1 UINT8_C(0x01) +#define BMA400_ACCEL_FILT1_BW_1 UINT8_C(0x01) /* Auto wake-up timeout value of 10.24s */ -#define BMA400_AUTO_WAKEUP_TIMEOUT_MAX UINT16_C(0x0FFF) +#define BMA400_TIMEOUT_MAX_AUTO_WAKEUP UINT16_C(0x0FFF) /* Auto low power timeout value of 10.24s */ -#define BMA400_AUTO_LP_TIMEOUT_MAX UINT16_C(0x0FFF) +#define BMA400_TIMEOUT_MAX_AUTO_LP UINT16_C(0x0FFF) /* Reference Update macros */ -#define BMA400_MANUAL_UPDATE UINT8_C(0x00) -#define BMA400_ONE_TIME_UPDATE UINT8_C(0x01) -#define BMA400_EVERY_TIME_UPDATE UINT8_C(0x02) -#define BMA400_LP_EVERY_TIME_UPDATE UINT8_C(0x03) +#define BMA400_UPDATE_MANUAL UINT8_C(0x00) +#define BMA400_UPDATE_ONE_TIME UINT8_C(0x01) +#define BMA400_UPDATE_EVERY_TIME UINT8_C(0x02) +#define BMA400_UPDATE_LP_EVERY_TIME UINT8_C(0x03) /* Reference Update macros for orient interrupts */ -#define BMA400_ORIENT_REFU_ACC_FILT_2 UINT8_C(0x01) -#define BMA400_ORIENT_REFU_ACC_FILT_LP UINT8_C(0x02) - -/* Stability evaluation macros for orient interrupts */ -#define BMA400_STABILITY_DISABLED UINT8_C(0x00) -#define BMA400_STABILITY_ACC_FILT_2 UINT8_C(0x01) -#define BMA400_STABILITY_ACC_FILT_LP UINT8_C(0x02) +#define BMA400_ORIENT_REFU_ACC_FILT_2 UINT8_C(0x01) +#define BMA400_ORIENT_REFU_ACC_FILT_LP UINT8_C(0x02) /* Number of samples needed for Auto-wakeup interrupt evaluation */ -#define BMA400_SAMPLE_COUNT_1 UINT8_C(0x00) -#define BMA400_SAMPLE_COUNT_2 UINT8_C(0x01) -#define BMA400_SAMPLE_COUNT_3 UINT8_C(0x02) -#define BMA400_SAMPLE_COUNT_4 UINT8_C(0x03) -#define BMA400_SAMPLE_COUNT_5 UINT8_C(0x04) -#define BMA400_SAMPLE_COUNT_6 UINT8_C(0x05) -#define BMA400_SAMPLE_COUNT_7 UINT8_C(0x06) -#define BMA400_SAMPLE_COUNT_8 UINT8_C(0x07) +#define BMA400_SAMPLE_COUNT_1 UINT8_C(0x00) +#define BMA400_SAMPLE_COUNT_2 UINT8_C(0x01) +#define BMA400_SAMPLE_COUNT_3 UINT8_C(0x02) +#define BMA400_SAMPLE_COUNT_4 UINT8_C(0x03) +#define BMA400_SAMPLE_COUNT_5 UINT8_C(0x04) +#define BMA400_SAMPLE_COUNT_6 UINT8_C(0x05) +#define BMA400_SAMPLE_COUNT_7 UINT8_C(0x06) +#define BMA400_SAMPLE_COUNT_8 UINT8_C(0x07) /* Auto low power configurations */ /* Auto low power timeout disabled */ -#define BMA400_AUTO_LP_TIMEOUT_DISABLE UINT8_C(0x00) +#define BMA400_AUTO_LP_TIMEOUT_DISABLE UINT8_C(0x00) /* Auto low power entered on drdy interrupt */ -#define BMA400_AUTO_LP_DRDY_TRIGGER UINT8_C(0x01) +#define BMA400_AUTO_LP_DRDY_TRIGGER UINT8_C(0x01) /* Auto low power entered on GEN1 interrupt */ -#define BMA400_AUTO_LP_GEN1_TRIGGER UINT8_C(0x02) +#define BMA400_AUTO_LP_GEN1_TRIGGER UINT8_C(0x02) /* Auto low power entered on timeout of threshold value */ -#define BMA400_AUTO_LP_TIMEOUT_EN UINT8_C(0x04) +#define BMA400_AUTO_LP_TIMEOUT_EN UINT8_C(0x04) /* Auto low power entered on timeout of threshold value * but reset on activity detection */ -#define BMA400_AUTO_LP_TIME_RESET_EN UINT8_C(0x08) +#define BMA400_AUTO_LP_TIME_RESET_EN UINT8_C(0x08) /* TAP INTERRUPT CONFIG MACROS */ /* Axes select for TAP interrupt */ -#define BMA400_X_AXIS_EN_TAP UINT8_C(0x02) -#define BMA400_Y_AXIS_EN_TAP UINT8_C(0x01) -#define BMA400_Z_AXIS_EN_TAP UINT8_C(0x00) +#define BMA400_TAP_X_AXIS_EN UINT8_C(0x02) +#define BMA400_TAP_Y_AXIS_EN UINT8_C(0x01) +#define BMA400_TAP_Z_AXIS_EN UINT8_C(0x00) /* TAP tics_th setting */ @@ -223,30 +234,30 @@ */ /* Configures 6 data samples for high-low tap signal change time */ -#define BMA400_TICS_TH_6_DATA_SAMPLES UINT8_C(0x00) +#define BMA400_TICS_TH_6_DATA_SAMPLES UINT8_C(0x00) /* Configures 9 data samples for high-low tap signal change time */ -#define BMA400_TICS_TH_9_DATA_SAMPLES UINT8_C(0x01) +#define BMA400_TICS_TH_9_DATA_SAMPLES UINT8_C(0x01) /* Configures 12 data samples for high-low tap signal change time */ -#define BMA400_TICS_TH_12_DATA_SAMPLES UINT8_C(0x02) +#define BMA400_TICS_TH_12_DATA_SAMPLES UINT8_C(0x02) /* Configures 18 data samples for high-low tap signal change time */ -#define BMA400_TICS_TH_18_DATA_SAMPLES UINT8_C(0x03) +#define BMA400_TICS_TH_18_DATA_SAMPLES UINT8_C(0x03) /* TAP Sensitivity setting */ /* It modifies the threshold for minimum TAP amplitude */ /* BMA400_TAP_SENSITIVITY_0 correspond to highest sensitivity */ -#define BMA400_TAP_SENSITIVITY_0 UINT8_C(0x00) -#define BMA400_TAP_SENSITIVITY_1 UINT8_C(0x01) -#define BMA400_TAP_SENSITIVITY_2 UINT8_C(0x02) -#define BMA400_TAP_SENSITIVITY_3 UINT8_C(0x03) -#define BMA400_TAP_SENSITIVITY_4 UINT8_C(0x04) -#define BMA400_TAP_SENSITIVITY_5 UINT8_C(0x05) -#define BMA400_TAP_SENSITIVITY_6 UINT8_C(0x06) +#define BMA400_TAP_SENSITIVITY_0 UINT8_C(0x00) +#define BMA400_TAP_SENSITIVITY_1 UINT8_C(0x01) +#define BMA400_TAP_SENSITIVITY_2 UINT8_C(0x02) +#define BMA400_TAP_SENSITIVITY_3 UINT8_C(0x03) +#define BMA400_TAP_SENSITIVITY_4 UINT8_C(0x04) +#define BMA400_TAP_SENSITIVITY_5 UINT8_C(0x05) +#define BMA400_TAP_SENSITIVITY_6 UINT8_C(0x06) /* BMA400_TAP_SENSITIVITY_7 correspond to lowest sensitivity */ -#define BMA400_TAP_SENSITIVITY_7 UINT8_C(0x07) +#define BMA400_TAP_SENSITIVITY_7 UINT8_C(0x07) /* BMA400 TAP - quiet settings */ @@ -256,16 +267,16 @@ */ /* Configures 60 data samples quiet time between single or double taps */ -#define BMA400_QUIET_60_DATA_SAMPLES UINT8_C(0x00) +#define BMA400_QUIET_60_DATA_SAMPLES UINT8_C(0x00) /* Configures 80 data samples quiet time between single or double taps */ -#define BMA400_QUIET_80_DATA_SAMPLES UINT8_C(0x01) +#define BMA400_QUIET_80_DATA_SAMPLES UINT8_C(0x01) /* Configures 100 data samples quiet time between single or double taps */ -#define BMA400_QUIET_100_DATA_SAMPLES UINT8_C(0x02) +#define BMA400_QUIET_100_DATA_SAMPLES UINT8_C(0x02) /* Configures 120 data samples quiet time between single or double taps */ -#define BMA400_QUIET_120_DATA_SAMPLES UINT8_C(0x03) +#define BMA400_QUIET_120_DATA_SAMPLES UINT8_C(0x03) /* BMA400 TAP - quiet_dt settings */ @@ -274,380 +285,386 @@ */ /* Configures 4 data samples minimum time between double taps */ -#define BMA400_QUIET_DT_4_DATA_SAMPLES UINT8_C(0x00) +#define BMA400_QUIET_DT_4_DATA_SAMPLES UINT8_C(0x00) /* Configures 8 data samples minimum time between double taps */ -#define BMA400_QUIET_DT_8_DATA_SAMPLES UINT8_C(0x01) +#define BMA400_QUIET_DT_8_DATA_SAMPLES UINT8_C(0x01) /* Configures 12 data samples minimum time between double taps */ -#define BMA400_QUIET_DT_12_DATA_SAMPLES UINT8_C(0x02) +#define BMA400_QUIET_DT_12_DATA_SAMPLES UINT8_C(0x02) /* Configures 16 data samples minimum time between double taps */ -#define BMA400_QUIET_DT_16_DATA_SAMPLES UINT8_C(0x03) +#define BMA400_QUIET_DT_16_DATA_SAMPLES UINT8_C(0x03) /* ACTIVITY CHANGE CONFIG MACROS */ /* Data source for activity change detection */ -#define BMA400_DATA_SRC_ACC_FILT1 UINT8_C(0x00) -#define BMA400_DATA_SRC_ACC_FILT2 UINT8_C(0x01) +#define BMA400_DATA_SRC_ACC_FILT1 UINT8_C(0x00) +#define BMA400_DATA_SRC_ACC_FILT2 UINT8_C(0x01) /* Number of samples to evaluate for activity change detection */ -#define BMA400_ACT_CH_SAMPLE_CNT_32 UINT8_C(0x00) -#define BMA400_ACT_CH_SAMPLE_CNT_64 UINT8_C(0x01) -#define BMA400_ACT_CH_SAMPLE_CNT_128 UINT8_C(0x02) -#define BMA400_ACT_CH_SAMPLE_CNT_256 UINT8_C(0x03) -#define BMA400_ACT_CH_SAMPLE_CNT_512 UINT8_C(0x04) +#define BMA400_ACT_CH_SAMPLE_CNT_32 UINT8_C(0x00) +#define BMA400_ACT_CH_SAMPLE_CNT_64 UINT8_C(0x01) +#define BMA400_ACT_CH_SAMPLE_CNT_128 UINT8_C(0x02) +#define BMA400_ACT_CH_SAMPLE_CNT_256 UINT8_C(0x03) +#define BMA400_ACT_CH_SAMPLE_CNT_512 UINT8_C(0x04) /* Interrupt pin configuration macros */ -#define BMA400_INT_PUSH_PULL_ACTIVE_0 UINT8_C(0x00) -#define BMA400_INT_PUSH_PULL_ACTIVE_1 UINT8_C(0x01) -#define BMA400_INT_OPEN_DRIVE_ACTIVE_0 UINT8_C(0x02) -#define BMA400_INT_OPEN_DRIVE_ACTIVE_1 UINT8_C(0x03) +#define BMA400_INT_PUSH_PULL_ACTIVE_0 UINT8_C(0x00) +#define BMA400_INT_PUSH_PULL_ACTIVE_1 UINT8_C(0x01) +#define BMA400_INT_OPEN_DRIVE_ACTIVE_0 UINT8_C(0x02) +#define BMA400_INT_OPEN_DRIVE_ACTIVE_1 UINT8_C(0x03) /* Interrupt Assertion status macros */ -#define BMA400_WAKEUP_INT_ASSERTED UINT16_C(0x0001) -#define BMA400_ORIENT_CH_INT_ASSERTED UINT16_C(0x0002) -#define BMA400_GEN1_INT_ASSERTED UINT16_C(0x0004) -#define BMA400_GEN2_INT_ASSERTED UINT16_C(0x0008) -#define BMA400_INT_OVERRUN_ASSERTED UINT16_C(0x0010) -#define BMA400_FIFO_FULL_INT_ASSERTED UINT16_C(0x0020) -#define BMA400_FIFO_WM_INT_ASSERTED UINT16_C(0x0040) -#define BMA400_DRDY_INT_ASSERTED UINT16_C(0x0080) -#define BMA400_STEP_INT_ASSERTED UINT16_C(0x0300) -#define BMA400_S_TAP_INT_ASSERTED UINT16_C(0x0400) -#define BMA400_D_TAP_INT_ASSERTED UINT16_C(0x0800) -#define BMA400_ACT_CH_X_ASSERTED UINT16_C(0x2000) -#define BMA400_ACT_CH_Y_ASSERTED UINT16_C(0x4000) -#define BMA400_ACT_CH_Z_ASSERTED UINT16_C(0x8000) +#define BMA400_ASSERTED_WAKEUP_INT UINT16_C(0x0001) +#define BMA400_ASSERTED_ORIENT_CH UINT16_C(0x0002) +#define BMA400_ASSERTED_GEN1_INT UINT16_C(0x0004) +#define BMA400_ASSERTED_GEN2_INT UINT16_C(0x0008) +#define BMA400_ASSERTED_INT_OVERRUN UINT16_C(0x0010) +#define BMA400_ASSERTED_FIFO_FULL_INT UINT16_C(0x0020) +#define BMA400_ASSERTED_FIFO_WM_INT UINT16_C(0x0040) +#define BMA400_ASSERTED_DRDY_INT UINT16_C(0x0080) +#define BMA400_ASSERTED_STEP_INT UINT16_C(0x0300) +#define BMA400_ASSERTED_S_TAP_INT UINT16_C(0x0400) +#define BMA400_ASSERTED_D_TAP_INT UINT16_C(0x0800) +#define BMA400_ASSERTED_ACT_CH_X UINT16_C(0x2000) +#define BMA400_ASSERTED_ACT_CH_Y UINT16_C(0x4000) +#define BMA400_ASSERTED_ACT_CH_Z UINT16_C(0x8000) /* Generic interrupt criterion_sel configuration macros */ -#define BMA400_ACTIVITY_INT UINT8_C(0x01) -#define BMA400_INACTIVITY_INT UINT8_C(0x00) +#define BMA400_ACTIVITY_INT UINT8_C(0x01) +#define BMA400_INACTIVITY_INT UINT8_C(0x00) /* Generic interrupt axes evaluation logic configuration macros */ -#define BMA400_ALL_AXES_INT UINT8_C(0x01) -#define BMA400_ANY_AXES_INT UINT8_C(0x00) +#define BMA400_ALL_AXES_INT UINT8_C(0x01) +#define BMA400_ANY_AXES_INT UINT8_C(0x00) /* Generic interrupt hysteresis configuration macros */ -#define BMA400_HYST_0_MG UINT8_C(0x00) -#define BMA400_HYST_24_MG UINT8_C(0x01) -#define BMA400_HYST_48_MG UINT8_C(0x02) -#define BMA400_HYST_96_MG UINT8_C(0x03) +#define BMA400_HYST_0_MG UINT8_C(0x00) +#define BMA400_HYST_24_MG UINT8_C(0x01) +#define BMA400_HYST_48_MG UINT8_C(0x02) +#define BMA400_HYST_96_MG UINT8_C(0x03) /* BMA400 Register Address */ -#define BMA400_CHIP_ID_ADDR UINT8_C(0x00) -#define BMA400_STATUS_ADDR UINT8_C(0x03) -#define BMA400_ACCEL_DATA_ADDR UINT8_C(0x04) -#define BMA400_INT_STAT0_ADDR UINT8_C(0x0E) -#define BMA400_TEMP_DATA_ADDR UINT8_C(0x11) -#define BMA400_FIFO_LENGTH_ADDR UINT8_C(0x12) -#define BMA400_FIFO_DATA_ADDR UINT8_C(0x14) -#define BMA400_STEP_CNT_0_ADDR UINT8_C(0x15) -#define BMA400_ACCEL_CONFIG_0_ADDR UINT8_C(0x19) -#define BMA400_ACCEL_CONFIG_1_ADDR UINT8_C(0x1A) -#define BMA400_ACCEL_CONFIG_2_ADDR UINT8_C(0x1B) -#define BMA400_INT_CONF_0_ADDR UINT8_C(0x1F) -#define BMA400_INT_12_IO_CTRL_ADDR UINT8_C(0x24) -#define BMA400_INT_MAP_ADDR UINT8_C(0x21) -#define BMA400_FIFO_CONFIG_0_ADDR UINT8_C(0x26) -#define BMA400_FIFO_READ_EN_ADDR UINT8_C(0x29) -#define BMA400_AUTO_LOW_POW_0_ADDR UINT8_C(0x2A) -#define BMA400_AUTO_LOW_POW_1_ADDR UINT8_C(0x2B) -#define BMA400_AUTOWAKEUP_0_ADDR UINT8_C(0x2C) -#define BMA400_AUTOWAKEUP_1_ADDR UINT8_C(0x2D) -#define BMA400_WAKEUP_INT_CONF_0_ADDR UINT8_C(0x2F) -#define BMA400_ORIENTCH_INT_CONFIG_ADDR UINT8_C(0x35) -#define BMA400_GEN1_INT_CONFIG_ADDR UINT8_C(0x3F) -#define BMA400_GEN2_INT_CONFIG_ADDR UINT8_C(0x4A) -#define BMA400_ACT_CH_CONFIG_0_ADDR UINT8_C(0x55) -#define BMA400_TAP_CONFIG_ADDR UINT8_C(0x57) -#define BMA400_SELF_TEST_ADDR UINT8_C(0x7D) -#define BMA400_COMMAND_REG_ADDR UINT8_C(0x7E) +#define BMA400_REG_CHIP_ID UINT8_C(0x00) +#define BMA400_REG_STATUS UINT8_C(0x03) +#define BMA400_REG_ACCEL_DATA UINT8_C(0x04) +#define BMA400_REG_INT_STAT0 UINT8_C(0x0E) +#define BMA400_REG_TEMP_DATA UINT8_C(0x11) +#define BMA400_REG_FIFO_LENGTH UINT8_C(0x12) +#define BMA400_REG_FIFO_DATA UINT8_C(0x14) +#define BMA400_REG_STEP_CNT_0 UINT8_C(0x15) +#define BMA400_REG_ACCEL_CONFIG_0 UINT8_C(0x19) +#define BMA400_REG_ACCEL_CONFIG_1 UINT8_C(0x1A) +#define BMA400_REG_ACCEL_CONFIG_2 UINT8_C(0x1B) +#define BMA400_REG_INT_CONF_0 UINT8_C(0x1F) +#define BMA400_REG_INT_12_IO_CTRL UINT8_C(0x24) +#define BMA400_REG_INT_MAP UINT8_C(0x21) +#define BMA400_REG_FIFO_CONFIG_0 UINT8_C(0x26) +#define BMA400_REG_FIFO_READ_EN UINT8_C(0x29) +#define BMA400_REG_AUTO_LOW_POW_0 UINT8_C(0x2A) +#define BMA400_REG_AUTO_LOW_POW_1 UINT8_C(0x2B) +#define BMA400_REG_AUTOWAKEUP_0 UINT8_C(0x2C) +#define BMA400_REG_AUTOWAKEUP_1 UINT8_C(0x2D) +#define BMA400_REG_WAKEUP_INT_CONF_0 UINT8_C(0x2F) +#define BMA400_REG_ORIENTCH_INT_CONFIG UINT8_C(0x35) +#define BMA400_REG_GEN1_INT_CONFIG UINT8_C(0x3F) +#define BMA400_REG_GEN2_INT_CONFIG UINT8_C(0x4A) +#define BMA400_REG_ACT_CH_CONFIG_0 UINT8_C(0x55) +#define BMA400_REG_TAP_CONFIG UINT8_C(0x57) +#define BMA400_REG_SELF_TEST UINT8_C(0x7D) +#define BMA400_REG_COMMAND UINT8_C(0x7E) /* BMA400 Command register */ -#define BMA400_SOFT_RESET_CMD UINT8_C(0xB6) -#define BMA400_FIFO_FLUSH_CMD UINT8_C(0xB0) +#define BMA400_SOFT_RESET_CMD UINT8_C(0xB6) +#define BMA400_FIFO_FLUSH_CMD UINT8_C(0xB0) /* BMA400 Delay definitions */ -#define BMA400_SOFT_RESET_DELAY_MS UINT8_C(5) -#define BMA400_SELF_TEST_DELAY_MS UINT8_C(7) -#define BMA400_SELF_TEST_DATA_READ_MS UINT8_C(50) +#define BMA400_DELAY_US_SOFT_RESET UINT8_C(5000) +#define BMA400_DELAY_US_SELF_TEST UINT8_C(7000) +#define BMA400_DELAY_US_SELF_TEST_DATA_READ UINT8_C(50000) /* Interface selection macro */ -#define BMA400_SPI_WR_MASK UINT8_C(0x7F) -#define BMA400_SPI_RD_MASK UINT8_C(0x80) +#define BMA400_SPI_WR_MASK UINT8_C(0x7F) +#define BMA400_SPI_RD_MASK UINT8_C(0x80) /* UTILITY MACROS */ -#define BMA400_SET_LOW_BYTE UINT16_C(0x00FF) -#define BMA400_SET_HIGH_BYTE UINT16_C(0xFF00) +#define BMA400_SET_LOW_BYTE UINT16_C(0x00FF) +#define BMA400_SET_HIGH_BYTE UINT16_C(0xFF00) /* Interrupt mapping selection */ -#define BMA400_DATA_READY_INT_MAP UINT8_C(0x01) -#define BMA400_FIFO_WM_INT_MAP UINT8_C(0x02) -#define BMA400_FIFO_FULL_INT_MAP UINT8_C(0x03) -#define BMA400_GEN2_INT_MAP UINT8_C(0x04) -#define BMA400_GEN1_INT_MAP UINT8_C(0x05) -#define BMA400_ORIENT_CH_INT_MAP UINT8_C(0x06) -#define BMA400_WAKEUP_INT_MAP UINT8_C(0x07) -#define BMA400_ACT_CH_INT_MAP UINT8_C(0x08) -#define BMA400_TAP_INT_MAP UINT8_C(0x09) -#define BMA400_STEP_INT_MAP UINT8_C(0x0A) -#define BMA400_INT_OVERRUN_MAP UINT8_C(0x0B) +#define BMA400_DATA_READY_INT_MAP UINT8_C(0x01) +#define BMA400_FIFO_WM_INT_MAP UINT8_C(0x02) +#define BMA400_FIFO_FULL_INT_MAP UINT8_C(0x03) +#define BMA400_GEN2_INT_MAP UINT8_C(0x04) +#define BMA400_GEN1_INT_MAP UINT8_C(0x05) +#define BMA400_ORIENT_CH_INT_MAP UINT8_C(0x06) +#define BMA400_WAKEUP_INT_MAP UINT8_C(0x07) +#define BMA400_ACT_CH_INT_MAP UINT8_C(0x08) +#define BMA400_TAP_INT_MAP UINT8_C(0x09) +#define BMA400_STEP_INT_MAP UINT8_C(0x0A) +#define BMA400_INT_OVERRUN_MAP UINT8_C(0x0B) /* BMA400 FIFO configurations */ -#define BMA400_FIFO_AUTO_FLUSH UINT8_C(0x01) -#define BMA400_FIFO_STOP_ON_FULL UINT8_C(0x02) -#define BMA400_FIFO_TIME_EN UINT8_C(0x04) -#define BMA400_FIFO_DATA_SRC UINT8_C(0x08) -#define BMA400_FIFO_8_BIT_EN UINT8_C(0x10) -#define BMA400_FIFO_X_EN UINT8_C(0x20) -#define BMA400_FIFO_Y_EN UINT8_C(0x40) -#define BMA400_FIFO_Z_EN UINT8_C(0x80) +#define BMA400_FIFO_AUTO_FLUSH UINT8_C(0x01) +#define BMA400_FIFO_STOP_ON_FULL UINT8_C(0x02) +#define BMA400_FIFO_TIME_EN UINT8_C(0x04) +#define BMA400_FIFO_DATA_SRC UINT8_C(0x08) +#define BMA400_FIFO_8_BIT_EN UINT8_C(0x10) +#define BMA400_FIFO_X_EN UINT8_C(0x20) +#define BMA400_FIFO_Y_EN UINT8_C(0x40) +#define BMA400_FIFO_Z_EN UINT8_C(0x80) /* BMA400 FIFO data configurations */ -#define BMA400_FIFO_EN_X UINT8_C(0x01) -#define BMA400_FIFO_EN_Y UINT8_C(0x02) -#define BMA400_FIFO_EN_Z UINT8_C(0x04) -#define BMA400_FIFO_EN_XY UINT8_C(0x03) -#define BMA400_FIFO_EN_YZ UINT8_C(0x06) -#define BMA400_FIFO_EN_XZ UINT8_C(0x05) -#define BMA400_FIFO_EN_XYZ UINT8_C(0x07) +#define BMA400_FIFO_EN_X UINT8_C(0x01) +#define BMA400_FIFO_EN_Y UINT8_C(0x02) +#define BMA400_FIFO_EN_Z UINT8_C(0x04) +#define BMA400_FIFO_EN_XY UINT8_C(0x03) +#define BMA400_FIFO_EN_YZ UINT8_C(0x06) +#define BMA400_FIFO_EN_XZ UINT8_C(0x05) +#define BMA400_FIFO_EN_XYZ UINT8_C(0x07) /* BMA400 Self test configurations */ -#define BMA400_DISABLE_SELF_TEST UINT8_C(0x00) -#define BMA400_ENABLE_POSITIVE_SELF_TEST UINT8_C(0x07) -#define BMA400_ENABLE_NEGATIVE_SELF_TEST UINT8_C(0x0F) +#define BMA400_SELF_TEST_DISABLE UINT8_C(0x00) +#define BMA400_SELF_TEST_ENABLE_POSITIVE UINT8_C(0x07) +#define BMA400_SELF_TEST_ENABLE_NEGATIVE UINT8_C(0x0F) /* BMA400 FIFO data masks */ -#define BMA400_FIFO_HEADER_MASK UINT8_C(0x3E) -#define BMA400_FIFO_BYTES_OVERREAD UINT8_C(25) -#define BMA400_AWIDTH_MASK UINT8_C(0xEF) -#define BMA400_FIFO_DATA_EN_MASK UINT8_C(0x0E) +#define BMA400_FIFO_HEADER_MASK UINT8_C(0x3E) +#define BMA400_FIFO_BYTES_OVERREAD UINT8_C(25) +#define BMA400_AWIDTH_MASK UINT8_C(0xEF) +#define BMA400_FIFO_DATA_EN_MASK UINT8_C(0x0E) /* BMA400 Step status field - Activity status */ -#define BMA400_STILL_ACT UINT8_C(0x00) -#define BMA400_WALK_ACT UINT8_C(0x01) -#define BMA400_RUN_ACT UINT8_C(0x02) +#define BMA400_STILL_ACT UINT8_C(0x00) +#define BMA400_WALK_ACT UINT8_C(0x01) +#define BMA400_RUN_ACT UINT8_C(0x02) /* It is inserted when FIFO_CONFIG0.fifo_data_src * is changed during the FIFO read */ -#define BMA400_FIFO_CONF0_CHANGE UINT8_C(0x01) +#define BMA400_FIFO_CONF0_CHANGE UINT8_C(0x01) /* It is inserted when ACC_CONFIG0.filt1_bw * is changed during the FIFO read */ -#define BMA400_ACCEL_CONF0_CHANGE UINT8_C(0x02) +#define BMA400_ACCEL_CONF0_CHANGE UINT8_C(0x02) /* It is inserted when ACC_CONFIG1.acc_range * acc_odr or osr is changed during the FIFO read */ -#define BMA400_ACCEL_CONF1_CHANGE UINT8_C(0x04) +#define BMA400_ACCEL_CONF1_CHANGE UINT8_C(0x04) /* Accel width setting either 12/8 bit mode */ -#define BMA400_12_BIT_FIFO_DATA UINT8_C(0x01) -#define BMA400_8_BIT_FIFO_DATA UINT8_C(0x00) +#define BMA400_12_BIT_FIFO_DATA UINT8_C(0x01) +#define BMA400_8_BIT_FIFO_DATA UINT8_C(0x00) /* BMA400 FIFO header configurations */ -#define BMA400_FIFO_SENSOR_TIME UINT8_C(0xA0) -#define BMA400_FIFO_EMPTY_FRAME UINT8_C(0x80) -#define BMA400_FIFO_CONTROL_FRAME UINT8_C(0x48) -#define BMA400_FIFO_XYZ_ENABLE UINT8_C(0x8E) -#define BMA400_FIFO_X_ENABLE UINT8_C(0x82) -#define BMA400_FIFO_Y_ENABLE UINT8_C(0x84) -#define BMA400_FIFO_Z_ENABLE UINT8_C(0x88) -#define BMA400_FIFO_XY_ENABLE UINT8_C(0x86) -#define BMA400_FIFO_YZ_ENABLE UINT8_C(0x8C) -#define BMA400_FIFO_XZ_ENABLE UINT8_C(0x8A) +#define BMA400_FIFO_SENSOR_TIME UINT8_C(0xA0) +#define BMA400_FIFO_EMPTY_FRAME UINT8_C(0x80) +#define BMA400_FIFO_CONTROL_FRAME UINT8_C(0x48) +#define BMA400_FIFO_XYZ_ENABLE UINT8_C(0x8E) +#define BMA400_FIFO_X_ENABLE UINT8_C(0x82) +#define BMA400_FIFO_Y_ENABLE UINT8_C(0x84) +#define BMA400_FIFO_Z_ENABLE UINT8_C(0x88) +#define BMA400_FIFO_XY_ENABLE UINT8_C(0x86) +#define BMA400_FIFO_YZ_ENABLE UINT8_C(0x8C) +#define BMA400_FIFO_XZ_ENABLE UINT8_C(0x8A) /* BMA400 bit mask definitions */ -#define BMA400_POWER_MODE_STATUS_MSK UINT8_C(0x06) -#define BMA400_POWER_MODE_STATUS_POS UINT8_C(1) +#define BMA400_POWER_MODE_STATUS_MSK UINT8_C(0x06) +#define BMA400_POWER_MODE_STATUS_POS UINT8_C(1) -#define BMA400_POWER_MODE_MSK UINT8_C(0x03) +#define BMA400_POWER_MODE_MSK UINT8_C(0x03) -#define BMA400_ACCEL_ODR_MSK UINT8_C(0x0F) +#define BMA400_ACCEL_ODR_MSK UINT8_C(0x0F) -#define BMA400_ACCEL_RANGE_MSK UINT8_C(0xC0) -#define BMA400_ACCEL_RANGE_POS UINT8_C(6) +#define BMA400_ACCEL_RANGE_MSK UINT8_C(0xC0) +#define BMA400_ACCEL_RANGE_POS UINT8_C(6) -#define BMA400_DATA_FILTER_MSK UINT8_C(0x0C) -#define BMA400_DATA_FILTER_POS UINT8_C(2) +#define BMA400_DATA_FILTER_MSK UINT8_C(0x0C) +#define BMA400_DATA_FILTER_POS UINT8_C(2) -#define BMA400_OSR_MSK UINT8_C(0x30) -#define BMA400_OSR_POS UINT8_C(4) +#define BMA400_OSR_MSK UINT8_C(0x30) +#define BMA400_OSR_POS UINT8_C(4) -#define BMA400_OSR_LP_MSK UINT8_C(0x60) -#define BMA400_OSR_LP_POS UINT8_C(5) +#define BMA400_OSR_LP_MSK UINT8_C(0x60) +#define BMA400_OSR_LP_POS UINT8_C(5) -#define BMA400_FILT_1_BW_MSK UINT8_C(0x80) -#define BMA400_FILT_1_BW_POS UINT8_C(7) +#define BMA400_FILT_1_BW_MSK UINT8_C(0x80) +#define BMA400_FILT_1_BW_POS UINT8_C(7) -#define BMA400_WAKEUP_TIMEOUT_MSK UINT8_C(0x04) -#define BMA400_WAKEUP_TIMEOUT_POS UINT8_C(2) +#define BMA400_WAKEUP_TIMEOUT_MSK UINT8_C(0x04) +#define BMA400_WAKEUP_TIMEOUT_POS UINT8_C(2) -#define BMA400_WAKEUP_THRES_LSB_MSK UINT16_C(0x000F) +#define BMA400_WAKEUP_THRES_LSB_MSK UINT16_C(0x000F) -#define BMA400_WAKEUP_THRES_MSB_MSK UINT16_C(0x0FF0) -#define BMA400_WAKEUP_THRES_MSB_POS UINT8_C(4) +#define BMA400_WAKEUP_THRES_MSB_MSK UINT16_C(0x0FF0) +#define BMA400_WAKEUP_THRES_MSB_POS UINT8_C(4) -#define BMA400_WAKEUP_TIMEOUT_THRES_MSK UINT8_C(0xF0) -#define BMA400_WAKEUP_TIMEOUT_THRES_POS UINT8_C(4) +#define BMA400_WAKEUP_TIMEOUT_THRES_MSK UINT8_C(0xF0) +#define BMA400_WAKEUP_TIMEOUT_THRES_POS UINT8_C(4) -#define BMA400_WAKEUP_INTERRUPT_MSK UINT8_C(0x02) -#define BMA400_WAKEUP_INTERRUPT_POS UINT8_C(1) +#define BMA400_WAKEUP_INTERRUPT_MSK UINT8_C(0x02) +#define BMA400_WAKEUP_INTERRUPT_POS UINT8_C(1) -#define BMA400_AUTO_LOW_POW_MSK UINT8_C(0x0F) +#define BMA400_AUTO_LOW_POW_MSK UINT8_C(0x0F) -#define BMA400_AUTO_LP_THRES_MSK UINT16_C(0x0FF0) -#define BMA400_AUTO_LP_THRES_POS UINT8_C(4) +#define BMA400_AUTO_LP_THRES_MSK UINT16_C(0x0FF0) +#define BMA400_AUTO_LP_THRES_POS UINT8_C(4) -#define BMA400_AUTO_LP_THRES_LSB_MSK UINT16_C(0x000F) +#define BMA400_AUTO_LP_THRES_LSB_MSK UINT16_C(0x000F) -#define BMA400_WKUP_REF_UPDATE_MSK UINT8_C(0x03) +#define BMA400_WKUP_REF_UPDATE_MSK UINT8_C(0x03) -#define BMA400_AUTO_LP_TIMEOUT_LSB_MSK UINT8_C(0xF0) -#define BMA400_AUTO_LP_TIMEOUT_LSB_POS UINT8_C(4) +#define BMA400_AUTO_LP_TIMEOUT_LSB_MSK UINT8_C(0xF0) +#define BMA400_AUTO_LP_TIMEOUT_LSB_POS UINT8_C(4) -#define BMA400_SAMPLE_COUNT_MSK UINT8_C(0x1C) -#define BMA400_SAMPLE_COUNT_POS UINT8_C(2) +#define BMA400_SAMPLE_COUNT_MSK UINT8_C(0x1C) +#define BMA400_SAMPLE_COUNT_POS UINT8_C(2) -#define BMA400_WAKEUP_EN_AXES_MSK UINT8_C(0xE0) -#define BMA400_WAKEUP_EN_AXES_POS UINT8_C(5) +#define BMA400_WAKEUP_EN_AXES_MSK UINT8_C(0xE0) +#define BMA400_WAKEUP_EN_AXES_POS UINT8_C(5) -#define BMA400_TAP_AXES_EN_MSK UINT8_C(0x18) -#define BMA400_TAP_AXES_EN_POS UINT8_C(3) +#define BMA400_TAP_AXES_EN_MSK UINT8_C(0x18) +#define BMA400_TAP_AXES_EN_POS UINT8_C(3) -#define BMA400_TAP_QUIET_DT_MSK UINT8_C(0x30) -#define BMA400_TAP_QUIET_DT_POS UINT8_C(4) +#define BMA400_TAP_QUIET_DT_MSK UINT8_C(0x30) +#define BMA400_TAP_QUIET_DT_POS UINT8_C(4) -#define BMA400_TAP_QUIET_MSK UINT8_C(0x0C) -#define BMA400_TAP_QUIET_POS UINT8_C(2) +#define BMA400_TAP_QUIET_MSK UINT8_C(0x0C) +#define BMA400_TAP_QUIET_POS UINT8_C(2) -#define BMA400_TAP_TICS_TH_MSK UINT8_C(0x03) +#define BMA400_TAP_TICS_TH_MSK UINT8_C(0x03) -#define BMA400_TAP_SENSITIVITY_MSK UINT8_C(0X07) +#define BMA400_TAP_SENSITIVITY_MSK UINT8_C(0X07) -#define BMA400_ACT_CH_AXES_EN_MSK UINT8_C(0xE0) -#define BMA400_ACT_CH_AXES_EN_POS UINT8_C(5) +#define BMA400_ACT_CH_AXES_EN_MSK UINT8_C(0xE0) +#define BMA400_ACT_CH_AXES_EN_POS UINT8_C(5) -#define BMA400_ACT_CH_DATA_SRC_MSK UINT8_C(0x10) -#define BMA400_ACT_CH_DATA_SRC_POS UINT8_C(4) +#define BMA400_ACT_CH_DATA_SRC_MSK UINT8_C(0x10) +#define BMA400_ACT_CH_DATA_SRC_POS UINT8_C(4) -#define BMA400_ACT_CH_NPTS_MSK UINT8_C(0x0F) +#define BMA400_ACT_CH_NPTS_MSK UINT8_C(0x0F) -#define BMA400_INT_AXES_EN_MSK UINT8_C(0xE0) -#define BMA400_INT_AXES_EN_POS UINT8_C(5) +#define BMA400_INT_AXES_EN_MSK UINT8_C(0xE0) +#define BMA400_INT_AXES_EN_POS UINT8_C(5) -#define BMA400_INT_DATA_SRC_MSK UINT8_C(0x10) -#define BMA400_INT_DATA_SRC_POS UINT8_C(4) +#define BMA400_INT_DATA_SRC_MSK UINT8_C(0x10) +#define BMA400_INT_DATA_SRC_POS UINT8_C(4) -#define BMA400_INT_REFU_MSK UINT8_C(0x0C) -#define BMA400_INT_REFU_POS UINT8_C(2) +#define BMA400_INT_REFU_MSK UINT8_C(0x0C) +#define BMA400_INT_REFU_POS UINT8_C(2) -#define BMA400_INT_HYST_MSK UINT8_C(0x03) -#define BMA400_STABILITY_MODE_MSK UINT8_C(0x03) +#define BMA400_INT_HYST_MSK UINT8_C(0x03) -#define BMA400_GEN_INT_COMB_MSK UINT8_C(0x01) +#define BMA400_GEN_INT_COMB_MSK UINT8_C(0x01) -#define BMA400_GEN_INT_CRITERION_MSK UINT8_C(0x02) -#define BMA400_GEN_INT_CRITERION_POS UINT8_C(0x01) +#define BMA400_GEN_INT_CRITERION_MSK UINT8_C(0x02) +#define BMA400_GEN_INT_CRITERION_POS UINT8_C(0x01) -#define BMA400_INT_PIN1_CONF_MSK UINT8_C(0x06) -#define BMA400_INT_PIN1_CONF_POS UINT8_C(1) +#define BMA400_INT_PIN1_CONF_MSK UINT8_C(0x06) +#define BMA400_INT_PIN1_CONF_POS UINT8_C(1) -#define BMA400_INT_PIN2_CONF_MSK UINT8_C(0x60) -#define BMA400_INT_PIN2_CONF_POS UINT8_C(5) +#define BMA400_INT_PIN2_CONF_MSK UINT8_C(0x60) +#define BMA400_INT_PIN2_CONF_POS UINT8_C(5) -#define BMA400_INT_STATUS_MSK UINT8_C(0xE0) -#define BMA400_INT_STATUS_POS UINT8_C(5) +#define BMA400_INT_STATUS_MSK UINT8_C(0xE0) +#define BMA400_INT_STATUS_POS UINT8_C(5) -#define BMA400_EN_DRDY_MSK UINT8_C(0x80) -#define BMA400_EN_DRDY_POS UINT8_C(7) +#define BMA400_EN_DRDY_MSK UINT8_C(0x80) +#define BMA400_EN_DRDY_POS UINT8_C(7) -#define BMA400_EN_FIFO_WM_MSK UINT8_C(0x40) -#define BMA400_EN_FIFO_WM_POS UINT8_C(6) +#define BMA400_EN_FIFO_WM_MSK UINT8_C(0x40) +#define BMA400_EN_FIFO_WM_POS UINT8_C(6) -#define BMA400_EN_FIFO_FULL_MSK UINT8_C(0x20) -#define BMA400_EN_FIFO_FULL_POS UINT8_C(5) +#define BMA400_EN_FIFO_FULL_MSK UINT8_C(0x20) +#define BMA400_EN_FIFO_FULL_POS UINT8_C(5) -#define BMA400_EN_INT_OVERRUN_MSK UINT8_C(0x10) -#define BMA400_EN_INT_OVERRUN_POS UINT8_C(4) +#define BMA400_EN_INT_OVERRUN_MSK UINT8_C(0x10) +#define BMA400_EN_INT_OVERRUN_POS UINT8_C(4) -#define BMA400_EN_GEN2_MSK UINT8_C(0x08) -#define BMA400_EN_GEN2_POS UINT8_C(3) +#define BMA400_EN_GEN2_MSK UINT8_C(0x08) +#define BMA400_EN_GEN2_POS UINT8_C(3) -#define BMA400_EN_GEN1_MSK UINT8_C(0x04) -#define BMA400_EN_GEN1_POS UINT8_C(2) +#define BMA400_EN_GEN1_MSK UINT8_C(0x04) +#define BMA400_EN_GEN1_POS UINT8_C(2) -#define BMA400_EN_ORIENT_CH_MSK UINT8_C(0x02) -#define BMA400_EN_ORIENT_CH_POS UINT8_C(1) +#define BMA400_EN_ORIENT_CH_MSK UINT8_C(0x02) +#define BMA400_EN_ORIENT_CH_POS UINT8_C(1) -#define BMA400_EN_LATCH_MSK UINT8_C(0x80) -#define BMA400_EN_LATCH_POS UINT8_C(7) +#define BMA400_EN_LATCH_MSK UINT8_C(0x80) +#define BMA400_EN_LATCH_POS UINT8_C(7) -#define BMA400_EN_ACTCH_MSK UINT8_C(0x10) -#define BMA400_EN_ACTCH_POS UINT8_C(4) +#define BMA400_EN_ACTCH_MSK UINT8_C(0x10) +#define BMA400_EN_ACTCH_POS UINT8_C(4) -#define BMA400_EN_D_TAP_MSK UINT8_C(0x08) -#define BMA400_EN_D_TAP_POS UINT8_C(3) +#define BMA400_EN_D_TAP_MSK UINT8_C(0x08) +#define BMA400_EN_D_TAP_POS UINT8_C(3) -#define BMA400_EN_S_TAP_MSK UINT8_C(0x04) -#define BMA400_EN_S_TAP_POS UINT8_C(2) +#define BMA400_EN_S_TAP_MSK UINT8_C(0x04) +#define BMA400_EN_S_TAP_POS UINT8_C(2) -#define BMA400_EN_STEP_INT_MSK UINT8_C(0x01) +#define BMA400_EN_STEP_INT_MSK UINT8_C(0x01) -#define BMA400_STEP_MAP_INT2_MSK UINT8_C(0x10) -#define BMA400_STEP_MAP_INT2_POS UINT8_C(4) +#define BMA400_STEP_MAP_INT2_MSK UINT8_C(0x10) +#define BMA400_STEP_MAP_INT2_POS UINT8_C(4) -#define BMA400_EN_WAKEUP_INT_MSK UINT8_C(0x01) +#define BMA400_EN_WAKEUP_INT_MSK UINT8_C(0x01) -#define BMA400_TAP_MAP_INT1_MSK UINT8_C(0x04) -#define BMA400_TAP_MAP_INT1_POS UINT8_C(2) +#define BMA400_TAP_MAP_INT1_MSK UINT8_C(0x04) +#define BMA400_TAP_MAP_INT1_POS UINT8_C(2) -#define BMA400_TAP_MAP_INT2_MSK UINT8_C(0x40) -#define BMA400_TAP_MAP_INT2_POS UINT8_C(6) +#define BMA400_TAP_MAP_INT2_MSK UINT8_C(0x40) +#define BMA400_TAP_MAP_INT2_POS UINT8_C(6) -#define BMA400_ACTCH_MAP_INT1_MSK UINT8_C(0x08) -#define BMA400_ACTCH_MAP_INT1_POS UINT8_C(3) +#define BMA400_ACTCH_MAP_INT1_MSK UINT8_C(0x08) +#define BMA400_ACTCH_MAP_INT1_POS UINT8_C(3) -#define BMA400_ACTCH_MAP_INT2_MSK UINT8_C(0x80) -#define BMA400_ACTCH_MAP_INT2_POS UINT8_C(7) +#define BMA400_ACTCH_MAP_INT2_MSK UINT8_C(0x80) +#define BMA400_ACTCH_MAP_INT2_POS UINT8_C(7) -#define BMA400_FIFO_BYTES_CNT_MSK UINT8_C(0x07) +#define BMA400_FIFO_BYTES_CNT_MSK UINT8_C(0x07) -#define BMA400_FIFO_TIME_EN_MSK UINT8_C(0x04) -#define BMA400_FIFO_TIME_EN_POS UINT8_C(2) +#define BMA400_FIFO_TIME_EN_MSK UINT8_C(0x04) +#define BMA400_FIFO_TIME_EN_POS UINT8_C(2) -#define BMA400_FIFO_AXES_EN_MSK UINT8_C(0xE0) -#define BMA400_FIFO_AXES_EN_POS UINT8_C(5) +#define BMA400_FIFO_AXES_EN_MSK UINT8_C(0xE0) +#define BMA400_FIFO_AXES_EN_POS UINT8_C(5) -#define BMA400_FIFO_8_BIT_EN_MSK UINT8_C(0x10) -#define BMA400_FIFO_8_BIT_EN_POS UINT8_C(4) +#define BMA400_FIFO_8_BIT_EN_MSK UINT8_C(0x10) +#define BMA400_FIFO_8_BIT_EN_POS UINT8_C(4) /* Macro to SET and GET BITS of a register */ #define BMA400_SET_BITS(reg_data, bitname, data) \ ((reg_data & ~(bitname##_MSK)) | \ ((data << bitname##_POS) & bitname##_MSK)) -#define BMA400_GET_BITS(reg_data, bitname) ((reg_data & (bitname##_MSK)) >> \ - (bitname##_POS)) +#define BMA400_GET_BITS(reg_data, bitname) ((reg_data & (bitname##_MSK)) >> \ + (bitname##_POS)) #define BMA400_SET_BITS_POS_0(reg_data, bitname, data) \ ((reg_data & ~(bitname##_MSK)) | \ (data & bitname##_MSK)) -#define BMA400_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK)) +#define BMA400_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK)) -#define BMA400_SET_BIT_VAL_0(reg_data, bitname) (reg_data & ~(bitname##_MSK)) +#define BMA400_SET_BIT_VAL_0(reg_data, bitname) (reg_data & ~(bitname##_MSK)) -#define BMA400_GET_LSB(var) (uint8_t)(var & BMA400_SET_LOW_BYTE) -#define BMA400_GET_MSB(var) (uint8_t)((var & BMA400_SET_HIGH_BYTE) >> 8) +#define BMA400_GET_LSB(var) (uint8_t)(var & BMA400_SET_LOW_BYTE) +#define BMA400_GET_MSB(var) (uint8_t)((var & BMA400_SET_HIGH_BYTE) >> 8) /* Macros used for Self test */ -/* Self-test: Resulting minimum difference signal in mg for BMA400 */ -#define BMA400_ST_ACC_X_AXIS_SIGNAL_DIFF UINT16_C(1500) -#define BMA400_ST_ACC_Y_AXIS_SIGNAL_DIFF UINT16_C(1200) -#define BMA400_ST_ACC_Z_AXIS_SIGNAL_DIFF UINT16_C(250) + +/* + * Derivation of values obtained by : + * Signal_Diff = ( (LSB/g value based on Accel Range) * (Minimum difference signal value) ) / 1000 + */ + +/* Self-test: Resulting minimum difference signal for BMA400 with Range 4G */ + +#define BMA400_ST_ACC_X_AXIS_SIGNAL_DIFF UINT16_C(768) +#define BMA400_ST_ACC_Y_AXIS_SIGNAL_DIFF UINT16_C(614) +#define BMA400_ST_ACC_Z_AXIS_SIGNAL_DIFF UINT16_C(128) /* * Interface selection enums @@ -655,24 +672,54 @@ enum bma400_intf { /* SPI interface */ BMA400_SPI_INTF, - /* I2C interface */ BMA400_I2C_INTF }; -/* - * Bus communication function pointer which should be mapped to - * the platform specific read and write functions of the user +/********************************************************* */ +/*! Function Pointers */ +/********************************************************* */ + +/*! + * @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 int8_t (*bma400_com_fptr_t)(void *intf_ptr, uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, - * uint16_t length); +typedef BMA400_INTF_RET_TYPE (*bma400_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 int8_t (*bma400_com_fptr_t)(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); - -/* Delay function pointer */ -typedef void (*bma400_delay_fptr_t)(uint32_t period); +typedef BMA400_INTF_RET_TYPE (*bma400_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 (*bma400_delay_us_fptr_t)(uint32_t period, void *intf_ptr); /* * Sensor selection enums @@ -990,14 +1037,6 @@ struct bma400_orient_int_conf */ uint8_t orient_int_dur; - /* Stability check conditions - * Assignable macros : - * - BMA400_STABILITY_DISABLED - * - BMA400_STABILITY_ACC_FILT_2 - * - BMA400_STABILITY_ACC_FILT_LP - */ - uint8_t stability_mode; - /* Reference value for x axes */ uint16_t orient_ref_x; @@ -1263,37 +1302,26 @@ struct bma400_sensor_data enum bma400_int_type { /* DRDY interrupt */ BMA400_DRDY_INT_EN, - /* FIFO watermark interrupt */ BMA400_FIFO_WM_INT_EN, - /* FIFO full interrupt */ BMA400_FIFO_FULL_INT_EN, - /* Generic interrupt 2 */ BMA400_GEN2_INT_EN, - /* Generic interrupt 1 */ BMA400_GEN1_INT_EN, - /* Orient change interrupt */ BMA400_ORIENT_CHANGE_INT_EN, - /* Latch interrupt */ BMA400_LATCH_INT_EN, - /* Activity change interrupt */ BMA400_ACTIVITY_CHANGE_INT_EN, - /* Double tap interrupt */ BMA400_DOUBLE_TAP_INT_EN, - /* Single tap interrupt */ BMA400_SINGLE_TAP_INT_EN, - /* Step interrupt */ BMA400_STEP_COUNTER_INT_EN, - /* Auto wakeup interrupt */ BMA400_AUTO_WAKEUP_EN }; @@ -1358,32 +1386,37 @@ struct bma400_dev /* Chip Id */ uint8_t chip_id; - /* Device Id */ - uint8_t dev_id; - /* SPI/I2C Interface selection */ enum bma400_intf intf; - /* Interface handle pointer */ + /*! + * 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; /* Decide SPI or I2C read mechanism */ uint8_t dummy_byte; /* Bus read function pointer */ - bma400_com_fptr_t read; + bma400_read_fptr_t read; /* Bus write function pointer */ - bma400_com_fptr_t write; + bma400_write_fptr_t write; - /* delay(in ms) function pointer */ - bma400_delay_fptr_t delay_ms; + /* delay(in us) function pointer */ + bma400_delay_us_fptr_t delay_us; /* Resolution for FOC */ uint8_t resolution; /* User set read/write length */ uint16_t read_write_len; + + /*! To store interface pointer error */ + BMA400_INTF_RET_TYPE intf_rslt; }; #endif /* BMA400_DEFS_H_ */ diff --git a/examples/accelerometer.c b/examples/accelerometer.c deleted file mode 100644 index b85a002..0000000 --- a/examples/accelerometer.c +++ /dev/null @@ -1,171 +0,0 @@ -#include -#include "bma400.h" - -#define GRAVITY_EARTH (9.80665f) /* Earth's gravity in m/s^2 */ - -void set_interface(enum bma400_intf intf, struct bma400_dev *dev); -void delay_ms(uint32_t period); -int8_t i2c_reg_write(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t i2c_reg_read(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t spi_reg_write(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t spi_reg_read(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -void print_rslt(int8_t rslt); -float lsb_to_ms2(int16_t val, float g_range, uint8_t bit_width); -float sensor_ticks_to_s(uint32_t sensor_time); - -int main(int argc, char const *argv[]) -{ - struct bma400_dev bma; - struct bma400_sensor_conf conf; - struct bma400_sensor_data data; - int8_t rslt; - uint8_t n_samples = 200; - float t, x, y, z; - - set_interface(BMA400_SPI_INTF, &bma); - - rslt = bma400_init(&bma); - print_rslt(rslt); - - rslt = bma400_soft_reset(&bma); - print_rslt(rslt); - - /* Select the type of configuration to be modified */ - conf.type = BMA400_ACCEL; - - /* Get the accelerometer configurations which are set in the sensor */ - rslt = bma400_get_sensor_conf(&conf, 1, &bma); - print_rslt(rslt); - - /* Modify the desired configurations as per macros - * available in bma400_defs.h file */ - conf.param.accel.odr = BMA400_ODR_100HZ; - conf.param.accel.range = BMA400_2G_RANGE; - conf.param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1; - - /* Set the desired configurations to the sensor */ - rslt = bma400_set_sensor_conf(&conf, 1, &bma); - print_rslt(rslt); - - rslt = bma400_set_power_mode(BMA400_LOW_POWER_MODE, &bma); - print_rslt(rslt); - - printf("t[s], Ax[m/s2], Ay[m/s2], Az[m/s2]\r\n"); - - while (n_samples && (rslt == BMA400_OK)) - { - bma.delay_ms(10); /* Wait for 10ms as ODR is set to 100Hz */ - - rslt = bma400_get_accel_data(BMA400_DATA_SENSOR_TIME, &data, &bma); - print_rslt(rslt); - - /* 12-bit accelerometer at range 2G */ - x = lsb_to_ms2(data.x, 2, 12); - y = lsb_to_ms2(data.y, 2, 12); - z = lsb_to_ms2(data.z, 2, 12); - t = sensor_ticks_to_s(data.sensortime); - - printf("%.4f, %.2f, %.2f, %.2f\r\n", t, x, y, z); - n_samples--; - } - - return 0; -} - -void set_interface(enum bma400_intf intf, struct bma400_dev *dev) -{ - switch (intf) - { - case BMA400_I2C_INTF: - dev->intf_ptr = NULL; /* To attach your interface device reference */ - dev->delay_ms = delay_ms; - dev->dev_id = BMA400_I2C_ADDRESS_SDO_LOW; - dev->read = i2c_reg_read; - dev->write = i2c_reg_write; - dev->intf = BMA400_I2C_INTF; - break; - case BMA400_SPI_INTF: - dev->intf_ptr = NULL; /* To attach your interface device reference */ - dev->dev_id = 0; /* Could be used to identify the chip select line. */ - dev->read = spi_reg_read; - dev->write = spi_reg_write; - dev->intf = BMA400_SPI_INTF; - break; - default: - printf("Interface not supported.\r\n"); - } -} - -void delay_ms(uint32_t period) -{ - /* Wait for a period amount of ms*/ -} - -int8_t i2c_reg_write(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Write to registers using I2C. Return 0 for a successful execution. */ - return -1; -} - -int8_t i2c_reg_read(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Read from registers using I2C. Return 0 for a successful execution. */ - return -1; -} - -int8_t spi_reg_write(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Write to registers using SPI. Return 0 for a successful execution. */ - return -1; -} - -int8_t spi_reg_read(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Read from registers using SPI. Return 0 for a successful execution. */ - return -1; -} - -void print_rslt(int8_t rslt) -{ - switch (rslt) - { - case BMA400_OK: - - /* Do nothing */ - break; - case BMA400_E_NULL_PTR: - printf("Error [%d] : Null pointer\r\n", rslt); - break; - case BMA400_E_COM_FAIL: - printf("Error [%d] : Communication failure\r\n", rslt); - break; - case BMA400_E_DEV_NOT_FOUND: - printf("Error [%d] : Device not found\r\n", rslt); - break; - case BMA400_E_INVALID_CONFIG: - printf("Error [%d] : Invalid configuration\r\n", rslt); - break; - case BMA400_W_SELF_TEST_FAIL: - printf("Warning [%d] : Self test failed\r\n", rslt); - break; - default: - printf("Error [%d] : Unknown error code\r\n", rslt); - break; - } -} - -float lsb_to_ms2(int16_t val, float g_range, uint8_t bit_width) -{ - float half_scale = (float)(1 << bit_width) / 2.0f; - - return GRAVITY_EARTH * val * g_range / half_scale; -} - -float sensor_ticks_to_s(uint32_t sensor_time) -{ - return (float)sensor_time * 0.0000390625f; -} diff --git a/examples/accelerometer/Makefile b/examples/accelerometer/Makefile new file mode 100644 index 0000000..cfa73a7 --- /dev/null +++ b/examples/accelerometer/Makefile @@ -0,0 +1,15 @@ +COINES_INSTALL_PATH ?= ../../../.. + +EXAMPLE_FILE ?= accelerometer.c + +API_LOCATION ?= ../.. + +C_SRCS += \ +$(API_LOCATION)/bma400.c \ +../common/common.c + +INCLUDEPATHS += \ +$(API_LOCATION) \ +../common + +include $(COINES_INSTALL_PATH)/coines.mk \ No newline at end of file diff --git a/examples/accelerometer/accelerometer.c b/examples/accelerometer/accelerometer.c new file mode 100644 index 0000000..b77a20d --- /dev/null +++ b/examples/accelerometer/accelerometer.c @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2020 Bosch Sensortec GmbH + * + * The license is available at root folder + * + */ + +/*! + * @ingroup bma400Examples + * @defgroup bma400ExamplesAccelerometer Accelerometer read + * @brief To read accelerometer xyz data for defined range and ODR + * \include accelerometer.c + */ + +#include +#include "bma400.h" +#include "common.h" + +/* Earth's gravity in m/s^2 */ +#define GRAVITY_EARTH (9.80665f) + +/* 39.0625us per tick */ +#define SENSOR_TICK_TO_S (0.0000390625f) + +static float lsb_to_ms2(int16_t accel_data, uint8_t g_range, uint8_t bit_width); + +int main(int argc, char const *argv[]) +{ + struct bma400_dev bma; + struct bma400_sensor_conf conf; + struct bma400_sensor_data data; + struct bma400_int_enable int_en; + int8_t rslt; + uint8_t n_samples = 50; + float t, x, y, z; + uint16_t int_status = 0; + + /* Interface reference is given as a parameter + * For I2C : BMA400_I2C_INTF + * For SPI : BMA400_SPI_INTF + */ + rslt = bma400_interface_init(&bma, BMA400_SPI_INTF); + bma400_check_rslt("bma400_interface_init", rslt); + + rslt = bma400_soft_reset(&bma); + bma400_check_rslt("bma400_soft_reset", rslt); + + rslt = bma400_init(&bma); + bma400_check_rslt("bma400_init", rslt); + + /* Select the type of configuration to be modified */ + conf.type = BMA400_ACCEL; + + /* Get the accelerometer configurations which are set in the sensor */ + rslt = bma400_get_sensor_conf(&conf, 1, &bma); + bma400_check_rslt("bma400_get_sensor_conf", rslt); + + /* Modify the desired configurations as per macros + * available in bma400_defs.h file */ + conf.param.accel.odr = BMA400_ODR_100HZ; + conf.param.accel.range = BMA400_RANGE_2G; + conf.param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1; + + /* Set the desired configurations to the sensor */ + rslt = bma400_set_sensor_conf(&conf, 1, &bma); + bma400_check_rslt("bma400_set_sensor_conf", rslt); + + rslt = bma400_set_power_mode(BMA400_MODE_NORMAL, &bma); + bma400_check_rslt("bma400_set_power_mode", rslt); + + int_en.type = BMA400_DRDY_INT_EN; + int_en.conf = BMA400_ENABLE; + + rslt = bma400_enable_interrupt(&int_en, 1, &bma); + bma400_check_rslt("bma400_enable_interrupt", rslt); + + printf("\nGet accel data - BMA400_DATA_SENSOR_TIME\n"); + + printf("Accel Gravity data in m/s^2\n"); + + while (n_samples && (rslt == BMA400_OK)) + { + rslt = bma400_get_interrupt_status(&int_status, &bma); + bma400_check_rslt("bma400_get_interrupt_status", rslt); + + if (int_status & BMA400_ASSERTED_DRDY_INT) + { + rslt = bma400_get_accel_data(BMA400_DATA_SENSOR_TIME, &data, &bma); + bma400_check_rslt("bma400_get_accel_data", rslt); + + /* 12-bit accelerometer at range 2G */ + x = lsb_to_ms2(data.x, 2, 12); + y = lsb_to_ms2(data.y, 2, 12); + z = lsb_to_ms2(data.z, 2, 12); + t = (float)data.sensortime * SENSOR_TICK_TO_S; + + printf("Gravity-x : %.2f, Gravity-y : %.2f, Gravity-z : %.2f, t(s) : %.4f\r\n", x, y, z, t); + n_samples--; + } + } + + n_samples = 50; + + printf("\nGet accel data - BMA400_DATA_ONLY\n"); + + printf("Accel Gravity data in m/s^2\n"); + + while (n_samples && (rslt == BMA400_OK)) + { + rslt = bma400_get_interrupt_status(&int_status, &bma); + bma400_check_rslt("bma400_get_interrupt_status", rslt); + + if (int_status & BMA400_ASSERTED_DRDY_INT) + { + rslt = bma400_get_accel_data(BMA400_DATA_ONLY, &data, &bma); + bma400_check_rslt("bma400_get_accel_data", rslt); + + /* 12-bit accelerometer at range 2G */ + x = lsb_to_ms2(data.x, 2, 12); + y = lsb_to_ms2(data.y, 2, 12); + z = lsb_to_ms2(data.z, 2, 12); + + printf("Gravity-x : %.2f, Gravity-y : %.2f, Gravity-z : %.2f\r\n", x, y, z); + n_samples--; + } + } + + bma400_coines_deinit(); + + return rslt; +} + +static float lsb_to_ms2(int16_t accel_data, uint8_t g_range, uint8_t bit_width) +{ + float accel_ms2; + int16_t half_scale; + + half_scale = 1 << (bit_width - 1); + accel_ms2 = (GRAVITY_EARTH * accel_data * g_range) / half_scale; + + return accel_ms2; + +} diff --git a/examples/activity_change/Makefile b/examples/activity_change/Makefile new file mode 100644 index 0000000..62f6460 --- /dev/null +++ b/examples/activity_change/Makefile @@ -0,0 +1,15 @@ +COINES_INSTALL_PATH ?= ../../../.. + +EXAMPLE_FILE ?= activity_change.c + +API_LOCATION ?= ../.. + +C_SRCS += \ +$(API_LOCATION)/bma400.c \ +../common/common.c + +INCLUDEPATHS += \ +$(API_LOCATION) \ +../common + +include $(COINES_INSTALL_PATH)/coines.mk \ No newline at end of file diff --git a/examples/activity_change/activity_change.c b/examples/activity_change/activity_change.c new file mode 100644 index 0000000..b9d2651 --- /dev/null +++ b/examples/activity_change/activity_change.c @@ -0,0 +1,161 @@ +/* + * Copyright (C) 2020 Bosch Sensortec GmbH + * + * The license is available at root folder + * + */ + +/*! + * @ingroup bma400Examples + * @defgroup bma400ExamplesActChange Activity change + * @brief To showcase activity change feature + * \include activity_change.c + */ + +#include +#include "bma400.h" +#include "common.h" + +/* Macro to determine count of activity change for each axis */ +#define BMA400_INT_COUNTER UINT8_C(5) + +/* struct to act as counter to test activity change interrupt - axis wise */ +struct test_axes_wise_counter +{ + uint8_t x_counter; + uint8_t y_counter; + uint8_t z_counter; +}; + +int main(int argc, char const *argv[]) +{ + struct bma400_dev bma; + + int8_t rslt = 0; + uint16_t int_status; + + struct test_axes_wise_counter act_ch_cnt = { 0 }; + struct bma400_sensor_data accel; + struct bma400_sensor_conf accel_settin[2] = { { 0 } }; + struct bma400_int_enable int_en; + + printf("Functionality test for Activity change interrupt\n"); + + /* Interface reference is given as a parameter + * For I2C : BMA400_I2C_INTF + * For SPI : BMA400_SPI_INTF + */ + rslt = bma400_interface_init(&bma, BMA400_SPI_INTF); + bma400_check_rslt("bma400_interface_init", rslt); + + rslt = bma400_soft_reset(&bma); + bma400_check_rslt("bma400_soft_reset", rslt); + + rslt = bma400_init(&bma); + bma400_check_rslt("bma400_init", rslt); + + accel_settin[0].type = BMA400_ACTIVITY_CHANGE_INT; + accel_settin[1].type = BMA400_ACCEL; + + rslt = bma400_get_sensor_conf(accel_settin, 2, &bma); + bma400_check_rslt("bma400_get_sensor_conf", rslt); + + accel_settin[0].param.act_ch.int_chan = BMA400_INT_CHANNEL_1; + accel_settin[0].param.act_ch.axes_sel = BMA400_AXIS_XYZ_EN; + accel_settin[0].param.act_ch.act_ch_ntps = BMA400_ACT_CH_SAMPLE_CNT_64; + accel_settin[0].param.act_ch.data_source = BMA400_DATA_SRC_ACC_FILT1; + accel_settin[0].param.act_ch.act_ch_thres = 10; + + accel_settin[1].param.accel.odr = BMA400_ODR_100HZ; + accel_settin[1].param.accel.range = BMA400_RANGE_2G; + accel_settin[1].param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1; + + /* Set the desired configurations to the sensor */ + rslt = bma400_set_sensor_conf(accel_settin, 2, &bma); + bma400_check_rslt("bma400_set_sensor_conf", rslt); + + rslt = bma400_set_power_mode(BMA400_MODE_NORMAL, &bma); + bma400_check_rslt("bma400_set_power_mode", rslt); + + int_en.type = BMA400_ACTIVITY_CHANGE_INT_EN; + int_en.conf = BMA400_ENABLE; + + rslt = bma400_enable_interrupt(&int_en, 1, &bma); + bma400_check_rslt("bma400_enable_interrupt", rslt); + + printf("Show activity on x y z axes of the board\n"); + + while (1) + { + rslt = bma400_get_sensor_conf(accel_settin, 2, &bma); + bma400_check_rslt("bma400_get_sensor_conf", rslt); + + rslt = bma400_get_interrupt_status(&int_status, &bma); + bma400_check_rslt("bma400_get_interrupt_status", rslt); + + if (int_status & BMA400_ASSERTED_ACT_CH_X) + { + printf("Activity change interrupt asserted on X axis\n"); + act_ch_cnt.x_counter++; + + rslt = bma400_get_accel_data(BMA400_DATA_SENSOR_TIME, &accel, &bma); + bma400_check_rslt("bma400_get_accel_data_X", rslt); + + if (rslt == BMA400_OK) + { + printf("Accel Data : X : %d Y : %d Z : %d SENSOR_TIME : %d\n", + accel.x, + accel.y, + accel.z, + accel.sensortime); + } + } + + if (int_status & BMA400_ASSERTED_ACT_CH_Y) + { + printf("Activity change interrupt asserted on Y axis\n"); + act_ch_cnt.y_counter++; + + rslt = bma400_get_accel_data(BMA400_DATA_SENSOR_TIME, &accel, &bma); + bma400_check_rslt("bma400_get_accel_data_Y", rslt); + + if (rslt == BMA400_OK) + { + printf("Accel Data : X : %d Y : %d Z : %d SENSOR_TIME : %d\n", + accel.x, + accel.y, + accel.z, + accel.sensortime); + } + } + + if (int_status & BMA400_ASSERTED_ACT_CH_Z) + { + printf("Activity change interrupt asserted on Z axis\n"); + act_ch_cnt.z_counter++; + + rslt = bma400_get_accel_data(BMA400_DATA_SENSOR_TIME, &accel, &bma); + bma400_check_rslt("bma400_get_accel_data_Z", rslt); + + if (rslt == BMA400_OK) + { + printf("Accel Data : X : %d Y : %d Z : %d SENSOR_TIME : %d\n", + accel.x, + accel.y, + accel.z, + accel.sensortime); + } + } + + if ((act_ch_cnt.x_counter >= BMA400_INT_COUNTER) && (act_ch_cnt.y_counter >= BMA400_INT_COUNTER) && + (act_ch_cnt.z_counter >= BMA400_INT_COUNTER)) + { + printf("Activity change interrupt test done !\n"); + break; + } + } + + bma400_coines_deinit(); + + return rslt; +} diff --git a/examples/basic.c b/examples/basic.c deleted file mode 100644 index 765dc25..0000000 --- a/examples/basic.c +++ /dev/null @@ -1,114 +0,0 @@ -#include -#include "bma400.h" - -void set_interface(enum bma400_intf intf, struct bma400_dev *dev); -void delay_ms(uint32_t period); -int8_t i2c_reg_write(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t i2c_reg_read(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t spi_reg_write(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t spi_reg_read(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -void print_rslt(int8_t rslt); - -int main(int argc, char const *argv[]) -{ - struct bma400_dev bma; - int8_t rslt; - - set_interface(BMA400_SPI_INTF, &bma); - - rslt = bma400_init(&bma); - print_rslt(rslt); - - if (rslt == BMA400_OK) - { - printf("BMA400 found with chip ID 0x%X\r\n", bma.chip_id); - } - - return 0; -} - -void set_interface(enum bma400_intf intf, struct bma400_dev *dev) -{ - switch (intf) - { - case BMA400_I2C_INTF: - dev->intf_ptr = NULL; /* To attach your interface device reference */ - dev->delay_ms = delay_ms; - dev->dev_id = BMA400_I2C_ADDRESS_SDO_LOW; - dev->read = i2c_reg_read; - dev->write = i2c_reg_write; - dev->intf = BMA400_I2C_INTF; - break; - case BMA400_SPI_INTF: - dev->intf_ptr = NULL; /* To attach your interface device reference */ - dev->dev_id = 0; /* Could be used to identify the chip select line. */ - dev->read = spi_reg_read; - dev->write = spi_reg_write; - dev->intf = BMA400_SPI_INTF; - break; - default: - printf("Interface not supported.\r\n"); - } -} - -void delay_ms(uint32_t period) -{ - /* Wait for a period amount of ms*/ -} - -int8_t i2c_reg_write(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Write to registers using I2C. Return 0 for a successful execution. */ - return -1; -} - -int8_t i2c_reg_read(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Read from registers using I2C. Return 0 for a successful execution. */ - return -1; -} - -int8_t spi_reg_write(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Write to registers using SPI. Return 0 for a successful execution. */ - return -1; -} - -int8_t spi_reg_read(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Read from registers using SPI. Return 0 for a successful execution. */ - return -1; -} - -void print_rslt(int8_t rslt) -{ - switch (rslt) - { - case BMA400_OK: - - /* Do nothing */ - break; - case BMA400_E_NULL_PTR: - printf("Error [%d] : Null pointer\r\n", rslt); - break; - case BMA400_E_COM_FAIL: - printf("Error [%d] : Communication failure\r\n", rslt); - break; - case BMA400_E_DEV_NOT_FOUND: - printf("Error [%d] : Device not found\r\n", rslt); - break; - case BMA400_E_INVALID_CONFIG: - printf("Error [%d] : Invalid configuration\r\n", rslt); - break; - case BMA400_W_SELF_TEST_FAIL: - printf("Warning [%d] : Self test failed\r\n", rslt); - break; - default: - printf("Error [%d] : Unknown error code\r\n", rslt); - break; - } -} diff --git a/examples/common/common.c b/examples/common/common.c new file mode 100644 index 0000000..7a5ea81 --- /dev/null +++ b/examples/common/common.c @@ -0,0 +1,163 @@ +/** + * Copyright (C) 2020 Bosch Sensortec GmbH. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include + +#include "bma400.h" +#include "coines.h" + +/*! Read write length varies based on user requirement */ +#define READ_WRITE_LENGTH UINT8_C(46) + +/* Variable to store the device address */ +static uint8_t dev_addr; + +/*! + * @brief I2C read function map to COINES platform + */ +BMA400_INTF_RET_TYPE bma400_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr) +{ + uint8_t dev_addr = *(uint8_t*)intf_ptr; + + return coines_read_i2c(dev_addr, reg_addr, reg_data, (uint16_t)len); +} + +/*! + * @brief I2C write function map to COINES platform + */ +BMA400_INTF_RET_TYPE bma400_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr) +{ + uint8_t dev_addr = *(uint8_t*)intf_ptr; + + return coines_write_i2c(dev_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len); +} + +/*! + * @brief SPI read function map to COINES platform + */ +BMA400_INTF_RET_TYPE bma400_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr) +{ + uint8_t dev_addr = *(uint8_t*)intf_ptr; + + return coines_read_spi(dev_addr, reg_addr, reg_data, (uint16_t)len); +} + +/*! + * @brief SPI write function map to COINES platform + */ +BMA400_INTF_RET_TYPE bma400_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr) +{ + uint8_t dev_addr = *(uint8_t*)intf_ptr; + + return coines_write_spi(dev_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len); +} + +/*! + * @brief Delay function map to COINES platform + */ +void bma400_delay_us(uint32_t period, void *intf_ptr) +{ + coines_delay_usec(period); +} + +void bma400_check_rslt(const char api_name[], int8_t rslt) +{ + switch (rslt) + { + case BMA400_OK: + + /* Do nothing */ + break; + case BMA400_E_NULL_PTR: + printf("Error [%d] : Null pointer\r\n", rslt); + break; + case BMA400_E_COM_FAIL: + printf("Error [%d] : Communication failure\r\n", rslt); + break; + case BMA400_E_INVALID_CONFIG: + printf("Error [%d] : Invalid configuration\r\n", rslt); + break; + case BMA400_E_DEV_NOT_FOUND: + printf("Error [%d] : Device not found\r\n", rslt); + break; + default: + printf("Error [%d] : Unknown error code\r\n", rslt); + break; + } +} + +int8_t bma400_interface_init(struct bma400_dev *bma400, uint8_t intf) +{ + int8_t rslt = BMA400_OK; + + /* Switch VDD for sensor off */ + coines_set_shuttleboard_vdd_vddio_config(0, 0); + coines_config_i2c_bus(COINES_I2C_BUS_0, COINES_I2C_FAST_MODE); + + /* Switch VDD for sensor on */ + coines_set_shuttleboard_vdd_vddio_config(3300, 3300); + + if (bma400 != NULL) + { + int16_t result = coines_open_comm_intf(COINES_COMM_INTF_USB); + if (result < COINES_SUCCESS) + { + printf( + "\n Unable to connect with Application Board ! \n" " 1. Check if the board is connected and powered on. \n" " 2. Check if Application Board USB driver is installed. \n" + " 3. Check if board is in use by another application. (Insufficient permissions to access USB) \n"); + exit(result); + } + + coines_set_shuttleboard_vdd_vddio_config(0, 0); + coines_delay_msec(100); + + /* Bus configuration : I2C */ + if (intf == BMA400_I2C_INTF) + { + printf("I2C Interface \n"); + + dev_addr = BMA400_I2C_ADDRESS_SDO_LOW; + bma400->read = bma400_i2c_read; + bma400->write = bma400_i2c_write; + bma400->intf = BMA400_I2C_INTF; + coines_config_i2c_bus(COINES_I2C_BUS_0, COINES_I2C_STANDARD_MODE); + } + /* Bus configuration : SPI */ + else if (intf == BMA400_SPI_INTF) + { + printf("SPI Interface \n"); + + dev_addr = COINES_SHUTTLE_PIN_7; + bma400->read = bma400_spi_read; + bma400->write = bma400_spi_write; + bma400->intf = BMA400_SPI_INTF; + coines_config_spi_bus(COINES_SPI_BUS_0, COINES_SPI_SPEED_7_5_MHZ, COINES_SPI_MODE0); + } + + bma400->intf_ptr = &dev_addr; + bma400->delay_us = bma400_delay_us; + bma400->read_write_len = READ_WRITE_LENGTH; + + coines_delay_msec(100); + + coines_set_shuttleboard_vdd_vddio_config(3300, 3300); + + coines_delay_msec(200); + } + else + { + rslt = BMA400_E_NULL_PTR; + } + + return rslt; +} + +void bma400_coines_deinit(void) +{ + coines_close_comm_intf(COINES_COMM_INTF_USB); +} diff --git a/examples/common/common.h b/examples/common/common.h new file mode 100644 index 0000000..f86f804 --- /dev/null +++ b/examples/common/common.h @@ -0,0 +1,31 @@ +/** + * Copyright (C) 2020 Bosch Sensortec GmbH. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus */ + +#include "bma400.h" + +int8_t bma400_interface_init(struct bma400_dev *bme, uint8_t intf); + +int8_t bma400_read_i2c(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); + +int8_t bma400_write_i2c(uint8_t i2c_addr, uint8_t reg_addr, const uint8_t *reg_data, uint16_t length); + +int8_t bma400_read_spi(uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); + +int8_t bma400_write_spi(uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); + +void bma400_delay_ms(uint32_t period_ms); + +void bma400_check_rslt(const char api_name[], int8_t rslt); + +void bma400_coines_deinit(void); + +#ifdef __cplusplus +} +#endif /*__cplusplus */ diff --git a/examples/fifo.c b/examples/fifo.c deleted file mode 100644 index 7239d97..0000000 --- a/examples/fifo.c +++ /dev/null @@ -1,264 +0,0 @@ -#include -#include "bma400.h" - -#define GRAVITY_EARTH (9.80665f) /* Earth's gravity in m/s^2 */ - -/* Include 2 additional frames to account for - * the next frame already being in the FIFO - * and the sensor time frame - */ -#define N_FRAMES 50 - -/* 50 Frames result in 50*7, 350 bytes. - * A few extra for the sensor time frame and - * in case the next frame is available too. - */ -#define FIFO_SIZE (357 + BMA400_FIFO_BYTES_OVERREAD) - -/* Delay to fill FIFO data At ODR of say 100 Hz, - * 1 frame gets updated in 1/100 = 0.01s i.e. for - * 50 frames we need 50 * 0.01 = 0.5 seconds delay - */ -#define WAIT_PERIOD_MS 500 - -void set_interface(enum bma400_intf intf, struct bma400_dev *dev); -void delay_ms(uint32_t period); -int8_t i2c_reg_write(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t i2c_reg_read(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t spi_reg_write(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t spi_reg_read(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -void print_rslt(int8_t rslt); -float lsb_to_ms2(int16_t val, float g_range, uint8_t bit_width); -float sensor_ticks_to_s(uint32_t sensor_time); - -int main(int argc, char const *argv[]) -{ - struct bma400_dev bma; - struct bma400_sensor_data accel_data[N_FRAMES] = { 0 }; - struct bma400_fifo_data fifo_frame; - struct bma400_device_conf fifo_conf; - struct bma400_sensor_conf conf; - int8_t rslt; - uint16_t i; - uint8_t fifo_buff[FIFO_SIZE] = { 0 }; - uint16_t accel_frames_req = N_FRAMES; - float x, y, z, t; - uint8_t n = 20; /* Read the FIFO 20 times */ - - set_interface(BMA400_SPI_INTF, &bma); - - rslt = bma400_init(&bma); - print_rslt(rslt); - - rslt = bma400_soft_reset(&bma); - print_rslt(rslt); - - /* Select the type of configuration to be modified */ - conf.type = BMA400_ACCEL; - - /* Get the accelerometer configurations which are set in the sensor */ - rslt = bma400_get_sensor_conf(&conf, 1, &bma); - print_rslt(rslt); - - /* Modify the desired configurations as per macros - * available in bma400_defs.h file */ - conf.param.accel.odr = BMA400_ODR_100HZ; - conf.param.accel.range = BMA400_2G_RANGE; - conf.param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1; - - /* Set the desired configurations to the sensor */ - rslt = bma400_set_sensor_conf(&conf, 1, &bma); - print_rslt(rslt); - - fifo_conf.type = BMA400_FIFO_CONF; - - rslt = bma400_get_device_conf(&fifo_conf, 1, &bma); - print_rslt(rslt); - - fifo_conf.param.fifo_conf.conf_regs = BMA400_FIFO_X_EN | BMA400_FIFO_Y_EN | BMA400_FIFO_Z_EN | BMA400_FIFO_TIME_EN; - fifo_conf.param.fifo_conf.conf_status = BMA400_ENABLE; - - rslt = bma400_set_device_conf(&fifo_conf, 1, &bma); - print_rslt(rslt); - - rslt = bma400_set_power_mode(BMA400_NORMAL_MODE, &bma); - print_rslt(rslt); - - while ((rslt == BMA400_OK) && n) - { - fifo_frame.data = fifo_buff; - fifo_frame.length = FIFO_SIZE; - bma.delay_ms(WAIT_PERIOD_MS); - - printf("Requested FIFO length : %d\r\n", fifo_frame.length); - - rslt = bma400_get_fifo_data(&fifo_frame, &bma); - print_rslt(rslt); - - if (rslt != BMA400_OK) - { - printf("FIFO read failed\r\n"); - } - - printf("Available FIFO length : %d \r\n", fifo_frame.length); - - do - { - accel_frames_req = N_FRAMES; - rslt = bma400_extract_accel(&fifo_frame, accel_data, &accel_frames_req, &bma); - print_rslt(rslt); - - if (rslt != BMA400_OK) - { - printf("Accelerometer data extraction failed\r\n"); - } - - if (accel_frames_req) - { - printf("Extracted FIFO frames : %d \r\n", accel_frames_req); - - printf("Frame index, Ax[m/s2], Ay[m/s2], Az[m/s2]\r\n"); - for (i = 0; i < accel_frames_req; i++) - { - bma.delay_ms(10); /* Wait for 10ms as ODR is set to 100Hz */ - - /* 12-bit accelerometer at range 2G */ - x = lsb_to_ms2(accel_data[i].x, 2, 12); - y = lsb_to_ms2(accel_data[i].y, 2, 12); - z = lsb_to_ms2(accel_data[i].z, 2, 12); - - printf("%d, %.2f, %.2f, %.2f\r\n", i, x, y, z); - } - } - } while (accel_frames_req); - - if (fifo_frame.fifo_sensor_time) - { - t = sensor_ticks_to_s(fifo_frame.fifo_sensor_time); - - printf("FIFO sensor time : %.4fs\r\n", t); - } - - if (fifo_frame.conf_change) - { - printf("FIFO configuration change: 0x%X\r\n", fifo_frame.conf_change); - - if (fifo_frame.conf_change & BMA400_FIFO_CONF0_CHANGE) - { - printf("FIFO data source configuration changed \r\n"); - } - - if (fifo_frame.conf_change & BMA400_ACCEL_CONF0_CHANGE) - { - printf("Accel filt1_bw configuration changed \r\n"); - } - - if (fifo_frame.conf_change & BMA400_ACCEL_CONF1_CHANGE) - { - printf("Accel odr/osr/range configuration changed \r\n"); - } - } - - n--; - } - - return 0; -} - -void set_interface(enum bma400_intf intf, struct bma400_dev *dev) -{ - switch (intf) - { - case BMA400_I2C_INTF: - dev->intf_ptr = NULL; /* To attach your interface device reference */ - dev->delay_ms = delay_ms; - dev->dev_id = BMA400_I2C_ADDRESS_SDO_LOW; - dev->read = i2c_reg_read; - dev->write = i2c_reg_write; - dev->intf = BMA400_I2C_INTF; - break; - case BMA400_SPI_INTF: - dev->intf_ptr = NULL; /* To attach your interface device reference */ - dev->dev_id = 0; /* Could be used to identify the chip select line. */ - dev->read = spi_reg_read; - dev->write = spi_reg_write; - dev->intf = BMA400_SPI_INTF; - break; - default: - printf("Interface not supported.\r\n"); - } -} - -void delay_ms(uint32_t period) -{ - /* Wait for a period amount of ms*/ -} - -int8_t i2c_reg_write(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Write to registers using I2C. Return 0 for a successful execution. */ - return -1; -} - -int8_t i2c_reg_read(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Read from registers using I2C. Return 0 for a successful execution. */ - return -1; -} - -int8_t spi_reg_write(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Write to registers using SPI. Return 0 for a successful execution. */ - return -1; -} - -int8_t spi_reg_read(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Read from registers using SPI. Return 0 for a successful execution. */ - return -1; -} - -void print_rslt(int8_t rslt) -{ - switch (rslt) - { - case BMA400_OK: - - /* Do nothing */ - break; - case BMA400_E_NULL_PTR: - printf("Error [%d] : Null pointer\r\n", rslt); - break; - case BMA400_E_COM_FAIL: - printf("Error [%d] : Communication failure\r\n", rslt); - break; - case BMA400_E_DEV_NOT_FOUND: - printf("Error [%d] : Device not found\r\n", rslt); - break; - case BMA400_E_INVALID_CONFIG: - printf("Error [%d] : Invalid configuration\r\n", rslt); - break; - case BMA400_W_SELF_TEST_FAIL: - printf("Warning [%d] : Self test failed\r\n", rslt); - break; - default: - printf("Error [%d] : Unknown error code\r\n", rslt); - break; - } -} - -float lsb_to_ms2(int16_t val, float g_range, uint8_t bit_width) -{ - float half_scale = (float)(1 << bit_width) / 2.0f; - - return GRAVITY_EARTH * val * g_range / half_scale; -} - -float sensor_ticks_to_s(uint32_t sensor_time) -{ - return (float)sensor_time * 0.0000390625f; -} diff --git a/examples/fifo_full_xyz_data/Makefile b/examples/fifo_full_xyz_data/Makefile new file mode 100644 index 0000000..bd6addf --- /dev/null +++ b/examples/fifo_full_xyz_data/Makefile @@ -0,0 +1,15 @@ +COINES_INSTALL_PATH ?= ../../../.. + +EXAMPLE_FILE ?= fifo_full_xyz_data.c + +API_LOCATION ?= ../.. + +C_SRCS += \ +$(API_LOCATION)/bma400.c \ +../common/common.c + +INCLUDEPATHS += \ +$(API_LOCATION) \ +../common + +include $(COINES_INSTALL_PATH)/coines.mk \ No newline at end of file diff --git a/examples/fifo_full_xyz_data/fifo_full_xyz_data.c b/examples/fifo_full_xyz_data/fifo_full_xyz_data.c new file mode 100644 index 0000000..0eea766 --- /dev/null +++ b/examples/fifo_full_xyz_data/fifo_full_xyz_data.c @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2020 Bosch Sensortec GmbH + * + * The license is available at root folder + * + */ + +/*! + * @ingroup bma400Examples + * @defgroup bma400ExamplesFifo FIFO read + * @brief Read and extract FIFO data + * \include fifo_full_xyz_data.c + */ + +#include +#include "bma400.h" +#include "common.h" + +/* Earth's gravity in m/s^2 */ +#define GRAVITY_EARTH (9.80665f) + +/* Total number of frames */ +#define N_FRAMES_FULL 1024 + +/* Add extra bytes to get complete fifo data */ +#define FIFO_SIZE_FULL (N_FRAMES_FULL + BMA400_FIFO_BYTES_OVERREAD) + +static float lsb_to_ms2(int16_t accel_data, uint8_t g_range, uint8_t bit_width); + +int main(int argc, char const *argv[]) +{ + int8_t rslt; + + uint16_t index; + + struct bma400_sensor_data accel_data[N_FRAMES_FULL] = { { 0 } }; + struct bma400_int_enable int_en; + struct bma400_fifo_data fifo_frame; + struct bma400_device_conf fifo_conf; + struct bma400_sensor_conf conf; + uint16_t int_status = 0; + uint8_t fifo_buff[FIFO_SIZE_FULL] = { 0 }; + uint16_t accel_frames_req = N_FRAMES_FULL; + float x, y, z; + uint8_t try = 1; + + struct bma400_dev bma; + + /* Interface reference is given as a parameter + * For I2C : BMA400_I2C_INTF + * For SPI : BMA400_SPI_INTF + */ + rslt = bma400_interface_init(&bma, BMA400_I2C_INTF); + bma400_check_rslt("bma400_interface_init", rslt); + + printf("Read FIFO Full interrupt XYZ data\n"); + + rslt = bma400_soft_reset(&bma); + bma400_check_rslt("bma400_soft_reset", rslt); + + rslt = bma400_init(&bma); + bma400_check_rslt("bma400_init", rslt); + + /* Select the type of configuration to be modified */ + conf.type = BMA400_ACCEL; + + /* Get the accelerometer configurations which are set in the sensor */ + rslt = bma400_get_sensor_conf(&conf, 1, &bma); + bma400_check_rslt("bma400_get_sensor_conf", rslt); + + /* Modify the desired configurations as per macros + * available in bma400_defs.h file */ + conf.param.accel.odr = BMA400_ODR_100HZ; + conf.param.accel.range = BMA400_RANGE_2G; + conf.param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1; + + /* Set the desired configurations to the sensor */ + rslt = bma400_set_sensor_conf(&conf, 1, &bma); + bma400_check_rslt("bma400_set_sensor_conf", rslt); + + fifo_conf.type = BMA400_FIFO_CONF; + + rslt = bma400_get_device_conf(&fifo_conf, 1, &bma); + bma400_check_rslt("bma400_get_device_conf", rslt); + + fifo_conf.param.fifo_conf.conf_regs = BMA400_FIFO_X_EN | BMA400_FIFO_Y_EN | BMA400_FIFO_Z_EN; + fifo_conf.param.fifo_conf.conf_status = BMA400_ENABLE; + fifo_conf.param.fifo_conf.fifo_full_channel = BMA400_INT_CHANNEL_1; + + rslt = bma400_set_device_conf(&fifo_conf, 1, &bma); + bma400_check_rslt("bma400_set_device_conf", rslt); + + rslt = bma400_set_power_mode(BMA400_MODE_NORMAL, &bma); + bma400_check_rslt("bma400_set_power_mode", rslt); + + fifo_frame.data = fifo_buff; + fifo_frame.length = FIFO_SIZE_FULL; + + int_en.type = BMA400_FIFO_FULL_INT_EN; + int_en.conf = BMA400_ENABLE; + + rslt = bma400_enable_interrupt(&int_en, 1, &bma); + bma400_check_rslt("bma400_enable_interrupt", rslt); + + while (try <= 25) + { + rslt = bma400_get_interrupt_status(&int_status, &bma); + bma400_check_rslt("bma400_get_interrupt_status", rslt); + + if (int_status & BMA400_ASSERTED_FIFO_FULL_INT) + { + printf("\n\nIteration : %d\n\n", try); + + printf("Requested FIFO length : %d\n", fifo_frame.length); + + rslt = bma400_get_fifo_data(&fifo_frame, &bma); + bma400_check_rslt("bma400_get_fifo_data", rslt); + + printf("Available FIFO length : %d\n", fifo_frame.length); + + accel_frames_req = N_FRAMES_FULL; + rslt = bma400_extract_accel(&fifo_frame, accel_data, &accel_frames_req, &bma); + bma400_check_rslt("bma400_extract_accel", rslt); + + if (accel_frames_req) + { + printf("Extracted FIFO frames : %d\n", accel_frames_req); + + printf("Accel data in LSB units and Gravity data in m/s^2\n"); + + for (index = 0; index < accel_frames_req; index++) + { + /* 12-bit accelerometer at range 2G */ + printf("Accel[%d] X : %d raw LSB Y : %d raw LSB Z : %d raw LSB\n", + index, + accel_data[index].x, + accel_data[index].y, + accel_data[index].z); + + /* 12-bit accelerometer at range 2G */ + x = lsb_to_ms2(accel_data[index].x, 2, 12); + y = lsb_to_ms2(accel_data[index].y, 2, 12); + z = lsb_to_ms2(accel_data[index].z, 2, 12); + + /* Print the data in m/s2. */ + printf("\t Gravity-x = %4.2f, Gravity-y = %4.2f, Gravity-z = %4.2f\n", x, y, z); + } + } + + if (fifo_frame.conf_change) + { + printf("FIFO configuration change: 0x%X\n", fifo_frame.conf_change); + + if (fifo_frame.conf_change & BMA400_FIFO_CONF0_CHANGE) + { + printf("FIFO data source configuration changed\n"); + } + + if (fifo_frame.conf_change & BMA400_ACCEL_CONF0_CHANGE) + { + printf("Accel filt1_bw configuration changed\n"); + } + + if (fifo_frame.conf_change & BMA400_ACCEL_CONF1_CHANGE) + { + printf("Accel odr/osr/range configuration changed\n"); + } + } + + try++; + } + } + + bma400_coines_deinit(); + + return rslt; +} + +static float lsb_to_ms2(int16_t accel_data, uint8_t g_range, uint8_t bit_width) +{ + float accel_ms2; + int16_t half_scale; + + half_scale = 1 << (bit_width - 1); + accel_ms2 = (GRAVITY_EARTH * accel_data * g_range) / half_scale; + + return accel_ms2; + +} diff --git a/examples/fifo_full_xyz_data_sensortime/Makefile b/examples/fifo_full_xyz_data_sensortime/Makefile new file mode 100644 index 0000000..9c31058 --- /dev/null +++ b/examples/fifo_full_xyz_data_sensortime/Makefile @@ -0,0 +1,15 @@ +COINES_INSTALL_PATH ?= ../../../.. + +EXAMPLE_FILE ?= fifo_full_xyz_data_sensortime.c + +API_LOCATION ?= ../.. + +C_SRCS += \ +$(API_LOCATION)/bma400.c \ +../common/common.c + +INCLUDEPATHS += \ +$(API_LOCATION) \ +../common + +include $(COINES_INSTALL_PATH)/coines.mk \ No newline at end of file diff --git a/examples/fifo_full_xyz_data_sensortime/fifo_full_xyz_data_sensortime.c b/examples/fifo_full_xyz_data_sensortime/fifo_full_xyz_data_sensortime.c new file mode 100644 index 0000000..cb83940 --- /dev/null +++ b/examples/fifo_full_xyz_data_sensortime/fifo_full_xyz_data_sensortime.c @@ -0,0 +1,197 @@ +/* + * Copyright (C) 2020 Bosch Sensortec GmbH + * + * The license is available at root folder + * + */ + +/*! + * @ingroup bma400Examples + * @defgroup bma400ExamplesFifoST FIFO read with sensortime + * @brief Read and extract FIFO data with sensortime + * \include fifo_full_xyz_data_sensortime.c + */ + +#include +#include "bma400.h" +#include "common.h" + +/* Earth's gravity in m/s^2 */ +#define GRAVITY_EARTH (9.80665f) + +/* 39.0625us per tick */ +#define SENSOR_TICK_TO_S (0.0000390625f) + +/* Total number of frames */ +#define N_FRAMES_FULL 1024 + +/* Add extra bytes to get complete fifo data */ +#define FIFO_SIZE_FULL (N_FRAMES_FULL + BMA400_FIFO_BYTES_OVERREAD) + +static float lsb_to_ms2(int16_t accel_data, uint8_t g_range, uint8_t bit_width); + +int main(int argc, char const *argv[]) +{ + int8_t rslt; + + uint16_t index; + + struct bma400_sensor_data accel_data[N_FRAMES_FULL] = { { 0 } }; + struct bma400_int_enable int_en; + struct bma400_fifo_data fifo_frame; + struct bma400_device_conf fifo_conf; + struct bma400_sensor_conf conf; + uint16_t int_status = 0; + uint8_t fifo_buff[FIFO_SIZE_FULL] = { 0 }; + uint16_t accel_frames_req = N_FRAMES_FULL; + float x, y, z; + uint8_t try = 1; + + struct bma400_dev bma; + + /* Interface reference is given as a parameter + * For I2C : BMA400_I2C_INTF + * For SPI : BMA400_SPI_INTF + */ + rslt = bma400_interface_init(&bma, BMA400_I2C_INTF); + bma400_check_rslt("bma400_interface_init", rslt); + + printf("Read FIFO Full interrupt XYZ data with sensortime\n"); + + rslt = bma400_soft_reset(&bma); + bma400_check_rslt("bma400_soft_reset", rslt); + + rslt = bma400_init(&bma); + bma400_check_rslt("bma400_init", rslt); + + /* Select the type of configuration to be modified */ + conf.type = BMA400_ACCEL; + + /* Get the accelerometer configurations which are set in the sensor */ + rslt = bma400_get_sensor_conf(&conf, 1, &bma); + bma400_check_rslt("bma400_get_sensor_conf", rslt); + + /* Modify the desired configurations as per macros + * available in bma400_defs.h file */ + conf.param.accel.odr = BMA400_ODR_100HZ; + conf.param.accel.range = BMA400_RANGE_2G; + conf.param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1; + + /* Set the desired configurations to the sensor */ + rslt = bma400_set_sensor_conf(&conf, 1, &bma); + bma400_check_rslt("bma400_set_sensor_conf", rslt); + + fifo_conf.type = BMA400_FIFO_CONF; + + rslt = bma400_get_device_conf(&fifo_conf, 1, &bma); + bma400_check_rslt("bma400_get_device_conf", rslt); + + fifo_conf.param.fifo_conf.conf_regs = BMA400_FIFO_X_EN | BMA400_FIFO_Y_EN | BMA400_FIFO_Z_EN | BMA400_FIFO_TIME_EN; + fifo_conf.param.fifo_conf.conf_status = BMA400_ENABLE; + fifo_conf.param.fifo_conf.fifo_full_channel = BMA400_INT_CHANNEL_1; + + rslt = bma400_set_device_conf(&fifo_conf, 1, &bma); + bma400_check_rslt("bma400_set_device_conf", rslt); + + rslt = bma400_set_power_mode(BMA400_MODE_NORMAL, &bma); + bma400_check_rslt("bma400_set_power_mode", rslt); + + fifo_frame.data = fifo_buff; + fifo_frame.length = FIFO_SIZE_FULL; + + int_en.type = BMA400_FIFO_FULL_INT_EN; + int_en.conf = BMA400_ENABLE; + + rslt = bma400_enable_interrupt(&int_en, 1, &bma); + bma400_check_rslt("bma400_enable_interrupt", rslt); + + while (try <= 25) + { + rslt = bma400_get_interrupt_status(&int_status, &bma); + bma400_check_rslt("bma400_get_interrupt_status", rslt); + + if (int_status & BMA400_ASSERTED_FIFO_FULL_INT) + { + printf("\n\nIteration : %d\n\n", try); + + printf("Requested FIFO length : %d\n", fifo_frame.length); + + rslt = bma400_get_fifo_data(&fifo_frame, &bma); + bma400_check_rslt("bma400_get_fifo_data", rslt); + + printf("Available FIFO length : %d\n", fifo_frame.length); + + accel_frames_req = N_FRAMES_FULL; + rslt = bma400_extract_accel(&fifo_frame, accel_data, &accel_frames_req, &bma); + bma400_check_rslt("bma400_extract_accel", rslt); + + if (accel_frames_req) + { + printf("Extracted FIFO frames : %d\n", accel_frames_req); + + printf("Accel data in LSB units and Gravity data in m/s^2\n"); + + for (index = 0; index < accel_frames_req; index++) + { + /* 12-bit accelerometer at range 2G */ + printf("Accel[%d] X : %d raw LSB Y : %d raw LSB Z : %d raw LSB\n", + index, + accel_data[index].x, + accel_data[index].y, + accel_data[index].z); + + /* 12-bit accelerometer at range 2G */ + x = lsb_to_ms2(accel_data[index].x, 2, 12); + y = lsb_to_ms2(accel_data[index].y, 2, 12); + z = lsb_to_ms2(accel_data[index].z, 2, 12); + + /* Print the data in m/s2. */ + printf("\t Gravity-x = %4.2f, Gravity-y = %4.2f, Gravity-z = %4.2f\n", x, y, z); + } + } + + if (fifo_frame.fifo_sensor_time) + { + printf("FIFO sensor time : %.4fs\n", (float)(fifo_frame.fifo_sensor_time) * SENSOR_TICK_TO_S); + } + + if (fifo_frame.conf_change) + { + printf("FIFO configuration change: 0x%X\n", fifo_frame.conf_change); + + if (fifo_frame.conf_change & BMA400_FIFO_CONF0_CHANGE) + { + printf("FIFO data source configuration changed\n"); + } + + if (fifo_frame.conf_change & BMA400_ACCEL_CONF0_CHANGE) + { + printf("Accel filt1_bw configuration changed\n"); + } + + if (fifo_frame.conf_change & BMA400_ACCEL_CONF1_CHANGE) + { + printf("Accel odr/osr/range configuration changed\n"); + } + } + + try++; + } + } + + bma400_coines_deinit(); + + return rslt; +} + +static float lsb_to_ms2(int16_t accel_data, uint8_t g_range, uint8_t bit_width) +{ + float accel_ms2; + int16_t half_scale; + + half_scale = 1 << (bit_width - 1); + accel_ms2 = (GRAVITY_EARTH * accel_data * g_range) / half_scale; + + return accel_ms2; + +} diff --git a/examples/fifo_watermark_xyz_data/Makefile b/examples/fifo_watermark_xyz_data/Makefile new file mode 100644 index 0000000..c53e44a --- /dev/null +++ b/examples/fifo_watermark_xyz_data/Makefile @@ -0,0 +1,15 @@ +COINES_INSTALL_PATH ?= ../../../.. + +EXAMPLE_FILE ?= fifo_watermark_xyz_data.c + +API_LOCATION ?= ../.. + +C_SRCS += \ +$(API_LOCATION)/bma400.c \ +../common/common.c + +INCLUDEPATHS += \ +$(API_LOCATION) \ +../common + +include $(COINES_INSTALL_PATH)/coines.mk \ No newline at end of file diff --git a/examples/fifo_watermark_xyz_data/fifo_watermark_xyz_data.c b/examples/fifo_watermark_xyz_data/fifo_watermark_xyz_data.c new file mode 100644 index 0000000..3371080 --- /dev/null +++ b/examples/fifo_watermark_xyz_data/fifo_watermark_xyz_data.c @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2020 Bosch Sensortec GmbH + * + * The license is available at root folder + * + */ + +/*! + * @ingroup bma400Examples + * @defgroup bma400ExamplesFifo FIFO watermark read + * @brief Read and extract FIFO watermark data + * \include fifo_watermark_xyz_data.c + */ + +#include +#include "bma400.h" +#include "common.h" + +/* Earth's gravity in m/s^2 */ +#define GRAVITY_EARTH (9.80665f) + +/* Total number of frames */ +#define N_FRAMES 200 + +/* Add extra bytes to get complete fifo data */ +#define FIFO_SIZE (N_FRAMES + BMA400_FIFO_BYTES_OVERREAD) + +static float lsb_to_ms2(int16_t accel_data, uint8_t g_range, uint8_t bit_width); + +int main(int argc, char const *argv[]) +{ + int8_t rslt; + + uint16_t index; + + struct bma400_sensor_data accel_data[N_FRAMES] = { { 0 } }; + struct bma400_int_enable int_en; + struct bma400_fifo_data fifo_frame; + struct bma400_device_conf fifo_conf; + struct bma400_sensor_conf conf; + uint16_t int_status = 0; + uint8_t fifo_buff[FIFO_SIZE] = { 0 }; + uint16_t accel_frames_req = N_FRAMES; + float x, y, z; + uint8_t try = 1; + + struct bma400_dev bma; + + /* Interface reference is given as a parameter + * For I2C : BMA400_I2C_INTF + * For SPI : BMA400_SPI_INTF + */ + rslt = bma400_interface_init(&bma, BMA400_I2C_INTF); + bma400_check_rslt("bma400_interface_init", rslt); + + printf("Read FIFO watermark interrupt XYZ data\n"); + + rslt = bma400_soft_reset(&bma); + bma400_check_rslt("bma400_soft_reset", rslt); + + rslt = bma400_init(&bma); + bma400_check_rslt("bma400_init", rslt); + + /* Select the type of configuration to be modified */ + conf.type = BMA400_ACCEL; + + /* Get the accelerometer configurations which are set in the sensor */ + rslt = bma400_get_sensor_conf(&conf, 1, &bma); + bma400_check_rslt("bma400_get_sensor_conf", rslt); + + /* Modify the desired configurations as per macros + * available in bma400_defs.h file */ + conf.param.accel.odr = BMA400_ODR_100HZ; + conf.param.accel.range = BMA400_RANGE_2G; + conf.param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1; + + /* Set the desired configurations to the sensor */ + rslt = bma400_set_sensor_conf(&conf, 1, &bma); + bma400_check_rslt("bma400_set_sensor_conf", rslt); + + fifo_conf.type = BMA400_FIFO_CONF; + + rslt = bma400_get_device_conf(&fifo_conf, 1, &bma); + bma400_check_rslt("bma400_get_device_conf", rslt); + + fifo_conf.param.fifo_conf.conf_regs = BMA400_FIFO_X_EN | BMA400_FIFO_Y_EN | BMA400_FIFO_Z_EN; + fifo_conf.param.fifo_conf.conf_status = BMA400_ENABLE; + fifo_conf.param.fifo_conf.fifo_watermark = 200; + fifo_conf.param.fifo_conf.fifo_wm_channel = BMA400_INT_CHANNEL_2; + + rslt = bma400_set_device_conf(&fifo_conf, 1, &bma); + bma400_check_rslt("bma400_set_device_conf", rslt); + + rslt = bma400_set_power_mode(BMA400_MODE_NORMAL, &bma); + bma400_check_rslt("bma400_set_power_mode", rslt); + + fifo_frame.data = fifo_buff; + fifo_frame.length = FIFO_SIZE; + + int_en.type = BMA400_FIFO_WM_INT_EN; + int_en.conf = BMA400_ENABLE; + + rslt = bma400_enable_interrupt(&int_en, 1, &bma); + bma400_check_rslt("bma400_enable_interrupt", rslt); + + while (try <= 25) + { + rslt = bma400_get_interrupt_status(&int_status, &bma); + bma400_check_rslt("bma400_get_interrupt_status", rslt); + + if (int_status & BMA400_ASSERTED_FIFO_WM_INT) + { + printf("\n\nIteration : %d\n\n", try); + + printf("Requested FIFO length : %d\n", fifo_frame.length); + + rslt = bma400_get_fifo_data(&fifo_frame, &bma); + bma400_check_rslt("bma400_get_fifo_data", rslt); + + printf("Available FIFO length : %d\n", fifo_frame.length); + + accel_frames_req = N_FRAMES; + rslt = bma400_extract_accel(&fifo_frame, accel_data, &accel_frames_req, &bma); + bma400_check_rslt("bma400_extract_accel", rslt); + + if (accel_frames_req) + { + printf("Extracted FIFO frames : %d\n", accel_frames_req); + + printf("Accel data in LSB units and Gravity data in m/s^2\n"); + + for (index = 0; index < accel_frames_req; index++) + { + /* 12-bit accelerometer at range 2G */ + printf("Accel[%d] X : %d raw LSB Y : %d raw LSB Z : %d raw LSB\n", + index, + accel_data[index].x, + accel_data[index].y, + accel_data[index].z); + + /* 12-bit accelerometer at range 2G */ + x = lsb_to_ms2(accel_data[index].x, 2, 12); + y = lsb_to_ms2(accel_data[index].y, 2, 12); + z = lsb_to_ms2(accel_data[index].z, 2, 12); + + /* Print the data in m/s2. */ + printf("\t Gravity-x = %4.2f, Gravity-y = %4.2f, Gravity-z = %4.2f\n", x, y, z); + } + } + + if (fifo_frame.conf_change) + { + printf("FIFO configuration change: 0x%X\n", fifo_frame.conf_change); + + if (fifo_frame.conf_change & BMA400_FIFO_CONF0_CHANGE) + { + printf("FIFO data source configuration changed\n"); + } + + if (fifo_frame.conf_change & BMA400_ACCEL_CONF0_CHANGE) + { + printf("Accel filt1_bw configuration changed\n"); + } + + if (fifo_frame.conf_change & BMA400_ACCEL_CONF1_CHANGE) + { + printf("Accel odr/osr/range configuration changed\n"); + } + } + + try++; + } + } + + bma400_coines_deinit(); + + return rslt; +} + +static float lsb_to_ms2(int16_t accel_data, uint8_t g_range, uint8_t bit_width) +{ + float accel_ms2; + int16_t half_scale; + + half_scale = 1 << (bit_width - 1); + accel_ms2 = (GRAVITY_EARTH * accel_data * g_range) / half_scale; + + return accel_ms2; + +} diff --git a/examples/fifo_watermark_xyz_data_sensortime/Makefile b/examples/fifo_watermark_xyz_data_sensortime/Makefile new file mode 100644 index 0000000..ce3f6c0 --- /dev/null +++ b/examples/fifo_watermark_xyz_data_sensortime/Makefile @@ -0,0 +1,15 @@ +COINES_INSTALL_PATH ?= ../../../.. + +EXAMPLE_FILE ?= fifo_watermark_xyz_data_sensortime.c + +API_LOCATION ?= ../.. + +C_SRCS += \ +$(API_LOCATION)/bma400.c \ +../common/common.c + +INCLUDEPATHS += \ +$(API_LOCATION) \ +../common + +include $(COINES_INSTALL_PATH)/coines.mk \ No newline at end of file diff --git a/examples/fifo_watermark_xyz_data_sensortime/fifo_watermark_xyz_data_sensortime.c b/examples/fifo_watermark_xyz_data_sensortime/fifo_watermark_xyz_data_sensortime.c new file mode 100644 index 0000000..23779a0 --- /dev/null +++ b/examples/fifo_watermark_xyz_data_sensortime/fifo_watermark_xyz_data_sensortime.c @@ -0,0 +1,198 @@ +/* + * Copyright (C) 2020 Bosch Sensortec GmbH + * + * The license is available at root folder + * + */ + +/*! + * @ingroup bma400Examples + * @defgroup bma400ExamplesFifo FIFO watermark read with sensortime + * @brief Read and extract FIFO watermark data with sensortime + * \include fifo_watermark_xyz_data_sensortime.c + */ + +#include +#include "bma400.h" +#include "common.h" + +/* Earth's gravity in m/s^2 */ +#define GRAVITY_EARTH (9.80665f) + +/* 39.0625us per tick */ +#define SENSOR_TICK_TO_S (0.0000390625f) + +/* Total number of frames */ +#define N_FRAMES 200 + +/* Add extra bytes to get complete fifo data */ +#define FIFO_SIZE (N_FRAMES + BMA400_FIFO_BYTES_OVERREAD) + +static float lsb_to_ms2(int16_t accel_data, uint8_t g_range, uint8_t bit_width); + +int main(int argc, char const *argv[]) +{ + int8_t rslt; + + uint16_t index; + + struct bma400_sensor_data accel_data[N_FRAMES] = { { 0 } }; + struct bma400_int_enable int_en; + struct bma400_fifo_data fifo_frame; + struct bma400_device_conf fifo_conf; + struct bma400_sensor_conf conf; + uint16_t int_status = 0; + uint8_t fifo_buff[FIFO_SIZE] = { 0 }; + uint16_t accel_frames_req = N_FRAMES; + float x, y, z; + uint8_t try = 1; + + struct bma400_dev bma; + + /* Interface reference is given as a parameter + * For I2C : BMA400_I2C_INTF + * For SPI : BMA400_SPI_INTF + */ + rslt = bma400_interface_init(&bma, BMA400_I2C_INTF); + bma400_check_rslt("bma400_interface_init", rslt); + + printf("Read FIFO watermark interrupt XYZ data with sensortime\n"); + + rslt = bma400_soft_reset(&bma); + bma400_check_rslt("bma400_soft_reset", rslt); + + rslt = bma400_init(&bma); + bma400_check_rslt("bma400_init", rslt); + + /* Select the type of configuration to be modified */ + conf.type = BMA400_ACCEL; + + /* Get the accelerometer configurations which are set in the sensor */ + rslt = bma400_get_sensor_conf(&conf, 1, &bma); + bma400_check_rslt("bma400_get_sensor_conf", rslt); + + /* Modify the desired configurations as per macros + * available in bma400_defs.h file */ + conf.param.accel.odr = BMA400_ODR_100HZ; + conf.param.accel.range = BMA400_RANGE_2G; + conf.param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1; + + /* Set the desired configurations to the sensor */ + rslt = bma400_set_sensor_conf(&conf, 1, &bma); + bma400_check_rslt("bma400_set_sensor_conf", rslt); + + fifo_conf.type = BMA400_FIFO_CONF; + + rslt = bma400_get_device_conf(&fifo_conf, 1, &bma); + bma400_check_rslt("bma400_get_device_conf", rslt); + + fifo_conf.param.fifo_conf.conf_regs = BMA400_FIFO_X_EN | BMA400_FIFO_Y_EN | BMA400_FIFO_Z_EN | BMA400_FIFO_TIME_EN; + fifo_conf.param.fifo_conf.conf_status = BMA400_ENABLE; + fifo_conf.param.fifo_conf.fifo_watermark = 200; + fifo_conf.param.fifo_conf.fifo_wm_channel = BMA400_INT_CHANNEL_2; + + rslt = bma400_set_device_conf(&fifo_conf, 1, &bma); + bma400_check_rslt("bma400_set_device_conf", rslt); + + rslt = bma400_set_power_mode(BMA400_MODE_NORMAL, &bma); + bma400_check_rslt("bma400_set_power_mode", rslt); + + fifo_frame.data = fifo_buff; + fifo_frame.length = FIFO_SIZE; + + int_en.type = BMA400_FIFO_WM_INT_EN; + int_en.conf = BMA400_ENABLE; + + rslt = bma400_enable_interrupt(&int_en, 1, &bma); + bma400_check_rslt("bma400_enable_interrupt", rslt); + + while (try <= 25) + { + rslt = bma400_get_interrupt_status(&int_status, &bma); + bma400_check_rslt("bma400_get_interrupt_status", rslt); + + if (int_status & BMA400_ASSERTED_FIFO_WM_INT) + { + printf("\n\nIteration : %d\n\n", try); + + printf("Requested FIFO length : %d\n", fifo_frame.length); + + rslt = bma400_get_fifo_data(&fifo_frame, &bma); + bma400_check_rslt("bma400_get_fifo_data", rslt); + + printf("Available FIFO length : %d\n", fifo_frame.length); + + accel_frames_req = N_FRAMES; + rslt = bma400_extract_accel(&fifo_frame, accel_data, &accel_frames_req, &bma); + bma400_check_rslt("bma400_extract_accel", rslt); + + if (accel_frames_req) + { + printf("Extracted FIFO frames : %d\n", accel_frames_req); + + printf("Accel data in LSB units and Gravity data in m/s^2\n"); + + for (index = 0; index < accel_frames_req; index++) + { + /* 12-bit accelerometer at range 2G */ + printf("Accel[%d] X : %d raw LSB Y : %d raw LSB Z : %d raw LSB\n", + index, + accel_data[index].x, + accel_data[index].y, + accel_data[index].z); + + /* 12-bit accelerometer at range 2G */ + x = lsb_to_ms2(accel_data[index].x, 2, 12); + y = lsb_to_ms2(accel_data[index].y, 2, 12); + z = lsb_to_ms2(accel_data[index].z, 2, 12); + + /* Print the data in m/s2. */ + printf("\t Gravity-x = %4.2f, Gravity-y = %4.2f, Gravity-z = %4.2f\n", x, y, z); + } + } + + if (fifo_frame.fifo_sensor_time) + { + printf("FIFO sensor time : %.4fs\n", (float)(fifo_frame.fifo_sensor_time) * SENSOR_TICK_TO_S); + } + + if (fifo_frame.conf_change) + { + printf("FIFO configuration change: 0x%X\n", fifo_frame.conf_change); + + if (fifo_frame.conf_change & BMA400_FIFO_CONF0_CHANGE) + { + printf("FIFO data source configuration changed\n"); + } + + if (fifo_frame.conf_change & BMA400_ACCEL_CONF0_CHANGE) + { + printf("Accel filt1_bw configuration changed\n"); + } + + if (fifo_frame.conf_change & BMA400_ACCEL_CONF1_CHANGE) + { + printf("Accel odr/osr/range configuration changed\n"); + } + } + + try++; + } + } + + bma400_coines_deinit(); + + return rslt; +} + +static float lsb_to_ms2(int16_t accel_data, uint8_t g_range, uint8_t bit_width) +{ + float accel_ms2; + int16_t half_scale; + + half_scale = 1 << (bit_width - 1); + accel_ms2 = (GRAVITY_EARTH * accel_data * g_range) / half_scale; + + return accel_ms2; + +} diff --git a/examples/orientation/Makefile b/examples/orientation/Makefile new file mode 100644 index 0000000..4061391 --- /dev/null +++ b/examples/orientation/Makefile @@ -0,0 +1,15 @@ +COINES_INSTALL_PATH ?= ../../../.. + +EXAMPLE_FILE ?= orientation.c + +API_LOCATION ?= ../.. + +C_SRCS += \ +$(API_LOCATION)/bma400.c \ +../common/common.c + +INCLUDEPATHS += \ +$(API_LOCATION) \ +../common + +include $(COINES_INSTALL_PATH)/coines.mk \ No newline at end of file diff --git a/examples/orientation/orientation.c b/examples/orientation/orientation.c new file mode 100644 index 0000000..dfd52bd --- /dev/null +++ b/examples/orientation/orientation.c @@ -0,0 +1,207 @@ +/* + * Copyright (C) 2020 Bosch Sensortec GmbH + * + * The license is available at root folder + * + */ + +/*! + * @ingroup bma400Examples + * @defgroup bma400ExamplesOrientation Orientation + * @brief To showcase orientation feature + * \include orientation.c + */ + +#include +#include "bma400.h" +#include "common.h" + +/* Macro to determine count of activity change for each axis */ +#define BMA400_INT_COUNTER UINT8_C(5) + +/* orient_feature interrupts */ +static void test_bma400_orient_feature_int(struct bma400_orient_int_conf test_orient_conf, struct bma400_dev *dev) +{ + int8_t rslt = 0; + + struct bma400_sensor_conf accel_settin[2]; + struct bma400_sensor_data accel; + struct bma400_int_enable int_en[2]; + + uint16_t int_status = 0; + uint8_t orient_cnter = 0; + + accel_settin[0].type = BMA400_ORIENT_CHANGE_INT; + accel_settin[1].type = BMA400_ACCEL; + + rslt = bma400_get_sensor_conf(accel_settin, 2, dev); + bma400_check_rslt("bma400_get_sensor_conf", rslt); + + accel_settin[0].param.orient.axes_sel = test_orient_conf.axes_sel; + accel_settin[0].param.orient.data_src = test_orient_conf.data_src; + accel_settin[0].param.orient.int_chan = test_orient_conf.int_chan; + accel_settin[0].param.orient.orient_int_dur = test_orient_conf.orient_int_dur; + accel_settin[0].param.orient.orient_thres = test_orient_conf.orient_thres; + accel_settin[0].param.orient.ref_update = test_orient_conf.ref_update; + accel_settin[0].param.orient.stability_thres = test_orient_conf.stability_thres; + accel_settin[0].param.orient.orient_ref_x = test_orient_conf.orient_ref_x; + accel_settin[0].param.orient.orient_ref_y = test_orient_conf.orient_ref_y; + accel_settin[0].param.orient.orient_ref_z = test_orient_conf.orient_ref_z; + + accel_settin[1].param.accel.odr = BMA400_ODR_100HZ; + accel_settin[1].param.accel.range = BMA400_RANGE_2G; + accel_settin[1].param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1; + + rslt = bma400_set_sensor_conf(accel_settin, 2, dev); + bma400_check_rslt("bma400_set_sensor_conf", rslt); + + rslt = bma400_set_power_mode(BMA400_MODE_NORMAL, dev); + bma400_check_rslt("bma400_set_power_mode", rslt); + + int_en[0].type = BMA400_ORIENT_CHANGE_INT_EN; + int_en[0].conf = BMA400_ENABLE; + + int_en[1].type = BMA400_LATCH_INT_EN; + int_en[1].conf = BMA400_ENABLE; + + rslt = bma400_enable_interrupt(int_en, 2, dev); + bma400_check_rslt("bma400_enable_interrupt", rslt); + + accel_settin[0].param.orient.axes_sel = 0; + accel_settin[0].param.orient.data_src = 0; + accel_settin[0].param.orient.int_chan = 0; + accel_settin[0].param.orient.orient_int_dur = 0; + accel_settin[0].param.orient.orient_thres = 0; + accel_settin[0].param.orient.ref_update = 0; + accel_settin[0].param.orient.stability_thres = 0; + accel_settin[0].param.orient.orient_ref_x = 0; + accel_settin[0].param.orient.orient_ref_y = 0; + accel_settin[0].param.orient.orient_ref_z = 0; + + rslt = bma400_get_sensor_conf(accel_settin, 1, dev); + bma400_check_rslt("bma400_interface_init", rslt); + + printf("Shake board for Orientation change interrupt\n"); + + while (1) + { + rslt = bma400_get_sensor_conf(accel_settin, 1, dev); + bma400_check_rslt("bma400_interface_init", rslt); + + rslt = bma400_get_interrupt_status(&int_status, dev); + bma400_check_rslt("bma400_interface_init", rslt); + + if (int_status & BMA400_ASSERTED_ORIENT_CH) + { + printf("Orientation interrupt detected\n"); + + if (orient_cnter == 0) + { + printf("Reference : X: %d Y : %d Z : %d\n", + accel_settin[0].param.orient.orient_ref_x, + accel_settin[0].param.orient.orient_ref_y, + accel_settin[0].param.orient.orient_ref_z); + } + + rslt = bma400_get_accel_data(BMA400_DATA_ONLY, &accel, dev); + if (rslt == BMA400_OK) + { + printf("Accel data : X : %d Y : %d Z : %d\n", accel.x, accel.y, accel.z); + } + + orient_cnter++; + } + + /* Loop breaker */ + if (orient_cnter >= BMA400_INT_COUNTER) + { + printf("Orientation interrupt test done. Exiting!\n"); + break; + } + } +} + +int main(int argc, char const *argv[]) +{ + struct bma400_dev bma; + + int8_t rslt = 0; + + struct bma400_orient_int_conf test_orient_conf = { 0 }; + + /* Interface reference is given as a parameter + * For I2C : BMA400_I2C_INTF + * For SPI : BMA400_SPI_INTF + */ + rslt = bma400_interface_init(&bma, BMA400_SPI_INTF); + bma400_check_rslt("bma400_interface_init", rslt); + + rslt = bma400_soft_reset(&bma); + bma400_check_rslt("bma400_soft_reset", rslt); + + rslt = bma400_init(&bma); + bma400_check_rslt("bma400_init", rslt); + + printf("Orient change interrupt with XYZ Axes enabled\n"); + test_orient_conf.axes_sel = BMA400_AXIS_XYZ_EN; + test_orient_conf.data_src = BMA400_DATA_SRC_ACC_FILT1; + test_orient_conf.int_chan = BMA400_INT_CHANNEL_2; + test_orient_conf.orient_int_dur = 7; /* 10ms/LSB */ + test_orient_conf.orient_thres = 125; /* 1 LSB = 8mg */ + test_orient_conf.ref_update = BMA400_ORIENT_REFU_ACC_FILT_2; + test_orient_conf.stability_thres = 10; /* 1 LSB = 8mg */ + + test_bma400_orient_feature_int(test_orient_conf, &bma); + + printf("Orient change interrupt with Y Axis enabled\n"); + test_orient_conf.axes_sel = BMA400_AXIS_Y_EN; + test_orient_conf.data_src = BMA400_DATA_SRC_ACC_FILT2; + test_orient_conf.int_chan = BMA400_UNMAP_INT_PIN; + test_orient_conf.orient_int_dur = 7; /* 10ms/LSB */ + test_orient_conf.orient_thres = 125; /* 1 LSB = 8mg */ + test_orient_conf.stability_thres = 10; /* 1 LSB = 8mg */ + + test_bma400_orient_feature_int(test_orient_conf, &bma); + + printf("Orient change interrupt with X Axis enabled\n"); + test_orient_conf.axes_sel = BMA400_AXIS_X_EN; + test_orient_conf.data_src = BMA400_DATA_SRC_ACC_FILT2; + test_orient_conf.int_chan = BMA400_MAP_BOTH_INT_PINS; + test_orient_conf.orient_int_dur = 7; /* 10ms/LSB */ + test_orient_conf.orient_thres = 100; /* 1 LSB = 8mg */ + test_orient_conf.ref_update = BMA400_ORIENT_REFU_ACC_FILT_2; + test_orient_conf.stability_thres = 10; /* 1 LSB = 8mg */ + + test_bma400_orient_feature_int(test_orient_conf, &bma); + + printf("Orient change interrupt with Z Axis enabled\n"); + test_orient_conf.axes_sel = BMA400_AXIS_Z_EN; + test_orient_conf.data_src = BMA400_DATA_SRC_ACC_FILT2; + test_orient_conf.int_chan = BMA400_INT_CHANNEL_1; + test_orient_conf.orient_int_dur = 7; /* 10ms/LSB */ + test_orient_conf.orient_thres = 125; /* 1 LSB = 8mg */ + test_orient_conf.ref_update = BMA400_ORIENT_REFU_ACC_FILT_2; + test_orient_conf.stability_thres = 10; /* 1 LSB = 8mg */ + + test_bma400_orient_feature_int(test_orient_conf, &bma); + + /* Manual update of ref value is reflected while we read only when we enable that specific axes */ + + printf("Orient change interrupt with Z Axis enabled and manual update\n"); + test_orient_conf.axes_sel = BMA400_AXIS_Z_EN; + test_orient_conf.data_src = BMA400_DATA_SRC_ACC_FILT2; + test_orient_conf.int_chan = BMA400_INT_CHANNEL_1; + test_orient_conf.orient_int_dur = 7; /* 10ms/LSB */ + test_orient_conf.orient_thres = 125; /* 1 LSB = 8mg */ + test_orient_conf.ref_update = BMA400_UPDATE_MANUAL; + test_orient_conf.stability_thres = 10; /* 1 LSB = 8mg */ + test_orient_conf.orient_ref_x = 200; + test_orient_conf.orient_ref_y = 300; + test_orient_conf.orient_ref_z = 2000; + + test_bma400_orient_feature_int(test_orient_conf, &bma); + + bma400_coines_deinit(); + + return rslt; +} diff --git a/examples/self_test.c b/examples/self_test.c deleted file mode 100644 index 7023414..0000000 --- a/examples/self_test.c +++ /dev/null @@ -1,120 +0,0 @@ -#include -#include "bma400.h" - -void set_interface(enum bma400_intf intf, struct bma400_dev *dev); -void delay_ms(uint32_t period); -int8_t i2c_reg_write(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t i2c_reg_read(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t spi_reg_write(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t spi_reg_read(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -void print_rslt(int8_t rslt); - -int main(int argc, char const *argv[]) -{ - struct bma400_dev bma; - int8_t rslt; - - set_interface(BMA400_SPI_INTF, &bma); - - rslt = bma400_init(&bma); - print_rslt(rslt); - - rslt = bma400_soft_reset(&bma); - print_rslt(rslt); - - rslt = bma400_perform_self_test(&bma); - print_rslt(rslt); - - if (rslt == BMA400_OK) - { - printf("Self test passed.\r\n"); - } - - return 0; -} - -void set_interface(enum bma400_intf intf, struct bma400_dev *dev) -{ - switch (intf) - { - case BMA400_I2C_INTF: - dev->intf_ptr = NULL; /* To attach your interface device reference */ - dev->delay_ms = delay_ms; - dev->dev_id = BMA400_I2C_ADDRESS_SDO_LOW; - dev->read = i2c_reg_read; - dev->write = i2c_reg_write; - dev->intf = BMA400_I2C_INTF; - break; - case BMA400_SPI_INTF: - dev->intf_ptr = NULL; /* To attach your interface device reference */ - dev->dev_id = 0; /* Could be used to identify the chip select line. */ - dev->read = spi_reg_read; - dev->write = spi_reg_write; - dev->intf = BMA400_SPI_INTF; - break; - default: - printf("Interface not supported.\r\n"); - } -} - -void delay_ms(uint32_t period) -{ - /* Wait for a period amount of ms*/ -} - -int8_t i2c_reg_write(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Write to registers using I2C. Return 0 for a successful execution. */ - return -1; -} - -int8_t i2c_reg_read(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Read from registers using I2C. Return 0 for a successful execution. */ - return -1; -} - -int8_t spi_reg_write(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Write to registers using SPI. Return 0 for a successful execution. */ - return -1; -} - -int8_t spi_reg_read(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Read from registers using SPI. Return 0 for a successful execution. */ - return -1; -} - -void print_rslt(int8_t rslt) -{ - switch (rslt) - { - case BMA400_OK: - - /* Do nothing */ - break; - case BMA400_E_NULL_PTR: - printf("Error [%d] : Null pointer\r\n", rslt); - break; - case BMA400_E_COM_FAIL: - printf("Error [%d] : Communication failure\r\n", rslt); - break; - case BMA400_E_DEV_NOT_FOUND: - printf("Error [%d] : Device not found\r\n", rslt); - break; - case BMA400_E_INVALID_CONFIG: - printf("Error [%d] : Invalid configuration\r\n", rslt); - break; - case BMA400_W_SELF_TEST_FAIL: - printf("Warning [%d] : Self test failed\r\n", rslt); - break; - default: - printf("Error [%d] : Unknown error code\r\n", rslt); - break; - } -} diff --git a/examples/selftest/Makefile b/examples/selftest/Makefile new file mode 100644 index 0000000..9c25ca8 --- /dev/null +++ b/examples/selftest/Makefile @@ -0,0 +1,15 @@ +COINES_INSTALL_PATH ?= ../../../.. + +EXAMPLE_FILE ?= selftest.c + +API_LOCATION ?= ../.. + +C_SRCS += \ +$(API_LOCATION)/bma400.c \ +../common/common.c + +INCLUDEPATHS += \ +$(API_LOCATION) \ +../common + +include $(COINES_INSTALL_PATH)/coines.mk \ No newline at end of file diff --git a/examples/selftest/selftest.c b/examples/selftest/selftest.c new file mode 100644 index 0000000..4375139 --- /dev/null +++ b/examples/selftest/selftest.c @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2020 Bosch Sensortec GmbH + * + * The license is available at root folder + * + */ + +/*! + * @ingroup bma400Examples + * @defgroup bma400ExamplesSelfTest Self test + * @brief Perform accelerometer self test + * \include selftest.c + */ + +#include +#include "bma400.h" +#include "common.h" + +int main(int argc, char const *argv[]) +{ + struct bma400_dev bma; + int8_t rslt; + + /* Interface reference is given as a parameter + * For I2C : BMA400_I2C_INTF + * For SPI : BMA400_SPI_INTF + */ + rslt = bma400_interface_init(&bma, BMA400_I2C_INTF); + bma400_check_rslt("bma400_interface_init", rslt); + + rslt = bma400_init(&bma); + bma400_check_rslt("bma400_init", rslt); + + rslt = bma400_soft_reset(&bma); + bma400_check_rslt("bma400_soft_reset", rslt); + + rslt = bma400_perform_self_test(&bma); + bma400_check_rslt("bma400_perform_self_test", rslt); + + if (rslt == BMA400_OK) + { + printf("\nSelf-test passed.\r\n"); + } + + bma400_coines_deinit(); + + return rslt; +} diff --git a/examples/step_counter.c b/examples/step_counter.c deleted file mode 100644 index 7a54b74..0000000 --- a/examples/step_counter.c +++ /dev/null @@ -1,153 +0,0 @@ -#include -#include "bma400.h" - -void set_interface(enum bma400_intf intf, struct bma400_dev *dev); -void delay_ms(uint32_t period); -int8_t i2c_reg_write(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t i2c_reg_read(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t spi_reg_write(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t spi_reg_read(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -void print_rslt(int8_t rslt); - -int main(int argc, char const *argv[]) -{ - struct bma400_dev bma; - struct bma400_int_enable step_int; - int8_t rslt; - uint8_t test_dur = 30; - uint32_t step_count; - uint8_t activity; - - set_interface(BMA400_SPI_INTF, &bma); - - rslt = bma400_init(&bma); - print_rslt(rslt); - - rslt = bma400_soft_reset(&bma); - print_rslt(rslt); - - step_int.type = BMA400_STEP_COUNTER_INT_EN; - step_int.conf = BMA400_ENABLE; - - rslt = bma400_enable_interrupt(&step_int, 1, &bma); - print_rslt(rslt); - - rslt = bma400_set_power_mode(BMA400_NORMAL_MODE, &bma); - print_rslt(rslt); - - printf("Steps counted, Activity classifier\r\n"); - - while (test_dur) - { - bma.delay_ms(1000); - - rslt = bma400_get_steps_counted(&step_count, &activity, &bma); - printf("%ld", step_count); - - switch (activity) - { - case BMA400_STILL_ACT: - printf(", Still\r\n"); - break; - case BMA400_WALK_ACT: - printf(", Walking\r\n"); - break; - case BMA400_RUN_ACT: - printf(", Running\r\n"); - break; - default: - printf(", undefined\r\n"); - break; - } - - test_dur--; - } - - return 0; -} - -void set_interface(enum bma400_intf intf, struct bma400_dev *dev) -{ - switch (intf) - { - case BMA400_I2C_INTF: - dev->intf_ptr = NULL; /* To attach your interface device reference */ - dev->delay_ms = delay_ms; - dev->dev_id = BMA400_I2C_ADDRESS_SDO_LOW; - dev->read = i2c_reg_read; - dev->write = i2c_reg_write; - dev->intf = BMA400_I2C_INTF; - break; - case BMA400_SPI_INTF: - dev->intf_ptr = NULL; /* To attach your interface device reference */ - dev->dev_id = 0; /* Could be used to identify the chip select line. */ - dev->read = spi_reg_read; - dev->write = spi_reg_write; - dev->intf = BMA400_SPI_INTF; - break; - default: - printf("Interface not supported.\r\n"); - } -} - -void delay_ms(uint32_t period) -{ - /* Wait for a period amount of ms*/ -} - -int8_t i2c_reg_write(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Write to registers using I2C. Return 0 for a successful execution. */ - return -1; -} - -int8_t i2c_reg_read(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Read from registers using I2C. Return 0 for a successful execution. */ - return -1; -} - -int8_t spi_reg_write(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Write to registers using SPI. Return 0 for a successful execution. */ - return -1; -} - -int8_t spi_reg_read(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Read from registers using SPI. Return 0 for a successful execution. */ - return -1; -} - -void print_rslt(int8_t rslt) -{ - switch (rslt) - { - case BMA400_OK: - - /* Do nothing */ - break; - case BMA400_E_NULL_PTR: - printf("Error [%d] : Null pointer\r\n", rslt); - break; - case BMA400_E_COM_FAIL: - printf("Error [%d] : Communication failure\r\n", rslt); - break; - case BMA400_E_DEV_NOT_FOUND: - printf("Error [%d] : Device not found\r\n", rslt); - break; - case BMA400_E_INVALID_CONFIG: - printf("Error [%d] : Invalid configuration\r\n", rslt); - break; - case BMA400_W_SELF_TEST_FAIL: - printf("Warning [%d] : Self test failed\r\n", rslt); - break; - default: - printf("Error [%d] : Unknown error code\r\n", rslt); - break; - } -} diff --git a/examples/step_counter/Makefile b/examples/step_counter/Makefile new file mode 100644 index 0000000..bfedb5c --- /dev/null +++ b/examples/step_counter/Makefile @@ -0,0 +1,15 @@ +COINES_INSTALL_PATH ?= ../../../.. + +EXAMPLE_FILE ?= step_counter.c + +API_LOCATION ?= ../.. + +C_SRCS += \ +$(API_LOCATION)/bma400.c \ +../common/common.c + +INCLUDEPATHS += \ +$(API_LOCATION) \ +../common + +include $(COINES_INSTALL_PATH)/coines.mk \ No newline at end of file diff --git a/examples/step_counter/step_counter.c b/examples/step_counter/step_counter.c new file mode 100644 index 0000000..e1cc50c --- /dev/null +++ b/examples/step_counter/step_counter.c @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2020 Bosch Sensortec GmbH + * + * The license is available at root folder + * + */ + +/*! + * @ingroup bma400Examples + * @defgroup bma400ExamplesStepCounter Step counter + * @brief To showcase step counter feature + * \include bma400_step_counter.c + */ + +#include +#include "bma400.h" +#include "common.h" + +int main(int argc, char const *argv[]) +{ + int8_t rslt = 0; + + struct bma400_dev bma; + struct bma400_sensor_conf accel_settin[2] = { { 0 } }; + struct bma400_int_enable int_en[2]; + + uint16_t int_status; + + uint32_t step_count = 0; + uint8_t act_int; + + uint8_t count = 10; + + /* Interface reference is given as a parameter + * For I2C : BMA400_I2C_INTF + * For SPI : BMA400_SPI_INTF + */ + rslt = bma400_interface_init(&bma, BMA400_I2C_INTF); + bma400_check_rslt("bma400_interface_init", rslt); + + rslt = bma400_soft_reset(&bma); + bma400_check_rslt("bma400_soft_reset", rslt); + + rslt = bma400_init(&bma); + bma400_check_rslt("bma400_init", rslt); + + accel_settin[0].type = BMA400_STEP_COUNTER_INT; + accel_settin[1].type = BMA400_ACCEL; + + rslt = bma400_get_sensor_conf(accel_settin, 2, &bma); + bma400_check_rslt("bma400_get_sensor_conf", rslt); + + accel_settin[0].param.step_cnt.int_chan = BMA400_INT_CHANNEL_1; + + accel_settin[1].param.accel.odr = BMA400_ODR_100HZ; + accel_settin[1].param.accel.range = BMA400_RANGE_2G; + accel_settin[1].param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1; + + /* Set the desired configurations to the sensor */ + rslt = bma400_set_sensor_conf(accel_settin, 2, &bma); + bma400_check_rslt("bma400_set_sensor_conf", rslt); + + rslt = bma400_set_power_mode(BMA400_MODE_NORMAL, &bma); + bma400_check_rslt("bma400_set_power_mode", rslt); + + int_en[0].type = BMA400_STEP_COUNTER_INT_EN; + int_en[0].conf = BMA400_ENABLE; + + int_en[1].type = BMA400_LATCH_INT_EN; + int_en[1].conf = BMA400_ENABLE; + + rslt = bma400_enable_interrupt(int_en, 2, &bma); + bma400_check_rslt("bma400_enable_interrupt", rslt); + + printf("Shake the board in terms of steps\n"); + + while (1) + { + rslt = bma400_get_interrupt_status(&int_status, &bma); + bma400_check_rslt("bma400_get_interrupt_status", rslt); + + if (int_status & BMA400_ASSERTED_STEP_INT) + { + rslt = bma400_get_steps_counted(&step_count, &act_int, &bma); + bma400_check_rslt("bma400_get_steps_counted", rslt); + + switch (act_int) + { + case BMA400_STILL_ACT: + printf("Step counter interrupt received\n"); + printf("Steps counted : %ld\n", step_count); + printf("Still Activity detected\n"); + count--; + break; + case BMA400_WALK_ACT: + printf("Step counter interrupt received\n"); + printf("Steps counted : %ld\n", step_count); + printf("Walking Activity detected\n"); + count--; + break; + case BMA400_RUN_ACT: + printf("Step counter interrupt received\n"); + printf("Steps counted : %ld\n", step_count); + printf("Running Activity detected\n"); + count--; + break; + } + if (count == 0) + { + break; + } + } + } + + bma400_coines_deinit(); + + return rslt; +} diff --git a/examples/tap_detection.c b/examples/tap_detection.c deleted file mode 100644 index 5df1e1d..0000000 --- a/examples/tap_detection.c +++ /dev/null @@ -1,178 +0,0 @@ -#include -#include "bma400.h" - -void set_interface(enum bma400_intf intf, struct bma400_dev *dev); -void delay_ms(uint32_t period); -int8_t i2c_reg_write(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t i2c_reg_read(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t spi_reg_write(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -int8_t spi_reg_read(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); -void print_rslt(int8_t rslt); - -int main(int argc, char const *argv[]) -{ - struct bma400_dev bma; - struct bma400_int_enable tap_int[2]; - struct bma400_sensor_conf conf[2]; - int8_t rslt; - uint32_t poll_period = 5, test_dur_ms = 30000; - uint16_t int_status; - - set_interface(BMA400_SPI_INTF, &bma); - - rslt = bma400_init(&bma); - print_rslt(rslt); - - rslt = bma400_soft_reset(&bma); - print_rslt(rslt); - - conf[0].type = BMA400_ACCEL; - conf[1].type = BMA400_TAP_INT; - - rslt = bma400_get_sensor_conf(conf, 2, &bma); - print_rslt(rslt); - - conf[0].param.accel.odr = BMA400_ODR_200HZ; - conf[0].param.accel.range = BMA400_4G_RANGE; - conf[0].param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1; - conf[0].param.accel.filt1_bw = BMA400_ACCEL_FILT1_BW_1; - - conf[1].param.tap.int_chan = BMA400_UNMAP_INT_PIN; - conf[1].param.tap.axes_sel = BMA400_Z_AXIS_EN_TAP; - conf[1].param.tap.sensitivity = BMA400_TAP_SENSITIVITY_0; - - rslt = bma400_set_sensor_conf(conf, 2, &bma); - print_rslt(rslt); - - bma.delay_ms(100); - - tap_int[0].type = BMA400_SINGLE_TAP_INT_EN; - tap_int[0].conf = BMA400_ENABLE; - - tap_int[1].type = BMA400_DOUBLE_TAP_INT_EN; - tap_int[1].conf = BMA400_ENABLE; - - rslt = bma400_enable_interrupt(tap_int, 2, &bma); - print_rslt(rslt); - - bma.delay_ms(100); - - rslt = bma400_set_power_mode(BMA400_NORMAL_MODE, &bma); - print_rslt(rslt); - - bma.delay_ms(100); - - if (rslt == BMA400_OK) - { - printf("Tap configured.\r\n"); - - while (test_dur_ms) - { - bma.delay_ms(poll_period); - - rslt = bma400_get_interrupt_status(&int_status, &bma); - print_rslt(rslt); - - if (int_status & BMA400_S_TAP_INT_ASSERTED) - { - printf("Single tap detected!\r\n"); - } - - if (int_status & BMA400_D_TAP_INT_ASSERTED) - { - printf("Double tap detected!\r\n"); - } - - test_dur_ms -= poll_period; - } - - } - - return 0; -} - -void set_interface(enum bma400_intf intf, struct bma400_dev *dev) -{ - switch (intf) - { - case BMA400_I2C_INTF: - dev->intf_ptr = NULL; /* To attach your interface device reference */ - dev->delay_ms = delay_ms; - dev->dev_id = BMA400_I2C_ADDRESS_SDO_LOW; - dev->read = i2c_reg_read; - dev->write = i2c_reg_write; - dev->intf = BMA400_I2C_INTF; - break; - case BMA400_SPI_INTF: - dev->intf_ptr = NULL; /* To attach your interface device reference */ - dev->dev_id = 0; /* Could be used to identify the chip select line. */ - dev->read = spi_reg_read; - dev->write = spi_reg_write; - dev->intf = BMA400_SPI_INTF; - break; - default: - printf("Interface not supported.\r\n"); - } -} - -void delay_ms(uint32_t period) -{ - /* Wait for a period amount of ms*/ -} - -int8_t i2c_reg_write(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Write to registers using I2C. Return 0 for a successful execution. */ - return -1; -} - -int8_t i2c_reg_read(void *intf_ptr, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Read from registers using I2C. Return 0 for a successful execution. */ - return -1; -} - -int8_t spi_reg_write(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Write to registers using SPI. Return 0 for a successful execution. */ - return -1; -} - -int8_t spi_reg_read(void *intf_ptr, uint8_t cs, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) -{ - - /* Read from registers using SPI. Return 0 for a successful execution. */ - return -1; -} - -void print_rslt(int8_t rslt) -{ - switch (rslt) - { - case BMA400_OK: - - /* Do nothing */ - break; - case BMA400_E_NULL_PTR: - printf("Error [%d] : Null pointer\r\n", rslt); - break; - case BMA400_E_COM_FAIL: - printf("Error [%d] : Communication failure\r\n", rslt); - break; - case BMA400_E_DEV_NOT_FOUND: - printf("Error [%d] : Device not found\r\n", rslt); - break; - case BMA400_E_INVALID_CONFIG: - printf("Error [%d] : Invalid configuration\r\n", rslt); - break; - case BMA400_W_SELF_TEST_FAIL: - printf("Warning [%d] : Self test failed\r\n", rslt); - break; - default: - printf("Error [%d] : Unknown error code\r\n", rslt); - break; - } -} diff --git a/examples/tap_detection/Makefile b/examples/tap_detection/Makefile new file mode 100644 index 0000000..5d35cf8 --- /dev/null +++ b/examples/tap_detection/Makefile @@ -0,0 +1,15 @@ +COINES_INSTALL_PATH ?= ../../../.. + +EXAMPLE_FILE ?= tap_detection.c + +API_LOCATION ?= ../.. + +C_SRCS += \ +$(API_LOCATION)/bma400.c \ +../common/common.c + +INCLUDEPATHS += \ +$(API_LOCATION) \ +../common + +include $(COINES_INSTALL_PATH)/coines.mk \ No newline at end of file diff --git a/examples/tap_detection/tap_detection.c b/examples/tap_detection/tap_detection.c new file mode 100644 index 0000000..0fdb059 --- /dev/null +++ b/examples/tap_detection/tap_detection.c @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2020 Bosch Sensortec GmbH + * + * The license is available at root folder + * + */ + +/*! + * @ingroup bma400Examples + * @defgroup bma400ExamplesTapDetection Tap detection + * @brief To showcase tap detection feature + * \include tap_detection.c + */ + +#include +#include "bma400.h" +#include "common.h" + +int main(int argc, char const *argv[]) +{ + struct bma400_dev bma; + + int8_t rslt = 0; + uint16_t int_status = 0; + int8_t count = 0; + + struct bma400_sensor_conf conf[2] = { { 0 } }; + struct bma400_int_enable int_en[2]; + + /* Interface reference is given as a parameter + * For I2C : BMA400_I2C_INTF + * For SPI : BMA400_SPI_INTF + */ + rslt = bma400_interface_init(&bma, BMA400_SPI_INTF); + bma400_check_rslt("bma400_interface_init", rslt); + + rslt = bma400_soft_reset(&bma); + bma400_check_rslt("bma400_soft_reset", rslt); + + rslt = bma400_init(&bma); + bma400_check_rslt("bma400_init", rslt); + + conf[0].type = BMA400_ACCEL; + conf[1].type = BMA400_TAP_INT; + + rslt = bma400_get_sensor_conf(conf, 2, &bma); + bma400_check_rslt("bma400_get_sensor_conf", rslt); + + conf[0].param.accel.odr = BMA400_ODR_200HZ; + conf[0].param.accel.range = BMA400_RANGE_16G; + conf[0].param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1; + conf[0].param.accel.filt1_bw = BMA400_ACCEL_FILT1_BW_1; + + conf[1].param.tap.int_chan = BMA400_INT_CHANNEL_1; + conf[1].param.tap.axes_sel = BMA400_TAP_X_AXIS_EN | BMA400_TAP_Y_AXIS_EN | BMA400_TAP_Z_AXIS_EN; + conf[1].param.tap.sensitivity = BMA400_TAP_SENSITIVITY_0; + conf[1].param.tap.tics_th = BMA400_TICS_TH_6_DATA_SAMPLES; + conf[1].param.tap.quiet = BMA400_QUIET_60_DATA_SAMPLES; + conf[1].param.tap.quiet_dt = BMA400_QUIET_DT_4_DATA_SAMPLES; + + rslt = bma400_set_sensor_conf(conf, 2, &bma); + bma400_check_rslt("bma400_set_sensor_conf", rslt); + + rslt = bma400_set_power_mode(BMA400_MODE_NORMAL, &bma); + bma400_check_rslt("bma400_set_power_mode", rslt); + + int_en[0].type = BMA400_SINGLE_TAP_INT_EN; + int_en[0].conf = BMA400_ENABLE; + + int_en[1].type = BMA400_DOUBLE_TAP_INT_EN; + int_en[1].conf = BMA400_ENABLE; + + rslt = bma400_enable_interrupt(int_en, 2, &bma); + bma400_check_rslt("bma400_enable_interrupt", rslt); + + printf("Single and Double Tap interrupts enabled\n"); + printf("Perform single or double tap on the board\n"); + + while (1) + { + rslt = bma400_get_interrupt_status(&int_status, &bma); + bma400_check_rslt("bma400_get_interrupt_status", rslt); + + if (rslt == BMA400_OK) + { + if (int_status & BMA400_ASSERTED_S_TAP_INT) + { + printf("Single tap detected\n"); + count++; + } + + if (int_status & BMA400_ASSERTED_D_TAP_INT) + { + printf("Double tap detected\n"); + count++; + } + + if (count == 5) + { + printf("Tap interrupt testing done. Exiting !\n"); + break; + } + } + } + + bma400_coines_deinit(); + + return rslt; +}