Mode1 Optical Validation

Dependencies:   max32630fthr

Committer:
phonemacro
Date:
Thu Mar 25 04:08:19 2021 +0000
Revision:
5:7f5a012747a5
Parent:
4:4f1e9439f048
Child:
6:e1b7190d6cb5
Add accel prints and pmic for hsp2

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