MAX30001G 1.3.0 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 uint32_t frequency = 40000,
158 uint32_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 uint32_t bioz_frequency = 8000,
196 uint32_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 uint32_t frequency = 40000,
249 uint32_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 uint32_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
283 #if 0
284 // LEGACY CODE
292 void scanBIOZ(uint8_t avg = 2, bool fast = false, bool fourleads = false, bool fullRange = false);
293
319 void scanBIOZ(const BIOZScanConfig& config, bool reuseCurrents = false);
320 #endif
321
326 void startBIOZScan(void);
327
332 void stopBIOZScan(void);
333
338 void stepBIOZScan(void);
339
340 // ---------------------------------------------------------------------------------------
341 // Registers: max30001g_regs.cpp
342 // ---------------------------------------------------------------------------------------
343
344 /* @brief Read all known MAX30001G registers into global register mirrors. */
345 void readAllRegisters(void);
346
347 /* @brief Read INFO register into global mirror. */
348 void readInfo(void);
349
350 /* @brief Read status register(s) and refresh status flags. */
351 void readStatusRegisters(void);
352
353 /* @brief Save current register configuration into internal snapshot. */
354 void saveConfig(void);
355
356 /* @brief Restore register configuration from internal snapshot. */
357 void restoreConfig(void);
358
359 /* @brief Read and print saved/current configuration related registers. */
360 void printConfig(void);
361
362 /* @brief Print all known register mirrors for debugging. */
363 void printAllRegisters(void);
364
365 /* @brief Print focused BIOZ diagnostic register values for scan/calibration debugging. */
366 void printBiozDiagnosticRegisters(const char* context = nullptr);
367
368 /* @brief Print INFO register decode. */
369 void printInfo(void);
370
371 /* @brief Print STATUS register decode. */
372 void printStatus(void);
373
374 // ---------------------------------------------------------------------------------------
375 // System: max30001g_system.h
376 // ---------------------------------------------------------------------------------------
377
378 /* @brief Issue synchronization command to align conversion timing. */
379 void synch(void);
380
381 /* @brief Issue software reset to device. */
382 void swReset(void);
383
392 void setFMSTR(uint8_t fmstr);
393
398 HealthCheckResult healthCheck(void);
399
400 // ---------------------------------------------------------------------------------------
401 // Read Data: max30001g_readdata.cpp
402 // ---------------------------------------------------------------------------------------
403
407 void FIFOReset(void);
408
413 void readECG_FIFO(bool reportRaw);
414
419 void readBIOZ_FIFO(bool reportRaw);
420
426 float readECG(bool reportRaw);
427
431 void readRTOR(void);
432
438 float readBIOZ(bool reportRaw);
439
440 // ---------------------------------------------------------------------------------------
441 // Interrupts: max30001g_interrupt.cpp
442 // ---------------------------------------------------------------------------------------
443
447 void serviceAllInterrupts(void);
448
455 bool servicePendingInterrupts(void);
456
460 void readAndClearFaults(void);
461
467 void clearLatchedStatusFlags(void);
468
480 bool setInterruptEventCallback(InterruptEvent event, InterruptCallback cb, void* context = nullptr);
481
489 bool setInterruptAggregateCallback(InterruptCallback cb, void* context = nullptr, uint32_t statusMask = 0x00FFFFFFUL);
490
496 void clearInterruptEventCallback(InterruptEvent event);
497
501 void clearInterruptAggregateCallback(void);
502
506 void clearAllInterruptCallbacks(void);
507
512 void handleECGFifoInterrupt(bool reportRaw = false);
513
518 void handleBIOZFifoInterrupt(bool reportRaw = false);
519
523 void handleRtoRInterrupt(void);
524
535 bool setInterrupt1(bool ecg, bool bioz, bool rtor, bool leadon, bool leadoff, bool bioz_fourwire = false) {
536 return setInterrupt(MAX30001_EN_INT1, ecg, bioz, rtor, leadon, leadoff, bioz_fourwire);
537 }
538
549 bool setInterrupt2(bool ecg, bool bioz, bool rtor, bool leadon, bool leadoff, bool bioz_fourwire = false) {
550 return setInterrupt(MAX30001_EN_INT2, ecg, bioz, rtor, leadon, leadoff, bioz_fourwire);
551 }
552
556 void setDefaultInterruptClearing(void);
557
563 void setFIFOInterruptThreshold(uint8_t ecg, uint8_t bioz);
564
565 // ---------------------------------------------------------------------------------------
566 // ECG Configuration: max30001g_configure_ecg.cpp
567 // ---------------------------------------------------------------------------------------
568
576 void setECGSamplingRate(uint8_t ECG);
577
595 void setECGfilter(uint8_t lpf, uint8_t hpf);
596
605 void setECGgain(uint8_t gain);
606
612 void setECGLeadPolarity(bool inverted, bool open);
613
618 void setECGAutoRecovery(int threshold_voltage);
619
620 /* @brief Disable ECG fast-recovery mode and return to normal operation. */
621 void setECGNormalRecovery(void);
622
623 /* @brief Enter manual ECG fast-recovery mode. */
624 void startECGManualRecovery(void);
625
626 /* @brief Exit manual ECG fast-recovery mode. */
627 void stopECGManualRecovery(void);
628
629 // ---------------------------------------------------------------------------------------
630 // BIOZ Configuration: max30001g_configure_bioz.cpp
631 // ---------------------------------------------------------------------------------------
632
639 void setBIOZSamplingRate(uint8_t speed_select);
640
650 void setBIOZgain(uint8_t gain, bool lowNoise);
651
668 void setBIOZModulationFrequencyByFrequency(uint32_t frequency_hz);
669
677 void setBIOZModulationFrequencybyIndex(uint8_t frequency_selector);
678
686 void setBIOZmag(uint32_t current_nA);
687
695 void setBIOZPhaseOffsetbyIndex(uint8_t selector);
696
722 void setBIOZPhaseOffsetbyPhase(float phase_deg);
723
732 void setBIOZPhaseOffsetbyPhase(uint32_t frequency_hz, float phase_deg);
733
757 void setBIOZfilter(uint8_t ahpf, uint8_t lpf, uint8_t hpf);
758
768 void setBIOZmodulation(uint8_t mode);
769
774 void setBIOZCurrentMonitor(bool enable);
775
776 // ---------------------------------------------------------------------------------------
777 // Leads Configuration: max30001g_configure_leads.cpp
778 // ---------------------------------------------------------------------------------------
779
786 void setLeadsOnDetection(bool enable);
787
802 void setLeadsOffDetection(bool enable, bool bioz_4, uint8_t electrode_impedance);
803
814 void setLeadsBias(bool enable, uint8_t resistance);
815
816 // ---------------------------------------------------------------------------------------
817 // RtoR Configuration: max30001g_configure_rtor.cpp
818 // ---------------------------------------------------------------------------------------
819
823 void setDefaultRtoR(void);
824
840 void setDefaultNoRtoR(void);
841
860 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);
861
862 // ---------------------------------------------------------------------------------------
863 // Test Signal and Calibration: max30001g_calibration.cpp
864 // ---------------------------------------------------------------------------------------
865
869 void setDefaultNoTestSignal(void);
870
874 void setDefaultECGTestSignal(void);
875
879 void setDefaultBIOZTestSignal(void);
880
884 void setDefaultECGandBIOZTestSignal(void);
885
898 void setTestSignal(
899 bool enableECGCalSignal,
900 bool enableBIOZCalSignal,
901 bool unipolar,
902 bool cal_vmag,
903 uint8_t freq,
904 uint8_t dutycycle
905 );
906
910 void setDefaultBIOZTestImpedance(void);
911
915 void setDefaultNoBIOZTestImpedance(void);
916
979 void setBIOZTestImpedance(
980 bool enable,
981 bool useHighResistance,
982 bool enableModulation,
983 uint8_t rnomValue,
984 uint8_t rmodValue,
985 uint8_t modFreq
986 );
987
988 /******************************************************************************************************/
989 /******************************************************************************************************/
990 /******************************************************************************************************/
991 /******************************************************************************************************/
992 private:
993
994 // ---------------------------------------------------------------------------------------
995 // Register related: max30001g_regs.cpp
996 // ---------------------------------------------------------------------------------------
997
1002 void printEN_INT(max30001_en_int_reg_t en_int);
1003
1004 /* @brief Print EN_INT1 register decode. */
1005 void printEN_INT1(void) { printEN_INT(en_int1); }
1006
1007 /* @brief Print EN_INT2 register decode. */
1008 void printEN_INT2(void) { printEN_INT(en_int2); }
1009
1010 /* @brief Print MNGR_INT register decode. */
1011 void printMNGR_INT(void);
1012
1013 /* @brief Print MNGR_DYN register decode. */
1014 void printMNGR_DYN(void);
1015
1016 /* @brief Print CNFG_GEN register decode. */
1017 void printCNFG_GEN(void);
1018
1019 /* @brief Print CNFG_CAL register decode. */
1020 void printCNFG_CAL(void);
1021
1022 /* @brief Print CNFG_EMUX register decode. */
1023 void printCNFG_EMUX(void);
1024
1025 /* @brief Print CNFG_ECG register decode. */
1026 void printCNFG_ECG(void);
1027
1028 /* @brief Print CNFG_BMUX register decode. */
1029 void printCNFG_BMUX(void);
1030
1031 /* @brief Print CNFG_BIOZ register decode. */
1032 void printCNFG_BIOZ(void);
1033
1034 /* @brief Print CNFG_BIOZ_LC register decode. */
1035 void printCNFG_BIOZ_LC(void);
1036
1037 /* @brief Print CNFG_RTOR1 register decode. */
1038 void printCNFG_RTOR1(void);
1039
1040 /* @brief Print CNFG_RTOR2 register decode. */
1041 void printCNFG_RTOR2(void);
1042
1043 // ---------------------------------------------------------------------------------------
1044 // System: max30001g_system.h
1045 // ---------------------------------------------------------------------------------------
1046
1047 // Read registers and update global variables based on register values
1048
1050 void updateGlobalECG_samplingRate(void);
1051
1053 void updateGlobalBIOZ_samplingRate(void);
1054
1055 /* @brief Update calibration frequency global from current registers. */
1056 void updateGlobalCAL_fcal(void);
1057
1058 /* @brief Update ECG latency global from current timing/filter state. */
1059 void updateGlobalECG_latency(void);
1060
1061 /* @brief Update BIOZ modulation-frequency global from current registers. */
1062 void updateGlobalBIOZ_frequency(void);
1063
1064 /* @brief Update BIOZ test-impedance globals from current registers. */
1065 void updateGlobalBIOZ_test_impedance(void);
1066
1067 /* @brief Update ECG LPF frequency global from current registers. */
1068 void updateGlobalECG_lpf(void);
1069
1070 /* @brief Update BIOZ DLPF frequency global from current registers. */
1071 void updateGlobalBIOZ_dlpf(void);
1072
1073 /* @brief Update RCAL modulation-frequency global from current registers. */
1074 void updateGlobalRCAL_freq(void);
1075
1076 /* @brief Recompute timing-dependent globals from current register state. */
1077 void refreshTimingGlobals(void);
1078
1079 // ---------------------------------------------------------------------------------------
1080 // Read Data: max30001g_readdata.cpp (internal single-sample helpers)
1081 // ---------------------------------------------------------------------------------------
1082
1083 // ---------------------------------------------------------------------------------------
1084 // Interrupts: max30001g_interrupt.cpp
1085 // ---------------------------------------------------------------------------------------
1086
1099 bool setInterrupt(uint8_t interrupt, bool ecg, bool bioz, bool rtor, bool leadon, bool leadoff, bool bioz_fourwire);
1100
1105 void latchStatusFlags(uint32_t statusWord);
1106
1111 uint32_t readStatusAndLatchFlags(void);
1112
1113 // ---------------------------------------------------------------------------------------
1114 // SPI Communication: max30001g_comm.cpp
1115 // ---------------------------------------------------------------------------------------
1121 void writeRegister(uint8_t address, uint32_t data);
1122
1128 uint32_t readRegister24(uint8_t address);
1129
1135 uint32_t readRegister(uint8_t address) { return readRegister24(address); }
1136
1142 uint8_t readRegisterByte(uint8_t address);
1143
1149 uint8_t readRegister8(uint8_t address) { return readRegisterByte(address); };
1150
1157 bool verifyWrite(uint8_t address, uint32_t expectedValue);
1158
1165 bool verifRegister(uint8_t address, uint32_t expectedValue) { return verifyWrite(address, expectedValue); }
1166
1171 bool spiCheck();
1172
1173 // ---------------------------------------------------------------------------------------
1174 // BIOZ: Impedance spectroscopy helper functions
1175 // ---------------------------------------------------------------------------------------
1176
1182 int32_t closestCurrent(int32_t current);
1183
1191 float impedanceCosineModel(float theta, float magnitude, float phase);
1192 float impedanceTriangularModel(float theta, float magnitude, float phase);
1193
1201 ImpedanceModel fitImpedanceCosine(const float* phases, const float* impedances, int num_points);
1202 ImpedanceModel fitImpedanceTriangular(const float* phases, const float* impedances, int num_points);
1203
1204 uint8_t biozScanPhaseCountForFreq(uint8_t freq_idx) const;
1205 uint8_t biozScanPhaseSelectorForStep(uint8_t freq_idx, uint8_t phase_step_idx) const;
1206 uint8_t biozScanSelectAHPF(uint8_t freq_idx) const;
1207 float biozScanRobustMeanFromBuffer(uint8_t outlier_min_samples, float outlier_sigma, bool& hasSamples);
1208
1209 // ---------------------------------------------------------------------------------------
1210 // Device
1211 // ---------------------------------------------------------------------------------------
1212 enum SetupProfile : uint8_t {
1213 PROFILE_NONE = 0,
1214 PROFILE_ECG,
1215 PROFILE_ECG_CAL,
1216 PROFILE_BIOZ,
1217 PROFILE_BIOZ_CAL,
1218 PROFILE_BIOZ_IMP_CAL,
1219 PROFILE_ECG_AND_BIOZ,
1220 PROFILE_BIOZ_SCAN
1221 };
1222
1223 enum BiozScanState : uint8_t {
1224 BIOZ_SCAN_IDLE = 0,
1225 BIOZ_SCAN_INIT,
1226 BIOZ_SCAN_CONFIG_FREQ,
1227 BIOZ_SCAN_CONFIG_CURRENT,
1228 BIOZ_SCAN_CONFIG_PHASE,
1229 BIOZ_SCAN_BEGIN_POINT,
1230 BIOZ_SCAN_DISCARD_POINT,
1231 BIOZ_SCAN_COLLECT_POINT,
1232 BIOZ_SCAN_PROCESS_POINT,
1233 BIOZ_SCAN_NEXT_PHASE,
1234 BIOZ_SCAN_EVALUATE_ATTEMPT,
1235 BIOZ_SCAN_FINALIZE_FREQ,
1236 BIOZ_SCAN_FINISH
1237 };
1238
1239 int _csPin; // chip select for SPI
1240 int _intPin1; // interrupt pin INTB (EN_INT1)
1241 int _intPin2; // interrupt pin INT2B (EN_INT2), optional
1242
1246 static void onAFE_IRQ1(void);
1250 static void onAFE_IRQ2(void);
1251
1252 SetupProfile _profile;
1253 bool _configured;
1254 bool _running;
1255
1256 bool _useECG;
1257 bool _useBIOZ;
1258 bool _useRTOR;
1259
1260 bool _drainECGOnUpdate;
1261 bool _drainBIOZOnUpdate;
1262 bool _readRTOROnUpdate;
1263
1264 bool _applyLeadSettingsOnStart;
1265 bool _leadBiasEnable;
1266 uint8_t _leadBiasResistance;
1267 bool _leadOffEnable;
1268 bool _leadOffBioz4;
1269 uint8_t _leadOffElectrodeImpedance;
1270 bool _leadOnEnable;
1271
1272 ConfigSnapshot _savedConfig;
1273
1274 // BIOZ scan current profile cache (for reuse across scans)
1275 bool _scanCurrentProfileValid;
1276 int32_t _scanCurrentProfile[MAX30001_BIOZ_NUM_FREQUENCIES];
1277 uint8_t _scanProfileFreqStart;
1278 uint8_t _scanProfileFreqEnd;
1279 bool _scanProfileFast;
1280
1281 BIOZScanConfig _scanRuntimeConfig;
1282 bool _scanReuseCurrents;
1283 bool _scanInProgress;
1284 bool _scanCompleted;
1285
1286 BiozScanState _BIOZScanState;
1287 uint8_t _scanFreqIndex;
1288 uint8_t _scanPhaseIndex;
1289 uint8_t _scanAttempt;
1290 uint8_t _scanNumPhaseMeasurements;
1291 uint8_t _scanDiscardSamplesSeen;
1292 uint8_t _scanDiscardSamplesTarget;
1293 uint8_t _scanCollectSamplesTarget;
1294 bool _scanCurrentChangedForAttempt;
1295 uint32_t _scanFifoTimeoutMs;
1296 uint32_t _scanWaitDeadlineMs;
1297
1298 float _scanThresholdMin;
1299 float _scanThresholdMax;
1300 float _scanAdcTarget;
1301
1302 bool _scanSawValid;
1303 bool _scanSawInvalidOrRange;
1304 bool _scanAnyAboveTarget;
1305 bool _scanAnyInTarget;
1306 float _scanMaxAbsRaw;
1307
1308 int32_t _scanCurrent[MAX30001_BIOZ_NUM_FREQUENCIES];
1309 float _scanFrequency[MAX30001_BIOZ_NUM_FREQUENCIES];
1310 float _scanImpedance[MAX30001_BIOZ_NUM_FREQUENCIES][MAX30001_BIOZ_NUM_PHASES];
1311 float _scanPhaseDeg[MAX30001_BIOZ_NUM_FREQUENCIES][MAX30001_BIOZ_NUM_PHASES];
1312 };
1313 // end of MAX30001G_Public_API
1315
1316 #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::setupBIOZImpedanceCalibration
void setupBIOZImpedanceCalibration(uint8_t speed=0, uint8_t gain=1, uint8_t ahpf=1, uint8_t dlpf=1, uint8_t dhpf=0, uint32_t frequency=40000, uint32_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:1005
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:548
MAX30001G::stepBIOZScan
void stepBIOZScan(void)
Advance state-machine style BIOZ scan flow by one step.
Definition: max30001g.cpp:1976
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:315
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:116
MAX30001G::setupBIOZSignalCalibration
void setupBIOZSignalCalibration(uint8_t speed=0, uint8_t gain=1)
Configure BIOZ voltage calibration signal path.
Definition: max30001g.cpp:914
MAX30001G::setBIOZModulationFrequencyByFrequency
void setBIOZModulationFrequencyByFrequency(uint32_t frequency_hz)
Set BIOZ modulation frequency by target Hz.
Definition: max30001g_configure_bioz.cpp:248
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:126
MAX30001G::setBIOZmag
void setBIOZmag(uint32_t current_nA)
Set BIOZ current magnitude.
Definition: max30001g_configure_bioz.cpp:312
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:626
MAX30001G::setupBIOZScan
void setupBIOZScan(uint8_t avg, bool fast, bool fourleads, bool fullRange)
Configure lifecycle-driven BIOZ scan flow.
Definition: max30001g.cpp:1639
MAX30001G::readBIOZ
float readBIOZ(bool reportRaw)
Read one BIOZ FIFO sample.
Definition: max30001g_readdata.cpp:145
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::setupBIOZExternalImpedanceCalibration
void setupBIOZExternalImpedanceCalibration(uint32_t frequency=40000, float phase=0.0f)
Configure external impedance calibration path.
Definition: max30001g.cpp:1254
MAX30001G::enableAFE
void enableAFE(bool ECG, bool BIOZ, bool RtoR)
Enable or disable ECG, BIOZ, and R-to-R engines.
Definition: max30001g.cpp:459
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:535
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::stopBIOZScan
void stopBIOZScan(void)
Stop state-machine style BIOZ scan flow.
Definition: max30001g.cpp:1792
MAX30001G::readECG
float readECG(bool reportRaw)
Read one ECG FIFO sample.
Definition: max30001g_readdata.cpp:118
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:185
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:549
MAX30001G::setBIOZModulationFrequencybyIndex
void setBIOZModulationFrequencybyIndex(uint8_t frequency_selector)
Set BIOZ modulation frequency by FCGEN index.
Definition: max30001g_configure_bioz.cpp:281
MAX30001G::setBIOZgain
void setBIOZgain(uint8_t gain, bool lowNoise)
Set BIOZ gain and front-end power/noise mode.
Definition: max30001g_configure_bioz.cpp:215
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:492
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:435
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:190
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:323
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:312
MAX30001G::setBIOZmodulation
void setBIOZmodulation(uint8_t mode)
Set BIOZ current-generator modulation mode.
Definition: max30001g_configure_bioz.cpp:614
MAX30001G::readECG_FIFO
void readECG_FIFO(bool reportRaw)
Burst-read ECG FIFO samples.
Definition: max30001g_readdata.cpp:181
MAX30001G::printStatus
void printStatus(void)
Definition: max30001g_regs.cpp:138
MAX30001G::printAllRegisters
void printAllRegisters(void)
Definition: max30001g_regs.cpp:75
MAX30001G::setBIOZPhaseOffsetbyPhase
void setBIOZPhaseOffsetbyPhase(float phase_deg)
Set BIOZ demodulation phase by degree request.
Definition: max30001g_configure_bioz.cpp:493
MAX30001G::startECGManualRecovery
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:88
MAX30001G::setBIOZPhaseOffsetbyIndex
void setBIOZPhaseOffsetbyIndex(uint8_t selector)
Set BIOZ demodulation phase by selector.
Definition: max30001g_configure_bioz.cpp:518
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::setupBIOZ
void setupBIOZ(uint8_t speed=0, uint8_t gain=1, uint8_t ahpf=1, uint8_t dlpf=1, uint8_t dhpf=0, uint32_t frequency=40000, uint32_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:723
MAX30001G::readBIOZ_FIFO
void readBIOZ_FIFO(bool reportRaw)
Burst-read BIOZ FIFO samples.
Definition: max30001g_readdata.cpp:248
MAX30001G::setDefaultNoRtoR
void setDefaultNoRtoR(void)
Apply default RTOR settings with RTOR disabled.
Definition: max30001g_configure_rtor.cpp:36
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, uint32_t bioz_frequency=8000, uint32_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:1280
MAX30001G::startBIOZScan
void startBIOZScan(void)
Start state-machine style BIOZ scan flow.
Definition: max30001g.cpp:1778
MAX30001G::stop
void stop(void)
Stop active measurement engines.
Definition: max30001g.cpp:368
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:68
MAX30001G::printInfo
void printInfo(void)
Definition: max30001g_regs.cpp:267
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::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:334
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:333
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:385
MAX30001G::printBiozDiagnosticRegisters
void printBiozDiagnosticRegisters(const char *context=nullptr)
Definition: max30001g_regs.cpp:96
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:648
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:77
ConfigSnapshot
ConfigSnapshot structure for storing/restoring MAX30001G register configurations.
Definition: max30001g_typedefs.h:125
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