Darien Figueroa / Mbed OS Final_Program

Dependencies:   USBDevice

Committer:
darienf
Date:
Sat Apr 10 03:05:42 2021 +0000
Revision:
3:36de8b9e4b1a
Parent:
HSP/Test/Test_MAX30001.cpp@0:832122ce6748
ayoooo

Who changed what in which revision?

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