diff --git a/src/SensorBMM150.cpp b/src/SensorBMM150.cpp new file mode 100644 index 0000000..f6c28fa --- /dev/null +++ b/src/SensorBMM150.cpp @@ -0,0 +1,36 @@ +/** + * + * @license MIT License + * + * Copyright (c) 2024 lewis he + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @file SensorBMM150.cpp + * @author Lewis He (lewishe@outlook.com) + * @date 2024-07-24 + * + */ +#include "SensorBMM150.hpp" + +#if defined(ARDUINO) +volatile bool SensorBMM150::__data_available; +#endif + + diff --git a/src/SensorBMM150.hpp b/src/SensorBMM150.hpp index b07cf10..17b48f4 100644 --- a/src/SensorBMM150.hpp +++ b/src/SensorBMM150.hpp @@ -239,9 +239,10 @@ class SensorBMM150 private: - static void IRAM_ATTR handleISR(void *available) + static void IRAM_ATTR handleISR(/*void *available*/) { - *(bool *)(available) = true; + // *(bool *)(available) = true; + __data_available = true; } bool initImpl() @@ -306,10 +307,19 @@ class SensorBMM150 bmm150_get_sensor_settings(&settings, dev); if (__handler.irq != SENSOR_PIN_NONE) { +/* #if defined(ARDUINO_ARCH_RP2040) attachInterruptParam((pin_size_t)(__handler.irq), handleISR, (PinStatus )RISING, (void *)&__data_available); #else attachInterruptArg(__handler.irq, handleISR, (void *)&__data_available, RISING); +#endif +*/ +#if defined(ARDUINO_ARCH_RP2040) + attachInterrupt((pin_size_t)(__handler.irq), handleISR, (PinStatus )RISING); +#elif defined(NRF52840_XXAA) || defined(NRF52832_XXAA) || defined(ESP32) || defined(ARDUINO_ARCH_ESP32) + attachInterrupt(__handler.irq, handleISR, RISING); +#else +#error "Interrupt registration not implemented" #endif } @@ -321,7 +331,7 @@ class SensorBMM150 struct bmm150_dev *dev = NULL; SensorLibConfigure __handler; int8_t __error_code; - volatile bool __data_available; + static volatile bool __data_available; };