From 8af79aa5a535f59c311a9b0d6d1809b1497fe62f Mon Sep 17 00:00:00 2001 From: "Anders L. Hurum" Date: Tue, 12 Jun 2018 15:00:44 +0200 Subject: [PATCH 1/4] added support for both interrupt channels --- bmi160.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bmi160.c b/bmi160.c index c5df92d..f4cbdaf 100644 --- a/bmi160.c +++ b/bmi160.c @@ -4502,7 +4502,7 @@ static int8_t config_int_out_ctrl(const struct bmi160_int_settg *int_config, con const struct bmi160_int_pin_settg *intr_pin_sett = &(int_config->int_pin_settg); /* Configuring channel 1 */ - if (int_config->int_channel == BMI160_INT_CHANNEL_1) { + if ((int_config->int_channel == BMI160_INT_CHANNEL_1) || (int_config->int_channel == BMI160_INT_CHANNEL_BOTH)) { /* Output enable */ temp = data & ~BMI160_INT1_OUTPUT_EN_MASK; @@ -4519,10 +4519,12 @@ static int8_t config_int_out_ctrl(const struct bmi160_int_settg *int_config, con /* edge control */ temp = data & ~BMI160_INT1_EDGE_CTRL_MASK; data = temp | ((intr_pin_sett->edge_ctrl) & BMI160_INT1_EDGE_CTRL_MASK); + } + + /* Configuring channel 2 */ + if ((int_config->int_channel == BMI160_INT_CHANNEL_2) || (int_config->int_channel == BMI_INT_CHANNEL_BOTH)) { - } else { - /* Configuring channel 2 */ - /* Output enable */ + /* Output enable */ temp = data & ~BMI160_INT2_OUTPUT_EN_MASK; data = temp | ((intr_pin_sett->output_en << 7) & BMI160_INT2_OUTPUT_EN_MASK); From 104705363f9818d92aa97ee2718f79b60321e553 Mon Sep 17 00:00:00 2001 From: "Anders L. Hurum" Date: Tue, 12 Jun 2018 15:05:37 +0200 Subject: [PATCH 2/4] added guard statement on setting int_channel to ensure correct conf --- bmi160.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bmi160.c b/bmi160.c index f4cbdaf..c21f780 100644 --- a/bmi160.c +++ b/bmi160.c @@ -4498,6 +4498,16 @@ static int8_t config_int_out_ctrl(const struct bmi160_int_settg *int_config, con rslt = bmi160_get_regs(BMI160_INT_OUT_CTRL_ADDR, &data, 1, dev); if (rslt == BMI160_OK) { + /* guard statement to ensure a valid pin channel is configured */ + switch (int_config->int_channel){ + case BMI160_INT_CHANNEL_1: + case BMI160_INT_CHANNEL_2: + case BMI160_INT_CHANNEL_BOTH: + break; + default: // invalid pin channel + return BMI160_E_DEV_NOT_FOUND; + } + /* updating the interrupt pin structure to local structure */ const struct bmi160_int_pin_settg *intr_pin_sett = &(int_config->int_pin_settg); From 622cd7eafd3c204d366757d66ee127949a1da223 Mon Sep 17 00:00:00 2001 From: "Anders L. Hurum" Date: Tue, 12 Jun 2018 15:12:08 +0200 Subject: [PATCH 3/4] fix: corrected small typo on preprocessor --- bmi160.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bmi160.c b/bmi160.c index c21f780..ae5a9ad 100644 --- a/bmi160.c +++ b/bmi160.c @@ -4532,7 +4532,7 @@ static int8_t config_int_out_ctrl(const struct bmi160_int_settg *int_config, con } /* Configuring channel 2 */ - if ((int_config->int_channel == BMI160_INT_CHANNEL_2) || (int_config->int_channel == BMI_INT_CHANNEL_BOTH)) { + if ((int_config->int_channel == BMI160_INT_CHANNEL_2) || (int_config->int_channel == BMI160_INT_CHANNEL_BOTH)) { /* Output enable */ temp = data & ~BMI160_INT2_OUTPUT_EN_MASK; From 24faecbc57a9e2e97ca649b70400b79e6c50cdfb Mon Sep 17 00:00:00 2001 From: "Anders L. Hurum" Date: Tue, 12 Jun 2018 15:26:59 +0200 Subject: [PATCH 4/4] ref: ensured proper indentations and style, tested on device After running with this version of drivers and dumping registers, I got the following result: BMI160_INT_OUT_CTRL_ADDR UINT8_C(0x53) :: 0x88 --- bmi160.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/bmi160.c b/bmi160.c index ae5a9ad..8bae5eb 100644 --- a/bmi160.c +++ b/bmi160.c @@ -4498,21 +4498,23 @@ static int8_t config_int_out_ctrl(const struct bmi160_int_settg *int_config, con rslt = bmi160_get_regs(BMI160_INT_OUT_CTRL_ADDR, &data, 1, dev); if (rslt == BMI160_OK) { - /* guard statement to ensure a valid pin channel is configured */ - switch (int_config->int_channel){ - case BMI160_INT_CHANNEL_1: - case BMI160_INT_CHANNEL_2: - case BMI160_INT_CHANNEL_BOTH: - break; - default: // invalid pin channel - return BMI160_E_DEV_NOT_FOUND; - } + + /* guard statement to ensure a valid pin channel is configured */ + switch (int_config->int_channel) { + case BMI160_INT_CHANNEL_1: + case BMI160_INT_CHANNEL_2: + case BMI160_INT_CHANNEL_BOTH: + break; + default: // invalid pin channel + return BMI160_E_DEV_NOT_FOUND; + } /* updating the interrupt pin structure to local structure */ const struct bmi160_int_pin_settg *intr_pin_sett = &(int_config->int_pin_settg); /* Configuring channel 1 */ - if ((int_config->int_channel == BMI160_INT_CHANNEL_1) || (int_config->int_channel == BMI160_INT_CHANNEL_BOTH)) { + if ((int_config->int_channel == BMI160_INT_CHANNEL_1) || + (int_config->int_channel == BMI160_INT_CHANNEL_BOTH)) { /* Output enable */ temp = data & ~BMI160_INT1_OUTPUT_EN_MASK; @@ -4531,10 +4533,11 @@ static int8_t config_int_out_ctrl(const struct bmi160_int_settg *int_config, con data = temp | ((intr_pin_sett->edge_ctrl) & BMI160_INT1_EDGE_CTRL_MASK); } - /* Configuring channel 2 */ - if ((int_config->int_channel == BMI160_INT_CHANNEL_2) || (int_config->int_channel == BMI160_INT_CHANNEL_BOTH)) { + /* Configuring channel 2 */ + if ((int_config->int_channel == BMI160_INT_CHANNEL_2) || + (int_config->int_channel == BMI160_INT_CHANNEL_BOTH)) { - /* Output enable */ + /* Output enable */ temp = data & ~BMI160_INT2_OUTPUT_EN_MASK; data = temp | ((intr_pin_sett->output_en << 7) & BMI160_INT2_OUTPUT_EN_MASK);