06-29-2022 11:32 PM
Hello,
starting from standard kernel module from MangoH (here is original code), I'm tring to enable both INTerrupts of BMI160,
INT1 must signal anymotion/significant motion
INT2 must signal Step Detect
I've added parts in bold to following code, but it seems not working.. someone maybe already done and can help.
Regads,
Gian
static int bmi160_setup_sigmot_int(struct bmi160_data *data) {
int ret = 0;
Route any motion/significant motion interrupt to int1
ret = regmap_write(
data->regmap,
BMI160_REG_INT_MAP_0,
BMI160_INT_MAP_0_INT1_ANYM_SIGMOT); //route anymotion to INT1
if (ret < 0)
return ret;
ret = regmap_write(
data->regmap,
BMI160_REG_INT_MAP_1,
0);
if (ret < 0)
return ret;
//Route Single Tap interrupt to int2
ret = regmap_write(
data->regmap,
BMI160_REG_INT_MAP_2,
BMI160_INT_MAP_2_INT2_STAP); //route single tap to INT2
if (ret < 0)
return ret;
ret = regmap_write(
data->regmap,
BMI160_REG_INT_LATCH,
(FIELD_PREP(BMI160_INT_LATCH_MODE,
BMI160_INT_LATCH_MODE_TMP_2560_MS)));
if (ret < 0)
return ret;
//Enable edge interrupt on INT1 pin
ret = regmap_write(
data->regmap,
BMI160_REG_INT_OUT_CTRL,
(BMI160_INT_OUT_CTRL_INT1_EDGE |
BMI160_INT_OUT_CTRL_INT1_LVL |
BMI160_INT_OUT_CTRL_INT1_OUTPUT_EN));
if (ret < 0)
return ret;
// Enable edge interrupt on INT2 pin
ret = regmap_write(
data->regmap,
BMI160_REG_INT_OUT_CTRL,
(BMI160_INT_OUT_CTRL_INT2_EDGE |
BMI160_INT_OUT_CTRL_INT2_LVL |
BMI160_INT_OUT_CTRL_INT2_OUTPUT_EN));
if (ret < 0)
return ret;
ret = regmap_write(
data->regmap,
BMI160_REG_INT_EN_0,
(BMI160_INT_EN_0_ANYM_X|
BMI160_INT_EN_0_ANYM_Y|
BMI160_INT_EN_0_ANYM_Z));
if (ret < 0)
return ret;
return ret;
}
06-30-2022 03:47 AM
Hi gianmariai,
It is recommended that you refer to the sensor API to configure the sensor BMI160. This is a reference example.
https://github.com/BoschSensortec/BMI160_driver/blob/master/examples/tap/tap.c
Open_BMI160_TAP(dev, BMI160_ENABLE);
Enable_MCU_INT1_Pin();
int8_t Open_BMI160_TAP(struct bmi160_dev *dev, uint8_t feature_enable)
{
int8_t rslt = BMI160_OK;
struct bmi160_int_settg int_config;
if (feature_enable > 0)
{
/* Select the Interrupt channel/pin */
int_config.int_channel = BMI160_INT_CHANNEL_1; /* Interrupt channel/pin 1 */
/* Select the interrupt channel/pin settings */
int_config.int_pin_settg.output_en = BMI160_ENABLE; /* Enabling interrupt pins to act as output pin */
int_config.int_pin_settg.output_mode = BMI160_DISABLE; /* Choosing push-pull mode for interrupt pin */
int_config.int_pin_settg.output_type = BMI160_ENABLE; /* Choosing active low output */
int_config.int_pin_settg.edge_ctrl = BMI160_DISABLE; /* Choosing edge triggered output */
int_config.int_pin_settg.input_en = BMI160_DISABLE; /* Disabling interrupt pin to act as input */
int_config.int_pin_settg.latch_dur = BMI160_LATCH_DUR_NONE; /* non-latched output */
/* Select the Interrupt type */
int_config.int_type = BMI160_ACC_SINGLE_TAP_INT; /* Choosing tap interrupt */
/* Select the Any-motion interrupt parameters */
int_config.int_type_cfg.acc_tap_int.tap_en = BMI160_ENABLE; /* 1- Enable tap, 0- disable tap */
int_config.int_type_cfg.acc_tap_int.tap_thr = 2; /* Set tap threshold */
int_config.int_type_cfg.acc_tap_int.tap_dur = 2; /* Set tap duration */
int_config.int_type_cfg.acc_tap_int.tap_shock = 0; /* Set tap shock value */
int_config.int_type_cfg.acc_tap_int.tap_quiet = 0; /* Set tap quiet duration */
int_config.int_type_cfg.acc_tap_int.tap_data_src=1; /* data source 0 : filter or 1 : pre-filter */
/* Set the Any-motion interrupt */
rslt = bmi160_set_int_config(&int_config, dev); /* sensor is an instance of the structure bmi160_dev */
PDEBUG("bmi160_set_int_config(tap enable) status:%d\r\n", rslt);
}
else
{
/* Select the Interrupt channel/pin */
int_config.int_channel = BMI160_INT_CHANNEL_1;
int_config.int_pin_settg.output_en = BMI160_DISABLE; /* Disabling interrupt pins to act as output pin */
int_config.int_pin_settg.edge_ctrl = BMI160_DISABLE; /* Choosing edge triggered output */
/* Select the Interrupt type */
int_config.int_type = BMI160_ACC_SINGLE_TAP_INT; /* Choosing Tap interrupt */
int_config.int_type_cfg.acc_tap_int.tap_en = BMI160_DISABLE; /* 1- Enable tap, 0- disable tap */
/* Set the Data ready interrupt */
rslt = bmi160_set_int_config(&int_config, dev); /* sensor is an instance of the structure bmi160_dev */
PDEBUG("bmi160_set_int_config(tap disable) status:%d\r\n", rslt);
}
return rslt;
}