Mode1 Optical Validation

Dependencies:   max32630fthr

Committer:
phonemacro
Date:
Fri May 20 00:17:29 2022 +0000
Revision:
55:04c9fad147d4
Parent:
54:2f19a5a83a62
Child:
56:60b61d5c8154
draft

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 16:ff1122f0624a 38 * https://os.mbed.com/users/phonemacro/code/MAX32664C_Example_Host_Code
phonemacro 16:ff1122f0624a 39 * Tera Term output is set to 115200 baud rate.
phonemacro 53:034f646141ae 40 * ver: 220512
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 55:04c9fad147d4 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 55:04c9fad147d4 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 46:553559610878 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 55:04c9fad147d4 96 #define MAXM86161_OPT_VALIDATION_RED 1 // Optical validatation
phonemacro 55:04c9fad147d4 97 #define MAXM86161_OPT_VALIDATION_IR 1 // Optical validatation
phonemacro 55:04c9fad147d4 98 #define MAXM86161_OPT_VALIDATION_GRN 1 // Optical validatation
phonemacro 55:04c9fad147d4 99 #define SENSOR_ONLY 1
phonemacro 33:c8fbd904df3e 100
phonemacro 33:c8fbd904df3e 101 // Comment out both of the below for Normal Algorithm Samples Format
phonemacro 55:04c9fad147d4 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 51:e2214db671c0 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 0:6f65cae31c54 145 #ifdef ALGO_ONLY
phonemacro 0:6f65cae31c54 146 #define TTL_SZ (ALGO_SZ)
phonemacro 0:6f65cae31c54 147 #else
phonemacro 14:c8cc6d7fd5f9 148 #ifdef RAW
phonemacro 14:c8cc6d7fd5f9 149 #define TTL_SZ (PPG_SZ+ACCEL_SZ)
phonemacro 14:c8cc6d7fd5f9 150 #else
phonemacro 14:c8cc6d7fd5f9 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 55:04c9fad147d4 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 55:04c9fad147d4 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 55:04c9fad147d4 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 55:04c9fad147d4 300 #if !defined(RAW) && !defined(SENSOR_ONLY)
phonemacro 55:04c9fad147d4 301
phonemacro 12:17a0bf823462 302 #ifdef EXTENDED_ALGO
phonemacro 45:d26b8bcce561 303 // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ);
phonemacro 0:6f65cae31c54 304 opmode = rsp[ptr];
phonemacro 0:6f65cae31c54 305 hr = (rsp[ptr+1] << 8) + rsp[ptr+2];
phonemacro 0:6f65cae31c54 306 hr_conf = rsp[ptr+3];
phonemacro 12:17a0bf823462 307 ibi = (rsp[ptr+4] << 8) + rsp[ptr+5];
phonemacro 12:17a0bf823462 308
phonemacro 12:17a0bf823462 309 ibi_conf = rsp[ptr+6];
phonemacro 12:17a0bf823462 310 act = rsp[ptr+7];
phonemacro 12:17a0bf823462 311 walk_stp = (rsp[ptr+8] << 24) + (rsp[ptr+9] << 16) + (rsp[ptr+10] << 8) + rsp[ptr+11];
phonemacro 12:17a0bf823462 312 run_stp = (rsp[ptr+12] << 24) + (rsp[ptr+13] << 16) + (rsp[ptr+14] << 8) + rsp[ptr+15];
phonemacro 12:17a0bf823462 313
phonemacro 12:17a0bf823462 314 energy = (rsp[ptr+16] << 24) + (rsp[ptr+17] << 16) + (rsp[ptr+18] << 8) + rsp[ptr+19];
phonemacro 12:17a0bf823462 315 amr = (rsp[ptr+20] << 24) + (rsp[ptr+21] << 16) + (rsp[ptr+22] << 8) + rsp[ptr+23];
phonemacro 12:17a0bf823462 316 iadj1_rqt = rsp[ptr+24];
phonemacro 12:17a0bf823462 317 iadj1 = (rsp[ptr+25] << 8) + rsp[ptr+26];
phonemacro 12:17a0bf823462 318
phonemacro 12:17a0bf823462 319 iadj2_rqt = rsp[ptr+27];
phonemacro 12:17a0bf823462 320 iadj2 = (rsp[ptr+28] << 8) + rsp[ptr+29];
phonemacro 12:17a0bf823462 321 iadj3_rqt = rsp[ptr+30];
phonemacro 12:17a0bf823462 322 iadj3 = (rsp[ptr+31] << 8) + rsp[ptr+32];
phonemacro 12:17a0bf823462 323
phonemacro 12:17a0bf823462 324 intadj_rqt = rsp[ptr+33];
phonemacro 12:17a0bf823462 325 intadj = rsp[ptr+34];
phonemacro 12:17a0bf823462 326 smpladj_rqt = rsp[ptr+35];
phonemacro 12:17a0bf823462 327 smpladj = rsp[ptr+36];
phonemacro 12:17a0bf823462 328
phonemacro 12:17a0bf823462 329 rqt_smplave = rsp[ptr+37];
phonemacro 12:17a0bf823462 330 afestatehr = rsp[ptr+38];
phonemacro 12:17a0bf823462 331 hr_motion = rsp[ptr+39];
phonemacro 12:17a0bf823462 332 scd = rsp[ptr+40];
phonemacro 12:17a0bf823462 333
phonemacro 12:17a0bf823462 334
phonemacro 12:17a0bf823462 335 r = (rsp[ptr+41] << 8) + rsp[ptr+42];
phonemacro 12:17a0bf823462 336 spo2_conf = rsp[ptr+43];
phonemacro 12:17a0bf823462 337
phonemacro 12:17a0bf823462 338 spo2 = (rsp[ptr+44] << 8) + rsp[ptr+45];
phonemacro 12:17a0bf823462 339 spo2_compl = rsp[ptr+46];
phonemacro 53:034f646141ae 340 spo2_lo = rsp[ptr+47]; // low quality
phonemacro 12:17a0bf823462 341 spo2_mo = rsp[ptr+48];
phonemacro 12:17a0bf823462 342
phonemacro 12:17a0bf823462 343 spo2_lopi = rsp[ptr+49];
phonemacro 12:17a0bf823462 344 spo2_unrel = rsp[ptr+50];
phonemacro 12:17a0bf823462 345 spo2_state = rsp[ptr+51];
phonemacro 12:17a0bf823462 346
phonemacro 12:17a0bf823462 347 ibi_offset = rsp[ptr+52];
phonemacro 12:17a0bf823462 348
phonemacro 12:17a0bf823462 349 sptr += (TTL_SZ);
phonemacro 36:a6e7ff9c87a0 350
phonemacro 12:17a0bf823462 351 #if 1
phonemacro 33:c8fbd904df3e 352 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 353 heading_printed = 1;
phonemacro 36:a6e7ff9c87a0 354 #if defined(ALGO_ONLY)
phonemacro 33:c8fbd904df3e 355 pc.printf("opmode,hr,hr_conf,ibi,ibi_conf,act,walk_stp,run_stp,energy,amr,");
phonemacro 33:c8fbd904df3e 356 pc.printf("iadj1_rqt,iadj1,iadj2_rqt,iadj2,iadj3_rqt,iadj3,intadj_rqt,intadj,");
phonemacro 33:c8fbd904df3e 357 pc.printf("smpladj_rqt,smpladj,rqt_smplave,afestatehr,hr_motion,scd,");
phonemacro 51:e2214db671c0 358 pc.printf("r,");
phonemacro 33:c8fbd904df3e 359 pc.printf("spo2,spo2_compl,spo2_lo,spo2_mo,spo2_lopi,spo2_unrel,spo2_state,ibi_offset,\n\r");
phonemacro 36:a6e7ff9c87a0 360 #endif
phonemacro 33:c8fbd904df3e 361 }
phonemacro 12:17a0bf823462 362 pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi);
phonemacro 12:17a0bf823462 363 pc.printf("%d,%d,", ibi_conf, act);
phonemacro 12:17a0bf823462 364 pc.printf("%d,%d,%d,", walk_stp, run_stp, energy);
phonemacro 12:17a0bf823462 365 pc.printf("%d,%d,%d,%d,", amr, iadj1_rqt, iadj1, iadj2_rqt);
phonemacro 12:17a0bf823462 366 pc.printf("%d,%d,%d,%d,", iadj2, iadj3_rqt, iadj3, intadj_rqt);
phonemacro 12:17a0bf823462 367 pc.printf("%d,%d,%d,%d,", intadj, smpladj_rqt, smpladj, rqt_smplave);
phonemacro 12:17a0bf823462 368 pc.printf("%d,%d,", afestatehr, hr_motion);
phonemacro 51:e2214db671c0 369 pc.printf("%d,%d", scd, r);
phonemacro 12:17a0bf823462 370 pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo);
phonemacro 12:17a0bf823462 371 pc.printf("%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state);
phonemacro 12:17a0bf823462 372 pc.printf("%d,", ibi_offset);
phonemacro 12:17a0bf823462 373 #else
phonemacro 33:c8fbd904df3e 374 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 375 heading_printed = 1;
phonemacro 36:a6e7ff9c87a0 376 #if defined(ALGO_ONLY)
phonemacro 53:034f646141ae 377 pc.printf("hr,r,hr_conf,spo2,spo2_conf,spo2_lo,spo2_unrel,spo2_state,scd,\n\r");
phonemacro 36:a6e7ff9c87a0 378 #endif
phonemacro 33:c8fbd904df3e 379 }
phonemacro 51:e2214db671c0 380 pc.printf("%d,%d,%d", hr, hr_conf, r);
phonemacro 12:17a0bf823462 381 pc.printf("%d,%d,", spo2, spo2_conf);
phonemacro 16:ff1122f0624a 382 pc.printf("%d,%d,%d,", spo2_lo, spo2_mo, spo2_lopi);
phonemacro 53:034f646141ae 383 pc.printf("%d,%d,%d,", spo2_unrel,spo2_state, scd);
phonemacro 36:a6e7ff9c87a0 384 #endif // if 1
phonemacro 33:c8fbd904df3e 385 #elif defined(PACKED_NORMAL_ALGO)
phonemacro 33:c8fbd904df3e 386 // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ);
phonemacro 35:67699bdae57e 387 opmode = rsp[ptr];
phonemacro 33:c8fbd904df3e 388 hr = (rsp[ptr+1] << 8) + rsp[ptr+2];
phonemacro 33:c8fbd904df3e 389 hr_conf = rsp[ptr+3];
phonemacro 33:c8fbd904df3e 390 ibi = (rsp[ptr+4] << 8) + rsp[ptr+5];
phonemacro 33:c8fbd904df3e 391
phonemacro 33:c8fbd904df3e 392 ibi_conf = rsp[ptr+6];
phonemacro 33:c8fbd904df3e 393 // act = rsp[ptr+7];
phonemacro 33:c8fbd904df3e 394 r = (rsp[ptr+7] << 8) + rsp[ptr+8];
phonemacro 33:c8fbd904df3e 395 spo2_conf = rsp[ptr+9];
phonemacro 33:c8fbd904df3e 396
phonemacro 33:c8fbd904df3e 397 spo2 = (rsp[ptr+10] << 8) + rsp[ptr+11];
phonemacro 33:c8fbd904df3e 398 spo2_compl = rsp[ptr+12];
phonemacro 33:c8fbd904df3e 399
phonemacro 33:c8fbd904df3e 400 spo2_lo = 0; spo2_mo = 0; spo2_lopi = 0; spo2_unrel = 0;
phonemacro 33:c8fbd904df3e 401
phonemacro 33:c8fbd904df3e 402 if (rsp[ptr+13] & 0x01)
phonemacro 33:c8fbd904df3e 403 spo2_lo = 1;
phonemacro 33:c8fbd904df3e 404 if (rsp[ptr+13] & 0x02)
phonemacro 33:c8fbd904df3e 405 spo2_mo = 1;
phonemacro 33:c8fbd904df3e 406 if (rsp[ptr+13] & 0x04)
phonemacro 33:c8fbd904df3e 407 spo2_lopi = 1;
phonemacro 33:c8fbd904df3e 408 if (rsp[ptr+13] & 0x08)
phonemacro 33:c8fbd904df3e 409 spo2_unrel = 1;
phonemacro 33:c8fbd904df3e 410 spo2_state = (0x30 & rsp[ptr+13]) >> 4;
phonemacro 33:c8fbd904df3e 411
phonemacro 33:c8fbd904df3e 412 scd = (0x03 & rsp[ptr+14]);
phonemacro 33:c8fbd904df3e 413 act = (0x1C & rsp[ptr+14]) >> 2;
phonemacro 33:c8fbd904df3e 414 inappro_ori = (0x20 & rsp[ptr+14]) >> 5;
phonemacro 33:c8fbd904df3e 415
phonemacro 33:c8fbd904df3e 416 ibi_offset = rsp[ptr+15];
phonemacro 33:c8fbd904df3e 417
phonemacro 33:c8fbd904df3e 418 sptr += (TTL_SZ);
phonemacro 37:249b548e6488 419 #if defined(PCK_CFG_MASK) // hex out, for printing config masked out packed data
phonemacro 35:67699bdae57e 420 // print as hex bytes
phonemacro 35:67699bdae57e 421 for (j=0; j<ALGO_SZ; j++)
phonemacro 35:67699bdae57e 422 pc.printf("%02X ", rsp[ptr+j]);
phonemacro 36:a6e7ff9c87a0 423 //pc.printf("\n\r" );
phonemacro 35:67699bdae57e 424 #endif
phonemacro 35:67699bdae57e 425
phonemacro 37:249b548e6488 426 #if !defined(PCK_CFG_MASK)
phonemacro 37:249b548e6488 427 #if 1
phonemacro 37:249b548e6488 428 #if 1 // print all
phonemacro 33:c8fbd904df3e 429 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 430 heading_printed = 1;
phonemacro 37:249b548e6488 431 #if defined(ALGO_ONLY)
phonemacro 33:c8fbd904df3e 432 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 433 #endif
phonemacro 33:c8fbd904df3e 434 }
phonemacro 33:c8fbd904df3e 435 pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi);
phonemacro 33:c8fbd904df3e 436 pc.printf("%d,%d,%d,%d,", ibi_conf, act, r, spo2_conf);
phonemacro 33:c8fbd904df3e 437 pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo);
phonemacro 33:c8fbd904df3e 438 pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state, scd);
phonemacro 33:c8fbd904df3e 439 pc.printf("%d,", ibi_offset);
phonemacro 33:c8fbd904df3e 440 pc.printf("%d,", inappro_ori);
phonemacro 55:04c9fad147d4 441 #endif
phonemacro 37:249b548e6488 442 #else // print some
phonemacro 33:c8fbd904df3e 443 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 444 heading_printed = 1;
phonemacro 37:249b548e6488 445 #if defined(ALGO_ONLY)
phonemacro 54:2f19a5a83a62 446 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 447 #endif
phonemacro 33:c8fbd904df3e 448 }
phonemacro 51:e2214db671c0 449 pc.printf("%d,%d,%d", hr, hr_conf, r);
phonemacro 33:c8fbd904df3e 450 pc.printf("%d,%d,", spo2, spo2_conf);
phonemacro 54:2f19a5a83a62 451 pc.printf("%d,%d,", spo2_lo,spo2_mo);
phonemacro 53:034f646141ae 452 pc.printf("%d,%d,%d,%d", spo2_lopi,spo2_unrel, spo2_state, scd);
phonemacro 37:249b548e6488 453 #endif
phonemacro 37:249b548e6488 454 #endif // #if defined(PCK_CFG_MASK)
phonemacro 37:249b548e6488 455
phonemacro 12:17a0bf823462 456 #else // normal algo size
phonemacro 12:17a0bf823462 457 // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ);
phonemacro 12:17a0bf823462 458 opmode = rsp[ptr];
phonemacro 12:17a0bf823462 459 hr = (rsp[ptr+1] << 8) + rsp[ptr+2];
phonemacro 12:17a0bf823462 460 hr_conf = rsp[ptr+3];
phonemacro 12:17a0bf823462 461 ibi = (rsp[ptr+4] << 8) + rsp[ptr+5];
phonemacro 4:4f1e9439f048 462
phonemacro 11:a16b6bf38841 463 ibi_conf = rsp[ptr+6];
phonemacro 3:da975696b936 464 act = rsp[ptr+7];
phonemacro 3:da975696b936 465 r = (rsp[ptr+8] << 8) + rsp[ptr+9];
phonemacro 0:6f65cae31c54 466 spo2_conf = rsp[ptr+10];
phonemacro 4:4f1e9439f048 467
phonemacro 0:6f65cae31c54 468 spo2 = (rsp[ptr+11] << 8) + rsp[ptr+12];
phonemacro 4:4f1e9439f048 469 spo2_compl = rsp[ptr+13];
phonemacro 4:4f1e9439f048 470 spo2_lo = rsp[ptr+14];
phonemacro 4:4f1e9439f048 471 spo2_mo = rsp[ptr+15];
phonemacro 4:4f1e9439f048 472
phonemacro 4:4f1e9439f048 473 spo2_lopi = rsp[ptr+16];
phonemacro 4:4f1e9439f048 474 spo2_unrel = rsp[ptr+17];
phonemacro 4:4f1e9439f048 475 spo2_state = rsp[ptr+18];
phonemacro 2:563d90a111b3 476 scd = rsp[ptr+19];
phonemacro 0:6f65cae31c54 477
phonemacro 36:a6e7ff9c87a0 478 // ibi_offset = rsp[ptr+20];
phonemacro 0:6f65cae31c54 479
phonemacro 4:4f1e9439f048 480 sptr += (TTL_SZ);
phonemacro 55:04c9fad147d4 481
phonemacro 27:a45d6e38f2de 482 #if 0
phonemacro 33:c8fbd904df3e 483 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 484 heading_printed = 1;
phonemacro 36:a6e7ff9c87a0 485 #if defined(ALGO_ONLY)
phonemacro 33:c8fbd904df3e 486 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 487 #endif
phonemacro 33:c8fbd904df3e 488 }
phonemacro 4:4f1e9439f048 489 pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi);
phonemacro 4:4f1e9439f048 490 pc.printf("%d,%d,%d,%d,", ibi_conf, act, r, spo2_conf);
phonemacro 4:4f1e9439f048 491 pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo);
phonemacro 4:4f1e9439f048 492 pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state, scd);
phonemacro 36:a6e7ff9c87a0 493 // pc.printf("%d,", ibi_offset);
phonemacro 4:4f1e9439f048 494 #else
phonemacro 33:c8fbd904df3e 495 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 496 heading_printed = 1;
phonemacro 36:a6e7ff9c87a0 497 #if defined(ALGO_ONLY)
phonemacro 54:2f19a5a83a62 498 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 499 #endif
phonemacro 33:c8fbd904df3e 500 }
phonemacro 51:e2214db671c0 501 pc.printf("%d,%d,%d,", hr, hr_conf, r);
phonemacro 4:4f1e9439f048 502 pc.printf("%d,%d,", spo2, spo2_conf);
phonemacro 54:2f19a5a83a62 503 pc.printf("%d,%d,", spo2_lo,spo2_mo);
phonemacro 53:034f646141ae 504 pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel,spo2_state, scd);
phonemacro 4:4f1e9439f048 505 #endif
phonemacro 12:17a0bf823462 506 #endif // end normal algo size
phonemacro 55:04c9fad147d4 507 #endif // !RAW && !SENSOR_ONLY
phonemacro 4:4f1e9439f048 508
phonemacro 3:da975696b936 509 pc.printf("\n\r");
phonemacro 0:6f65cae31c54 510 }
phonemacro 0:6f65cae31c54 511 }
phonemacro 0:6f65cae31c54 512
phonemacro 6:e1b7190d6cb5 513 #ifdef MAXREFDES103_CFG
phonemacro 14:c8cc6d7fd5f9 514 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 515 // init_max20303_pmic
phonemacro 14:c8cc6d7fd5f9 516 /*****************************************************************************/
phonemacro 6:e1b7190d6cb5 517 void init_max20303_pmic(void) {
phonemacro 5:7f5a012747a5 518 /* Wait for pmic to settle down */
phonemacro 5:7f5a012747a5 519 thread_sleep_for(800);
phonemacro 5:7f5a012747a5 520
phonemacro 5:7f5a012747a5 521 //set_time(1544787300); // Set RTC time to Wed, 28 Oct 2009 11:35:37
phonemacro 6:e1b7190d6cb5 522 MAX20303 max20303(&sh_i2c);
phonemacro 5:7f5a012747a5 523 /*Set LDO1 to 1.8v*/
phonemacro 5:7f5a012747a5 524 max20303.LDO1Config();
phonemacro 5:7f5a012747a5 525
phonemacro 5:7f5a012747a5 526 /*Set LDO2 to 3v*/
phonemacro 5:7f5a012747a5 527 max20303.LDO2Config();
phonemacro 5:7f5a012747a5 528
phonemacro 5:7f5a012747a5 529 //max20303.BoostEnable();
phonemacro 5:7f5a012747a5 530 max20303.BuckBoostEnable();
phonemacro 5:7f5a012747a5 531
phonemacro 5:7f5a012747a5 532 max20303.led0on(0);
phonemacro 5:7f5a012747a5 533 max20303.led1on(0);
phonemacro 5:7f5a012747a5 534 max20303.led2on(0);
phonemacro 5:7f5a012747a5 535
phonemacro 5:7f5a012747a5 536 /* Wait for pmic to settle down */
phonemacro 5:7f5a012747a5 537 thread_sleep_for(200);
phonemacro 28:315604f4b374 538
phonemacro 5:7f5a012747a5 539 }
phonemacro 6:e1b7190d6cb5 540 #endif // MAXREFDES103_CFG
phonemacro 14:c8cc6d7fd5f9 541
phonemacro 55:04c9fad147d4 542 void reset_sh(void) {
phonemacro 10:192ea88e964b 543 // switch to application mode
phonemacro 0:6f65cae31c54 544 rst = 0;
phonemacro 0:6f65cae31c54 545 mfio = 1;
phonemacro 0:6f65cae31c54 546 thread_sleep_for(10);
phonemacro 0:6f65cae31c54 547 rst = 1;
phonemacro 0:6f65cae31c54 548 thread_sleep_for(1500);
phonemacro 10:192ea88e964b 549 #ifdef MAXREFDES103_CFG
phonemacro 10:192ea88e964b 550 init_max20303_pmic();
phonemacro 10:192ea88e964b 551 #endif
phonemacro 47:346a13fbdc0f 552 // 33.13.31 needs at least 1.6s
phonemacro 47:346a13fbdc0f 553 // thread_sleep_for(100);
phonemacro 55:04c9fad147d4 554 }
phonemacro 55:04c9fad147d4 555
phonemacro 55:04c9fad147d4 556 /*****************************************************************************/
phonemacro 55:04c9fad147d4 557 // init_sh_algo
phonemacro 55:04c9fad147d4 558 /*****************************************************************************/
phonemacro 55:04c9fad147d4 559 void init_sh_algo(void) {
phonemacro 55:04c9fad147d4 560 char cmd[64];
phonemacro 55:04c9fad147d4 561 char rsp[256];
phonemacro 55:04c9fad147d4 562
phonemacro 55:04c9fad147d4 563 reset_sh();
phonemacro 55:04c9fad147d4 564
phonemacro 55:04c9fad147d4 565 #ifdef OPTIMIZE_FIFO_READ
phonemacro 55:04c9fad147d4 566 check_fifo_countdown = MAX_FIFO_CNT;
phonemacro 55:04c9fad147d4 567 #endif
phonemacro 0:6f65cae31c54 568
phonemacro 1:da792e46a385 569 mfio = 0; wait_us(300);
phonemacro 42:6f980909371f 570 #ifdef REDUCE_RPT_PERIOD
phonemacro 42:6f980909371f 571 //Change report period to 25
phonemacro 55:04c9fad147d4 572 cmd[0] = 0x10; cmd[1] = 0x02; cmd[2] = REDUCE_RPT_PERIOD;
phonemacro 42:6f980909371f 573 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 42:6f980909371f 574 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 42:6f980909371f 575 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 42:6f980909371f 576 mfio = 1; mfio = 0; wait_us(300);
phonemacro 42:6f980909371f 577 pc.printf("Wr report period 25 %x\n\r", rsp[0]);
phonemacro 42:6f980909371f 578 #endif
phonemacro 48:6b93b56bb22e 579 //1.10 rd ver
phonemacro 4:4f1e9439f048 580 cmd[0] = 0xFF; cmd[1] = 0x03;
phonemacro 6:e1b7190d6cb5 581 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 1:da792e46a385 582 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 583 sh_i2c.read(SH_ADDR, rsp, 4);
phonemacro 1:da792e46a385 584 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 585 pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]);
phonemacro 0:6f65cae31c54 586
phonemacro 35:67699bdae57e 587 // wr config mask for packed normal data output fifo
phonemacro 37:249b548e6488 588 #if defined(PCK_CFG_MASK)
phonemacro 37:249b548e6488 589 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x20; cmd[3] = 0x7F; cmd[4] = 0xFF; cmd[5] = 0x00;
phonemacro 44:1b165a68474d 590 // cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x20; cmd[3] = 0xFF; cmd[4] = 0xFF; cmd[5] = 0x00;
phonemacro 35:67699bdae57e 591 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 35:67699bdae57e 592 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 593 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 35:67699bdae57e 594 mfio = 1; mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 595 pc.printf("wr config mask packed: %x \n\r", rsp[0]);
phonemacro 35:67699bdae57e 596 // rd config mask for packed normal data output fifo
phonemacro 35:67699bdae57e 597 cmd[0] = 0x51; cmd[1] = 0x07; cmd[2] = 0x20;
phonemacro 35:67699bdae57e 598 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 35:67699bdae57e 599 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 600 sh_i2c.read(SH_ADDR, rsp, 4);
phonemacro 35:67699bdae57e 601 mfio = 1; mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 602 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 603 #endif
phonemacro 35:67699bdae57e 604
phonemacro 33:c8fbd904df3e 605 #if defined(MAXM86161_CFG) || defined(MAXM86146_CFG)
phonemacro 33:c8fbd904df3e 606 // rd algo sz normal
phonemacro 17:0d6e99a0fd8d 607 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x01;
phonemacro 17:0d6e99a0fd8d 608 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 17:0d6e99a0fd8d 609 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 610 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 17:0d6e99a0fd8d 611 mfio = 1; mfio = 0; wait_us(300);
phonemacro 33:c8fbd904df3e 612 pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 33:c8fbd904df3e 613 // rd algo sz extended
phonemacro 17:0d6e99a0fd8d 614 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x02;
phonemacro 17:0d6e99a0fd8d 615 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 17:0d6e99a0fd8d 616 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 617 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 17:0d6e99a0fd8d 618 mfio = 1; mfio = 0; wait_us(300);
phonemacro 33:c8fbd904df3e 619 pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 33:c8fbd904df3e 620 // rd algo sz scd
phonemacro 17:0d6e99a0fd8d 621 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x03;
phonemacro 17:0d6e99a0fd8d 622 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 17:0d6e99a0fd8d 623 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 624 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 17:0d6e99a0fd8d 625 mfio = 1; mfio = 0; wait_us(300);
phonemacro 33:c8fbd904df3e 626 pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 45:d26b8bcce561 627 #if defined(PACKED_NORMAL_ALGO) && (defined(MAXM86161_CFG) || defined(MAXM86146_CFG))
phonemacro 35:67699bdae57e 628 // rd algo sz packed normal
phonemacro 33:c8fbd904df3e 629 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x04;
phonemacro 33:c8fbd904df3e 630 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 33:c8fbd904df3e 631 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 33:c8fbd904df3e 632 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 33:c8fbd904df3e 633 mfio = 1; mfio = 0; wait_us(300);
phonemacro 33:c8fbd904df3e 634 pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 33:c8fbd904df3e 635 #endif
phonemacro 17:0d6e99a0fd8d 636 #endif
phonemacro 17:0d6e99a0fd8d 637
phonemacro 17:0d6e99a0fd8d 638 #if 0
phonemacro 17:0d6e99a0fd8d 639 // set Perfusion Index threshold to .05 (3x.13.19+)
phonemacro 17:0d6e99a0fd8d 640 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x1D; cmd[3] = 50;
phonemacro 16:ff1122f0624a 641 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 16:ff1122f0624a 642 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 16:ff1122f0624a 643 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 16:ff1122f0624a 644 mfio = 1; mfio = 0; wait_us(300);
phonemacro 16:ff1122f0624a 645 pc.printf("pi set to 0x19 : %x \n\r", rsp[0]);
phonemacro 17:0d6e99a0fd8d 646 #endif
phonemacro 16:ff1122f0624a 647
phonemacro 48:6b93b56bb22e 648 // 1.1 sensor and algo data
phonemacro 4:4f1e9439f048 649 cmd[0] = 0x10; cmd[1] = 0x00;
phonemacro 2:563d90a111b3 650 #ifdef ALGO_ONLY
phonemacro 0:6f65cae31c54 651 cmd[2] = 0x02; // algo data
phonemacro 4:4f1e9439f048 652 pc.printf("algo only \n\r");
phonemacro 2:563d90a111b3 653 #else
phonemacro 2:563d90a111b3 654 cmd[2] = 0x03; // sensor + algo data
phonemacro 4:4f1e9439f048 655 pc.printf("sens+algo \n\r");
phonemacro 2:563d90a111b3 656 #endif
phonemacro 6:e1b7190d6cb5 657 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 1:da792e46a385 658 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 659 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 660 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 661 pc.printf("1.2 Status: %x\n\r", rsp[0]);
phonemacro 52:e5aba237e804 662 // 1.4 Continuous HR, Spo2
phonemacro 52:e5aba237e804 663 #ifndef SPO2_CAL_RPT
phonemacro 32:92adfbe18ab6 664 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0A; cmd[3] = 0x00;
phonemacro 32:92adfbe18ab6 665 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 32:92adfbe18ab6 666 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 667 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 32:92adfbe18ab6 668 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 669 pc.printf("1.5 Status: %x\n\r", rsp[0]);
phonemacro 52:e5aba237e804 670 #endif
phonemacro 48:6b93b56bb22e 671 // 1.5 AEC enable (default)
phonemacro 4:4f1e9439f048 672 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0B; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 673 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 1:da792e46a385 674 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 675 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 676 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 677 pc.printf("1.6 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 678 #if AGC
phonemacro 48:6b93b56bb22e 679 // AGC 1.6 Disable auto PD (default
phonemacro 13:1baccc6275a7 680 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x12; cmd[3] = 0x00;
phonemacro 13:1baccc6275a7 681 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 13:1baccc6275a7 682 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 683 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 13:1baccc6275a7 684 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 685 pc.printf("AGC1.7 Status: %x\n\r", rsp[0]);
phonemacro 48:6b93b56bb22e 686 // AGC 1.7 Disable SCD (default)
phonemacro 13:1baccc6275a7 687 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0C; cmd[3] = 0x00;
phonemacro 13:1baccc6275a7 688 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 13:1baccc6275a7 689 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 690 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 13:1baccc6275a7 691 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 692 pc.printf("AGC1.8 Status: %x\n\r", rsp[0]);
phonemacro 48:6b93b56bb22e 693 // AGC 1.8 Set AGC target PD TO 10uA
phonemacro 13:1baccc6275a7 694 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x11; cmd[3] = 0x00; cmd[3] = 0x64;
phonemacro 13:1baccc6275a7 695 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 13:1baccc6275a7 696 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 697 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 13:1baccc6275a7 698 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 699 pc.printf("AGC1.9 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 700 #else
phonemacro 48:6b93b56bb22e 701 // 1.6 enable auto PD (default)
phonemacro 4:4f1e9439f048 702 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x12; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 703 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 1:da792e46a385 704 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 705 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 706 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 707 pc.printf("1.7 Status: %x\n\r", rsp[0]);
phonemacro 48:6b93b56bb22e 708 // 1.7 SCD (default)
phonemacro 4:4f1e9439f048 709 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0C; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 710 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 4:4f1e9439f048 711 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 712 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 4:4f1e9439f048 713 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 714 pc.printf("1.8 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 715 #endif
phonemacro 28:315604f4b374 716
phonemacro 28:315604f4b374 717 #if defined(MAXM86161_CFG) //only use Red and IR
phonemacro 55:04c9fad147d4 718 //1.20 map leds to slots
phonemacro 28:315604f4b374 719 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x23; cmd[4] = 0x00; cmd[5] = 0x00;
phonemacro 28:315604f4b374 720 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 28:315604f4b374 721 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 722 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 723 mfio = 1; mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 724 pc.printf("map leds to slots %x\n\r", rsp[0]);
phonemacro 30:77a30ea425da 725 //1.21 map HR inputs to slots, default is 0x0073 for MAXM86161
phonemacro 30:77a30ea425da 726 #if 0 // NA for MAXM86161
phonemacro 28:315604f4b374 727 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x73;
phonemacro 28:315604f4b374 728 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 28:315604f4b374 729 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 730 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 731 mfio = 1; mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 732 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 30:77a30ea425da 733 #endif
phonemacro 28:315604f4b374 734 //1.22 map SpO2 inputs to slots
phonemacro 28:315604f4b374 735 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x00; cmd[4] = 0x10;
phonemacro 28:315604f4b374 736 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 28:315604f4b374 737 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 738 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 739 mfio = 1; mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 740 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 28:315604f4b374 741 #endif
phonemacro 28:315604f4b374 742
phonemacro 3:da975696b936 743 #ifdef MAXM86146_CFG
phonemacro 32:92adfbe18ab6 744 //1.20 map leds to slots for MAXM86146
phonemacro 4:4f1e9439f048 745 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x13; cmd[4] = 0x56; cmd[5] = 0x00;
phonemacro 6:e1b7190d6cb5 746 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 3:da975696b936 747 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 748 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 749 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 750 pc.printf("map leds to slots %x\n\r", rsp[0]);
phonemacro 3:da975696b936 751 //1.21 map HR inputs to slots
phonemacro 4:4f1e9439f048 752 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x11;
phonemacro 6:e1b7190d6cb5 753 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 3:da975696b936 754 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 755 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 756 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 757 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 3:da975696b936 758 //1.22 map SpO2 inputs to slots
phonemacro 4:4f1e9439f048 759 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x30; cmd[4] = 0x20;
phonemacro 6:e1b7190d6cb5 760 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 3:da975696b936 761 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 762 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 763 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 764 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 26:33c0d3fd2a95 765
phonemacro 3:da975696b936 766 #if 0
phonemacro 2:563d90a111b3 767 //1.20 Sec 4.1 map leds to slots for MAXM86146
phonemacro 4:4f1e9439f048 768 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x15; cmd[4] = 0x60; cmd[5] = 0x00;
phonemacro 6:e1b7190d6cb5 769 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 1:da792e46a385 770 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 771 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 772 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 773 pc.printf("map leds to slots%x\n\r", rsp[0]);
phonemacro 2:563d90a111b3 774 //1.21 map HR inputs to slots
phonemacro 4:4f1e9439f048 775 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x01;
phonemacro 6:e1b7190d6cb5 776 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 1:da792e46a385 777 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 778 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 779 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 780 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 2:563d90a111b3 781 //1.22 map SpO2 inputs to slots
phonemacro 4:4f1e9439f048 782 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x20; cmd[4] = 0x10;
phonemacro 6:e1b7190d6cb5 783 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 1:da792e46a385 784 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 785 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 786 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 787 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 3:da975696b936 788 #endif
phonemacro 3:da975696b936 789 #endif // MAXM86146_CFG
phonemacro 0:6f65cae31c54 790
phonemacro 28:315604f4b374 791 #if 0 // MAXM86161 test new commands
phonemacro 28:315604f4b374 792 // LDO enable
phonemacro 28:315604f4b374 793 cmd[0] = 0x10; cmd[1] = 0x12; cmd[2] = 0x01;
phonemacro 28:315604f4b374 794 //cmd[0] = 0x10; cmd[1] = 0x12; cmd[2] = 0x00;
phonemacro 28:315604f4b374 795 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 28:315604f4b374 796 thread_sleep_for(2);
phonemacro 28:315604f4b374 797 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 798 pc.printf("\n\r ldo en %x\n\r", rsp[0]);
phonemacro 28:315604f4b374 799 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 800 // GPIO enable
phonemacro 28:315604f4b374 801 cmd[0] = 0x10; cmd[1] = 0x13; cmd[2] = 0x01;
phonemacro 28:315604f4b374 802 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 28:315604f4b374 803 thread_sleep_for(2);
phonemacro 28:315604f4b374 804 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 805 pc.printf("\n\r gpio en %x\n\r", rsp[0]);
phonemacro 28:315604f4b374 806 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 807 #endif
phonemacro 47:346a13fbdc0f 808 #if 0
phonemacro 47:346a13fbdc0f 809 //write SpO2 coefficients 0x00000000 FFD7FBDD 00AB61FE
phonemacro 55:04c9fad147d4 810 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x00;
phonemacro 47:346a13fbdc0f 811 cmd[3] = 0x00; cmd[4] = 0x00; cmd[5] = 0x00; cmd[6] = 0x00;
phonemacro 47:346a13fbdc0f 812 cmd[7] = 0xFF; cmd[8] = 0xD7; cmd[9] = 0xFB; cmd[10] = 0xDD;
phonemacro 47:346a13fbdc0f 813 cmd[11] = 0x00; cmd[12] = 0xAB; cmd[13] = 0x61; cmd[14] = 0xFE;
phonemacro 47:346a13fbdc0f 814 sh_i2c.write(SH_ADDR, cmd, 15);
phonemacro 47:346a13fbdc0f 815 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 47:346a13fbdc0f 816 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 47:346a13fbdc0f 817 mfio = 1; mfio = 0; wait_us(300);
phonemacro 47:346a13fbdc0f 818 pc.printf("Wr Spo2 Coeff %x\n\r", rsp[0]);
phonemacro 47:346a13fbdc0f 819 #endif
phonemacro 55:04c9fad147d4 820 //1.26 rd SpO2 Coefficients
phonemacro 47:346a13fbdc0f 821 cmd[0] = 0x51; cmd[1] = 0x07; cmd[2] = 0x00;
phonemacro 47:346a13fbdc0f 822 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 47:346a13fbdc0f 823 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 47:346a13fbdc0f 824 sh_i2c.read(SH_ADDR, rsp, 13);
phonemacro 47:346a13fbdc0f 825 mfio = 1; mfio = 0; wait_us(300);
phonemacro 47:346a13fbdc0f 826 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 827
phonemacro 32:92adfbe18ab6 828 // 1.30 Enable HR, SpO2 algo
phonemacro 12:17a0bf823462 829 #ifdef EXTENDED_ALGO
phonemacro 12:17a0bf823462 830 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x02;
phonemacro 33:c8fbd904df3e 831 #elif defined(PACKED_NORMAL_ALGO)
phonemacro 33:c8fbd904df3e 832 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x04;
phonemacro 12:17a0bf823462 833 #else
phonemacro 4:4f1e9439f048 834 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x01;
phonemacro 12:17a0bf823462 835 #endif
phonemacro 6:e1b7190d6cb5 836 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 28:315604f4b374 837 mfio = 1;
phonemacro 0:6f65cae31c54 838 thread_sleep_for(465);
phonemacro 28:315604f4b374 839 mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 840 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 841 pc.printf("1.14 status: %x\n\r", rsp[0]);
phonemacro 0:6f65cae31c54 842
phonemacro 4:4f1e9439f048 843 #if 1
phonemacro 4:4f1e9439f048 844 //1.31 rd AFE part id
phonemacro 4:4f1e9439f048 845 cmd[0] = 0x41; cmd[1] = 0x00; cmd[2] = 0xFF;
phonemacro 6:e1b7190d6cb5 846 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 4:4f1e9439f048 847 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 848 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 4:4f1e9439f048 849 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 850 pc.printf("1.31 part id afe %x %x\n\r", rsp[0], rsp[1]);
phonemacro 4:4f1e9439f048 851 //1.32 rd accel who
phonemacro 4:4f1e9439f048 852 cmd[0] = 0x41; cmd[1] = 0x04; cmd[2] = 0x0F;
phonemacro 6:e1b7190d6cb5 853 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 4:4f1e9439f048 854 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 855 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 4:4f1e9439f048 856 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 857 pc.printf("1.32 who accel %x %x\n\r", rsp[0], rsp[1]);
phonemacro 28:315604f4b374 858 #endif
phonemacro 52:e5aba237e804 859 // 1.35 spo2 calibration report for data collection
phonemacro 52:e5aba237e804 860 #ifdef SPO2_CAL_RPT
phonemacro 52:e5aba237e804 861 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0A; cmd[3] = 0x06;
phonemacro 52:e5aba237e804 862 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 52:e5aba237e804 863 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 52:e5aba237e804 864 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 52:e5aba237e804 865 mfio = 1; mfio = 0; wait_us(300);
phonemacro 52:e5aba237e804 866 pc.printf("1.5 Status: %x\n\r", rsp[0]);
phonemacro 52:e5aba237e804 867 #endif
phonemacro 52:e5aba237e804 868 // rd algo mode
phonemacro 52:e5aba237e804 869 cmd[0] = 0x51; cmd[1] = 0x07; cmd[2] = 0x0A;
phonemacro 52:e5aba237e804 870 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 52:e5aba237e804 871 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 52:e5aba237e804 872 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 52:e5aba237e804 873 mfio = 1; mfio = 0; wait_us(300);
phonemacro 52:e5aba237e804 874 pc.printf("algo mode %x %x\n\r", rsp[0], rsp[1]);
phonemacro 52:e5aba237e804 875
phonemacro 26:33c0d3fd2a95 876 mfio = 1;
phonemacro 10:192ea88e964b 877 }
phonemacro 10:192ea88e964b 878
phonemacro 14:c8cc6d7fd5f9 879 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 880 // init_sh_raw
phonemacro 14:c8cc6d7fd5f9 881 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 882 void init_sh_raw(void) {
phonemacro 29:a7dd81450b35 883 char cmd[16];
phonemacro 14:c8cc6d7fd5f9 884 char rsp[256];
phonemacro 55:04c9fad147d4 885
phonemacro 55:04c9fad147d4 886 reset_sh();
phonemacro 14:c8cc6d7fd5f9 887
phonemacro 14:c8cc6d7fd5f9 888 mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 889
phonemacro 32:92adfbe18ab6 890 //1.0 read operating mode
phonemacro 14:c8cc6d7fd5f9 891 cmd[0] = 0x02; cmd[1] = 0x00;
phonemacro 14:c8cc6d7fd5f9 892 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 14:c8cc6d7fd5f9 893 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 894 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 14:c8cc6d7fd5f9 895 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 896 pc.printf("\n\r 0x02 0x00 Status, Read Operating Mode: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 32:92adfbe18ab6 897 //1.1 rd ver
phonemacro 14:c8cc6d7fd5f9 898 cmd[0] = 0xFF; cmd[1] = 0x03;
phonemacro 14:c8cc6d7fd5f9 899 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 14:c8cc6d7fd5f9 900 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 901 sh_i2c.read(SH_ADDR, rsp, 4);
phonemacro 14:c8cc6d7fd5f9 902 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 903 pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]);
phonemacro 14:c8cc6d7fd5f9 904
phonemacro 32:92adfbe18ab6 905 // raw1.2 sensor data
phonemacro 14:c8cc6d7fd5f9 906 cmd[0] = 0x10; cmd[1] = 0x00; cmd[2] = 0x01;
phonemacro 14:c8cc6d7fd5f9 907 pc.printf("raw sensor data only \n\r");
phonemacro 14:c8cc6d7fd5f9 908 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 14:c8cc6d7fd5f9 909 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 910 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 911 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 912 pc.printf("raw1.2 Status: %x\n\r", rsp[0]);
phonemacro 32:92adfbe18ab6 913 // raw1.3 interrupt threshold
phonemacro 14:c8cc6d7fd5f9 914 cmd[0] = 0x10; cmd[1] = 0x01; cmd[2] = 0x01;
phonemacro 14:c8cc6d7fd5f9 915 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 14:c8cc6d7fd5f9 916 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 917 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 918 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 919 pc.printf("raw1.3 Status: %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 920 #ifdef MAXM86146_CFG
phonemacro 50:dd2f60ab5686 921 //1.20 map leds to slots for MAXM86146
phonemacro 50:dd2f60ab5686 922 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x13; cmd[4] = 0x56; cmd[5] = 0x00;
phonemacro 50:dd2f60ab5686 923 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 50:dd2f60ab5686 924 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 925 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 50:dd2f60ab5686 926 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 927 pc.printf("map leds to slots %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 928 //1.21 map HR inputs to slots
phonemacro 50:dd2f60ab5686 929 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x11;
phonemacro 50:dd2f60ab5686 930 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 50:dd2f60ab5686 931 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 932 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 50:dd2f60ab5686 933 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 934 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 935 //1.22 map SpO2 inputs to slots
phonemacro 50:dd2f60ab5686 936 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x30; cmd[4] = 0x20;
phonemacro 50:dd2f60ab5686 937 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 50:dd2f60ab5686 938 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 939 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 50:dd2f60ab5686 940 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 941 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 942 #endif
phonemacro 50:dd2f60ab5686 943
phonemacro 55:04c9fad147d4 944 //#if defined(MAXM86146_CFG) || defined(MAXM86161_CFG)
phonemacro 55:04c9fad147d4 945 #if 0
phonemacro 50:dd2f60ab5686 946 // raw enable sh accel
phonemacro 14:c8cc6d7fd5f9 947 cmd[0] = 0x44; cmd[1] = 0x04; cmd[2] = 0x01; cmd[3] = 0x00;
phonemacro 14:c8cc6d7fd5f9 948 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 29:a7dd81450b35 949 mfio = 1; thread_sleep_for(20); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 950 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 29:a7dd81450b35 951 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 952 pc.printf("raw1.10 accel Status: %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 953 // raw enable AFE
phonemacro 55:04c9fad147d4 954 // cmd[0] = 0x44; cmd[1] = 0x00; cmd[2] = 0x01; cmd[3] = 0x00;
phonemacro 30:77a30ea425da 955 // sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 38:8ff33869be1f 956 cmd[0] = 0x44; cmd[1] = 0x00; cmd[2] = 0x01; // 3 bytes // tested on 33.13.31/12
phonemacro 38:8ff33869be1f 957 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 55:04c9fad147d4 958 // 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 959 // sh_i2c.write(SH_ADDR, cmd, 9);
phonemacro 55:04c9fad147d4 960 mfio = 1; thread_sleep_for(465); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 961 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 962 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 963 pc.printf("raw1.11 afe en Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 964 #else
phonemacro 55:04c9fad147d4 965 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 38:8ff33869be1f 966 sh_i2c.write(SH_ADDR, cmd, 9);
phonemacro 38:8ff33869be1f 967 mfio = 1; thread_sleep_for(465); mfio = 0; wait_us(300);
phonemacro 29:a7dd81450b35 968 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 969 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 970 pc.printf("raw1.10/11 accel, afe en Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 971 #endif
phonemacro 32:92adfbe18ab6 972
phonemacro 50:dd2f60ab5686 973 /// raw 1.20 AFE part id
phonemacro 50:dd2f60ab5686 974 cmd[0] = 0x41; cmd[1] = 0x00; cmd[2] = 0xFF;
phonemacro 50:dd2f60ab5686 975 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 50:dd2f60ab5686 976 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 977 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 50:dd2f60ab5686 978 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 979 pc.printf("raw1.6 part id Status: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 50:dd2f60ab5686 980 // raw1.21 rd accel WHO reg
phonemacro 30:77a30ea425da 981 cmd[0] = 0x41; cmd[1] = 0x04; cmd[2] = 0x0F;
phonemacro 30:77a30ea425da 982 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 30:77a30ea425da 983 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 30:77a30ea425da 984 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 30:77a30ea425da 985 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 986 pc.printf("1.7 Who Status: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 32:92adfbe18ab6 987
phonemacro 55:04c9fad147d4 988 // raw1.8 sample rate
phonemacro 50:dd2f60ab5686 989 #if RAW_HZ == 25
phonemacro 50:dd2f60ab5686 990 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x00; // set AFE reg 0x12 to 25 Hz, ave 1
phonemacro 50:dd2f60ab5686 991 #elif RAW_HZ == 50
phonemacro 50:dd2f60ab5686 992 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x40; // set AFE reg 0x12 to 50 Hz
phonemacro 50:dd2f60ab5686 993 #elif RAW_HZ == 100
phonemacro 46:553559610878 994 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x18; // set AFE reg 0x12 to 100 Hz
phonemacro 50:dd2f60ab5686 995 #elif RAW_HZ == 200
phonemacro 50:dd2f60ab5686 996 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x20; // set AFE reg 0x12 to 200 Hz
phonemacro 50:dd2f60ab5686 997 #elif RAW_HZ == 2004
phonemacro 50:dd2f60ab5686 998 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x22; // set AFE reg 0x12 to 200 Hz, ave 4
phonemacro 46:553559610878 999 #else
phonemacro 46:553559610878 1000 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x18; // set AFE reg 0x12 to 100 Hz
phonemacro 46:553559610878 1001 #endif
phonemacro 14:c8cc6d7fd5f9 1002 // cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x20; // set AFE reg 0x12 to 200 Hz
phonemacro 14:c8cc6d7fd5f9 1003 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1004 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1005 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1006 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 1007 pc.printf("raw1.8 Status: %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 1008 // LED1 current
phonemacro 50:dd2f60ab5686 1009 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x23; cmd[3] = 0x19;
phonemacro 14:c8cc6d7fd5f9 1010 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1011 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1012 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1013 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1014 pc.printf("LED1 Status: %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 1015 // LED2 current
phonemacro 50:dd2f60ab5686 1016 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x24; cmd[3] = 0x19;
phonemacro 50:dd2f60ab5686 1017 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 50:dd2f60ab5686 1018 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1019 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 50:dd2f60ab5686 1020 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1021 pc.printf("LED2 Status: %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 1022 // LED3 current
phonemacro 50:dd2f60ab5686 1023 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x25; cmd[3] = 0x19;
phonemacro 14:c8cc6d7fd5f9 1024 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1025 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1026 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1027 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1028 pc.printf("LED3 Status: %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 1029 // LED4 current
phonemacro 50:dd2f60ab5686 1030 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x26; cmd[3] = 0x19;
phonemacro 14:c8cc6d7fd5f9 1031 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1032 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1033 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1034 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1035 pc.printf("LED4 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 1036 // LED5 current
phonemacro 50:dd2f60ab5686 1037 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x27; cmd[3] = 0x19;
phonemacro 14:c8cc6d7fd5f9 1038 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1039 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1040 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1041 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1042 pc.printf("LED5 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 1043 // LED6 current
phonemacro 50:dd2f60ab5686 1044 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x28; cmd[3] = 0x19;
phonemacro 14:c8cc6d7fd5f9 1045 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1046 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1047 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1048 mfio = 1; mfio = 0; wait_us(300);
phonemacro 50:dd2f60ab5686 1049 pc.printf("LED6 Status: %x\n\r", rsp[0]);
phonemacro 50:dd2f60ab5686 1050 #if 0
phonemacro 14:c8cc6d7fd5f9 1051 // Set Seq cntrl1 LED2, LED1
phonemacro 14:c8cc6d7fd5f9 1052 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x20; cmd[3] = 0x21;
phonemacro 14:c8cc6d7fd5f9 1053 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1054 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1055 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1056 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1057 pc.printf("Seq cntrl1 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 1058 // Set Seq cntrl2 LED4, LED3
phonemacro 14:c8cc6d7fd5f9 1059 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x21; cmd[3] = 0xA3;
phonemacro 14:c8cc6d7fd5f9 1060 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1061 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1062 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1063 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1064 pc.printf("Seq cntrl2 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 1065 // Set Seq cntrl3 LED6, LED5
phonemacro 14:c8cc6d7fd5f9 1066 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x22; cmd[3] = 0x21;
phonemacro 14:c8cc6d7fd5f9 1067 // cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x22; cmd[3] = 0x99; // Ambient
phonemacro 14:c8cc6d7fd5f9 1068 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 1069 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1070 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 1071 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 1072 pc.printf("Seq cntrl3 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 1073 #endif
phonemacro 28:315604f4b374 1074 mfio = 1;
phonemacro 28:315604f4b374 1075 }
phonemacro 14:c8cc6d7fd5f9 1076
phonemacro 55:04c9fad147d4 1077
phonemacro 55:04c9fad147d4 1078 void set_seq_green(void) {
phonemacro 55:04c9fad147d4 1079 char cmd[16];
phonemacro 55:04c9fad147d4 1080 char rsp[32];
phonemacro 55:04c9fad147d4 1081 // Set Sequence to ambient, LED1
phonemacro 55:04c9fad147d4 1082 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x20; cmd[3] = 0x91;
phonemacro 55:04c9fad147d4 1083 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1084 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1085 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1086 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1087 // pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1088 // Set Sequence to LED4, LED3 to ambient, ambient
phonemacro 55:04c9fad147d4 1089 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x21; cmd[3] = 0x99;
phonemacro 55:04c9fad147d4 1090 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1091 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1092 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1093 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1094 // pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1095 }
phonemacro 55:04c9fad147d4 1096
phonemacro 55:04c9fad147d4 1097 void set_green_reg(void) {
phonemacro 55:04c9fad147d4 1098 char cmd[16];
phonemacro 55:04c9fad147d4 1099 char rsp[32];
phonemacro 55:04c9fad147d4 1100
phonemacro 55:04c9fad147d4 1101 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x09; cmd[3] = 0x7D;
phonemacro 55:04c9fad147d4 1102 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1103 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1104 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1105 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1106 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1107
phonemacro 55:04c9fad147d4 1108 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x11; cmd[3] = 0x3F;
phonemacro 55:04c9fad147d4 1109 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1110 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1111 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1112 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1113 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1114
phonemacro 55:04c9fad147d4 1115 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x30;
phonemacro 55:04c9fad147d4 1116 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1117 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1118 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1119 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1120 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1121
phonemacro 55:04c9fad147d4 1122 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x13; cmd[3] = 0xC0;
phonemacro 55:04c9fad147d4 1123 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1124 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1125 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1126 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1127 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1128
phonemacro 55:04c9fad147d4 1129 #if 1
phonemacro 55:04c9fad147d4 1130 // set seq1 reg
phonemacro 55:04c9fad147d4 1131 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x20; cmd[3] = 0x21;
phonemacro 55:04c9fad147d4 1132 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1133 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1134 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1135 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1136 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1137
phonemacro 55:04c9fad147d4 1138 // set seq2 reg
phonemacro 55:04c9fad147d4 1139 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x21; cmd[3] = 0x03;
phonemacro 55:04c9fad147d4 1140 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1141 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1142 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1143 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1144 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1145 #endif
phonemacro 55:04c9fad147d4 1146 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x22; cmd[3] = 0x00;
phonemacro 55:04c9fad147d4 1147 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1148 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1149 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1150 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1151 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1152
phonemacro 55:04c9fad147d4 1153 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x09; cmd[3] = 0x7D;
phonemacro 55:04c9fad147d4 1154 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1155 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1156 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1157 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1158 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1159
phonemacro 55:04c9fad147d4 1160 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x23; cmd[3] = 0xA7;
phonemacro 55:04c9fad147d4 1161 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1162 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1163 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1164 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1165 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1166
phonemacro 55:04c9fad147d4 1167 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x24; cmd[3] = 0x00;
phonemacro 55:04c9fad147d4 1168 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1169 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1170 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1171 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1172 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1173
phonemacro 55:04c9fad147d4 1174 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x25; cmd[3] = 0x00;
phonemacro 55:04c9fad147d4 1175 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1176 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1177 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1178 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1179 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1180
phonemacro 55:04c9fad147d4 1181 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x2A; cmd[3] = 0x3F;
phonemacro 55:04c9fad147d4 1182 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1183 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1184 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1185 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1186 pc.printf("wr afe reg Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1187 }
phonemacro 55:04c9fad147d4 1188
phonemacro 55:04c9fad147d4 1189
phonemacro 55:04c9fad147d4 1190 /*****************************************************************************/
phonemacro 55:04c9fad147d4 1191 // init_sh_opt Mode1 optical validation for MAXM86161
phonemacro 55:04c9fad147d4 1192 /*****************************************************************************/
phonemacro 55:04c9fad147d4 1193 void init_sh_opt(void) {
phonemacro 55:04c9fad147d4 1194 char cmd[16];
phonemacro 55:04c9fad147d4 1195 char rsp[32];
phonemacro 55:04c9fad147d4 1196
phonemacro 55:04c9fad147d4 1197 reset_sh();
phonemacro 55:04c9fad147d4 1198
phonemacro 55:04c9fad147d4 1199 mfio = 0;wait_us(300);
phonemacro 55:04c9fad147d4 1200 //1.0 read operating mode
phonemacro 55:04c9fad147d4 1201 cmd[0] = 0x02; cmd[1] = 0x00;
phonemacro 55:04c9fad147d4 1202 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 55:04c9fad147d4 1203 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1204 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 55:04c9fad147d4 1205 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1206 pc.printf("\n\r 0x02 0x00 Status, Read Operating Mode: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 55:04c9fad147d4 1207 //1.1 rd ver
phonemacro 55:04c9fad147d4 1208 cmd[0] = 0xFF; cmd[1] = 0x03;
phonemacro 55:04c9fad147d4 1209 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 55:04c9fad147d4 1210 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1211 sh_i2c.read(SH_ADDR, rsp, 4);
phonemacro 55:04c9fad147d4 1212 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1213 pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]);
phonemacro 55:04c9fad147d4 1214
phonemacro 55:04c9fad147d4 1215 // Sensor Data only
phonemacro 55:04c9fad147d4 1216 cmd[0] = 0x10; cmd[1] = 0x00; cmd[2] = 0x01;
phonemacro 55:04c9fad147d4 1217 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 55:04c9fad147d4 1218 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1219 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1220 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1221 pc.printf("Sensor data Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1222
phonemacro 55:04c9fad147d4 1223 // HRM, SpO2
phonemacro 55:04c9fad147d4 1224 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0A; cmd[3] = 0x00;
phonemacro 55:04c9fad147d4 1225 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1226 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1227 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1228 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1229 pc.printf("HR, SPO2 Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1230 // Disable AEC
phonemacro 55:04c9fad147d4 1231 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0B; cmd[3] = 0x00;
phonemacro 55:04c9fad147d4 1232 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1233 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1234 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1235 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1236 pc.printf("Disable AEC Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1237 // Disable Auto PD
phonemacro 55:04c9fad147d4 1238 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x12; cmd[3] = 0x00;
phonemacro 55:04c9fad147d4 1239 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1240 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1241 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1242 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1243 pc.printf("Disable Auto PD Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1244 // Disable SCD
phonemacro 55:04c9fad147d4 1245 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0C; cmd[3] = 0x00;
phonemacro 55:04c9fad147d4 1246 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1247 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1248 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1249 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1250 pc.printf("Disable SCD Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1251
phonemacro 55:04c9fad147d4 1252
phonemacro 55:04c9fad147d4 1253 // Enable Algo, normal report
phonemacro 55:04c9fad147d4 1254 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x01;
phonemacro 55:04c9fad147d4 1255 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 55:04c9fad147d4 1256 mfio = 1; thread_sleep_for(465); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1257 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 55:04c9fad147d4 1258 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1259 pc.printf("Disable SCD Status: %x\n\r", rsp[0]);
phonemacro 55:04c9fad147d4 1260
phonemacro 55:04c9fad147d4 1261 #if 1
phonemacro 55:04c9fad147d4 1262 //1.31 rd AFE part id
phonemacro 55:04c9fad147d4 1263 cmd[0] = 0x41; cmd[1] = 0x00; cmd[2] = 0xFF;
phonemacro 55:04c9fad147d4 1264 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 55:04c9fad147d4 1265 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1266 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 55:04c9fad147d4 1267 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1268 pc.printf("1.31 part id afe %x %x\n\r", rsp[0], rsp[1]);
phonemacro 55:04c9fad147d4 1269 //1.32 rd accel who
phonemacro 55:04c9fad147d4 1270 cmd[0] = 0x41; cmd[1] = 0x04; cmd[2] = 0x0F;
phonemacro 55:04c9fad147d4 1271 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 55:04c9fad147d4 1272 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1273 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 55:04c9fad147d4 1274 mfio = 1; mfio = 0; wait_us(300);
phonemacro 55:04c9fad147d4 1275 pc.printf("1.32 who accel %x %x\n\r", rsp[0], rsp[1]);
phonemacro 55:04c9fad147d4 1276 #endif
phonemacro 55:04c9fad147d4 1277
phonemacro 55:04c9fad147d4 1278 set_green_reg();
phonemacro 55:04c9fad147d4 1279
phonemacro 55:04c9fad147d4 1280 mfio = 1;
phonemacro 55:04c9fad147d4 1281 }
phonemacro 14:c8cc6d7fd5f9 1282 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 1283 // main
phonemacro 14:c8cc6d7fd5f9 1284 /*****************************************************************************/
phonemacro 10:192ea88e964b 1285 int main()
phonemacro 10:192ea88e964b 1286 {
phonemacro 10:192ea88e964b 1287 sh_i2c.frequency(400000);
phonemacro 10:192ea88e964b 1288 int32_t ledcnt = 0;
phonemacro 10:192ea88e964b 1289 rLED = LED_OFF; gLED = LED_ON; bLED = LED_OFF;
phonemacro 10:192ea88e964b 1290 Ticker ticker; // calls a callback repeatedly with a timeout
phonemacro 28:315604f4b374 1291
phonemacro 28:315604f4b374 1292 #if 0 // test disable algo
phonemacro 28:315604f4b374 1293 char cmd[8];
phonemacro 28:315604f4b374 1294 char rsp[256];
phonemacro 55:04c9fad147d4 1295
phonemacro 28:315604f4b374 1296 // 3.1 Disable algo
phonemacro 28:315604f4b374 1297 mfio = 1; mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 1298 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x00;
phonemacro 28:315604f4b374 1299 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 28:315604f4b374 1300 thread_sleep_for(465);
phonemacro 28:315604f4b374 1301 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 1302 pc.printf("3.1 disable algo: %x\n\r", rsp[0]);
phonemacro 28:315604f4b374 1303 mfio = 1;
phonemacro 28:315604f4b374 1304 #endif
phonemacro 28:315604f4b374 1305
phonemacro 10:192ea88e964b 1306 //ticker.attach(callback(&blink_timer), BLINKING_RATE_MS); /* set timer for one second */
phonemacro 14:c8cc6d7fd5f9 1307 #ifdef RAW
phonemacro 14:c8cc6d7fd5f9 1308 init_sh_raw();
phonemacro 55:04c9fad147d4 1309 #elif defined(MAXM86161_OPT_VALIDATION_RED) || defined(MAXM86161_OPT_VALIDATION_IR) || defined(MAXM86161_OPT_VALIDATION_GRN)
phonemacro 55:04c9fad147d4 1310 init_sh_opt();
phonemacro 14:c8cc6d7fd5f9 1311 #else
phonemacro 14:c8cc6d7fd5f9 1312 init_sh_algo();
phonemacro 14:c8cc6d7fd5f9 1313 #endif
phonemacro 28:315604f4b374 1314 mfio = 1;
phonemacro 33:c8fbd904df3e 1315 heading_printed = 0;
phonemacro 8:e6ae69cfecbf 1316 #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG) || defined(MAXM86146_CFG)
phonemacro 6:e1b7190d6cb5 1317 Timer tmr1;
phonemacro 0:6f65cae31c54 1318 while (1) {
phonemacro 6:e1b7190d6cb5 1319 tmr1.start();
phonemacro 55:04c9fad147d4 1320 #if defined(RAW)
phonemacro 50:dd2f60ab5686 1321 #if RAW_HZ == 25
phonemacro 50:dd2f60ab5686 1322 if (tmr1.read_ms() >= 40) {
phonemacro 50:dd2f60ab5686 1323 #elif RAW_HZ == 50
phonemacro 50:dd2f60ab5686 1324 if (tmr1.read_ms() >= 20) {
phonemacro 50:dd2f60ab5686 1325 #elif RAW_HZ == 100
phonemacro 29:a7dd81450b35 1326 if (tmr1.read_ms() >= 10) {
phonemacro 50:dd2f60ab5686 1327 #elif RAW_HZ == 200 || RAW_HZ == 2004
phonemacro 50:dd2f60ab5686 1328 if (tmr1.read_ms() >= 5) {
phonemacro 46:553559610878 1329 #else
phonemacro 46:553559610878 1330 if (tmr1.read_ms() >= 10) {
phonemacro 46:553559610878 1331 #endif
phonemacro 29:a7dd81450b35 1332 #else
phonemacro 42:6f980909371f 1333 #ifdef REDUCE_RPT_PERIOD
phonemacro 42:6f980909371f 1334 #ifdef USE_FIFO_BUFFER_CNT
phonemacro 42:6f980909371f 1335 if (tmr1.read_ms() >= 40*REDUCE_RPT_PERIOD*USE_FIFO_BUFFER_CNT) {
phonemacro 42:6f980909371f 1336 #else
phonemacro 42:6f980909371f 1337 if (tmr1.read_ms() >= 40*REDUCE_RPT_PERIOD) {
phonemacro 42:6f980909371f 1338 #endif
phonemacro 42:6f980909371f 1339 #else
phonemacro 42:6f980909371f 1340 #ifdef USE_FIFO_BUFFER_CNT
phonemacro 42:6f980909371f 1341 if (tmr1.read_ms() >= 40*USE_FIFO_BUFFER_CNT) {
phonemacro 42:6f980909371f 1342 #else
phonemacro 28:315604f4b374 1343 if (tmr1.read_ms() >= 40) {
phonemacro 42:6f980909371f 1344 #endif
phonemacro 42:6f980909371f 1345 #endif
phonemacro 29:a7dd81450b35 1346 #endif
phonemacro 7:23b067817ab8 1347 tmr1.reset();
phonemacro 10:192ea88e964b 1348 read_sh_fifo();
phonemacro 55:04c9fad147d4 1349
phonemacro 55:04c9fad147d4 1350 #if defined(MAXM86161_OPT_VALIDATION_GRN)
phonemacro 55:04c9fad147d4 1351 // set_seq_green();
phonemacro 55:04c9fad147d4 1352 #endif
phonemacro 55:04c9fad147d4 1353
phonemacro 7:23b067817ab8 1354 if ((ledcnt++ % 50) == 0)
phonemacro 6:e1b7190d6cb5 1355 gLED = !gLED;
phonemacro 0:6f65cae31c54 1356 }
phonemacro 0:6f65cae31c54 1357 }
phonemacro 6:e1b7190d6cb5 1358 #else
phonemacro 6:e1b7190d6cb5 1359 ticker.attach(callback(&fifo_timer), 0.040f);
phonemacro 6:e1b7190d6cb5 1360 while (1) {
phonemacro 6:e1b7190d6cb5 1361 if (Time_to_Read_PPG) {
phonemacro 10:192ea88e964b 1362 read_sh_fifo();
phonemacro 7:23b067817ab8 1363 if ((ledcnt++ % 50) == 0)
phonemacro 6:e1b7190d6cb5 1364 gLED = !gLED;
phonemacro 6:e1b7190d6cb5 1365 }
phonemacro 6:e1b7190d6cb5 1366 }
phonemacro 6:e1b7190d6cb5 1367 #endif
phonemacro 0:6f65cae31c54 1368 }