Mode1 Optical Validation

Dependencies:   max32630fthr

Committer:
phonemacro
Date:
Fri Mar 26 01:05:49 2021 +0000
Revision:
8:e6ae69cfecbf
Parent:
7:23b067817ab8
Child:
9:12720bbacfe2
Fix fifo reading for MAXM86146

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phonemacro 0:6f65cae31c54 1 /*******************************************************************************
phonemacro 0:6f65cae31c54 2 * Copyright (C) 2018 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 4:4f1e9439f048 38 * Warning, if using the either
phonemacro 4:4f1e9439f048 39 * MAX32630FTHR+MAXM86161_ADPTER_REVB+MAXM86146EVSYS sensor brd or
phonemacro 4:4f1e9439f048 40 * MAX32630FTHR+MAXM86161_ADPTER_REVB+MAXM86161EVSYS sensor brd,
phonemacro 4:4f1e9439f048 41 * The VLED is connected to USB power which is noisy. The VLED should be
phonemacro 4:4f1e9439f048 42 * connected to a regulated power supply if you are testing accuracy.
phonemacro 4:4f1e9439f048 43 *******************************************************************************
phonemacro 4:4f1e9439f048 44 */
phonemacro 4:4f1e9439f048 45 /******************************************************************************
phonemacro 4:4f1e9439f048 46 * Tera Term output is set to 115200 baud rate.
phonemacro 6:e1b7190d6cb5 47 * ver: 210325
phonemacro 5:7f5a012747a5 48 ******************************************************************************/
phonemacro 5:7f5a012747a5 49
phonemacro 6:e1b7190d6cb5 50 /*****************************************************************************/
phonemacro 6:e1b7190d6cb5 51 // define one and only one of the following three platforms
phonemacro 8:e6ae69cfecbf 52 #define MAXM86146_CFG 1 // tested on MAXM86146EVSYS_sensorBrd+MAXM86161_ADAPTER_REVB+MAX32630FTHR
phonemacro 8:e6ae69cfecbf 53 //#define MAXREFDES103_CFG // tested on MAXREFDES103
phonemacro 6:e1b7190d6cb5 54 //#define MAX86161_CFG 1
phonemacro 6:e1b7190d6cb5 55 /*****************************************************************************/
phonemacro 6:e1b7190d6cb5 56
phonemacro 6:e1b7190d6cb5 57 #define ALGO_ONLY 1 // define this if you only want the algo data, comment out if you want raw sensor+algo data
phonemacro 6:e1b7190d6cb5 58
phonemacro 6:e1b7190d6cb5 59
phonemacro 6:e1b7190d6cb5 60 #ifdef MAXREFDES103_CFG
phonemacro 5:7f5a012747a5 61 #include "MAX20303.h"
phonemacro 6:e1b7190d6cb5 62 I2C sh_i2c_pmic(P5_7, P6_0);
phonemacro 5:7f5a012747a5 63 #endif
phonemacro 5:7f5a012747a5 64
phonemacro 2:563d90a111b3 65 #ifdef MAXM86146_CFG
phonemacro 0:6f65cae31c54 66 #define PPG_SZ 36 //maxm86146
phonemacro 0:6f65cae31c54 67 #else
phonemacro 0:6f65cae31c54 68 #define PPG_SZ 18 //maxm86161, max86141
phonemacro 0:6f65cae31c54 69 #endif
phonemacro 0:6f65cae31c54 70 #define ACCEL_SZ 6 // accel
phonemacro 0:6f65cae31c54 71 #define SENSOR_SZ (PPG_SZ+ACCEL_SZ)
phonemacro 3:da975696b936 72 //#define ALGO_SZ 20 // 24 bytes is the algo normal size for 3x.12.0
phonemacro 3:da975696b936 73 #define ALGO_SZ 24 // 24 bytes is the algo normal size for 3x.13.x
phonemacro 0:6f65cae31c54 74 #ifdef ALGO_ONLY
phonemacro 0:6f65cae31c54 75 #define TTL_SZ (ALGO_SZ)
phonemacro 0:6f65cae31c54 76 #else
phonemacro 0:6f65cae31c54 77 #define TTL_SZ (PPG_SZ+ACCEL_SZ+ALGO_SZ)
phonemacro 0:6f65cae31c54 78 #endif
phonemacro 0:6f65cae31c54 79
phonemacro 3:da975696b936 80 Serial pc(USBTX, USBRX, 115200);
phonemacro 0:6f65cae31c54 81 DigitalOut rLED(LED1);
phonemacro 0:6f65cae31c54 82 DigitalOut gLED(LED2);
phonemacro 0:6f65cae31c54 83 DigitalOut bLED(LED3);
phonemacro 5:7f5a012747a5 84 /******************************************************************************
phonemacro 5:7f5a012747a5 85 * MAX32630FTHR GPIOs
phonemacro 5:7f5a012747a5 86 ******************************************************************************/
phonemacro 0:6f65cae31c54 87 #define RST_PIN P5_6
phonemacro 0:6f65cae31c54 88 #define MFIO_PIN P5_4
phonemacro 0:6f65cae31c54 89 DigitalOut rst(RST_PIN, PullUp);
phonemacro 0:6f65cae31c54 90 DigitalOut mfio(MFIO_PIN, PullUp);
phonemacro 6:e1b7190d6cb5 91 I2C sh_i2c(P3_4, P3_5);
phonemacro 6:e1b7190d6cb5 92
phonemacro 6:e1b7190d6cb5 93 //#define thread_sleep_for(x) wait_ms(x) // for older versions of mbed
phonemacro 0:6f65cae31c54 94
phonemacro 5:7f5a012747a5 95
phonemacro 6:e1b7190d6cb5 96 const int SH_ADDR = 0xAA;//0x55;
phonemacro 0:6f65cae31c54 97 int32_t Time_to_Read_PPG = 0;
phonemacro 0:6f65cae31c54 98
phonemacro 0:6f65cae31c54 99 #define BLINKING_RATE_MS 1000ms
phonemacro 0:6f65cae31c54 100 void blink_timer(void) {
phonemacro 0:6f65cae31c54 101 gLED = !gLED; /* blink the green LED */
phonemacro 0:6f65cae31c54 102 }
phonemacro 0:6f65cae31c54 103
phonemacro 0:6f65cae31c54 104 void fifo_timer(void) {
phonemacro 0:6f65cae31c54 105 Time_to_Read_PPG = 1;
phonemacro 0:6f65cae31c54 106 }
phonemacro 0:6f65cae31c54 107
phonemacro 0:6f65cae31c54 108 void read_ppg(void) {
phonemacro 0:6f65cae31c54 109 char cmd[8], i, j, samples;
phonemacro 0:6f65cae31c54 110 char rsp[3000];
phonemacro 0:6f65cae31c54 111 int32_t ppg[12];
phonemacro 5:7f5a012747a5 112 int16_t accel[3];
phonemacro 4:4f1e9439f048 113 int32_t status, opmode, hr, hr_conf, ibi, ibi_conf, act, r, spo2, spo2_conf;
phonemacro 4:4f1e9439f048 114 int32_t spo2_compl, spo2_lo, spo2_mo, spo2_lopi, spo2_unrel, spo2_state, ibi_offset, scd;
phonemacro 2:563d90a111b3 115 int32_t scnt = 0;
phonemacro 0:6f65cae31c54 116 int32_t ptr = 0;
phonemacro 0:6f65cae31c54 117 int32_t sptr = 0;
phonemacro 1:da792e46a385 118 mfio = 0; wait_us(300);
phonemacro 0:6f65cae31c54 119 Time_to_Read_PPG = 0;
phonemacro 0:6f65cae31c54 120 #if 0
phonemacro 0:6f65cae31c54 121 // 2.1
phonemacro 4:4f1e9439f048 122 cmd[0] = 0x00; cmd[1] = 0x00;
phonemacro 6:e1b7190d6cb5 123 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 0:6f65cae31c54 124 wait_us(100);
phonemacro 6:e1b7190d6cb5 125 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 3:da975696b936 126 // pc.printf("2.1 Status: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 0:6f65cae31c54 127 #endif
phonemacro 0:6f65cae31c54 128 // 2.2
phonemacro 4:4f1e9439f048 129 cmd[0] = 0x12; cmd[1] = 0x00;
phonemacro 6:e1b7190d6cb5 130 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 0:6f65cae31c54 131 wait_us(100);
phonemacro 6:e1b7190d6cb5 132 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 3:da975696b936 133 // pc.printf("2.2 Status: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 0:6f65cae31c54 134 samples = rsp[1];
phonemacro 3:da975696b936 135 // pc.printf("num samples %d, (num*ttl)+1 %d\n\r", rsp[1], TTL_SZ*samples+1);
phonemacro 3:da975696b936 136 // pc.printf("num smpls %d \n\r", samples);
phonemacro 0:6f65cae31c54 137 scnt = rsp[1];
phonemacro 0:6f65cae31c54 138 // 2.3
phonemacro 4:4f1e9439f048 139 cmd[0] = 0x12; cmd[1] = 0x01;
phonemacro 6:e1b7190d6cb5 140 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 0:6f65cae31c54 141 wait_us(100);
phonemacro 0:6f65cae31c54 142 // thread_sleep_for(1);
phonemacro 6:e1b7190d6cb5 143 sh_i2c.read(SH_ADDR, rsp, 1+(TTL_SZ*samples));
phonemacro 0:6f65cae31c54 144 status = rsp[0];
phonemacro 5:7f5a012747a5 145
phonemacro 0:6f65cae31c54 146 sptr = 1;
phonemacro 0:6f65cae31c54 147 for (i = 0; i < scnt; i++) {
phonemacro 0:6f65cae31c54 148 #ifdef ALGO_ONLY
phonemacro 0:6f65cae31c54 149 ptr = sptr;
phonemacro 0:6f65cae31c54 150 #else
phonemacro 2:563d90a111b3 151 ptr = sptr;
phonemacro 2:563d90a111b3 152 ppg[0] = (rsp[ptr+0] << 16) | (rsp[ptr+1] << 8) | (rsp[ptr+2]);
phonemacro 2:563d90a111b3 153 ppg[1] = (rsp[ptr+3] << 16) | (rsp[ptr+4] << 8) | (rsp[ptr+5]);
phonemacro 2:563d90a111b3 154 ppg[2] = (rsp[ptr+6] << 16) | (rsp[ptr+7] << 8) | (rsp[ptr+8]);
phonemacro 3:da975696b936 155 ppg[3] = (rsp[ptr+9] << 16) | (rsp[ptr+10] << 8) | (rsp[ptr+11]);
phonemacro 4:4f1e9439f048 156 ppg[4] = (rsp[ptr+12] << 16) | (rsp[ptr+13] << 8) | (rsp[ptr+14]);
phonemacro 4:4f1e9439f048 157 ppg[5] = (rsp[ptr+15] << 16) | (rsp[ptr+16] << 8) | (rsp[ptr+17]);
phonemacro 3:da975696b936 158 pc.printf("%d,%d,%d,%d,", ppg[0], ppg[1], ppg[2], ppg[3]);
phonemacro 4:4f1e9439f048 159 // pc.printf("%d,%d,", ppg[4], ppg[5]);
phonemacro 5:7f5a012747a5 160 accel[0] = (rsp[PPG_SZ+0] << 8) | (rsp[PPG_SZ+1]);
phonemacro 5:7f5a012747a5 161 accel[1] = (rsp[PPG_SZ+2] << 8) | (rsp[PPG_SZ+3]);
phonemacro 5:7f5a012747a5 162 accel[2] = (rsp[PPG_SZ+4] << 8) | (rsp[PPG_SZ+5]);
phonemacro 5:7f5a012747a5 163 pc.printf("%d,%d,%d,", accel[0], accel[1], accel[2]);
phonemacro 5:7f5a012747a5 164
phonemacro 0:6f65cae31c54 165 ptr = sptr + SENSOR_SZ;
phonemacro 0:6f65cae31c54 166 #endif
phonemacro 3:da975696b936 167 // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ);
phonemacro 0:6f65cae31c54 168 opmode = rsp[ptr];
phonemacro 0:6f65cae31c54 169 hr = (rsp[ptr+1] << 8) + rsp[ptr+2];
phonemacro 0:6f65cae31c54 170 hr_conf = rsp[ptr+3];
phonemacro 3:da975696b936 171 ibi = rsp[ptr+4];
phonemacro 4:4f1e9439f048 172
phonemacro 3:da975696b936 173 ibi_conf = (rsp[ptr+5] << 8) + rsp[ptr+6];
phonemacro 3:da975696b936 174 act = rsp[ptr+7];
phonemacro 3:da975696b936 175 r = (rsp[ptr+8] << 8) + rsp[ptr+9];
phonemacro 0:6f65cae31c54 176 spo2_conf = rsp[ptr+10];
phonemacro 4:4f1e9439f048 177
phonemacro 0:6f65cae31c54 178 spo2 = (rsp[ptr+11] << 8) + rsp[ptr+12];
phonemacro 4:4f1e9439f048 179 spo2_compl = rsp[ptr+13];
phonemacro 4:4f1e9439f048 180 spo2_lo = rsp[ptr+14];
phonemacro 4:4f1e9439f048 181 spo2_mo = rsp[ptr+15];
phonemacro 4:4f1e9439f048 182
phonemacro 4:4f1e9439f048 183 spo2_lopi = rsp[ptr+16];
phonemacro 4:4f1e9439f048 184 spo2_unrel = rsp[ptr+17];
phonemacro 4:4f1e9439f048 185 spo2_state = rsp[ptr+18];
phonemacro 2:563d90a111b3 186 scd = rsp[ptr+19];
phonemacro 0:6f65cae31c54 187
phonemacro 4:4f1e9439f048 188 ibi_offset = rsp[ptr+20];
phonemacro 0:6f65cae31c54 189
phonemacro 4:4f1e9439f048 190 sptr += (TTL_SZ);
phonemacro 4:4f1e9439f048 191 #if 0
phonemacro 4:4f1e9439f048 192 pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi);
phonemacro 4:4f1e9439f048 193 pc.printf("%d,%d,%d,%d,", ibi_conf, act, r, spo2_conf);
phonemacro 4:4f1e9439f048 194 pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo);
phonemacro 4:4f1e9439f048 195 pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state, scd);
phonemacro 4:4f1e9439f048 196 pc.printf("%d,", ibi_offset);
phonemacro 4:4f1e9439f048 197 #else
phonemacro 4:4f1e9439f048 198 pc.printf("%d,%d,", hr, hr_conf);
phonemacro 4:4f1e9439f048 199 pc.printf("%d,%d,", spo2, spo2_conf);
phonemacro 4:4f1e9439f048 200 pc.printf("%d,", spo2_lo);
phonemacro 4:4f1e9439f048 201 pc.printf("%d,%d,", spo2_unrel, scd);
phonemacro 4:4f1e9439f048 202 #endif
phonemacro 4:4f1e9439f048 203
phonemacro 4:4f1e9439f048 204
phonemacro 3:da975696b936 205 pc.printf("\n\r");
phonemacro 0:6f65cae31c54 206 }
phonemacro 0:6f65cae31c54 207 mfio = 1;
phonemacro 0:6f65cae31c54 208 }
phonemacro 0:6f65cae31c54 209
phonemacro 6:e1b7190d6cb5 210 #ifdef MAXREFDES103_CFG
phonemacro 6:e1b7190d6cb5 211 void init_max20303_pmic(void) {
phonemacro 5:7f5a012747a5 212 /* Wait for pmic to settle down */
phonemacro 5:7f5a012747a5 213 thread_sleep_for(800);
phonemacro 5:7f5a012747a5 214
phonemacro 5:7f5a012747a5 215 //set_time(1544787300); // Set RTC time to Wed, 28 Oct 2009 11:35:37
phonemacro 6:e1b7190d6cb5 216 MAX20303 max20303(&sh_i2c);
phonemacro 5:7f5a012747a5 217 /*Set LDO1 to 1.8v*/
phonemacro 5:7f5a012747a5 218 max20303.LDO1Config();
phonemacro 5:7f5a012747a5 219
phonemacro 5:7f5a012747a5 220 /*Set LDO2 to 3v*/
phonemacro 5:7f5a012747a5 221 max20303.LDO2Config();
phonemacro 5:7f5a012747a5 222
phonemacro 5:7f5a012747a5 223 //max20303.BoostEnable();
phonemacro 5:7f5a012747a5 224 max20303.BuckBoostEnable();
phonemacro 5:7f5a012747a5 225
phonemacro 5:7f5a012747a5 226 max20303.led0on(0);
phonemacro 5:7f5a012747a5 227 max20303.led1on(0);
phonemacro 5:7f5a012747a5 228 max20303.led2on(0);
phonemacro 5:7f5a012747a5 229
phonemacro 5:7f5a012747a5 230 /* Wait for pmic to settle down */
phonemacro 5:7f5a012747a5 231 thread_sleep_for(200);
phonemacro 6:e1b7190d6cb5 232
phonemacro 5:7f5a012747a5 233 }
phonemacro 6:e1b7190d6cb5 234 #endif // MAXREFDES103_CFG
phonemacro 0:6f65cae31c54 235 int main()
phonemacro 5:7f5a012747a5 236 {
phonemacro 6:e1b7190d6cb5 237 sh_i2c.frequency(400000);
phonemacro 0:6f65cae31c54 238 char cmd[8], i, j;
phonemacro 0:6f65cae31c54 239 char rsp[256];
phonemacro 0:6f65cae31c54 240 int32_t ppg[12];
phonemacro 6:e1b7190d6cb5 241 int32_t ledcnt = 0;
phonemacro 4:4f1e9439f048 242 rLED = LED_OFF; gLED = LED_ON; bLED = LED_OFF;
phonemacro 0:6f65cae31c54 243 Ticker ticker; // calls a callback repeatedly with a timeout
phonemacro 0:6f65cae31c54 244 //ticker.attach(callback(&blink_timer), BLINKING_RATE_MS); /* set timer for one second */
phonemacro 0:6f65cae31c54 245
phonemacro 0:6f65cae31c54 246 // application
phonemacro 0:6f65cae31c54 247 rst = 0;
phonemacro 0:6f65cae31c54 248 mfio = 1;
phonemacro 0:6f65cae31c54 249 thread_sleep_for(10);
phonemacro 0:6f65cae31c54 250 rst = 1;
phonemacro 0:6f65cae31c54 251 thread_sleep_for(1500);
phonemacro 0:6f65cae31c54 252
phonemacro 1:da792e46a385 253 mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 254
phonemacro 6:e1b7190d6cb5 255 #ifdef MAXREFDES103_CFG
phonemacro 6:e1b7190d6cb5 256 init_max20303_pmic();
phonemacro 6:e1b7190d6cb5 257 #endif
phonemacro 4:4f1e9439f048 258 //read operating mode
phonemacro 4:4f1e9439f048 259 cmd[0] = 0x02; cmd[1] = 0x00;
phonemacro 6:e1b7190d6cb5 260 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 1:da792e46a385 261 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 262 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 6:e1b7190d6cb5 263 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 264 pc.printf("\n\r 0x02 0x00 Status, Read Operating Mode: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 5:7f5a012747a5 265 //1.11 rd ver
phonemacro 4:4f1e9439f048 266 cmd[0] = 0xFF; cmd[1] = 0x03;
phonemacro 6:e1b7190d6cb5 267 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 1:da792e46a385 268 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 269 sh_i2c.read(SH_ADDR, rsp, 4);
phonemacro 1:da792e46a385 270 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 271 pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]);
phonemacro 0:6f65cae31c54 272
phonemacro 0:6f65cae31c54 273 // 1.3 sensor and algo data
phonemacro 4:4f1e9439f048 274 cmd[0] = 0x10; cmd[1] = 0x00;
phonemacro 2:563d90a111b3 275 #ifdef ALGO_ONLY
phonemacro 0:6f65cae31c54 276 cmd[2] = 0x02; // algo data
phonemacro 4:4f1e9439f048 277 pc.printf("algo only \n\r");
phonemacro 2:563d90a111b3 278 #else
phonemacro 2:563d90a111b3 279 cmd[2] = 0x03; // sensor + algo data
phonemacro 4:4f1e9439f048 280 pc.printf("sens+algo \n\r");
phonemacro 2:563d90a111b3 281 #endif
phonemacro 6:e1b7190d6cb5 282 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 1:da792e46a385 283 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 284 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 285 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 286 pc.printf("1.3 Status: %x\n\r", rsp[0]);
phonemacro 3:da975696b936 287 // 1.7 cont hr, spo2
phonemacro 4:4f1e9439f048 288 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0A; cmd[3] = 0x00;
phonemacro 6:e1b7190d6cb5 289 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 3:da975696b936 290 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 291 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 292 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 293 pc.printf("1.7 Status: %x\n\r", rsp[0]);
phonemacro 4:4f1e9439f048 294 // 1.8 AEC enable (default)
phonemacro 4:4f1e9439f048 295 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0B; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 296 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 1:da792e46a385 297 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 298 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 299 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 300 pc.printf("1.8 Status: %x\n\r", rsp[0]);
phonemacro 4:4f1e9439f048 301 // 1.9 auto PD (default
phonemacro 4:4f1e9439f048 302 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x12; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 303 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 1:da792e46a385 304 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 305 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 306 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 307 pc.printf("1.9 Status: %x\n\r", rsp[0]);
phonemacro 4:4f1e9439f048 308 // 1.10 SCD (default)
phonemacro 4:4f1e9439f048 309 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0C; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 310 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 4:4f1e9439f048 311 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 312 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 4:4f1e9439f048 313 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 314 pc.printf("1.7 Status: %x\n\r", rsp[0]);
phonemacro 3:da975696b936 315 #ifdef MAXM86146_CFG
phonemacro 3:da975696b936 316 //1.20 Sec 4.1 map leds to slots for MAXM86146
phonemacro 4:4f1e9439f048 317 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x13; cmd[4] = 0x56; cmd[5] = 0x00;
phonemacro 6:e1b7190d6cb5 318 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 3:da975696b936 319 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 320 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 321 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 322 pc.printf("map leds to slots%x\n\r", rsp[0]);
phonemacro 3:da975696b936 323 //1.21 map HR inputs to slots
phonemacro 4:4f1e9439f048 324 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x11;
phonemacro 6:e1b7190d6cb5 325 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 3:da975696b936 326 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 327 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 328 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 329 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 3:da975696b936 330 //1.22 map SpO2 inputs to slots
phonemacro 4:4f1e9439f048 331 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x30; cmd[4] = 0x20;
phonemacro 6:e1b7190d6cb5 332 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 3:da975696b936 333 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 334 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 335 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 336 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 3:da975696b936 337 #if 0
phonemacro 2:563d90a111b3 338 //1.20 Sec 4.1 map leds to slots for MAXM86146
phonemacro 4:4f1e9439f048 339 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x15; cmd[4] = 0x60; cmd[5] = 0x00;
phonemacro 6:e1b7190d6cb5 340 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 1:da792e46a385 341 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 342 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 343 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 344 pc.printf("map leds to slots%x\n\r", rsp[0]);
phonemacro 2:563d90a111b3 345 //1.21 map HR inputs to slots
phonemacro 4:4f1e9439f048 346 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x01;
phonemacro 6:e1b7190d6cb5 347 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 1:da792e46a385 348 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 349 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 350 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 351 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 2:563d90a111b3 352 //1.22 map SpO2 inputs to slots
phonemacro 4:4f1e9439f048 353 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x20; cmd[4] = 0x10;
phonemacro 6:e1b7190d6cb5 354 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 1:da792e46a385 355 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 356 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 357 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 358 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 3:da975696b936 359 #endif
phonemacro 3:da975696b936 360 #endif // MAXM86146_CFG
phonemacro 0:6f65cae31c54 361
phonemacro 4:4f1e9439f048 362 // 1.3 Enable HR, SpO2 algo
phonemacro 4:4f1e9439f048 363 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x01;
phonemacro 6:e1b7190d6cb5 364 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 0:6f65cae31c54 365 thread_sleep_for(465);
phonemacro 6:e1b7190d6cb5 366 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 367 pc.printf("1.14 status: %x\n\r", rsp[0]);
phonemacro 0:6f65cae31c54 368 mfio = 1;
phonemacro 0:6f65cae31c54 369
phonemacro 4:4f1e9439f048 370 #if 1
phonemacro 4:4f1e9439f048 371 //1.31 rd AFE part id
phonemacro 4:4f1e9439f048 372 cmd[0] = 0x41; cmd[1] = 0x00; cmd[2] = 0xFF;
phonemacro 6:e1b7190d6cb5 373 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 4:4f1e9439f048 374 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 375 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 4:4f1e9439f048 376 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 377 pc.printf("1.31 part id afe %x %x\n\r", rsp[0], rsp[1]);
phonemacro 4:4f1e9439f048 378 //1.32 rd accel who
phonemacro 4:4f1e9439f048 379 cmd[0] = 0x41; cmd[1] = 0x04; cmd[2] = 0x0F;
phonemacro 6:e1b7190d6cb5 380 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 4:4f1e9439f048 381 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 382 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 4:4f1e9439f048 383 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 384 pc.printf("1.32 who accel %x %x\n\r", rsp[0], rsp[1]);
phonemacro 4:4f1e9439f048 385 #endif
phonemacro 4:4f1e9439f048 386
phonemacro 8:e6ae69cfecbf 387 #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG) || defined(MAXM86146_CFG)
phonemacro 6:e1b7190d6cb5 388 Timer tmr1;
phonemacro 0:6f65cae31c54 389 while (1) {
phonemacro 6:e1b7190d6cb5 390 tmr1.start();
phonemacro 6:e1b7190d6cb5 391 if (tmr1.read_ms() > 40) {
phonemacro 7:23b067817ab8 392 tmr1.reset();
phonemacro 4:4f1e9439f048 393 read_ppg();
phonemacro 7:23b067817ab8 394 if ((ledcnt++ % 50) == 0)
phonemacro 6:e1b7190d6cb5 395 gLED = !gLED;
phonemacro 0:6f65cae31c54 396 }
phonemacro 0:6f65cae31c54 397 }
phonemacro 6:e1b7190d6cb5 398 #else
phonemacro 6:e1b7190d6cb5 399 ticker.attach(callback(&fifo_timer), 0.040f);
phonemacro 6:e1b7190d6cb5 400 while (1) {
phonemacro 6:e1b7190d6cb5 401 if (Time_to_Read_PPG) {
phonemacro 6:e1b7190d6cb5 402 read_ppg();
phonemacro 7:23b067817ab8 403 if ((ledcnt++ % 50) == 0)
phonemacro 6:e1b7190d6cb5 404 gLED = !gLED;
phonemacro 6:e1b7190d6cb5 405 }
phonemacro 6:e1b7190d6cb5 406 }
phonemacro 6:e1b7190d6cb5 407 #endif
phonemacro 0:6f65cae31c54 408 }