Mode1 Optical Validation

Dependencies:   max32630fthr

Committer:
phonemacro
Date:
Thu Jun 17 21:28:43 2021 +0000
Revision:
22:f6b366c3b954
Parent:
21:67d58af1ec56
Child:
23:e7ecf1416965
Updated back to optimized read fifo for maxm86146

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phonemacro 0:6f65cae31c54 1 /*******************************************************************************
phonemacro 9:12720bbacfe2 2 * Copyright (C) 2021 Maxim Integrated Products, Inc., All Rights Reserved.
phonemacro 0:6f65cae31c54 3 *
phonemacro 0:6f65cae31c54 4 * Permission is hereby granted, free of charge, to any person obtaining a
phonemacro 0:6f65cae31c54 5 * copy of this software and associated documentation files (the "Software"),
phonemacro 0:6f65cae31c54 6 * to deal in the Software without restriction, including without limitation
phonemacro 0:6f65cae31c54 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
phonemacro 0:6f65cae31c54 8 * and/or sell copies of the Software, and to permit persons to whom the
phonemacro 0:6f65cae31c54 9 * Software is furnished to do so, subject to the following conditions:
phonemacro 0:6f65cae31c54 10 *
phonemacro 0:6f65cae31c54 11 * The above copyright notice and this permission notice shall be included
phonemacro 0:6f65cae31c54 12 * in all copies or substantial portions of the Software.
phonemacro 0:6f65cae31c54 13 *
phonemacro 0:6f65cae31c54 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
phonemacro 0:6f65cae31c54 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
phonemacro 0:6f65cae31c54 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
phonemacro 0:6f65cae31c54 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
phonemacro 0:6f65cae31c54 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
phonemacro 0:6f65cae31c54 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
phonemacro 0:6f65cae31c54 20 * OTHER DEALINGS IN THE SOFTWARE.
phonemacro 0:6f65cae31c54 21 *
phonemacro 0:6f65cae31c54 22 * Except as contained in this notice, the name of Maxim Integrated
phonemacro 0:6f65cae31c54 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
phonemacro 0:6f65cae31c54 24 * Products, Inc. Branding Policy.
phonemacro 0:6f65cae31c54 25 *
phonemacro 0:6f65cae31c54 26 * The mere transfer of this software does not imply any licenses
phonemacro 0:6f65cae31c54 27 * of trade secrets, proprietary technology, copyrights, patents,
phonemacro 0:6f65cae31c54 28 * trademarks, maskwork rights, or any other form of intellectual
phonemacro 0:6f65cae31c54 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
phonemacro 0:6f65cae31c54 30 * ownership rights.
phonemacro 0:6f65cae31c54 31 *******************************************************************************
phonemacro 0:6f65cae31c54 32 */
phonemacro 0:6f65cae31c54 33
phonemacro 0:6f65cae31c54 34 #include "mbed.h"
phonemacro 0:6f65cae31c54 35 #include "platform/mbed_thread.h"
phonemacro 3:da975696b936 36 #include "mbed.h"
phonemacro 4:4f1e9439f048 37 /******************************************************************************
phonemacro 16:ff1122f0624a 38 * https://os.mbed.com/users/phonemacro/code/MAX32664C_Example_Host_Code
phonemacro 16:ff1122f0624a 39 * Tera Term output is set to 115200 baud rate.
phonemacro 20:7fc26287beb7 40 * ver: 210615
phonemacro 16:ff1122f0624a 41 ******************************************************************************/
phonemacro 16:ff1122f0624a 42
phonemacro 16:ff1122f0624a 43 /******************************************************************************
phonemacro 4:4f1e9439f048 44 * Warning, if using the either
phonemacro 4:4f1e9439f048 45 * MAX32630FTHR+MAXM86161_ADPTER_REVB+MAXM86146EVSYS sensor brd or
phonemacro 4:4f1e9439f048 46 * MAX32630FTHR+MAXM86161_ADPTER_REVB+MAXM86161EVSYS sensor brd,
phonemacro 4:4f1e9439f048 47 * The VLED is connected to USB power which is noisy. The VLED should be
phonemacro 4:4f1e9439f048 48 * connected to a regulated power supply if you are testing accuracy.
phonemacro 4:4f1e9439f048 49 *******************************************************************************
phonemacro 4:4f1e9439f048 50 */
phonemacro 5:7f5a012747a5 51
phonemacro 6:e1b7190d6cb5 52 /*****************************************************************************/
phonemacro 6:e1b7190d6cb5 53 // define one and only one of the following three platforms
phonemacro 21:67d58af1ec56 54 #define MAXM86146_CFG 1 // tested on MAXM86146EVSYS_sensorBrd+MAXM86161_ADAPTER_REVB+MAX32630FTHR 33.13.12
phonemacro 21:67d58af1ec56 55 //#define MAXREFDES103_CFG // not tested
phonemacro 21:67d58af1ec56 56 //#define MAXM86161_CFG 1 // tested on MAXM86161+MAX32630FTHR v32.9.22, 32.13.12
phonemacro 6:e1b7190d6cb5 57 /*****************************************************************************/
phonemacro 22:f6b366c3b954 58 #if defined(MAXM86161_CFG) //|| defined(MAXM86146_CFG) // don't need 3.3V for MAXM86146EVSYS_sensorBrd+MAXM86161_ADAPTER_REVB+MAX32630FTHR
phonemacro 17:0d6e99a0fd8d 59 #include "max32630fthr.h"
phonemacro 17:0d6e99a0fd8d 60 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); // Enable J1-pin2, 3.3V and set GPIO to 3.3v
phonemacro 21:67d58af1ec56 61 #endif
phonemacro 14:c8cc6d7fd5f9 62 //#define RAW // define this if you only AFE+accel data, no algo
phonemacro 14:c8cc6d7fd5f9 63 #define ALGO_ONLY 1 // define this if you only want algo data, comment out if you want raw sensor+algo data
phonemacro 12:17a0bf823462 64 //#define EXTENDED_ALGO 1 // define this if you want the extended algo format
phonemacro 13:1baccc6275a7 65 //#define AGC 1 // define this for AGC, otherwise the default is AEC
phonemacro 6:e1b7190d6cb5 66
phonemacro 6:e1b7190d6cb5 67 #ifdef MAXREFDES103_CFG
phonemacro 5:7f5a012747a5 68 #include "MAX20303.h"
phonemacro 6:e1b7190d6cb5 69 I2C sh_i2c_pmic(P5_7, P6_0);
phonemacro 5:7f5a012747a5 70 #endif
phonemacro 5:7f5a012747a5 71
phonemacro 2:563d90a111b3 72 #ifdef MAXM86146_CFG
phonemacro 0:6f65cae31c54 73 #define PPG_SZ 36 //maxm86146
phonemacro 0:6f65cae31c54 74 #else
phonemacro 0:6f65cae31c54 75 #define PPG_SZ 18 //maxm86161, max86141
phonemacro 0:6f65cae31c54 76 #endif
phonemacro 0:6f65cae31c54 77 #define ACCEL_SZ 6 // accel
phonemacro 0:6f65cae31c54 78 #define SENSOR_SZ (PPG_SZ+ACCEL_SZ)
phonemacro 18:f4c95b1c0efc 79
phonemacro 21:67d58af1ec56 80 //#define old_msbl 1 // 3x.12.0 or earlier
phonemacro 18:f4c95b1c0efc 81 #ifdef old_msbl
phonemacro 18:f4c95b1c0efc 82 #ifdef EXTENDED_ALGO
phonemacro 18:f4c95b1c0efc 83 #define ALGO_SZ 52 // 52 bytes is the extended algo size for 3x.12.0
phonemacro 18:f4c95b1c0efc 84 #else
phonemacro 18:f4c95b1c0efc 85 #define ALGO_SZ 20 // 20 bytes is the algo normal size for 3x.12.0
phonemacro 18:f4c95b1c0efc 86 #endif
phonemacro 12:17a0bf823462 87 #else
phonemacro 18:f4c95b1c0efc 88 #ifdef EXTENDED_ALGO
phonemacro 21:67d58af1ec56 89 #define ALGO_SZ 56 // 56 bytes is the extended algo size for 3x.13.x+
phonemacro 18:f4c95b1c0efc 90 #else
phonemacro 21:67d58af1ec56 91 #define ALGO_SZ 24 // 24 bytes is the algo normal size for 3x.13.x+
phonemacro 18:f4c95b1c0efc 92 #endif
phonemacro 12:17a0bf823462 93 #endif
phonemacro 18:f4c95b1c0efc 94
phonemacro 0:6f65cae31c54 95 #ifdef ALGO_ONLY
phonemacro 0:6f65cae31c54 96 #define TTL_SZ (ALGO_SZ)
phonemacro 0:6f65cae31c54 97 #else
phonemacro 14:c8cc6d7fd5f9 98 #ifdef RAW
phonemacro 14:c8cc6d7fd5f9 99 #define TTL_SZ (PPG_SZ+ACCEL_SZ)
phonemacro 14:c8cc6d7fd5f9 100 #else
phonemacro 14:c8cc6d7fd5f9 101 #define TTL_SZ (PPG_SZ+ACCEL_SZ+ALGO_SZ)
phonemacro 14:c8cc6d7fd5f9 102 #endif
phonemacro 0:6f65cae31c54 103 #endif
phonemacro 0:6f65cae31c54 104
phonemacro 3:da975696b936 105 Serial pc(USBTX, USBRX, 115200);
phonemacro 0:6f65cae31c54 106 DigitalOut rLED(LED1);
phonemacro 0:6f65cae31c54 107 DigitalOut gLED(LED2);
phonemacro 0:6f65cae31c54 108 DigitalOut bLED(LED3);
phonemacro 5:7f5a012747a5 109 /******************************************************************************
phonemacro 5:7f5a012747a5 110 * MAX32630FTHR GPIOs
phonemacro 5:7f5a012747a5 111 ******************************************************************************/
phonemacro 0:6f65cae31c54 112 #define RST_PIN P5_6
phonemacro 0:6f65cae31c54 113 #define MFIO_PIN P5_4
phonemacro 0:6f65cae31c54 114 DigitalOut rst(RST_PIN, PullUp);
phonemacro 0:6f65cae31c54 115 DigitalOut mfio(MFIO_PIN, PullUp);
phonemacro 6:e1b7190d6cb5 116 I2C sh_i2c(P3_4, P3_5);
phonemacro 6:e1b7190d6cb5 117
phonemacro 6:e1b7190d6cb5 118 //#define thread_sleep_for(x) wait_ms(x) // for older versions of mbed
phonemacro 0:6f65cae31c54 119
phonemacro 5:7f5a012747a5 120
phonemacro 6:e1b7190d6cb5 121 const int SH_ADDR = 0xAA;//0x55;
phonemacro 0:6f65cae31c54 122 int32_t Time_to_Read_PPG = 0;
phonemacro 0:6f65cae31c54 123
phonemacro 0:6f65cae31c54 124 #define BLINKING_RATE_MS 1000ms
phonemacro 0:6f65cae31c54 125 void blink_timer(void) {
phonemacro 0:6f65cae31c54 126 gLED = !gLED; /* blink the green LED */
phonemacro 0:6f65cae31c54 127 }
phonemacro 0:6f65cae31c54 128
phonemacro 0:6f65cae31c54 129 void fifo_timer(void) {
phonemacro 0:6f65cae31c54 130 Time_to_Read_PPG = 1;
phonemacro 0:6f65cae31c54 131 }
phonemacro 0:6f65cae31c54 132
phonemacro 14:c8cc6d7fd5f9 133 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 134 // read_sh_fifo
phonemacro 14:c8cc6d7fd5f9 135 /*****************************************************************************/
phonemacro 10:192ea88e964b 136 void read_sh_fifo(void) {
phonemacro 0:6f65cae31c54 137 char cmd[8], i, j, samples;
phonemacro 0:6f65cae31c54 138 char rsp[3000];
phonemacro 0:6f65cae31c54 139 int32_t ppg[12];
phonemacro 5:7f5a012747a5 140 int16_t accel[3];
phonemacro 12:17a0bf823462 141 int32_t status, opmode, hr, hr_conf, ibi, ibi_conf;
phonemacro 12:17a0bf823462 142 #ifdef EXTENDED_ALGO
phonemacro 12:17a0bf823462 143 int32_t walk_stp, run_stp, energy, amr, iadj1_rqt, iadj1, iadj2_rqt, iadj2, iadj3_rqt, iadj3;
phonemacro 12:17a0bf823462 144 int32_t intadj_rqt, intadj, smpladj_rqt, smpladj, rqt_smplave, afestatehr, hr_motion;
phonemacro 12:17a0bf823462 145 #endif
phonemacro 12:17a0bf823462 146 int32_t act, r, spo2, spo2_conf;
phonemacro 4:4f1e9439f048 147 int32_t spo2_compl, spo2_lo, spo2_mo, spo2_lopi, spo2_unrel, spo2_state, ibi_offset, scd;
phonemacro 2:563d90a111b3 148 int32_t scnt = 0;
phonemacro 0:6f65cae31c54 149 int32_t ptr = 0;
phonemacro 0:6f65cae31c54 150 int32_t sptr = 0;
phonemacro 1:da792e46a385 151 mfio = 0; wait_us(300);
phonemacro 0:6f65cae31c54 152 Time_to_Read_PPG = 0;
phonemacro 22:f6b366c3b954 153 #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG)
phonemacro 0:6f65cae31c54 154 // 2.1
phonemacro 4:4f1e9439f048 155 cmd[0] = 0x00; cmd[1] = 0x00;
phonemacro 6:e1b7190d6cb5 156 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 22:f6b366c3b954 157 wait_us(100);
phonemacro 6:e1b7190d6cb5 158 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 3:da975696b936 159 // pc.printf("2.1 Status: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 22:f6b366c3b954 160 #else
phonemacro 22:f6b366c3b954 161 // testd 33.13.12 doesn't need 2.1
phonemacro 0:6f65cae31c54 162 #endif
phonemacro 0:6f65cae31c54 163 // 2.2
phonemacro 4:4f1e9439f048 164 cmd[0] = 0x12; cmd[1] = 0x00;
phonemacro 6:e1b7190d6cb5 165 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 22:f6b366c3b954 166 wait_us(100);
phonemacro 6:e1b7190d6cb5 167 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 3:da975696b936 168 // pc.printf("2.2 Status: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 0:6f65cae31c54 169 samples = rsp[1];
phonemacro 3:da975696b936 170 // pc.printf("num samples %d, (num*ttl)+1 %d\n\r", rsp[1], TTL_SZ*samples+1);
phonemacro 3:da975696b936 171 // pc.printf("num smpls %d \n\r", samples);
phonemacro 0:6f65cae31c54 172 scnt = rsp[1];
phonemacro 0:6f65cae31c54 173 // 2.3
phonemacro 4:4f1e9439f048 174 cmd[0] = 0x12; cmd[1] = 0x01;
phonemacro 6:e1b7190d6cb5 175 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 22:f6b366c3b954 176 wait_us(100);
phonemacro 6:e1b7190d6cb5 177 sh_i2c.read(SH_ADDR, rsp, 1+(TTL_SZ*samples));
phonemacro 22:f6b366c3b954 178 mfio = 1;
phonemacro 21:67d58af1ec56 179
phonemacro 0:6f65cae31c54 180 status = rsp[0];
phonemacro 5:7f5a012747a5 181
phonemacro 0:6f65cae31c54 182 sptr = 1;
phonemacro 0:6f65cae31c54 183 for (i = 0; i < scnt; i++) {
phonemacro 0:6f65cae31c54 184 #ifdef ALGO_ONLY
phonemacro 0:6f65cae31c54 185 ptr = sptr;
phonemacro 0:6f65cae31c54 186 #else
phonemacro 2:563d90a111b3 187 ptr = sptr;
phonemacro 2:563d90a111b3 188 ppg[0] = (rsp[ptr+0] << 16) | (rsp[ptr+1] << 8) | (rsp[ptr+2]);
phonemacro 2:563d90a111b3 189 ppg[1] = (rsp[ptr+3] << 16) | (rsp[ptr+4] << 8) | (rsp[ptr+5]);
phonemacro 2:563d90a111b3 190 ppg[2] = (rsp[ptr+6] << 16) | (rsp[ptr+7] << 8) | (rsp[ptr+8]);
phonemacro 3:da975696b936 191 ppg[3] = (rsp[ptr+9] << 16) | (rsp[ptr+10] << 8) | (rsp[ptr+11]);
phonemacro 4:4f1e9439f048 192 ppg[4] = (rsp[ptr+12] << 16) | (rsp[ptr+13] << 8) | (rsp[ptr+14]);
phonemacro 4:4f1e9439f048 193 ppg[5] = (rsp[ptr+15] << 16) | (rsp[ptr+16] << 8) | (rsp[ptr+17]);
phonemacro 3:da975696b936 194 pc.printf("%d,%d,%d,%d,", ppg[0], ppg[1], ppg[2], ppg[3]);
phonemacro 14:c8cc6d7fd5f9 195 #ifdef MAXM86146_CFG
phonemacro 14:c8cc6d7fd5f9 196 #ifdef RAW
phonemacro 14:c8cc6d7fd5f9 197 pc.printf("%d,%d,", ppg[4], ppg[5]);
phonemacro 14:c8cc6d7fd5f9 198 ppg[6] = (rsp[ptr+18] << 16) | (rsp[ptr+19] << 8) | (rsp[ptr+20]);
phonemacro 14:c8cc6d7fd5f9 199 ppg[7] = (rsp[ptr+21] << 16) | (rsp[ptr+22] << 8) | (rsp[ptr+23]);
phonemacro 14:c8cc6d7fd5f9 200 ppg[8] = (rsp[ptr+24] << 16) | (rsp[ptr+25] << 8) | (rsp[ptr+26]);
phonemacro 14:c8cc6d7fd5f9 201 ppg[9] = (rsp[ptr+27] << 16) | (rsp[ptr+28] << 8) | (rsp[ptr+29]);
phonemacro 14:c8cc6d7fd5f9 202 ppg[10] = (rsp[ptr+30] << 16) | (rsp[ptr+31] << 8) | (rsp[ptr+32]);
phonemacro 14:c8cc6d7fd5f9 203 ppg[11] = (rsp[ptr+33] << 16) | (rsp[ptr+34] << 8) | (rsp[ptr+35]);
phonemacro 14:c8cc6d7fd5f9 204 pc.printf("%d,%d,%d,%d,%d,%d,", ppg[6], ppg[7],ppg[8], ppg[9],ppg[10], ppg[11]);
phonemacro 14:c8cc6d7fd5f9 205 #endif
phonemacro 14:c8cc6d7fd5f9 206 #endif
phonemacro 5:7f5a012747a5 207 accel[0] = (rsp[PPG_SZ+0] << 8) | (rsp[PPG_SZ+1]);
phonemacro 5:7f5a012747a5 208 accel[1] = (rsp[PPG_SZ+2] << 8) | (rsp[PPG_SZ+3]);
phonemacro 5:7f5a012747a5 209 accel[2] = (rsp[PPG_SZ+4] << 8) | (rsp[PPG_SZ+5]);
phonemacro 5:7f5a012747a5 210 pc.printf("%d,%d,%d,", accel[0], accel[1], accel[2]);
phonemacro 5:7f5a012747a5 211
phonemacro 0:6f65cae31c54 212 ptr = sptr + SENSOR_SZ;
phonemacro 0:6f65cae31c54 213 #endif
phonemacro 14:c8cc6d7fd5f9 214 #ifndef RAW
phonemacro 12:17a0bf823462 215 #ifdef EXTENDED_ALGO
phonemacro 3:da975696b936 216 // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ);
phonemacro 0:6f65cae31c54 217 opmode = rsp[ptr];
phonemacro 0:6f65cae31c54 218 hr = (rsp[ptr+1] << 8) + rsp[ptr+2];
phonemacro 0:6f65cae31c54 219 hr_conf = rsp[ptr+3];
phonemacro 12:17a0bf823462 220 ibi = (rsp[ptr+4] << 8) + rsp[ptr+5];
phonemacro 12:17a0bf823462 221
phonemacro 12:17a0bf823462 222 ibi_conf = rsp[ptr+6];
phonemacro 12:17a0bf823462 223 act = rsp[ptr+7];
phonemacro 12:17a0bf823462 224 walk_stp = (rsp[ptr+8] << 24) + (rsp[ptr+9] << 16) + (rsp[ptr+10] << 8) + rsp[ptr+11];
phonemacro 12:17a0bf823462 225 run_stp = (rsp[ptr+12] << 24) + (rsp[ptr+13] << 16) + (rsp[ptr+14] << 8) + rsp[ptr+15];
phonemacro 12:17a0bf823462 226
phonemacro 12:17a0bf823462 227 energy = (rsp[ptr+16] << 24) + (rsp[ptr+17] << 16) + (rsp[ptr+18] << 8) + rsp[ptr+19];
phonemacro 12:17a0bf823462 228 amr = (rsp[ptr+20] << 24) + (rsp[ptr+21] << 16) + (rsp[ptr+22] << 8) + rsp[ptr+23];
phonemacro 12:17a0bf823462 229 iadj1_rqt = rsp[ptr+24];
phonemacro 12:17a0bf823462 230 iadj1 = (rsp[ptr+25] << 8) + rsp[ptr+26];
phonemacro 12:17a0bf823462 231
phonemacro 12:17a0bf823462 232 iadj2_rqt = rsp[ptr+27];
phonemacro 12:17a0bf823462 233 iadj2 = (rsp[ptr+28] << 8) + rsp[ptr+29];
phonemacro 12:17a0bf823462 234 iadj3_rqt = rsp[ptr+30];
phonemacro 12:17a0bf823462 235 iadj3 = (rsp[ptr+31] << 8) + rsp[ptr+32];
phonemacro 12:17a0bf823462 236
phonemacro 12:17a0bf823462 237 intadj_rqt = rsp[ptr+33];
phonemacro 12:17a0bf823462 238 intadj = rsp[ptr+34];
phonemacro 12:17a0bf823462 239 smpladj_rqt = rsp[ptr+35];
phonemacro 12:17a0bf823462 240 smpladj = rsp[ptr+36];
phonemacro 12:17a0bf823462 241
phonemacro 12:17a0bf823462 242 rqt_smplave = rsp[ptr+37];
phonemacro 12:17a0bf823462 243 afestatehr = rsp[ptr+38];
phonemacro 12:17a0bf823462 244 hr_motion = rsp[ptr+39];
phonemacro 12:17a0bf823462 245 scd = rsp[ptr+40];
phonemacro 12:17a0bf823462 246
phonemacro 12:17a0bf823462 247
phonemacro 12:17a0bf823462 248 r = (rsp[ptr+41] << 8) + rsp[ptr+42];
phonemacro 12:17a0bf823462 249 spo2_conf = rsp[ptr+43];
phonemacro 12:17a0bf823462 250
phonemacro 12:17a0bf823462 251 spo2 = (rsp[ptr+44] << 8) + rsp[ptr+45];
phonemacro 12:17a0bf823462 252 spo2_compl = rsp[ptr+46];
phonemacro 12:17a0bf823462 253 spo2_lo = rsp[ptr+47];
phonemacro 12:17a0bf823462 254 spo2_mo = rsp[ptr+48];
phonemacro 12:17a0bf823462 255
phonemacro 12:17a0bf823462 256 spo2_lopi = rsp[ptr+49];
phonemacro 12:17a0bf823462 257 spo2_unrel = rsp[ptr+50];
phonemacro 12:17a0bf823462 258 spo2_state = rsp[ptr+51];
phonemacro 12:17a0bf823462 259
phonemacro 12:17a0bf823462 260 ibi_offset = rsp[ptr+52];
phonemacro 12:17a0bf823462 261
phonemacro 12:17a0bf823462 262 sptr += (TTL_SZ);
phonemacro 12:17a0bf823462 263 #if 1
phonemacro 12:17a0bf823462 264 pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi);
phonemacro 12:17a0bf823462 265 pc.printf("%d,%d,", ibi_conf, act);
phonemacro 12:17a0bf823462 266 pc.printf("%d,%d,%d,", walk_stp, run_stp, energy);
phonemacro 12:17a0bf823462 267 pc.printf("%d,%d,%d,%d,", amr, iadj1_rqt, iadj1, iadj2_rqt);
phonemacro 12:17a0bf823462 268 pc.printf("%d,%d,%d,%d,", iadj2, iadj3_rqt, iadj3, intadj_rqt);
phonemacro 12:17a0bf823462 269 pc.printf("%d,%d,%d,%d,", intadj, smpladj_rqt, smpladj, rqt_smplave);
phonemacro 12:17a0bf823462 270 pc.printf("%d,%d,", afestatehr, hr_motion);
phonemacro 12:17a0bf823462 271 pc.printf("%d,", scd);
phonemacro 12:17a0bf823462 272 pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo);
phonemacro 12:17a0bf823462 273 pc.printf("%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state);
phonemacro 12:17a0bf823462 274 pc.printf("%d,", ibi_offset);
phonemacro 12:17a0bf823462 275 #else
phonemacro 12:17a0bf823462 276 pc.printf("%d,%d,", hr, hr_conf);
phonemacro 12:17a0bf823462 277 pc.printf("%d,%d,", spo2, spo2_conf);
phonemacro 16:ff1122f0624a 278 pc.printf("%d,%d,%d,", spo2_lo, spo2_mo, spo2_lopi);
phonemacro 12:17a0bf823462 279 pc.printf("%d,%d,", spo2_unrel, scd);
phonemacro 12:17a0bf823462 280 #endif
phonemacro 12:17a0bf823462 281 #else // normal algo size
phonemacro 12:17a0bf823462 282 // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ);
phonemacro 12:17a0bf823462 283 opmode = rsp[ptr];
phonemacro 12:17a0bf823462 284 hr = (rsp[ptr+1] << 8) + rsp[ptr+2];
phonemacro 12:17a0bf823462 285 hr_conf = rsp[ptr+3];
phonemacro 12:17a0bf823462 286 ibi = (rsp[ptr+4] << 8) + rsp[ptr+5];
phonemacro 4:4f1e9439f048 287
phonemacro 11:a16b6bf38841 288 ibi_conf = rsp[ptr+6];
phonemacro 3:da975696b936 289 act = rsp[ptr+7];
phonemacro 3:da975696b936 290 r = (rsp[ptr+8] << 8) + rsp[ptr+9];
phonemacro 0:6f65cae31c54 291 spo2_conf = rsp[ptr+10];
phonemacro 4:4f1e9439f048 292
phonemacro 0:6f65cae31c54 293 spo2 = (rsp[ptr+11] << 8) + rsp[ptr+12];
phonemacro 4:4f1e9439f048 294 spo2_compl = rsp[ptr+13];
phonemacro 4:4f1e9439f048 295 spo2_lo = rsp[ptr+14];
phonemacro 4:4f1e9439f048 296 spo2_mo = rsp[ptr+15];
phonemacro 4:4f1e9439f048 297
phonemacro 4:4f1e9439f048 298 spo2_lopi = rsp[ptr+16];
phonemacro 4:4f1e9439f048 299 spo2_unrel = rsp[ptr+17];
phonemacro 4:4f1e9439f048 300 spo2_state = rsp[ptr+18];
phonemacro 2:563d90a111b3 301 scd = rsp[ptr+19];
phonemacro 0:6f65cae31c54 302
phonemacro 4:4f1e9439f048 303 ibi_offset = rsp[ptr+20];
phonemacro 0:6f65cae31c54 304
phonemacro 4:4f1e9439f048 305 sptr += (TTL_SZ);
phonemacro 4:4f1e9439f048 306 #if 0
phonemacro 4:4f1e9439f048 307 pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi);
phonemacro 4:4f1e9439f048 308 pc.printf("%d,%d,%d,%d,", ibi_conf, act, r, spo2_conf);
phonemacro 4:4f1e9439f048 309 pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo);
phonemacro 4:4f1e9439f048 310 pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state, scd);
phonemacro 4:4f1e9439f048 311 pc.printf("%d,", ibi_offset);
phonemacro 4:4f1e9439f048 312 #else
phonemacro 4:4f1e9439f048 313 pc.printf("%d,%d,", hr, hr_conf);
phonemacro 4:4f1e9439f048 314 pc.printf("%d,%d,", spo2, spo2_conf);
phonemacro 4:4f1e9439f048 315 pc.printf("%d,", spo2_lo);
phonemacro 4:4f1e9439f048 316 pc.printf("%d,%d,", spo2_unrel, scd);
phonemacro 4:4f1e9439f048 317 #endif
phonemacro 12:17a0bf823462 318 #endif // end normal algo size
phonemacro 14:c8cc6d7fd5f9 319 #endif // !RAW
phonemacro 4:4f1e9439f048 320
phonemacro 3:da975696b936 321 pc.printf("\n\r");
phonemacro 0:6f65cae31c54 322 }
phonemacro 0:6f65cae31c54 323 }
phonemacro 0:6f65cae31c54 324
phonemacro 6:e1b7190d6cb5 325 #ifdef MAXREFDES103_CFG
phonemacro 14:c8cc6d7fd5f9 326 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 327 // init_max20303_pmic
phonemacro 14:c8cc6d7fd5f9 328 /*****************************************************************************/
phonemacro 6:e1b7190d6cb5 329 void init_max20303_pmic(void) {
phonemacro 5:7f5a012747a5 330 /* Wait for pmic to settle down */
phonemacro 5:7f5a012747a5 331 thread_sleep_for(800);
phonemacro 5:7f5a012747a5 332
phonemacro 5:7f5a012747a5 333 //set_time(1544787300); // Set RTC time to Wed, 28 Oct 2009 11:35:37
phonemacro 6:e1b7190d6cb5 334 MAX20303 max20303(&sh_i2c);
phonemacro 5:7f5a012747a5 335 /*Set LDO1 to 1.8v*/
phonemacro 5:7f5a012747a5 336 max20303.LDO1Config();
phonemacro 5:7f5a012747a5 337
phonemacro 5:7f5a012747a5 338 /*Set LDO2 to 3v*/
phonemacro 5:7f5a012747a5 339 max20303.LDO2Config();
phonemacro 5:7f5a012747a5 340
phonemacro 5:7f5a012747a5 341 //max20303.BoostEnable();
phonemacro 5:7f5a012747a5 342 max20303.BuckBoostEnable();
phonemacro 5:7f5a012747a5 343
phonemacro 5:7f5a012747a5 344 max20303.led0on(0);
phonemacro 5:7f5a012747a5 345 max20303.led1on(0);
phonemacro 5:7f5a012747a5 346 max20303.led2on(0);
phonemacro 5:7f5a012747a5 347
phonemacro 5:7f5a012747a5 348 /* Wait for pmic to settle down */
phonemacro 5:7f5a012747a5 349 thread_sleep_for(200);
phonemacro 6:e1b7190d6cb5 350
phonemacro 5:7f5a012747a5 351 }
phonemacro 6:e1b7190d6cb5 352 #endif // MAXREFDES103_CFG
phonemacro 14:c8cc6d7fd5f9 353
phonemacro 14:c8cc6d7fd5f9 354 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 355 // init_sh_algo
phonemacro 14:c8cc6d7fd5f9 356 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 357 void init_sh_algo(void) {
phonemacro 14:c8cc6d7fd5f9 358 char cmd[8];
phonemacro 0:6f65cae31c54 359 char rsp[256];
phonemacro 10:192ea88e964b 360 // switch to application mode
phonemacro 0:6f65cae31c54 361 rst = 0;
phonemacro 0:6f65cae31c54 362 mfio = 1;
phonemacro 0:6f65cae31c54 363 thread_sleep_for(10);
phonemacro 0:6f65cae31c54 364 rst = 1;
phonemacro 0:6f65cae31c54 365 thread_sleep_for(1500);
phonemacro 10:192ea88e964b 366 #ifdef MAXREFDES103_CFG
phonemacro 10:192ea88e964b 367 init_max20303_pmic();
phonemacro 10:192ea88e964b 368 #endif
phonemacro 21:67d58af1ec56 369 #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG) || defined(MAXM86146_CFG) // 32.13.19+
phonemacro 20:7fc26287beb7 370 thread_sleep_for(250);
phonemacro 20:7fc26287beb7 371 #endif
phonemacro 0:6f65cae31c54 372
phonemacro 1:da792e46a385 373 mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 374
phonemacro 4:4f1e9439f048 375 //read operating mode
phonemacro 4:4f1e9439f048 376 cmd[0] = 0x02; cmd[1] = 0x00;
phonemacro 6:e1b7190d6cb5 377 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 1:da792e46a385 378 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 379 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 6:e1b7190d6cb5 380 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 381 pc.printf("\n\r 0x02 0x00 Status, Read Operating Mode: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 5:7f5a012747a5 382 //1.11 rd ver
phonemacro 4:4f1e9439f048 383 cmd[0] = 0xFF; cmd[1] = 0x03;
phonemacro 6:e1b7190d6cb5 384 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 1:da792e46a385 385 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 386 sh_i2c.read(SH_ADDR, rsp, 4);
phonemacro 1:da792e46a385 387 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 388 pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]);
phonemacro 0:6f65cae31c54 389
phonemacro 17:0d6e99a0fd8d 390 #if 0
phonemacro 17:0d6e99a0fd8d 391 // algo sz
phonemacro 17:0d6e99a0fd8d 392 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x01;
phonemacro 17:0d6e99a0fd8d 393 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 17:0d6e99a0fd8d 394 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 395 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 17:0d6e99a0fd8d 396 mfio = 1; mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 397 pc.printf("algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 17:0d6e99a0fd8d 398
phonemacro 17:0d6e99a0fd8d 399 // algo sz
phonemacro 17:0d6e99a0fd8d 400 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x02;
phonemacro 17:0d6e99a0fd8d 401 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 17:0d6e99a0fd8d 402 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 403 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 17:0d6e99a0fd8d 404 mfio = 1; mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 405 pc.printf("algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 17:0d6e99a0fd8d 406
phonemacro 17:0d6e99a0fd8d 407 // algo sz
phonemacro 17:0d6e99a0fd8d 408 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x03;
phonemacro 17:0d6e99a0fd8d 409 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 17:0d6e99a0fd8d 410 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 411 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 17:0d6e99a0fd8d 412 mfio = 1; mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 413 pc.printf("algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 17:0d6e99a0fd8d 414 #endif
phonemacro 17:0d6e99a0fd8d 415
phonemacro 17:0d6e99a0fd8d 416 #if 0
phonemacro 17:0d6e99a0fd8d 417 // set Perfusion Index threshold to .05 (3x.13.19+)
phonemacro 17:0d6e99a0fd8d 418 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x1D; cmd[3] = 50;
phonemacro 16:ff1122f0624a 419 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 16:ff1122f0624a 420 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 16:ff1122f0624a 421 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 16:ff1122f0624a 422 mfio = 1; mfio = 0; wait_us(300);
phonemacro 16:ff1122f0624a 423 pc.printf("pi set to 0x19 : %x \n\r", rsp[0]);
phonemacro 17:0d6e99a0fd8d 424 #endif
phonemacro 16:ff1122f0624a 425
phonemacro 0:6f65cae31c54 426 // 1.3 sensor and algo data
phonemacro 4:4f1e9439f048 427 cmd[0] = 0x10; cmd[1] = 0x00;
phonemacro 2:563d90a111b3 428 #ifdef ALGO_ONLY
phonemacro 0:6f65cae31c54 429 cmd[2] = 0x02; // algo data
phonemacro 4:4f1e9439f048 430 pc.printf("algo only \n\r");
phonemacro 2:563d90a111b3 431 #else
phonemacro 2:563d90a111b3 432 cmd[2] = 0x03; // sensor + algo data
phonemacro 4:4f1e9439f048 433 pc.printf("sens+algo \n\r");
phonemacro 2:563d90a111b3 434 #endif
phonemacro 6:e1b7190d6cb5 435 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 1:da792e46a385 436 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 437 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 438 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 439 pc.printf("1.3 Status: %x\n\r", rsp[0]);
phonemacro 3:da975696b936 440 // 1.7 cont hr, spo2
phonemacro 4:4f1e9439f048 441 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0A; cmd[3] = 0x00;
phonemacro 6:e1b7190d6cb5 442 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 3:da975696b936 443 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 444 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 445 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 446 pc.printf("1.7 Status: %x\n\r", rsp[0]);
phonemacro 4:4f1e9439f048 447 // 1.8 AEC enable (default)
phonemacro 4:4f1e9439f048 448 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0B; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 449 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 1:da792e46a385 450 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 451 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 452 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 453 pc.printf("1.8 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 454 #if AGC
phonemacro 13:1baccc6275a7 455 // AGC1.8 Disable auto PD (default
phonemacro 13:1baccc6275a7 456 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x12; cmd[3] = 0x00;
phonemacro 13:1baccc6275a7 457 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 13:1baccc6275a7 458 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 459 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 13:1baccc6275a7 460 mfio = 1; mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 461 pc.printf("AGC1.8 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 462 // AGC1.9 Disable SCD (default)
phonemacro 13:1baccc6275a7 463 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0C; cmd[3] = 0x00;
phonemacro 13:1baccc6275a7 464 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 13:1baccc6275a7 465 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 466 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 13:1baccc6275a7 467 mfio = 1; mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 468 pc.printf("AGC1.9 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 469 // AGC1.10 Set AGC target PD TO 10uA
phonemacro 13:1baccc6275a7 470 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x11; cmd[3] = 0x00; cmd[3] = 0x64;
phonemacro 13:1baccc6275a7 471 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 13:1baccc6275a7 472 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 473 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 13:1baccc6275a7 474 mfio = 1; mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 475 pc.printf("AGC1.10 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 476 #else
phonemacro 4:4f1e9439f048 477 // 1.9 auto PD (default
phonemacro 4:4f1e9439f048 478 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x12; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 479 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 1:da792e46a385 480 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 481 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 482 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 483 pc.printf("1.9 Status: %x\n\r", rsp[0]);
phonemacro 4:4f1e9439f048 484 // 1.10 SCD (default)
phonemacro 4:4f1e9439f048 485 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0C; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 486 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 4:4f1e9439f048 487 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 488 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 4:4f1e9439f048 489 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 490 pc.printf("1.7 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 491 #endif
phonemacro 3:da975696b936 492 #ifdef MAXM86146_CFG
phonemacro 3:da975696b936 493 //1.20 Sec 4.1 map leds to slots for MAXM86146
phonemacro 4:4f1e9439f048 494 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x13; cmd[4] = 0x56; cmd[5] = 0x00;
phonemacro 6:e1b7190d6cb5 495 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 3:da975696b936 496 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 497 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 498 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 499 pc.printf("map leds to slots %x\n\r", rsp[0]);
phonemacro 3:da975696b936 500 //1.21 map HR inputs to slots
phonemacro 4:4f1e9439f048 501 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x11;
phonemacro 6:e1b7190d6cb5 502 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 3:da975696b936 503 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 504 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 505 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 506 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 3:da975696b936 507 //1.22 map SpO2 inputs to slots
phonemacro 4:4f1e9439f048 508 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x30; cmd[4] = 0x20;
phonemacro 6:e1b7190d6cb5 509 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 3:da975696b936 510 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 511 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 512 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 513 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 3:da975696b936 514 #if 0
phonemacro 2:563d90a111b3 515 //1.20 Sec 4.1 map leds to slots for MAXM86146
phonemacro 4:4f1e9439f048 516 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x15; cmd[4] = 0x60; cmd[5] = 0x00;
phonemacro 6:e1b7190d6cb5 517 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 1:da792e46a385 518 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 519 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 520 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 521 pc.printf("map leds to slots%x\n\r", rsp[0]);
phonemacro 2:563d90a111b3 522 //1.21 map HR inputs to slots
phonemacro 4:4f1e9439f048 523 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x01;
phonemacro 6:e1b7190d6cb5 524 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 1:da792e46a385 525 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 526 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 527 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 528 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 2:563d90a111b3 529 //1.22 map SpO2 inputs to slots
phonemacro 4:4f1e9439f048 530 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x20; cmd[4] = 0x10;
phonemacro 6:e1b7190d6cb5 531 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 1:da792e46a385 532 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 533 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 534 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 535 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 3:da975696b936 536 #endif
phonemacro 3:da975696b936 537 #endif // MAXM86146_CFG
phonemacro 0:6f65cae31c54 538
phonemacro 4:4f1e9439f048 539 // 1.3 Enable HR, SpO2 algo
phonemacro 12:17a0bf823462 540 #ifdef EXTENDED_ALGO
phonemacro 12:17a0bf823462 541 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x02;
phonemacro 12:17a0bf823462 542 #else
phonemacro 4:4f1e9439f048 543 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x01;
phonemacro 12:17a0bf823462 544 #endif
phonemacro 6:e1b7190d6cb5 545 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 0:6f65cae31c54 546 thread_sleep_for(465);
phonemacro 6:e1b7190d6cb5 547 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 548 pc.printf("1.14 status: %x\n\r", rsp[0]);
phonemacro 0:6f65cae31c54 549 mfio = 1;
phonemacro 0:6f65cae31c54 550
phonemacro 4:4f1e9439f048 551 #if 1
phonemacro 4:4f1e9439f048 552 //1.31 rd AFE part id
phonemacro 4:4f1e9439f048 553 cmd[0] = 0x41; cmd[1] = 0x00; cmd[2] = 0xFF;
phonemacro 6:e1b7190d6cb5 554 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 4:4f1e9439f048 555 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 556 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 4:4f1e9439f048 557 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 558 pc.printf("1.31 part id afe %x %x\n\r", rsp[0], rsp[1]);
phonemacro 4:4f1e9439f048 559 //1.32 rd accel who
phonemacro 4:4f1e9439f048 560 cmd[0] = 0x41; cmd[1] = 0x04; cmd[2] = 0x0F;
phonemacro 6:e1b7190d6cb5 561 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 4:4f1e9439f048 562 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 563 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 4:4f1e9439f048 564 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 565 pc.printf("1.32 who accel %x %x\n\r", rsp[0], rsp[1]);
phonemacro 4:4f1e9439f048 566 #endif
phonemacro 10:192ea88e964b 567 }
phonemacro 10:192ea88e964b 568
phonemacro 14:c8cc6d7fd5f9 569 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 570 // init_sh_raw
phonemacro 14:c8cc6d7fd5f9 571 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 572 void init_sh_raw(void) {
phonemacro 14:c8cc6d7fd5f9 573 char cmd[8];
phonemacro 14:c8cc6d7fd5f9 574 char rsp[256];
phonemacro 14:c8cc6d7fd5f9 575 // switch to application mode
phonemacro 14:c8cc6d7fd5f9 576 rst = 0;
phonemacro 14:c8cc6d7fd5f9 577 mfio = 1;
phonemacro 14:c8cc6d7fd5f9 578 thread_sleep_for(10);
phonemacro 14:c8cc6d7fd5f9 579 rst = 1;
phonemacro 14:c8cc6d7fd5f9 580 thread_sleep_for(1500);
phonemacro 14:c8cc6d7fd5f9 581 #ifdef MAXREFDES103_CFG
phonemacro 14:c8cc6d7fd5f9 582 init_max20303_pmic();
phonemacro 14:c8cc6d7fd5f9 583 #endif
phonemacro 14:c8cc6d7fd5f9 584
phonemacro 14:c8cc6d7fd5f9 585 mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 586
phonemacro 14:c8cc6d7fd5f9 587 //read operating mode
phonemacro 14:c8cc6d7fd5f9 588 cmd[0] = 0x02; cmd[1] = 0x00;
phonemacro 14:c8cc6d7fd5f9 589 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 14:c8cc6d7fd5f9 590 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 591 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 14:c8cc6d7fd5f9 592 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 593 pc.printf("\n\r 0x02 0x00 Status, Read Operating Mode: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 14:c8cc6d7fd5f9 594 //1.11 rd ver
phonemacro 14:c8cc6d7fd5f9 595 cmd[0] = 0xFF; cmd[1] = 0x03;
phonemacro 14:c8cc6d7fd5f9 596 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 14:c8cc6d7fd5f9 597 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 598 sh_i2c.read(SH_ADDR, rsp, 4);
phonemacro 14:c8cc6d7fd5f9 599 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 600 pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]);
phonemacro 14:c8cc6d7fd5f9 601
phonemacro 14:c8cc6d7fd5f9 602 // raw1.1 sensor data
phonemacro 14:c8cc6d7fd5f9 603 cmd[0] = 0x10; cmd[1] = 0x00; cmd[2] = 0x01;
phonemacro 14:c8cc6d7fd5f9 604 pc.printf("raw sensor data only \n\r");
phonemacro 14:c8cc6d7fd5f9 605 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 14:c8cc6d7fd5f9 606 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 607 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 608 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 609 pc.printf("raw1.1 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 610 // raw1.2 interrupt threshold
phonemacro 14:c8cc6d7fd5f9 611 cmd[0] = 0x10; cmd[1] = 0x01; cmd[2] = 0x01;
phonemacro 14:c8cc6d7fd5f9 612 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 14:c8cc6d7fd5f9 613 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 614 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 615 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 616 pc.printf("raw1.2 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 617 // raw1.3 enable sh accel
phonemacro 14:c8cc6d7fd5f9 618 cmd[0] = 0x44; cmd[1] = 0x04; cmd[2] = 0x01; cmd[3] = 0x00;
phonemacro 14:c8cc6d7fd5f9 619 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 620 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 621 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 622 mfio = 1; thread_sleep_for(20); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 623 pc.printf("raw1.3 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 624 // raw1.4 enable AFE
phonemacro 14:c8cc6d7fd5f9 625 cmd[0] = 0x44; cmd[1] = 0x00; cmd[2] = 0x01; cmd[3] = 0x00;
phonemacro 14:c8cc6d7fd5f9 626 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 627 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 628 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 629 mfio = 1; thread_sleep_for(250); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 630 pc.printf("raw1.4 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 631 // raw1.5 sample rate 100 Hz, ave 1
phonemacro 14:c8cc6d7fd5f9 632 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x18; // set AFE reg 0x12 to 100 Hz
phonemacro 14:c8cc6d7fd5f9 633 // cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x20; // set AFE reg 0x12 to 200 Hz
phonemacro 14:c8cc6d7fd5f9 634 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 635 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 636 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 637 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 638 pc.printf("raw1.5 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 639 // raw1.6 LED1 current
phonemacro 14:c8cc6d7fd5f9 640 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x23; cmd[3] = 0x7F;
phonemacro 14:c8cc6d7fd5f9 641 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 642 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 643 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 644 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 645 pc.printf("raw1.6 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 646 #ifndef MAXM86146_CFG
phonemacro 14:c8cc6d7fd5f9 647 // raw1.7 LED2 current
phonemacro 14:c8cc6d7fd5f9 648 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x24; cmd[3] = 0x7F;
phonemacro 14:c8cc6d7fd5f9 649 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 650 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 651 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 652 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 653 pc.printf("raw1.7 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 654 #endif
phonemacro 14:c8cc6d7fd5f9 655 // raw1.8 LED3 current
phonemacro 14:c8cc6d7fd5f9 656 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x25; cmd[3] = 0x7F;
phonemacro 14:c8cc6d7fd5f9 657 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 658 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 659 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 660 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 661 pc.printf("raw1.8 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 662 #ifdef MAXM86146_CFG
phonemacro 14:c8cc6d7fd5f9 663 // LED5 current
phonemacro 14:c8cc6d7fd5f9 664 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x27; cmd[3] = 0x7F;
phonemacro 14:c8cc6d7fd5f9 665 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 666 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 667 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 668 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 669 pc.printf("led5 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 670 // LED6 current
phonemacro 14:c8cc6d7fd5f9 671 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x27; cmd[3] = 0x7F;
phonemacro 14:c8cc6d7fd5f9 672 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 673 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 674 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 675 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 676 pc.printf("led6 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 677
phonemacro 14:c8cc6d7fd5f9 678 // Set Seq cntrl1 LED2, LED1
phonemacro 14:c8cc6d7fd5f9 679 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x20; cmd[3] = 0x21;
phonemacro 14:c8cc6d7fd5f9 680 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 681 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 682 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 683 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 684 pc.printf("Seq cntrl1 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 685 // Set Seq cntrl2 LED4, LED3
phonemacro 14:c8cc6d7fd5f9 686 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x21; cmd[3] = 0xA3;
phonemacro 14:c8cc6d7fd5f9 687 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 688 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 689 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 690 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 691 pc.printf("Seq cntrl2 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 692 // Set Seq cntrl3 LED6, LED5
phonemacro 14:c8cc6d7fd5f9 693 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x22; cmd[3] = 0x21;
phonemacro 14:c8cc6d7fd5f9 694 // cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x22; cmd[3] = 0x99; // Ambient
phonemacro 14:c8cc6d7fd5f9 695 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 696 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 697 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 698 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 699 pc.printf("Seq cntrl3 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 700
phonemacro 14:c8cc6d7fd5f9 701 #endif
phonemacro 14:c8cc6d7fd5f9 702 }
phonemacro 14:c8cc6d7fd5f9 703
phonemacro 14:c8cc6d7fd5f9 704 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 705 // main
phonemacro 14:c8cc6d7fd5f9 706 /*****************************************************************************/
phonemacro 10:192ea88e964b 707 int main()
phonemacro 10:192ea88e964b 708 {
phonemacro 10:192ea88e964b 709 sh_i2c.frequency(400000);
phonemacro 10:192ea88e964b 710 int32_t ledcnt = 0;
phonemacro 10:192ea88e964b 711 rLED = LED_OFF; gLED = LED_ON; bLED = LED_OFF;
phonemacro 10:192ea88e964b 712 Ticker ticker; // calls a callback repeatedly with a timeout
phonemacro 10:192ea88e964b 713 //ticker.attach(callback(&blink_timer), BLINKING_RATE_MS); /* set timer for one second */
phonemacro 14:c8cc6d7fd5f9 714 #ifdef RAW
phonemacro 14:c8cc6d7fd5f9 715 init_sh_raw();
phonemacro 14:c8cc6d7fd5f9 716 #else
phonemacro 14:c8cc6d7fd5f9 717 init_sh_algo();
phonemacro 14:c8cc6d7fd5f9 718 #endif
phonemacro 8:e6ae69cfecbf 719 #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG) || defined(MAXM86146_CFG)
phonemacro 6:e1b7190d6cb5 720 Timer tmr1;
phonemacro 0:6f65cae31c54 721 while (1) {
phonemacro 6:e1b7190d6cb5 722 tmr1.start();
phonemacro 6:e1b7190d6cb5 723 if (tmr1.read_ms() > 40) {
phonemacro 7:23b067817ab8 724 tmr1.reset();
phonemacro 10:192ea88e964b 725 read_sh_fifo();
phonemacro 7:23b067817ab8 726 if ((ledcnt++ % 50) == 0)
phonemacro 6:e1b7190d6cb5 727 gLED = !gLED;
phonemacro 0:6f65cae31c54 728 }
phonemacro 0:6f65cae31c54 729 }
phonemacro 6:e1b7190d6cb5 730 #else
phonemacro 6:e1b7190d6cb5 731 ticker.attach(callback(&fifo_timer), 0.040f);
phonemacro 6:e1b7190d6cb5 732 while (1) {
phonemacro 6:e1b7190d6cb5 733 if (Time_to_Read_PPG) {
phonemacro 10:192ea88e964b 734 read_sh_fifo();
phonemacro 7:23b067817ab8 735 if ((ledcnt++ % 50) == 0)
phonemacro 6:e1b7190d6cb5 736 gLED = !gLED;
phonemacro 6:e1b7190d6cb5 737 }
phonemacro 6:e1b7190d6cb5 738 }
phonemacro 6:e1b7190d6cb5 739 #endif
phonemacro 0:6f65cae31c54 740 }