From 31cc8068d7adf9fa1ed936bf7b16563c6b6357ab Mon Sep 17 00:00:00 2001 From: Ashwin Date: Fri, 10 Mar 2023 10:46:47 +0530 Subject: [PATCH 01/18] Added interrupt terms --- src/protocentral_max30001.cpp | 9 +++++++++ src/protocentral_max30001.h | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/protocentral_max30001.cpp b/src/protocentral_max30001.cpp index b21f33c..63acb2a 100644 --- a/src/protocentral_max30001.cpp +++ b/src/protocentral_max30001.cpp @@ -293,3 +293,12 @@ void MAX30001::getHRandRR(void) unsigned int RR = (unsigned int)rtor* (7.8125) ; //8ms RRinterval = RR; } + +void MAX30001::setInterrupts(void) +{ + + _max30001RegWrite(EN_INT, 0x000401); + delay(100); + //_max30001Synch(); + //delay(100); +} \ No newline at end of file diff --git a/src/protocentral_max30001.h b/src/protocentral_max30001.h index 9998db5..a44cc14 100644 --- a/src/protocentral_max30001.h +++ b/src/protocentral_max30001.h @@ -102,4 +102,28 @@ class MAX30001 #define CLK_PIN 6 #define RTOR_INTR_MASK 0x04 +enum EN_INT_bits { + EN_EINT=0x800000, + EN_ECG_FIFO_OVF=0x400000, + EN_ECG_FAST_REC=0x200000, + EN_DCLOFFINT=0x100000, + EN_BIOZ_FIFO_INT=0x80000, + EN_BIOZ_FIFO_OVF=0x40000, + EN_BIOZ_OVER_RANGE=0x20000, + EN_BIOZ_UNDER_RANGE=0x10000, + EN_BIOZ_CG_MON=0x8000, + + EN_LONINT=0x800, + EN_RRINT=0x400, + EN_SAMP=0x200, + EN_PLLINT=0x100, + + EN_BCGMP=0x20, + EN_BCGMN=0x10, + EN_LDOFF_PH=0x8, + EN_LDOFF_PL=0x4, + EN_LDOFF_NH=0x2, + EN_LDOFF_NL=0x1 +}; + #endif From f161d189483dde1c169752905a6d4b12433dfa33 Mon Sep 17 00:00:00 2001 From: Ashwin Date: Fri, 10 Mar 2023 16:11:47 +0530 Subject: [PATCH 02/18] Basic interrupt working --- .vscode/arduino.json | 7 + .vscode/c_cpp_properties.json | 495 ++++++++++++++++++ examples/.DS_Store | Bin 6148 -> 6148 bytes .../Example2-Interrupt-Driven.ino | 168 ++++++ src/protocentral_max30001.cpp | 57 +- src/protocentral_max30001.h | 107 +++- 6 files changed, 803 insertions(+), 31 deletions(-) create mode 100644 .vscode/arduino.json create mode 100644 .vscode/c_cpp_properties.json create mode 100644 examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino diff --git a/.vscode/arduino.json b/.vscode/arduino.json new file mode 100644 index 0000000..ffdd47e --- /dev/null +++ b/.vscode/arduino.json @@ -0,0 +1,7 @@ +{ + "port": "/dev/tty.usbmodem101", + "configuration": "flash=2097152_0,freq=133,opt=Small,rtti=Disabled,stackprotect=Disabled,exceptions=Disabled,dbgport=Disabled,dbglvl=None,usbstack=picosdk,ipbtstack=ipv4only,uploadmethod=default", + "board": "rp2040:rp2040:rpipico", + "output": "../build", + "sketch": "examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino" +} \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..e4fe8d7 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,495 @@ +{ + "version": 4, + "configurations": [ + { + "name": "Arduino", + "compilerPath": "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/bin/arm-none-eabi-g++", + "compilerArgs": [ + "-I", + "-Werror=return-type", + "-march=armv6-m", + "-mcpu=cortex-m0plus", + "-mthumb", + "-ffunction-sections", + "-fdata-sections", + "-fno-exceptions" + ], + "intelliSenseMode": "gcc-x64", + "includePath": [ + "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.0.0/include", + "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.0.0/cores/rp2040", + "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.0.0/variants/rpipico", + "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.0.0/libraries/SPI/src", + "/Users/akw/Documents/Arduino/libraries/protocentral_max30001_arduino_library/src", + "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/arm-none-eabi/include/c++/10.3.0", + "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/arm-none-eabi/include/c++/10.3.0/arm-none-eabi/thumb", + "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/arm-none-eabi/include/c++/10.3.0/backward", + "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/lib/gcc/arm-none-eabi/10.3.0/include", + "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/lib/gcc/arm-none-eabi/10.3.0/include-fixed", + "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/arm-none-eabi/include" + ], + "forcedInclude": [ + "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.0.0/cores/rp2040/Arduino.h" + ], + "cStandard": "c11", + "cppStandard": "c++17", + "defines": [ + "CFG_TUSB_MCU=OPT_MCU_RP2040", + "USBD_PID=0x000a", + "USBD_VID=0x2e8a", + "USBD_MAX_POWER_MA=250", + "USB_MANUFACTURER=\"Raspberry Pi\"", + "USB_PRODUCT=\"Pico\"", + "PICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1", + "CYW43_LWIP=1", + "LWIP_IPV6=0", + "LWIP_IPV4=1", + "LWIP_IGMP=1", + "LWIP_CHECKSUM_CTRL_PER_NETIF=1", + "ARDUINO_VARIANT=\"rpipico\"", + "TARGET_RP2040", + "ARM_MATH_CM0_FAMILY", + "ARM_MATH_CM0_PLUS", + "F_CPU=133000000L", + "ARDUINO=10607", + "ARDUINO_RASPBERRY_PI_PICO", + "BOARD_NAME=\"RASPBERRY_PI_PICO\"", + "ARDUINO_ARCH_RP2040", + "WIFICC=CYW43_COUNTRY_WORLDWIDE", + "__DBL_MIN_EXP__=(-1021)", + "__HQ_FBIT__=15", + "__cpp_attributes=200809L", + "__UINT_LEAST16_MAX__=0xffff", + "__ARM_SIZEOF_WCHAR_T=4", + "__ATOMIC_ACQUIRE=2", + "__SFRACT_IBIT__=0", + "__FLT_MIN__=1.1754943508222875e-38F", + "__GCC_IEC_559_COMPLEX=0", + "__cpp_aggregate_nsdmi=201304L", + "__UFRACT_MAX__=0XFFFFP-16UR", + "__UINT_LEAST8_TYPE__=unsigned char", + "__DQ_FBIT__=63", + "__INTMAX_C(c)=c ## LL", + "__ULFRACT_FBIT__=32", + "__CHAR_BIT__=8", + "__USQ_IBIT__=0", + "__UINT8_MAX__=0xff", + "__ACCUM_FBIT__=15", + "__WINT_MAX__=0xffffffffU", + "__FLT32_MIN_EXP__=(-125)", + "__cpp_static_assert=200410L", + "__USFRACT_FBIT__=8", + "__ORDER_LITTLE_ENDIAN__=1234", + "__SIZE_MAX__=0xffffffffU", + "__WCHAR_MAX__=0xffffffffU", + "__LACCUM_IBIT__=32", + "__DBL_DENORM_MIN__=double(4.9406564584124654e-324L)", + "__GCC_ATOMIC_CHAR_LOCK_FREE=1", + "__GCC_IEC_559=0", + "__FLT32X_DECIMAL_DIG__=17", + "__FLT_EVAL_METHOD__=0", + "__TQ_IBIT__=0", + "__cpp_binary_literals=201304L", + "__LLACCUM_MAX__=0X7FFFFFFFFFFFFFFFP-31LLK", + "__FLT64_DECIMAL_DIG__=17", + "__GCC_ATOMIC_CHAR32_T_LOCK_FREE=1", + "__cpp_variadic_templates=200704L", + "__UINT_FAST64_MAX__=0xffffffffffffffffULL", + "__SIG_ATOMIC_TYPE__=int", + "__DBL_MIN_10_EXP__=(-307)", + "__FINITE_MATH_ONLY__=0", + "__ARMEL__=1", + "__cpp_variable_templates=201304L", + "__FLT32X_MAX_EXP__=1024", + "__LFRACT_IBIT__=0", + "__GNUC_PATCHLEVEL__=0", + "__FLT32_HAS_DENORM__=1", + "__LFRACT_MAX__=0X7FFFFFFFP-31LR", + "__USA_FBIT__=16", + "__UINT_FAST8_MAX__=0xffffffffU", + "__cpp_rvalue_reference=200610L", + "__FLT32_MAX_10_EXP__=38", + "__INT8_C(c)=c", + "__INT_LEAST8_WIDTH__=8", + "__UINT_LEAST64_MAX__=0xffffffffffffffffULL", + "__SA_FBIT__=15", + "__SHRT_MAX__=0x7fff", + "__LDBL_MAX__=1.7976931348623157e+308L", + "__FRACT_MAX__=0X7FFFP-15R", + "__UFRACT_FBIT__=16", + "__UFRACT_MIN__=0.0UR", + "__UINT_LEAST8_MAX__=0xff", + "__GCC_ATOMIC_BOOL_LOCK_FREE=1", + "__UINTMAX_TYPE__=long long unsigned int", + "__LLFRACT_EPSILON__=0x1P-63LLR", + "__FLT_EVAL_METHOD_TS_18661_3__=0", + "__CHAR_UNSIGNED__=1", + "__UINT32_MAX__=0xffffffffUL", + "__GXX_EXPERIMENTAL_CXX0X__=1", + "__ULFRACT_MAX__=0XFFFFFFFFP-32ULR", + "__TA_IBIT__=64", + "__LDBL_MAX_EXP__=1024", + "__WINT_MIN__=0U", + "__INT_LEAST16_WIDTH__=16", + "__ULLFRACT_MIN__=0.0ULLR", + "__SCHAR_MAX__=0x7f", + "__WCHAR_MIN__=0U", + "__INT64_C(c)=c ## LL", + "__GCC_ATOMIC_POINTER_LOCK_FREE=1", + "__LLACCUM_MIN__=(-0X1P31LLK-0X1P31LLK)", + "__SIZEOF_INT__=4", + "__FLT32X_MANT_DIG__=53", + "__GCC_ATOMIC_CHAR16_T_LOCK_FREE=1", + "__USACCUM_IBIT__=8", + "__USER_LABEL_PREFIX__", + "__STDC_HOSTED__=1", + "__LFRACT_MIN__=(-0.5LR-0.5LR)", + "__HA_IBIT__=8", + "__cpp_decltype_auto=201304L", + "__DBL_DIG__=15", + "__FLT32_DIG__=6", + "__FLT_EPSILON__=1.1920928955078125e-7F", + "__APCS_32__=1", + "__GXX_WEAK__=1", + "__SHRT_WIDTH__=16", + "__USFRACT_IBIT__=0", + "__LDBL_MIN__=2.2250738585072014e-308L", + "__FRACT_MIN__=(-0.5R-0.5R)", + "__cpp_threadsafe_static_init=200806L", + "__DA_IBIT__=32", + "__ARM_SIZEOF_MINIMAL_ENUM=1", + "__FLT32X_HAS_INFINITY__=1", + "__INT32_MAX__=0x7fffffffL", + "__UQQ_FBIT__=8", + "__INT_WIDTH__=32", + "__SIZEOF_LONG__=4", + "__UACCUM_MAX__=0XFFFFFFFFP-16UK", + "__UINT16_C(c)=c", + "__DECIMAL_DIG__=17", + "__LFRACT_EPSILON__=0x1P-31LR", + "__FLT64_EPSILON__=2.2204460492503131e-16F64", + "__ULFRACT_MIN__=0.0ULR", + "__INT16_MAX__=0x7fff", + "__FLT64_MIN_EXP__=(-1021)", + "__LDBL_HAS_QUIET_NAN__=1", + "__ULACCUM_IBIT__=32", + "__FLT64_MANT_DIG__=53", + "__UACCUM_EPSILON__=0x1P-16UK", + "__GNUC__=10", + "__ULLACCUM_MAX__=0XFFFFFFFFFFFFFFFFP-32ULLK", + "__GXX_RTTI=1", + "__HQ_IBIT__=0", + "__FLT_HAS_DENORM__=1", + "__SIZEOF_LONG_DOUBLE__=8", + "__SA_IBIT__=16", + "__BIGGEST_ALIGNMENT__=8", + "__STDC_UTF_16__=1", + "__FLT64_MAX_10_EXP__=308", + "__GNUC_STDC_INLINE__=1", + "__DQ_IBIT__=0", + "__cpp_delegating_constructors=200604L", + "__FLT32_HAS_INFINITY__=1", + "__DBL_MAX__=double(1.7976931348623157e+308L)", + "__ULFRACT_IBIT__=0", + "__cpp_raw_strings=200710L", + "__INT_FAST32_MAX__=0x7fffffff", + "__DBL_HAS_INFINITY__=1", + "__HAVE_SPECULATION_SAFE_VALUE=1", + "__ACCUM_IBIT__=16", + "__THUMB_INTERWORK__=1", + "__INTPTR_WIDTH__=32", + "__UINT_LEAST32_MAX__=0xffffffffUL", + "__ULLACCUM_IBIT__=32", + "__LACCUM_MAX__=0X7FFFFFFFFFFFFFFFP-31LK", + "__FLT32X_HAS_DENORM__=1", + "__INT_FAST16_TYPE__=int", + "__LDBL_HAS_DENORM__=1", + "__cplusplus=201402L", + "__cpp_ref_qualifiers=200710L", + "__INT_LEAST32_MAX__=0x7fffffffL", + "__ARM_PCS=1", + "__ACCUM_MAX__=0X7FFFFFFFP-15K", + "__DEPRECATED=1", + "__ARM_ARCH_6M__=1", + "__cpp_rvalue_references=200610L", + "__DBL_MAX_EXP__=1024", + "__USACCUM_EPSILON__=0x1P-8UHK", + "__WCHAR_WIDTH__=32", + "__FLT32_MAX__=3.4028234663852886e+38F32", + "__GCC_ATOMIC_LONG_LOCK_FREE=1", + "__SFRACT_MAX__=0X7FP-7HR", + "__FRACT_IBIT__=0", + "__PTRDIFF_MAX__=0x7fffffff", + "__UACCUM_MIN__=0.0UK", + "__UACCUM_IBIT__=16", + "__FLT32_HAS_QUIET_NAN__=1", + "__GNUG__=10", + "__LONG_LONG_MAX__=0x7fffffffffffffffLL", + "__ULACCUM_MAX__=0XFFFFFFFFFFFFFFFFP-32ULK", + "__cpp_nsdmi=200809L", + "__SIZEOF_WINT_T__=4", + "__LONG_LONG_WIDTH__=64", + "__cpp_initializer_lists=200806L", + "__FLT32_MAX_EXP__=128", + "__ULLACCUM_MIN__=0.0ULLK", + "__cpp_hex_float=201603L", + "__GXX_ABI_VERSION=1014", + "__UTA_FBIT__=64", + "__FLT_MIN_EXP__=(-125)", + "__UFRACT_IBIT__=0", + "__cpp_lambdas=200907L", + "__INT_FAST64_TYPE__=long long int", + "__FLT64_DENORM_MIN__=4.9406564584124654e-324F64", + "__DBL_MIN__=double(2.2250738585072014e-308L)", + "__SIZEOF_POINTER__=4", + "__DBL_HAS_QUIET_NAN__=1", + "__FLT32X_EPSILON__=2.2204460492503131e-16F32x", + "__LACCUM_MIN__=(-0X1P31LK-0X1P31LK)", + "__FRACT_FBIT__=15", + "__ULLACCUM_FBIT__=32", + "__GXX_TYPEINFO_EQUALITY_INLINE=0", + "__FLT64_MIN_10_EXP__=(-307)", + "__ULLFRACT_EPSILON__=0x1P-64ULLR", + "__USES_INITFINI__=1", + "__REGISTER_PREFIX__", + "__UINT16_MAX__=0xffff", + "__ACCUM_MIN__=(-0X1P15K-0X1P15K)", + "__SQ_IBIT__=0", + "__FLT32_MIN__=1.1754943508222875e-38F32", + "__UINT8_TYPE__=unsigned char", + "__UHA_FBIT__=8", + "__FLT_DIG__=6", + "__NO_INLINE__=1", + "__SFRACT_MIN__=(-0.5HR-0.5HR)", + "__UTQ_FBIT__=128", + "__DEC_EVAL_METHOD__=2", + "__FLT_MANT_DIG__=24", + "__LDBL_DECIMAL_DIG__=17", + "__VERSION__=\"10.3.0\"", + "__UINT64_C(c)=c ## ULL", + "__ULLFRACT_FBIT__=64", + "__cpp_unicode_characters=200704L", + "__SOFTFP__=1", + "__FRACT_EPSILON__=0x1P-15R", + "__ULACCUM_MIN__=0.0ULK", + "__UDA_FBIT__=32", + "__LLACCUM_EPSILON__=0x1P-31LLK", + "__GCC_ATOMIC_INT_LOCK_FREE=1", + "__FLOAT_WORD_ORDER__=__ORDER_LITTLE_ENDIAN__", + "__USFRACT_MIN__=0.0UHR", + "__FLT32_MANT_DIG__=24", + "__UQQ_IBIT__=0", + "__USFRACT_MAX__=0XFFP-8UHR", + "__SCHAR_WIDTH__=8", + "__INT32_C(c)=c ## L", + "__ORDER_PDP_ENDIAN__=3412", + "__UHQ_FBIT__=16", + "__LLACCUM_FBIT__=31", + "__INT_FAST32_TYPE__=int", + "__UINT_LEAST16_TYPE__=short unsigned int", + "__DBL_HAS_DENORM__=1", + "__cpp_rtti=199711L", + "__SIZE_TYPE__=unsigned int", + "__UINT64_MAX__=0xffffffffffffffffULL", + "__UDQ_FBIT__=64", + "__INT8_TYPE__=signed char", + "__thumb__=1", + "__cpp_digit_separators=201309L", + "__ELF__=1", + "__SACCUM_EPSILON__=0x1P-7HK", + "__ULFRACT_EPSILON__=0x1P-32ULR", + "__LLFRACT_FBIT__=63", + "__FLT_RADIX__=2", + "__INT_LEAST16_TYPE__=short int", + "__ARM_ARCH_PROFILE=77", + "__LDBL_EPSILON__=2.2204460492503131e-16L", + "__UINTMAX_C(c)=c ## ULL", + "__SACCUM_MAX__=0X7FFFP-7HK", + "__FLT32X_MIN__=2.2250738585072014e-308F32x", + "__SIG_ATOMIC_MAX__=0x7fffffff", + "__UACCUM_FBIT__=16", + "__GCC_ATOMIC_WCHAR_T_LOCK_FREE=1", + "__VFP_FP__=1", + "__SIZEOF_PTRDIFF_T__=4", + "__LACCUM_EPSILON__=0x1P-31LK", + "__LDBL_DIG__=15", + "__FLT32X_MIN_EXP__=(-1021)", + "__INT_FAST16_MAX__=0x7fffffff", + "__FLT64_DIG__=15", + "__UINT_FAST32_MAX__=0xffffffffU", + "__UINT_LEAST64_TYPE__=long long unsigned int", + "__SFRACT_EPSILON__=0x1P-7HR", + "__FLT_HAS_QUIET_NAN__=1", + "__FLT_MAX_10_EXP__=38", + "__LONG_MAX__=0x7fffffffL", + "__SIZEOF_SIZE_T__=4", + "__FLT_HAS_INFINITY__=1", + "__cpp_unicode_literals=200710L", + "__UINT_FAST16_TYPE__=unsigned int", + "__INT_FAST32_WIDTH__=32", + "__CHAR16_TYPE__=short unsigned int", + "__PRAGMA_REDEFINE_EXTNAME=1", + "__SIZE_WIDTH__=32", + "__INT_LEAST16_MAX__=0x7fff", + "__INT64_MAX__=0x7fffffffffffffffLL", + "__SACCUM_FBIT__=7", + "__FLT32_DENORM_MIN__=1.4012984643248171e-45F32", + "__SIG_ATOMIC_WIDTH__=32", + "__INT_LEAST64_TYPE__=long long int", + "__INT16_TYPE__=short int", + "__INT_LEAST8_TYPE__=signed char", + "__SQ_FBIT__=31", + "__ARM_ARCH_ISA_THUMB=1", + "__INT_FAST8_MAX__=0x7fffffff", + "__ARM_ARCH=6", + "__INTPTR_MAX__=0x7fffffff", + "__cpp_sized_deallocation=201309L", + "__QQ_FBIT__=7", + "__UTA_IBIT__=64", + "__FLT64_HAS_QUIET_NAN__=1", + "__FLT32_MIN_10_EXP__=(-37)", + "__EXCEPTIONS=1", + "__PTRDIFF_WIDTH__=32", + "__LDBL_MANT_DIG__=53", + "__SFRACT_FBIT__=7", + "__cpp_range_based_for=200907L", + "__SACCUM_MIN__=(-0X1P7HK-0X1P7HK)", + "__FLT64_HAS_INFINITY__=1", + "__SIG_ATOMIC_MIN__=(-__SIG_ATOMIC_MAX__ - 1)", + "__cpp_return_type_deduction=201304L", + "__INTPTR_TYPE__=int", + "__UINT16_TYPE__=short unsigned int", + "__WCHAR_TYPE__=unsigned int", + "__SIZEOF_FLOAT__=4", + "__THUMBEL__=1", + "__TQ_FBIT__=127", + "__USQ_FBIT__=32", + "__UINTPTR_MAX__=0xffffffffU", + "__INT_FAST64_WIDTH__=64", + "__cpp_decltype=200707L", + "__FLT32_DECIMAL_DIG__=9", + "__INT_FAST64_MAX__=0x7fffffffffffffffLL", + "__GCC_ATOMIC_TEST_AND_SET_TRUEVAL=1", + "__FLT_NORM_MAX__=3.4028234663852886e+38F", + "__UINT_FAST64_TYPE__=long long unsigned int", + "__INT_MAX__=0x7fffffff", + "__LACCUM_FBIT__=31", + "__USACCUM_MIN__=0.0UHK", + "__UHA_IBIT__=8", + "__INT64_TYPE__=long long int", + "__FLT_MAX_EXP__=128", + "__UTQ_IBIT__=0", + "__DBL_MANT_DIG__=53", + "__cpp_inheriting_constructors=201511L", + "__INT_LEAST64_MAX__=0x7fffffffffffffffLL", + "__WINT_TYPE__=unsigned int", + "__UINT_LEAST32_TYPE__=long unsigned int", + "__SIZEOF_SHORT__=2", + "__ULLFRACT_IBIT__=0", + "__FLT32_NORM_MAX__=3.4028234663852886e+38F32", + "__LDBL_MIN_EXP__=(-1021)", + "__arm__=1", + "__FLT64_MAX__=1.7976931348623157e+308F64", + "__UDA_IBIT__=32", + "__WINT_WIDTH__=32", + "__INT_LEAST8_MAX__=0x7f", + "__INT_LEAST64_WIDTH__=64", + "__FLT32X_MAX_10_EXP__=308", + "__LFRACT_FBIT__=31", + "__WCHAR_UNSIGNED__=1", + "__LDBL_MAX_10_EXP__=308", + "__ATOMIC_RELAXED=0", + "__DBL_EPSILON__=double(2.2204460492503131e-16L)", + "__UINT8_C(c)=c", + "__FLT64_MAX_EXP__=1024", + "__INT_LEAST32_TYPE__=long int", + "__SIZEOF_WCHAR_T__=4", + "__LLFRACT_MAX__=0X7FFFFFFFFFFFFFFFP-63LLR", + "__FLT64_NORM_MAX__=1.7976931348623157e+308F64", + "__INTMAX_MAX__=0x7fffffffffffffffLL", + "__INT_FAST8_TYPE__=int", + "__ULLACCUM_EPSILON__=0x1P-32ULLK", + "__USACCUM_MAX__=0XFFFFP-8UHK", + "__LDBL_HAS_INFINITY__=1", + "__UHQ_IBIT__=0", + "__LLACCUM_IBIT__=32", + "__FLT64_HAS_DENORM__=1", + "__FLT32_EPSILON__=1.1920928955078125e-7F32", + "__DBL_DECIMAL_DIG__=17", + "__STDC_UTF_32__=1", + "__INT_FAST8_WIDTH__=32", + "__FLT32X_MAX__=1.7976931348623157e+308F32x", + "__TA_FBIT__=63", + "__DBL_NORM_MAX__=double(1.7976931348623157e+308L)", + "__BYTE_ORDER__=__ORDER_LITTLE_ENDIAN__", + "__UDQ_IBIT__=0", + "__INTMAX_WIDTH__=64", + "__ORDER_BIG_ENDIAN__=4321", + "__cpp_runtime_arrays=198712L", + "__UINT64_TYPE__=long long unsigned int", + "__ACCUM_EPSILON__=0x1P-15K", + "__UINT32_C(c)=c ## UL", + "__cpp_alias_templates=200704L", + "__FLT_DENORM_MIN__=1.4012984643248171e-45F", + "__LLFRACT_IBIT__=0", + "__INT8_MAX__=0x7f", + "__LONG_WIDTH__=32", + "__UINT_FAST32_TYPE__=unsigned int", + "__FLT32X_NORM_MAX__=1.7976931348623157e+308F32x", + "__CHAR32_TYPE__=long unsigned int", + "__FLT_MAX__=3.4028234663852886e+38F", + "__cpp_constexpr=201304L", + "__USACCUM_FBIT__=8", + "__INT32_TYPE__=long int", + "__SIZEOF_DOUBLE__=8", + "__cpp_exceptions=199711L", + "__FLT_MIN_10_EXP__=(-37)", + "__UFRACT_EPSILON__=0x1P-16UR", + "__FLT64_MIN__=2.2250738585072014e-308F64", + "__INT_LEAST32_WIDTH__=32", + "__INTMAX_TYPE__=long long int", + "__FLT32X_HAS_QUIET_NAN__=1", + "__ATOMIC_CONSUME=1", + "__GNUC_MINOR__=3", + "__INT_FAST16_WIDTH__=32", + "__UINTMAX_MAX__=0xffffffffffffffffULL", + "__FLT32X_DENORM_MIN__=4.9406564584124654e-324F32x", + "__HA_FBIT__=7", + "__DBL_MAX_10_EXP__=308", + "__LDBL_DENORM_MIN__=4.9406564584124654e-324L", + "__INT16_C(c)=c", + "__STDC__=1", + "__FLT32X_DIG__=15", + "__PTRDIFF_TYPE__=int", + "__LLFRACT_MIN__=(-0.5LLR-0.5LLR)", + "__ATOMIC_SEQ_CST=5", + "__DA_FBIT__=31", + "__UINT32_TYPE__=long unsigned int", + "__FLT32X_MIN_10_EXP__=(-307)", + "__UINTPTR_TYPE__=unsigned int", + "__USA_IBIT__=16", + "__ARM_EABI__=1", + "__LDBL_MIN_10_EXP__=(-307)", + "__cpp_generic_lambdas=201304L", + "__SIZEOF_LONG_LONG__=8", + "__ULACCUM_EPSILON__=0x1P-32ULK", + "__cpp_user_defined_literals=200809L", + "__SACCUM_IBIT__=8", + "__GCC_ATOMIC_LLONG_LOCK_FREE=1", + "__FLT_DECIMAL_DIG__=9", + "__UINT_FAST16_MAX__=0xffffffffU", + "__LDBL_NORM_MAX__=1.7976931348623157e+308L", + "__GCC_ATOMIC_SHORT_LOCK_FREE=1", + "__ULLFRACT_MAX__=0XFFFFFFFFFFFFFFFFP-64ULLR", + "__UINT_FAST8_TYPE__=unsigned int", + "__USFRACT_EPSILON__=0x1P-8UHR", + "__ULACCUM_FBIT__=32", + "__QQ_IBIT__=0", + "__cpp_init_captures=201304L", + "__ATOMIC_ACQ_REL=4", + "__ATOMIC_RELEASE=3", + "USBCON" + ] + } + ] +} \ No newline at end of file diff --git a/examples/.DS_Store b/examples/.DS_Store index d10bd5557324a5b0e7f6aa15896e3d08e57304fd..8742020d240c415819d8a4e6a0f8bc4fb6c46aa7 100644 GIT binary patch delta 67 zcmZoMXfc=|#>B)qu~2NHo+2a5#(>?7j4YdZSdtkxi*g9DOl)Y|%+A5j0aUVCkmEb^ VWPTAx4hA4#WME*~93irX82~Q$4*dWC literal 6148 zcmeH~zfQw25XL`4hpK=m8z6=-qYh`m}qGQNJ&!_%AYMSz|6$N%u~SI z@B}dNoo$tb79`q&5b{aB&%M}}`X1-c<7*QE{El#R?%mCn&Y zh!)ByVQXNt3pfIfz+WREdv}$)^$K-FNblb&wz-chI7N&D_ResQE_b(#D`AggTWI5g z*IT#@kIS{AIO>?!TiBUQ)+i2wMi@7kE#JLcdwjTk+MHD8<_~4=oTN#3d|a%2!S@?f z=U>Okm1eo|e7}2B&@4xOwkUolIEj2&Zc>l1^nu$t*IkvXQPydXtFg`|tFz6x_z>6G zbvU;_T9!1c<(EFI5uPVaX}nBB_z0tMj5S*^R?QV$@8B(syPaduL@&C`#X* zaZeA2@{Kz02si>+0@LPaQR+X>>z|$fvy@IM plW~brJ%!GeW8INbyvU}F*F5P^eXEI4MriJjfX3jQBk-#P-T;&8%1HnK diff --git a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino new file mode 100644 index 0000000..e39068c --- /dev/null +++ b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino @@ -0,0 +1,168 @@ +////////////////////////////////////////////////////////////////////////////////////////// +// +// Demo code for the MAX30001 breakout board +// +// This example plots the ECG through serial UART on openview processing GUI. +// GUI URL: https://github.com/Protocentral/protocentral_openview.git +// +// Arduino connections: +// +// |MAX30001 pin label| Pin Function |Arduino Connection| +// |----------------- |:--------------------:|-----------------:| +// | MISO | Slave Out | D12 | +// | MOSI | Slave In | D11 | +// | SCLK | Serial Clock | D13 | +// | CS | Chip Select | D7 | +// | VCC | Digital VDD | +5V | +// | GND | Digital Gnd | Gnd | +// | FCLK | 32K CLOCK | - | +// | INT1 | Interrupt1 | 02 | +// | INT2 | Interrupt2 | - | +// +// This software is licensed under the MIT License(http://opensource.org/licenses/MIT). +// +// 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. +// +// For information on how to use, visit https://github.com/Protocentral/protocentral_max30001 +// +///////////////////////////////////////////////////////////////////////////////////////// + +#include +#include "protocentral_max30001.h" + +#define SPI_SCK_PIN 2 +#define SPI_MOSI_PIN 3 +#define SPI_MISO_PIN 4 + +#define MAX30001_CS_PIN 5 +#define MAX30001_INTB_PIN 20 +#define MAX30001_INT2B_PIN 19 + +#define MAX30001_DELAY_SAMPLES 8 // Time between consecutive samples + +#define CES_CMDIF_PKT_START_1 0x0A +#define CES_CMDIF_PKT_START_2 0xFA +#define CES_CMDIF_TYPE_DATA 0x02 +#define CES_CMDIF_PKT_STOP 0x0B +#define DATA_LEN 0x0C +#define ZERO 0 + +volatile char DataPacket[DATA_LEN]; +const char DataPacketFooter[2] = { ZERO, CES_CMDIF_PKT_STOP }; +const char DataPacketHeader[5] = { CES_CMDIF_PKT_START_1, CES_CMDIF_PKT_START_2, DATA_LEN, ZERO, CES_CMDIF_TYPE_DATA }; + +uint8_t data_len = 0x0C; + +MAX30001 max30001(MAX30001_CS_PIN); + +signed long ecg_data; +signed long bioz_data; + +void sendData(signed long ecg_sample, signed long bioz_sample, bool _bioZSkipSample) { + + DataPacket[0] = ecg_sample; + DataPacket[1] = ecg_sample >> 8; + DataPacket[2] = ecg_sample >> 16; + DataPacket[3] = ecg_sample >> 24; + + DataPacket[4] = bioz_sample; + DataPacket[5] = bioz_sample >> 8; + DataPacket[6] = bioz_sample >> 16; + DataPacket[7] = bioz_sample >> 24; + + if (_bioZSkipSample == false) { + DataPacket[8] = 0x00; + } else { + DataPacket[8] = 0xFF; + } + + DataPacket[9] = 0x00; // max30001.heartRate >> 8; + DataPacket[10] = 0x00; + DataPacket[11] = 0x00; + + // Send packet header (in ProtoCentral OpenView format) + for (int i = 0; i < 5; i++) { + Serial.write(DataPacketHeader[i]); + } + + // Send the data payload + for (int i = 0; i < DATA_LEN; i++) // transmit the data + { + Serial.write(DataPacket[i]); + } + + // Send packet footer (in ProtoCentral OpenView format) + for (int i = 0; i < 2; i++) { + Serial.write(DataPacketFooter[i]); + } +} + +bool BioZSkipSample = false; + +void setup() +{ + Serial.begin(57600); // Serial begin + + pinMode(MAX30001_CS_PIN, OUTPUT); + digitalWrite(MAX30001_CS_PIN, HIGH); + + pinMode(MAX30001_INTB_PIN, INPUT); + + SPI.setRX(SPI_MISO_PIN); + SPI.setTX(SPI_MOSI_PIN); + SPI.setSCK(SPI_SCK_PIN); + + SPI.begin(); + + bool ret = max30001.max30001ReadInfo(); + if (ret) { + Serial.println("MAX 30001 read ID Success"); + } else { + while (!ret) { + // stay here untill the issue is fixed. + ret = max30001.max30001ReadInfo(); + Serial.println("Failed to read ID, please make sure all the pins are connected"); + delay(5000); + } + } + + Serial.println("Initialising the chip ..."); + max30001.BeginECGBioZ(); // initialize MAX30001 + // max30001.Begin(); + + Serial.println("Chip initialised"); + attachInterrupt(digitalPinToInterrupt(MAX30001_INTB_PIN), intr_cb, FALLING); + + +} + +//Interrupt callback handler +void intr_cb() { + //spi_data_available = 1; + //Read the interrupt status register + // max30001.readStatus(); + //Serial.println("I"); + max30001.readStatus(); + ecg_data = max30001.getECGSamples(); + bioz_data = max30001.getBioZSamples(); +} + +void loop() { + //ecg_data = max30001.getECGSamples(); + // max30001.getHRandRR(); + if (BioZSkipSample == false) { + //bioz_data = max30001.getBioZSamples(); + //sendData(ecg_data, bioz_data, BioZSkipSample); + BioZSkipSample = true; + } else + { + bioz_data = 0x00; + //sendData(ecg_data, bioz_data, BioZSkipSample); + BioZSkipSample=false; + } + delay(4); +} \ No newline at end of file diff --git a/src/protocentral_max30001.cpp b/src/protocentral_max30001.cpp index 63acb2a..a5240af 100644 --- a/src/protocentral_max30001.cpp +++ b/src/protocentral_max30001.cpp @@ -69,6 +69,31 @@ void MAX30001::_max30001RegWrite (unsigned char WRITE_ADDRESS, unsigned long dat SPI.endTransaction(); } +void MAX30001::_max30001RegRead24(uint8_t Reg_address, uint32_t *read_data) +{ + uint8_t spiTxBuff; + + uint8_t buff[4]; + + SPI.beginTransaction(SPISettings(MAX30001_SPI_SPEED, MSBFIRST, SPI_MODE0)); + + digitalWrite(_cs_pin, LOW); + + spiTxBuff = (Reg_address<<1 ) | RREG; + SPI.transfer(spiTxBuff); //Send register location + + for ( int i = 0; i < 3; i++) + { + buff[i] = SPI.transfer(0xff); + } + + digitalWrite(_cs_pin, HIGH); + + *read_data = (buff[0]<<16) | (buff[1]<<8) | buff[2]; + + SPI.endTransaction(); +} + void MAX30001::_max30001RegRead(uint8_t Reg_address, uint8_t * buff) { uint8_t spiTxBuff; @@ -183,6 +208,8 @@ void MAX30001::BeginECGBioZ() _max30001RegWrite(CNFG_BMUX,0x000040); // Pins connected internally to BioZ channels delay(100); + setInterrupts(EN_EINT|0x01); // Enable ECG Interrupts + //_max30001RegWrite(CNFG_RTOR1,0x3fc600); _max30001Synch(); delay(100); @@ -294,11 +321,33 @@ void MAX30001::getHRandRR(void) RRinterval = RR; } -void MAX30001::setInterrupts(void) +void MAX30001::setInterrupts(uint32_t interrupts_to_set) { - - _max30001RegWrite(EN_INT, 0x000401); + _max30001RegWrite(EN_INT, interrupts_to_set); delay(100); //_max30001Synch(); //delay(100); -} \ No newline at end of file +} + +void MAX30001::readStatus(void) { + /*uint8_t regReadBuff[4]; + _max30001RegRead(STATUS, regReadBuff); + unsigned long status = (unsigned long) (regReadBuff[0]); + status = status <<24; + unsigned long status1 = (unsigned long) (regReadBuff[1]); + status1 = status1 <<16; + unsigned long status2 = (unsigned long) (regReadBuff[2]); + status2 = status2 <<8; + unsigned long status3 = (unsigned long) (regReadBuff[3]); + status = (unsigned long) (status | status1 | status2 | status3); + Serial.print("Status: "); + Serial.println(status, HEX); + */ + + _max30001RegRead24(STATUS, &global_status.all); + + Serial.print("Status: "); + Serial.println(global_status.all, HEX); + + +} diff --git a/src/protocentral_max30001.h b/src/protocentral_max30001.h index a44cc14..0d673b1 100644 --- a/src/protocentral_max30001.h +++ b/src/protocentral_max30001.h @@ -1,4 +1,4 @@ -// ______ _ _____ _ _ +// ______ _ _____ _ _ // | ___ \ | | / __ \ | | | | // | |_/ / __ ___ | |_ ___ | / \/ ___ _ __ | |_ _ __ __ _| | // | __/ '__/ _ \| __/ _ \| | / _ \ '_ \| __| '__/ _` | | @@ -28,6 +28,48 @@ #include +typedef union max30001_status_reg +{ + uint32_t all; + + struct + { + uint32_t loff_nl : 1; + uint32_t loff_nh : 1; + uint32_t loff_pl : 1; + uint32_t loff_ph : 1; + + uint32_t bcgmn : 1; + uint32_t bcgmp : 1; + uint32_t reserved1 : 1; + uint32_t reserved2 : 1; + + uint32_t pllint : 1; + uint32_t samp : 1; + uint32_t rrint : 1; + uint32_t lonint : 1; + + uint32_t pedge : 1; + uint32_t povf : 1; + uint32_t pint : 1; + uint32_t bcgmon : 1; + + uint32_t bundr : 1; + uint32_t bover : 1; + uint32_t bovf : 1; + uint32_t bint : 1; + + uint32_t dcloffint : 1; + uint32_t fstint : 1; + uint32_t eovf : 1; + uint32_t eint : 1; + + uint32_t reserved : 8; + + } bit; + +} max30001_status_t; + typedef enum { SAMPLINGRATE_128 = 128, @@ -47,19 +89,27 @@ class MAX30001 void BeginECGOnly(); void BeginECGBioZ(); void BeginRtoRMode(); - + signed long getECGSamples(void); signed long getBioZSamples(void); void getHRandRR(void); bool max30001ReadInfo(void); void max30001SetsamplingRate(uint16_t samplingRate); - + + void setInterrupts(uint32_t interrupts); + void readStatus(void); + + max30001_status_t global_status; + private: - void _max30001ReadData(int num_samples, uint8_t *readBuffer); + void + _max30001ReadData(int num_samples, uint8_t *readBuffer); void _max30001Synch(void); void _max30001RegWrite(unsigned char WRITE_ADDRESS, unsigned long data); void _max30001RegRead(uint8_t Reg_address, uint8_t *buff); + void _max30001RegRead24(uint8_t Reg_address, uint32_t *read_data); + void _max30001SwReset(void); int _cs_pin; @@ -82,7 +132,7 @@ class MAX30001 #define CNFG_EMUX 0x14 #define CNFG_ECG 0x15 -#define CNFG_BIOZ_LC 0x1A +#define CNFG_BIOZ_LC 0x1A #define CNFG_BMUX 0x17 #define CNFG_BIOZ 0x18 @@ -102,28 +152,31 @@ class MAX30001 #define CLK_PIN 6 #define RTOR_INTR_MASK 0x04 -enum EN_INT_bits { - EN_EINT=0x800000, - EN_ECG_FIFO_OVF=0x400000, - EN_ECG_FAST_REC=0x200000, - EN_DCLOFFINT=0x100000, - EN_BIOZ_FIFO_INT=0x80000, - EN_BIOZ_FIFO_OVF=0x40000, - EN_BIOZ_OVER_RANGE=0x20000, - EN_BIOZ_UNDER_RANGE=0x10000, - EN_BIOZ_CG_MON=0x8000, - - EN_LONINT=0x800, - EN_RRINT=0x400, - EN_SAMP=0x200, - EN_PLLINT=0x100, - - EN_BCGMP=0x20, - EN_BCGMN=0x10, - EN_LDOFF_PH=0x8, - EN_LDOFF_PL=0x4, - EN_LDOFF_NH=0x2, - EN_LDOFF_NL=0x1 +enum EN_INT_bits +{ + EN_EINT = 0x800000, + EN_ECG_FIFO_OVF = 0x400000, + EN_ECG_FAST_REC = 0x200000, + EN_DCLOFFINT = 0x100000, + EN_BIOZ_FIFO_INT = 0x80000, + EN_BIOZ_FIFO_OVF = 0x40000, + EN_BIOZ_OVER_RANGE = 0x20000, + EN_BIOZ_UNDER_RANGE = 0x10000, + EN_BIOZ_CG_MON = 0x8000, + + EN_LONINT = 0x800, + EN_RRINT = 0x400, + EN_SAMP = 0x200, + EN_PLLINT = 0x100, + + EN_BCGMP = 0x20, + EN_BCGMN = 0x10, + EN_LDOFF_PH = 0x8, + EN_LDOFF_PL = 0x4, + EN_LDOFF_NH = 0x2, + EN_LDOFF_NL = 0x1 }; + + #endif From 84f9914ad2b4d657835bf19ce0dba22a112473a4 Mon Sep 17 00:00:00 2001 From: Ashwin K Whitchurch Date: Fri, 10 Mar 2023 23:18:44 +0530 Subject: [PATCH 03/18] Added readback functions. Untested --- .../Example2-Interrupt-Driven.ino | 9 +- src/protocentral_max30001.cpp | 261 +++++++++--------- src/protocentral_max30001.h | 163 ++++++----- 3 files changed, 237 insertions(+), 196 deletions(-) diff --git a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino index e39068c..ac17554 100644 --- a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino +++ b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino @@ -146,9 +146,12 @@ void intr_cb() { //Read the interrupt status register // max30001.readStatus(); //Serial.println("I"); - max30001.readStatus(); - ecg_data = max30001.getECGSamples(); - bioz_data = max30001.getBioZSamples(); + //max30001.readStatus(); + //ecg_data = max30001.getECGSamples(); + //bioz_data = max30001.getBioZSamples(); + max30001.max30001ServiceAllInterrupts(); + + } void loop() { diff --git a/src/protocentral_max30001.cpp b/src/protocentral_max30001.cpp index a5240af..ffb1c98 100644 --- a/src/protocentral_max30001.cpp +++ b/src/protocentral_max30001.cpp @@ -1,10 +1,10 @@ -// ______ _ _____ _ _ +// ______ _ _____ _ _ // | ___ \ | | / __ \ | | | | // | |_/ / __ ___ | |_ ___ | / \/ ___ _ __ | |_ _ __ __ _| | // | __/ '__/ _ \| __/ _ \| | / _ \ '_ \| __| '__/ _` | | // | | | | | (_) | || (_) | \__/\ __/ | | | |_| | | (_| | | -// \_| |_| \___/ \__\___/ \____/\___|_| |_|\__|_| \__,_|_| - +// \_| |_| \___/ \__\___/ \____/\___|_| |_|\__|_| \__,_|_| + ////////////////////////////////////////////////////////////////////////////////////////// // // Demo code for the MAX30001 breakout board @@ -35,23 +35,22 @@ // ///////////////////////////////////////////////////////////////////////////////////////// -#include +#include #include "protocentral_max30001.h" #define MAX30001_SPI_SPEED 1000000 MAX30001::MAX30001(int cs_pin) { - _cs_pin=cs_pin; + _cs_pin = cs_pin; pinMode(_cs_pin, OUTPUT); - digitalWrite(_cs_pin,HIGH); - - + digitalWrite(_cs_pin, HIGH); } -void MAX30001::_max30001RegWrite (unsigned char WRITE_ADDRESS, unsigned long data) + +void MAX30001::_max30001RegWrite(unsigned char WRITE_ADDRESS, unsigned long data) { - //Combine the register address and the command into one byte: - byte dataToSend = (WRITE_ADDRESS<<1) | WREG; + // Combine the register address and the command into one byte: + byte dataToSend = (WRITE_ADDRESS << 1) | WREG; SPI.beginTransaction(SPISettings(MAX30001_SPI_SPEED, MSBFIRST, SPI_MODE0)); @@ -59,8 +58,8 @@ void MAX30001::_max30001RegWrite (unsigned char WRITE_ADDRESS, unsigned long dat delay(2); SPI.transfer(dataToSend); - SPI.transfer(data>>16); - SPI.transfer(data>>8); + SPI.transfer(data >> 16); + SPI.transfer(data >> 8); SPI.transfer(data); delay(2); @@ -79,22 +78,22 @@ void MAX30001::_max30001RegRead24(uint8_t Reg_address, uint32_t *read_data) digitalWrite(_cs_pin, LOW); - spiTxBuff = (Reg_address<<1 ) | RREG; - SPI.transfer(spiTxBuff); //Send register location + spiTxBuff = (Reg_address << 1) | RREG; + SPI.transfer(spiTxBuff); // Send register location - for ( int i = 0; i < 3; i++) + for (int i = 0; i < 3; i++) { - buff[i] = SPI.transfer(0xff); + buff[i] = SPI.transfer(0xff); } digitalWrite(_cs_pin, HIGH); - *read_data = (buff[0]<<16) | (buff[1]<<8) | buff[2]; - + *read_data = (buff[0] << 16) | (buff[1] << 8) | buff[2]; + SPI.endTransaction(); } -void MAX30001::_max30001RegRead(uint8_t Reg_address, uint8_t * buff) +void MAX30001::_max30001RegRead(uint8_t Reg_address, uint8_t *buff) { uint8_t spiTxBuff; @@ -102,69 +101,51 @@ void MAX30001::_max30001RegRead(uint8_t Reg_address, uint8_t * buff) digitalWrite(_cs_pin, LOW); - spiTxBuff = (Reg_address<<1 ) | RREG; - SPI.transfer(spiTxBuff); //Send register location + spiTxBuff = (Reg_address << 1) | RREG; + SPI.transfer(spiTxBuff); // Send register location - for ( int i = 0; i < 3; i++) + for (int i = 0; i < 3; i++) { - buff[i] = SPI.transfer(0xff); + buff[i] = SPI.transfer(0xff); } digitalWrite(_cs_pin, HIGH); - + SPI.endTransaction(); } void MAX30001::_max30001SwReset(void) { - _max30001RegWrite(SW_RST,0x000000); + _max30001RegWrite(SW_RST, 0x000000); delay(100); } void MAX30001::_max30001Synch(void) { - _max30001RegWrite(SYNCH,0x000000); + _max30001RegWrite(SYNCH, 0x000000); } bool MAX30001::max30001ReadInfo(void) { - uint8_t readBuff[4] ; + uint8_t readBuff[4]; _max30001RegRead(INFO, readBuff); - if((readBuff[0]&0xf0) == 0x50 ){ - Serial.print("MAX30001 Detected. Rev ID: "); - Serial.println((readBuff[0]&0xf0)); - - return true; - }else{ + if ((readBuff[0] & 0xf0) == 0x50) + { + Serial.print("MAX30001 Detected. Rev ID: "); + Serial.println((readBuff[0] & 0xf0)); - Serial.println("MAX30001 read info error\n"); - return false; + return true; } - - return false; -} - -void MAX30001::_max30001ReadData(int num_samples, uint8_t * readBuffer) -{ - uint8_t spiTxBuff; - - SPI.beginTransaction(SPISettings(MAX30001_SPI_SPEED, MSBFIRST, SPI_MODE0)); - - digitalWrite(_cs_pin, LOW); - - spiTxBuff = (ECG_FIFO_BURST<<1 ) | RREG; - SPI.transfer(spiTxBuff); //Send register location - - for ( int i = 0; i < num_samples*3; ++i) + else { - readBuffer[i] = SPI.transfer(0x00); - } - digitalWrite(_cs_pin, HIGH); + Serial.println("MAX30001 read info error\n"); + return false; + } - SPI.endTransaction(); + return false; } void MAX30001::BeginECGOnly() @@ -173,14 +154,14 @@ void MAX30001::BeginECGOnly() delay(100); _max30001RegWrite(CNFG_GEN, 0x081007); delay(100); - _max30001RegWrite(CNFG_CAL, 0x720000); // 0x700000 + _max30001RegWrite(CNFG_CAL, 0x720000); // 0x700000 delay(100); - _max30001RegWrite(CNFG_EMUX,0x0B0000); + _max30001RegWrite(CNFG_EMUX, 0x0B0000); delay(100); - _max30001RegWrite(CNFG_ECG, 0x825000); // d23 - d22 : 10 for 250sps , 00:500 sps + _max30001RegWrite(CNFG_ECG, 0x825000); // d23 - d22 : 10 for 250sps , 00:500 sps delay(100); - _max30001RegWrite(CNFG_RTOR1,0x3fc600); + _max30001RegWrite(CNFG_RTOR1, 0x3fc600); _max30001Synch(); delay(100); } @@ -191,24 +172,24 @@ void MAX30001::BeginECGBioZ() delay(100); _max30001RegWrite(CNFG_GEN, 0x0C0004); // ECG & BioZ Enabled , FMSTR = 32768 delay(100); - _max30001RegWrite(CNFG_CAL, 0x720000); // Calibration sources disabled + _max30001RegWrite(CNFG_CAL, 0x720000); // Calibration sources disabled delay(100); - _max30001RegWrite(CNFG_ECG, 0x825000); // ECG_RATE: 125 SPS, + _max30001RegWrite(CNFG_ECG, 0x825000); // ECG_RATE: 125 SPS, delay(100); - _max30001RegWrite(CNFG_EMUX,0x0B0000); // Pins internally connection to ECG Channels + _max30001RegWrite(CNFG_EMUX, 0x0B0000); // Pins internally connection to ECG Channels delay(100); - _max30001RegWrite(CNFG_BIOZ, 0x201433); // BioZ Rate: 64 SPS | Current generator: 32 uA + _max30001RegWrite(CNFG_BIOZ, 0x201433); // BioZ Rate: 64 SPS | Current generator: 32 uA delay(100); - //Set MAX30001G specific BioZ LC + // Set MAX30001G specific BioZ LC _max30001RegWrite(CNFG_BIOZ_LC, 0x800000); // Turn OFF low current mode - _max30001RegWrite(CNFG_BMUX,0x000040); // Pins connected internally to BioZ channels + _max30001RegWrite(CNFG_BMUX, 0x000040); // Pins connected internally to BioZ channels delay(100); - setInterrupts(EN_EINT|0x01); // Enable ECG Interrupts + max30001SetInterrupts(EN_EINT | 0x01); // Enable ECG Interrupts //_max30001RegWrite(CNFG_RTOR1,0x3fc600); _max30001Synch(); @@ -221,13 +202,13 @@ void MAX30001::BeginRtoRMode() delay(100); _max30001RegWrite(CNFG_GEN, 0x080004); delay(100); - _max30001RegWrite(CNFG_CAL, 0x720000); // 0x700000 + _max30001RegWrite(CNFG_CAL, 0x720000); // 0x700000 delay(100); - _max30001RegWrite(CNFG_EMUX,0x0B0000); + _max30001RegWrite(CNFG_EMUX, 0x0B0000); delay(100); - _max30001RegWrite(CNFG_ECG, 0x805000); // d23 - d22 : 10 for 250sps , 00:500 sps + _max30001RegWrite(CNFG_ECG, 0x805000); // d23 - d22 : 10 for 250sps , 00:500 sps delay(100); - _max30001RegWrite(CNFG_RTOR1,0x3fc600); + _max30001RegWrite(CNFG_RTOR1, 0x3fc600); delay(100); _max30001RegWrite(EN_INT, 0x000401); delay(100); @@ -235,28 +216,29 @@ void MAX30001::BeginRtoRMode() delay(100); } -//not tested +// not tested void MAX30001::max30001SetsamplingRate(uint16_t samplingRate) { uint8_t regBuff[4] = {0}; _max30001RegRead(CNFG_ECG, regBuff); - switch(samplingRate){ - case SAMPLINGRATE_128: - regBuff[0] = (regBuff[0] | 0x80 ); - break; + switch (samplingRate) + { + case SAMPLINGRATE_128: + regBuff[0] = (regBuff[0] | 0x80); + break; - case SAMPLINGRATE_256: - regBuff[0] = (regBuff[0] | 0x40 ); - break; + case SAMPLINGRATE_256: + regBuff[0] = (regBuff[0] | 0x40); + break; - case SAMPLINGRATE_512: - regBuff[0] = (regBuff[0] | 0x00 ); - break; + case SAMPLINGRATE_512: + regBuff[0] = (regBuff[0] | 0x00); + break; - default : - Serial.println("Invalid sample rate. Please choose between 128, 256 or 512"); - break; + default: + Serial.println("Invalid sample rate. Please choose between 128, 256 or 512"); + break; } unsigned long cnfgEcg; @@ -272,16 +254,16 @@ signed long MAX30001::getECGSamples(void) uint8_t regReadBuff[4]; _max30001RegRead(ECG_FIFO, regReadBuff); - unsigned long data0 = (unsigned long) (regReadBuff[0]); - data0 = data0 <<24; - unsigned long data1 = (unsigned long) (regReadBuff[1]); - data1 = data1 <<16; - unsigned long data2 = (unsigned long) (regReadBuff[2]); - data2 = data2 >>6; + unsigned long data0 = (unsigned long)(regReadBuff[0]); + data0 = data0 << 24; + unsigned long data1 = (unsigned long)(regReadBuff[1]); + data1 = data1 << 16; + unsigned long data2 = (unsigned long)(regReadBuff[2]); + data2 = data2 >> 6; data2 = data2 & 0x03; - unsigned long data = (unsigned long) (data0 | data1 | data2); - ecg_data = (signed long) data; + unsigned long data = (unsigned long)(data0 | data1 | data2); + ecg_data = (signed long)data; return ecg_data; } @@ -289,65 +271,94 @@ signed long MAX30001::getBioZSamples(void) { uint8_t regReadBuff[4]; _max30001RegRead(BIOZ_FIFO, regReadBuff); - - unsigned long data0 = (unsigned long) (regReadBuff[0]); - data0 = data0 <<24; - unsigned long data1 = (unsigned long) (regReadBuff[1]); - data1 = data1 <<16; - unsigned long data2 = (unsigned long) (regReadBuff[2]); - data2 = data2 >>6; + + unsigned long data0 = (unsigned long)(regReadBuff[0]); + data0 = data0 << 24; + unsigned long data1 = (unsigned long)(regReadBuff[1]); + data1 = data1 << 16; + unsigned long data2 = (unsigned long)(regReadBuff[2]); + data2 = data2 >> 6; data2 = data2 & 0x03; - unsigned long data = (unsigned long) (data0 | data1 | data2); - bioz_data = (signed long) (data); + unsigned long data = (unsigned long)(data0 | data1 | data2); + bioz_data = (signed long)(data); return bioz_data; } - void MAX30001::getHRandRR(void) { uint8_t regReadBuff[4]; _max30001RegRead(RTOR, regReadBuff); - unsigned long RTOR_msb = (unsigned long) (regReadBuff[0]); - unsigned char RTOR_lsb = (unsigned char) (regReadBuff[1]); - unsigned long rtor = (RTOR_msb<<8 | RTOR_lsb); - rtor = ((rtor >>2) & 0x3fff) ; + unsigned long RTOR_msb = (unsigned long)(regReadBuff[0]); + unsigned char RTOR_lsb = (unsigned char)(regReadBuff[1]); + unsigned long rtor = (RTOR_msb << 8 | RTOR_lsb); + rtor = ((rtor >> 2) & 0x3fff); - float hr = 60 /((float)rtor*0.0078125); + float hr = 60 / ((float)rtor * 0.0078125); heartRate = (unsigned int)hr; - unsigned int RR = (unsigned int)rtor* (7.8125) ; //8ms + unsigned int RR = (unsigned int)rtor * (7.8125); // 8ms RRinterval = RR; } -void MAX30001::setInterrupts(uint32_t interrupts_to_set) +void MAX30001::max30001SetInterrupts(uint32_t interrupts_to_set) { _max30001RegWrite(EN_INT, interrupts_to_set); delay(100); //_max30001Synch(); - //delay(100); + // delay(100); } -void MAX30001::readStatus(void) { - /*uint8_t regReadBuff[4]; - _max30001RegRead(STATUS, regReadBuff); - unsigned long status = (unsigned long) (regReadBuff[0]); - status = status <<24; - unsigned long status1 = (unsigned long) (regReadBuff[1]); - status1 = status1 <<16; - unsigned long status2 = (unsigned long) (regReadBuff[2]); - status2 = status2 <<8; - unsigned long status3 = (unsigned long) (regReadBuff[3]); - status = (unsigned long) (status | status1 | status2 | status3); - Serial.print("Status: "); - Serial.println(status, HEX); - */ +/**/ +void MAX30001::readStatus(void) +{ _max30001RegRead24(STATUS, &global_status.all); Serial.print("Status: "); Serial.println(global_status.all, HEX); +} + +void MAX30001::_max30001ReadECGFIFO(int num_samples, uint8_t *readBuffer) +{ + uint8_t spiTxBuff; + SPI.beginTransaction(SPISettings(MAX30001_SPI_SPEED, MSBFIRST, SPI_MODE0)); + + digitalWrite(_cs_pin, LOW); + + spiTxBuff = (ECG_FIFO_BURST << 1) | RREG; + SPI.transfer(spiTxBuff); // Send register location + + for (int i = 0; i < num_samples * 3; ++i) + { + readBuffer[i] = SPI.transfer(0x00); + } + digitalWrite(_cs_pin, HIGH); + + SPI.endTransaction(); +} + +void MAX30001::max30001ServiceAllInterrupts(void) +{ + static uint32_t InitReset = 0; + int fifo_num_bytes = 0; + + max30001_mngr_int_t mngr_int; + + readStatus(); + + if (global_status.bit.eint == 1) // EINT bit is set. FIFO is full + { + // Read the number of bytes in FIFO (from MNGR_INT register) + _max30001RegRead24(MNGR_INT, &mngr_int.all); + fifo_num_bytes = (mngr_int.bit.e_fit + 1) * 3; + + // Read ECG FIFO in Burst mode + _max30001ReadECGFIFO(fifo_num_bytes, _readBuffer); + + // Read BIOZ FIFO in Burst mode + } } diff --git a/src/protocentral_max30001.h b/src/protocentral_max30001.h index 0d673b1..2ec0ffd 100644 --- a/src/protocentral_max30001.h +++ b/src/protocentral_max30001.h @@ -28,6 +28,68 @@ #include +#define WREG 0x00 +#define RREG 0x01 + +#define STATUS 0x01 +#define EN_INT 0x02 +#define EN_INT2 0x03 +#define MNGR_INT 0x04 +#define MNGR_DYN 0x05 +#define SW_RST 0x08 +#define SYNCH 0x09 +#define FIFO_RST 0x0A +#define INFO 0x0F +#define CNFG_GEN 0x10 +#define CNFG_CAL 0x12 +#define CNFG_EMUX 0x14 +#define CNFG_ECG 0x15 + +#define CNFG_BIOZ_LC 0x1A + +#define CNFG_BMUX 0x17 +#define CNFG_BIOZ 0x18 + +#define CNFG_RTOR1 0x1D +#define CNFG_RTOR2 0x1E + +#define ECG_FIFO_BURST 0x20 +#define ECG_FIFO 0x21 + +#define BIOZ_FIFO_BURST 0x22 +#define BIOZ_FIFO 0x23 + +#define RTOR 0x25 +#define NO_OP 0x7F + +#define CLK_PIN 6 +#define RTOR_INTR_MASK 0x04 + +enum EN_INT_bits +{ + EN_EINT = 0x800000, + EN_ECG_FIFO_OVF = 0x400000, + EN_ECG_FAST_REC = 0x200000, + EN_DCLOFFINT = 0x100000, + EN_BIOZ_FIFO_INT = 0x80000, + EN_BIOZ_FIFO_OVF = 0x40000, + EN_BIOZ_OVER_RANGE = 0x20000, + EN_BIOZ_UNDER_RANGE = 0x10000, + EN_BIOZ_CG_MON = 0x8000, + + EN_LONINT = 0x800, + EN_RRINT = 0x400, + EN_SAMP = 0x200, + EN_PLLINT = 0x100, + + EN_BCGMP = 0x20, + EN_BCGMN = 0x10, + EN_LDOFF_PH = 0x8, + EN_LDOFF_PL = 0x4, + EN_LDOFF_NH = 0x2, + EN_LDOFF_NL = 0x1 +}; + typedef union max30001_status_reg { uint32_t all; @@ -70,6 +132,33 @@ typedef union max30001_status_reg } max30001_status_t; +/** + * @brief MNGR_INT (0x04) + */ +typedef union max30001_mngr_int_reg +{ + uint32_t all; + + struct + { + uint32_t samp_it : 2; + uint32_t clr_samp : 1; + uint32_t clr_pedge : 1; + uint32_t clr_rrint : 2; + uint32_t clr_fast : 1; + uint32_t reserved1 : 1; + uint32_t reserved2 : 4; + uint32_t reserved3 : 4; + + uint32_t b_fit : 3; + uint32_t e_fit : 5; + + uint32_t reserved : 8; + + } bit; + +} max30001_mngr_int_t; + typedef enum { SAMPLINGRATE_128 = 128, @@ -97,14 +186,14 @@ class MAX30001 bool max30001ReadInfo(void); void max30001SetsamplingRate(uint16_t samplingRate); - void setInterrupts(uint32_t interrupts); - void readStatus(void); + void max30001SetInterrupts(uint32_t interrupts); + void max30001ServiceAllInterrupts(); - max30001_status_t global_status; + void readStatus(void); private: void - _max30001ReadData(int num_samples, uint8_t *readBuffer); + _max30001ReadECGFIFO(int num_samples, uint8_t *readBuffer); void _max30001Synch(void); void _max30001RegWrite(unsigned char WRITE_ADDRESS, unsigned long data); void _max30001RegRead(uint8_t Reg_address, uint8_t *buff); @@ -112,71 +201,9 @@ class MAX30001 void _max30001SwReset(void); + max30001_status_t global_status; int _cs_pin; + uint8_t _readBuffer[128]; // 4*32 samples }; -#define WREG 0x00 -#define RREG 0x01 - -#define STATUS 0x01 -#define EN_INT 0x02 -#define EN_INT2 0x03 -#define MNGR_INT 0x04 -#define MNGR_DYN 0x05 -#define SW_RST 0x08 -#define SYNCH 0x09 -#define FIFO_RST 0x0A -#define INFO 0x0F -#define CNFG_GEN 0x10 -#define CNFG_CAL 0x12 -#define CNFG_EMUX 0x14 -#define CNFG_ECG 0x15 - -#define CNFG_BIOZ_LC 0x1A - -#define CNFG_BMUX 0x17 -#define CNFG_BIOZ 0x18 - -#define CNFG_RTOR1 0x1D -#define CNFG_RTOR2 0x1E - -#define ECG_FIFO_BURST 0x20 -#define ECG_FIFO 0x21 - -#define BIOZ_FIFO_BURST 0x22 -#define BIOZ_FIFO 0x23 - -#define RTOR 0x25 -#define NO_OP 0x7F - -#define CLK_PIN 6 -#define RTOR_INTR_MASK 0x04 - -enum EN_INT_bits -{ - EN_EINT = 0x800000, - EN_ECG_FIFO_OVF = 0x400000, - EN_ECG_FAST_REC = 0x200000, - EN_DCLOFFINT = 0x100000, - EN_BIOZ_FIFO_INT = 0x80000, - EN_BIOZ_FIFO_OVF = 0x40000, - EN_BIOZ_OVER_RANGE = 0x20000, - EN_BIOZ_UNDER_RANGE = 0x10000, - EN_BIOZ_CG_MON = 0x8000, - - EN_LONINT = 0x800, - EN_RRINT = 0x400, - EN_SAMP = 0x200, - EN_PLLINT = 0x100, - - EN_BCGMP = 0x20, - EN_BCGMN = 0x10, - EN_LDOFF_PH = 0x8, - EN_LDOFF_PL = 0x4, - EN_LDOFF_NH = 0x2, - EN_LDOFF_NL = 0x1 -}; - - - #endif From 177ade87ef19bc1d4b40f3ee6dc4871ce23f942e Mon Sep 17 00:00:00 2001 From: Ashwin K Whitchurch Date: Mon, 13 Mar 2023 23:05:29 +0530 Subject: [PATCH 04/18] Add more functions --- src/protocentral_max30001.cpp | 21 +++++++++++++++++++++ src/protocentral_max30001.h | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/protocentral_max30001.cpp b/src/protocentral_max30001.cpp index ffb1c98..c8f5a1b 100644 --- a/src/protocentral_max30001.cpp +++ b/src/protocentral_max30001.cpp @@ -341,6 +341,27 @@ void MAX30001::_max30001ReadECGFIFO(int num_samples, uint8_t *readBuffer) SPI.endTransaction(); } +void MAX30001::_max30001ReadBIOZFIFO(int num_samples, uint8_t *readBuffer) +{ + uint8_t spiTxBuff; + + SPI.beginTransaction(SPISettings(MAX30001_SPI_SPEED, MSBFIRST, SPI_MODE0)); + + digitalWrite(_cs_pin, LOW); + + spiTxBuff = (BIOZ_FIFO_BURST << 1) | RREG; + SPI.transfer(spiTxBuff); // Send register location + + for (int i = 0; i < num_samples * 3; ++i) + { + readBuffer[i] = SPI.transfer(0x00); + } + + digitalWrite(_cs_pin, HIGH); + + SPI.endTransaction(); +} + void MAX30001::max30001ServiceAllInterrupts(void) { static uint32_t InitReset = 0; diff --git a/src/protocentral_max30001.h b/src/protocentral_max30001.h index 2ec0ffd..857216c 100644 --- a/src/protocentral_max30001.h +++ b/src/protocentral_max30001.h @@ -193,7 +193,9 @@ class MAX30001 private: void - _max30001ReadECGFIFO(int num_samples, uint8_t *readBuffer); + void _max30001ReadECGFIFO(int num_samples, uint8_t *readBuffer); + void _max30001ReadBIOZFIFO(int num_samples, uint8_t *readBuffer); + void _max30001Synch(void); void _max30001RegWrite(unsigned char WRITE_ADDRESS, unsigned long data); void _max30001RegRead(uint8_t Reg_address, uint8_t *buff); From c884b29be7e6dfac9fa0c38ae6ab4523c847714a Mon Sep 17 00:00:00 2001 From: Ashwin Date: Thu, 16 Mar 2023 11:46:24 +0530 Subject: [PATCH 05/18] Interrupt driven ex working --- .../Example2-Interrupt-Driven.ino | 19 ++++++++-- src/protocentral_max30001.cpp | 35 ++++++++++++++++--- src/protocentral_max30001.h | 9 +++-- 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino index ac17554..7d997a6 100644 --- a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino +++ b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino @@ -157,7 +157,7 @@ void intr_cb() { void loop() { //ecg_data = max30001.getECGSamples(); // max30001.getHRandRR(); - if (BioZSkipSample == false) { + /*if (BioZSkipSample == false) { //bioz_data = max30001.getBioZSamples(); //sendData(ecg_data, bioz_data, BioZSkipSample); BioZSkipSample = true; @@ -166,6 +166,19 @@ void loop() { bioz_data = 0x00; //sendData(ecg_data, bioz_data, BioZSkipSample); BioZSkipSample=false; - } - delay(4); + }*/ + + + + if(max30001.ecgSamplesAvailable>0) + { + //Serial.print("Data Available: "); + //Serial.println(max30001.ecgSamplesAvailable); + for(int i=0;i>8; + + s32ECGData[secg_counter++] = secgtemp; + } + + ecgSamplesAvailable = num_bytes/3; } void MAX30001::_max30001ReadBIOZFIFO(int num_samples, uint8_t *readBuffer) @@ -367,6 +385,9 @@ void MAX30001::max30001ServiceAllInterrupts(void) static uint32_t InitReset = 0; int fifo_num_bytes = 0; + + + max30001_mngr_int_t mngr_int; readStatus(); @@ -376,9 +397,13 @@ void MAX30001::max30001ServiceAllInterrupts(void) // Read the number of bytes in FIFO (from MNGR_INT register) _max30001RegRead24(MNGR_INT, &mngr_int.all); fifo_num_bytes = (mngr_int.bit.e_fit + 1) * 3; + // Serial.println("MNGR"); + // Serial.println(fifo_num_bytes); // Read ECG FIFO in Burst mode _max30001ReadECGFIFO(fifo_num_bytes, _readBuffer); + // getECGSamples(); + // ecgDataAvailable=fifo_num_bytes; // Read BIOZ FIFO in Burst mode } diff --git a/src/protocentral_max30001.h b/src/protocentral_max30001.h index 857216c..3a88165 100644 --- a/src/protocentral_max30001.h +++ b/src/protocentral_max30001.h @@ -175,6 +175,9 @@ class MAX30001 signed long ecg_data; signed long bioz_data; + int ecgSamplesAvailable; + signed long s32ECGData[128]; + void BeginECGOnly(); void BeginECGBioZ(); void BeginRtoRMode(); @@ -192,9 +195,9 @@ class MAX30001 void readStatus(void); private: - void - void _max30001ReadECGFIFO(int num_samples, uint8_t *readBuffer); - void _max30001ReadBIOZFIFO(int num_samples, uint8_t *readBuffer); + + void _max30001ReadECGFIFO(int num_bytes, uint8_t *readBuffer); + void _max30001ReadBIOZFIFO(int num_bytes, uint8_t *readBuffer); void _max30001Synch(void); void _max30001RegWrite(unsigned char WRITE_ADDRESS, unsigned long data); From a27cf08b4ac2640ab33fb3b54788334c9083ed40 Mon Sep 17 00:00:00 2001 From: Ashwin Date: Thu, 16 Mar 2023 13:48:28 +0530 Subject: [PATCH 06/18] Refactoring --- .../Example2-Interrupt-Driven.ino | 94 +++++++++---------- src/protocentral_max30001.cpp | 15 +-- 2 files changed, 48 insertions(+), 61 deletions(-) diff --git a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino index 7d997a6..5804df2 100644 --- a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino +++ b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino @@ -38,11 +38,11 @@ #define SPI_MOSI_PIN 3 #define SPI_MISO_PIN 4 -#define MAX30001_CS_PIN 5 -#define MAX30001_INTB_PIN 20 -#define MAX30001_INT2B_PIN 19 +#define MAX30001_CS_PIN 5 +#define MAX30001_INTB_PIN 20 +#define MAX30001_INT2B_PIN 19 -#define MAX30001_DELAY_SAMPLES 8 // Time between consecutive samples +#define MAX30001_DELAY_SAMPLES 8 // Time between consecutive samples #define CES_CMDIF_PKT_START_1 0x0A #define CES_CMDIF_PKT_START_2 0xFA @@ -52,8 +52,8 @@ #define ZERO 0 volatile char DataPacket[DATA_LEN]; -const char DataPacketFooter[2] = { ZERO, CES_CMDIF_PKT_STOP }; -const char DataPacketHeader[5] = { CES_CMDIF_PKT_START_1, CES_CMDIF_PKT_START_2, DATA_LEN, ZERO, CES_CMDIF_TYPE_DATA }; +const char DataPacketFooter[2] = {ZERO, CES_CMDIF_PKT_STOP}; +const char DataPacketHeader[5] = {CES_CMDIF_PKT_START_1, CES_CMDIF_PKT_START_2, DATA_LEN, ZERO, CES_CMDIF_TYPE_DATA}; uint8_t data_len = 0x0C; @@ -62,7 +62,8 @@ MAX30001 max30001(MAX30001_CS_PIN); signed long ecg_data; signed long bioz_data; -void sendData(signed long ecg_sample, signed long bioz_sample, bool _bioZSkipSample) { +void sendData(signed long ecg_sample, signed long bioz_sample, bool _bioZSkipSample) +{ DataPacket[0] = ecg_sample; DataPacket[1] = ecg_sample >> 8; @@ -74,55 +75,66 @@ void sendData(signed long ecg_sample, signed long bioz_sample, bool _bioZSkipSam DataPacket[6] = bioz_sample >> 16; DataPacket[7] = bioz_sample >> 24; - if (_bioZSkipSample == false) { + if (_bioZSkipSample == false) + { DataPacket[8] = 0x00; - } else { + } + else + { DataPacket[8] = 0xFF; } - DataPacket[9] = 0x00; // max30001.heartRate >> 8; + DataPacket[9] = 0x00; // max30001.heartRate >> 8; DataPacket[10] = 0x00; DataPacket[11] = 0x00; // Send packet header (in ProtoCentral OpenView format) - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 5; i++) + { Serial.write(DataPacketHeader[i]); } // Send the data payload - for (int i = 0; i < DATA_LEN; i++) // transmit the data + for (int i = 0; i < DATA_LEN; i++) // transmit the data { Serial.write(DataPacket[i]); } // Send packet footer (in ProtoCentral OpenView format) - for (int i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) + { Serial.write(DataPacketFooter[i]); } } bool BioZSkipSample = false; -void setup() +void setup() { - Serial.begin(57600); // Serial begin + Serial.begin(57600); // Serial begin pinMode(MAX30001_CS_PIN, OUTPUT); digitalWrite(MAX30001_CS_PIN, HIGH); pinMode(MAX30001_INTB_PIN, INPUT); +#ifdef ARDUINO_ARCH_RP2040 SPI.setRX(SPI_MISO_PIN); SPI.setTX(SPI_MOSI_PIN); SPI.setSCK(SPI_SCK_PIN); +#endif SPI.begin(); bool ret = max30001.max30001ReadInfo(); - if (ret) { + if (ret) + { Serial.println("MAX 30001 read ID Success"); - } else { - while (!ret) { + } + else + { + while (!ret) + { // stay here untill the issue is fixed. ret = max30001.max30001ReadInfo(); Serial.println("Failed to read ID, please make sure all the pins are connected"); @@ -131,32 +143,22 @@ void setup() } Serial.println("Initialising the chip ..."); - max30001.BeginECGBioZ(); // initialize MAX30001 - // max30001.Begin(); + max30001.BeginECGBioZ(); // initialize MAX30001 Serial.println("Chip initialised"); attachInterrupt(digitalPinToInterrupt(MAX30001_INTB_PIN), intr_cb, FALLING); - - } -//Interrupt callback handler -void intr_cb() { - //spi_data_available = 1; - //Read the interrupt status register - // max30001.readStatus(); - //Serial.println("I"); - //max30001.readStatus(); - //ecg_data = max30001.getECGSamples(); - //bioz_data = max30001.getBioZSamples(); +// Interrupt callback handler +void intr_cb() +{ max30001.max30001ServiceAllInterrupts(); - - } -void loop() { - //ecg_data = max30001.getECGSamples(); - // max30001.getHRandRR(); +void loop() +{ + // ecg_data = max30001.getECGSamples(); + // max30001.getHRandRR(); /*if (BioZSkipSample == false) { //bioz_data = max30001.getBioZSamples(); //sendData(ecg_data, bioz_data, BioZSkipSample); @@ -167,18 +169,16 @@ void loop() { //sendData(ecg_data, bioz_data, BioZSkipSample); BioZSkipSample=false; }*/ - - - if(max30001.ecgSamplesAvailable>0) + if (max30001.ecgSamplesAvailable > 0) + { + // Serial.print("Data Available: "); + // Serial.println(max30001.ecgSamplesAvailable); + for (int i = 0; i < max30001.ecgSamplesAvailable; i++) { - //Serial.print("Data Available: "); - //Serial.println(max30001.ecgSamplesAvailable); - for(int i=0;i Date: Sun, 19 Mar 2023 18:06:11 +0530 Subject: [PATCH 07/18] Move Interrupt handler to main loop --- .vscode/c_cpp_properties.json | 10 +-- .../Example2-Interrupt-Driven.ino | 9 +-- src/protocentral_max30001.cpp | 61 ++++++++++++++----- src/protocentral_max30001.h | 10 +-- 4 files changed, 58 insertions(+), 32 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index e4fe8d7..161dab3 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -16,10 +16,10 @@ ], "intelliSenseMode": "gcc-x64", "includePath": [ - "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.0.0/include", - "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.0.0/cores/rp2040", - "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.0.0/variants/rpipico", - "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.0.0/libraries/SPI/src", + "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.1.0/include", + "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.1.0/cores/rp2040", + "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.1.0/variants/rpipico", + "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.1.0/libraries/SPI/src", "/Users/akw/Documents/Arduino/libraries/protocentral_max30001_arduino_library/src", "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/arm-none-eabi/include/c++/10.3.0", "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/arm-none-eabi/include/c++/10.3.0/arm-none-eabi/thumb", @@ -29,7 +29,7 @@ "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/arm-none-eabi/include" ], "forcedInclude": [ - "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.0.0/cores/rp2040/Arduino.h" + "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.1.0/cores/rp2040/Arduino.h" ], "cStandard": "c11", "cppStandard": "c++17", diff --git a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino index 5804df2..821ea1f 100644 --- a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino +++ b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino @@ -146,17 +146,12 @@ void setup() max30001.BeginECGBioZ(); // initialize MAX30001 Serial.println("Chip initialised"); - attachInterrupt(digitalPinToInterrupt(MAX30001_INTB_PIN), intr_cb, FALLING); -} - -// Interrupt callback handler -void intr_cb() -{ - max30001.max30001ServiceAllInterrupts(); + //attachInterrupt(digitalPinToInterrupt(MAX30001_INTB_PIN), intr_cb, FALLING); } void loop() { + max30001.max30001ServiceAllInterrupts(); // ecg_data = max30001.getECGSamples(); // max30001.getHRandRR(); /*if (BioZSkipSample == false) { diff --git a/src/protocentral_max30001.cpp b/src/protocentral_max30001.cpp index 5dff2e8..6882c95 100644 --- a/src/protocentral_max30001.cpp +++ b/src/protocentral_max30001.cpp @@ -127,6 +127,11 @@ void MAX30001::_max30001Synch(void) _max30001RegWrite(SYNCH, 0x000000); } +void MAX30001::_max30001FIFOReset(void) +{ + _max30001RegWrite(FIFO_RST, 0x000000); +} + bool MAX30001::max30001ReadInfo(void) { uint8_t readBuff[4]; @@ -312,10 +317,12 @@ void MAX30001::max30001SetInterrupts(uint32_t interrupts_to_set) // delay(100); } -void MAX30001::_max30001ReadECGFIFO(int num_bytes, uint8_t *readBuffer) +int secg_counter = 0; + +void MAX30001::_max30001ReadECGFIFO(int num_bytes) { - uint8_t spiTxBuff; - unsigned long uecgtemp; + uint8_t spiTxBuff; + unsigned long uecgtemp; signed long secgtemp; SPI.beginTransaction(SPISettings(MAX30001_SPI_SPEED, MSBFIRST, SPI_MODE0)); @@ -325,31 +332,52 @@ void MAX30001::_max30001ReadECGFIFO(int num_bytes, uint8_t *readBuffer) spiTxBuff = (ECG_FIFO_BURST << 1) | RREG; SPI.transfer(spiTxBuff); // Send register location - for (int i = 0; i < num_bytes; ++i) + for (int i = 0; i < num_bytes; i++) { - readBuffer[i] = SPI.transfer(0x00); + _readBufferECG[i] = SPI.transfer(0x00); } digitalWrite(_cs_pin, HIGH); SPI.endTransaction(); - int secg_counter=0; + secg_counter = 0; + unsigned char ecg_etag; for (int i = 0; i < num_bytes; i += 3) { - uecgtemp=(unsigned long)((unsigned long)readBuffer[i]<<16 |(unsigned long)readBuffer[i+1]<<8| (unsigned long)readBuffer[i+2]); - uecgtemp=(unsigned long) (uecgtemp<<8); - secgtemp=(signed long)uecgtemp; - secgtemp=(signed long) secgtemp>>8; + // Get etag + ecg_etag = ((((unsigned char) _readBufferECG[i + 2]) & 0x38) >> 3); + Serial.println(ecg_etag, HEX); + if (ecg_etag == 0x00) + { + // uecgtemp=(unsigned long)((unsigned long)readBuffer[i]<<16 |(unsigned long)readBuffer[i+1]<<8| (unsigned long)(readBuffer[i+2]&0xC0)); + uecgtemp = (unsigned long)(((unsigned long)_readBufferECG[i] << 16 | (unsigned long)_readBufferECG[i + 1] << 8) | (unsigned long)(_readBufferECG[i+2]&0xC0)); + uecgtemp = (unsigned long)(uecgtemp << 8); + + secgtemp = (signed long)uecgtemp; + //secgtemp = (signed long)secgtemp >> 8; - s32ECGData[secg_counter++] = secgtemp; + s32ECGData[secg_counter++] = secgtemp; + } else if(ecg_etag==0x07) + { + Serial.println("OVF"); + _max30001FIFOReset(); + + + + } } - ecgSamplesAvailable = num_bytes/3; + Serial.print("F"); + Serial.println(secg_counter); + + secg_counter = 0; + + ecgSamplesAvailable = (num_bytes / 3); } -void MAX30001::_max30001ReadBIOZFIFO(int num_samples, uint8_t *readBuffer) +void MAX30001::_max30001ReadBIOZFIFO(int num_samples) { uint8_t spiTxBuff; @@ -362,7 +390,7 @@ void MAX30001::_max30001ReadBIOZFIFO(int num_samples, uint8_t *readBuffer) for (int i = 0; i < num_samples * 3; ++i) { - readBuffer[i] = SPI.transfer(0x00); + _readBufferBIOZ[i] = SPI.transfer(0x00); } digitalWrite(_cs_pin, HIGH); @@ -377,7 +405,7 @@ void MAX30001::max30001ServiceAllInterrupts(void) max30001_mngr_int_t mngr_int; - _max30001RegRead24(STATUS, &global_status.all); + _max30001RegRead24(STATUS, &global_status.all); if (global_status.bit.eint == 1) // EINT bit is set. FIFO is full { @@ -388,7 +416,8 @@ void MAX30001::max30001ServiceAllInterrupts(void) // Serial.println(fifo_num_bytes); // Read ECG FIFO in Burst mode - _max30001ReadECGFIFO(fifo_num_bytes, _readBuffer); + _max30001ReadECGFIFO(fifo_num_bytes); + //_max30001ReadBIOZFIFO(fifo_num_bytes/2, _readBufferBIOZ); // getECGSamples(); // ecgDataAvailable=fifo_num_bytes; diff --git a/src/protocentral_max30001.h b/src/protocentral_max30001.h index 3a88165..65eee31 100644 --- a/src/protocentral_max30001.h +++ b/src/protocentral_max30001.h @@ -175,7 +175,7 @@ class MAX30001 signed long ecg_data; signed long bioz_data; - int ecgSamplesAvailable; + volatile int ecgSamplesAvailable; signed long s32ECGData[128]; void BeginECGOnly(); @@ -196,8 +196,8 @@ class MAX30001 private: - void _max30001ReadECGFIFO(int num_bytes, uint8_t *readBuffer); - void _max30001ReadBIOZFIFO(int num_bytes, uint8_t *readBuffer); + void _max30001ReadECGFIFO(int num_bytes); + void _max30001ReadBIOZFIFO(int num_bytes); void _max30001Synch(void); void _max30001RegWrite(unsigned char WRITE_ADDRESS, unsigned long data); @@ -205,10 +205,12 @@ class MAX30001 void _max30001RegRead24(uint8_t Reg_address, uint32_t *read_data); void _max30001SwReset(void); + void _max30001FIFOReset(void); max30001_status_t global_status; int _cs_pin; - uint8_t _readBuffer[128]; // 4*32 samples + volatile unsigned char _readBufferECG[128]; // 4*32 samples + volatile unsigned char _readBufferBIOZ[128]; // 4*32 samples }; #endif From 03a486e174526fc42d315e75aae7fd427038aba3 Mon Sep 17 00:00:00 2001 From: Ashwin Date: Sun, 19 Mar 2023 18:27:34 +0530 Subject: [PATCH 08/18] Update ecg data available reading --- src/protocentral_max30001.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/protocentral_max30001.cpp b/src/protocentral_max30001.cpp index 6882c95..ddd563e 100644 --- a/src/protocentral_max30001.cpp +++ b/src/protocentral_max30001.cpp @@ -347,34 +347,33 @@ void MAX30001::_max30001ReadECGFIFO(int num_bytes) for (int i = 0; i < num_bytes; i += 3) { // Get etag - ecg_etag = ((((unsigned char) _readBufferECG[i + 2]) & 0x38) >> 3); - Serial.println(ecg_etag, HEX); - if (ecg_etag == 0x00) + ecg_etag = ((((unsigned char)_readBufferECG[i + 2]) & 0x38) >> 3); + //Serial.println(ecg_etag, HEX); + + if (ecg_etag == 0x00) //Valid sample { // uecgtemp=(unsigned long)((unsigned long)readBuffer[i]<<16 |(unsigned long)readBuffer[i+1]<<8| (unsigned long)(readBuffer[i+2]&0xC0)); uecgtemp = (unsigned long)(((unsigned long)_readBufferECG[i] << 16 | (unsigned long)_readBufferECG[i + 1] << 8) | (unsigned long)(_readBufferECG[i+2]&0xC0)); uecgtemp = (unsigned long)(uecgtemp << 8); secgtemp = (signed long)uecgtemp; - //secgtemp = (signed long)secgtemp >> 8; + secgtemp = (signed long)secgtemp >> 8; s32ECGData[secg_counter++] = secgtemp; - } else if(ecg_etag==0x07) + } + else if (ecg_etag == 0x07) //FIFO Overflow { - Serial.println("OVF"); + //Serial.println("OVF"); _max30001FIFOReset(); - - - } } - Serial.print("F"); - Serial.println(secg_counter); + //Serial.print("F"); + //Serial.println(secg_counter); + ecgSamplesAvailable = secg_counter ; secg_counter = 0; - ecgSamplesAvailable = (num_bytes / 3); } void MAX30001::_max30001ReadBIOZFIFO(int num_samples) From 67411e94475470ea8386fd787d3672f4f6b43ff2 Mon Sep 17 00:00:00 2001 From: Ashwin K Whitchurch Date: Sun, 19 Mar 2023 22:37:21 +0530 Subject: [PATCH 09/18] ECG Signal is clear --- .vscode/arduino.json | 3 +- examples/.DS_Store | Bin 6148 -> 6148 bytes .../Example1-ECG-BioZ-stream-Openview.ino | 55 +++++++++++------- .../Example2-Interrupt-Driven.ino | 2 +- src/protocentral_max30001.cpp | 16 +++-- 5 files changed, 47 insertions(+), 29 deletions(-) diff --git a/.vscode/arduino.json b/.vscode/arduino.json index ffdd47e..9a8cf88 100644 --- a/.vscode/arduino.json +++ b/.vscode/arduino.json @@ -1,7 +1,6 @@ { - "port": "/dev/tty.usbmodem101", + "port": "/dev/tty.usbmodem2101", "configuration": "flash=2097152_0,freq=133,opt=Small,rtti=Disabled,stackprotect=Disabled,exceptions=Disabled,dbgport=Disabled,dbglvl=None,usbstack=picosdk,ipbtstack=ipv4only,uploadmethod=default", "board": "rp2040:rp2040:rpipico", - "output": "../build", "sketch": "examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino" } \ No newline at end of file diff --git a/examples/.DS_Store b/examples/.DS_Store index 8742020d240c415819d8a4e6a0f8bc4fb6c46aa7..42c387b5a4d50b6a03ac763804e71dfea4860184 100644 GIT binary patch delta 383 zcmZoMXfc=|#>B!ku~2NHo+2aL#(>?7iyN4k7}+-SFeNkAOES1JR4^nmuu5=%;pof3;N4uv{GE9+zlb9T&_*VZEt?}m)-VGAFEw13 delta 67 zcmZoMXfc=|#>B)qu~2NHo+2a5#(>?7j4YdZSdtkxi*g9DOl)Y|%+A5j0aUVCkmEb^ VWPTAx4hA4#WME*~93irX82~Q$4*dWC diff --git a/examples/Example1-ECG-BioZ-stream-Openview/Example1-ECG-BioZ-stream-Openview.ino b/examples/Example1-ECG-BioZ-stream-Openview/Example1-ECG-BioZ-stream-Openview.ino index 07bca90..2c13c97 100644 --- a/examples/Example1-ECG-BioZ-stream-Openview/Example1-ECG-BioZ-stream-Openview.ino +++ b/examples/Example1-ECG-BioZ-stream-Openview/Example1-ECG-BioZ-stream-Openview.ino @@ -35,7 +35,7 @@ #include "protocentral_max30001.h" #define MAX30001_CS_PIN 7 -#define MAX30001_DELAY_SAMPLES 8 // Time between consecutive samples +#define MAX30001_DELAY_SAMPLES 8 // Time between consecutive samples #define CES_CMDIF_PKT_START_1 0x0A #define CES_CMDIF_PKT_START_2 0xFA @@ -45,8 +45,8 @@ #define ZERO 0 volatile char DataPacket[DATA_LEN]; -const char DataPacketFooter[2] = { ZERO, CES_CMDIF_PKT_STOP }; -const char DataPacketHeader[5] = { CES_CMDIF_PKT_START_1, CES_CMDIF_PKT_START_2, DATA_LEN, ZERO, CES_CMDIF_TYPE_DATA }; +const char DataPacketFooter[2] = {ZERO, CES_CMDIF_PKT_STOP}; +const char DataPacketHeader[5] = {CES_CMDIF_PKT_START_1, CES_CMDIF_PKT_START_2, DATA_LEN, ZERO, CES_CMDIF_TYPE_DATA}; uint8_t data_len = 0x0C; @@ -55,7 +55,8 @@ MAX30001 max30001(MAX30001_CS_PIN); signed long ecg_data; signed long bioz_data; -void sendData(signed long ecg_sample, signed long bioz_sample, bool _bioZSkipSample) { +void sendData(signed long ecg_sample, signed long bioz_sample, bool _bioZSkipSample) +{ DataPacket[0] = ecg_sample; DataPacket[1] = ecg_sample >> 8; @@ -67,46 +68,55 @@ void sendData(signed long ecg_sample, signed long bioz_sample, bool _bioZSkipSam DataPacket[6] = bioz_sample >> 16; DataPacket[7] = bioz_sample >> 24; - if (_bioZSkipSample == false) { + if (_bioZSkipSample == false) + { DataPacket[8] = 0x00; - } else { + } + else + { DataPacket[8] = 0xFF; } - DataPacket[9] = 0x00; // max30001.heartRate >> 8; + DataPacket[9] = 0x00; // max30001.heartRate >> 8; DataPacket[10] = 0x00; DataPacket[11] = 0x00; // Send packet header (in ProtoCentral OpenView format) - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 5; i++) + { Serial.write(DataPacketHeader[i]); } // Send the data payload - for (int i = 0; i < DATA_LEN; i++) // transmit the data + for (int i = 0; i < DATA_LEN; i++) // transmit the data { Serial.write(DataPacket[i]); } // Send packet footer (in ProtoCentral OpenView format) - for (int i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) + { Serial.write(DataPacketFooter[i]); } } bool BioZSkipSample = false; -void setup() +void setup() { - Serial.begin(57600); // Serial begin + Serial.begin(57600); // Serial begin SPI.begin(); bool ret = max30001.max30001ReadInfo(); - if (ret) { + if (ret) + { Serial.println("MAX 30001 read ID Success"); - } else { - while (!ret) { + } + else + { + while (!ret) + { // stay here untill the issue is fixed. ret = max30001.max30001ReadInfo(); Serial.println("Failed to read ID, please make sure all the pins are connected"); @@ -115,22 +125,25 @@ void setup() } Serial.println("Initialising the chip ..."); - max30001.BeginECGBioZ(); // initialize MAX30001 - // max30001.Begin(); + max30001.BeginECGBioZ(); // initialize MAX30001 + // max30001.Begin(); } -void loop() { +void loop() +{ ecg_data = max30001.getECGSamples(); // max30001.getHRandRR(); - if (BioZSkipSample == false) { + if (BioZSkipSample == false) + { bioz_data = max30001.getBioZSamples(); sendData(ecg_data, bioz_data, BioZSkipSample); BioZSkipSample = true; - } else + } + else { bioz_data = 0x00; sendData(ecg_data, bioz_data, BioZSkipSample); - BioZSkipSample=false; + BioZSkipSample = false; } delay(8); } \ No newline at end of file diff --git a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino index 821ea1f..7cd9151 100644 --- a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino +++ b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino @@ -146,7 +146,7 @@ void setup() max30001.BeginECGBioZ(); // initialize MAX30001 Serial.println("Chip initialised"); - //attachInterrupt(digitalPinToInterrupt(MAX30001_INTB_PIN), intr_cb, FALLING); + // attachInterrupt(digitalPinToInterrupt(MAX30001_INTB_PIN), intr_cb, FALLING); } void loop() diff --git a/src/protocentral_max30001.cpp b/src/protocentral_max30001.cpp index ddd563e..5453ae0 100644 --- a/src/protocentral_max30001.cpp +++ b/src/protocentral_max30001.cpp @@ -177,14 +177,20 @@ void MAX30001::BeginECGBioZ() { _max30001SwReset(); delay(100); - _max30001RegWrite(CNFG_GEN, 0x0C0004); // ECG & BioZ Enabled , FMSTR = 32768 + + _max30001RegWrite(CNFG_GEN, 0xC0004); // ECG & BioZ Enabled , FMSTR = 32768 delay(100); - _max30001RegWrite(CNFG_CAL, 0x720000); // Calibration sources disabled + //_max30001RegWrite(CNFG_CAL, 0x720000); // Calibration sources disabled + + _max30001RegWrite(CNFG_CAL, 0x702000); // Calibration sources disabled delay(100); - _max30001RegWrite(CNFG_ECG, 0x825000); // ECG_RATE: 125 SPS, + //_max30001RegWrite(CNFG_EMUX, 0x0B0000); // Pins internally connection to ECG Channels + _max30001RegWrite(CNFG_EMUX, 0x00); // Pins internally connection to ECG Channels delay(100); - _max30001RegWrite(CNFG_EMUX, 0x0B0000); // Pins internally connection to ECG Channels + + //_max30001RegWrite(CNFG_ECG, 0x825000); // ECG_RATE: 125 SPS, + _max30001RegWrite(CNFG_ECG, 0x835000); delay(100); _max30001RegWrite(CNFG_BIOZ, 0x201433); // BioZ Rate: 64 SPS | Current generator: 32 uA @@ -196,7 +202,7 @@ void MAX30001::BeginECGBioZ() _max30001RegWrite(CNFG_BMUX, 0x000040); // Pins connected internally to BioZ channels delay(100); - max30001SetInterrupts(EN_EINT | 0x01); // Enable ECG Interrupts + //max30001SetInterrupts(EN_EINT | 0x01); // Enable ECG Interrupts //_max30001RegWrite(CNFG_RTOR1,0x3fc600); _max30001Synch(); From 0fe3f65cea6a4e645b3a5abb676500e893067ba3 Mon Sep 17 00:00:00 2001 From: Ashwin Date: Mon, 20 Mar 2023 08:58:08 +0530 Subject: [PATCH 10/18] ECG working. On HPi 5 --- .vscode/arduino.json | 2 +- .../Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.vscode/arduino.json b/.vscode/arduino.json index 9a8cf88..bfc9241 100644 --- a/.vscode/arduino.json +++ b/.vscode/arduino.json @@ -1,5 +1,5 @@ { - "port": "/dev/tty.usbmodem2101", + "port": "/dev/tty.usbmodem101", "configuration": "flash=2097152_0,freq=133,opt=Small,rtti=Disabled,stackprotect=Disabled,exceptions=Disabled,dbgport=Disabled,dbglvl=None,usbstack=picosdk,ipbtstack=ipv4only,uploadmethod=default", "board": "rp2040:rp2040:rpipico", "sketch": "examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino" diff --git a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino index 7cd9151..af0fd65 100644 --- a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino +++ b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino @@ -42,6 +42,8 @@ #define MAX30001_INTB_PIN 20 #define MAX30001_INT2B_PIN 19 +#define AFE44XX_CS_PIN 27 + #define MAX30001_DELAY_SAMPLES 8 // Time between consecutive samples #define CES_CMDIF_PKT_START_1 0x0A @@ -116,6 +118,9 @@ void setup() pinMode(MAX30001_CS_PIN, OUTPUT); digitalWrite(MAX30001_CS_PIN, HIGH); + pinMode(AFE44XX_CS_PIN, OUTPUT); + digitalWrite(AFE44XX_CS_PIN, HIGH); + pinMode(MAX30001_INTB_PIN, INPUT); #ifdef ARDUINO_ARCH_RP2040 From da692b01bc10c3349af7583fa4654887914a1dfa Mon Sep 17 00:00:00 2001 From: Ashwin Date: Mon, 20 Mar 2023 10:21:58 +0530 Subject: [PATCH 11/18] Added BioZ FIFO. Untested --- src/protocentral_max30001.cpp | 47 +++++++++++++++++++++++++++++++++-- src/protocentral_max30001.h | 2 ++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/protocentral_max30001.cpp b/src/protocentral_max30001.cpp index 5453ae0..7e850f1 100644 --- a/src/protocentral_max30001.cpp +++ b/src/protocentral_max30001.cpp @@ -324,6 +324,7 @@ void MAX30001::max30001SetInterrupts(uint32_t interrupts_to_set) } int secg_counter = 0; +int sbioz_counter = 0; void MAX30001::_max30001ReadECGFIFO(int num_bytes) { @@ -382,9 +383,11 @@ void MAX30001::_max30001ReadECGFIFO(int num_bytes) } -void MAX30001::_max30001ReadBIOZFIFO(int num_samples) +void MAX30001::_max30001ReadBIOZFIFO(int num_bytes) { uint8_t spiTxBuff; + unsigned long ubioztemp; + signed long sbioztemp; SPI.beginTransaction(SPISettings(MAX30001_SPI_SPEED, MSBFIRST, SPI_MODE0)); @@ -393,7 +396,7 @@ void MAX30001::_max30001ReadBIOZFIFO(int num_samples) spiTxBuff = (BIOZ_FIFO_BURST << 1) | RREG; SPI.transfer(spiTxBuff); // Send register location - for (int i = 0; i < num_samples * 3; ++i) + for (int i = 0; i < num_bytes; i++) { _readBufferBIOZ[i] = SPI.transfer(0x00); } @@ -401,6 +404,36 @@ void MAX30001::_max30001ReadBIOZFIFO(int num_samples) digitalWrite(_cs_pin, HIGH); SPI.endTransaction(); + + sbioz_counter = 0; + unsigned char bioz_etag; + + for (int i = 0; i < num_bytes; i += 3) + { + // Get etag + bioz_etag = ((((unsigned char)_readBufferBIOZ[i + 2]) & 0x38) >> 3); + //Serial.println(ecg_etag, HEX); + + if (bioz_etag == 0x00) //Valid sample + { + // uecgtemp=(unsigned long)((unsigned long)readBuffer[i]<<16 |(unsigned long)readBuffer[i+1]<<8| (unsigned long)(readBuffer[i+2]&0xC0)); + ubioztemp = (unsigned long)(((unsigned long)_readBufferBIOZ[i] << 16 | (unsigned long)_readBufferBIOZ[i + 1] << 8) | (unsigned long)(_readBufferBIOZ[i+2]&0xC0)); + ubioztemp = (unsigned long)(ubioztemp << 8); + + sbioztemp = (signed long)ubioztemp; + sbioztemp = (signed long)sbioztemp >> 8; + + s32BIOZData[sbioz_counter++] = sbioztemp; + } + else if (bioz_etag == 0x07) //FIFO Overflow + { + //Serial.println("OVF"); + _max30001FIFOReset(); + } + } + + biozSamplesAvailable = sbioz_counter ; + sbioz_counter = 0; } void MAX30001::max30001ServiceAllInterrupts(void) @@ -428,4 +461,14 @@ void MAX30001::max30001ServiceAllInterrupts(void) // Read BIOZ FIFO in Burst mode } + + if(global_status.bit.bint==1) //BIOZ FIFO is full + { + _max30001RegRead24(MNGR_INT, &mngr_int.all); + fifo_num_bytes = (mngr_int.bit.b_fit + 1) * 3; + + _max30001ReadBIOZFIFO(fifo_num_bytes); + + } + } diff --git a/src/protocentral_max30001.h b/src/protocentral_max30001.h index 65eee31..9a3f9c4 100644 --- a/src/protocentral_max30001.h +++ b/src/protocentral_max30001.h @@ -176,7 +176,9 @@ class MAX30001 signed long bioz_data; volatile int ecgSamplesAvailable; + volatile int biozSamplesAvailable; signed long s32ECGData[128]; + signed long s32BIOZData[128]; void BeginECGOnly(); void BeginECGBioZ(); From d64e51b29f5c3a46d9b47ded311df0f66e610d52 Mon Sep 17 00:00:00 2001 From: Ashwin Date: Mon, 20 Mar 2023 14:02:30 +0530 Subject: [PATCH 12/18] BioZ sampling rate tested --- src/protocentral_max30001.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/protocentral_max30001.cpp b/src/protocentral_max30001.cpp index 7e850f1..2eff80e 100644 --- a/src/protocentral_max30001.cpp +++ b/src/protocentral_max30001.cpp @@ -193,14 +193,17 @@ void MAX30001::BeginECGBioZ() _max30001RegWrite(CNFG_ECG, 0x835000); delay(100); + _max30001RegWrite(CNFG_BMUX, 0x000040); // Pins connected internally to BioZ channels + delay(100); + _max30001RegWrite(CNFG_BIOZ, 0x201433); // BioZ Rate: 64 SPS | Current generator: 32 uA delay(100); // Set MAX30001G specific BioZ LC _max30001RegWrite(CNFG_BIOZ_LC, 0x800000); // Turn OFF low current mode - _max30001RegWrite(CNFG_BMUX, 0x000040); // Pins connected internally to BioZ channels - delay(100); + _max30001RegWrite(MNGR_INT, 0x7F0000); // EFIT=16, BFIT=8 + //max30001SetInterrupts(EN_EINT | 0x01); // Enable ECG Interrupts @@ -450,16 +453,8 @@ void MAX30001::max30001ServiceAllInterrupts(void) // Read the number of bytes in FIFO (from MNGR_INT register) _max30001RegRead24(MNGR_INT, &mngr_int.all); fifo_num_bytes = (mngr_int.bit.e_fit + 1) * 3; - // Serial.println("MNGR"); - // Serial.println(fifo_num_bytes); - // Read ECG FIFO in Burst mode _max30001ReadECGFIFO(fifo_num_bytes); - //_max30001ReadBIOZFIFO(fifo_num_bytes/2, _readBufferBIOZ); - // getECGSamples(); - // ecgDataAvailable=fifo_num_bytes; - - // Read BIOZ FIFO in Burst mode } if(global_status.bit.bint==1) //BIOZ FIFO is full @@ -467,8 +462,8 @@ void MAX30001::max30001ServiceAllInterrupts(void) _max30001RegRead24(MNGR_INT, &mngr_int.all); fifo_num_bytes = (mngr_int.bit.b_fit + 1) * 3; + // Read BIOZ FIFO in Burst mode _max30001ReadBIOZFIFO(fifo_num_bytes); - } - + } } From 861945f9cced69ffaf5858927eec6b8fec720c0c Mon Sep 17 00:00:00 2001 From: Ashwin Date: Mon, 20 Mar 2023 19:16:18 +0530 Subject: [PATCH 13/18] Update protocentral_max30001.cpp --- src/protocentral_max30001.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/protocentral_max30001.cpp b/src/protocentral_max30001.cpp index 2eff80e..6568e2d 100644 --- a/src/protocentral_max30001.cpp +++ b/src/protocentral_max30001.cpp @@ -202,7 +202,7 @@ void MAX30001::BeginECGBioZ() // Set MAX30001G specific BioZ LC _max30001RegWrite(CNFG_BIOZ_LC, 0x800000); // Turn OFF low current mode - _max30001RegWrite(MNGR_INT, 0x7F0000); // EFIT=16, BFIT=8 + _max30001RegWrite(MNGR_INT, 0x7B0000); // EFIT=16, BFIT=8 //max30001SetInterrupts(EN_EINT | 0x01); // Enable ECG Interrupts From 01f8e3613fbccfdcc797abb063200c3d61631541 Mon Sep 17 00:00:00 2001 From: Ashwin K Whitchurch Date: Tue, 21 Mar 2023 19:59:31 +0530 Subject: [PATCH 14/18] Added register change functions --- .vscode/arduino.json | 5 +- .vscode/c_cpp_properties.json | 546 ++++++++++-------- .../Example2-Interrupt-Driven.ino | 2 +- src/protocentral_max30001.cpp | 40 +- src/protocentral_max30001.h | 89 ++- 5 files changed, 419 insertions(+), 263 deletions(-) diff --git a/.vscode/arduino.json b/.vscode/arduino.json index bfc9241..18b1538 100644 --- a/.vscode/arduino.json +++ b/.vscode/arduino.json @@ -1,6 +1,5 @@ { - "port": "/dev/tty.usbmodem101", - "configuration": "flash=2097152_0,freq=133,opt=Small,rtti=Disabled,stackprotect=Disabled,exceptions=Disabled,dbgport=Disabled,dbglvl=None,usbstack=picosdk,ipbtstack=ipv4only,uploadmethod=default", - "board": "rp2040:rp2040:rpipico", + "port": "/dev/tty.usbmodem1401", + "board": "arduino:avr:uno", "sketch": "examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino" } \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 161dab3..1f34f71 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -3,118 +3,100 @@ "configurations": [ { "name": "Arduino", - "compilerPath": "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/bin/arm-none-eabi-g++", + "compilerPath": "/Users/akw/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++", "compilerArgs": [ - "-I", - "-Werror=return-type", - "-march=armv6-m", - "-mcpu=cortex-m0plus", - "-mthumb", + "-w", + "-std=gnu++11", + "-fpermissive", + "-fno-exceptions", "-ffunction-sections", "-fdata-sections", - "-fno-exceptions" + "-fno-threadsafe-statics", + "-Wno-error=narrowing" ], "intelliSenseMode": "gcc-x64", "includePath": [ - "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.1.0/include", - "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.1.0/cores/rp2040", - "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.1.0/variants/rpipico", - "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.1.0/libraries/SPI/src", + "/Users/akw/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino", + "/Users/akw/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/variants/standard", + "/Users/akw/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/libraries/SPI/src", "/Users/akw/Documents/Arduino/libraries/protocentral_max30001_arduino_library/src", - "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/arm-none-eabi/include/c++/10.3.0", - "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/arm-none-eabi/include/c++/10.3.0/arm-none-eabi/thumb", - "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/arm-none-eabi/include/c++/10.3.0/backward", - "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/lib/gcc/arm-none-eabi/10.3.0/include", - "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/lib/gcc/arm-none-eabi/10.3.0/include-fixed", - "/Users/akw/Library/Arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/arm-none-eabi/include" + "/Users/akw/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/lib/gcc/avr/7.3.0/include", + "/Users/akw/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/lib/gcc/avr/7.3.0/include-fixed", + "/Users/akw/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/avr/include" ], "forcedInclude": [ - "/Users/akw/Library/Arduino15/packages/rp2040/hardware/rp2040/3.1.0/cores/rp2040/Arduino.h" + "/Users/akw/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/Arduino.h" ], "cStandard": "c11", - "cppStandard": "c++17", + "cppStandard": "c++11", "defines": [ - "CFG_TUSB_MCU=OPT_MCU_RP2040", - "USBD_PID=0x000a", - "USBD_VID=0x2e8a", - "USBD_MAX_POWER_MA=250", - "USB_MANUFACTURER=\"Raspberry Pi\"", - "USB_PRODUCT=\"Pico\"", - "PICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1", - "CYW43_LWIP=1", - "LWIP_IPV6=0", - "LWIP_IPV4=1", - "LWIP_IGMP=1", - "LWIP_CHECKSUM_CTRL_PER_NETIF=1", - "ARDUINO_VARIANT=\"rpipico\"", - "TARGET_RP2040", - "ARM_MATH_CM0_FAMILY", - "ARM_MATH_CM0_PLUS", - "F_CPU=133000000L", + "F_CPU=16000000L", "ARDUINO=10607", - "ARDUINO_RASPBERRY_PI_PICO", - "BOARD_NAME=\"RASPBERRY_PI_PICO\"", - "ARDUINO_ARCH_RP2040", - "WIFICC=CYW43_COUNTRY_WORLDWIDE", - "__DBL_MIN_EXP__=(-1021)", + "ARDUINO_AVR_UNO", + "ARDUINO_ARCH_AVR", + "__DBL_MIN_EXP__=(-125)", "__HQ_FBIT__=15", - "__cpp_attributes=200809L", - "__UINT_LEAST16_MAX__=0xffff", - "__ARM_SIZEOF_WCHAR_T=4", + "__cpp_attributes=200809", + "__UINT_LEAST16_MAX__=0xffffU", "__ATOMIC_ACQUIRE=2", "__SFRACT_IBIT__=0", - "__FLT_MIN__=1.1754943508222875e-38F", + "__FLT_MIN__=1.17549435e-38F", "__GCC_IEC_559_COMPLEX=0", - "__cpp_aggregate_nsdmi=201304L", + "__BUILTIN_AVR_SLEEP=1", + "__BUILTIN_AVR_COUNTLSULLK=1", + "__cpp_aggregate_nsdmi=201304", + "__BUILTIN_AVR_COUNTLSULLR=1", "__UFRACT_MAX__=0XFFFFP-16UR", "__UINT_LEAST8_TYPE__=unsigned char", "__DQ_FBIT__=63", "__INTMAX_C(c)=c ## LL", "__ULFRACT_FBIT__=32", + "__SACCUM_EPSILON__=0x1P-7HK", "__CHAR_BIT__=8", "__USQ_IBIT__=0", "__UINT8_MAX__=0xff", "__ACCUM_FBIT__=15", - "__WINT_MAX__=0xffffffffU", + "__WINT_MAX__=0x7fff", "__FLT32_MIN_EXP__=(-125)", - "__cpp_static_assert=200410L", + "__cpp_static_assert=200410", "__USFRACT_FBIT__=8", "__ORDER_LITTLE_ENDIAN__=1234", - "__SIZE_MAX__=0xffffffffU", - "__WCHAR_MAX__=0xffffffffU", + "__SIZE_MAX__=0xffffU", + "__WCHAR_MAX__=0x7fff", "__LACCUM_IBIT__=32", - "__DBL_DENORM_MIN__=double(4.9406564584124654e-324L)", + "__DBL_DENORM_MIN__=double(1.40129846e-45L)", "__GCC_ATOMIC_CHAR_LOCK_FREE=1", "__GCC_IEC_559=0", - "__FLT32X_DECIMAL_DIG__=17", "__FLT_EVAL_METHOD__=0", - "__TQ_IBIT__=0", - "__cpp_binary_literals=201304L", - "__LLACCUM_MAX__=0X7FFFFFFFFFFFFFFFP-31LLK", - "__FLT64_DECIMAL_DIG__=17", + "__BUILTIN_AVR_LLKBITS=1", + "__cpp_binary_literals=201304", + "__LLACCUM_MAX__=0X7FFFFFFFFFFFFFFFP-47LLK", "__GCC_ATOMIC_CHAR32_T_LOCK_FREE=1", - "__cpp_variadic_templates=200704L", + "__BUILTIN_AVR_HKBITS=1", + "__BUILTIN_AVR_BITSLLK=1", + "__FRACT_FBIT__=15", + "__BUILTIN_AVR_BITSLLR=1", + "__cpp_variadic_templates=200704", "__UINT_FAST64_MAX__=0xffffffffffffffffULL", - "__SIG_ATOMIC_TYPE__=int", - "__DBL_MIN_10_EXP__=(-307)", + "__SIG_ATOMIC_TYPE__=char", + "__BUILTIN_AVR_UHKBITS=1", + "__UACCUM_FBIT__=16", + "__DBL_MIN_10_EXP__=(-37)", "__FINITE_MATH_ONLY__=0", - "__ARMEL__=1", - "__cpp_variable_templates=201304L", - "__FLT32X_MAX_EXP__=1024", + "__cpp_variable_templates=201304", "__LFRACT_IBIT__=0", "__GNUC_PATCHLEVEL__=0", "__FLT32_HAS_DENORM__=1", "__LFRACT_MAX__=0X7FFFFFFFP-31LR", - "__USA_FBIT__=16", - "__UINT_FAST8_MAX__=0xffffffffU", - "__cpp_rvalue_reference=200610L", - "__FLT32_MAX_10_EXP__=38", + "__UINT_FAST8_MAX__=0xff", + "__has_include(STR)=__has_include__(STR)", + "__DEC64_MAX_EXP__=385", "__INT8_C(c)=c", "__INT_LEAST8_WIDTH__=8", "__UINT_LEAST64_MAX__=0xffffffffffffffffULL", "__SA_FBIT__=15", "__SHRT_MAX__=0x7fff", - "__LDBL_MAX__=1.7976931348623157e+308L", + "__LDBL_MAX__=3.40282347e+38L", "__FRACT_MAX__=0X7FFFP-15R", "__UFRACT_FBIT__=16", "__UFRACT_MIN__=0.0UR", @@ -122,372 +104,434 @@ "__GCC_ATOMIC_BOOL_LOCK_FREE=1", "__UINTMAX_TYPE__=long long unsigned int", "__LLFRACT_EPSILON__=0x1P-63LLR", + "__BUILTIN_AVR_DELAY_CYCLES=1", + "__DEC32_EPSILON__=1E-6DF", "__FLT_EVAL_METHOD_TS_18661_3__=0", - "__CHAR_UNSIGNED__=1", "__UINT32_MAX__=0xffffffffUL", "__GXX_EXPERIMENTAL_CXX0X__=1", "__ULFRACT_MAX__=0XFFFFFFFFP-32ULR", - "__TA_IBIT__=64", - "__LDBL_MAX_EXP__=1024", - "__WINT_MIN__=0U", + "__TA_IBIT__=16", + "__LDBL_MAX_EXP__=128", + "__WINT_MIN__=(-__WINT_MAX__ - 1)", "__INT_LEAST16_WIDTH__=16", "__ULLFRACT_MIN__=0.0ULLR", "__SCHAR_MAX__=0x7f", - "__WCHAR_MIN__=0U", + "__WCHAR_MIN__=(-__WCHAR_MAX__ - 1)", "__INT64_C(c)=c ## LL", + "__DBL_DIG__=6", "__GCC_ATOMIC_POINTER_LOCK_FREE=1", - "__LLACCUM_MIN__=(-0X1P31LLK-0X1P31LLK)", - "__SIZEOF_INT__=4", - "__FLT32X_MANT_DIG__=53", + "__AVR_HAVE_SPH__=1", + "__LLACCUM_MIN__=(-0X1P15LLK-0X1P15LLK)", + "__BUILTIN_AVR_KBITS=1", + "__BUILTIN_AVR_ABSK=1", + "__BUILTIN_AVR_ABSR=1", + "__SIZEOF_INT__=2", + "__SIZEOF_POINTER__=2", "__GCC_ATOMIC_CHAR16_T_LOCK_FREE=1", "__USACCUM_IBIT__=8", "__USER_LABEL_PREFIX__", "__STDC_HOSTED__=1", + "__LDBL_HAS_INFINITY__=1", "__LFRACT_MIN__=(-0.5LR-0.5LR)", "__HA_IBIT__=8", - "__cpp_decltype_auto=201304L", - "__DBL_DIG__=15", "__FLT32_DIG__=6", - "__FLT_EPSILON__=1.1920928955078125e-7F", - "__APCS_32__=1", + "__TQ_IBIT__=0", + "__FLT_EPSILON__=1.19209290e-7F", "__GXX_WEAK__=1", "__SHRT_WIDTH__=16", "__USFRACT_IBIT__=0", - "__LDBL_MIN__=2.2250738585072014e-308L", + "__LDBL_MIN__=1.17549435e-38L", "__FRACT_MIN__=(-0.5R-0.5R)", - "__cpp_threadsafe_static_init=200806L", + "__AVR_SFR_OFFSET__=0x20", + "__DEC32_MAX__=9.999999E96DF", + "__cpp_threadsafe_static_init=200806", "__DA_IBIT__=32", - "__ARM_SIZEOF_MINIMAL_ENUM=1", - "__FLT32X_HAS_INFINITY__=1", "__INT32_MAX__=0x7fffffffL", "__UQQ_FBIT__=8", - "__INT_WIDTH__=32", + "__INT_WIDTH__=16", "__SIZEOF_LONG__=4", "__UACCUM_MAX__=0XFFFFFFFFP-16UK", - "__UINT16_C(c)=c", - "__DECIMAL_DIG__=17", + "__UINT16_C(c)=c ## U", + "__PTRDIFF_WIDTH__=16", + "__DECIMAL_DIG__=9", "__LFRACT_EPSILON__=0x1P-31LR", - "__FLT64_EPSILON__=2.2204460492503131e-16F64", + "__AVR_2_BYTE_PC__=1", "__ULFRACT_MIN__=0.0ULR", - "__INT16_MAX__=0x7fff", - "__FLT64_MIN_EXP__=(-1021)", + "__INTMAX_WIDTH__=64", + "__has_include_next(STR)=__has_include_next__(STR)", + "__BUILTIN_AVR_ULLRBITS=1", "__LDBL_HAS_QUIET_NAN__=1", "__ULACCUM_IBIT__=32", - "__FLT64_MANT_DIG__=53", "__UACCUM_EPSILON__=0x1P-16UK", - "__GNUC__=10", - "__ULLACCUM_MAX__=0XFFFFFFFFFFFFFFFFP-32ULLK", - "__GXX_RTTI=1", + "__BUILTIN_AVR_SEI=1", + "__GNUC__=7", + "__ULLACCUM_MAX__=0XFFFFFFFFFFFFFFFFP-48ULLK", + "__cpp_delegating_constructors=200604", "__HQ_IBIT__=0", + "__BUILTIN_AVR_SWAP=1", "__FLT_HAS_DENORM__=1", - "__SIZEOF_LONG_DOUBLE__=8", - "__SA_IBIT__=16", - "__BIGGEST_ALIGNMENT__=8", + "__SIZEOF_LONG_DOUBLE__=4", + "__BIGGEST_ALIGNMENT__=1", "__STDC_UTF_16__=1", - "__FLT64_MAX_10_EXP__=308", + "__UINT24_MAX__=16777215UL", + "__BUILTIN_AVR_NOP=1", "__GNUC_STDC_INLINE__=1", "__DQ_IBIT__=0", - "__cpp_delegating_constructors=200604L", "__FLT32_HAS_INFINITY__=1", - "__DBL_MAX__=double(1.7976931348623157e+308L)", + "__DBL_MAX__=double(3.40282347e+38L)", "__ULFRACT_IBIT__=0", - "__cpp_raw_strings=200710L", - "__INT_FAST32_MAX__=0x7fffffff", + "__cpp_raw_strings=200710", + "__INT_FAST32_MAX__=0x7fffffffL", "__DBL_HAS_INFINITY__=1", - "__HAVE_SPECULATION_SAFE_VALUE=1", + "__INT64_MAX__=0x7fffffffffffffffLL", "__ACCUM_IBIT__=16", - "__THUMB_INTERWORK__=1", - "__INTPTR_WIDTH__=32", - "__UINT_LEAST32_MAX__=0xffffffffUL", - "__ULLACCUM_IBIT__=32", + "__DEC32_MIN_EXP__=(-94)", + "__BUILTIN_AVR_UKBITS=1", + "__INTPTR_WIDTH__=16", + "__BUILTIN_AVR_FMULSU=1", "__LACCUM_MAX__=0X7FFFFFFFFFFFFFFFP-31LK", - "__FLT32X_HAS_DENORM__=1", "__INT_FAST16_TYPE__=int", "__LDBL_HAS_DENORM__=1", + "__BUILTIN_AVR_BITSK=1", + "__BUILTIN_AVR_BITSR=1", "__cplusplus=201402L", - "__cpp_ref_qualifiers=200710L", + "__cpp_ref_qualifiers=200710", + "__DEC128_MAX__=9.999999999999999999999999999999999E6144DL", "__INT_LEAST32_MAX__=0x7fffffffL", - "__ARM_PCS=1", + "__USING_SJLJ_EXCEPTIONS__=1", + "__DEC32_MIN__=1E-95DF", "__ACCUM_MAX__=0X7FFFFFFFP-15K", "__DEPRECATED=1", - "__ARM_ARCH_6M__=1", - "__cpp_rvalue_references=200610L", - "__DBL_MAX_EXP__=1024", + "__cpp_rvalue_references=200610", + "__DBL_MAX_EXP__=128", "__USACCUM_EPSILON__=0x1P-8UHK", - "__WCHAR_WIDTH__=32", - "__FLT32_MAX__=3.4028234663852886e+38F32", - "__GCC_ATOMIC_LONG_LOCK_FREE=1", + "__WCHAR_WIDTH__=16", + "__FLT32_MAX__=3.40282347e+38F32", + "__DEC128_EPSILON__=1E-33DL", "__SFRACT_MAX__=0X7FP-7HR", "__FRACT_IBIT__=0", - "__PTRDIFF_MAX__=0x7fffffff", + "__PTRDIFF_MAX__=0x7fff", "__UACCUM_MIN__=0.0UK", "__UACCUM_IBIT__=16", + "__BUILTIN_AVR_NOPS=1", + "__BUILTIN_AVR_WDR=1", "__FLT32_HAS_QUIET_NAN__=1", - "__GNUG__=10", + "__GNUG__=7", "__LONG_LONG_MAX__=0x7fffffffffffffffLL", + "__SIZEOF_SIZE_T__=2", "__ULACCUM_MAX__=0XFFFFFFFFFFFFFFFFP-32ULK", - "__cpp_nsdmi=200809L", - "__SIZEOF_WINT_T__=4", + "__cpp_rvalue_reference=200610", + "__cpp_nsdmi=200809", + "__SIZEOF_WINT_T__=2", "__LONG_LONG_WIDTH__=64", - "__cpp_initializer_lists=200806L", + "__cpp_initializer_lists=200806", "__FLT32_MAX_EXP__=128", + "__SA_IBIT__=16", "__ULLACCUM_MIN__=0.0ULLK", - "__cpp_hex_float=201603L", - "__GXX_ABI_VERSION=1014", - "__UTA_FBIT__=64", + "__BUILTIN_AVR_ROUNDUHK=1", + "__BUILTIN_AVR_ROUNDUHR=1", + "__cpp_hex_float=201603", + "__GXX_ABI_VERSION=1011", + "__INT24_MAX__=8388607L", + "__UTA_FBIT__=48", "__FLT_MIN_EXP__=(-125)", + "__USFRACT_MAX__=0XFFP-8UHR", "__UFRACT_IBIT__=0", - "__cpp_lambdas=200907L", + "__BUILTIN_AVR_ROUNDFX=1", + "__BUILTIN_AVR_ROUNDULK=1", + "__BUILTIN_AVR_ROUNDULR=1", + "__cpp_lambdas=200907", + "__BUILTIN_AVR_COUNTLSLLK=1", + "__BUILTIN_AVR_COUNTLSLLR=1", + "__BUILTIN_AVR_ROUNDHK=1", "__INT_FAST64_TYPE__=long long int", - "__FLT64_DENORM_MIN__=4.9406564584124654e-324F64", - "__DBL_MIN__=double(2.2250738585072014e-308L)", - "__SIZEOF_POINTER__=4", - "__DBL_HAS_QUIET_NAN__=1", - "__FLT32X_EPSILON__=2.2204460492503131e-16F32x", + "__BUILTIN_AVR_ROUNDHR=1", + "__DBL_MIN__=double(1.17549435e-38L)", + "__BUILTIN_AVR_COUNTLSK=1", + "__BUILTIN_AVR_ROUNDLK=1", + "__BUILTIN_AVR_COUNTLSR=1", + "__BUILTIN_AVR_ROUNDLR=1", "__LACCUM_MIN__=(-0X1P31LK-0X1P31LK)", - "__FRACT_FBIT__=15", - "__ULLACCUM_FBIT__=32", - "__GXX_TYPEINFO_EQUALITY_INLINE=0", - "__FLT64_MIN_10_EXP__=(-307)", + "__ULLACCUM_FBIT__=48", + "__BUILTIN_AVR_LKBITS=1", "__ULLFRACT_EPSILON__=0x1P-64ULLR", - "__USES_INITFINI__=1", + "__DEC128_MIN__=1E-6143DL", "__REGISTER_PREFIX__", - "__UINT16_MAX__=0xffff", + "__UINT16_MAX__=0xffffU", + "__DBL_HAS_DENORM__=1", + "__BUILTIN_AVR_ULKBITS=1", "__ACCUM_MIN__=(-0X1P15K-0X1P15K)", + "__AVR_ARCH__=2", "__SQ_IBIT__=0", - "__FLT32_MIN__=1.1754943508222875e-38F32", + "__FLT32_MIN__=1.17549435e-38F32", "__UINT8_TYPE__=unsigned char", + "__BUILTIN_AVR_ROUNDUK=1", + "__BUILTIN_AVR_ROUNDUR=1", "__UHA_FBIT__=8", - "__FLT_DIG__=6", "__NO_INLINE__=1", "__SFRACT_MIN__=(-0.5HR-0.5HR)", "__UTQ_FBIT__=128", - "__DEC_EVAL_METHOD__=2", "__FLT_MANT_DIG__=24", - "__LDBL_DECIMAL_DIG__=17", - "__VERSION__=\"10.3.0\"", + "__LDBL_DECIMAL_DIG__=9", + "__VERSION__=\"7.3.0\"", "__UINT64_C(c)=c ## ULL", "__ULLFRACT_FBIT__=64", - "__cpp_unicode_characters=200704L", - "__SOFTFP__=1", + "__cpp_unicode_characters=200704", "__FRACT_EPSILON__=0x1P-15R", "__ULACCUM_MIN__=0.0ULK", "__UDA_FBIT__=32", - "__LLACCUM_EPSILON__=0x1P-31LLK", + "__cpp_decltype_auto=201304", + "__LLACCUM_EPSILON__=0x1P-47LLK", "__GCC_ATOMIC_INT_LOCK_FREE=1", + "__FLT32_MANT_DIG__=24", + "__BUILTIN_AVR_BITSUHK=1", + "__BUILTIN_AVR_BITSUHR=1", "__FLOAT_WORD_ORDER__=__ORDER_LITTLE_ENDIAN__", "__USFRACT_MIN__=0.0UHR", - "__FLT32_MANT_DIG__=24", + "__BUILTIN_AVR_BITSULK=1", + "__ULLACCUM_IBIT__=16", + "__BUILTIN_AVR_BITSULR=1", "__UQQ_IBIT__=0", - "__USFRACT_MAX__=0XFFP-8UHR", + "__BUILTIN_AVR_LLRBITS=1", "__SCHAR_WIDTH__=8", + "__BUILTIN_AVR_BITSULLK=1", + "__BUILTIN_AVR_BITSULLR=1", "__INT32_C(c)=c ## L", + "__DEC64_EPSILON__=1E-15DD", "__ORDER_PDP_ENDIAN__=3412", + "__DEC128_MIN_EXP__=(-6142)", "__UHQ_FBIT__=16", - "__LLACCUM_FBIT__=31", - "__INT_FAST32_TYPE__=int", - "__UINT_LEAST16_TYPE__=short unsigned int", - "__DBL_HAS_DENORM__=1", - "__cpp_rtti=199711L", + "__LLACCUM_FBIT__=47", + "__FLT32_MAX_10_EXP__=38", + "__BUILTIN_AVR_ROUNDULLK=1", + "__BUILTIN_AVR_ROUNDULLR=1", + "__INT_FAST32_TYPE__=long int", + "__BUILTIN_AVR_HRBITS=1", + "__UINT_LEAST16_TYPE__=unsigned int", + "__BUILTIN_AVR_UHRBITS=1", + "__INT16_MAX__=0x7fff", "__SIZE_TYPE__=unsigned int", "__UINT64_MAX__=0xffffffffffffffffULL", "__UDQ_FBIT__=64", "__INT8_TYPE__=signed char", - "__thumb__=1", - "__cpp_digit_separators=201309L", + "__cpp_digit_separators=201309", "__ELF__=1", - "__SACCUM_EPSILON__=0x1P-7HK", "__ULFRACT_EPSILON__=0x1P-32ULR", "__LLFRACT_FBIT__=63", "__FLT_RADIX__=2", - "__INT_LEAST16_TYPE__=short int", - "__ARM_ARCH_PROFILE=77", - "__LDBL_EPSILON__=2.2204460492503131e-16L", + "__INT_LEAST16_TYPE__=int", + "__BUILTIN_AVR_ABSFX=1", + "__LDBL_EPSILON__=1.19209290e-7L", "__UINTMAX_C(c)=c ## ULL", + "__INT24_MIN__=(-__INT24_MAX__-1)", "__SACCUM_MAX__=0X7FFFP-7HK", - "__FLT32X_MIN__=2.2250738585072014e-308F32x", - "__SIG_ATOMIC_MAX__=0x7fffffff", - "__UACCUM_FBIT__=16", + "__BUILTIN_AVR_ABSHR=1", + "__SIG_ATOMIC_MAX__=0x7f", "__GCC_ATOMIC_WCHAR_T_LOCK_FREE=1", - "__VFP_FP__=1", - "__SIZEOF_PTRDIFF_T__=4", + "__cpp_sized_deallocation=201309", + "__SIZEOF_PTRDIFF_T__=2", + "__AVR=1", + "__BUILTIN_AVR_ABSLK=1", + "__BUILTIN_AVR_ABSLR=1", "__LACCUM_EPSILON__=0x1P-31LK", - "__LDBL_DIG__=15", - "__FLT32X_MIN_EXP__=(-1021)", - "__INT_FAST16_MAX__=0x7fffffff", - "__FLT64_DIG__=15", - "__UINT_FAST32_MAX__=0xffffffffU", + "__DEC32_SUBNORMAL_MIN__=0.000001E-95DF", + "__INT_FAST16_MAX__=0x7fff", + "__UINT_FAST32_MAX__=0xffffffffUL", "__UINT_LEAST64_TYPE__=long long unsigned int", + "__USACCUM_MAX__=0XFFFFP-8UHK", "__SFRACT_EPSILON__=0x1P-7HR", "__FLT_HAS_QUIET_NAN__=1", "__FLT_MAX_10_EXP__=38", "__LONG_MAX__=0x7fffffffL", - "__SIZEOF_SIZE_T__=4", + "__DEC128_SUBNORMAL_MIN__=0.000000000000000000000000000000001E-6143DL", "__FLT_HAS_INFINITY__=1", - "__cpp_unicode_literals=200710L", + "__cpp_unicode_literals=200710", + "__USA_FBIT__=16", "__UINT_FAST16_TYPE__=unsigned int", + "__DEC64_MAX__=9.999999999999999E384DD", "__INT_FAST32_WIDTH__=32", - "__CHAR16_TYPE__=short unsigned int", + "__BUILTIN_AVR_RBITS=1", + "__CHAR16_TYPE__=unsigned int", "__PRAGMA_REDEFINE_EXTNAME=1", - "__SIZE_WIDTH__=32", + "__SIZE_WIDTH__=16", "__INT_LEAST16_MAX__=0x7fff", - "__INT64_MAX__=0x7fffffffffffffffLL", + "__DEC64_MANT_DIG__=16", + "__UINT_LEAST32_MAX__=0xffffffffUL", "__SACCUM_FBIT__=7", - "__FLT32_DENORM_MIN__=1.4012984643248171e-45F32", - "__SIG_ATOMIC_WIDTH__=32", + "__FLT32_DENORM_MIN__=1.40129846e-45F32", + "__GCC_ATOMIC_LONG_LOCK_FREE=1", + "__SIG_ATOMIC_WIDTH__=8", "__INT_LEAST64_TYPE__=long long int", - "__INT16_TYPE__=short int", + "__INT16_TYPE__=int", "__INT_LEAST8_TYPE__=signed char", "__SQ_FBIT__=31", - "__ARM_ARCH_ISA_THUMB=1", - "__INT_FAST8_MAX__=0x7fffffff", - "__ARM_ARCH=6", - "__INTPTR_MAX__=0x7fffffff", - "__cpp_sized_deallocation=201309L", + "__DEC32_MAX_EXP__=97", + "__INT_FAST8_MAX__=0x7f", + "__INTPTR_MAX__=0x7fff", "__QQ_FBIT__=7", - "__UTA_IBIT__=64", - "__FLT64_HAS_QUIET_NAN__=1", + "__cpp_range_based_for=200907", + "__UTA_IBIT__=16", + "__AVR_ERRATA_SKIP__=1", "__FLT32_MIN_10_EXP__=(-37)", - "__EXCEPTIONS=1", - "__PTRDIFF_WIDTH__=32", - "__LDBL_MANT_DIG__=53", + "__LDBL_MANT_DIG__=24", "__SFRACT_FBIT__=7", - "__cpp_range_based_for=200907L", "__SACCUM_MIN__=(-0X1P7HK-0X1P7HK)", - "__FLT64_HAS_INFINITY__=1", + "__DBL_HAS_QUIET_NAN__=1", "__SIG_ATOMIC_MIN__=(-__SIG_ATOMIC_MAX__ - 1)", - "__cpp_return_type_deduction=201304L", + "AVR=1", + "__BUILTIN_AVR_FMULS=1", + "__cpp_return_type_deduction=201304", "__INTPTR_TYPE__=int", - "__UINT16_TYPE__=short unsigned int", - "__WCHAR_TYPE__=unsigned int", + "__UINT16_TYPE__=unsigned int", + "__WCHAR_TYPE__=int", "__SIZEOF_FLOAT__=4", - "__THUMBEL__=1", - "__TQ_FBIT__=127", + "__AVR__=1", + "__BUILTIN_AVR_INSERT_BITS=1", "__USQ_FBIT__=32", - "__UINTPTR_MAX__=0xffffffffU", + "__UINTPTR_MAX__=0xffffU", "__INT_FAST64_WIDTH__=64", - "__cpp_decltype=200707L", + "__DEC64_MIN_EXP__=(-382)", + "__cpp_decltype=200707", "__FLT32_DECIMAL_DIG__=9", "__INT_FAST64_MAX__=0x7fffffffffffffffLL", "__GCC_ATOMIC_TEST_AND_SET_TRUEVAL=1", - "__FLT_NORM_MAX__=3.4028234663852886e+38F", + "__FLT_DIG__=6", "__UINT_FAST64_TYPE__=long long unsigned int", - "__INT_MAX__=0x7fffffff", + "__BUILTIN_AVR_BITSHK=1", + "__BUILTIN_AVR_BITSHR=1", + "__INT_MAX__=0x7fff", "__LACCUM_FBIT__=31", "__USACCUM_MIN__=0.0UHK", "__UHA_IBIT__=8", "__INT64_TYPE__=long long int", + "__BUILTIN_AVR_BITSLK=1", + "__BUILTIN_AVR_BITSLR=1", "__FLT_MAX_EXP__=128", "__UTQ_IBIT__=0", - "__DBL_MANT_DIG__=53", - "__cpp_inheriting_constructors=201511L", + "__DBL_MANT_DIG__=24", + "__cpp_inheriting_constructors=201511", + "__BUILTIN_AVR_ULLKBITS=1", "__INT_LEAST64_MAX__=0x7fffffffffffffffLL", - "__WINT_TYPE__=unsigned int", + "__DEC64_MIN__=1E-383DD", + "__WINT_TYPE__=int", "__UINT_LEAST32_TYPE__=long unsigned int", "__SIZEOF_SHORT__=2", "__ULLFRACT_IBIT__=0", - "__FLT32_NORM_MAX__=3.4028234663852886e+38F32", - "__LDBL_MIN_EXP__=(-1021)", - "__arm__=1", - "__FLT64_MAX__=1.7976931348623157e+308F64", + "__LDBL_MIN_EXP__=(-125)", "__UDA_IBIT__=32", - "__WINT_WIDTH__=32", + "__WINT_WIDTH__=16", "__INT_LEAST8_MAX__=0x7f", - "__INT_LEAST64_WIDTH__=64", - "__FLT32X_MAX_10_EXP__=308", "__LFRACT_FBIT__=31", - "__WCHAR_UNSIGNED__=1", - "__LDBL_MAX_10_EXP__=308", + "__LDBL_MAX_10_EXP__=38", "__ATOMIC_RELAXED=0", - "__DBL_EPSILON__=double(2.2204460492503131e-16L)", + "__DBL_EPSILON__=double(1.19209290e-7L)", + "__BUILTIN_AVR_BITSUK=1", + "__BUILTIN_AVR_BITSUR=1", "__UINT8_C(c)=c", - "__FLT64_MAX_EXP__=1024", "__INT_LEAST32_TYPE__=long int", - "__SIZEOF_WCHAR_T__=4", + "__BUILTIN_AVR_URBITS=1", + "__SIZEOF_WCHAR_T__=2", "__LLFRACT_MAX__=0X7FFFFFFFFFFFFFFFP-63LLR", - "__FLT64_NORM_MAX__=1.7976931348623157e+308F64", - "__INTMAX_MAX__=0x7fffffffffffffffLL", - "__INT_FAST8_TYPE__=int", - "__ULLACCUM_EPSILON__=0x1P-32ULLK", - "__USACCUM_MAX__=0XFFFFP-8UHK", - "__LDBL_HAS_INFINITY__=1", + "__TQ_FBIT__=127", + "__INT_FAST8_TYPE__=signed char", + "__ULLACCUM_EPSILON__=0x1P-48ULLK", + "__BUILTIN_AVR_ROUNDK=1", + "__BUILTIN_AVR_ROUNDR=1", "__UHQ_IBIT__=0", - "__LLACCUM_IBIT__=32", - "__FLT64_HAS_DENORM__=1", - "__FLT32_EPSILON__=1.1920928955078125e-7F32", - "__DBL_DECIMAL_DIG__=17", + "__LLACCUM_IBIT__=16", + "__FLT32_EPSILON__=1.19209290e-7F32", + "__DBL_DECIMAL_DIG__=9", "__STDC_UTF_32__=1", - "__INT_FAST8_WIDTH__=32", - "__FLT32X_MAX__=1.7976931348623157e+308F32x", - "__TA_FBIT__=63", - "__DBL_NORM_MAX__=double(1.7976931348623157e+308L)", - "__BYTE_ORDER__=__ORDER_LITTLE_ENDIAN__", + "__INT_FAST8_WIDTH__=8", + "__DEC_EVAL_METHOD__=2", + "__TA_FBIT__=47", "__UDQ_IBIT__=0", - "__INTMAX_WIDTH__=64", "__ORDER_BIG_ENDIAN__=4321", - "__cpp_runtime_arrays=198712L", + "__cpp_runtime_arrays=198712", + "__WITH_AVRLIBC__=1", "__UINT64_TYPE__=long long unsigned int", "__ACCUM_EPSILON__=0x1P-15K", "__UINT32_C(c)=c ## UL", - "__cpp_alias_templates=200704L", - "__FLT_DENORM_MIN__=1.4012984643248171e-45F", + "__BUILTIN_AVR_COUNTLSUHK=1", + "__INTMAX_MAX__=0x7fffffffffffffffLL", + "__cpp_alias_templates=200704", + "__BUILTIN_AVR_COUNTLSUHR=1", + "__BYTE_ORDER__=__ORDER_LITTLE_ENDIAN__", + "__FLT_DENORM_MIN__=1.40129846e-45F", "__LLFRACT_IBIT__=0", "__INT8_MAX__=0x7f", "__LONG_WIDTH__=32", - "__UINT_FAST32_TYPE__=unsigned int", - "__FLT32X_NORM_MAX__=1.7976931348623157e+308F32x", + "__UINT_FAST32_TYPE__=long unsigned int", "__CHAR32_TYPE__=long unsigned int", - "__FLT_MAX__=3.4028234663852886e+38F", - "__cpp_constexpr=201304L", + "__BUILTIN_AVR_COUNTLSULK=1", + "__BUILTIN_AVR_COUNTLSULR=1", + "__FLT_MAX__=3.40282347e+38F", + "__cpp_constexpr=201304", "__USACCUM_FBIT__=8", + "__BUILTIN_AVR_COUNTLSFX=1", "__INT32_TYPE__=long int", - "__SIZEOF_DOUBLE__=8", - "__cpp_exceptions=199711L", + "__SIZEOF_DOUBLE__=4", "__FLT_MIN_10_EXP__=(-37)", "__UFRACT_EPSILON__=0x1P-16UR", - "__FLT64_MIN__=2.2250738585072014e-308F64", "__INT_LEAST32_WIDTH__=32", + "__BUILTIN_AVR_COUNTLSHK=1", + "__BUILTIN_AVR_COUNTLSHR=1", "__INTMAX_TYPE__=long long int", - "__FLT32X_HAS_QUIET_NAN__=1", + "__BUILTIN_AVR_ABSLLK=1", + "__BUILTIN_AVR_ABSLLR=1", + "__DEC128_MAX_EXP__=6145", + "__AVR_HAVE_16BIT_SP__=1", "__ATOMIC_CONSUME=1", "__GNUC_MINOR__=3", - "__INT_FAST16_WIDTH__=32", + "__INT_FAST16_WIDTH__=16", "__UINTMAX_MAX__=0xffffffffffffffffULL", - "__FLT32X_DENORM_MIN__=4.9406564584124654e-324F32x", + "__DEC32_MANT_DIG__=7", "__HA_FBIT__=7", - "__DBL_MAX_10_EXP__=308", - "__LDBL_DENORM_MIN__=4.9406564584124654e-324L", + "__BUILTIN_AVR_COUNTLSLK=1", + "__BUILTIN_AVR_COUNTLSLR=1", + "__BUILTIN_AVR_CLI=1", + "__DBL_MAX_10_EXP__=38", + "__LDBL_DENORM_MIN__=1.40129846e-45L", "__INT16_C(c)=c", + "__cpp_generic_lambdas=201304", "__STDC__=1", - "__FLT32X_DIG__=15", "__PTRDIFF_TYPE__=int", "__LLFRACT_MIN__=(-0.5LLR-0.5LLR)", + "__BUILTIN_AVR_LRBITS=1", "__ATOMIC_SEQ_CST=5", "__DA_FBIT__=31", "__UINT32_TYPE__=long unsigned int", - "__FLT32X_MIN_10_EXP__=(-307)", + "__BUILTIN_AVR_ROUNDLLK=1", "__UINTPTR_TYPE__=unsigned int", + "__BUILTIN_AVR_ROUNDLLR=1", "__USA_IBIT__=16", - "__ARM_EABI__=1", - "__LDBL_MIN_10_EXP__=(-307)", - "__cpp_generic_lambdas=201304L", + "__BUILTIN_AVR_ULRBITS=1", + "__DEC64_SUBNORMAL_MIN__=0.000000000000001E-383DD", + "__DEC128_MANT_DIG__=34", + "__LDBL_MIN_10_EXP__=(-37)", + "__BUILTIN_AVR_COUNTLSUK=1", + "__BUILTIN_AVR_COUNTLSUR=1", "__SIZEOF_LONG_LONG__=8", "__ULACCUM_EPSILON__=0x1P-32ULK", - "__cpp_user_defined_literals=200809L", + "__cpp_user_defined_literals=200809", "__SACCUM_IBIT__=8", "__GCC_ATOMIC_LLONG_LOCK_FREE=1", + "__LDBL_DIG__=6", "__FLT_DECIMAL_DIG__=9", - "__UINT_FAST16_MAX__=0xffffffffU", - "__LDBL_NORM_MAX__=1.7976931348623157e+308L", + "__UINT_FAST16_MAX__=0xffffU", "__GCC_ATOMIC_SHORT_LOCK_FREE=1", + "__BUILTIN_AVR_ABSHK=1", + "__BUILTIN_AVR_FLASH_SEGMENT=1", + "__INT_LEAST64_WIDTH__=64", "__ULLFRACT_MAX__=0XFFFFFFFFFFFFFFFFP-64ULLR", - "__UINT_FAST8_TYPE__=unsigned int", + "__UINT_FAST8_TYPE__=unsigned char", "__USFRACT_EPSILON__=0x1P-8UHR", "__ULACCUM_FBIT__=32", "__QQ_IBIT__=0", - "__cpp_init_captures=201304L", + "__cpp_init_captures=201304", "__ATOMIC_ACQ_REL=4", "__ATOMIC_RELEASE=3", + "__BUILTIN_AVR_FMUL=1", "USBCON" ] } diff --git a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino index af0fd65..72bfecb 100644 --- a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino +++ b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino @@ -38,7 +38,7 @@ #define SPI_MOSI_PIN 3 #define SPI_MISO_PIN 4 -#define MAX30001_CS_PIN 5 +#define MAX30001_CS_PIN 7 // 5 #define MAX30001_INTB_PIN 20 #define MAX30001_INT2B_PIN 19 diff --git a/src/protocentral_max30001.cpp b/src/protocentral_max30001.cpp index 6568e2d..59b32ae 100644 --- a/src/protocentral_max30001.cpp +++ b/src/protocentral_max30001.cpp @@ -175,6 +175,9 @@ void MAX30001::BeginECGOnly() void MAX30001::BeginECGBioZ() { + max30001_cnfg_bmux_t cnfg_bmux; + max30001_cnfg_bioz_t cnfg_bioz; + _max30001SwReset(); delay(100); @@ -193,17 +196,44 @@ void MAX30001::BeginECGBioZ() _max30001RegWrite(CNFG_ECG, 0x835000); delay(100); - _max30001RegWrite(CNFG_BMUX, 0x000040); // Pins connected internally to BioZ channels + cnfg_bmux.bit.openp = 0; + cnfg_bmux.bit.openn = 0; + cnfg_bmux.bit.calp_sel = 0x00; // No cal signal on BioZ + cnfg_bmux.bit.caln_sel = 0x00; // No cal signal on BioZ + cnfg_bmux.bit.cg_mode = 0x00; // Unchopped + cnfg_bmux.bit.en_bist=0; + cnfg_bmux.bit.rnom=0x00; + cnfg_bmux.bit.rmod=0x04; + cnfg_bmux.bit.fbist=0; + + _max30001RegWrite(CNFG_BMUX, cnfg_bmux.all); delay(100); - _max30001RegWrite(CNFG_BIOZ, 0x201433); // BioZ Rate: 64 SPS | Current generator: 32 uA - delay(100); + //_max30001RegWrite(CNFG_BMUX, 0x000040); // Pins connected internally to BioZ channels + //delay(100); - // Set MAX30001G specific BioZ LC + // Set MAX30001G specific BioZ LC _max30001RegWrite(CNFG_BIOZ_LC, 0x800000); // Turn OFF low current mode + delay(100); + + cnfg_bioz.bit.rate = 0; + cnfg_bioz.bit.ahpf = 0b010; + cnfg_bioz.bit.ext_rbias = 0x00; + cnfg_bioz.bit.ln_bioz=1; + cnfg_bioz.bit.gain = 0b10; + cnfg_bioz.bit.dhpf = 0b01; + cnfg_bioz.bit.dlpf = 0x01; + cnfg_bioz.bit.fcgen = 0b100; + cnfg_bioz.bit.cgmon = 0x00; + cnfg_bioz.bit.cgmag = 0b011; + cnfg_bioz.bit.phoff = 0x0000; + + //_max30001RegWrite(CNFG_BIOZ, 0x201433); // BioZ Rate: 64 SPS | Current generator: 32 uA + _max30001RegWrite(CNFG_BIOZ, cnfg_bioz.all); + delay(100); _max30001RegWrite(MNGR_INT, 0x7B0000); // EFIT=16, BFIT=8 - + delay(100); //max30001SetInterrupts(EN_EINT | 0x01); // Enable ECG Interrupts diff --git a/src/protocentral_max30001.h b/src/protocentral_max30001.h index 9a3f9c4..31d218d 100644 --- a/src/protocentral_max30001.h +++ b/src/protocentral_max30001.h @@ -21,8 +21,42 @@ // // For information on how to use, visit https://github.com/Protocentral/protocentral-max30001-arduino // +// SOME PARTS OF THIS CODE ARE COPYRIGHT MAXIM INTEFGRATED PRODUCTS, INC. and are used with permission according to the following license: +// ///////////////////////////////////////////////////////////////////////////////////////// +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * 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 MAXIM INTEGRATED 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. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + *******************************************************************************/ + #ifndef protocentral_max30001_h #define protocentral_max30001_h @@ -159,6 +193,56 @@ typedef union max30001_mngr_int_reg } max30001_mngr_int_t; +/** + * @brief CNFG_BMUX (0x17) + */ +typedef union max30001_cnfg_bmux_reg +{ + uint32_t all; + struct + { + uint32_t fbist : 2; + uint32_t reserved1 : 2; + uint32_t rmod : 3; + uint32_t reserved2 : 1; + uint32_t rnom : 3; + uint32_t en_bist : 1; + uint32_t cg_mode : 2; + uint32_t reserved3 : 2; + uint32_t caln_sel : 2; + uint32_t calp_sel : 2; + uint32_t openn : 1; + uint32_t openp : 1; + uint32_t reserved4 : 2; + uint32_t reserved : 8; + } bit; + +} max30001_cnfg_bmux_t; + +/** + * @brief CNFG_BIOZ (0x18) + */ +typedef union max30001_bioz_reg +{ + uint32_t all; + struct + { + uint32_t phoff : 4; + uint32_t cgmag : 3; + uint32_t cgmon : 1; + uint32_t fcgen : 4; + uint32_t dlpf : 2; + uint32_t dhpf : 2; + uint32_t gain : 2; + uint32_t ln_bioz : 1; + uint32_t ext_rbias : 1; + uint32_t ahpf : 3; + uint32_t rate : 1; + uint32_t reserved : 8; + } bit; + +} max30001_cnfg_bioz_t; + typedef enum { SAMPLINGRATE_128 = 128, @@ -197,10 +281,9 @@ class MAX30001 void readStatus(void); private: - void _max30001ReadECGFIFO(int num_bytes); void _max30001ReadBIOZFIFO(int num_bytes); - + void _max30001Synch(void); void _max30001RegWrite(unsigned char WRITE_ADDRESS, unsigned long data); void _max30001RegRead(uint8_t Reg_address, uint8_t *buff); @@ -211,7 +294,7 @@ class MAX30001 max30001_status_t global_status; int _cs_pin; - volatile unsigned char _readBufferECG[128]; // 4*32 samples + volatile unsigned char _readBufferECG[128]; // 4*32 samples volatile unsigned char _readBufferBIOZ[128]; // 4*32 samples }; From 778d35de85e3521ce8aea14f462bbeaadeee25e5 Mon Sep 17 00:00:00 2001 From: Ashwin K Whitchurch Date: Tue, 21 Mar 2023 20:15:28 +0530 Subject: [PATCH 15/18] Update Example2-Interrupt-Driven.ino --- .../Example2-Interrupt-Driven.ino | 35 ++----------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino index 72bfecb..1b7a544 100644 --- a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino +++ b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino @@ -34,15 +34,8 @@ #include #include "protocentral_max30001.h" -#define SPI_SCK_PIN 2 -#define SPI_MOSI_PIN 3 -#define SPI_MISO_PIN 4 - #define MAX30001_CS_PIN 7 // 5 -#define MAX30001_INTB_PIN 20 -#define MAX30001_INT2B_PIN 19 - -#define AFE44XX_CS_PIN 27 +#define MAX30001_INTB_PIN 2 #define MAX30001_DELAY_SAMPLES 8 // Time between consecutive samples @@ -118,17 +111,6 @@ void setup() pinMode(MAX30001_CS_PIN, OUTPUT); digitalWrite(MAX30001_CS_PIN, HIGH); - pinMode(AFE44XX_CS_PIN, OUTPUT); - digitalWrite(AFE44XX_CS_PIN, HIGH); - - pinMode(MAX30001_INTB_PIN, INPUT); - -#ifdef ARDUINO_ARCH_RP2040 - SPI.setRX(SPI_MISO_PIN); - SPI.setTX(SPI_MOSI_PIN); - SPI.setSCK(SPI_SCK_PIN); -#endif - SPI.begin(); bool ret = max30001.max30001ReadInfo(); @@ -151,24 +133,11 @@ void setup() max30001.BeginECGBioZ(); // initialize MAX30001 Serial.println("Chip initialised"); - // attachInterrupt(digitalPinToInterrupt(MAX30001_INTB_PIN), intr_cb, FALLING); } void loop() { max30001.max30001ServiceAllInterrupts(); - // ecg_data = max30001.getECGSamples(); - // max30001.getHRandRR(); - /*if (BioZSkipSample == false) { - //bioz_data = max30001.getBioZSamples(); - //sendData(ecg_data, bioz_data, BioZSkipSample); - BioZSkipSample = true; - } else - { - bioz_data = 0x00; - //sendData(ecg_data, bioz_data, BioZSkipSample); - BioZSkipSample=false; - }*/ if (max30001.ecgSamplesAvailable > 0) { @@ -180,5 +149,5 @@ void loop() } max30001.ecgSamplesAvailable = 0; } - // delay(4); + } \ No newline at end of file From 4849ff36308e89849e502c5674c56014b0241887 Mon Sep 17 00:00:00 2001 From: Ashwin K Whitchurch Date: Wed, 22 Mar 2023 09:52:47 +0530 Subject: [PATCH 16/18] Temp commit --- .vscode/arduino.json | 2 +- .../Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.vscode/arduino.json b/.vscode/arduino.json index 18b1538..fdbd5ce 100644 --- a/.vscode/arduino.json +++ b/.vscode/arduino.json @@ -1,5 +1,5 @@ { - "port": "/dev/tty.usbmodem1401", + "port": "/dev/tty.usbmodem11201", "board": "arduino:avr:uno", "sketch": "examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino" } \ No newline at end of file diff --git a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino index 1b7a544..450c268 100644 --- a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino +++ b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino @@ -108,8 +108,8 @@ void setup() { Serial.begin(57600); // Serial begin - pinMode(MAX30001_CS_PIN, OUTPUT); - digitalWrite(MAX30001_CS_PIN, HIGH); + //pinMode(MAX30001_CS_PIN, OUTPUT); + //digitalWrite(MAX30001_CS_PIN, HIGH); SPI.begin(); @@ -149,5 +149,4 @@ void loop() } max30001.ecgSamplesAvailable = 0; } - } \ No newline at end of file From 7b489aa606d3bd4d17d01e92f26ba537cc87bf39 Mon Sep 17 00:00:00 2001 From: Ashwin Date: Wed, 22 Mar 2023 13:16:38 +0530 Subject: [PATCH 17/18] Removed interrupt driven example --- .DS_Store | Bin 8196 -> 8196 bytes .vscode/arduino.json | 4 +- examples/.DS_Store | Bin 6148 -> 6148 bytes .../Example2-Interrupt-Driven.ino | 152 ------------------ 4 files changed, 2 insertions(+), 154 deletions(-) delete mode 100644 examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino diff --git a/.DS_Store b/.DS_Store index e76291e580dc2ef0ab7520d13c109b52255a8805..4589208803c4ec5491bd33277ea1229ce7606ccd 100644 GIT binary patch delta 189 zcmZp1XmOa}&nUhzU^hRb_+}n~UyQm*<;4X_Ir&Kp3=F%H3UV@wOAHLIF)}f;u(Gjp zuyb&8#0F>Nmj{<5mXsDdO>P$O_T%K>j2DoquGTd)F*49mFflW!)lsOn1hb9JYHK+; zM3wcegW|Jua`WRB!GQn#;Jc S;Th9rc8T9Cj0PJE8JPh@&o5B` delta 42 ycmZp1XmOa}&nUVvU^hRb=w=>)UyPF<2(@o+7oNqqS)Jzr^JaF5-z*zznV11Ybq?wP diff --git a/.vscode/arduino.json b/.vscode/arduino.json index fdbd5ce..723b771 100644 --- a/.vscode/arduino.json +++ b/.vscode/arduino.json @@ -1,5 +1,5 @@ { - "port": "/dev/tty.usbmodem11201", + "port": "/dev/tty.usbmodem212301", "board": "arduino:avr:uno", - "sketch": "examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino" + "sketch": "examples/Example1-ECG-BioZ-stream-Openview/Example1-ECG-BioZ-stream-Openview.ino" } \ No newline at end of file diff --git a/examples/.DS_Store b/examples/.DS_Store index 42c387b5a4d50b6a03ac763804e71dfea4860184..8742020d240c415819d8a4e6a0f8bc4fb6c46aa7 100644 GIT binary patch delta 67 zcmZoMXfc=|#>B)qu~2NHo+2a5#(>?7j4YdZSdtkxi*g9DOl)Y|%+A5j0aUVCkmEb^ VWPTAx4hA4#WME*~93irX82~Q$4*dWC delta 383 zcmZoMXfc=|#>B!ku~2NHo+2aL#(>?7iyN4k7}+-SFeNkAOES1JR4^nmuu5=%;pof3;N4uv{GE9+zlb9T&_*VZEt?}m)-VGAFEw13 diff --git a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino b/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino deleted file mode 100644 index 450c268..0000000 --- a/examples/Example2-Interrupt-Driven/Example2-Interrupt-Driven.ino +++ /dev/null @@ -1,152 +0,0 @@ -////////////////////////////////////////////////////////////////////////////////////////// -// -// Demo code for the MAX30001 breakout board -// -// This example plots the ECG through serial UART on openview processing GUI. -// GUI URL: https://github.com/Protocentral/protocentral_openview.git -// -// Arduino connections: -// -// |MAX30001 pin label| Pin Function |Arduino Connection| -// |----------------- |:--------------------:|-----------------:| -// | MISO | Slave Out | D12 | -// | MOSI | Slave In | D11 | -// | SCLK | Serial Clock | D13 | -// | CS | Chip Select | D7 | -// | VCC | Digital VDD | +5V | -// | GND | Digital Gnd | Gnd | -// | FCLK | 32K CLOCK | - | -// | INT1 | Interrupt1 | 02 | -// | INT2 | Interrupt2 | - | -// -// This software is licensed under the MIT License(http://opensource.org/licenses/MIT). -// -// 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. -// -// For information on how to use, visit https://github.com/Protocentral/protocentral_max30001 -// -///////////////////////////////////////////////////////////////////////////////////////// - -#include -#include "protocentral_max30001.h" - -#define MAX30001_CS_PIN 7 // 5 -#define MAX30001_INTB_PIN 2 - -#define MAX30001_DELAY_SAMPLES 8 // Time between consecutive samples - -#define CES_CMDIF_PKT_START_1 0x0A -#define CES_CMDIF_PKT_START_2 0xFA -#define CES_CMDIF_TYPE_DATA 0x02 -#define CES_CMDIF_PKT_STOP 0x0B -#define DATA_LEN 0x0C -#define ZERO 0 - -volatile char DataPacket[DATA_LEN]; -const char DataPacketFooter[2] = {ZERO, CES_CMDIF_PKT_STOP}; -const char DataPacketHeader[5] = {CES_CMDIF_PKT_START_1, CES_CMDIF_PKT_START_2, DATA_LEN, ZERO, CES_CMDIF_TYPE_DATA}; - -uint8_t data_len = 0x0C; - -MAX30001 max30001(MAX30001_CS_PIN); - -signed long ecg_data; -signed long bioz_data; - -void sendData(signed long ecg_sample, signed long bioz_sample, bool _bioZSkipSample) -{ - - DataPacket[0] = ecg_sample; - DataPacket[1] = ecg_sample >> 8; - DataPacket[2] = ecg_sample >> 16; - DataPacket[3] = ecg_sample >> 24; - - DataPacket[4] = bioz_sample; - DataPacket[5] = bioz_sample >> 8; - DataPacket[6] = bioz_sample >> 16; - DataPacket[7] = bioz_sample >> 24; - - if (_bioZSkipSample == false) - { - DataPacket[8] = 0x00; - } - else - { - DataPacket[8] = 0xFF; - } - - DataPacket[9] = 0x00; // max30001.heartRate >> 8; - DataPacket[10] = 0x00; - DataPacket[11] = 0x00; - - // Send packet header (in ProtoCentral OpenView format) - for (int i = 0; i < 5; i++) - { - Serial.write(DataPacketHeader[i]); - } - - // Send the data payload - for (int i = 0; i < DATA_LEN; i++) // transmit the data - { - Serial.write(DataPacket[i]); - } - - // Send packet footer (in ProtoCentral OpenView format) - for (int i = 0; i < 2; i++) - { - Serial.write(DataPacketFooter[i]); - } -} - -bool BioZSkipSample = false; - -void setup() -{ - Serial.begin(57600); // Serial begin - - //pinMode(MAX30001_CS_PIN, OUTPUT); - //digitalWrite(MAX30001_CS_PIN, HIGH); - - SPI.begin(); - - bool ret = max30001.max30001ReadInfo(); - if (ret) - { - Serial.println("MAX 30001 read ID Success"); - } - else - { - while (!ret) - { - // stay here untill the issue is fixed. - ret = max30001.max30001ReadInfo(); - Serial.println("Failed to read ID, please make sure all the pins are connected"); - delay(5000); - } - } - - Serial.println("Initialising the chip ..."); - max30001.BeginECGBioZ(); // initialize MAX30001 - - Serial.println("Chip initialised"); -} - -void loop() -{ - max30001.max30001ServiceAllInterrupts(); - - if (max30001.ecgSamplesAvailable > 0) - { - // Serial.print("Data Available: "); - // Serial.println(max30001.ecgSamplesAvailable); - for (int i = 0; i < max30001.ecgSamplesAvailable; i++) - { - sendData(max30001.s32ECGData[i], 0, false); - } - max30001.ecgSamplesAvailable = 0; - } -} \ No newline at end of file From 27ca4c03dc959dfb484bdb7e4e0b1ecb3ba49ef6 Mon Sep 17 00:00:00 2001 From: Ashwin Date: Wed, 22 Mar 2023 13:22:20 +0530 Subject: [PATCH 18/18] Edit GH workflow Portenta m4 --- .github/workflows/compile-examples.yml | 81 +++++++++++--------------- 1 file changed, 33 insertions(+), 48 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 015918b..009713f 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -1,25 +1,29 @@ name: Compile Examples +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows on: - pull_request: + push: paths: - ".github/workflows/compile-examples.yml" - "examples/**" - "src/**" - push: + pull_request: paths: - ".github/workflows/compile-examples.yml" - "examples/**" - "src/**" + schedule: + # Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms). + - cron: "0 8 * * TUE" + workflow_dispatch: + repository_dispatch: jobs: build: + name: ${{ matrix.board.fqbn }} runs-on: ubuntu-latest env: - UNIVERSAL_LIBRARIES: | - - source-path: ./ - SKETCHES_REPORTS_PATH: sketches-reports strategy: @@ -27,40 +31,28 @@ jobs: matrix: board: - - fqbn: arduino:avr:uno + - fqbn: arduino:avr:nano platforms: | - name: arduino:avr - - fqbn: arduino:samd:mkr1000 - platforms: | - - name: arduino:samd - - fqbn: arduino:samd:mkrzero - platforms: | - - name: arduino:samd - - fqbn: arduino:samd:mkrwifi1010 - platforms: | - - name: arduino:samd - - fqbn: arduino:samd:mkrfox1200 - platforms: | - - name: arduino:samd - - fqbn: arduino:samd:mkrwan1300 + - fqbn: arduino:avr:mega platforms: | - - name: arduino:samd - - fqbn: arduino:samd:mkrwan1310 + - name: arduino:avr + - fqbn: arduino:avr:leonardo platforms: | - - name: arduino:samd - - fqbn: arduino:samd:mkrgsm1400 + - name: arduino:avr + - fqbn: arduino:megaavr:nona4809 platforms: | - - name: arduino:samd - - fqbn: arduino:samd:mkrnb1500 + - name: arduino:megaavr + - fqbn: arduino:sam:arduino_due_x_dbg platforms: | - - name: arduino:samd - - fqbn: arduino:samd:mkrvidor4000 + - name: arduino:sam + - fqbn: arduino:samd:mkrzero platforms: | - name: arduino:samd - - fqbn: arduino:mbed_portenta:envie_m7 + - fqbn: arduino:mbed_portenta:envie_m7:target_core=cm4 platforms: | - name: arduino:mbed_portenta - - fqbn: arduino:mbed_portenta:envie_m4 + - fqbn: arduino:mbed_portenta:envie_m7 platforms: | - name: arduino:mbed_portenta - fqbn: arduino:mbed_nano:nano33ble @@ -69,37 +61,30 @@ jobs: - fqbn: arduino:mbed_nano:nanorp2040connect platforms: | - name: arduino:mbed_nano - - fqbn: arduino:mbed_edge:edge_control - platforms: | - - name: arduino:mbed_edge - - fqbn: esp32:esp32:esp32 - platforms: | - - name: esp32:esp32 - source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json - - fqbn: rp2040:rp2040:rpipico - platforms: | - - name: rp2040:rp2040 - source-url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json steps: - - name: Checkout + - name: Checkout repository uses: actions/checkout@v3 - - name: Install ESP32 platform dependencies - if: startsWith(matrix.board.fqbn, 'esp32:esp32') - run: pip3 install pyserial - - name: Compile examples uses: arduino/compile-sketches@v1 with: + github-token: ${{ secrets.GITHUB_TOKEN }} fqbn: ${{ matrix.board.fqbn }} platforms: ${{ matrix.board.platforms }} + libraries: | + # Install the library from the local path. + - source-path: ./ + # Additional library dependencies can be listed here. + # See: https://github.com/arduino/compile-sketches#libraries + sketch-paths: | + - examples enable-deltas-report: true sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} - - name: Save memory usage change report as artifact - if: github.event_name == 'pull_request' + - name: Save sketches report as workflow artifact uses: actions/upload-artifact@v3 with: - name: ${{ env.SKETCHES_REPORTS_PATH }} + if-no-files-found: error path: ${{ env.SKETCHES_REPORTS_PATH }} + name: ${{ env.SKETCHES_REPORTS_PATH }} \ No newline at end of file