From e5795fd6b92c9d1c8edd2df4a4c0ea76d76cd75b Mon Sep 17 00:00:00 2001 From: Rohit Sangwan Date: Fri, 15 Aug 2025 09:51:37 +0530 Subject: [PATCH] Add MacOS support --- interface_lib/include/endian_compat.h | 19 +++++++++++++++++++ interface_lib/src/device_imu.c | 1 + interface_lib/src/device_mcu.c | 2 ++ 3 files changed, 22 insertions(+) create mode 100644 interface_lib/include/endian_compat.h diff --git a/interface_lib/include/endian_compat.h b/interface_lib/include/endian_compat.h new file mode 100644 index 0000000..10fc591 --- /dev/null +++ b/interface_lib/include/endian_compat.h @@ -0,0 +1,19 @@ +#pragma once + +#if defined(__APPLE__) +#include + +#define htole16(x) OSSwapHostToLittleInt16(x) +#define htole32(x) OSSwapHostToLittleInt32(x) +#define htole64(x) OSSwapHostToLittleInt64(x) + +#define le16toh(x) OSSwapLittleToHostInt16(x) +#define le32toh(x) OSSwapLittleToHostInt32(x) +#define le64toh(x) OSSwapLittleToHostInt64(x) + +#elif defined(__linux__) +#include // or #include on older systems + +#else +#error "Endian conversion functions not defined for this platform" +#endif \ No newline at end of file diff --git a/interface_lib/src/device_imu.c b/interface_lib/src/device_imu.c index d0d1a43..5d7e76e 100644 --- a/interface_lib/src/device_imu.c +++ b/interface_lib/src/device_imu.c @@ -42,6 +42,7 @@ #include "crc32.h" #include "hid_ids.h" +#include "endian_compat.h" #define GRAVITY_G (9.806f) diff --git a/interface_lib/src/device_mcu.c b/interface_lib/src/device_mcu.c index 551617d..4f26bed 100644 --- a/interface_lib/src/device_mcu.c +++ b/interface_lib/src/device_mcu.c @@ -36,6 +36,8 @@ #include "crc32.h" #include "hid_ids.h" +#include "endian_compat.h" + #ifndef NDEBUG #define device_mcu_error(msg) fprintf(stderr, "ERROR: %s\n", msg)