Skip to content

Commit 2def083

Browse files
committed
Make interrupt handling more generic
1 parent bb26957 commit 2def083

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/BMI270.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
#include "mbed_shared_queues.h"
88
#include "drivers/InterruptIn.h"
99

10-
static mbed::InterruptIn irq(BoschSensorClass::BMI270_INT1, PullDown);
1110
static events::EventQueue queue(10 * EVENTS_EVENT_SIZE);
12-
static rtos::Thread event_t(osPriorityHigh, 768, nullptr, "events");
1311
#endif
1412
BoschSensorClass::BoschSensorClass(TwoWire& wire)
1513
{
1614
_wire = &wire;
15+
#ifdef TARGET_ARDUINO_NANO33BLE
16+
BMI270_INT1 = p11;
17+
#endif
1718
}
1819

1920
void BoschSensorClass::debug(Stream& stream)
@@ -23,6 +24,11 @@ void BoschSensorClass::debug(Stream& stream)
2324
#ifdef __MBED__
2425
void BoschSensorClass::onInterrupt(mbed::Callback<void(void)> cb)
2526
{
27+
if (BMI270_INT1 == NC) {
28+
return;
29+
}
30+
static mbed::InterruptIn irq(BMI270_INT1, PullDown);
31+
static rtos::Thread event_t(osPriorityHigh, 768, nullptr, "events");
2632
_cb = cb;
2733
event_t.start(callback(&queue, &events::EventQueue::dispatch_forever));
2834
irq.rise(mbed::callback(this, &BoschSensorClass::interrupt_handler));

src/BoschSensorClass.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ class BoschSensorClass {
3838
void debug(arduino::Stream&);
3939
#ifdef __MBED__
4040
void onInterrupt(mbed::Callback<void()>);
41-
static const PinName BMI270_INT1 = p11;
41+
void setInterruptPin(PinName irq_pin) {
42+
BMI270_INT1 = irq_pin;
43+
}
44+
void setInterruptPin(pin_size_t irq_pin) {
45+
BMI270_INT1 = digitalPinToPinName(irq_pin);
46+
}
47+
PinName BMI270_INT1 = NC;
4248
#endif
4349
// Accelerometer
4450
virtual int readAcceleration(float& x, float& y, float& z); // Results are in G (earth gravity).

0 commit comments

Comments
 (0)