Host software for the MAX30001 ECG, PACE, biopotential, bioimpedance, R-to-R peak sensor. Hosted on the MAX32630FTHR.

Dependencies:   SDFileSystem USBDevice max32630fthr

Fork of MAX30001-MAX32630FTHR-ECG-EVKIT by Maxim Integrated

Committer:
Emre.Eken@IST-LT-35101.maxim-ic.internal
Date:
Thu Apr 05 10:53:26 2018 +0300
Revision:
0:8e4630a71eb1
mbed os 5.8.1 compatible

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 1 /*******************************************************************************
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 3 *
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 4 * Permission is hereby granted, free of charge, to any person obtaining a
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 5 * copy of this software and associated documentation files (the "Software"),
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 6 * to deal in the Software without restriction, including without limitation
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 8 * and/or sell copies of the Software, and to permit persons to whom the
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 9 * Software is furnished to do so, subject to the following conditions:
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 10 *
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 11 * The above copyright notice and this permission notice shall be included
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 12 * in all copies or substantial portions of the Software.
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 13 *
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 20 * OTHER DEALINGS IN THE SOFTWARE.
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 21 *
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 22 * Except as contained in this notice, the name of Maxim Integrated
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 24 * Products, Inc. Branding Policy.
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 25 *
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 26 * The mere transfer of this software does not imply any licenses
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 27 * of trade secrets, proprietary technology, copyrights, patents,
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 28 * trademarks, maskwork rights, or any other form of intellectual
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 30 * ownership rights.
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 31 *******************************************************************************
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 32 */
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 33 #include "Test_MAX30001.h"
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 34 #include "Test_Utilities.h"
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 35
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 36 uint32_t testing_max30001 = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 37 uint32_t testing_ecg_flags[4];
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 38
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 39 //******************************************************************************
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 40 void test_MAX30001(void (*outputString)(const char *)) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 41 int totalPass = 1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 42 int pass;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 43 uint32_t foundEcg = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 44 uint32_t foundBioz = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 45 uint32_t foundPace = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 46 uint32_t foundRtoR = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 47 uint32_t id;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 48 char str2[128];
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 49 int partVersion; // 0 = 30004
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 50 // 1 = 30001
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 51 // 2 = 30002
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 52 // 3 = 30003
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 53 Timer timer;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 54 MAX30001 *max30001;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 55 max30001 = Peripherals::max30001();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 56
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 57 // read the id
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 58 max30001->max30001_reg_read(MAX30001::INFO, &id);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 59 // read id twice because it needs to be read twice
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 60 max30001->max30001_reg_read(MAX30001::INFO, &id);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 61 partVersion = id >> 12;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 62 partVersion = partVersion & 0x3;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 63
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 64 // display header
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 65 if (partVersion == 0)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 66 outputString("Testing MAX30004|");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 67 if (partVersion == 1) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 68 outputString("Testing MAX30001|");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 69 outputString("Testing ECG, RtoR, BioZ, PACE|");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 70 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 71 if (partVersion == 2)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 72 outputString("Testing MAX30002|");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 73 if (partVersion == 3) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 74 outputString("Testing MAX30003|");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 75 outputString("Only Testing ECG and RtoR|");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 76 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 77 sprintf(str2, "Device ID = 0x%06X|", id);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 78 outputString(str2);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 79
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 80 // clear testing flags
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 81 testing_ecg_flags[TESTING_ECG_FLAG] = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 82 testing_ecg_flags[TESTING_BIOZ_FLAG] = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 83 testing_ecg_flags[TESTING_PACE_FLAG] = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 84 testing_ecg_flags[TESTING_RTOR_FLAG] = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 85
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 86 // start streams
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 87 testing_max30001 = 1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 88 if (partVersion == 1)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 89 outputString("Start Streaming ECG, RtoR, PACE, BIOZ, CAL enabled, "
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 90 "verifying streams...|");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 91 if (partVersion == 3)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 92 outputString(
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 93 "Start Streaming ECG, RtoR, CAL enabled, verifying streams...|");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 94 // max30001_CAL_InitStart(0b1, 0b1, 0b1, 0b011, 0x7FF, 0b0);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 95 max30001->max30001_CAL_InitStart(0b1, 0b1, 0b1, 0b011, 0x7FF, 0b0);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 96 max30001->max30001_ECG_InitStart(0b1, 0b1, 0b1, 0b0, 0b10, 0b11, 0x1F, 0b00,
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 97 0b00, 0b0, 0b01);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 98 if (partVersion == 1)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 99 max30001->max30001_PACE_InitStart(0b1, 0b0, 0b0, 0b1, 0x0, 0b0, 0b00, 0b0,
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 100 0b0);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 101 if (partVersion == 1)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 102 max30001->max30001_BIOZ_InitStart(0b1, 0b1, 0b1, 0b10, 0b11, 0b00, 7, 0b0,
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 103 0b010, 0b0, 0b10, 0b00, 0b00, 2, 0b0,
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 104 0b111, 0b0000, 0b0000);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 105 max30001->max30001_RtoR_InitStart(0b1, 0b0011, 0b1111, 0b00, 0b0011, 0b000001,
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 106 0b00, 0b000, 0b01);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 107 max30001->max30001_Rbias_FMSTR_Init(0b01, 0b10, 0b1, 0b1, 0b00);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 108 max30001->max30001_synch();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 109
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 110 // look for each stream
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 111 timer.start();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 112 while (1) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 113 if ((foundEcg == 0) && (testing_ecg_flags[TESTING_ECG_FLAG] == 1)) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 114 foundEcg = 1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 115 outputString("ECG Stream: PASS|");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 116 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 117 if ((foundBioz == 0) && (testing_ecg_flags[TESTING_BIOZ_FLAG] == 1)) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 118 foundBioz = 1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 119 outputString("Bioz Stream: PASS|");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 120 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 121 if ((foundPace == 0) && (testing_ecg_flags[TESTING_PACE_FLAG] == 1)) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 122 foundPace = 1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 123 outputString("PACE Stream: PASS|");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 124 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 125 if ((foundRtoR == 0) && (testing_ecg_flags[TESTING_RTOR_FLAG] == 1)) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 126 foundRtoR = 1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 127 outputString("RtoR Stream: PASS|");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 128 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 129 if ((foundEcg == 1) && (foundBioz == 1) && (foundPace == 1) &&
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 130 (foundRtoR == 1) && (partVersion == 1)) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 131 break;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 132 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 133 if ((foundEcg == 1) && (foundRtoR == 1) && (partVersion == 3)) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 134 break;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 135 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 136 if (timer.read() >= TESTING_MAX30001_TIMEOUT_SECONDS) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 137 break;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 138 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 139 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 140 timer.stop();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 141 if (foundEcg == 0) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 142 outputString("ECG Stream: FAIL|");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 143 totalPass &= pass;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 144 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 145 if ((foundBioz == 0) && (partVersion == 1)) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 146 outputString("Bioz Stream: FAIL|");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 147 totalPass &= pass;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 148 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 149 if ((foundPace == 0) && (partVersion == 1)) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 150 outputString("PACE Stream: FAIL|");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 151 totalPass &= pass;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 152 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 153 if (foundRtoR == 0) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 154 outputString("RtoR Stream: FAIL|");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 155 totalPass &= pass;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 156 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 157
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 158 // stop all streams
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 159 max30001->max30001_Stop_ECG();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 160 if (partVersion == 1)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 161 max30001->max30001_Stop_PACE();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 162 if (partVersion == 1)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 163 max30001->max30001_Stop_BIOZ();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 164 max30001->max30001_Stop_RtoR();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 165 testing_max30001 = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 166 // final results
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 167 outputString("Result: ");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 168 _printPassFail(totalPass, 0, outputString);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 169 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 170