Skip to content
Open
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
14 changes: 13 additions & 1 deletion examples/Interrupts_subclassing/Interrupts_subclassing.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ class MyBoschSensor: public BoschSensorClass {
struct bmi2_int_pin_config int_pin_cfg;
int_pin_cfg.pin_type = BMI2_INT1;
int_pin_cfg.int_latch = BMI2_INT_NON_LATCH;
#if defined(ARDUINO_ARDUINO_NESSO_N1)
int_pin_cfg.pin_cfg[0].lvl = BMI2_INT_ACTIVE_LOW;
#else
int_pin_cfg.pin_cfg[0].lvl = BMI2_INT_ACTIVE_HIGH;
#endif
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;
Expand Down Expand Up @@ -52,7 +56,11 @@ class MyBoschSensor: public BoschSensorClass {
}
};

#if defined(ARDUINO_ARDUINO_NESSO_N1)
MyBoschSensor myIMU(Wire);
#else
MyBoschSensor myIMU(Wire1);
#endif

void print_data() {
// we can also read accelerometer / gyro data here!
Expand All @@ -65,7 +73,11 @@ void setup() {
while (!Serial);
myIMU.debug(Serial);
myIMU.onInterrupt(print_data);
myIMU.begin();
#if defined(ARDUINO_ARDUINO_NESSO_N1)
myIMU.begin(BOSCH_ACCEL_ONLY);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be BOSCH_ACCELEROMETER_ONLY?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitly yes, thanks for spotting 😓 Copy pasting from a sketch into a PR is never a good idea 🙂

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps the one below should be BOSCH_ACCEL_AND_MAGN too rather than BOSCH_ACCEL_AND_GYRO

#else
myIMU.begin(BOSCH_ACCEL_AND_GYRO);
#endif

Serial.print("Accelerometer sample rate = ");
Serial.println(myIMU.accelerationSampleRate());
Expand Down
10 changes: 10 additions & 0 deletions src/BMI270.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ void BoschSensorClass::onInterrupt(mbed::Callback<void(void)> cb)
irq.rise(mbed::callback(this, &BoschSensorClass::interrupt_handler));
}
#endif
#ifdef ARDUINO_ARCH_ESP32
void BoschSensorClass::onInterrupt(void (*cb)(void))
{
if (BMI270_INT1 == -1) {
return;
}
pinMode(BMI270_INT1, INPUT_PULLUP);
attachInterrupt(BMI270_INT1, cb, FALLING);
}
#endif
int BoschSensorClass::begin(CfgBoshSensor_t cfg) {

_wire->begin();
Expand Down
13 changes: 12 additions & 1 deletion src/BoschSensorClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ContinuousMode {
if (ret != 0) {
return 0;
}
_available = min(status, sizeof(fifoData)) / (6 + 6); // 6 bytes per accel sample
_available = min((size_t)status, sizeof(fifoData)) / (6 + 6); // 6 bytes per accel sample
_availableG = _available;
_availableA = _available;
ret = bmi2_extract_accel(accel_data, &_available, &fifoFrame, bmi2);
Expand Down Expand Up @@ -150,6 +150,17 @@ class BoschSensorClass {
}
PinName BMI270_INT1 = NC;
#endif
#ifdef ARDUINO_ARCH_ESP32
void onInterrupt(void (*)(void));
void setInterruptPin(int irq_pin) {
BMI270_INT1 = irq_pin;
}
#if defined(ARDUINO_ARDUINO_NESSO_N1)
int BMI270_INT1 = 3;
#else
int BMI270_INT1 = -1;
#endif
#endif
// Accelerometer
virtual int readAcceleration(float& x, float& y, float& z); // Results are in G (earth gravity).
virtual int accelerationAvailable(); // Number of samples in the FIFO.
Expand Down
Loading