From f0102d47874b2ab20558bc2a5ec11b85ae597bc8 Mon Sep 17 00:00:00 2001 From: lewisxhe Date: Mon, 10 Feb 2025 10:06:39 +0800 Subject: [PATCH] Added the possibility of compiling with Arduino mbed and Arduino zephyr, not tested yet --- src/SensorLib.h | 4 ++-- src/bosch/BoschPhySensorInfo.hpp | 2 +- src/bosch/BoschSensorControl.hpp | 2 +- src/bosch/BoschSensorInfo.hpp | 2 +- src/bosch/bhy2_parse.c | 4 ---- src/bosch/bhy2_parse.h | 4 ++++ src/platform/arduino/SensorCommArduino_HW.hpp | 4 ++-- src/platform/arduino/SensorCommArduino_SPI.hpp | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/SensorLib.h b/src/SensorLib.h index 7c7f5fb..e6f3f54 100644 --- a/src/SensorLib.h +++ b/src/SensorLib.h @@ -85,7 +85,7 @@ #define ATTR_NOT_IMPLEMENTED __attribute__((error("Not implemented"))) -#if !defined(ARDUINO_ARCH_ESP32) && defined(LOG_PORT) && defined(ARDUINO) && !defined(__MBED__) +#if !defined(ARDUINO_ARCH_ESP32) && defined(LOG_PORT) && defined(ARDUINO) && !defined(ARDUINO_ARCH_MBED) && !defined(ARDUINO_ARCH_ZEPHYR) #define LOG_FILE_LINE_INFO __FILE__, __LINE__ @@ -101,7 +101,7 @@ #define log_d(fmt, ...) LOG_PORT.printf("[D][%s:%d] " fmt "\n", LOG_FILE_LINE_INFO, ##__VA_ARGS__) #endif /*log_d*/ -#elif defined(__MBED__) +#elif defined(ARDUINO_ARCH_MBED) || defined(ARDUINO_ARCH_ZEPHYR) #define LOG_FILE_LINE_INFO __FILE__, __LINE__ diff --git a/src/bosch/BoschPhySensorInfo.hpp b/src/bosch/BoschPhySensorInfo.hpp index 70d213d..ad99346 100644 --- a/src/bosch/BoschPhySensorInfo.hpp +++ b/src/bosch/BoschPhySensorInfo.hpp @@ -62,7 +62,7 @@ class BoschPhySensorInfo memset(orientation_matrix, 0, sizeof(orientation_matrix)); } -#if defined(ARDUINO) && !defined(__MBED__) +#if defined(ARDUINO) && !defined(ARDUINO_ARCH_MBED) && !defined(ARDUINO_ARCH_ZEPHYR) void print(Stream &stream) { const char *irq_status_str[2] = { "Disabled", "Enabled" }; diff --git a/src/bosch/BoschSensorControl.hpp b/src/bosch/BoschSensorControl.hpp index c1d1c1c..cd704c2 100644 --- a/src/bosch/BoschSensorControl.hpp +++ b/src/bosch/BoschSensorControl.hpp @@ -51,7 +51,7 @@ class SensorBHI260APControl debuggingEnabled(true), faultEnabled(true), interruptIsActiveLow(false), interruptIsPulseTriggered(false), interruptPinDriveIsOpenDrain(false) {} -#if defined(ARDUINO) && !defined(__MBED__) +#if defined(ARDUINO) && !defined(ARDUINO_ARCH_MBED) && !defined(ARDUINO_ARCH_ZEPHYR) void print(Stream &stream) { stream.printf("Host interrupt control\n"); diff --git a/src/bosch/BoschSensorInfo.hpp b/src/bosch/BoschSensorInfo.hpp index 0641842..9f0a513 100644 --- a/src/bosch/BoschSensorInfo.hpp +++ b/src/bosch/BoschSensorInfo.hpp @@ -149,7 +149,7 @@ class BoschSensorInfo return *this; } -#if defined(ARDUINO) && !defined(__MBED__) +#if defined(ARDUINO) && !defined(ARDUINO_ARCH_MBED) && !defined(ARDUINO_ARCH_ZEPHYR) void printVirtualSensorList(Stream &stream) { if (!dev) { diff --git a/src/bosch/bhy2_parse.c b/src/bosch/bhy2_parse.c index 02c194a..c928a13 100644 --- a/src/bosch/bhy2_parse.c +++ b/src/bosch/bhy2_parse.c @@ -96,10 +96,6 @@ uint32_t bhy2_parse_step_counter(const uint8_t *data) return (uint32_t)(data[0] | ((uint32_t)data[1] << 8) | ((uint32_t)data[2] << 16) | ((uint32_t)data[3] << 24)); } -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - void bhy2_quaternion_to_euler(const uint8_t *data, float *roll, float *pitch, float *yaw) { float w, x, y, z; diff --git a/src/bosch/bhy2_parse.h b/src/bosch/bhy2_parse.h index 03533c8..eac6745 100644 --- a/src/bosch/bhy2_parse.h +++ b/src/bosch/bhy2_parse.h @@ -45,6 +45,10 @@ extern "C" { #include "bhy2.h" +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + /** * @brief Function to parse FIFO frame data into temperature * @param[in] data : Reference to the data buffer storing data from the FIFO diff --git a/src/platform/arduino/SensorCommArduino_HW.hpp b/src/platform/arduino/SensorCommArduino_HW.hpp index d7dc174..bc07c6c 100644 --- a/src/platform/arduino/SensorCommArduino_HW.hpp +++ b/src/platform/arduino/SensorCommArduino_HW.hpp @@ -41,7 +41,7 @@ class HalArduino : public SensorHal if (modeCallback) { modeCallback(pin, mode); } else { -#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_MBED) +#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_MBED) || defined(ARDUINO_ARCH_ZEPHYR) ::pinMode(pin, static_cast(mode)); #else ::pinMode(pin, mode); @@ -54,7 +54,7 @@ class HalArduino : public SensorHal if (writeCallback) { writeCallback(pin, level); } else { -#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_MBED) +#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_MBED) || defined(ARDUINO_ARCH_ZEPHYR) ::digitalWrite(pin, static_cast(level)); #else ::digitalWrite(pin, level); diff --git a/src/platform/arduino/SensorCommArduino_SPI.hpp b/src/platform/arduino/SensorCommArduino_SPI.hpp index 22c9ef9..b4f8a73 100644 --- a/src/platform/arduino/SensorCommArduino_SPI.hpp +++ b/src/platform/arduino/SensorCommArduino_SPI.hpp @@ -39,7 +39,7 @@ #define writeBytes(txBuf,size) spi.transfer(txBuf,nullptr,size) #elif defined(ARDUINO_ARCH_NRF52) #define writeBytes(txBuf,size) spi.transfer(txBuf,nullptr,size) -#elif defined(ARDUINO_ARCH_MBED) +#elif defined(ARDUINO_ARCH_MBED) || defined(ARDUINO_ARCH_ZEPHYR) #define writeBytes(txBuf,size) spi.transfer((void*)txBuf,size) #else #define writeBytes(txBuf,size) spi.writeBytes(txBuf,size)