Skip to content

Commit fd6eacd

Browse files
authored
Merge pull request #2 from arduino-libraries/bmi2
Enable BMI2 interrupt capabilities
2 parents 03c9dc7 + 0720274 commit fd6eacd

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

src/Arduino_Nesso_N1.h

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "Wire.h"
88
#include <M5GFX.h>
99
#include <lgfx/v1/panel/Panel_ST7789.hpp>
10-
//#include "Arduino_BMI270_BMM150.h"
10+
#include "Arduino_BMI270_BMM150.h"
1111

1212
#undef LORA_LNA_ENABLE
1313
#undef LORA_ANTENNA_SWITCH
@@ -250,5 +250,67 @@ class NessoTouch {
250250
}
251251
};
252252

253+
class MyBoschSensor: public BoschSensorClass {
254+
255+
public:
256+
MyBoschSensor(TwoWire& wire = Wire) : BoschSensorClass(wire) {};
257+
bool begin() {
258+
return BoschSensorClass::begin(BOSCH_ACCELEROMETER_ONLY);
259+
}
260+
261+
protected:
262+
virtual int8_t configure_sensor(struct bmi2_dev *dev)
263+
{
264+
int8_t rslt;
265+
uint8_t sens_list[2] = { BMI2_ACCEL, BMI2_GYRO };
266+
267+
// This configures the second gpio expander and clears its interrupt status
268+
pinMode(LORA_ENABLE, INPUT);
269+
270+
struct bmi2_int_pin_config int_pin_cfg;
271+
int_pin_cfg.pin_type = BMI2_INT1;
272+
int_pin_cfg.int_latch = BMI2_INT_LATCH;
273+
int_pin_cfg.pin_cfg[0].lvl = BMI2_INT_ACTIVE_LOW;
274+
int_pin_cfg.pin_cfg[0].od = BMI2_INT_PUSH_PULL;
275+
int_pin_cfg.pin_cfg[0].output_en = BMI2_INT_OUTPUT_ENABLE;
276+
int_pin_cfg.pin_cfg[0].input_en = BMI2_INT_INPUT_DISABLE;
277+
278+
struct bmi2_sens_config sens_cfg[2];
279+
sens_cfg[0].type = BMI2_ACCEL;
280+
sens_cfg[0].cfg.acc.bwp = BMI2_ACC_OSR2_AVG2;
281+
sens_cfg[0].cfg.acc.odr = BMI2_ACC_ODR_25HZ;
282+
sens_cfg[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
283+
sens_cfg[0].cfg.acc.range = BMI2_ACC_RANGE_4G;
284+
sens_cfg[1].type = BMI2_GYRO;
285+
sens_cfg[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
286+
sens_cfg[1].cfg.gyr.bwp = BMI2_GYR_OSR2_MODE;
287+
sens_cfg[1].cfg.gyr.odr = BMI2_GYR_ODR_25HZ;
288+
sens_cfg[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
289+
sens_cfg[1].cfg.gyr.ois_range = BMI2_GYR_OIS_2000;
290+
291+
rslt = bmi2_set_int_pin_config(&int_pin_cfg, dev);
292+
if (rslt != BMI2_OK)
293+
return rslt;
294+
295+
rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, dev);
296+
if (rslt != BMI2_OK)
297+
return rslt;
298+
299+
rslt = bmi2_set_sensor_config(sens_cfg, 2, dev);
300+
if (rslt != BMI2_OK)
301+
return rslt;
302+
303+
rslt = bmi2_sensor_enable(sens_list, 2, dev);
304+
if (rslt != BMI2_OK)
305+
return rslt;
306+
307+
return rslt;
308+
}
309+
};
310+
311+
extern MyBoschSensor myIMU;
312+
#undef IMU
313+
#define IMU myIMU
314+
253315
#endif
254316
#endif

src/expander.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
static bool wireInitialized = true;
44
bool ExpanderPin::_initialized[2] = {false, false};
55

6+
MyBoschSensor myIMU(Wire);
7+
68
// IO expander datasheet from https://www.diodes.com/datasheet/download/PI4IOE5V6408.pdf
79
// Battery charger datasheet from https://www.awinic.com/en/productDetail/AW32001ACSR
810
// battery gauge datasheet from https://www.ti.com/product/BQ27220
@@ -40,13 +42,17 @@ void pinMode(ExpanderPin pin, uint8_t mode) {
4042
if (!pin.initialized()) {
4143
Wire.begin();
4244
// reset all registers to default state
45+
readRegister(pin.address, 0x1);
4346
writeRegister(pin.address, 0x1, 0x1);
47+
readRegister(pin.address, 0x1);
4448
// set all pins as high as default state
4549
writeRegister(pin.address, 0x9, 0xFF);
4650
// interrupt mask to all pins
4751
writeRegister(pin.address, 0x11, 0xFF);
4852
// all input
4953
writeRegister(pin.address, 0x3, 0);
54+
// clear interrupt status
55+
readRegister(pin.address, 0x13);
5056
pin.initialize();
5157
}
5258
writeBitRegister(pin.address, 0x3, pin.pin, mode == OUTPUT);

0 commit comments

Comments
 (0)