Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion src/Arduino_Nesso_N1.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "Wire.h"
#include <M5GFX.h>
#include <lgfx/v1/panel/Panel_ST7789.hpp>
//#include "Arduino_BMI270_BMM150.h"
#include "Arduino_BMI270_BMM150.h"

#undef LORA_LNA_ENABLE
#undef LORA_ANTENNA_SWITCH
Expand Down Expand Up @@ -250,5 +250,67 @@ class NessoTouch {
}
};

class MyBoschSensor: public BoschSensorClass {

public:
MyBoschSensor(TwoWire& wire = Wire) : BoschSensorClass(wire) {};
bool begin() {
return BoschSensorClass::begin(BOSCH_ACCELEROMETER_ONLY);
}

protected:
virtual int8_t configure_sensor(struct bmi2_dev *dev)
{
int8_t rslt;
uint8_t sens_list[2] = { BMI2_ACCEL, BMI2_GYRO };

// This configures the second gpio expander and clears its interrupt status
pinMode(LORA_ENABLE, INPUT);

struct bmi2_int_pin_config int_pin_cfg;
int_pin_cfg.pin_type = BMI2_INT1;
int_pin_cfg.int_latch = BMI2_INT_LATCH;
int_pin_cfg.pin_cfg[0].lvl = BMI2_INT_ACTIVE_LOW;
int_pin_cfg.pin_cfg[0].od = BMI2_INT_PUSH_PULL;
int_pin_cfg.pin_cfg[0].output_en = BMI2_INT_OUTPUT_ENABLE;
int_pin_cfg.pin_cfg[0].input_en = BMI2_INT_INPUT_DISABLE;

struct bmi2_sens_config sens_cfg[2];
sens_cfg[0].type = BMI2_ACCEL;
sens_cfg[0].cfg.acc.bwp = BMI2_ACC_OSR2_AVG2;
sens_cfg[0].cfg.acc.odr = BMI2_ACC_ODR_25HZ;
sens_cfg[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
sens_cfg[0].cfg.acc.range = BMI2_ACC_RANGE_4G;
sens_cfg[1].type = BMI2_GYRO;
sens_cfg[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
sens_cfg[1].cfg.gyr.bwp = BMI2_GYR_OSR2_MODE;
sens_cfg[1].cfg.gyr.odr = BMI2_GYR_ODR_25HZ;
sens_cfg[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
sens_cfg[1].cfg.gyr.ois_range = BMI2_GYR_OIS_2000;

rslt = bmi2_set_int_pin_config(&int_pin_cfg, dev);
if (rslt != BMI2_OK)
return rslt;

rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, dev);
if (rslt != BMI2_OK)
return rslt;

rslt = bmi2_set_sensor_config(sens_cfg, 2, dev);
if (rslt != BMI2_OK)
return rslt;

rslt = bmi2_sensor_enable(sens_list, 2, dev);
if (rslt != BMI2_OK)
return rslt;

return rslt;
}
};

extern MyBoschSensor myIMU;
#undef IMU
#define IMU myIMU

#endif
#endif
6 changes: 6 additions & 0 deletions src/expander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
static bool wireInitialized = true;
bool ExpanderPin::_initialized[2] = {false, false};

MyBoschSensor myIMU(Wire);

// IO expander datasheet from https://www.diodes.com/datasheet/download/PI4IOE5V6408.pdf
// Battery charger datasheet from https://www.awinic.com/en/productDetail/AW32001ACSR
// battery gauge datasheet from https://www.ti.com/product/BQ27220
Expand Down Expand Up @@ -40,13 +42,17 @@ void pinMode(ExpanderPin pin, uint8_t mode) {
if (!pin.initialized()) {
Wire.begin();
// reset all registers to default state
readRegister(pin.address, 0x1);
writeRegister(pin.address, 0x1, 0x1);
readRegister(pin.address, 0x1);
// set all pins as high as default state
writeRegister(pin.address, 0x9, 0xFF);
// interrupt mask to all pins
writeRegister(pin.address, 0x11, 0xFF);
// all input
writeRegister(pin.address, 0x3, 0);
// clear interrupt status
readRegister(pin.address, 0x13);
pin.initialize();
}
writeBitRegister(pin.address, 0x3, pin.pin, mode == OUTPUT);
Expand Down