MAX30001G 1.0.1 Arduino library for MAX30001G ECG and BIOZ AFE

max30001g.h
Go to the documentation of this file.
1 /******************************************************************************************************/
2 // Include file for the MAX30001G ECG and Bioimpedance module
3 //
4 // Urs Utzinger, maintainer for the code, July 2024 - present
5 // GPT-5.3 assisted development, review and testing, Spring 2026
6 /******************************************************************************************************/
7
8 #ifndef MAX30001G_H
9 #define MAX30001G_H
10
11 // Standard Libraries
12 #include <stdint.h>
13 #include <SPI.h>
14
15 // MAX30001G base data types
16 #include "max30001g_defs.h" // Register addresses, bit masks, and other constants
17 #include "max30001g_regs_typedefs.h" // Register value structures and unions
18 #include "max30001g_typedefs.h" // Data structures for BIOZ and ECG configuration and scan results
19 #include "max30001g_globals.h" // Global variables for device state and configuration
20
21 // SPI Settings (defined in max30001g_comm.cpp)
22 extern SPISettings SPI_SETTINGS;
23
34 class MAX30001G {
35
36 /******************************************************************************************************/
37 /******************************************************************************************************/
38 /******************************************************************************************************/
39 /******************************************************************************************************/
40 public:
41
48 MAX30001G(uint8_t csPin, int intPin1 = -1, int intPin2 = -1);
49
50 enum InterruptEvent : uint8_t {
51 IRQ_ECG_FIFO = 0,
52 IRQ_ECG_OVF,
53 IRQ_ECG_FAST,
54 IRQ_ECG_LEADOFF,
55 IRQ_BIOZ_FIFO,
56 IRQ_BIOZ_OVF,
57 IRQ_BIOZ_OVER,
58 IRQ_BIOZ_UNDER,
59 IRQ_BIOZ_CGMON,
60 IRQ_LEADS_ON,
61 IRQ_RTOR,
62 IRQ_PLL_UNLOCK,
63 IRQ_EVENT_COUNT
64 };
65
66 typedef void (*InterruptCallback)(MAX30001G* device, uint32_t status, void* context);
67
68 /* @brief Initialize the device state and read startup registers. */
69 void begin(void);
70
71 /* @brief Stop device operation, disable interrupts, and detach ISR pins. */
72 void end(void);
73
77 void start(void);
78
82 void stop(void);
83
89 bool update(bool reportRaw = false);
90
95 bool updateRaw(void) { return update(true); }
96
97 // ---------------------------------------------------------------------------------------
98 // Setup Functions
99 // ---------------------------------------------------------------------------------------
100
107 void enableAFE(bool ECG, bool BIOZ, bool RtoR);
108
127 void setupECG(
128 uint8_t speed = 1,
129 uint8_t gain = 2,
130 bool threeleads = true);
131
151 void setupBIOZ(
152 uint8_t speed = 0,
153 uint8_t gain = 1,
154 uint8_t ahpf = 1,
155 uint8_t dlpf = 1,
156 uint8_t dhpf = 0,
157 uint16_t frequency = 40000,
158 uint16_t current = 8000,
159 float phase = 0.0f,
160 bool leadbias = true,
161 bool leadsoffdetect = false,
162 bool fourleads = false
163 );
164
187 void setupECGandBIOZ(
188 uint8_t ecg_speed = 1,
189 uint8_t ecg_gain = 2,
190 bool ecg_threeleads = true,
191 uint8_t bioz_speed = 0,
192 uint8_t bioz_gain = 1,
193 uint8_t bioz_dlpf = 1,
194 uint8_t bioz_dhpf = 0,
195 uint16_t bioz_frequency = 8000,
196 uint16_t bioz_current = 8000,
197 float bioz_phase = 0.0f,
198 bool leadbias = true,
199 bool leadsoffdetect = false,
200 bool bioz_fourleads = false
201 ); // initialize AFE for ECG and BIOZ
202
210 void setupECGSignalCalibration(uint8_t speed = 1, uint8_t gain = 2);
211
219 void setupBIOZSignalCalibration(uint8_t speed = 0, uint8_t gain = 1);
220
242 void setupBIOZImpedanceCalibration(
243 uint8_t speed = 0,
244 uint8_t gain = 1,
245 uint8_t ahpf = 1,
246 uint8_t dlpf = 1,
247 uint8_t dhpf = 0,
248 uint16_t frequency = 40000,
249 uint16_t current = 8000,
250 float phase = 0.0f,
251 uint32_t resistance = 5000,
252 uint8_t modulation = 0,
253 uint8_t modulation_frequency = 3
254 );
255
261 void setupBIOZExternalImpedanceCalibration(
262 uint16_t frequency = 40000, float phase = 0.0f
263 );
264
273 void setupBIOZScan(uint8_t avg, bool fast, bool fourleads, bool fullRange);
274
281 void setupBIOZScan(const BIOZScanConfig& config = BIOZScanConfig(), bool reuseCurrents = false);
282
290 void scanBIOZ(uint8_t avg = 2, bool fast = false, bool fourleads = false, bool fullRange = false);
291
313 void scanBIOZ(const BIOZScanConfig& config, bool reuseCurrents = false);
314
319 void startBIOZScan(void);
320
325 void stopBIOZScan(void);
326
331 void stepBIOZScan(void);
332
333 // ---------------------------------------------------------------------------------------
334 // Registers: max30001g_regs.cpp
335 // ---------------------------------------------------------------------------------------
336
337 /* @brief Read all known MAX30001G registers into global register mirrors. */
338 void readAllRegisters(void);
339
340 /* @brief Read INFO register into global mirror. */
341 void readInfo(void);
342
343 /* @brief Read status register(s) and refresh status flags. */
344 void readStatusRegisters(void);
345
346 /* @brief Save current register configuration into internal snapshot. */
347 void saveConfig(void);
348
349 /* @brief Restore register configuration from internal snapshot. */
350 void restoreConfig(void);
351
352 /* @brief Read and print saved/current configuration related registers. */
353 void printConfig(void);
354
355 /* @brief Print all known register mirrors for debugging. */
356 void printAllRegisters(void);
357
358 /* @brief Print INFO register decode. */
359 void printInfo(void);
360
361 /* @brief Print STATUS register decode. */
362 void printStatus(void);
363
364 // ---------------------------------------------------------------------------------------
365 // System: max30001g_system.h
366 // ---------------------------------------------------------------------------------------
367
368 /* @brief Issue synchronization command to align conversion timing. */
369 void synch(void);
370
371 /* @brief Issue software reset to device. */
372 void swReset(void);
373
382 void setFMSTR(uint8_t fmstr);
383
388 HealthCheckResult healthCheck(void);
389
390 // ---------------------------------------------------------------------------------------
391 // Read Data: max30001g_readdata.cpp
392 // ---------------------------------------------------------------------------------------
393
397 void FIFOReset(void);
398
403 void readECG_FIFO(bool reportRaw);
404
409 void readBIOZ_FIFO(bool reportRaw);
410
416 float readECG(bool reportRaw);
417
421 void readRTOR(void);
422
428 float readBIOZ(bool reportRaw);
429
430 // ---------------------------------------------------------------------------------------
431 // Interrupts: max30001g_interrupt.cpp
432 // ---------------------------------------------------------------------------------------
433
437 void serviceAllInterrupts(void);
438
445 bool servicePendingInterrupts(void);
446
450 void readAndClearFaults(void);
451
457 void clearLatchedStatusFlags(void);
458
470 bool setInterruptEventCallback(InterruptEvent event, InterruptCallback cb, void* context = nullptr);
471
479 bool setInterruptAggregateCallback(InterruptCallback cb, void* context = nullptr, uint32_t statusMask = 0x00FFFFFFUL);
480
486 void clearInterruptEventCallback(InterruptEvent event);
487
491 void clearInterruptAggregateCallback(void);
492
496 void clearAllInterruptCallbacks(void);
497
502 void handleECGFifoInterrupt(bool reportRaw = false);
503
508 void handleBIOZFifoInterrupt(bool reportRaw = false);
509
513 void handleRtoRInterrupt(void);
514
525 bool setInterrupt1(bool ecg, bool bioz, bool rtor, bool leadon, bool leadoff, bool bioz_fourwire = false) {
526 return setInterrupt(MAX30001_EN_INT1, ecg, bioz, rtor, leadon, leadoff, bioz_fourwire);
527 }
528
539 bool setInterrupt2(bool ecg, bool bioz, bool rtor, bool leadon, bool leadoff, bool bioz_fourwire = false) {
540 return setInterrupt(MAX30001_EN_INT2, ecg, bioz, rtor, leadon, leadoff, bioz_fourwire);
541 }
542
546 void setDefaultInterruptClearing(void);
547
553 void setFIFOInterruptThreshold(uint8_t ecg, uint8_t bioz);
554
555 // ---------------------------------------------------------------------------------------
556 // ECG Configuration: max30001g_configure_ecg.cpp
557 // ---------------------------------------------------------------------------------------
558
566 void setECGSamplingRate(uint8_t ECG);
567
585 void setECGfilter(uint8_t lpf, uint8_t hpf);
586
595 void setECGgain(uint8_t gain);
596
602 void setECGLeadPolarity(bool inverted, bool open);
603
608 void setECGAutoRecovery(int threshold_voltage);
609
610 /* @brief Disable ECG fast-recovery mode and return to normal operation. */
611 void setECGNormalRecovery(void);@details
612
613 /* @brief Enter manual ECG fast-recovery mode. */
614 void startECGManualRecovery(void);
615
616 /* @brief Exit manual ECG fast-recovery mode. */
617 void stopECGManualRecovery(void);
618
619 // ---------------------------------------------------------------------------------------
620 // BIOZ Configuration: max30001g_configure_bioz.cpp
621 // ---------------------------------------------------------------------------------------
622
629 void setBIOZSamplingRate(uint8_t speed_select);
639 void setBIOZgain(uint8_t gain, bool lowNoise);
640
657 void setBIOZModulationFrequencyByFrequency(uint16_t frequency_hz);
658
666 void setBIOZModulationFrequencybyIndex(uint8_t frequency_selector);
667
675 void setBIOZmag(uint32_t current_nA);
676
684 void setBIOZPhaseOffsetbyIndex(uint8_t selector);
685
711 void setBIOZPhaseOffsetbyPhase(float phase_deg);
712
721 void setBIOZPhaseOffsetbyPhase(uint16_t frequency_hz, float phase_deg);
722
746 void setBIOZfilter(uint8_t ahpf, uint8_t lpf, uint8_t hpf);
747
757 void setBIOZmodulation(uint8_t mode);
758
763 void setBIOZCurrentMonitor(bool enable);
764
765 // ---------------------------------------------------------------------------------------
766 // Leads Configuration: max30001g_configure_leads.cpp
767 // ---------------------------------------------------------------------------------------
768
775 void setLeadsOnDetection(bool enable);
776
791 void setLeadsOffDetection(bool enable, bool bioz_4, uint8_t electrode_impedance);
792
803 void setLeadsBias(bool enable, uint8_t resistance);
804
805 // ---------------------------------------------------------------------------------------
806 // RtoR Configuration: max30001g_configure_rtor.cpp
807 // ---------------------------------------------------------------------------------------
808
812 void setDefaultRtoR(void);
813
829 void setDefaultNoRtoR(void);
830
849 void setRtoR(bool enable, uint8_t ptsf, uint8_t pavg, uint8_t gain, uint8_t wndw, uint8_t hoff, uint8_t ravg, uint8_t rhsf);
850
851 // ---------------------------------------------------------------------------------------
852 // Test Signal and Calibration: max30001g_calibration.cpp
853 // ---------------------------------------------------------------------------------------
854
858 void setDefaultNoTestSignal(void);
859
863 void setDefaultECGTestSignal(void);
864
868 void setDefaultBIOZTestSignal(void);
869
873 void setDefaultECGandBIOZTestSignal(void);
874
887 void setTestSignal(
888 bool enableECGCalSignal,
889 bool enableBIOZCalSignal,
890 bool unipolar,
891 bool cal_vmag,
892 uint8_t freq,
893 uint8_t dutycycle
894 );
895
899 void setDefaultBIOZTestImpedance(void);
900
904 void setDefaultNoBIOZTestImpedance(void);
905
968 void setBIOZTestImpedance(
969 bool enable,
970 bool useHighResistance,
971 bool enableModulation,
972 uint8_t rnomValue,
973 uint8_t rmodValue,
974 uint8_t modFreq
975 );
976
977 /******************************************************************************************************/
978 /******************************************************************************************************/
979 /******************************************************************************************************/
980 /******************************************************************************************************/
981 private:
982
983 // ---------------------------------------------------------------------------------------
984 // Register related: max30001g_regs.cpp
985 // ---------------------------------------------------------------------------------------
986
991 void printEN_INT(max30001_en_int_reg_t en_int);
992
993 /* @brief Print EN_INT1 register decode. */
994 void printEN_INT1(void) { printEN_INT(en_int1); }
995
996 /* @brief Print EN_INT2 register decode. */
997 void printEN_INT2(void) { printEN_INT(en_int2); }
998
999 /* @brief Print MNGR_INT register decode. */
1000 void printMNGR_INT(void);
1001
1002 /* @brief Print MNGR_DYN register decode. */
1003 void printMNGR_DYN(void);
1004
1005 /* @brief Print CNFG_GEN register decode. */
1006 void printCNFG_GEN(void);
1007
1008 /* @brief Print CNFG_CAL register decode. */
1009 void printCNFG_CAL(void);
1010
1011 /* @brief Print CNFG_EMUX register decode. */
1012 void printCNFG_EMUX(void);
1013
1014 /* @brief Print CNFG_ECG register decode. */
1015 void printCNFG_ECG(void);
1016
1017 /* @brief Print CNFG_BMUX register decode. */
1018 void printCNFG_BMUX(void);
1019
1020 /* @brief Print CNFG_BIOZ register decode. */
1021 void printCNFG_BIOZ(void);
1022
1023 /* @brief Print CNFG_BIOZ_LC register decode. */
1024 void printCNFG_BIOZ_LC(void);
1025
1026 /* @brief Print CNFG_RTOR1 register decode. */
1027 void printCNFG_RTOR1(void);
1028
1029 /* @brief Print CNFG_RTOR2 register decode. */
1030 void printCNFG_RTOR2(void);
1031
1032 // ---------------------------------------------------------------------------------------
1033 // System: max30001g_system.h
1034 // ---------------------------------------------------------------------------------------
1035
1036 // Read registers and update global variables based on register values
1037
1039 void updateGlobalECG_samplingRate(void);
1040
1042 void updateGlobalBIOZ_samplingRate(void);
1043
1044 /* @brief Update calibration frequency global from current registers. */
1045 void updateGlobalCAL_fcal(void);
1046
1047 /* @brief Update ECG latency global from current timing/filter state. */
1048 void updateGlobalECG_latency(void);
1049
1050 /* @brief Update BIOZ modulation-frequency global from current registers. */
1051 void updateGlobalBIOZ_frequency(void);
1052
1053 /* @brief Update BIOZ test-impedance globals from current registers. */
1054 void updateGlobalBIOZ_test_impedance(void);
1055
1056 /* @brief Update ECG LPF frequency global from current registers. */
1057 void updateGlobalECG_lpf(void);
1058
1059 /* @brief Update BIOZ DLPF frequency global from current registers. */
1060 void updateGlobalBIOZ_dlpf(void);
1061
1062 /* @brief Update RCAL modulation-frequency global from current registers. */
1063 void updateGlobalRCAL_freq(void);
1064
1065 /* @brief Recompute timing-dependent globals from current register state. */
1066 void refreshTimingGlobals(void);
1067
1068 // ---------------------------------------------------------------------------------------
1069 // Read Data: max30001g_readdata.cpp (internal single-sample helpers)
1070 // ---------------------------------------------------------------------------------------
1071
1072 // ---------------------------------------------------------------------------------------
1073 // Interrupts: max30001g_interrupt.cpp
1074 // ---------------------------------------------------------------------------------------
1075
1088 bool setInterrupt(uint8_t interrupt, bool ecg, bool bioz, bool rtor, bool leadon, bool leadoff, bool bioz_fourwire);
1089
1094 void latchStatusFlags(uint32_t statusWord);
1095
1100 uint32_t readStatusAndLatchFlags(void);
1101
1102 // ---------------------------------------------------------------------------------------
1103 // SPI Communication: max30001g_comm.cpp
1104 // ---------------------------------------------------------------------------------------
1110 void writeRegister(uint8_t address, uint32_t data);
1111
1117 uint32_t readRegister24(uint8_t address);
1118
1124 uint32_t readRegister(uint8_t address) { return readRegister24(address); }
1125
1131 uint8_t readRegisterByte(uint8_t address);
1132
1138 uint8_t readRegister8(uint8_t address) { return readRegisterByte(address); };
1139
1146 bool verifyWrite(uint8_t address, uint32_t expectedValue);
1147
1154 bool verifRegister(uint8_t address, uint32_t expectedValue) { return verifyWrite(address, expectedValue); }
1155
1160 bool spiCheck();
1161
1162 // ---------------------------------------------------------------------------------------
1163 // BIOZ: Impedance spectroscopy helper functions
1164 // ---------------------------------------------------------------------------------------
1165
1171 int32_t closestCurrent(int32_t current);
1172
1180 float impedancemodel(float theta, float magnitude, float phase);
1181
1189 ImpedanceModel fitImpedance(const float* phases, const float* impedances, int num_points);
1190
1191 uint8_t biozScanPhaseCountForFreq(uint8_t freq_idx) const;
1192 uint8_t biozScanSelectAHpf(float lowest_frequency_hz) const;
1193 float biozScanRobustMeanFromBuffer(uint8_t outlier_min_samples, float outlier_sigma, bool& hasSamples);
1194
1195 // ---------------------------------------------------------------------------------------
1196 // Device
1197 // ---------------------------------------------------------------------------------------
1198 enum SetupProfile : uint8_t {
1199 PROFILE_NONE = 0,
1200 PROFILE_ECG,
1201 PROFILE_ECG_CAL,
1202 PROFILE_BIOZ,
1203 PROFILE_BIOZ_CAL,
1204 PROFILE_BIOZ_IMP_CAL,
1205 PROFILE_ECG_AND_BIOZ,
1206 PROFILE_BIOZ_SCAN
1207 };
1208
1209 enum BiozScanState : uint8_t {
1210 BIOZ_SCAN_IDLE = 0,
1211 BIOZ_SCAN_INIT,
1212 BIOZ_SCAN_CONFIG_FREQ,
1213 BIOZ_SCAN_PREPARE_ATTEMPT,
1214 BIOZ_SCAN_CONFIG_PHASE,
1215 BIOZ_SCAN_WAIT_DATA,
1216 BIOZ_SCAN_PROCESS_PHASE,
1217 BIOZ_SCAN_EVALUATE_ATTEMPT,
1218 BIOZ_SCAN_FINALIZE_FREQ,
1219 BIOZ_SCAN_FINISH
1220 };
1221
1222 int _csPin; // chip select for SPI
1223 int _intPin1; // interrupt pin INTB (EN_INT1)
1224 int _intPin2; // interrupt pin INT2B (EN_INT2), optional
1225
1229 static void onAFE_IRQ1(void);
1233 static void onAFE_IRQ2(void);
1234
1235 SetupProfile _profile;
1236 bool _configured;
1237 bool _running;
1238
1239 bool _useECG;
1240 bool _useBIOZ;
1241 bool _useRTOR;
1242
1243 bool _drainECGOnUpdate;
1244 bool _drainBIOZOnUpdate;
1245 bool _readRTOROnUpdate;
1246
1247 bool _applyLeadSettingsOnStart;
1248 bool _leadBiasEnable;
1249 uint8_t _leadBiasResistance;
1250 bool _leadOffEnable;
1251 bool _leadOffBioz4;
1252 uint8_t _leadOffElectrodeImpedance;
1253 bool _leadOnEnable;
1254
1255 ConfigSnapshot _savedConfig;
1256
1257 // BIOZ scan current profile cache (for reuse across scans)
1258 bool _scanCurrentProfileValid;
1259 int32_t _scanCurrentProfile[MAX30001_BIOZ_NUM_FREQUENCIES];
1260 uint8_t _scanProfileFreqStart;
1261 uint8_t _scanProfileFreqEnd;
1262 bool _scanProfileFast;
1263
1264 BIOZScanConfig _scanRuntimeConfig;
1265 bool _scanReuseCurrents;
1266 bool _scanInProgress;
1267 bool _scanCompleted;
1268
1269 BiozScanState _BIOZScanState;
1270 uint8_t _scanFreqIndex;
1271 uint8_t _scanPhaseIndex;
1272 uint8_t _scanAttempt;
1273 uint8_t _scanNumPhaseMeasurements;
1274 uint32_t _scanWaitDeadlineMs;
1275
1276 float _scanThresholdMin;
1277 float _scanThresholdMax;
1278 float _scanAdcTarget;
1279
1280 bool _scanSawValid;
1281 bool _scanSawInvalidOrRange;
1282 bool _scanAnyAboveTarget;
1283 bool _scanAnyInTarget;
1284 float _scanMaxAbsRaw;
1285
1286 int32_t _scanCurrent[MAX30001_BIOZ_NUM_FREQUENCIES];
1287 float _scanFrequency[MAX30001_BIOZ_NUM_FREQUENCIES];
1288 float _scanImpedance[MAX30001_BIOZ_NUM_FREQUENCIES][MAX30001_BIOZ_NUM_PHASES];
1289 float _scanPhaseDeg[MAX30001_BIOZ_NUM_FREQUENCIES][MAX30001_BIOZ_NUM_PHASES];
1290 };
1291 // end of MAX30001G_Public_API
1293
1294 #endif // MAX30001G_H
MAX30001G
MAX30001G device driver class used by Arduino sketches.
Definition: max30001g.h:34
MAX30001G::setDefaultRtoR
void setDefaultRtoR(void)
Apply default RTOR settings and enable RTOR detection.
Definition: max30001g_configure_rtor.cpp:9
MAX30001G::setECGgain
void setECGgain(uint8_t gain)
Set ECG PGA gain.
Definition: max30001g_configure_ecg.cpp:113
MAX30001G::setDefaultECGandBIOZTestSignal
void setDefaultECGandBIOZTestSignal(void)
Apply default voltage calibration settings to ECG and BIOZ.
Definition: max30001g_calibration.cpp:75
MAX30001G::setFIFOInterruptThreshold
void setFIFOInterruptThreshold(uint8_t ecg, uint8_t bioz)
Set FIFO threshold that triggers ECG/BIOZ FIFO interrupts.
Definition: max30001g_interrupt.cpp:555
MAX30001G::clearLatchedStatusFlags
void clearLatchedStatusFlags(void)
Clear software-latched interrupt/fault flags.
Definition: max30001g_interrupt.cpp:90
MAX30001G::setBIOZfilter
void setBIOZfilter(uint8_t ahpf, uint8_t lpf, uint8_t hpf)
Configure BIOZ analog and digital filters.
Definition: max30001g_configure_bioz.cpp:540
MAX30001G::stepBIOZScan
void stepBIOZScan(void)
Advance state-machine style BIOZ scan flow by one step.
Definition: max30001g.cpp:1729
MAX30001G::scanBIOZ
void scanBIOZ(uint8_t avg=2, bool fast=false, bool fourleads=false, bool fullRange=false)
Run impedance scan using basic options.
Definition: max30001g.cpp:2045
MAX30001G::setDefaultBIOZTestSignal
void setDefaultBIOZTestSignal(void)
Apply default BIOZ voltage calibration signal settings.
Definition: max30001g_calibration.cpp:56
MAX30001G::setDefaultECGTestSignal
void setDefaultECGTestSignal(void)
Apply default ECG voltage calibration signal settings.
Definition: max30001g_calibration.cpp:38
MAX30001G::begin
void begin(void)
Definition: max30001g.cpp:215
MAX30001G::setECGfilter
void setECGfilter(uint8_t lpf, uint8_t hpf)
Configure ECG digital filters.
Definition: max30001g_configure_ecg.cpp:52
MAX30001G::setRtoR
void setRtoR(bool enable, uint8_t ptsf, uint8_t pavg, uint8_t gain, uint8_t wndw, uint8_t hoff, uint8_t ravg, uint8_t rhsf)
Configure RTOR algorithm parameters.
Definition: max30001g_configure_rtor.cpp:61
MAX30001G::readInfo
void readInfo(void)
Definition: max30001g_regs.cpp:96
MAX30001G::setupBIOZSignalCalibration
void setupBIOZSignalCalibration(uint8_t speed=0, uint8_t gain=1)
Configure BIOZ voltage calibration signal path.
Definition: max30001g.cpp:793
MAX30001G::setLeadsOffDetection
void setLeadsOffDetection(bool enable, bool bioz_4, uint8_t electrode_impedance)
Configure lead-off detection behavior.
Definition: max30001g_configure_leads.cpp:45
MAX30001G::setECGSamplingRate
void setECGSamplingRate(uint8_t ECG)
Set ECG sample-rate selector.
Definition: max30001g_configure_ecg.cpp:8
MAX30001G::readStatusRegisters
void readStatusRegisters(void)
Definition: max30001g_regs.cpp:106
MAX30001G::setBIOZmag
void setBIOZmag(uint32_t current_nA)
Set BIOZ current magnitude.
Definition: max30001g_configure_bioz.cpp:309
MAX30001G::setECGNormalRecovery
void setECGNormalRecovery(void)
Definition: max30001g_configure_ecg.cpp:243
MAX30001G::setupECGSignalCalibration
void setupECGSignalCalibration(uint8_t speed=1, uint8_t gain=2)
Configure ECG voltage calibration signal path.
Definition: max30001g.cpp:505
MAX30001G::setupBIOZScan
void setupBIOZScan(uint8_t avg, bool fast, bool fourleads, bool fullRange)
Configure lifecycle-driven BIOZ scan flow.
Definition: max30001g.cpp:1502
MAX30001G::readBIOZ
float readBIOZ(bool reportRaw)
Read one BIOZ FIFO sample.
Definition: max30001g_readdata.cpp:143
MAX30001G::handleECGFifoInterrupt
void handleECGFifoInterrupt(bool reportRaw=false)
Convenience callback handler: read ECG FIFO.
Definition: max30001g_interrupt.cpp:338
MAX30001G::clearInterruptAggregateCallback
void clearInterruptAggregateCallback(void)
Clear aggregate interrupt callback.
Definition: max30001g_interrupt.cpp:310
MAX30001G::serviceAllInterrupts
void serviceAllInterrupts(void)
Read STATUS and update interrupt-driven global flags.
Definition: max30001g_interrupt.cpp:178
MAX30001G::enableAFE
void enableAFE(bool ECG, bool BIOZ, bool RtoR)
Enable or disable ECG, BIOZ, and R-to-R engines.
Definition: max30001g.cpp:2568
MAX30001G::setInterrupt1
bool setInterrupt1(bool ecg, bool bioz, bool rtor, bool leadon, bool leadoff, bool bioz_fourwire=false)
Configure interrupt line INT1 event enables.
Definition: max30001g.h:525
MAX30001G::setInterruptAggregateCallback
bool setInterruptAggregateCallback(InterruptCallback cb, void *context=nullptr, uint32_t statusMask=0x00FFFFFFUL)
Register aggregate callback invoked for status bits matching a mask.
Definition: max30001g_interrupt.cpp:282
MAX30001G::handleRtoRInterrupt
void handleRtoRInterrupt(void)
Convenience callback handler: read RTOR data.
Definition: max30001g_interrupt.cpp:346
MAX30001G::setupECGandBIOZ
void setupECGandBIOZ(uint8_t ecg_speed=1, uint8_t ecg_gain=2, bool ecg_threeleads=true, uint8_t bioz_speed=0, uint8_t bioz_gain=1, uint8_t bioz_dlpf=1, uint8_t bioz_dhpf=0, uint16_t bioz_frequency=8000, uint16_t bioz_current=8000, float bioz_phase=0.0f, bool leadbias=true, bool leadsoffdetect=false, bool bioz_fourleads=false)
Configure simultaneous ECG and BIOZ operation.
Definition: max30001g.cpp:1159
MAX30001G::stopBIOZScan
void stopBIOZScan(void)
Stop state-machine style BIOZ scan flow.
Definition: max30001g.cpp:1627
MAX30001G::setupBIOZ
void setupBIOZ(uint8_t speed=0, uint8_t gain=1, uint8_t ahpf=1, uint8_t dlpf=1, uint8_t dhpf=0, uint16_t frequency=40000, uint16_t current=8000, float phase=0.0f, bool leadbias=true, bool leadsoffdetect=false, bool fourleads=false)
Configure a ready-to-use BIOZ profile.
Definition: max30001g.cpp:602
MAX30001G::readECG
float readECG(bool reportRaw)
Read one ECG FIFO sample.
Definition: max30001g_readdata.cpp:116
MAX30001G::printConfig
void printConfig(void)
Definition: max30001g_regs.cpp:70
MAX30001G::setInterruptEventCallback
bool setInterruptEventCallback(InterruptEvent event, InterruptCallback cb, void *context=nullptr)
Register callback for one specific interrupt event.
Definition: max30001g_interrupt.cpp:266
MAX30001G::setLeadsOnDetection
void setLeadsOnDetection(bool enable)
Enable/disable ultra-low-power lead-on detection.
Definition: max30001g_configure_leads.cpp:7
MAX30001G::MAX30001G
MAX30001G(uint8_t csPin, int intPin1=-1, int intPin2=-1)
Construct a MAX30001G device instance.
Definition: max30001g.cpp:90
MAX30001G::setInterrupt2
bool setInterrupt2(bool ecg, bool bioz, bool rtor, bool leadon, bool leadoff, bool bioz_fourwire=false)
Configure interrupt line INT2 event enables.
Definition: max30001g.h:539
MAX30001G::setBIOZModulationFrequencybyIndex
void setBIOZModulationFrequencybyIndex(uint8_t frequency_selector)
Set BIOZ modulation frequency by FCGEN index.
Definition: max30001g_configure_bioz.cpp:278
MAX30001G::setBIOZgain
void setBIOZgain(uint8_t gain, bool lowNoise)
Set BIOZ gain and front-end power/noise mode.
Definition: max30001g_configure_bioz.cpp:212
MAX30001G::setTestSignal
void setTestSignal(bool enableECGCalSignal, bool enableBIOZCalSignal, bool unipolar, bool cal_vmag, uint8_t freq, uint8_t dutycycle)
Configure calibration voltage source and waveform settings.
Definition: max30001g_calibration.cpp:96
MAX30001G::setupECG
void setupECG(uint8_t speed=1, uint8_t gain=2, bool threeleads=true)
Configure a ready-to-use ECG profile.
Definition: max30001g.cpp:371
MAX30001G::servicePendingInterrupts
bool servicePendingInterrupts(void)
Service interrupts only when ISR software flags indicate pending work.
Definition: max30001g_interrupt.cpp:154
MAX30001G::handleBIOZFifoInterrupt
void handleBIOZFifoInterrupt(bool reportRaw=false)
Convenience callback handler: read BIOZ FIFO.
Definition: max30001g_interrupt.cpp:342
MAX30001G::end
void end(void)
Definition: max30001g.cpp:334
MAX30001G::stopECGManualRecovery
void stopECGManualRecovery(void)
Definition: max30001g_configure_ecg.cpp:268
MAX30001G::readAllRegisters
void readAllRegisters(void)
Definition: max30001g_regs.cpp:10
MAX30001G::setBIOZSamplingRate
void setBIOZSamplingRate(uint8_t speed_select)
Set BIOZ sample-rate selector.
Definition: max30001g_configure_bioz.cpp:187
MAX30001G::setDefaultNoTestSignal
void setDefaultNoTestSignal(void)
Disable ECG/BIOZ voltage calibration source routing.
Definition: max30001g_calibration.cpp:24
MAX30001G::setDefaultBIOZTestImpedance
void setDefaultBIOZTestImpedance(void)
Apply default internal BIOZ test impedance settings.
Definition: max30001g_calibration.cpp:313
MAX30001G::setECGAutoRecovery
void setECGAutoRecovery(int threshold_voltage)
Enable automatic ECG fast-recovery mode.
Definition: max30001g_configure_ecg.cpp:206
MAX30001G::setDefaultNoBIOZTestImpedance
void setDefaultNoBIOZTestImpedance(void)
Disable internal BIOZ test impedance path.
Definition: max30001g_calibration.cpp:302
MAX30001G::setBIOZmodulation
void setBIOZmodulation(uint8_t mode)
Set BIOZ current-generator modulation mode.
Definition: max30001g_configure_bioz.cpp:606
MAX30001G::readECG_FIFO
void readECG_FIFO(bool reportRaw)
Burst-read ECG FIFO samples.
Definition: max30001g_readdata.cpp:179
MAX30001G::printStatus
void printStatus(void)
Definition: max30001g_regs.cpp:118
MAX30001G::setupBIOZExternalImpedanceCalibration
void setupBIOZExternalImpedanceCalibration(uint16_t frequency=40000, float phase=0.0f)
Configure external impedance calibration path.
Definition: max30001g.cpp:1133
MAX30001G::printAllRegisters
void printAllRegisters(void)
Definition: max30001g_regs.cpp:75
MAX30001G::setupBIOZImpedanceCalibration
void setupBIOZImpedanceCalibration(uint8_t speed=0, uint8_t gain=1, uint8_t ahpf=1, uint8_t dlpf=1, uint8_t dhpf=0, uint16_t frequency=40000, uint16_t current=8000, float phase=0.0f, uint32_t resistance=5000, uint8_t modulation=0, uint8_t modulation_frequency=3)
Configure internal BIOZ impedance calibration/test path.
Definition: max30001g.cpp:884
MAX30001G::setBIOZPhaseOffsetbyPhase
void setBIOZPhaseOffsetbyPhase(float phase_deg)
Set BIOZ demodulation phase by degree request.
Definition: max30001g_configure_bioz.cpp:490
MAX30001G::startECGManualRecovery
details void startECGManualRecovery(void)
Definition: max30001g_configure_ecg.cpp:259
MAX30001G::readAndClearFaults
void readAndClearFaults(void)
Read and clear fault-related status conditions.
Definition: max30001g_interrupt.cpp:258
MAX30001G::setDefaultInterruptClearing
void setDefaultInterruptClearing(void)
Configure default interrupt-clear, clears on RR read, fast recovery read, and sample read.
Definition: max30001g_interrupt.cpp:512
MAX30001G::synch
void synch(void)
Definition: max30001g_system.cpp:34
MAX30001G::restoreConfig
void restoreConfig(void)
Definition: max30001g_regs.cpp:45
MAX30001G::readRTOR
void readRTOR(void)
Read RTOR result and update RR-interval globals/buffer.
Definition: max30001g_readdata.cpp:86
MAX30001G::setBIOZPhaseOffsetbyIndex
void setBIOZPhaseOffsetbyIndex(uint8_t selector)
Set BIOZ demodulation phase by selector.
Definition: max30001g_configure_bioz.cpp:514
MAX30001G::clearAllInterruptCallbacks
void clearAllInterruptCallbacks(void)
Clear all registered interrupt callbacks for this instance.
Definition: max30001g_interrupt.cpp:323
MAX30001G::setECGLeadPolarity
void setECGLeadPolarity(bool inverted, bool open)
Configure ECG polarity and input switch state.
Definition: max30001g_configure_ecg.cpp:158
MAX30001G::setLeadsBias
void setLeadsBias(bool enable, uint8_t resistance)
Configure lead-bias mode and resistance.
Definition: max30001g_configure_leads.cpp:360
MAX30001G::setFMSTR
void setFMSTR(uint8_t fmstr)
Set master clock selector and recompute timing globals.
Definition: max30001g_system.cpp:47
MAX30001G::readBIOZ_FIFO
void readBIOZ_FIFO(bool reportRaw)
Burst-read BIOZ FIFO samples.
Definition: max30001g_readdata.cpp:246
MAX30001G::setDefaultNoRtoR
void setDefaultNoRtoR(void)
Apply default RTOR settings with RTOR disabled.
Definition: max30001g_configure_rtor.cpp:36
MAX30001G::startBIOZScan
void startBIOZScan(void)
Start state-machine style BIOZ scan flow.
Definition: max30001g.cpp:1613
MAX30001G::stop
void stop(void)
Stop active measurement engines.
Definition: max30001g.cpp:268
MAX30001G::InterruptCallback
void(* InterruptCallback)(MAX30001G *device, uint32_t status, void *context)
Definition: max30001g.h:66
MAX30001G::FIFOReset
void FIFOReset(void)
Reset ECG and BIOZ FIFOs. Does not affect data already transferred to RingBuffer.
Definition: max30001g_readdata.cpp:66
MAX30001G::printInfo
void printInfo(void)
Definition: max30001g_regs.cpp:243
MAX30001G::saveConfig
void saveConfig(void)
Definition: max30001g_regs.cpp:28
MAX30001G::healthCheck
HealthCheckResult healthCheck(void)
Run basic health checks and return a summary result.
Definition: max30001g_system.cpp:18
MAX30001G::setBIOZModulationFrequencyByFrequency
void setBIOZModulationFrequencyByFrequency(uint16_t frequency_hz)
Set BIOZ modulation frequency by target Hz.
Definition: max30001g_configure_bioz.cpp:245
MAX30001G::setBIOZTestImpedance
void setBIOZTestImpedance(bool enable, bool useHighResistance, bool enableModulation, uint8_t rnomValue, uint8_t rmodValue, uint8_t modFreq)
Configure BIOZ test impedance and optional modulation.
Definition: max30001g_calibration.cpp:324
MAX30001G::updateRaw
bool updateRaw(void)
Alias for raw-code update cycle.
Definition: max30001g.h:95
MAX30001G::start
void start(void)
Start measurement engines according to the most recent setup profile.
Definition: max30001g.cpp:233
MAX30001G::swReset
void swReset(void)
Definition: max30001g_system.cpp:41
MAX30001G::update
bool update(bool reportRaw=false)
Service pending IRQ work and drain enabled FIFOs.
Definition: max30001g.cpp:285
MAX30001G::clearInterruptEventCallback
void clearInterruptEventCallback(InterruptEvent event)
Clear callback for one interrupt event.
Definition: max30001g_interrupt.cpp:294
MAX30001G::setBIOZCurrentMonitor
void setBIOZCurrentMonitor(bool enable)
Enable/disable BIOZ current monitor.
Definition: max30001g_configure_bioz.cpp:640
MAX30001G::InterruptEvent
InterruptEvent
Definition: max30001g.h:50
MAX30001G::IRQ_BIOZ_UNDER
@ IRQ_BIOZ_UNDER
Definition: max30001g.h:58
MAX30001G::IRQ_ECG_OVF
@ IRQ_ECG_OVF
Definition: max30001g.h:52
MAX30001G::IRQ_BIOZ_CGMON
@ IRQ_BIOZ_CGMON
Definition: max30001g.h:59
MAX30001G::IRQ_ECG_LEADOFF
@ IRQ_ECG_LEADOFF
Definition: max30001g.h:54
MAX30001G::IRQ_ECG_FAST
@ IRQ_ECG_FAST
Definition: max30001g.h:53
MAX30001G::IRQ_ECG_FIFO
@ IRQ_ECG_FIFO
Definition: max30001g.h:51
MAX30001G::IRQ_RTOR
@ IRQ_RTOR
Definition: max30001g.h:61
MAX30001G::IRQ_PLL_UNLOCK
@ IRQ_PLL_UNLOCK
Definition: max30001g.h:62
MAX30001G::IRQ_BIOZ_OVF
@ IRQ_BIOZ_OVF
Definition: max30001g.h:56
MAX30001G::IRQ_EVENT_COUNT
@ IRQ_EVENT_COUNT
Definition: max30001g.h:63
MAX30001G::IRQ_BIOZ_OVER
@ IRQ_BIOZ_OVER
Definition: max30001g.h:57
MAX30001G::IRQ_BIOZ_FIFO
@ IRQ_BIOZ_FIFO
Definition: max30001g.h:55
MAX30001G::IRQ_LEADS_ON
@ IRQ_LEADS_ON
Definition: max30001g.h:60
SPI_SETTINGS
SPISettings SPI_SETTINGS
max30001g_defs.h
MAX30001_BIOZ_NUM_FREQUENCIES
#define MAX30001_BIOZ_NUM_FREQUENCIES
Definition: max30001g_defs.h:11
MAX30001_EN_INT2
#define MAX30001_EN_INT2
Definition: max30001g_defs.h:20
MAX30001_BIOZ_NUM_PHASES
#define MAX30001_BIOZ_NUM_PHASES
Definition: max30001g_defs.h:12
MAX30001_EN_INT1
#define MAX30001_EN_INT1
Definition: max30001g_defs.h:19
en_int2
max30001_en_int_reg_t en_int2
Definition: max30001g_globals.cpp:82
fmstr
float fmstr
Definition: max30001g_globals.cpp:55
status
max30001_status_reg_t status
Definition: max30001g_globals.cpp:80
en_int1
max30001_en_int_reg_t en_int1
Definition: max30001g_globals.cpp:81
max30001g_globals.h
max30001g_regs_typedefs.h
max30001g_typedefs.h
BIOZScanConfig
BIOZScanConfig configuration structure fields:
Definition: max30001g_typedefs.h:63
ConfigSnapshot
ConfigSnapshot structure for storing/restoring MAX30001G register configurations.
Definition: max30001g_typedefs.h:103
HealthCheckResult
HealthCheckResult structure for storing health check results.
Definition: max30001g_typedefs.h:39
ImpedanceModel
ImpedanceModel structure for storing impedance measurement results.
Definition: max30001g_typedefs.h:16
max30001_en_int_reg_t
EN_INT (0x02) and (0x03) page 43 we can attach two interrupt lines to functions of the MAX30001 multi...
Definition: max30001g_regs_typedefs.h:59