|
10 | 10 | static events::EventQueue queue(10 * EVENTS_EVENT_SIZE); |
11 | 11 | #endif |
12 | 12 |
|
| 13 | +#ifdef ARDUINO_ARCH_ESP32 |
| 14 | +#include "FunctionalInterrupt.h" |
| 15 | +#endif |
| 16 | + |
13 | 17 | #if defined(ARDUINO_NANO33BLE) |
14 | 18 | #define TARGET_ARDUINO_NANO33BLE |
15 | 19 | #endif |
@@ -39,14 +43,43 @@ void BoschSensorClass::onInterrupt(mbed::Callback<void(void)> cb) |
39 | 43 | irq.rise(mbed::callback(this, &BoschSensorClass::interrupt_handler)); |
40 | 44 | } |
41 | 45 | #endif |
| 46 | + |
42 | 47 | #ifdef ARDUINO_ARCH_ESP32 |
| 48 | +static EventGroupHandle_t xHandle = NULL; |
| 49 | +struct bmi_task_data { |
| 50 | + BoschSensorClass* imu; |
| 51 | + struct bmi2_dev* bmi2; |
| 52 | +}; |
| 53 | + |
| 54 | +void irq_thread(void *pvParameters) |
| 55 | +{ |
| 56 | + bmi_task_data* instance_ptr = static_cast<bmi_task_data*>(pvParameters); |
| 57 | + uint16_t status; |
| 58 | + while (1) { |
| 59 | + xEventGroupWaitBits(xHandle, 1, pdTRUE, pdFALSE, portMAX_DELAY); |
| 60 | + if (instance_ptr->imu && instance_ptr->imu->_cb) { |
| 61 | + bmi2_get_int_status(&status, instance_ptr->bmi2); |
| 62 | + instance_ptr->imu->_cb(); |
| 63 | + } |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +void BoschSensorClass::cb_wrapper() |
| 68 | +{ |
| 69 | + xEventGroupSetBits(xHandle, 0xFF); |
| 70 | +} |
| 71 | + |
43 | 72 | void BoschSensorClass::onInterrupt(void (*cb)(void)) |
44 | 73 | { |
45 | 74 | if (BMI270_INT1 == -1) { |
46 | 75 | return; |
47 | 76 | } |
| 77 | + xHandle = xEventGroupCreate(); |
| 78 | + _cb = cb; |
| 79 | + static struct bmi_task_data instance = { this, &bmi2 }; |
48 | 80 | pinMode(BMI270_INT1, INPUT_PULLUP); |
49 | | - attachInterrupt(BMI270_INT1, cb, FALLING); |
| 81 | + xTaskCreate(irq_thread, "bmi_irq_thread", 4096, &instance, 1, NULL); |
| 82 | + attachInterrupt(BMI270_INT1, std::bind(&BoschSensorClass::cb_wrapper, this), FALLING); |
50 | 83 | } |
51 | 84 | #endif |
52 | 85 | int BoschSensorClass::begin(CfgBoshSensor_t cfg) { |
|
0 commit comments