Mode1 Optical Validation

Dependencies:   max32630fthr

Committer:
phonemacro
Date:
Tue Apr 12 22:53:08 2022 +0000
Revision:
44:1b165a68474d
Parent:
43:81a5371eeb7e
Child:
45:d26b8bcce561
Fix accel data indexing

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 44:1b165a68474d 40 * ver: 220412
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 36:a6e7ff9c87a0 54 //#define MAXM86146_CFG 1 // tested on MAXM86146EVSYS_sensorBrd+MAXM86161_ADAPTER_REVB+MAX32630FTHR 33.13.31/12
phonemacro 21:67d58af1ec56 55 //#define MAXREFDES103_CFG // not tested
phonemacro 36:a6e7ff9c87a0 56 #define MAXM86161_CFG 1 // tested on MAXM86161+MAX32630FTHR v32.9.23, 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 40:b32b644797ba 87 //#define RAW // define this if you want AFE+accel data, no algorithm
phonemacro 44:1b165a68474d 88 //#define ALGO_ONLY 1 // define this if you only want algo data, comment out if you want raw sensor+algo data
phonemacro 33:c8fbd904df3e 89
phonemacro 33:c8fbd904df3e 90 // Comment out both of the below for Normal Algorithm Samples Format
phonemacro 33:c8fbd904df3e 91 //#define EXTENDED_ALGO 1 // define this if you want the extended algo samples report format
phonemacro 35:67699bdae57e 92 //#define PACKED_NORMAL_ALGO 1 // define this if you want the packed normal algo samples report format, 33.13.31
phonemacro 37:249b548e6488 93 //#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 94 //#define AGC 1 // define this for AGC, otherwise the default is AEC
phonemacro 6:e1b7190d6cb5 95
phonemacro 42:6f980909371f 96
phonemacro 42:6f980909371f 97 //#define REDUCE_RPT_PERIOD 0x19 // Report samples every 25 frame.
phonemacro 42:6f980909371f 98 //#define USE_FIFO_BUFFER_CNT 5 // Allow the FIFO to fill this many samples
phonemacro 42:6f980909371f 99
phonemacro 6:e1b7190d6cb5 100 #ifdef MAXREFDES103_CFG
phonemacro 5:7f5a012747a5 101 #include "MAX20303.h"
phonemacro 6:e1b7190d6cb5 102 I2C sh_i2c_pmic(P5_7, P6_0);
phonemacro 5:7f5a012747a5 103 #endif
phonemacro 5:7f5a012747a5 104
phonemacro 32:92adfbe18ab6 105 #ifdef MAXM86146_CFG
phonemacro 32:92adfbe18ab6 106 #define PPG_SZ 36 //maxm86146
phonemacro 32:92adfbe18ab6 107 #else
phonemacro 32:92adfbe18ab6 108 #define PPG_SZ 18 //maxm86161, max86141
phonemacro 32:92adfbe18ab6 109 #endif
phonemacro 32:92adfbe18ab6 110 #define ACCEL_SZ 6 // accel
phonemacro 32:92adfbe18ab6 111 #define SENSOR_SZ (PPG_SZ+ACCEL_SZ)
phonemacro 32:92adfbe18ab6 112
phonemacro 32:92adfbe18ab6 113 #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 114 #define old_algo_sz 1 // 3x.12.0 or earlier; 32.9.x
phonemacro 28:315604f4b374 115 #endif
phonemacro 30:77a30ea425da 116
phonemacro 33:c8fbd904df3e 117 #ifdef old_algo_sz
phonemacro 18:f4c95b1c0efc 118 #ifdef EXTENDED_ALGO
phonemacro 33:c8fbd904df3e 119 #define ALGO_SZ 52 // 52 bytes, extended algo size for 3x.12.0
phonemacro 33:c8fbd904df3e 120 #elif defined(PACKED_NORMAL_ALGO)
phonemacro 33:c8fbd904df3e 121 #define ALGO_SZ 16 // 16 bytes, packed algo normal size for 33.31.31
phonemacro 18:f4c95b1c0efc 122 #else
phonemacro 42:6f980909371f 123 #define ALGO_SZ 20 // 20 bytes, normal algo size for 3x.12.0
phonemacro 18:f4c95b1c0efc 124 #endif
phonemacro 12:17a0bf823462 125 #else
phonemacro 18:f4c95b1c0efc 126 #ifdef EXTENDED_ALGO
phonemacro 33:c8fbd904df3e 127 #define ALGO_SZ 56 // 56 bytes, extended algo size for 3x.13.x+
phonemacro 18:f4c95b1c0efc 128 #else
phonemacro 33:c8fbd904df3e 129 #define ALGO_SZ 24 // 24 bytes, normal algo size for 3x.13.x+
phonemacro 18:f4c95b1c0efc 130 #endif
phonemacro 12:17a0bf823462 131 #endif
phonemacro 18:f4c95b1c0efc 132
phonemacro 0:6f65cae31c54 133 #ifdef ALGO_ONLY
phonemacro 0:6f65cae31c54 134 #define TTL_SZ (ALGO_SZ)
phonemacro 0:6f65cae31c54 135 #else
phonemacro 14:c8cc6d7fd5f9 136 #ifdef RAW
phonemacro 14:c8cc6d7fd5f9 137 #define TTL_SZ (PPG_SZ+ACCEL_SZ)
phonemacro 14:c8cc6d7fd5f9 138 #else
phonemacro 14:c8cc6d7fd5f9 139 #define TTL_SZ (PPG_SZ+ACCEL_SZ+ALGO_SZ)
phonemacro 14:c8cc6d7fd5f9 140 #endif
phonemacro 0:6f65cae31c54 141 #endif
phonemacro 0:6f65cae31c54 142
phonemacro 3:da975696b936 143 Serial pc(USBTX, USBRX, 115200);
phonemacro 0:6f65cae31c54 144 DigitalOut rLED(LED1);
phonemacro 0:6f65cae31c54 145 DigitalOut gLED(LED2);
phonemacro 0:6f65cae31c54 146 DigitalOut bLED(LED3);
phonemacro 6:e1b7190d6cb5 147
phonemacro 33:c8fbd904df3e 148 int32_t heading_printed; // has the heading been printed?
phonemacro 33:c8fbd904df3e 149
phonemacro 33:c8fbd904df3e 150
phonemacro 6:e1b7190d6cb5 151 //#define thread_sleep_for(x) wait_ms(x) // for older versions of mbed
phonemacro 0:6f65cae31c54 152
phonemacro 5:7f5a012747a5 153
phonemacro 6:e1b7190d6cb5 154 const int SH_ADDR = 0xAA;//0x55;
phonemacro 0:6f65cae31c54 155 int32_t Time_to_Read_PPG = 0;
phonemacro 0:6f65cae31c54 156
phonemacro 0:6f65cae31c54 157 #define BLINKING_RATE_MS 1000ms
phonemacro 0:6f65cae31c54 158 void blink_timer(void) {
phonemacro 0:6f65cae31c54 159 gLED = !gLED; /* blink the green LED */
phonemacro 0:6f65cae31c54 160 }
phonemacro 0:6f65cae31c54 161
phonemacro 0:6f65cae31c54 162 void fifo_timer(void) {
phonemacro 0:6f65cae31c54 163 Time_to_Read_PPG = 1;
phonemacro 0:6f65cae31c54 164 }
phonemacro 0:6f65cae31c54 165
phonemacro 14:c8cc6d7fd5f9 166 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 167 // read_sh_fifo
phonemacro 14:c8cc6d7fd5f9 168 /*****************************************************************************/
phonemacro 27:a45d6e38f2de 169 /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/
phonemacro 28:315604f4b374 170 #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 171 #ifdef OPTIMIZE_FIFO_READ // tested on MAXM86146EVSYS
phonemacro 27:a45d6e38f2de 172 int32_t check_fifo_countdown;
phonemacro 42:6f980909371f 173 #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 174 #endif
phonemacro 42:6f980909371f 175
phonemacro 10:192ea88e964b 176 void read_sh_fifo(void) {
phonemacro 33:c8fbd904df3e 177 char cmd[8], i, j, k, samples;
phonemacro 0:6f65cae31c54 178 char rsp[3000];
phonemacro 0:6f65cae31c54 179 int32_t ppg[12];
phonemacro 5:7f5a012747a5 180 int16_t accel[3];
phonemacro 33:c8fbd904df3e 181 int32_t tst[20];
phonemacro 12:17a0bf823462 182 int32_t status, opmode, hr, hr_conf, ibi, ibi_conf;
phonemacro 12:17a0bf823462 183 #ifdef EXTENDED_ALGO
phonemacro 12:17a0bf823462 184 int32_t walk_stp, run_stp, energy, amr, iadj1_rqt, iadj1, iadj2_rqt, iadj2, iadj3_rqt, iadj3;
phonemacro 12:17a0bf823462 185 int32_t intadj_rqt, intadj, smpladj_rqt, smpladj, rqt_smplave, afestatehr, hr_motion;
phonemacro 12:17a0bf823462 186 #endif
phonemacro 12:17a0bf823462 187 int32_t act, r, spo2, spo2_conf;
phonemacro 33:c8fbd904df3e 188 int32_t spo2_compl, spo2_lo, spo2_mo, spo2_lopi, spo2_unrel, spo2_state, ibi_offset, scd, inappro_ori;
phonemacro 0:6f65cae31c54 189 int32_t ptr = 0;
phonemacro 0:6f65cae31c54 190 int32_t sptr = 0;
phonemacro 1:da792e46a385 191 mfio = 0; wait_us(300);
phonemacro 0:6f65cae31c54 192 Time_to_Read_PPG = 0;
phonemacro 42:6f980909371f 193 samples = 1;
phonemacro 42:6f980909371f 194 #ifdef USE_FIFO_BUFFER_CNT
phonemacro 42:6f980909371f 195 samples = USE_FIFO_BUFFER_CNT;
phonemacro 42:6f980909371f 196 #endif
phonemacro 27:a45d6e38f2de 197 #if defined(OPTIMIZE_FIFO_READ)
phonemacro 27:a45d6e38f2de 198 check_fifo_countdown--;
phonemacro 27:a45d6e38f2de 199 if (check_fifo_countdown == 0) {
phonemacro 27:a45d6e38f2de 200 #endif
phonemacro 27:a45d6e38f2de 201
phonemacro 22:f6b366c3b954 202 #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG)
phonemacro 0:6f65cae31c54 203 // 2.1
phonemacro 27:a45d6e38f2de 204 cmd[0] = 0x00; cmd[1] = 0x00;
phonemacro 27:a45d6e38f2de 205 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 27:a45d6e38f2de 206 wait_us(100);
phonemacro 27:a45d6e38f2de 207 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 27:a45d6e38f2de 208 // pc.printf("2.1 Status: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 22:f6b366c3b954 209 #else
phonemacro 33:c8fbd904df3e 210 // tested w/ 33.13.12 doen't need 2.1
phonemacro 0:6f65cae31c54 211 #endif
phonemacro 0:6f65cae31c54 212 // 2.2
phonemacro 35:67699bdae57e 213 #if defined(PACKED_NORMAL_ALGO)
phonemacro 35:67699bdae57e 214 cmd[0] = 0x20;
phonemacro 35:67699bdae57e 215 sh_i2c.write(SH_ADDR, cmd, 1);
phonemacro 35:67699bdae57e 216 #else
phonemacro 27:a45d6e38f2de 217 cmd[0] = 0x12; cmd[1] = 0x00;
phonemacro 27:a45d6e38f2de 218 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 35:67699bdae57e 219 #endif
phonemacro 27:a45d6e38f2de 220 wait_us(100);
phonemacro 27:a45d6e38f2de 221 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 35:67699bdae57e 222 // mfio = 1; mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 223
phonemacro 27:a45d6e38f2de 224 // pc.printf("2.2 Status: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 27:a45d6e38f2de 225 samples = rsp[1];
phonemacro 27:a45d6e38f2de 226 // pc.printf("num samples %d, (num*ttl)+1 %d\n\r", rsp[1], TTL_SZ*samples+1);
phonemacro 27:a45d6e38f2de 227 // pc.printf("num smpls %d \n\r", samples);
phonemacro 27:a45d6e38f2de 228 #if defined(OPTIMIZE_FIFO_READ)
phonemacro 27:a45d6e38f2de 229 }
phonemacro 27:a45d6e38f2de 230 if (check_fifo_countdown <= 0)
phonemacro 27:a45d6e38f2de 231 check_fifo_countdown = MAX_FIFO_CNT;
phonemacro 27:a45d6e38f2de 232 #endif
phonemacro 27:a45d6e38f2de 233
phonemacro 0:6f65cae31c54 234 // 2.3
phonemacro 35:67699bdae57e 235 #if defined(PACKED_NORMAL_ALGO)
phonemacro 35:67699bdae57e 236 cmd[0] = 0x21;;
phonemacro 35:67699bdae57e 237 sh_i2c.write(SH_ADDR, cmd, 1);
phonemacro 35:67699bdae57e 238 #else
phonemacro 35:67699bdae57e 239 cmd[0] = 0x12; cmd[1] = 0x01;
phonemacro 35:67699bdae57e 240 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 35:67699bdae57e 241 #endif
phonemacro 35:67699bdae57e 242 wait_us(100);
phonemacro 35:67699bdae57e 243 sh_i2c.read(SH_ADDR, rsp, 1+(TTL_SZ*samples));
phonemacro 42:6f980909371f 244 //pc.printf("num smpls %d ttlsiz %d\n\r", samples, TTL_SZ);
phonemacro 35:67699bdae57e 245 // mfio = 1; mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 246 mfio = 1;
phonemacro 21:67d58af1ec56 247
phonemacro 0:6f65cae31c54 248 status = rsp[0];
phonemacro 5:7f5a012747a5 249
phonemacro 0:6f65cae31c54 250 sptr = 1;
phonemacro 42:6f980909371f 251 for (i = 0; i < samples; i++) {
phonemacro 0:6f65cae31c54 252 ptr = sptr;
phonemacro 35:67699bdae57e 253 #if !defined(ALGO_ONLY)
phonemacro 2:563d90a111b3 254 ppg[0] = (rsp[ptr+0] << 16) | (rsp[ptr+1] << 8) | (rsp[ptr+2]);
phonemacro 2:563d90a111b3 255 ppg[1] = (rsp[ptr+3] << 16) | (rsp[ptr+4] << 8) | (rsp[ptr+5]);
phonemacro 2:563d90a111b3 256 ppg[2] = (rsp[ptr+6] << 16) | (rsp[ptr+7] << 8) | (rsp[ptr+8]);
phonemacro 3:da975696b936 257 ppg[3] = (rsp[ptr+9] << 16) | (rsp[ptr+10] << 8) | (rsp[ptr+11]);
phonemacro 4:4f1e9439f048 258 ppg[4] = (rsp[ptr+12] << 16) | (rsp[ptr+13] << 8) | (rsp[ptr+14]);
phonemacro 4:4f1e9439f048 259 ppg[5] = (rsp[ptr+15] << 16) | (rsp[ptr+16] << 8) | (rsp[ptr+17]);
phonemacro 3:da975696b936 260 pc.printf("%d,%d,%d,%d,", ppg[0], ppg[1], ppg[2], ppg[3]);
phonemacro 14:c8cc6d7fd5f9 261 #ifdef MAXM86146_CFG
phonemacro 32:92adfbe18ab6 262 #ifdef RAW
phonemacro 14:c8cc6d7fd5f9 263 pc.printf("%d,%d,", ppg[4], ppg[5]);
phonemacro 14:c8cc6d7fd5f9 264 ppg[6] = (rsp[ptr+18] << 16) | (rsp[ptr+19] << 8) | (rsp[ptr+20]);
phonemacro 14:c8cc6d7fd5f9 265 ppg[7] = (rsp[ptr+21] << 16) | (rsp[ptr+22] << 8) | (rsp[ptr+23]);
phonemacro 14:c8cc6d7fd5f9 266 ppg[8] = (rsp[ptr+24] << 16) | (rsp[ptr+25] << 8) | (rsp[ptr+26]);
phonemacro 14:c8cc6d7fd5f9 267 ppg[9] = (rsp[ptr+27] << 16) | (rsp[ptr+28] << 8) | (rsp[ptr+29]);
phonemacro 14:c8cc6d7fd5f9 268 ppg[10] = (rsp[ptr+30] << 16) | (rsp[ptr+31] << 8) | (rsp[ptr+32]);
phonemacro 14:c8cc6d7fd5f9 269 ppg[11] = (rsp[ptr+33] << 16) | (rsp[ptr+34] << 8) | (rsp[ptr+35]);
phonemacro 14:c8cc6d7fd5f9 270 pc.printf("%d,%d,%d,%d,%d,%d,", ppg[6], ppg[7],ppg[8], ppg[9],ppg[10], ppg[11]);
phonemacro 36:a6e7ff9c87a0 271 #endif // raw
phonemacro 36:a6e7ff9c87a0 272 #endif // MAXM86146_CFG
phonemacro 44:1b165a68474d 273 accel[0] = (rsp[1+PPG_SZ+0] << 8) | (rsp[1+PPG_SZ+1]);
phonemacro 44:1b165a68474d 274 accel[1] = (rsp[1+PPG_SZ+2] << 8) | (rsp[1+PPG_SZ+3]);
phonemacro 44:1b165a68474d 275 accel[2] = (rsp[1+PPG_SZ+4] << 8) | (rsp[1+PPG_SZ+5]);
phonemacro 5:7f5a012747a5 276 pc.printf("%d,%d,%d,", accel[0], accel[1], accel[2]);
phonemacro 5:7f5a012747a5 277
phonemacro 0:6f65cae31c54 278 ptr = sptr + SENSOR_SZ;
phonemacro 36:a6e7ff9c87a0 279
phonemacro 36:a6e7ff9c87a0 280 #endif //!defined(ALGO_ONLY)
phonemacro 29:a7dd81450b35 281
phonemacro 14:c8cc6d7fd5f9 282 #ifndef RAW
phonemacro 12:17a0bf823462 283 #ifdef EXTENDED_ALGO
phonemacro 0:6f65cae31c54 284 opmode = rsp[ptr];
phonemacro 0:6f65cae31c54 285 hr = (rsp[ptr+1] << 8) + rsp[ptr+2];
phonemacro 0:6f65cae31c54 286 hr_conf = rsp[ptr+3];
phonemacro 12:17a0bf823462 287 ibi = (rsp[ptr+4] << 8) + rsp[ptr+5];
phonemacro 12:17a0bf823462 288
phonemacro 12:17a0bf823462 289 ibi_conf = rsp[ptr+6];
phonemacro 12:17a0bf823462 290 act = rsp[ptr+7];
phonemacro 12:17a0bf823462 291 walk_stp = (rsp[ptr+8] << 24) + (rsp[ptr+9] << 16) + (rsp[ptr+10] << 8) + rsp[ptr+11];
phonemacro 12:17a0bf823462 292 run_stp = (rsp[ptr+12] << 24) + (rsp[ptr+13] << 16) + (rsp[ptr+14] << 8) + rsp[ptr+15];
phonemacro 12:17a0bf823462 293
phonemacro 12:17a0bf823462 294 energy = (rsp[ptr+16] << 24) + (rsp[ptr+17] << 16) + (rsp[ptr+18] << 8) + rsp[ptr+19];
phonemacro 12:17a0bf823462 295 amr = (rsp[ptr+20] << 24) + (rsp[ptr+21] << 16) + (rsp[ptr+22] << 8) + rsp[ptr+23];
phonemacro 12:17a0bf823462 296 iadj1_rqt = rsp[ptr+24];
phonemacro 12:17a0bf823462 297 iadj1 = (rsp[ptr+25] << 8) + rsp[ptr+26];
phonemacro 12:17a0bf823462 298
phonemacro 12:17a0bf823462 299 iadj2_rqt = rsp[ptr+27];
phonemacro 12:17a0bf823462 300 iadj2 = (rsp[ptr+28] << 8) + rsp[ptr+29];
phonemacro 12:17a0bf823462 301 iadj3_rqt = rsp[ptr+30];
phonemacro 12:17a0bf823462 302 iadj3 = (rsp[ptr+31] << 8) + rsp[ptr+32];
phonemacro 12:17a0bf823462 303
phonemacro 12:17a0bf823462 304 intadj_rqt = rsp[ptr+33];
phonemacro 12:17a0bf823462 305 intadj = rsp[ptr+34];
phonemacro 12:17a0bf823462 306 smpladj_rqt = rsp[ptr+35];
phonemacro 12:17a0bf823462 307 smpladj = rsp[ptr+36];
phonemacro 12:17a0bf823462 308
phonemacro 12:17a0bf823462 309 rqt_smplave = rsp[ptr+37];
phonemacro 12:17a0bf823462 310 afestatehr = rsp[ptr+38];
phonemacro 12:17a0bf823462 311 hr_motion = rsp[ptr+39];
phonemacro 12:17a0bf823462 312 scd = rsp[ptr+40];
phonemacro 12:17a0bf823462 313
phonemacro 12:17a0bf823462 314
phonemacro 12:17a0bf823462 315 r = (rsp[ptr+41] << 8) + rsp[ptr+42];
phonemacro 12:17a0bf823462 316 spo2_conf = rsp[ptr+43];
phonemacro 12:17a0bf823462 317
phonemacro 12:17a0bf823462 318 spo2 = (rsp[ptr+44] << 8) + rsp[ptr+45];
phonemacro 12:17a0bf823462 319 spo2_compl = rsp[ptr+46];
phonemacro 12:17a0bf823462 320 spo2_lo = rsp[ptr+47];
phonemacro 12:17a0bf823462 321 spo2_mo = rsp[ptr+48];
phonemacro 12:17a0bf823462 322
phonemacro 12:17a0bf823462 323 spo2_lopi = rsp[ptr+49];
phonemacro 12:17a0bf823462 324 spo2_unrel = rsp[ptr+50];
phonemacro 12:17a0bf823462 325 spo2_state = rsp[ptr+51];
phonemacro 12:17a0bf823462 326
phonemacro 12:17a0bf823462 327 ibi_offset = rsp[ptr+52];
phonemacro 12:17a0bf823462 328
phonemacro 12:17a0bf823462 329 sptr += (TTL_SZ);
phonemacro 36:a6e7ff9c87a0 330
phonemacro 12:17a0bf823462 331 #if 1
phonemacro 33:c8fbd904df3e 332 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 333 heading_printed = 1;
phonemacro 36:a6e7ff9c87a0 334 #if defined(ALGO_ONLY)
phonemacro 33:c8fbd904df3e 335 pc.printf("opmode,hr,hr_conf,ibi,ibi_conf,act,walk_stp,run_stp,energy,amr,");
phonemacro 33:c8fbd904df3e 336 pc.printf("iadj1_rqt,iadj1,iadj2_rqt,iadj2,iadj3_rqt,iadj3,intadj_rqt,intadj,");
phonemacro 33:c8fbd904df3e 337 pc.printf("smpladj_rqt,smpladj,rqt_smplave,afestatehr,hr_motion,scd,");
phonemacro 33:c8fbd904df3e 338 pc.printf("spo2,spo2_compl,spo2_lo,spo2_mo,spo2_lopi,spo2_unrel,spo2_state,ibi_offset,\n\r");
phonemacro 36:a6e7ff9c87a0 339 #endif
phonemacro 33:c8fbd904df3e 340 }
phonemacro 12:17a0bf823462 341 pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi);
phonemacro 12:17a0bf823462 342 pc.printf("%d,%d,", ibi_conf, act);
phonemacro 12:17a0bf823462 343 pc.printf("%d,%d,%d,", walk_stp, run_stp, energy);
phonemacro 12:17a0bf823462 344 pc.printf("%d,%d,%d,%d,", amr, iadj1_rqt, iadj1, iadj2_rqt);
phonemacro 12:17a0bf823462 345 pc.printf("%d,%d,%d,%d,", iadj2, iadj3_rqt, iadj3, intadj_rqt);
phonemacro 12:17a0bf823462 346 pc.printf("%d,%d,%d,%d,", intadj, smpladj_rqt, smpladj, rqt_smplave);
phonemacro 12:17a0bf823462 347 pc.printf("%d,%d,", afestatehr, hr_motion);
phonemacro 12:17a0bf823462 348 pc.printf("%d,", scd);
phonemacro 12:17a0bf823462 349 pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo);
phonemacro 12:17a0bf823462 350 pc.printf("%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state);
phonemacro 12:17a0bf823462 351 pc.printf("%d,", ibi_offset);
phonemacro 12:17a0bf823462 352 #else
phonemacro 33:c8fbd904df3e 353 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 354 heading_printed = 1;
phonemacro 36:a6e7ff9c87a0 355 #if defined(ALGO_ONLY)
phonemacro 33:c8fbd904df3e 356 pc.printf("hr,hr_conf,spo2,spo2_conf,spo2_lo,spo2_unrel,scd,\n\r");
phonemacro 36:a6e7ff9c87a0 357 #endif
phonemacro 33:c8fbd904df3e 358 }
phonemacro 12:17a0bf823462 359 pc.printf("%d,%d,", hr, hr_conf);
phonemacro 12:17a0bf823462 360 pc.printf("%d,%d,", spo2, spo2_conf);
phonemacro 16:ff1122f0624a 361 pc.printf("%d,%d,%d,", spo2_lo, spo2_mo, spo2_lopi);
phonemacro 12:17a0bf823462 362 pc.printf("%d,%d,", spo2_unrel, scd);
phonemacro 36:a6e7ff9c87a0 363 #endif // if 1
phonemacro 33:c8fbd904df3e 364 #elif defined(PACKED_NORMAL_ALGO)
phonemacro 33:c8fbd904df3e 365 // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ);
phonemacro 35:67699bdae57e 366 opmode = rsp[ptr];
phonemacro 33:c8fbd904df3e 367 hr = (rsp[ptr+1] << 8) + rsp[ptr+2];
phonemacro 33:c8fbd904df3e 368 hr_conf = rsp[ptr+3];
phonemacro 33:c8fbd904df3e 369 ibi = (rsp[ptr+4] << 8) + rsp[ptr+5];
phonemacro 33:c8fbd904df3e 370
phonemacro 33:c8fbd904df3e 371 ibi_conf = rsp[ptr+6];
phonemacro 33:c8fbd904df3e 372 // act = rsp[ptr+7];
phonemacro 33:c8fbd904df3e 373 r = (rsp[ptr+7] << 8) + rsp[ptr+8];
phonemacro 33:c8fbd904df3e 374 spo2_conf = rsp[ptr+9];
phonemacro 33:c8fbd904df3e 375
phonemacro 33:c8fbd904df3e 376 spo2 = (rsp[ptr+10] << 8) + rsp[ptr+11];
phonemacro 33:c8fbd904df3e 377 spo2_compl = rsp[ptr+12];
phonemacro 33:c8fbd904df3e 378
phonemacro 33:c8fbd904df3e 379 spo2_lo = 0; spo2_mo = 0; spo2_lopi = 0; spo2_unrel = 0;
phonemacro 33:c8fbd904df3e 380
phonemacro 33:c8fbd904df3e 381 if (rsp[ptr+13] & 0x01)
phonemacro 33:c8fbd904df3e 382 spo2_lo = 1;
phonemacro 33:c8fbd904df3e 383 if (rsp[ptr+13] & 0x02)
phonemacro 33:c8fbd904df3e 384 spo2_mo = 1;
phonemacro 33:c8fbd904df3e 385 if (rsp[ptr+13] & 0x04)
phonemacro 33:c8fbd904df3e 386 spo2_lopi = 1;
phonemacro 33:c8fbd904df3e 387 if (rsp[ptr+13] & 0x08)
phonemacro 33:c8fbd904df3e 388 spo2_unrel = 1;
phonemacro 33:c8fbd904df3e 389 spo2_state = (0x30 & rsp[ptr+13]) >> 4;
phonemacro 33:c8fbd904df3e 390
phonemacro 33:c8fbd904df3e 391 scd = (0x03 & rsp[ptr+14]);
phonemacro 33:c8fbd904df3e 392 act = (0x1C & rsp[ptr+14]) >> 2;
phonemacro 33:c8fbd904df3e 393 inappro_ori = (0x20 & rsp[ptr+14]) >> 5;
phonemacro 33:c8fbd904df3e 394
phonemacro 33:c8fbd904df3e 395 ibi_offset = rsp[ptr+15];
phonemacro 33:c8fbd904df3e 396
phonemacro 33:c8fbd904df3e 397 sptr += (TTL_SZ);
phonemacro 37:249b548e6488 398 #if defined(PCK_CFG_MASK) // hex out, for printing config masked out packed data
phonemacro 35:67699bdae57e 399 // print as hex bytes
phonemacro 35:67699bdae57e 400 for (j=0; j<ALGO_SZ; j++)
phonemacro 35:67699bdae57e 401 pc.printf("%02X ", rsp[ptr+j]);
phonemacro 36:a6e7ff9c87a0 402 //pc.printf("\n\r" );
phonemacro 35:67699bdae57e 403 #endif
phonemacro 35:67699bdae57e 404
phonemacro 37:249b548e6488 405 #if !defined(PCK_CFG_MASK)
phonemacro 37:249b548e6488 406 #if 1
phonemacro 37:249b548e6488 407 #if 1 // print all
phonemacro 33:c8fbd904df3e 408 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 409 heading_printed = 1;
phonemacro 37:249b548e6488 410 #if defined(ALGO_ONLY)
phonemacro 33:c8fbd904df3e 411 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 412 #endif
phonemacro 33:c8fbd904df3e 413 }
phonemacro 33:c8fbd904df3e 414 pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi);
phonemacro 33:c8fbd904df3e 415 pc.printf("%d,%d,%d,%d,", ibi_conf, act, r, spo2_conf);
phonemacro 33:c8fbd904df3e 416 pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo);
phonemacro 33:c8fbd904df3e 417 pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state, scd);
phonemacro 33:c8fbd904df3e 418 pc.printf("%d,", ibi_offset);
phonemacro 33:c8fbd904df3e 419 pc.printf("%d,", inappro_ori);
phonemacro 37:249b548e6488 420 #endif
phonemacro 37:249b548e6488 421 #else // print some
phonemacro 33:c8fbd904df3e 422 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 423 heading_printed = 1;
phonemacro 37:249b548e6488 424 #if defined(ALGO_ONLY)
phonemacro 33:c8fbd904df3e 425 pc.printf("hr,hr_conf,spo2,spo2_conf,spo2_lo,spo2_unrel,scd,\n\r");
phonemacro 37:249b548e6488 426 #endif
phonemacro 33:c8fbd904df3e 427 }
phonemacro 33:c8fbd904df3e 428 pc.printf("%d,%d,", hr, hr_conf);
phonemacro 33:c8fbd904df3e 429 pc.printf("%d,%d,", spo2, spo2_conf);
phonemacro 33:c8fbd904df3e 430 pc.printf("%d,", spo2_lo);
phonemacro 33:c8fbd904df3e 431 pc.printf("%d,%d,", spo2_unrel, scd);
phonemacro 37:249b548e6488 432 #endif
phonemacro 37:249b548e6488 433 #endif // #if defined(PCK_CFG_MASK)
phonemacro 37:249b548e6488 434
phonemacro 12:17a0bf823462 435 #else // normal algo size
phonemacro 12:17a0bf823462 436 // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ);
phonemacro 12:17a0bf823462 437 opmode = rsp[ptr];
phonemacro 12:17a0bf823462 438 hr = (rsp[ptr+1] << 8) + rsp[ptr+2];
phonemacro 12:17a0bf823462 439 hr_conf = rsp[ptr+3];
phonemacro 12:17a0bf823462 440 ibi = (rsp[ptr+4] << 8) + rsp[ptr+5];
phonemacro 4:4f1e9439f048 441
phonemacro 11:a16b6bf38841 442 ibi_conf = rsp[ptr+6];
phonemacro 3:da975696b936 443 act = rsp[ptr+7];
phonemacro 3:da975696b936 444 r = (rsp[ptr+8] << 8) + rsp[ptr+9];
phonemacro 0:6f65cae31c54 445 spo2_conf = rsp[ptr+10];
phonemacro 4:4f1e9439f048 446
phonemacro 0:6f65cae31c54 447 spo2 = (rsp[ptr+11] << 8) + rsp[ptr+12];
phonemacro 4:4f1e9439f048 448 spo2_compl = rsp[ptr+13];
phonemacro 4:4f1e9439f048 449 spo2_lo = rsp[ptr+14];
phonemacro 4:4f1e9439f048 450 spo2_mo = rsp[ptr+15];
phonemacro 4:4f1e9439f048 451
phonemacro 4:4f1e9439f048 452 spo2_lopi = rsp[ptr+16];
phonemacro 4:4f1e9439f048 453 spo2_unrel = rsp[ptr+17];
phonemacro 4:4f1e9439f048 454 spo2_state = rsp[ptr+18];
phonemacro 2:563d90a111b3 455 scd = rsp[ptr+19];
phonemacro 0:6f65cae31c54 456
phonemacro 36:a6e7ff9c87a0 457 // ibi_offset = rsp[ptr+20];
phonemacro 0:6f65cae31c54 458
phonemacro 4:4f1e9439f048 459 sptr += (TTL_SZ);
phonemacro 36:a6e7ff9c87a0 460
phonemacro 27:a45d6e38f2de 461 #if 0
phonemacro 33:c8fbd904df3e 462 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 463 heading_printed = 1;
phonemacro 36:a6e7ff9c87a0 464 #if defined(ALGO_ONLY)
phonemacro 33:c8fbd904df3e 465 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 466 #endif
phonemacro 33:c8fbd904df3e 467 }
phonemacro 4:4f1e9439f048 468 pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi);
phonemacro 4:4f1e9439f048 469 pc.printf("%d,%d,%d,%d,", ibi_conf, act, r, spo2_conf);
phonemacro 4:4f1e9439f048 470 pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo);
phonemacro 4:4f1e9439f048 471 pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state, scd);
phonemacro 36:a6e7ff9c87a0 472 // pc.printf("%d,", ibi_offset);
phonemacro 4:4f1e9439f048 473 #else
phonemacro 33:c8fbd904df3e 474 if (heading_printed == 0) {
phonemacro 33:c8fbd904df3e 475 heading_printed = 1;
phonemacro 36:a6e7ff9c87a0 476 #if defined(ALGO_ONLY)
phonemacro 33:c8fbd904df3e 477 pc.printf("hr,hr_conf,spo2,spo2_conf,spo2_lo,spo2_unrel,scd,\n\r");
phonemacro 36:a6e7ff9c87a0 478 #endif
phonemacro 33:c8fbd904df3e 479 }
phonemacro 4:4f1e9439f048 480 pc.printf("%d,%d,", hr, hr_conf);
phonemacro 4:4f1e9439f048 481 pc.printf("%d,%d,", spo2, spo2_conf);
phonemacro 4:4f1e9439f048 482 pc.printf("%d,", spo2_lo);
phonemacro 4:4f1e9439f048 483 pc.printf("%d,%d,", spo2_unrel, scd);
phonemacro 4:4f1e9439f048 484 #endif
phonemacro 12:17a0bf823462 485 #endif // end normal algo size
phonemacro 14:c8cc6d7fd5f9 486 #endif // !RAW
phonemacro 4:4f1e9439f048 487
phonemacro 3:da975696b936 488 pc.printf("\n\r");
phonemacro 0:6f65cae31c54 489 }
phonemacro 0:6f65cae31c54 490 }
phonemacro 0:6f65cae31c54 491
phonemacro 6:e1b7190d6cb5 492 #ifdef MAXREFDES103_CFG
phonemacro 14:c8cc6d7fd5f9 493 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 494 // init_max20303_pmic
phonemacro 14:c8cc6d7fd5f9 495 /*****************************************************************************/
phonemacro 6:e1b7190d6cb5 496 void init_max20303_pmic(void) {
phonemacro 5:7f5a012747a5 497 /* Wait for pmic to settle down */
phonemacro 5:7f5a012747a5 498 thread_sleep_for(800);
phonemacro 5:7f5a012747a5 499
phonemacro 5:7f5a012747a5 500 //set_time(1544787300); // Set RTC time to Wed, 28 Oct 2009 11:35:37
phonemacro 6:e1b7190d6cb5 501 MAX20303 max20303(&sh_i2c);
phonemacro 5:7f5a012747a5 502 /*Set LDO1 to 1.8v*/
phonemacro 5:7f5a012747a5 503 max20303.LDO1Config();
phonemacro 5:7f5a012747a5 504
phonemacro 5:7f5a012747a5 505 /*Set LDO2 to 3v*/
phonemacro 5:7f5a012747a5 506 max20303.LDO2Config();
phonemacro 5:7f5a012747a5 507
phonemacro 5:7f5a012747a5 508 //max20303.BoostEnable();
phonemacro 5:7f5a012747a5 509 max20303.BuckBoostEnable();
phonemacro 5:7f5a012747a5 510
phonemacro 5:7f5a012747a5 511 max20303.led0on(0);
phonemacro 5:7f5a012747a5 512 max20303.led1on(0);
phonemacro 5:7f5a012747a5 513 max20303.led2on(0);
phonemacro 5:7f5a012747a5 514
phonemacro 5:7f5a012747a5 515 /* Wait for pmic to settle down */
phonemacro 5:7f5a012747a5 516 thread_sleep_for(200);
phonemacro 28:315604f4b374 517
phonemacro 5:7f5a012747a5 518 }
phonemacro 6:e1b7190d6cb5 519 #endif // MAXREFDES103_CFG
phonemacro 14:c8cc6d7fd5f9 520
phonemacro 14:c8cc6d7fd5f9 521 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 522 // init_sh_algo
phonemacro 14:c8cc6d7fd5f9 523 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 524 void init_sh_algo(void) {
phonemacro 35:67699bdae57e 525 char cmd[64];
phonemacro 0:6f65cae31c54 526 char rsp[256];
phonemacro 27:a45d6e38f2de 527
phonemacro 27:a45d6e38f2de 528 #ifdef OPTIMIZE_FIFO_READ
phonemacro 27:a45d6e38f2de 529 check_fifo_countdown = MAX_FIFO_CNT;
phonemacro 27:a45d6e38f2de 530 #endif
phonemacro 27:a45d6e38f2de 531
phonemacro 10:192ea88e964b 532 // switch to application mode
phonemacro 0:6f65cae31c54 533 rst = 0;
phonemacro 0:6f65cae31c54 534 mfio = 1;
phonemacro 0:6f65cae31c54 535 thread_sleep_for(10);
phonemacro 0:6f65cae31c54 536 rst = 1;
phonemacro 0:6f65cae31c54 537 thread_sleep_for(1500);
phonemacro 10:192ea88e964b 538 #ifdef MAXREFDES103_CFG
phonemacro 10:192ea88e964b 539 init_max20303_pmic();
phonemacro 10:192ea88e964b 540 #endif
phonemacro 23:e7ecf1416965 541 #if 0 // 1.5s is ok for 33.13.12
phonemacro 23:e7ecf1416965 542 thread_sleep_for(250);
phonemacro 20:7fc26287beb7 543 #endif
phonemacro 0:6f65cae31c54 544
phonemacro 1:da792e46a385 545 mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 546 #if 0
phonemacro 35:67699bdae57e 547 //write SpO2 coefficients 0x00000000 FFD7FBDD 00AB61FE
phonemacro 35:67699bdae57e 548 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x00;
phonemacro 35:67699bdae57e 549 cmd[3] = 0x00; cmd[4] = 0x00; cmd[5] = 0x00; cmd[6] = 0x00;
phonemacro 35:67699bdae57e 550 cmd[7] = 0xFF; cmd[8] = 0xD7; cmd[9] = 0xFB; cmd[10] = 0xDD;
phonemacro 35:67699bdae57e 551 cmd[11] = 0x00; cmd[12] = 0xAB; cmd[13] = 0x61; cmd[14] = 0xFE;
phonemacro 35:67699bdae57e 552 sh_i2c.write(SH_ADDR, cmd, 15);
phonemacro 1:da792e46a385 553 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 554 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 35:67699bdae57e 555 mfio = 1; mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 556 pc.printf("Wr Spo2 Coeff %x\n\r", rsp[0]);
phonemacro 35:67699bdae57e 557 #endif
phonemacro 35:67699bdae57e 558 //1.1 rd SpO2 Coefficients
phonemacro 35:67699bdae57e 559 cmd[0] = 0x51; cmd[1] = 0x07; cmd[2] = 0x00;
phonemacro 35:67699bdae57e 560 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 6:e1b7190d6cb5 561 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 562 sh_i2c.read(SH_ADDR, rsp, 13);
phonemacro 35:67699bdae57e 563 mfio = 1; mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 564 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 42:6f980909371f 565 #ifdef REDUCE_RPT_PERIOD
phonemacro 42:6f980909371f 566 //Change report period to 25
phonemacro 42:6f980909371f 567 cmd[0] = 0x10; cmd[1] = 0x02; cmd[2] = REDUCE_RPT_PERIOD;
phonemacro 42:6f980909371f 568 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 42:6f980909371f 569 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 42:6f980909371f 570 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 42:6f980909371f 571 mfio = 1; mfio = 0; wait_us(300);
phonemacro 42:6f980909371f 572 pc.printf("Wr report period 25 %x\n\r", rsp[0]);
phonemacro 42:6f980909371f 573 #endif
phonemacro 35:67699bdae57e 574 //1.9 rd ver
phonemacro 4:4f1e9439f048 575 cmd[0] = 0xFF; cmd[1] = 0x03;
phonemacro 6:e1b7190d6cb5 576 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 1:da792e46a385 577 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 578 sh_i2c.read(SH_ADDR, rsp, 4);
phonemacro 1:da792e46a385 579 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 580 pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]);
phonemacro 0:6f65cae31c54 581
phonemacro 35:67699bdae57e 582 // wr config mask for packed normal data output fifo
phonemacro 37:249b548e6488 583 #if defined(PCK_CFG_MASK)
phonemacro 37:249b548e6488 584 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x20; cmd[3] = 0x7F; cmd[4] = 0xFF; cmd[5] = 0x00;
phonemacro 44:1b165a68474d 585 // cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x20; cmd[3] = 0xFF; cmd[4] = 0xFF; cmd[5] = 0x00;
phonemacro 35:67699bdae57e 586 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 35:67699bdae57e 587 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 588 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 35:67699bdae57e 589 mfio = 1; mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 590 pc.printf("wr config mask packed: %x \n\r", rsp[0]);
phonemacro 35:67699bdae57e 591 // rd config mask for packed normal data output fifo
phonemacro 35:67699bdae57e 592 cmd[0] = 0x51; cmd[1] = 0x07; cmd[2] = 0x20;
phonemacro 35:67699bdae57e 593 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 35:67699bdae57e 594 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 595 sh_i2c.read(SH_ADDR, rsp, 4);
phonemacro 35:67699bdae57e 596 mfio = 1; mfio = 0; wait_us(300);
phonemacro 35:67699bdae57e 597 pc.printf("rd config mask for packed normal data output fifo %d %X %X %X \n\r", rsp[0], rsp[1], rsp[2], rsp[3]);
phonemacro 44:1b165a68474d 598 #endif
phonemacro 35:67699bdae57e 599
phonemacro 33:c8fbd904df3e 600 #if defined(MAXM86161_CFG) || defined(MAXM86146_CFG)
phonemacro 33:c8fbd904df3e 601 // rd algo sz normal
phonemacro 17:0d6e99a0fd8d 602 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x01;
phonemacro 17:0d6e99a0fd8d 603 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 17:0d6e99a0fd8d 604 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 605 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 17:0d6e99a0fd8d 606 mfio = 1; mfio = 0; wait_us(300);
phonemacro 33:c8fbd904df3e 607 pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 33:c8fbd904df3e 608 // rd algo sz extended
phonemacro 17:0d6e99a0fd8d 609 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x02;
phonemacro 17:0d6e99a0fd8d 610 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 17:0d6e99a0fd8d 611 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 612 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 17:0d6e99a0fd8d 613 mfio = 1; mfio = 0; wait_us(300);
phonemacro 33:c8fbd904df3e 614 pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 33:c8fbd904df3e 615 // rd algo sz scd
phonemacro 17:0d6e99a0fd8d 616 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x03;
phonemacro 17:0d6e99a0fd8d 617 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 17:0d6e99a0fd8d 618 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 619 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 17:0d6e99a0fd8d 620 mfio = 1; mfio = 0; wait_us(300);
phonemacro 33:c8fbd904df3e 621 pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 36:a6e7ff9c87a0 622 #if defined(MAXM86161_CFG) || defined(MAXM86146_CFG)
phonemacro 35:67699bdae57e 623 // rd algo sz packed normal
phonemacro 33:c8fbd904df3e 624 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x04;
phonemacro 33:c8fbd904df3e 625 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 33:c8fbd904df3e 626 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 33:c8fbd904df3e 627 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 33:c8fbd904df3e 628 mfio = 1; mfio = 0; wait_us(300);
phonemacro 33:c8fbd904df3e 629 pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 33:c8fbd904df3e 630 #endif
phonemacro 17:0d6e99a0fd8d 631 #endif
phonemacro 17:0d6e99a0fd8d 632
phonemacro 17:0d6e99a0fd8d 633 #if 0
phonemacro 17:0d6e99a0fd8d 634 // set Perfusion Index threshold to .05 (3x.13.19+)
phonemacro 17:0d6e99a0fd8d 635 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x1D; cmd[3] = 50;
phonemacro 16:ff1122f0624a 636 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 16:ff1122f0624a 637 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 16:ff1122f0624a 638 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 16:ff1122f0624a 639 mfio = 1; mfio = 0; wait_us(300);
phonemacro 16:ff1122f0624a 640 pc.printf("pi set to 0x19 : %x \n\r", rsp[0]);
phonemacro 17:0d6e99a0fd8d 641 #endif
phonemacro 16:ff1122f0624a 642
phonemacro 32:92adfbe18ab6 643 // 1.2 sensor and algo data
phonemacro 4:4f1e9439f048 644 cmd[0] = 0x10; cmd[1] = 0x00;
phonemacro 2:563d90a111b3 645 #ifdef ALGO_ONLY
phonemacro 0:6f65cae31c54 646 cmd[2] = 0x02; // algo data
phonemacro 4:4f1e9439f048 647 pc.printf("algo only \n\r");
phonemacro 2:563d90a111b3 648 #else
phonemacro 2:563d90a111b3 649 cmd[2] = 0x03; // sensor + algo data
phonemacro 4:4f1e9439f048 650 pc.printf("sens+algo \n\r");
phonemacro 2:563d90a111b3 651 #endif
phonemacro 6:e1b7190d6cb5 652 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 1:da792e46a385 653 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 654 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 655 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 656 pc.printf("1.2 Status: %x\n\r", rsp[0]);
phonemacro 32:92adfbe18ab6 657 // 1.5 cont hr, spo2
phonemacro 32:92adfbe18ab6 658 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0A; cmd[3] = 0x00;
phonemacro 32:92adfbe18ab6 659 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 32:92adfbe18ab6 660 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 661 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 32:92adfbe18ab6 662 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 663 pc.printf("1.5 Status: %x\n\r", rsp[0]);
phonemacro 32:92adfbe18ab6 664 // 1.6 AEC enable (default)
phonemacro 4:4f1e9439f048 665 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0B; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 666 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 1:da792e46a385 667 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 668 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 669 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 670 pc.printf("1.6 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 671 #if AGC
phonemacro 32:92adfbe18ab6 672 // AGC1.7 Disable auto PD (default
phonemacro 13:1baccc6275a7 673 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x12; cmd[3] = 0x00;
phonemacro 13:1baccc6275a7 674 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 13:1baccc6275a7 675 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 676 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 13:1baccc6275a7 677 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 678 pc.printf("AGC1.7 Status: %x\n\r", rsp[0]);
phonemacro 32:92adfbe18ab6 679 // AGC1.8 Disable SCD (default)
phonemacro 13:1baccc6275a7 680 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0C; cmd[3] = 0x00;
phonemacro 13:1baccc6275a7 681 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 13:1baccc6275a7 682 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 683 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 13:1baccc6275a7 684 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 685 pc.printf("AGC1.8 Status: %x\n\r", rsp[0]);
phonemacro 32:92adfbe18ab6 686 // AGC1.9 Set AGC target PD TO 10uA
phonemacro 13:1baccc6275a7 687 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x11; cmd[3] = 0x00; cmd[3] = 0x64;
phonemacro 13:1baccc6275a7 688 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 13:1baccc6275a7 689 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 690 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 13:1baccc6275a7 691 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 692 pc.printf("AGC1.9 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 693 #else
phonemacro 32:92adfbe18ab6 694 // 1.7 auto PD (default
phonemacro 4:4f1e9439f048 695 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x12; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 696 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 1:da792e46a385 697 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 698 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 699 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 700 pc.printf("1.7 Status: %x\n\r", rsp[0]);
phonemacro 32:92adfbe18ab6 701 // 1.8 SCD (default)
phonemacro 4:4f1e9439f048 702 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0C; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 703 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 4:4f1e9439f048 704 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 705 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 4:4f1e9439f048 706 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 707 pc.printf("1.8 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 708 #endif
phonemacro 28:315604f4b374 709
phonemacro 28:315604f4b374 710 #if defined(MAXM86161_CFG) //only use Red and IR
phonemacro 32:92adfbe18ab6 711 //1.20 map leds to slots
phonemacro 28:315604f4b374 712 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x23; cmd[4] = 0x00; cmd[5] = 0x00;
phonemacro 28:315604f4b374 713 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 28:315604f4b374 714 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 715 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 716 mfio = 1; mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 717 pc.printf("map leds to slots %x\n\r", rsp[0]);
phonemacro 30:77a30ea425da 718 //1.21 map HR inputs to slots, default is 0x0073 for MAXM86161
phonemacro 30:77a30ea425da 719 #if 0 // NA for MAXM86161
phonemacro 28:315604f4b374 720 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x73;
phonemacro 28:315604f4b374 721 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 28:315604f4b374 722 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 723 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 724 mfio = 1; mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 725 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 30:77a30ea425da 726 #endif
phonemacro 28:315604f4b374 727 //1.22 map SpO2 inputs to slots
phonemacro 28:315604f4b374 728 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x00; cmd[4] = 0x10;
phonemacro 28:315604f4b374 729 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 28:315604f4b374 730 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 731 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 732 mfio = 1; mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 733 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 28:315604f4b374 734 #endif
phonemacro 28:315604f4b374 735
phonemacro 3:da975696b936 736 #ifdef MAXM86146_CFG
phonemacro 32:92adfbe18ab6 737 //1.20 map leds to slots for MAXM86146
phonemacro 4:4f1e9439f048 738 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x13; cmd[4] = 0x56; cmd[5] = 0x00;
phonemacro 6:e1b7190d6cb5 739 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 3:da975696b936 740 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 741 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 742 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 743 pc.printf("map leds to slots %x\n\r", rsp[0]);
phonemacro 3:da975696b936 744 //1.21 map HR inputs to slots
phonemacro 4:4f1e9439f048 745 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x11;
phonemacro 6:e1b7190d6cb5 746 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 3:da975696b936 747 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 748 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 749 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 750 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 3:da975696b936 751 //1.22 map SpO2 inputs to slots
phonemacro 4:4f1e9439f048 752 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x30; cmd[4] = 0x20;
phonemacro 6:e1b7190d6cb5 753 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 3:da975696b936 754 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 755 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 756 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 757 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 26:33c0d3fd2a95 758
phonemacro 3:da975696b936 759 #if 0
phonemacro 2:563d90a111b3 760 //1.20 Sec 4.1 map leds to slots for MAXM86146
phonemacro 4:4f1e9439f048 761 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x15; cmd[4] = 0x60; cmd[5] = 0x00;
phonemacro 6:e1b7190d6cb5 762 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 1:da792e46a385 763 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 764 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 765 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 766 pc.printf("map leds to slots%x\n\r", rsp[0]);
phonemacro 2:563d90a111b3 767 //1.21 map HR inputs to slots
phonemacro 4:4f1e9439f048 768 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x01;
phonemacro 6:e1b7190d6cb5 769 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 1:da792e46a385 770 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 771 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 772 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 773 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 2:563d90a111b3 774 //1.22 map SpO2 inputs to slots
phonemacro 4:4f1e9439f048 775 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x20; cmd[4] = 0x10;
phonemacro 6:e1b7190d6cb5 776 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 1:da792e46a385 777 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 778 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 779 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 780 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 3:da975696b936 781 #endif
phonemacro 3:da975696b936 782 #endif // MAXM86146_CFG
phonemacro 0:6f65cae31c54 783
phonemacro 28:315604f4b374 784 #if 0 // MAXM86161 test new commands
phonemacro 28:315604f4b374 785 // LDO enable
phonemacro 28:315604f4b374 786 cmd[0] = 0x10; cmd[1] = 0x12; cmd[2] = 0x01;
phonemacro 28:315604f4b374 787 //cmd[0] = 0x10; cmd[1] = 0x12; cmd[2] = 0x00;
phonemacro 28:315604f4b374 788 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 28:315604f4b374 789 thread_sleep_for(2);
phonemacro 28:315604f4b374 790 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 791 pc.printf("\n\r ldo en %x\n\r", rsp[0]);
phonemacro 28:315604f4b374 792 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 793 // GPIO enable
phonemacro 28:315604f4b374 794 cmd[0] = 0x10; cmd[1] = 0x13; cmd[2] = 0x01;
phonemacro 28:315604f4b374 795 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 28:315604f4b374 796 thread_sleep_for(2);
phonemacro 28:315604f4b374 797 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 798 pc.printf("\n\r gpio en %x\n\r", rsp[0]);
phonemacro 28:315604f4b374 799 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 800 #endif
phonemacro 28:315604f4b374 801
phonemacro 32:92adfbe18ab6 802 // 1.30 Enable HR, SpO2 algo
phonemacro 12:17a0bf823462 803 #ifdef EXTENDED_ALGO
phonemacro 12:17a0bf823462 804 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x02;
phonemacro 33:c8fbd904df3e 805 #elif defined(PACKED_NORMAL_ALGO)
phonemacro 33:c8fbd904df3e 806 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x04;
phonemacro 12:17a0bf823462 807 #else
phonemacro 4:4f1e9439f048 808 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x01;
phonemacro 12:17a0bf823462 809 #endif
phonemacro 6:e1b7190d6cb5 810 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 28:315604f4b374 811 mfio = 1;
phonemacro 0:6f65cae31c54 812 thread_sleep_for(465);
phonemacro 28:315604f4b374 813 mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 814 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 815 pc.printf("1.14 status: %x\n\r", rsp[0]);
phonemacro 0:6f65cae31c54 816
phonemacro 4:4f1e9439f048 817 #if 1
phonemacro 4:4f1e9439f048 818 //1.31 rd AFE part id
phonemacro 4:4f1e9439f048 819 cmd[0] = 0x41; cmd[1] = 0x00; cmd[2] = 0xFF;
phonemacro 6:e1b7190d6cb5 820 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 4:4f1e9439f048 821 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 822 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 4:4f1e9439f048 823 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 824 pc.printf("1.31 part id afe %x %x\n\r", rsp[0], rsp[1]);
phonemacro 4:4f1e9439f048 825 //1.32 rd accel who
phonemacro 4:4f1e9439f048 826 cmd[0] = 0x41; cmd[1] = 0x04; cmd[2] = 0x0F;
phonemacro 6:e1b7190d6cb5 827 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 4:4f1e9439f048 828 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 829 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 4:4f1e9439f048 830 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 831 pc.printf("1.32 who accel %x %x\n\r", rsp[0], rsp[1]);
phonemacro 28:315604f4b374 832 #endif
phonemacro 26:33c0d3fd2a95 833 mfio = 1;
phonemacro 10:192ea88e964b 834 }
phonemacro 10:192ea88e964b 835
phonemacro 14:c8cc6d7fd5f9 836 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 837 // init_sh_raw
phonemacro 14:c8cc6d7fd5f9 838 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 839 void init_sh_raw(void) {
phonemacro 29:a7dd81450b35 840 char cmd[16];
phonemacro 14:c8cc6d7fd5f9 841 char rsp[256];
phonemacro 14:c8cc6d7fd5f9 842 // switch to application mode
phonemacro 14:c8cc6d7fd5f9 843 rst = 0;
phonemacro 14:c8cc6d7fd5f9 844 mfio = 1;
phonemacro 14:c8cc6d7fd5f9 845 thread_sleep_for(10);
phonemacro 14:c8cc6d7fd5f9 846 rst = 1;
phonemacro 14:c8cc6d7fd5f9 847 thread_sleep_for(1500);
phonemacro 14:c8cc6d7fd5f9 848 #ifdef MAXREFDES103_CFG
phonemacro 14:c8cc6d7fd5f9 849 init_max20303_pmic();
phonemacro 14:c8cc6d7fd5f9 850 #endif
phonemacro 14:c8cc6d7fd5f9 851
phonemacro 14:c8cc6d7fd5f9 852 mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 853
phonemacro 32:92adfbe18ab6 854 //1.0 read operating mode
phonemacro 14:c8cc6d7fd5f9 855 cmd[0] = 0x02; cmd[1] = 0x00;
phonemacro 14:c8cc6d7fd5f9 856 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 14:c8cc6d7fd5f9 857 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 858 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 14:c8cc6d7fd5f9 859 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 860 pc.printf("\n\r 0x02 0x00 Status, Read Operating Mode: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 32:92adfbe18ab6 861 //1.1 rd ver
phonemacro 14:c8cc6d7fd5f9 862 cmd[0] = 0xFF; cmd[1] = 0x03;
phonemacro 14:c8cc6d7fd5f9 863 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 14:c8cc6d7fd5f9 864 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 865 sh_i2c.read(SH_ADDR, rsp, 4);
phonemacro 14:c8cc6d7fd5f9 866 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 867 pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]);
phonemacro 14:c8cc6d7fd5f9 868
phonemacro 32:92adfbe18ab6 869 // raw1.2 sensor data
phonemacro 14:c8cc6d7fd5f9 870 cmd[0] = 0x10; cmd[1] = 0x00; cmd[2] = 0x01;
phonemacro 14:c8cc6d7fd5f9 871 pc.printf("raw sensor data only \n\r");
phonemacro 14:c8cc6d7fd5f9 872 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 14:c8cc6d7fd5f9 873 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 874 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 875 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 876 pc.printf("raw1.2 Status: %x\n\r", rsp[0]);
phonemacro 32:92adfbe18ab6 877 // raw1.3 interrupt threshold
phonemacro 14:c8cc6d7fd5f9 878 cmd[0] = 0x10; cmd[1] = 0x01; cmd[2] = 0x01;
phonemacro 14:c8cc6d7fd5f9 879 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 14:c8cc6d7fd5f9 880 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 881 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 882 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 883 pc.printf("raw1.3 Status: %x\n\r", rsp[0]);
phonemacro 32:92adfbe18ab6 884 // raw1.4 enable sh accel
phonemacro 14:c8cc6d7fd5f9 885 cmd[0] = 0x44; cmd[1] = 0x04; cmd[2] = 0x01; cmd[3] = 0x00;
phonemacro 14:c8cc6d7fd5f9 886 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 29:a7dd81450b35 887 mfio = 1; thread_sleep_for(20); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 888 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 29:a7dd81450b35 889 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 890 pc.printf("raw1.4 Status: %x\n\r", rsp[0]);
phonemacro 32:92adfbe18ab6 891 // raw1.6 enable AFE
phonemacro 30:77a30ea425da 892 // cmd[0] = 0x44; cmd[1] = 0x00; cmd[2] = 0x01; cmd[3] = 0x00;
phonemacro 30:77a30ea425da 893 // sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 38:8ff33869be1f 894 cmd[0] = 0x44; cmd[1] = 0x00; cmd[2] = 0x01; // 3 bytes // tested on 33.13.31/12
phonemacro 38:8ff33869be1f 895 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 38:8ff33869be1f 896 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 897 sh_i2c.write(SH_ADDR, cmd, 9);
phonemacro 38:8ff33869be1f 898 mfio = 1; thread_sleep_for(465); mfio = 0; wait_us(300);
phonemacro 29:a7dd81450b35 899 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 900 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 901 pc.printf("raw1.6 Status: %x\n\r", rsp[0]);
phonemacro 32:92adfbe18ab6 902
phonemacro 32:92adfbe18ab6 903 // raw1.7 rd accel WHO reg
phonemacro 30:77a30ea425da 904 cmd[0] = 0x41; cmd[1] = 0x04; cmd[2] = 0x0F;
phonemacro 30:77a30ea425da 905 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 30:77a30ea425da 906 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 30:77a30ea425da 907 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 30:77a30ea425da 908 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 909 pc.printf("1.7 Who Status: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 32:92adfbe18ab6 910 // rd1.6 AFE part id
phonemacro 30:77a30ea425da 911 cmd[0] = 0x41; cmd[1] = 0x00; cmd[2] = 0xFF;
phonemacro 30:77a30ea425da 912 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 30:77a30ea425da 913 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 30:77a30ea425da 914 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 30:77a30ea425da 915 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 916 pc.printf("raw1.6 part id Status: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 32:92adfbe18ab6 917
phonemacro 32:92adfbe18ab6 918 // raw1.8 sample rate 100 Hz, ave 1
phonemacro 39:2f2788876776 919 // cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x00; // set AFE reg 0x12 to 25 Hz
phonemacro 14:c8cc6d7fd5f9 920 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x18; // set AFE reg 0x12 to 100 Hz
phonemacro 14:c8cc6d7fd5f9 921 // cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x20; // set AFE reg 0x12 to 200 Hz
phonemacro 14:c8cc6d7fd5f9 922 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 923 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 924 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 925 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 926 pc.printf("raw1.8 Status: %x\n\r", rsp[0]);
phonemacro 32:92adfbe18ab6 927 // raw1.9 LED1 current
phonemacro 29:a7dd81450b35 928 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x23; cmd[3] = 0x3F;
phonemacro 14:c8cc6d7fd5f9 929 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 930 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 931 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 932 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 933 pc.printf("raw1.9 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 934 #ifndef MAXM86146_CFG
phonemacro 32:92adfbe18ab6 935 // raw1.10 LED2 current
phonemacro 38:8ff33869be1f 936 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x24; cmd[3] = 0x3F;
phonemacro 14:c8cc6d7fd5f9 937 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 938 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 939 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 940 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 941 pc.printf("raw1.10 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 942 #endif
phonemacro 32:92adfbe18ab6 943 // raw1.11 LED3 current
phonemacro 38:8ff33869be1f 944 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x25; cmd[3] = 0x3F;
phonemacro 14:c8cc6d7fd5f9 945 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 946 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 947 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 948 mfio = 1; mfio = 0; wait_us(300);
phonemacro 32:92adfbe18ab6 949 pc.printf("raw1.11 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 950 #ifdef MAXM86146_CFG
phonemacro 14:c8cc6d7fd5f9 951 // LED5 current
phonemacro 14:c8cc6d7fd5f9 952 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x27; cmd[3] = 0x7F;
phonemacro 14:c8cc6d7fd5f9 953 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 954 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 955 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 956 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 957 pc.printf("led5 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 958 // LED6 current
phonemacro 14:c8cc6d7fd5f9 959 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x27; cmd[3] = 0x7F;
phonemacro 14:c8cc6d7fd5f9 960 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 961 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 962 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 963 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 964 pc.printf("led6 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 965
phonemacro 14:c8cc6d7fd5f9 966 // Set Seq cntrl1 LED2, LED1
phonemacro 14:c8cc6d7fd5f9 967 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x20; cmd[3] = 0x21;
phonemacro 14:c8cc6d7fd5f9 968 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 969 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 970 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 971 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 972 pc.printf("Seq cntrl1 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 973 // Set Seq cntrl2 LED4, LED3
phonemacro 14:c8cc6d7fd5f9 974 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x21; cmd[3] = 0xA3;
phonemacro 14:c8cc6d7fd5f9 975 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 976 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 977 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 978 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 979 pc.printf("Seq cntrl2 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 980 // Set Seq cntrl3 LED6, LED5
phonemacro 14:c8cc6d7fd5f9 981 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x22; cmd[3] = 0x21;
phonemacro 14:c8cc6d7fd5f9 982 // cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x22; cmd[3] = 0x99; // Ambient
phonemacro 14:c8cc6d7fd5f9 983 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 984 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 985 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 986 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 987 pc.printf("Seq cntrl3 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 988
phonemacro 14:c8cc6d7fd5f9 989 #endif
phonemacro 28:315604f4b374 990 mfio = 1;
phonemacro 28:315604f4b374 991 }
phonemacro 14:c8cc6d7fd5f9 992
phonemacro 14:c8cc6d7fd5f9 993 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 994 // main
phonemacro 14:c8cc6d7fd5f9 995 /*****************************************************************************/
phonemacro 10:192ea88e964b 996 int main()
phonemacro 10:192ea88e964b 997 {
phonemacro 10:192ea88e964b 998 sh_i2c.frequency(400000);
phonemacro 10:192ea88e964b 999 int32_t ledcnt = 0;
phonemacro 10:192ea88e964b 1000 rLED = LED_OFF; gLED = LED_ON; bLED = LED_OFF;
phonemacro 10:192ea88e964b 1001 Ticker ticker; // calls a callback repeatedly with a timeout
phonemacro 28:315604f4b374 1002
phonemacro 28:315604f4b374 1003 #if 0 // test disable algo
phonemacro 28:315604f4b374 1004 char cmd[8];
phonemacro 28:315604f4b374 1005 char rsp[256];
phonemacro 28:315604f4b374 1006 // 3.1 Disable algo
phonemacro 28:315604f4b374 1007 mfio = 1; mfio = 0; wait_us(300);
phonemacro 28:315604f4b374 1008 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x00;
phonemacro 28:315604f4b374 1009 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 28:315604f4b374 1010 thread_sleep_for(465);
phonemacro 28:315604f4b374 1011 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 28:315604f4b374 1012 pc.printf("3.1 disable algo: %x\n\r", rsp[0]);
phonemacro 28:315604f4b374 1013 mfio = 1;
phonemacro 28:315604f4b374 1014 #endif
phonemacro 28:315604f4b374 1015
phonemacro 10:192ea88e964b 1016 //ticker.attach(callback(&blink_timer), BLINKING_RATE_MS); /* set timer for one second */
phonemacro 14:c8cc6d7fd5f9 1017 #ifdef RAW
phonemacro 14:c8cc6d7fd5f9 1018 init_sh_raw();
phonemacro 14:c8cc6d7fd5f9 1019 #else
phonemacro 14:c8cc6d7fd5f9 1020 init_sh_algo();
phonemacro 14:c8cc6d7fd5f9 1021 #endif
phonemacro 28:315604f4b374 1022 mfio = 1;
phonemacro 33:c8fbd904df3e 1023 heading_printed = 0;
phonemacro 8:e6ae69cfecbf 1024 #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG) || defined(MAXM86146_CFG)
phonemacro 6:e1b7190d6cb5 1025 Timer tmr1;
phonemacro 0:6f65cae31c54 1026 while (1) {
phonemacro 6:e1b7190d6cb5 1027 tmr1.start();
phonemacro 29:a7dd81450b35 1028 #if defined(RAW)
phonemacro 29:a7dd81450b35 1029 if (tmr1.read_ms() >= 10) {
phonemacro 29:a7dd81450b35 1030 #else
phonemacro 42:6f980909371f 1031 #ifdef REDUCE_RPT_PERIOD
phonemacro 42:6f980909371f 1032 #ifdef USE_FIFO_BUFFER_CNT
phonemacro 42:6f980909371f 1033 if (tmr1.read_ms() >= 40*REDUCE_RPT_PERIOD*USE_FIFO_BUFFER_CNT) {
phonemacro 42:6f980909371f 1034 #else
phonemacro 42:6f980909371f 1035 if (tmr1.read_ms() >= 40*REDUCE_RPT_PERIOD) {
phonemacro 42:6f980909371f 1036 #endif
phonemacro 42:6f980909371f 1037 #else
phonemacro 42:6f980909371f 1038 #ifdef USE_FIFO_BUFFER_CNT
phonemacro 42:6f980909371f 1039 if (tmr1.read_ms() >= 40*USE_FIFO_BUFFER_CNT) {
phonemacro 42:6f980909371f 1040 #else
phonemacro 28:315604f4b374 1041 if (tmr1.read_ms() >= 40) {
phonemacro 42:6f980909371f 1042 #endif
phonemacro 42:6f980909371f 1043 #endif
phonemacro 29:a7dd81450b35 1044 #endif
phonemacro 7:23b067817ab8 1045 tmr1.reset();
phonemacro 10:192ea88e964b 1046 read_sh_fifo();
phonemacro 7:23b067817ab8 1047 if ((ledcnt++ % 50) == 0)
phonemacro 6:e1b7190d6cb5 1048 gLED = !gLED;
phonemacro 0:6f65cae31c54 1049 }
phonemacro 0:6f65cae31c54 1050 }
phonemacro 6:e1b7190d6cb5 1051 #else
phonemacro 6:e1b7190d6cb5 1052 ticker.attach(callback(&fifo_timer), 0.040f);
phonemacro 6:e1b7190d6cb5 1053 while (1) {
phonemacro 6:e1b7190d6cb5 1054 if (Time_to_Read_PPG) {
phonemacro 10:192ea88e964b 1055 read_sh_fifo();
phonemacro 7:23b067817ab8 1056 if ((ledcnt++ % 50) == 0)
phonemacro 6:e1b7190d6cb5 1057 gLED = !gLED;
phonemacro 6:e1b7190d6cb5 1058 }
phonemacro 6:e1b7190d6cb5 1059 }
phonemacro 6:e1b7190d6cb5 1060 #endif
phonemacro 0:6f65cae31c54 1061 }