Mode1 Optical Validation

Dependencies:   max32630fthr

Committer:
phonemacro
Date:
Tue Mar 15 21:01:25 2022 +0000
Revision:
33:c8fbd904df3e
Parent:
32:92adfbe18ab6
Child:
34:53043966c276
Add Packed Normal Algorithm Samples Format.; Add headings to prints.

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