Mode1 Optical Validation

Dependencies:   max32630fthr

Committer:
phonemacro
Date:
Fri May 20 02:09:50 2022 +0000
Revision:
57:51feeb984d0b
Parent:
56:60b61d5c8154
Child:
58:33af4ccb8220
added color tests

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