Mode1 Optical Validation

Dependencies:   max32630fthr

Committer:
phonemacro
Date:
Wed Jun 01 01:03:55 2022 +0000
Revision:
61:a2e73c5b87e7
Parent:
60:fdccd048489b
Child:
62:21a7745d02e0
Initial code, green1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phonemacro 0:6f65cae31c54 1 /*******************************************************************************
phonemacro 30:77a30ea425da 2 * Copyright (C) 2021-22 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 61:a2e73c5b87e7 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 60:fdccd048489b 40 * ver: 220531
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 24:064478ff33d2 52 /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/
phonemacro 6:e1b7190d6cb5 53 // define one and only one of the following three platforms
phonemacro 61:a2e73c5b87e7 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 61:a2e73c5b87e7 56 //#define MAXM86161_CFG 1 // tested on MAXM86161+MAX32630FTHR v32.9.22, 32.13.12
phonemacro 6:e1b7190d6cb5 57 /*****************************************************************************/
phonemacro 24:064478ff33d2 58
phonemacro 24:064478ff33d2 59 /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/
phonemacro 24:064478ff33d2 60 // define which adaptor board is being used
phonemacro 26:33c0d3fd2a95 61 #define MAXM86161_ADPTR_EVKIT_B
phonemacro 26:33c0d3fd2a95 62 //#define MAXREFDES1319 // MAXM86161: Remove J7; For PIN1=ACC_INTN, J9 set to 2-3; For PIN13=OPT_INTN, J10 set to 2-3
phonemacro 24:064478ff33d2 63 /******************************************************************************
phonemacro 24:064478ff33d2 64 * MAX32630FTHR GPIOs
phonemacro 24:064478ff33d2 65 ******************************************************************************/
phonemacro 24:064478ff33d2 66 #ifdef MAXM86161_ADPTR_EVKIT_B
phonemacro 24:064478ff33d2 67 #define RST_PIN P5_6
phonemacro 24:064478ff33d2 68 #define MFIO_PIN P5_4
phonemacro 24:064478ff33d2 69 #else
phonemacro 24:064478ff33d2 70 #ifdef MAXREFDES1319
phonemacro 24:064478ff33d2 71 #define RST_PIN P3_0
phonemacro 24:064478ff33d2 72 #define MFIO_PIN P5_2
phonemacro 24:064478ff33d2 73 #endif
phonemacro 24:064478ff33d2 74 #endif
phonemacro 24:064478ff33d2 75
phonemacro 24:064478ff33d2 76 DigitalOut rst(RST_PIN, PullUp);
phonemacro 24:064478ff33d2 77 DigitalOut mfio(MFIO_PIN, PullUp);
phonemacro 24:064478ff33d2 78 I2C sh_i2c(P3_4, P3_5);
phonemacro 24:064478ff33d2 79
phonemacro 24:064478ff33d2 80 /*****************************************************************************/
phonemacro 26:33c0d3fd2a95 81 #if defined(MAXM86161_CFG) //|| defined(MAXM86146_CFG) // don't need 3.3V for MAXM86146EVSYS_sensorBrd+MAXM86161_ADAPTER_REVB+MAX32630FTHR
phonemacro 17:0d6e99a0fd8d 82 #include "max32630fthr.h"
phonemacro 17:0d6e99a0fd8d 83 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); // Enable J1-pin2, 3.3V and set GPIO to 3.3v
phonemacro 21:67d58af1ec56 84 #endif
phonemacro 26:33c0d3fd2a95 85
phonemacro 26:33c0d3fd2a95 86 /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/
phonemacro 50:dd2f60ab5686 87 // comment the two below if you want raw sensor+algo data
phonemacro 51:e2214db671c0 88 //#define ALGO_ONLY 1 // define this if you only want algo data
phonemacro 61:a2e73c5b87e7 89 #define RAW // define this if you want AFE+accel data, no algorithm, tested on 33.13.31
phonemacro 50:dd2f60ab5686 90 //#define RAW_HZ 25 // Raw data rate
phonemacro 55:04c9fad147d4 91 //#define RAW_HZ 50 // Raw data rate
phonemacro 55:04c9fad147d4 92 #define RAW_HZ 100 // Raw data rate
phonemacro 50:dd2f60ab5686 93 //#define RAW_HZ 200 // Raw data rate
phonemacro 50:dd2f60ab5686 94 //#define RAW_HZ 2004 // Raw data rate 200 Hz, ave 4
phonemacro 53:034f646141ae 95 //#define SPO2_CAL_RPT 1
phonemacro 58:33af4ccb8220 96 #define MAXM86161_OPT_VALIDATION_GRN 1 // Optical validatation
phonemacro 56:60b61d5c8154 97 //#define MAXM86161_OPT_VALIDATION_IR 1 // Optical validatation
phonemacro 58:33af4ccb8220 98 //#define MAXM86161_OPT_VALIDATION_RED 1 // Optical validatation
phonemacro 61:a2e73c5b87e7 99
phonemacro 33:c8fbd904df3e 100
phonemacro 33:c8fbd904df3e 101 // Comment out both of the below for Normal Algorithm Samples Format
phonemacro 61:a2e73c5b87e7 102 //#define EXTENDED_ALGO 1 // define this if you want the extended algo samples report format
phonemacro 35:67699bdae57e 103 //#define PACKED_NORMAL_ALGO 1 // define this if you want the packed normal algo samples report format, 33.13.31
phonemacro 45:d26b8bcce561 104 //#define PCK_CFG_MASK 1 // define this and the above if you want to config mask out some of the packed data, 33.13.31
phonemacro 13:1baccc6275a7 105 //#define AGC 1 // define this for AGC, otherwise the default is AEC
phonemacro 6:e1b7190d6cb5 106
phonemacro 61:a2e73c5b87e7 107 //#define USE_SYN 1
phonemacro 42:6f980909371f 108
phonemacro 42:6f980909371f 109 //#define REDUCE_RPT_PERIOD 0x19 // Report samples every 25 frame.
phonemacro 45:d26b8bcce561 110 //#define USE_FIFO_BUFFER_CNT 5 // Allow the FIFO to accumulate this many samples
phonemacro 42:6f980909371f 111
phonemacro 6:e1b7190d6cb5 112 #ifdef MAXREFDES103_CFG
phonemacro 5:7f5a012747a5 113 #include "MAX20303.h"
phonemacro 6:e1b7190d6cb5 114 I2C sh_i2c_pmic(P5_7, P6_0);
phonemacro 5:7f5a012747a5 115 #endif
phonemacro 5:7f5a012747a5 116
phonemacro 32:92adfbe18ab6 117 #ifdef MAXM86146_CFG
phonemacro 32:92adfbe18ab6 118 #define PPG_SZ 36 //maxm86146
phonemacro 32:92adfbe18ab6 119 #else
phonemacro 32:92adfbe18ab6 120 #define PPG_SZ 18 //maxm86161, max86141
phonemacro 32:92adfbe18ab6 121 #endif
phonemacro 32:92adfbe18ab6 122 #define ACCEL_SZ 6 // accel
phonemacro 32:92adfbe18ab6 123 #define SENSOR_SZ (PPG_SZ+ACCEL_SZ)
phonemacro 32:92adfbe18ab6 124
phonemacro 32:92adfbe18ab6 125 #if defined(MAXM86161_CFG) || defined(MAXM86146_CFG) // MAXM86161, MAXM86146, keep algo Fifo size as 52, 20 to keep compatible w/ the GUI
phonemacro 33:c8fbd904df3e 126 #define old_algo_sz 1 // 3x.12.0 or earlier; 32.9.x
phonemacro 28:315604f4b374 127 #endif
phonemacro 30:77a30ea425da 128
phonemacro 33:c8fbd904df3e 129 #ifdef old_algo_sz
phonemacro 18:f4c95b1c0efc 130 #ifdef EXTENDED_ALGO
phonemacro 33:c8fbd904df3e 131 #define ALGO_SZ 52 // 52 bytes, extended algo size for 3x.12.0
phonemacro 33:c8fbd904df3e 132 #elif defined(PACKED_NORMAL_ALGO)
phonemacro 33:c8fbd904df3e 133 #define ALGO_SZ 16 // 16 bytes, packed algo normal size for 33.31.31
phonemacro 18:f4c95b1c0efc 134 #else
phonemacro 42:6f980909371f 135 #define ALGO_SZ 20 // 20 bytes, normal algo size for 3x.12.0
phonemacro 18:f4c95b1c0efc 136 #endif
phonemacro 12:17a0bf823462 137 #else
phonemacro 18:f4c95b1c0efc 138 #ifdef EXTENDED_ALGO
phonemacro 33:c8fbd904df3e 139 #define ALGO_SZ 56 // 56 bytes, extended algo size for 3x.13.x+
phonemacro 18:f4c95b1c0efc 140 #else
phonemacro 33:c8fbd904df3e 141 #define ALGO_SZ 24 // 24 bytes, normal algo size for 3x.13.x+
phonemacro 18:f4c95b1c0efc 142 #endif
phonemacro 12:17a0bf823462 143 #endif
phonemacro 18:f4c95b1c0efc 144
phonemacro 61:a2e73c5b87e7 145 #ifdef ALGO_ONLY
phonemacro 61:a2e73c5b87e7 146 #define TTL_SZ (ALGO_SZ)
phonemacro 0:6f65cae31c54 147 #else
phonemacro 61:a2e73c5b87e7 148 #ifdef RAW
phonemacro 61:a2e73c5b87e7 149 #define TTL_SZ (PPG_SZ+ACCEL_SZ)
phonemacro 14:c8cc6d7fd5f9 150 #else
phonemacro 61:a2e73c5b87e7 151 #define TTL_SZ (PPG_SZ+ACCEL_SZ+ALGO_SZ)
phonemacro 14:c8cc6d7fd5f9 152 #endif
phonemacro 0:6f65cae31c54 153 #endif
phonemacro 0:6f65cae31c54 154
phonemacro 3:da975696b936 155 Serial pc(USBTX, USBRX, 115200);
phonemacro 0:6f65cae31c54 156 DigitalOut rLED(LED1);
phonemacro 0:6f65cae31c54 157 DigitalOut gLED(LED2);
phonemacro 0:6f65cae31c54 158 DigitalOut bLED(LED3);
phonemacro 6:e1b7190d6cb5 159
phonemacro 33:c8fbd904df3e 160 int32_t heading_printed; // has the heading been printed?
phonemacro 33:c8fbd904df3e 161
phonemacro 33:c8fbd904df3e 162
phonemacro 6:e1b7190d6cb5 163 //#define thread_sleep_for(x) wait_ms(x) // for older versions of mbed
phonemacro 0:6f65cae31c54 164
phonemacro 5:7f5a012747a5 165
phonemacro 6:e1b7190d6cb5 166 const int SH_ADDR = 0xAA;//0x55;
phonemacro 0:6f65cae31c54 167 int32_t Time_to_Read_PPG = 0;
phonemacro 0:6f65cae31c54 168
phonemacro 0:6f65cae31c54 169 #define BLINKING_RATE_MS 1000ms
phonemacro 0:6f65cae31c54 170 void blink_timer(void) {
phonemacro 0:6f65cae31c54 171 gLED = !gLED; /* blink the green LED */
phonemacro 0:6f65cae31c54 172 }
phonemacro 0:6f65cae31c54 173
phonemacro 0:6f65cae31c54 174 void fifo_timer(void) {
phonemacro 0:6f65cae31c54 175 Time_to_Read_PPG = 1;
phonemacro 0:6f65cae31c54 176 }
phonemacro 0:6f65cae31c54 177
phonemacro 14:c8cc6d7fd5f9 178 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 179 // read_sh_fifo
phonemacro 14:c8cc6d7fd5f9 180 /*****************************************************************************/
phonemacro 27:a45d6e38f2de 181 /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/
phonemacro 61:a2e73c5b87e7 182 #define OPTIMIZE_FIFO_READ 1 // Assume that the FIFO is filled at the specified rate, so just periodically check then number of samples in the FIFO to save power
phonemacro 27:a45d6e38f2de 183 #ifdef OPTIMIZE_FIFO_READ // tested on MAXM86146EVSYS
phonemacro 27:a45d6e38f2de 184 int32_t check_fifo_countdown;
phonemacro 42:6f980909371f 185 #define MAX_FIFO_CNT 20 // Only send the 0x00 0x00 (step 2.0), and 0x12 0x00 (step 2.1) commands every MAX_FIFO_CNT frames.
phonemacro 27:a45d6e38f2de 186 #endif
phonemacro 42:6f980909371f 187
phonemacro 10:192ea88e964b 188 void read_sh_fifo(void) {
phonemacro 33:c8fbd904df3e 189 char cmd[8], i, j, k, samples;
phonemacro 0:6f65cae31c54 190 char rsp[3000];
phonemacro 0:6f65cae31c54 191 int32_t ppg[12];
phonemacro 5:7f5a012747a5 192 int16_t accel[3];
phonemacro 33:c8fbd904df3e 193 int32_t tst[20];
phonemacro 12:17a0bf823462 194 int32_t status, opmode, hr, hr_conf, ibi, ibi_conf;
phonemacro 12:17a0bf823462 195 #ifdef EXTENDED_ALGO
phonemacro 12:17a0bf823462 196 int32_t walk_stp, run_stp, energy, amr, iadj1_rqt, iadj1, iadj2_rqt, iadj2, iadj3_rqt, iadj3;
phonemacro 12:17a0bf823462 197 int32_t intadj_rqt, intadj, smpladj_rqt, smpladj, rqt_smplave, afestatehr, hr_motion;
phonemacro 12:17a0bf823462 198 #endif
phonemacro 12:17a0bf823462 199 int32_t act, r, spo2, spo2_conf;
phonemacro 33:c8fbd904df3e 200 int32_t spo2_compl, spo2_lo, spo2_mo, spo2_lopi, spo2_unrel, spo2_state, ibi_offset, scd, inappro_ori;
phonemacro 0:6f65cae31c54 201 int32_t ptr = 0;
phonemacro 0:6f65cae31c54 202 int32_t sptr = 0;
phonemacro 1:da792e46a385 203 mfio = 0; wait_us(300);
phonemacro 0:6f65cae31c54 204 Time_to_Read_PPG = 0;
phonemacro 42:6f980909371f 205 samples = 1;
phonemacro 42:6f980909371f 206 #ifdef USE_FIFO_BUFFER_CNT
phonemacro 42:6f980909371f 207 samples = USE_FIFO_BUFFER_CNT;
phonemacro 42:6f980909371f 208 #endif
phonemacro 27:a45d6e38f2de 209 #if defined(OPTIMIZE_FIFO_READ)
phonemacro 27:a45d6e38f2de 210 check_fifo_countdown--;
phonemacro 27:a45d6e38f2de 211 if (check_fifo_countdown == 0) {
phonemacro 27:a45d6e38f2de 212 #endif
phonemacro 27:a45d6e38f2de 213
phonemacro 22:f6b366c3b954 214 #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG)
phonemacro 0:6f65cae31c54 215 // 2.1
phonemacro 27:a45d6e38f2de 216 cmd[0] = 0x00; cmd[1] = 0x00;
phonemacro 27:a45d6e38f2de 217 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 27:a45d6e38f2de 218 wait_us(100);
phonemacro 27:a45d6e38f2de 219 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 27:a45d6e38f2de 220 // pc.printf("2.1 Status: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 22:f6b366c3b954 221 #else
phonemacro 45:d26b8bcce561 222 // tested w/ 33.13.12 don't need 2.1
phonemacro 0:6f65cae31c54 223 #endif
phonemacro 0:6f65cae31c54 224 // 2.2
phonemacro 50:dd2f60ab5686 225 #if defined(PACKED_NORMAL_ALGO) || defined(USE_SYN)
phonemacro 61:a2e73c5b87e7 226 cmd[0] = 0x20;
phonemacro 35:67699bdae57e 227 sh_i2c.write(SH_ADDR, cmd, 1);
phonemacro 35:67699bdae57e 228 #else
phonemacro 27:a45d6e38f2de 229 cmd[0] = 0x12; cmd[1] = 0x00;
phonemacro 27:a45d6e38f2de 230 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 35:67699bdae57e 231 #endif
phonemacro 27:a45d6e38f2de 232 wait_us(100);
phonemacro 27:a45d6e38f2de 233 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 35:67699bdae57e 234 // mfio = 1; mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 235
phonemacro 27:a45d6e38f2de 236 // pc.printf("2.2 Status: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 27:a45d6e38f2de 237 samples = rsp[1];
phonemacro 27:a45d6e38f2de 238 // pc.printf("num samples %d, (num*ttl)+1 %d\n\r", rsp[1], TTL_SZ*samples+1);
phonemacro 27:a45d6e38f2de 239 // pc.printf("num smpls %d \n\r", samples);
phonemacro 27:a45d6e38f2de 240 #if defined(OPTIMIZE_FIFO_READ)
phonemacro 27:a45d6e38f2de 241 }
phonemacro 27:a45d6e38f2de 242 if (check_fifo_countdown <= 0)
phonemacro 27:a45d6e38f2de 243 check_fifo_countdown = MAX_FIFO_CNT;
phonemacro 27:a45d6e38f2de 244 #endif
phonemacro 27:a45d6e38f2de 245
phonemacro 0:6f65cae31c54 246 // 2.3
phonemacro 50:dd2f60ab5686 247 #if defined(PACKED_NORMAL_ALGO) || defined(USE_SYN)
phonemacro 35:67699bdae57e 248 cmd[0] = 0x21;;
phonemacro 35:67699bdae57e 249 sh_i2c.write(SH_ADDR, cmd, 1);
phonemacro 35:67699bdae57e 250 #else
phonemacro 45:d26b8bcce561 251 cmd[0] = 0x12; cmd[1] = 0x01;
phonemacro 45:d26b8bcce561 252 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 35:67699bdae57e 253 #endif
phonemacro 45:d26b8bcce561 254 wait_us(100);
phonemacro 45:d26b8bcce561 255 sh_i2c.read(SH_ADDR, rsp, 1+(TTL_SZ*samples));
phonemacro 42:6f980909371f 256 //pc.printf("num smpls %d ttlsiz %d\n\r", samples, TTL_SZ);
phonemacro 35:67699bdae57e 257 // mfio = 1; mfio = 0; wait_us(300);
phonemacro 45:d26b8bcce561 258 mfio = 1;
phonemacro 21:67d58af1ec56 259
phonemacro 0:6f65cae31c54 260 status = rsp[0];
phonemacro 5:7f5a012747a5 261
phonemacro 0:6f65cae31c54 262 sptr = 1;
phonemacro 42:6f980909371f 263 for (i = 0; i < samples; i++) {
phonemacro 0:6f65cae31c54 264 ptr = sptr;
phonemacro 35:67699bdae57e 265 #if !defined(ALGO_ONLY)
phonemacro 2:563d90a111b3 266 ppg[0] = (rsp[ptr+0] << 16) | (rsp[ptr+1] << 8) | (rsp[ptr+2]);
phonemacro 2:563d90a111b3 267 ppg[1] = (rsp[ptr+3] << 16) | (rsp[ptr+4] << 8) | (rsp[ptr+5]);
phonemacro 2:563d90a111b3 268 ppg[2] = (rsp[ptr+6] << 16) | (rsp[ptr+7] << 8) | (rsp[ptr+8]);
phonemacro 3:da975696b936 269 ppg[3] = (rsp[ptr+9] << 16) | (rsp[ptr+10] << 8) | (rsp[ptr+11]);
phonemacro 4:4f1e9439f048 270 ppg[4] = (rsp[ptr+12] << 16) | (rsp[ptr+13] << 8) | (rsp[ptr+14]);
phonemacro 4:4f1e9439f048 271 ppg[5] = (rsp[ptr+15] << 16) | (rsp[ptr+16] << 8) | (rsp[ptr+17]);
phonemacro 3:da975696b936 272 pc.printf("%d,%d,%d,%d,", ppg[0], ppg[1], ppg[2], ppg[3]);
phonemacro 47:346a13fbdc0f 273 #if defined(RAW) || defined(SPO2_CAL_RPT)
phonemacro 50:dd2f60ab5686 274 #if RAW_HZ <= 100
phonemacro 50:dd2f60ab5686 275 pc.printf("%d,%d,", ppg[4], ppg[5]);
phonemacro 50:dd2f60ab5686 276 #endif
phonemacro 61:a2e73c5b87e7 277 #endif
phonemacro 14:c8cc6d7fd5f9 278 #ifdef MAXM86146_CFG
phonemacro 47:346a13fbdc0f 279 #if defined(RAW) || defined(SPO2_CAL_RPT)
phonemacro 14:c8cc6d7fd5f9 280 ppg[6] = (rsp[ptr+18] << 16) | (rsp[ptr+19] << 8) | (rsp[ptr+20]);
phonemacro 14:c8cc6d7fd5f9 281 ppg[7] = (rsp[ptr+21] << 16) | (rsp[ptr+22] << 8) | (rsp[ptr+23]);
phonemacro 14:c8cc6d7fd5f9 282 ppg[8] = (rsp[ptr+24] << 16) | (rsp[ptr+25] << 8) | (rsp[ptr+26]);
phonemacro 14:c8cc6d7fd5f9 283 ppg[9] = (rsp[ptr+27] << 16) | (rsp[ptr+28] << 8) | (rsp[ptr+29]);
phonemacro 14:c8cc6d7fd5f9 284 ppg[10] = (rsp[ptr+30] << 16) | (rsp[ptr+31] << 8) | (rsp[ptr+32]);
phonemacro 14:c8cc6d7fd5f9 285 ppg[11] = (rsp[ptr+33] << 16) | (rsp[ptr+34] << 8) | (rsp[ptr+35]);
phonemacro 50:dd2f60ab5686 286 #if RAW_HZ <= 100
phonemacro 14:c8cc6d7fd5f9 287 pc.printf("%d,%d,%d,%d,%d,%d,", ppg[6], ppg[7],ppg[8], ppg[9],ppg[10], ppg[11]);
phonemacro 50:dd2f60ab5686 288 #endif
phonemacro 36:a6e7ff9c87a0 289 #endif // raw
phonemacro 36:a6e7ff9c87a0 290 #endif // MAXM86146_CFG
phonemacro 44:1b165a68474d 291 accel[0] = (rsp[1+PPG_SZ+0] << 8) | (rsp[1+PPG_SZ+1]);
phonemacro 44:1b165a68474d 292 accel[1] = (rsp[1+PPG_SZ+2] << 8) | (rsp[1+PPG_SZ+3]);
phonemacro 44:1b165a68474d 293 accel[2] = (rsp[1+PPG_SZ+4] << 8) | (rsp[1+PPG_SZ+5]);
phonemacro 5:7f5a012747a5 294 pc.printf("%d,%d,%d,", accel[0], accel[1], accel[2]);
phonemacro 5:7f5a012747a5 295
phonemacro 0:6f65cae31c54 296 ptr = sptr + SENSOR_SZ;
phonemacro 36:a6e7ff9c87a0 297
phonemacro 36:a6e7ff9c87a0 298 #endif //!defined(ALGO_ONLY)
phonemacro 29:a7dd81450b35 299
phonemacro 61:a2e73c5b87e7 300 #ifndef RAW
phonemacro 12:17a0bf823462 301 #ifdef EXTENDED_ALGO
phonemacro 45:d26b8bcce561 302 // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ);
phonemacro 0:6f65cae31c54 303 opmode = rsp[ptr];
phonemacro 0:6f65cae31c54 304 hr = (rsp[ptr+1] << 8) + rsp[ptr+2];
phonemacro 0:6f65cae31c54 305 hr_conf = rsp[ptr+3];
phonemacro 12:17a0bf823462 306 ibi = (rsp[ptr+4] << 8) + rsp[ptr+5];
phonemacro 12:17a0bf823462 307
phonemacro 12:17a0bf823462 308 ibi_conf = rsp[ptr+6];
phonemacro 12:17a0bf823462 309 act = rsp[ptr+7];
phonemacro 12:17a0bf823462 310 walk_stp = (rsp[ptr+8] << 24) + (rsp[ptr+9] << 16) + (rsp[ptr+10] << 8) + rsp[ptr+11];
phonemacro 12:17a0bf823462 311 run_stp = (rsp[ptr+12] << 24) + (rsp[ptr+13] << 16) + (rsp[ptr+14] << 8) + rsp[ptr+15];
phonemacro 12:17a0bf823462 312
phonemacro 12:17a0bf823462 313 energy = (rsp[ptr+16] << 24) + (rsp[ptr+17] << 16) + (rsp[ptr+18] << 8) + rsp[ptr+19];
phonemacro 12:17a0bf823462 314 amr = (rsp[ptr+20] << 24) + (rsp[ptr+21] << 16) + (rsp[ptr+22] << 8) + rsp[ptr+23];
phonemacro 12:17a0bf823462 315 iadj1_rqt = rsp[ptr+24];
phonemacro 12:17a0bf823462 316 iadj1 = (rsp[ptr+25] << 8) + rsp[ptr+26];
phonemacro 12:17a0bf823462 317
phonemacro 12:17a0bf823462 318 iadj2_rqt = rsp[ptr+27];
phonemacro 12:17a0bf823462 319 iadj2 = (rsp[ptr+28] << 8) + rsp[ptr+29];
phonemacro 12:17a0bf823462 320 iadj3_rqt = rsp[ptr+30];
phonemacro 12:17a0bf823462 321 iadj3 = (rsp[ptr+31] << 8) + rsp[ptr+32];
phonemacro 12:17a0bf823462 322
phonemacro 12:17a0bf823462 323 intadj_rqt = rsp[ptr+33];
phonemacro 12:17a0bf823462 324 intadj = rsp[ptr+34];
phonemacro 12:17a0bf823462 325 smpladj_rqt = rsp[ptr+35];
phonemacro 12:17a0bf823462 326 smpladj = rsp[ptr+36];
phonemacro 12:17a0bf823462 327
phonemacro 12:17a0bf823462 328 rqt_smplave = rsp[ptr+37];
phonemacro 12:17a0bf823462 329 afestatehr = rsp[ptr+38];
phonemacro 12:17a0bf823462 330 hr_motion = rsp[ptr+39];
phonemacro 12:17a0bf823462 331 scd = rsp[ptr+40];
phonemacro 12:17a0bf823462 332
phonemacro 12:17a0bf823462 333
phonemacro 12:17a0bf823462 334 r = (rsp[ptr+41] << 8) + rsp[ptr+42];
phonemacro 12:17a0bf823462 335 spo2_conf = rsp[ptr+43];
phonemacro 12:17a0bf823462 336
phonemacro 12:17a0bf823462 337 spo2 = (rsp[ptr+44] << 8) + rsp[ptr+45];
phonemacro 12:17a0bf823462 338 spo2_compl = rsp[ptr+46];
phonemacro 53:034f646141ae 339 spo2_lo = rsp[ptr+47]; // low quality
phonemacro 12:17a0bf823462 340 spo2_mo = rsp[ptr+48];
phonemacro 12:17a0bf823462 341
phonemacro 12:17a0bf823462 342 spo2_lopi = rsp[ptr+49];
phonemacro 12:17a0bf823462 343 spo2_unrel = rsp[ptr+50];
phonemacro 12:17a0bf823462 344 spo2_state = rsp[ptr+51];
phonemacro 12:17a0bf823462 345
phonemacro 12:17a0bf823462 346 ibi_offset = rsp[ptr+52];
phonemacro 12:17a0bf823462 347
phonemacro 12:17a0bf823462 348 sptr += (TTL_SZ);
phonemacro 36:a6e7ff9c87a0 349
phonemacro 12:17a0bf823462 350 #if 1
phonemacro 33:c8fbd904df3e 351 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 352 heading_printed = 1;
phonemacro 36:a6e7ff9c87a0 353 #if defined(ALGO_ONLY)
phonemacro 33:c8fbd904df3e 354 pc.printf("opmode,hr,hr_conf,ibi,ibi_conf,act,walk_stp,run_stp,energy,amr,");
phonemacro 33:c8fbd904df3e 355 pc.printf("iadj1_rqt,iadj1,iadj2_rqt,iadj2,iadj3_rqt,iadj3,intadj_rqt,intadj,");
phonemacro 33:c8fbd904df3e 356 pc.printf("smpladj_rqt,smpladj,rqt_smplave,afestatehr,hr_motion,scd,");
phonemacro 51:e2214db671c0 357 pc.printf("r,");
phonemacro 33:c8fbd904df3e 358 pc.printf("spo2,spo2_compl,spo2_lo,spo2_mo,spo2_lopi,spo2_unrel,spo2_state,ibi_offset,\n\r");
phonemacro 36:a6e7ff9c87a0 359 #endif
phonemacro 33:c8fbd904df3e 360 }
phonemacro 12:17a0bf823462 361 pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi);
phonemacro 12:17a0bf823462 362 pc.printf("%d,%d,", ibi_conf, act);
phonemacro 12:17a0bf823462 363 pc.printf("%d,%d,%d,", walk_stp, run_stp, energy);
phonemacro 12:17a0bf823462 364 pc.printf("%d,%d,%d,%d,", amr, iadj1_rqt, iadj1, iadj2_rqt);
phonemacro 12:17a0bf823462 365 pc.printf("%d,%d,%d,%d,", iadj2, iadj3_rqt, iadj3, intadj_rqt);
phonemacro 12:17a0bf823462 366 pc.printf("%d,%d,%d,%d,", intadj, smpladj_rqt, smpladj, rqt_smplave);
phonemacro 12:17a0bf823462 367 pc.printf("%d,%d,", afestatehr, hr_motion);
phonemacro 51:e2214db671c0 368 pc.printf("%d,%d", scd, r);
phonemacro 12:17a0bf823462 369 pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo);
phonemacro 12:17a0bf823462 370 pc.printf("%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state);
phonemacro 12:17a0bf823462 371 pc.printf("%d,", ibi_offset);
phonemacro 12:17a0bf823462 372 #else
phonemacro 33:c8fbd904df3e 373 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 374 heading_printed = 1;
phonemacro 36:a6e7ff9c87a0 375 #if defined(ALGO_ONLY)
phonemacro 53:034f646141ae 376 pc.printf("hr,r,hr_conf,spo2,spo2_conf,spo2_lo,spo2_unrel,spo2_state,scd,\n\r");
phonemacro 36:a6e7ff9c87a0 377 #endif
phonemacro 33:c8fbd904df3e 378 }
phonemacro 51:e2214db671c0 379 pc.printf("%d,%d,%d", hr, hr_conf, r);
phonemacro 12:17a0bf823462 380 pc.printf("%d,%d,", spo2, spo2_conf);
phonemacro 16:ff1122f0624a 381 pc.printf("%d,%d,%d,", spo2_lo, spo2_mo, spo2_lopi);
phonemacro 53:034f646141ae 382 pc.printf("%d,%d,%d,", spo2_unrel,spo2_state, scd);
phonemacro 36:a6e7ff9c87a0 383 #endif // if 1
phonemacro 33:c8fbd904df3e 384 #elif defined(PACKED_NORMAL_ALGO)
phonemacro 33:c8fbd904df3e 385 // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ);
phonemacro 35:67699bdae57e 386 opmode = rsp[ptr];
phonemacro 33:c8fbd904df3e 387 hr = (rsp[ptr+1] << 8) + rsp[ptr+2];
phonemacro 33:c8fbd904df3e 388 hr_conf = rsp[ptr+3];
phonemacro 33:c8fbd904df3e 389 ibi = (rsp[ptr+4] << 8) + rsp[ptr+5];
phonemacro 33:c8fbd904df3e 390
phonemacro 33:c8fbd904df3e 391 ibi_conf = rsp[ptr+6];
phonemacro 33:c8fbd904df3e 392 // act = rsp[ptr+7];
phonemacro 33:c8fbd904df3e 393 r = (rsp[ptr+7] << 8) + rsp[ptr+8];
phonemacro 33:c8fbd904df3e 394 spo2_conf = rsp[ptr+9];
phonemacro 33:c8fbd904df3e 395
phonemacro 33:c8fbd904df3e 396 spo2 = (rsp[ptr+10] << 8) + rsp[ptr+11];
phonemacro 33:c8fbd904df3e 397 spo2_compl = rsp[ptr+12];
phonemacro 33:c8fbd904df3e 398
phonemacro 33:c8fbd904df3e 399 spo2_lo = 0; spo2_mo = 0; spo2_lopi = 0; spo2_unrel = 0;
phonemacro 33:c8fbd904df3e 400
phonemacro 33:c8fbd904df3e 401 if (rsp[ptr+13] & 0x01)
phonemacro 33:c8fbd904df3e 402 spo2_lo = 1;
phonemacro 33:c8fbd904df3e 403 if (rsp[ptr+13] & 0x02)
phonemacro 33:c8fbd904df3e 404 spo2_mo = 1;
phonemacro 33:c8fbd904df3e 405 if (rsp[ptr+13] & 0x04)
phonemacro 33:c8fbd904df3e 406 spo2_lopi = 1;
phonemacro 33:c8fbd904df3e 407 if (rsp[ptr+13] & 0x08)
phonemacro 33:c8fbd904df3e 408 spo2_unrel = 1;
phonemacro 33:c8fbd904df3e 409 spo2_state = (0x30 & rsp[ptr+13]) >> 4;
phonemacro 33:c8fbd904df3e 410
phonemacro 33:c8fbd904df3e 411 scd = (0x03 & rsp[ptr+14]);
phonemacro 33:c8fbd904df3e 412 act = (0x1C & rsp[ptr+14]) >> 2;
phonemacro 33:c8fbd904df3e 413 inappro_ori = (0x20 & rsp[ptr+14]) >> 5;
phonemacro 33:c8fbd904df3e 414
phonemacro 33:c8fbd904df3e 415 ibi_offset = rsp[ptr+15];
phonemacro 33:c8fbd904df3e 416
phonemacro 33:c8fbd904df3e 417 sptr += (TTL_SZ);
phonemacro 37:249b548e6488 418 #if defined(PCK_CFG_MASK) // hex out, for printing config masked out packed data
phonemacro 35:67699bdae57e 419 // print as hex bytes
phonemacro 35:67699bdae57e 420 for (j=0; j<ALGO_SZ; j++)
phonemacro 35:67699bdae57e 421 pc.printf("%02X ", rsp[ptr+j]);
phonemacro 36:a6e7ff9c87a0 422 //pc.printf("\n\r" );
phonemacro 35:67699bdae57e 423 #endif
phonemacro 35:67699bdae57e 424
phonemacro 37:249b548e6488 425 #if !defined(PCK_CFG_MASK)
phonemacro 37:249b548e6488 426 #if 1
phonemacro 37:249b548e6488 427 #if 1 // print all
phonemacro 33:c8fbd904df3e 428 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 429 heading_printed = 1;
phonemacro 37:249b548e6488 430 #if defined(ALGO_ONLY)
phonemacro 33:c8fbd904df3e 431 pc.printf("opmode,hr,hr_conf,ibi,ibi_conf,act,r,spo2_conf,spo2,spo2_compl,spo2_lo,spo2_mo,spo2_lopi,spo2_unrel,spo2_state,scd,ibioffset,inappro_ori,\n\r");
phonemacro 37:249b548e6488 432 #endif
phonemacro 33:c8fbd904df3e 433 }
phonemacro 33:c8fbd904df3e 434 pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi);
phonemacro 33:c8fbd904df3e 435 pc.printf("%d,%d,%d,%d,", ibi_conf, act, r, spo2_conf);
phonemacro 33:c8fbd904df3e 436 pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo);
phonemacro 33:c8fbd904df3e 437 pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state, scd);
phonemacro 33:c8fbd904df3e 438 pc.printf("%d,", ibi_offset);
phonemacro 33:c8fbd904df3e 439 pc.printf("%d,", inappro_ori);
phonemacro 61:a2e73c5b87e7 440 #endif
phonemacro 37:249b548e6488 441 #else // print some
phonemacro 33:c8fbd904df3e 442 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 443 heading_printed = 1;
phonemacro 37:249b548e6488 444 #if defined(ALGO_ONLY)
phonemacro 54:2f19a5a83a62 445 pc.printf("hr,hr_conf,r,spo2,spo2_conf,spo2_lo,spo2_mo,spo2_lopi,spo2_unrel,spo2_state,scd,\n\r");
phonemacro 37:249b548e6488 446 #endif
phonemacro 33:c8fbd904df3e 447 }
phonemacro 51:e2214db671c0 448 pc.printf("%d,%d,%d", hr, hr_conf, r);
phonemacro 33:c8fbd904df3e 449 pc.printf("%d,%d,", spo2, spo2_conf);
phonemacro 54:2f19a5a83a62 450 pc.printf("%d,%d,", spo2_lo,spo2_mo);
phonemacro 53:034f646141ae 451 pc.printf("%d,%d,%d,%d", spo2_lopi,spo2_unrel, spo2_state, scd);
phonemacro 37:249b548e6488 452 #endif
phonemacro 37:249b548e6488 453 #endif // #if defined(PCK_CFG_MASK)
phonemacro 37:249b548e6488 454
phonemacro 12:17a0bf823462 455 #else // normal algo size
phonemacro 12:17a0bf823462 456 // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ);
phonemacro 12:17a0bf823462 457 opmode = rsp[ptr];
phonemacro 12:17a0bf823462 458 hr = (rsp[ptr+1] << 8) + rsp[ptr+2];
phonemacro 12:17a0bf823462 459 hr_conf = rsp[ptr+3];
phonemacro 12:17a0bf823462 460 ibi = (rsp[ptr+4] << 8) + rsp[ptr+5];
phonemacro 4:4f1e9439f048 461
phonemacro 11:a16b6bf38841 462 ibi_conf = rsp[ptr+6];
phonemacro 3:da975696b936 463 act = rsp[ptr+7];
phonemacro 3:da975696b936 464 r = (rsp[ptr+8] << 8) + rsp[ptr+9];
phonemacro 0:6f65cae31c54 465 spo2_conf = rsp[ptr+10];
phonemacro 4:4f1e9439f048 466
phonemacro 0:6f65cae31c54 467 spo2 = (rsp[ptr+11] << 8) + rsp[ptr+12];
phonemacro 4:4f1e9439f048 468 spo2_compl = rsp[ptr+13];
phonemacro 4:4f1e9439f048 469 spo2_lo = rsp[ptr+14];
phonemacro 4:4f1e9439f048 470 spo2_mo = rsp[ptr+15];
phonemacro 4:4f1e9439f048 471
phonemacro 4:4f1e9439f048 472 spo2_lopi = rsp[ptr+16];
phonemacro 4:4f1e9439f048 473 spo2_unrel = rsp[ptr+17];
phonemacro 4:4f1e9439f048 474 spo2_state = rsp[ptr+18];
phonemacro 2:563d90a111b3 475 scd = rsp[ptr+19];
phonemacro 0:6f65cae31c54 476
phonemacro 36:a6e7ff9c87a0 477 // ibi_offset = rsp[ptr+20];
phonemacro 0:6f65cae31c54 478
phonemacro 4:4f1e9439f048 479 sptr += (TTL_SZ);
phonemacro 61:a2e73c5b87e7 480
phonemacro 27:a45d6e38f2de 481 #if 0
phonemacro 33:c8fbd904df3e 482 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 483 heading_printed = 1;
phonemacro 36:a6e7ff9c87a0 484 #if defined(ALGO_ONLY)
phonemacro 33:c8fbd904df3e 485 pc.printf("opmode,hr,hr_conf,ibi,ibi_conf,act,r,spo2_conf,spo2,spo2_compl,spo2_lo,spo2_mo,spo2_lopi,spo2_unrel,spo2_state,scd,ibioffset,\n\r");
phonemacro 36:a6e7ff9c87a0 486 #endif
phonemacro 33:c8fbd904df3e 487 }
phonemacro 4:4f1e9439f048 488 pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi);
phonemacro 4:4f1e9439f048 489 pc.printf("%d,%d,%d,%d,", ibi_conf, act, r, spo2_conf);
phonemacro 4:4f1e9439f048 490 pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo);
phonemacro 4:4f1e9439f048 491 pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state, scd);
phonemacro 36:a6e7ff9c87a0 492 // pc.printf("%d,", ibi_offset);
phonemacro 4:4f1e9439f048 493 #else
phonemacro 33:c8fbd904df3e 494 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 495 heading_printed = 1;
phonemacro 36:a6e7ff9c87a0 496 #if defined(ALGO_ONLY)
phonemacro 54:2f19a5a83a62 497 pc.printf("hr,hr_conf,r,spo2,spo2_conf,spo2_lo,spo2_mo,spo2_lopi,spo2_unrel,spo2_state,scd,\n\r");
phonemacro 36:a6e7ff9c87a0 498 #endif
phonemacro 33:c8fbd904df3e 499 }
phonemacro 51:e2214db671c0 500 pc.printf("%d,%d,%d,", hr, hr_conf, r);
phonemacro 4:4f1e9439f048 501 pc.printf("%d,%d,", spo2, spo2_conf);
phonemacro 54:2f19a5a83a62 502 pc.printf("%d,%d,", spo2_lo,spo2_mo);
phonemacro 53:034f646141ae 503 pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel,spo2_state, scd);
phonemacro 4:4f1e9439f048 504 #endif
phonemacro 12:17a0bf823462 505 #endif // end normal algo size
phonemacro 61:a2e73c5b87e7 506 #endif // !RAW
phonemacro 4:4f1e9439f048 507
phonemacro 3:da975696b936 508 pc.printf("\n\r");
phonemacro 0:6f65cae31c54 509 }
phonemacro 0:6f65cae31c54 510 }
phonemacro 0:6f65cae31c54 511
phonemacro 6:e1b7190d6cb5 512 #ifdef MAXREFDES103_CFG
phonemacro 14:c8cc6d7fd5f9 513 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 514 // init_max20303_pmic
phonemacro 14:c8cc6d7fd5f9 515 /*****************************************************************************/
phonemacro 6:e1b7190d6cb5 516 void init_max20303_pmic(void) {
phonemacro 5:7f5a012747a5 517 /* Wait for pmic to settle down */
phonemacro 5:7f5a012747a5 518 thread_sleep_for(800);
phonemacro 5:7f5a012747a5 519
phonemacro 5:7f5a012747a5 520 //set_time(1544787300); // Set RTC time to Wed, 28 Oct 2009 11:35:37
phonemacro 6:e1b7190d6cb5 521 MAX20303 max20303(&sh_i2c);
phonemacro 5:7f5a012747a5 522 /*Set LDO1 to 1.8v*/
phonemacro 5:7f5a012747a5 523 max20303.LDO1Config();
phonemacro 5:7f5a012747a5 524
phonemacro 5:7f5a012747a5 525 /*Set LDO2 to 3v*/
phonemacro 5:7f5a012747a5 526 max20303.LDO2Config();
phonemacro 5:7f5a012747a5 527
phonemacro 5:7f5a012747a5 528 //max20303.BoostEnable();
phonemacro 5:7f5a012747a5 529 max20303.BuckBoostEnable();
phonemacro 5:7f5a012747a5 530
phonemacro 5:7f5a012747a5 531 max20303.led0on(0);
phonemacro 5:7f5a012747a5 532 max20303.led1on(0);
phonemacro 5:7f5a012747a5 533 max20303.led2on(0);
phonemacro 5:7f5a012747a5 534
phonemacro 5:7f5a012747a5 535 /* Wait for pmic to settle down */
phonemacro 5:7f5a012747a5 536 thread_sleep_for(200);
phonemacro 28:315604f4b374 537
phonemacro 5:7f5a012747a5 538 }
phonemacro 6:e1b7190d6cb5 539 #endif // MAXREFDES103_CFG
phonemacro 14:c8cc6d7fd5f9 540
phonemacro 61:a2e73c5b87e7 541 /*****************************************************************************/
phonemacro 61:a2e73c5b87e7 542 // init_sh_algo
phonemacro 61:a2e73c5b87e7 543 /*****************************************************************************/
phonemacro 61:a2e73c5b87e7 544 void init_sh_algo(void) {
phonemacro 61:a2e73c5b87e7 545 char cmd[64];
phonemacro 61:a2e73c5b87e7 546 char rsp[256];
phonemacro 61:a2e73c5b87e7 547
phonemacro 61:a2e73c5b87e7 548 #ifdef OPTIMIZE_FIFO_READ
phonemacro 61:a2e73c5b87e7 549 check_fifo_countdown = MAX_FIFO_CNT;
phonemacro 61:a2e73c5b87e7 550 #endif
phonemacro 61:a2e73c5b87e7 551
phonemacro 10:192ea88e964b 552 // switch to application mode
phonemacro 0:6f65cae31c54 553 rst = 0;
phonemacro 0:6f65cae31c54 554 mfio = 1;
phonemacro 0:6f65cae31c54 555 thread_sleep_for(10);
phonemacro 0:6f65cae31c54 556 rst = 1;
phonemacro 0:6f65cae31c54 557 thread_sleep_for(1500);
phonemacro 10:192ea88e964b 558 #ifdef MAXREFDES103_CFG
phonemacro 10:192ea88e964b 559 init_max20303_pmic();
phonemacro 10:192ea88e964b 560 #endif
phonemacro 47:346a13fbdc0f 561 // 33.13.31 needs at least 1.6s
phonemacro 47:346a13fbdc0f 562 // thread_sleep_for(100);
phonemacro 0:6f65cae31c54 563
phonemacro 1:da792e46a385 564 mfio = 0; wait_us(300);
phonemacro 42:6f980909371f 565 #ifdef REDUCE_RPT_PERIOD
phonemacro 42:6f980909371f 566 //Change report period to 25
phonemacro 61:a2e73c5b87e7 567 cmd[0] = 0x10; cmd[1] = 0x02; cmd[2] = REDUCE_RPT_PERIOD;
phonemacro 42:6f980909371f 568 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 42:6f980909371f 569 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 42:6f980909371f 570 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 42:6f980909371f 571 mfio = 1; mfio = 0; wait_us(300);
phonemacro 42:6f980909371f 572 pc.printf("Wr report period 25 %x\n\r", rsp[0]);
phonemacro 42:6f980909371f 573 #endif
phonemacro 48:6b93b56bb22e 574 //1.10 rd ver
phonemacro 4:4f1e9439f048 575 cmd[0] = 0xFF; cmd[1] = 0x03;
phonemacro 6:e1b7190d6cb5 576 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 1:da792e46a385 577 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 578 sh_i2c.read(SH_ADDR, rsp, 4);
phonemacro 1:da792e46a385 579 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 580 pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]);
phonemacro 0:6f65cae31c54 581
phonemacro 35:67699bdae57e 582 // wr config mask for packed normal data output fifo
phonemacro 37:249b548e6488 583 #if defined(PCK_CFG_MASK)
phonemacro 37:249b548e6488 584 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x20; cmd[3] = 0x7F; cmd[4] = 0xFF; cmd[5] = 0x00;
phonemacro 44:1b165a68474d 585 // cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x20; cmd[3] = 0xFF; cmd[4] = 0xFF; cmd[5] = 0x00;
phonemacro 35:67699bdae57e 586 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 35:67699bdae57e 587 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 588 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 35:67699bdae57e 589 mfio = 1; mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 590 pc.printf("wr config mask packed: %x \n\r", rsp[0]);
phonemacro 35:67699bdae57e 591 // rd config mask for packed normal data output fifo
phonemacro 35:67699bdae57e 592 cmd[0] = 0x51; cmd[1] = 0x07; cmd[2] = 0x20;
phonemacro 35:67699bdae57e 593 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 35:67699bdae57e 594 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 595 sh_i2c.read(SH_ADDR, rsp, 4);
phonemacro 35:67699bdae57e 596 mfio = 1; mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 597 pc.printf("rd config mask for packed normal data output fifo %d %X %X %X \n\r", rsp[0], rsp[1], rsp[2], rsp[3]);
phonemacro 44:1b165a68474d 598 #endif
phonemacro 35:67699bdae57e 599
phonemacro 33:c8fbd904df3e 600 #if defined(MAXM86161_CFG) || defined(MAXM86146_CFG)
phonemacro 33:c8fbd904df3e 601 // rd algo sz normal
phonemacro 17:0d6e99a0fd8d 602 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x01;
phonemacro 17:0d6e99a0fd8d 603 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 17:0d6e99a0fd8d 604 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 605 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 17:0d6e99a0fd8d 606 mfio = 1; mfio = 0; wait_us(300);
phonemacro 33:c8fbd904df3e 607 pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 33:c8fbd904df3e 608 // rd algo sz extended
phonemacro 17:0d6e99a0fd8d 609 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x02;
phonemacro 17:0d6e99a0fd8d 610 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 17:0d6e99a0fd8d 611 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 612 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 17:0d6e99a0fd8d 613 mfio = 1; mfio = 0; wait_us(300);
phonemacro 33:c8fbd904df3e 614 pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 33:c8fbd904df3e 615 // rd algo sz scd
phonemacro 17:0d6e99a0fd8d 616 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x03;
phonemacro 17:0d6e99a0fd8d 617 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 17:0d6e99a0fd8d 618 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 619 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 17:0d6e99a0fd8d 620 mfio = 1; mfio = 0; wait_us(300);
phonemacro 33:c8fbd904df3e 621 pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 45:d26b8bcce561 622 #if defined(PACKED_NORMAL_ALGO) && (defined(MAXM86161_CFG) || defined(MAXM86146_CFG))
phonemacro 35:67699bdae57e 623 // rd algo sz packed normal
phonemacro 33:c8fbd904df3e 624 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x04;
phonemacro 33:c8fbd904df3e 625 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 33:c8fbd904df3e 626 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 33:c8fbd904df3e 627 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 33:c8fbd904df3e 628 mfio = 1; mfio = 0; wait_us(300);
phonemacro 33:c8fbd904df3e 629 pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 33:c8fbd904df3e 630 #endif
phonemacro 17:0d6e99a0fd8d 631 #endif
phonemacro 17:0d6e99a0fd8d 632
phonemacro 17:0d6e99a0fd8d 633 #if 0
phonemacro 17:0d6e99a0fd8d 634 // set Perfusion Index threshold to .05 (3x.13.19+)
phonemacro 17:0d6e99a0fd8d 635 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x1D; cmd[3] = 50;
phonemacro 16:ff1122f0624a 636 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 16:ff1122f0624a 637 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 16:ff1122f0624a 638 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 16:ff1122f0624a 639 mfio = 1; mfio = 0; wait_us(300);
phonemacro 16:ff1122f0624a 640 pc.printf("pi set to 0x19 : %x \n\r", rsp[0]);
phonemacro 17:0d6e99a0fd8d 641 #endif
phonemacro 16:ff1122f0624a 642
phonemacro 48:6b93b56bb22e 643 // 1.1 sensor and algo data
phonemacro 4:4f1e9439f048 644 cmd[0] = 0x10; cmd[1] = 0x00;
phonemacro 2:563d90a111b3 645 #ifdef ALGO_ONLY
phonemacro 0:6f65cae31c54 646 cmd[2] = 0x02; // algo data
phonemacro 4:4f1e9439f048 647 pc.printf("algo only \n\r");
phonemacro 2:563d90a111b3 648 #else
phonemacro 2:563d90a111b3 649 cmd[2] = 0x03; // sensor + algo data
phonemacro 4:4f1e9439f048 650 pc.printf("sens+algo \n\r");
phonemacro 2:563d90a111b3 651 #endif
phonemacro 6:e1b7190d6cb5 652 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 1:da792e46a385 653 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 654 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 655 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 656 pc.printf("1.2 Status: %x\n\r", rsp[0]);
phonemacro 52:e5aba237e804 657 // 1.4 Continuous HR, Spo2
phonemacro 52:e5aba237e804 658 #ifndef SPO2_CAL_RPT
phonemacro 32:92adfbe18ab6 659 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0A; cmd[3] = 0x00;
phonemacro 32:92adfbe18ab6 660 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 32:92adfbe18ab6 661 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 662 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 32:92adfbe18ab6 663 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 664 pc.printf("1.5 Status: %x\n\r", rsp[0]);
phonemacro 52:e5aba237e804 665 #endif
phonemacro 48:6b93b56bb22e 666 // 1.5 AEC enable (default)
phonemacro 4:4f1e9439f048 667 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0B; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 668 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 1:da792e46a385 669 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 670 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 671 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 672 pc.printf("1.6 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 673 #if AGC
phonemacro 48:6b93b56bb22e 674 // AGC 1.6 Disable auto PD (default
phonemacro 13:1baccc6275a7 675 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x12; cmd[3] = 0x00;
phonemacro 13:1baccc6275a7 676 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 13:1baccc6275a7 677 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 678 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 13:1baccc6275a7 679 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 680 pc.printf("AGC1.7 Status: %x\n\r", rsp[0]);
phonemacro 48:6b93b56bb22e 681 // AGC 1.7 Disable SCD (default)
phonemacro 13:1baccc6275a7 682 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0C; cmd[3] = 0x00;
phonemacro 13:1baccc6275a7 683 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 13:1baccc6275a7 684 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 685 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 13:1baccc6275a7 686 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 687 pc.printf("AGC1.8 Status: %x\n\r", rsp[0]);
phonemacro 48:6b93b56bb22e 688 // AGC 1.8 Set AGC target PD TO 10uA
phonemacro 13:1baccc6275a7 689 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x11; cmd[3] = 0x00; cmd[3] = 0x64;
phonemacro 13:1baccc6275a7 690 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 13:1baccc6275a7 691 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 692 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 13:1baccc6275a7 693 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 694 pc.printf("AGC1.9 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 695 #else
phonemacro 48:6b93b56bb22e 696 // 1.6 enable auto PD (default)
phonemacro 4:4f1e9439f048 697 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x12; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 698 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 1:da792e46a385 699 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 700 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 701 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 702 pc.printf("1.7 Status: %x\n\r", rsp[0]);
phonemacro 48:6b93b56bb22e 703 // 1.7 SCD (default)
phonemacro 4:4f1e9439f048 704 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0C; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 705 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 4:4f1e9439f048 706 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 707 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 4:4f1e9439f048 708 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 709 pc.printf("1.8 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 710 #endif
phonemacro 28:315604f4b374 711
phonemacro 28:315604f4b374 712 #if defined(MAXM86161_CFG) //only use Red and IR
phonemacro 61:a2e73c5b87e7 713 //1.20 map leds to slots
phonemacro 28:315604f4b374 714 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x23; cmd[4] = 0x00; cmd[5] = 0x00;
phonemacro 28:315604f4b374 715 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 28:315604f4b374 716 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 717 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 718 mfio = 1; mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 719 pc.printf("map leds to slots %x\n\r", rsp[0]);
phonemacro 30:77a30ea425da 720 //1.21 map HR inputs to slots, default is 0x0073 for MAXM86161
phonemacro 30:77a30ea425da 721 #if 0 // NA for MAXM86161
phonemacro 28:315604f4b374 722 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x73;
phonemacro 28:315604f4b374 723 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 28:315604f4b374 724 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 725 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 726 mfio = 1; mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 727 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 30:77a30ea425da 728 #endif
phonemacro 28:315604f4b374 729 //1.22 map SpO2 inputs to slots
phonemacro 28:315604f4b374 730 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x00; cmd[4] = 0x10;
phonemacro 28:315604f4b374 731 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 28:315604f4b374 732 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 733 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 734 mfio = 1; mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 735 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 28:315604f4b374 736 #endif
phonemacro 28:315604f4b374 737
phonemacro 3:da975696b936 738 #ifdef MAXM86146_CFG
phonemacro 32:92adfbe18ab6 739 //1.20 map leds to slots for MAXM86146
phonemacro 4:4f1e9439f048 740 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x13; cmd[4] = 0x56; cmd[5] = 0x00;
phonemacro 6:e1b7190d6cb5 741 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 3:da975696b936 742 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 743 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 744 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 745 pc.printf("map leds to slots %x\n\r", rsp[0]);
phonemacro 3:da975696b936 746 //1.21 map HR inputs to slots
phonemacro 4:4f1e9439f048 747 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x11;
phonemacro 6:e1b7190d6cb5 748 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 3:da975696b936 749 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 750 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 751 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 752 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 3:da975696b936 753 //1.22 map SpO2 inputs to slots
phonemacro 4:4f1e9439f048 754 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x30; cmd[4] = 0x20;
phonemacro 6:e1b7190d6cb5 755 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 3:da975696b936 756 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 757 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 758 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 759 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 26:33c0d3fd2a95 760
phonemacro 3:da975696b936 761 #if 0
phonemacro 2:563d90a111b3 762 //1.20 Sec 4.1 map leds to slots for MAXM86146
phonemacro 4:4f1e9439f048 763 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x15; cmd[4] = 0x60; cmd[5] = 0x00;
phonemacro 6:e1b7190d6cb5 764 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 1:da792e46a385 765 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 766 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 767 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 768 pc.printf("map leds to slots%x\n\r", rsp[0]);
phonemacro 2:563d90a111b3 769 //1.21 map HR inputs to slots
phonemacro 4:4f1e9439f048 770 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x01;
phonemacro 6:e1b7190d6cb5 771 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 1:da792e46a385 772 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 773 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 774 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 775 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 2:563d90a111b3 776 //1.22 map SpO2 inputs to slots
phonemacro 4:4f1e9439f048 777 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x20; cmd[4] = 0x10;
phonemacro 6:e1b7190d6cb5 778 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 1:da792e46a385 779 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 780 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 781 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 782 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 3:da975696b936 783 #endif
phonemacro 3:da975696b936 784 #endif // MAXM86146_CFG
phonemacro 0:6f65cae31c54 785
phonemacro 28:315604f4b374 786 #if 0 // MAXM86161 test new commands
phonemacro 28:315604f4b374 787 // LDO enable
phonemacro 28:315604f4b374 788 cmd[0] = 0x10; cmd[1] = 0x12; cmd[2] = 0x01;
phonemacro 28:315604f4b374 789 //cmd[0] = 0x10; cmd[1] = 0x12; cmd[2] = 0x00;
phonemacro 28:315604f4b374 790 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 28:315604f4b374 791 thread_sleep_for(2);
phonemacro 28:315604f4b374 792 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 793 pc.printf("\n\r ldo en %x\n\r", rsp[0]);
phonemacro 28:315604f4b374 794 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 795 // GPIO enable
phonemacro 28:315604f4b374 796 cmd[0] = 0x10; cmd[1] = 0x13; cmd[2] = 0x01;
phonemacro 28:315604f4b374 797 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 28:315604f4b374 798 thread_sleep_for(2);
phonemacro 28:315604f4b374 799 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 800 pc.printf("\n\r gpio en %x\n\r", rsp[0]);
phonemacro 28:315604f4b374 801 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 802 #endif
phonemacro 47:346a13fbdc0f 803 #if 0
phonemacro 47:346a13fbdc0f 804 //write SpO2 coefficients 0x00000000 FFD7FBDD 00AB61FE
phonemacro 61:a2e73c5b87e7 805 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x00;
phonemacro 47:346a13fbdc0f 806 cmd[3] = 0x00; cmd[4] = 0x00; cmd[5] = 0x00; cmd[6] = 0x00;
phonemacro 47:346a13fbdc0f 807 cmd[7] = 0xFF; cmd[8] = 0xD7; cmd[9] = 0xFB; cmd[10] = 0xDD;
phonemacro 47:346a13fbdc0f 808 cmd[11] = 0x00; cmd[12] = 0xAB; cmd[13] = 0x61; cmd[14] = 0xFE;
phonemacro 47:346a13fbdc0f 809 sh_i2c.write(SH_ADDR, cmd, 15);
phonemacro 47:346a13fbdc0f 810 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 47:346a13fbdc0f 811 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 47:346a13fbdc0f 812 mfio = 1; mfio = 0; wait_us(300);
phonemacro 47:346a13fbdc0f 813 pc.printf("Wr Spo2 Coeff %x\n\r", rsp[0]);
phonemacro 47:346a13fbdc0f 814 #endif
phonemacro 61:a2e73c5b87e7 815 //1.26 rd SpO2 Coefficients
phonemacro 47:346a13fbdc0f 816 cmd[0] = 0x51; cmd[1] = 0x07; cmd[2] = 0x00;
phonemacro 47:346a13fbdc0f 817 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 47:346a13fbdc0f 818 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 47:346a13fbdc0f 819 sh_i2c.read(SH_ADDR, rsp, 13);
phonemacro 47:346a13fbdc0f 820 mfio = 1; mfio = 0; wait_us(300);
phonemacro 47:346a13fbdc0f 821 pc.printf("%x SpO2 Coeff %2X%2X%2X%2X %2X%2X%2X%2X %2X%2X%2X%2X\n\r", rsp[0], rsp[1], rsp[2], rsp[3], rsp[4], rsp[5], rsp[6], rsp[7], rsp[8], rsp[9], rsp[10], rsp[11], rsp[12]);
phonemacro 28:315604f4b374 822
phonemacro 32:92adfbe18ab6 823 // 1.30 Enable HR, SpO2 algo
phonemacro 12:17a0bf823462 824 #ifdef EXTENDED_ALGO
phonemacro 12:17a0bf823462 825 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x02;
phonemacro 33:c8fbd904df3e 826 #elif defined(PACKED_NORMAL_ALGO)
phonemacro 33:c8fbd904df3e 827 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x04;
phonemacro 12:17a0bf823462 828 #else
phonemacro 4:4f1e9439f048 829 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x01;
phonemacro 12:17a0bf823462 830 #endif
phonemacro 6:e1b7190d6cb5 831 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 28:315604f4b374 832 mfio = 1;
phonemacro 0:6f65cae31c54 833 thread_sleep_for(465);
phonemacro 28:315604f4b374 834 mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 835 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 836 pc.printf("1.14 status: %x\n\r", rsp[0]);
phonemacro 0:6f65cae31c54 837
phonemacro 4:4f1e9439f048 838 #if 1
phonemacro 4:4f1e9439f048 839 //1.31 rd AFE part id
phonemacro 4:4f1e9439f048 840 cmd[0] = 0x41; cmd[1] = 0x00; cmd[2] = 0xFF;
phonemacro 6:e1b7190d6cb5 841 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 4:4f1e9439f048 842 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 843 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 4:4f1e9439f048 844 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 845 pc.printf("1.31 part id afe %x %x\n\r", rsp[0], rsp[1]);
phonemacro 4:4f1e9439f048 846 //1.32 rd accel who
phonemacro 4:4f1e9439f048 847 cmd[0] = 0x41; cmd[1] = 0x04; cmd[2] = 0x0F;
phonemacro 6:e1b7190d6cb5 848 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 4:4f1e9439f048 849 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 850 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 4:4f1e9439f048 851 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 852 pc.printf("1.32 who accel %x %x\n\r", rsp[0], rsp[1]);
phonemacro 28:315604f4b374 853 #endif
phonemacro 52:e5aba237e804 854 // 1.35 spo2 calibration report for data collection
phonemacro 52:e5aba237e804 855 #ifdef SPO2_CAL_RPT
phonemacro 52:e5aba237e804 856 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0A; cmd[3] = 0x06;
phonemacro 52:e5aba237e804 857 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 52:e5aba237e804 858 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 52:e5aba237e804 859 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 52:e5aba237e804 860 mfio = 1; mfio = 0; wait_us(300);
phonemacro 52:e5aba237e804 861 pc.printf("1.5 Status: %x\n\r", rsp[0]);
phonemacro 52:e5aba237e804 862 #endif
phonemacro 52:e5aba237e804 863 // rd algo mode
phonemacro 52:e5aba237e804 864 cmd[0] = 0x51; cmd[1] = 0x07; cmd[2] = 0x0A;
phonemacro 52:e5aba237e804 865 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 52:e5aba237e804 866 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 52:e5aba237e804 867 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 52:e5aba237e804 868 mfio = 1; mfio = 0; wait_us(300);
phonemacro 52:e5aba237e804 869 pc.printf("algo mode %x %x\n\r", rsp[0], rsp[1]);
phonemacro 52:e5aba237e804 870
phonemacro 26:33c0d3fd2a95 871 mfio = 1;
phonemacro 10:192ea88e964b 872 }
phonemacro 10:192ea88e964b 873
phonemacro 61:a2e73c5b87e7 874
phonemacro 61:a2e73c5b87e7 875 void set_reg_opt_validation(void) {
phonemacro 61:a2e73c5b87e7 876 char cmd[16];
phonemacro 61:a2e73c5b87e7 877 char rsp[32];
phonemacro 61:a2e73c5b87e7 878
phonemacro 61:a2e73c5b87e7 879 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x09; cmd[3] = 0x7D; // fifo_a_full
phonemacro 61:a2e73c5b87e7 880 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 881 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 882 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 883 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 884 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 885
phonemacro 61:a2e73c5b87e7 886 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x11; cmd[3] = 0x3F; // ppg2_adc_rge=32768 ppg1_adc_rge=32768 tint=117.3us
phonemacro 61:a2e73c5b87e7 887 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 888 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 889 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 890 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 891 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 892
phonemacro 61:a2e73c5b87e7 893 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x13; cmd[3] = 0xC0; // reg ppg config 3
phonemacro 61:a2e73c5b87e7 894 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 895 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 896 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 897 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 898 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 899
phonemacro 61:a2e73c5b87e7 900 #if 0
phonemacro 61:a2e73c5b87e7 901 // set seq1 reg
phonemacro 61:a2e73c5b87e7 902 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x20; cmd[3] = 0x21;
phonemacro 61:a2e73c5b87e7 903 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 904 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 905 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 906 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 907 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 908
phonemacro 61:a2e73c5b87e7 909 // set seq2 reg
phonemacro 61:a2e73c5b87e7 910 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x21; cmd[3] = 0x43;
phonemacro 61:a2e73c5b87e7 911 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 912 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 913 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 914 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 915 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 916 // always set seq3 reg to none
phonemacro 61:a2e73c5b87e7 917 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x22; cmd[3] = 0x00;
phonemacro 61:a2e73c5b87e7 918 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 919 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 920 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 921 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 922 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 923 #endif
phonemacro 61:a2e73c5b87e7 924
phonemacro 61:a2e73c5b87e7 925 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x09; cmd[3] = 0x7D;
phonemacro 61:a2e73c5b87e7 926 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 927 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 928 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 929 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 930 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 931
phonemacro 61:a2e73c5b87e7 932 #if defined(MAXM86161_OPT_VALIDATION_GRN)
phonemacro 61:a2e73c5b87e7 933 // Set Green1 current to 1uA, 10uA or 30uA
phonemacro 61:a2e73c5b87e7 934 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x23; cmd[3] = 0xA7;
phonemacro 61:a2e73c5b87e7 935 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 936 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 937 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 938 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 939 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 940
phonemacro 61:a2e73c5b87e7 941 // Set LED2 current
phonemacro 61:a2e73c5b87e7 942 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x24; cmd[3] = 0x0;
phonemacro 61:a2e73c5b87e7 943 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 944 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 945 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 946 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 947 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 948
phonemacro 61:a2e73c5b87e7 949 // Set Green2 current
phonemacro 61:a2e73c5b87e7 950 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x25; cmd[3] = 0x0;
phonemacro 61:a2e73c5b87e7 951 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 952 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 953 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 954 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 955 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 956
phonemacro 61:a2e73c5b87e7 957 // Set LED4 current
phonemacro 61:a2e73c5b87e7 958 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x26; cmd[3] = 0x0;
phonemacro 61:a2e73c5b87e7 959 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 960 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 961 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 962 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 963 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 964
phonemacro 61:a2e73c5b87e7 965 // Set Red current
phonemacro 61:a2e73c5b87e7 966 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x27; cmd[3] = 0x0;
phonemacro 61:a2e73c5b87e7 967 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 968 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 969 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 970 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 971 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 972
phonemacro 61:a2e73c5b87e7 973 // Set IR current
phonemacro 61:a2e73c5b87e7 974 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x28; cmd[3] = 0x0;
phonemacro 61:a2e73c5b87e7 975 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 976 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 977 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 978 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 979 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 980 #endif
phonemacro 61:a2e73c5b87e7 981 #if defined(MAXM86161_OPT_VALIDATION_IR)
phonemacro 61:a2e73c5b87e7 982 // Set Green current
phonemacro 61:a2e73c5b87e7 983 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x23; cmd[3] = 0x0;
phonemacro 61:a2e73c5b87e7 984 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 985 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 986 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 987 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 988 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 989
phonemacro 61:a2e73c5b87e7 990 // Set IR current to 1uA, 10uA or 30uA
phonemacro 61:a2e73c5b87e7 991 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x24; cmd[3] = 0xA7;
phonemacro 61:a2e73c5b87e7 992 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 993 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 994 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 995 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 996 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 997
phonemacro 61:a2e73c5b87e7 998 // Set Red current
phonemacro 61:a2e73c5b87e7 999 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x25; cmd[3] = 0x0;
phonemacro 61:a2e73c5b87e7 1000 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 1001 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1002 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 1003 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1004 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 1005 #endif
phonemacro 61:a2e73c5b87e7 1006
phonemacro 61:a2e73c5b87e7 1007 #if defined(MAXM86161_OPT_VALIDATION_RED)
phonemacro 61:a2e73c5b87e7 1008 // Set Green current
phonemacro 61:a2e73c5b87e7 1009 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x23; cmd[3] = 0x0;
phonemacro 61:a2e73c5b87e7 1010 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 1011 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1012 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 1013 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1014 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 1015
phonemacro 61:a2e73c5b87e7 1016 // Set IR current
phonemacro 61:a2e73c5b87e7 1017 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x24; cmd[3] = 0x0;
phonemacro 61:a2e73c5b87e7 1018 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 1019 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1020 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 1021 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1022 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 1023
phonemacro 61:a2e73c5b87e7 1024 // Set Red current to 1uA, 10uA or 30uA
phonemacro 61:a2e73c5b87e7 1025 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x25; cmd[3] = 0xA7;
phonemacro 61:a2e73c5b87e7 1026 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 1027 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1028 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 1029 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1030 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 1031
phonemacro 61:a2e73c5b87e7 1032 #endif
phonemacro 61:a2e73c5b87e7 1033 #if defined(MAXM86161_OPT_VALIDATION_XTALK)
phonemacro 61:a2e73c5b87e7 1034 // Set Green current
phonemacro 61:a2e73c5b87e7 1035 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x23; cmd[3] = 0xFF;
phonemacro 61:a2e73c5b87e7 1036 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 1037 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1038 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 1039 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1040 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 1041
phonemacro 61:a2e73c5b87e7 1042 // Set IR current to 1uA, 10uA or 30uA
phonemacro 61:a2e73c5b87e7 1043 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x24; cmd[3] = 0xFF;
phonemacro 61:a2e73c5b87e7 1044 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 1045 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1046 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 1047 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1048 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 1049
phonemacro 61:a2e73c5b87e7 1050 // Set Red current
phonemacro 61:a2e73c5b87e7 1051 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x25; cmd[3] = 0xFF;
phonemacro 61:a2e73c5b87e7 1052 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 1053 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1054 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 1055 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1056 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 1057 #endif
phonemacro 61:a2e73c5b87e7 1058
phonemacro 61:a2e73c5b87e7 1059 // configure LED Range
phonemacro 61:a2e73c5b87e7 1060 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x2A; cmd[3] = 0x3F;
phonemacro 61:a2e73c5b87e7 1061 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 61:a2e73c5b87e7 1062 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1063 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 61:a2e73c5b87e7 1064 mfio = 1; mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1065 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 61:a2e73c5b87e7 1066
phonemacro 61:a2e73c5b87e7 1067
phonemacro 61:a2e73c5b87e7 1068 }
phonemacro 61:a2e73c5b87e7 1069
phonemacro 14:c8cc6d7fd5f9 1070 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 1071 // init_sh_raw
phonemacro 14:c8cc6d7fd5f9 1072 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 1073 void init_sh_raw(void) {
phonemacro 29:a7dd81450b35 1074 char cmd[16];
phonemacro 14:c8cc6d7fd5f9 1075 char rsp[256];
phonemacro 61:a2e73c5b87e7 1076 // switch to application mode
phonemacro 61:a2e73c5b87e7 1077 rst = 0;
phonemacro 61:a2e73c5b87e7 1078 mfio = 1;
phonemacro 61:a2e73c5b87e7 1079 thread_sleep_for(10);
phonemacro 61:a2e73c5b87e7 1080 rst = 1;
phonemacro 61:a2e73c5b87e7 1081 thread_sleep_for(1500);
phonemacro 61:a2e73c5b87e7 1082 #ifdef MAXREFDES103_CFG
phonemacro 61:a2e73c5b87e7 1083 init_max20303_pmic();
phonemacro 61:a2e73c5b87e7 1084 #endif
phonemacro 14:c8cc6d7fd5f9 1085
phonemacro 14:c8cc6d7fd5f9 1086 mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1087
phonemacro 32:92adfbe18ab6 1088 //1.0 read operating mode
phonemacro 14:c8cc6d7fd5f9 1089 cmd[0] = 0x02; cmd[1] = 0x00;
phonemacro 14:c8cc6d7fd5f9 1090 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 14:c8cc6d7fd5f9 1091 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1092 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 14:c8cc6d7fd5f9 1093 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1094 pc.printf("\n\r 0x02 0x00 Status, Read Operating Mode: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 32:92adfbe18ab6 1095 //1.1 rd ver
phonemacro 14:c8cc6d7fd5f9 1096 cmd[0] = 0xFF; cmd[1] = 0x03;
phonemacro 14:c8cc6d7fd5f9 1097 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 14:c8cc6d7fd5f9 1098 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1099 sh_i2c.read(SH_ADDR, rsp, 4);
phonemacro 14:c8cc6d7fd5f9 1100 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1101 pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]);
phonemacro 14:c8cc6d7fd5f9 1102
phonemacro 32:92adfbe18ab6 1103 // raw1.2 sensor data
phonemacro 14:c8cc6d7fd5f9 1104 cmd[0] = 0x10; cmd[1] = 0x00; cmd[2] = 0x01;
phonemacro 14:c8cc6d7fd5f9 1105 pc.printf("raw sensor data only \n\r");
phonemacro 14:c8cc6d7fd5f9 1106 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 14:c8cc6d7fd5f9 1107 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1108 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1109 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 1110 pc.printf("raw1.2 Status: %x\n\r", rsp[0]);
phonemacro 32:92adfbe18ab6 1111 // raw1.3 interrupt threshold
phonemacro 14:c8cc6d7fd5f9 1112 cmd[0] = 0x10; cmd[1] = 0x01; cmd[2] = 0x01;
phonemacro 14:c8cc6d7fd5f9 1113 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 14:c8cc6d7fd5f9 1114 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1115 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1116 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 1117 pc.printf("raw1.3 Status: %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 1118 #ifdef MAXM86146_CFG
phonemacro 50:dd2f60ab5686 1119 //1.20 map leds to slots for MAXM86146
phonemacro 50:dd2f60ab5686 1120 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x13; cmd[4] = 0x56; cmd[5] = 0x00;
phonemacro 50:dd2f60ab5686 1121 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 50:dd2f60ab5686 1122 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1123 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 50:dd2f60ab5686 1124 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1125 pc.printf("map leds to slots %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 1126 //1.21 map HR inputs to slots
phonemacro 50:dd2f60ab5686 1127 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x11;
phonemacro 50:dd2f60ab5686 1128 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 50:dd2f60ab5686 1129 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1130 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 50:dd2f60ab5686 1131 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1132 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 1133 //1.22 map SpO2 inputs to slots
phonemacro 50:dd2f60ab5686 1134 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x30; cmd[4] = 0x20;
phonemacro 50:dd2f60ab5686 1135 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 50:dd2f60ab5686 1136 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1137 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 50:dd2f60ab5686 1138 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1139 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 1140 #endif
phonemacro 50:dd2f60ab5686 1141
phonemacro 50:dd2f60ab5686 1142 // raw enable sh accel
phonemacro 14:c8cc6d7fd5f9 1143 cmd[0] = 0x44; cmd[1] = 0x04; cmd[2] = 0x01; cmd[3] = 0x00;
phonemacro 14:c8cc6d7fd5f9 1144 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 29:a7dd81450b35 1145 mfio = 1; thread_sleep_for(20); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1146 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 29:a7dd81450b35 1147 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1148 pc.printf("raw1.4 Status: %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 1149 // raw enable AFE
phonemacro 61:a2e73c5b87e7 1150 // cmd[0] = 0x44; cmd[1] = 0x00; cmd[2] = 0x01; cmd[3] = 0x00;
phonemacro 30:77a30ea425da 1151 // sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 38:8ff33869be1f 1152 cmd[0] = 0x44; cmd[1] = 0x00; cmd[2] = 0x01; // 3 bytes // tested on 33.13.31/12
phonemacro 38:8ff33869be1f 1153 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 61:a2e73c5b87e7 1154 // cmd[0] = 0x44; cmd[1] = 0xFF; cmd[2] = 0x02; cmd[3] = 0x04; cmd[4] = 0x01; cmd[5] = 0x00; cmd[6] = 0x00; cmd[7] = 0x01; cmd[8] = 0x00;
phonemacro 55:04c9fad147d4 1155 // sh_i2c.write(SH_ADDR, cmd, 9);
phonemacro 55:04c9fad147d4 1156 mfio = 1; thread_sleep_for(465); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1157 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1158 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 61:a2e73c5b87e7 1159 pc.printf("raw1.6 Status: %x\n\r", rsp[0]);
phonemacro 32:92adfbe18ab6 1160
phonemacro 50:dd2f60ab5686 1161 /// raw 1.20 AFE part id
phonemacro 50:dd2f60ab5686 1162 cmd[0] = 0x41; cmd[1] = 0x00; cmd[2] = 0xFF;
phonemacro 50:dd2f60ab5686 1163 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 50:dd2f60ab5686 1164 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1165 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 50:dd2f60ab5686 1166 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1167 pc.printf("raw1.6 part id Status: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 50:dd2f60ab5686 1168 // raw1.21 rd accel WHO reg
phonemacro 30:77a30ea425da 1169 cmd[0] = 0x41; cmd[1] = 0x04; cmd[2] = 0x0F;
phonemacro 30:77a30ea425da 1170 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 30:77a30ea425da 1171 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 30:77a30ea425da 1172 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 30:77a30ea425da 1173 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 1174 pc.printf("1.7 Who Status: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 32:92adfbe18ab6 1175
phonemacro 61:a2e73c5b87e7 1176 // raw1.8 sample rate
phonemacro 50:dd2f60ab5686 1177 #if RAW_HZ == 25
phonemacro 50:dd2f60ab5686 1178 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x00; // set AFE reg 0x12 to 25 Hz, ave 1
phonemacro 50:dd2f60ab5686 1179 #elif RAW_HZ == 50
phonemacro 50:dd2f60ab5686 1180 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x40; // set AFE reg 0x12 to 50 Hz
phonemacro 50:dd2f60ab5686 1181 #elif RAW_HZ == 100
phonemacro 46:553559610878 1182 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x18; // set AFE reg 0x12 to 100 Hz
phonemacro 50:dd2f60ab5686 1183 #elif RAW_HZ == 200
phonemacro 50:dd2f60ab5686 1184 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x20; // set AFE reg 0x12 to 200 Hz
phonemacro 50:dd2f60ab5686 1185 #elif RAW_HZ == 2004
phonemacro 50:dd2f60ab5686 1186 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x22; // set AFE reg 0x12 to 200 Hz, ave 4
phonemacro 46:553559610878 1187 #else
phonemacro 46:553559610878 1188 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x18; // set AFE reg 0x12 to 100 Hz
phonemacro 46:553559610878 1189 #endif
phonemacro 14:c8cc6d7fd5f9 1190 // cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x20; // set AFE reg 0x12 to 200 Hz
phonemacro 14:c8cc6d7fd5f9 1191 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1192 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1193 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1194 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 1195 pc.printf("raw1.8 Status: %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 1196 // LED1 current
phonemacro 50:dd2f60ab5686 1197 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x23; cmd[3] = 0x19;
phonemacro 14:c8cc6d7fd5f9 1198 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1199 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1200 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1201 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1202 pc.printf("LED1 Status: %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 1203 // LED2 current
phonemacro 50:dd2f60ab5686 1204 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x24; cmd[3] = 0x19;
phonemacro 50:dd2f60ab5686 1205 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 50:dd2f60ab5686 1206 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1207 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 50:dd2f60ab5686 1208 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1209 pc.printf("LED2 Status: %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 1210 // LED3 current
phonemacro 50:dd2f60ab5686 1211 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x25; cmd[3] = 0x19;
phonemacro 14:c8cc6d7fd5f9 1212 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1213 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1214 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1215 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1216 pc.printf("LED3 Status: %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 1217 // LED4 current
phonemacro 50:dd2f60ab5686 1218 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x26; cmd[3] = 0x19;
phonemacro 14:c8cc6d7fd5f9 1219 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1220 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1221 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1222 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1223 pc.printf("LED4 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 1224 // LED5 current
phonemacro 50:dd2f60ab5686 1225 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x27; cmd[3] = 0x19;
phonemacro 14:c8cc6d7fd5f9 1226 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1227 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1228 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1229 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1230 pc.printf("LED5 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 1231 // LED6 current
phonemacro 50:dd2f60ab5686 1232 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x28; cmd[3] = 0x19;
phonemacro 14:c8cc6d7fd5f9 1233 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1234 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1235 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1236 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1237 pc.printf("LED6 Status: %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 1238 #if 0
phonemacro 14:c8cc6d7fd5f9 1239 // Set Seq cntrl1 LED2, LED1
phonemacro 14:c8cc6d7fd5f9 1240 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x20; cmd[3] = 0x21;
phonemacro 14:c8cc6d7fd5f9 1241 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1242 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1243 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1244 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1245 pc.printf("Seq cntrl1 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 1246 // Set Seq cntrl2 LED4, LED3
phonemacro 14:c8cc6d7fd5f9 1247 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x21; cmd[3] = 0xA3;
phonemacro 14:c8cc6d7fd5f9 1248 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1249 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1250 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1251 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1252 pc.printf("Seq cntrl2 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 1253 // Set Seq cntrl3 LED6, LED5
phonemacro 14:c8cc6d7fd5f9 1254 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x22; cmd[3] = 0x21;
phonemacro 14:c8cc6d7fd5f9 1255 // cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x22; cmd[3] = 0x99; // Ambient
phonemacro 14:c8cc6d7fd5f9 1256 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1257 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1258 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1259 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1260 pc.printf("Seq cntrl3 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 1261 #endif
phonemacro 61:a2e73c5b87e7 1262 set_reg_opt_validation();
phonemacro 28:315604f4b374 1263 mfio = 1;
phonemacro 28:315604f4b374 1264 }
phonemacro 14:c8cc6d7fd5f9 1265
phonemacro 14:c8cc6d7fd5f9 1266 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 1267 // main
phonemacro 14:c8cc6d7fd5f9 1268 /*****************************************************************************/
phonemacro 10:192ea88e964b 1269 int main()
phonemacro 10:192ea88e964b 1270 {
phonemacro 10:192ea88e964b 1271 sh_i2c.frequency(400000);
phonemacro 10:192ea88e964b 1272 int32_t ledcnt = 0;
phonemacro 10:192ea88e964b 1273 rLED = LED_OFF; gLED = LED_ON; bLED = LED_OFF;
phonemacro 10:192ea88e964b 1274 Ticker ticker; // calls a callback repeatedly with a timeout
phonemacro 28:315604f4b374 1275
phonemacro 28:315604f4b374 1276 #if 0 // test disable algo
phonemacro 28:315604f4b374 1277 char cmd[8];
phonemacro 28:315604f4b374 1278 char rsp[256];
phonemacro 28:315604f4b374 1279 // 3.1 Disable algo
phonemacro 28:315604f4b374 1280 mfio = 1; mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 1281 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x00;
phonemacro 28:315604f4b374 1282 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 28:315604f4b374 1283 thread_sleep_for(465);
phonemacro 28:315604f4b374 1284 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 1285 pc.printf("3.1 disable algo: %x\n\r", rsp[0]);
phonemacro 28:315604f4b374 1286 mfio = 1;
phonemacro 28:315604f4b374 1287 #endif
phonemacro 28:315604f4b374 1288
phonemacro 10:192ea88e964b 1289 //ticker.attach(callback(&blink_timer), BLINKING_RATE_MS); /* set timer for one second */
phonemacro 14:c8cc6d7fd5f9 1290 #ifdef RAW
phonemacro 14:c8cc6d7fd5f9 1291 init_sh_raw();
phonemacro 14:c8cc6d7fd5f9 1292 #else
phonemacro 14:c8cc6d7fd5f9 1293 init_sh_algo();
phonemacro 14:c8cc6d7fd5f9 1294 #endif
phonemacro 28:315604f4b374 1295 mfio = 1;
phonemacro 33:c8fbd904df3e 1296 heading_printed = 0;
phonemacro 8:e6ae69cfecbf 1297 #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG) || defined(MAXM86146_CFG)
phonemacro 6:e1b7190d6cb5 1298 Timer tmr1;
phonemacro 0:6f65cae31c54 1299 while (1) {
phonemacro 6:e1b7190d6cb5 1300 tmr1.start();
phonemacro 61:a2e73c5b87e7 1301 #if defined(RAW)
phonemacro 50:dd2f60ab5686 1302 #if RAW_HZ == 25
phonemacro 50:dd2f60ab5686 1303 if (tmr1.read_ms() >= 40) {
phonemacro 50:dd2f60ab5686 1304 #elif RAW_HZ == 50
phonemacro 50:dd2f60ab5686 1305 if (tmr1.read_ms() >= 20) {
phonemacro 50:dd2f60ab5686 1306 #elif RAW_HZ == 100
phonemacro 29:a7dd81450b35 1307 if (tmr1.read_ms() >= 10) {
phonemacro 50:dd2f60ab5686 1308 #elif RAW_HZ == 200 || RAW_HZ == 2004
phonemacro 50:dd2f60ab5686 1309 if (tmr1.read_ms() >= 5) {
phonemacro 46:553559610878 1310 #else
phonemacro 46:553559610878 1311 if (tmr1.read_ms() >= 10) {
phonemacro 46:553559610878 1312 #endif
phonemacro 29:a7dd81450b35 1313 #else
phonemacro 42:6f980909371f 1314 #ifdef REDUCE_RPT_PERIOD
phonemacro 42:6f980909371f 1315 #ifdef USE_FIFO_BUFFER_CNT
phonemacro 42:6f980909371f 1316 if (tmr1.read_ms() >= 40*REDUCE_RPT_PERIOD*USE_FIFO_BUFFER_CNT) {
phonemacro 42:6f980909371f 1317 #else
phonemacro 42:6f980909371f 1318 if (tmr1.read_ms() >= 40*REDUCE_RPT_PERIOD) {
phonemacro 42:6f980909371f 1319 #endif
phonemacro 42:6f980909371f 1320 #else
phonemacro 42:6f980909371f 1321 #ifdef USE_FIFO_BUFFER_CNT
phonemacro 42:6f980909371f 1322 if (tmr1.read_ms() >= 40*USE_FIFO_BUFFER_CNT) {
phonemacro 42:6f980909371f 1323 #else
phonemacro 28:315604f4b374 1324 if (tmr1.read_ms() >= 40) {
phonemacro 42:6f980909371f 1325 #endif
phonemacro 42:6f980909371f 1326 #endif
phonemacro 29:a7dd81450b35 1327 #endif
phonemacro 7:23b067817ab8 1328 tmr1.reset();
phonemacro 10:192ea88e964b 1329 read_sh_fifo();
phonemacro 7:23b067817ab8 1330 if ((ledcnt++ % 50) == 0)
phonemacro 6:e1b7190d6cb5 1331 gLED = !gLED;
phonemacro 0:6f65cae31c54 1332 }
phonemacro 0:6f65cae31c54 1333 }
phonemacro 6:e1b7190d6cb5 1334 #else
phonemacro 6:e1b7190d6cb5 1335 ticker.attach(callback(&fifo_timer), 0.040f);
phonemacro 6:e1b7190d6cb5 1336 while (1) {
phonemacro 6:e1b7190d6cb5 1337 if (Time_to_Read_PPG) {
phonemacro 10:192ea88e964b 1338 read_sh_fifo();
phonemacro 7:23b067817ab8 1339 if ((ledcnt++ % 50) == 0)
phonemacro 6:e1b7190d6cb5 1340 gLED = !gLED;
phonemacro 6:e1b7190d6cb5 1341 }
phonemacro 6:e1b7190d6cb5 1342 }
phonemacro 6:e1b7190d6cb5 1343 #endif
phonemacro 0:6f65cae31c54 1344 }