Mode1 Optical Validation

Dependencies:   max32630fthr

Committer:
phonemacro
Date:
Wed Jun 23 22:05:36 2021 +0000
Revision:
27:a45d6e38f2de
Parent:
26:33c0d3fd2a95
Child:
28:315604f4b374
Add the code to allow optimizing the FIFO read.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phonemacro 0:6f65cae31c54 1 /*******************************************************************************
phonemacro 9:12720bbacfe2 2 * Copyright (C) 2021 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 24:064478ff33d2 40 * ver: 210622
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 21:67d58af1ec56 54 #define MAXM86146_CFG 1 // tested on MAXM86146EVSYS_sensorBrd+MAXM86161_ADAPTER_REVB+MAX32630FTHR 33.13.12
phonemacro 21:67d58af1ec56 55 //#define MAXREFDES103_CFG // not tested
phonemacro 21:67d58af1ec56 56 //#define MAXM86161_CFG 1 // tested on MAXM86161+MAX32630FTHR v32.9.22, 32.13.12
phonemacro 6:e1b7190d6cb5 57 /*****************************************************************************/
phonemacro 24:064478ff33d2 58
phonemacro 24:064478ff33d2 59 /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/
phonemacro 24:064478ff33d2 60 // define which adaptor board is being used
phonemacro 26:33c0d3fd2a95 61 #define MAXM86161_ADPTR_EVKIT_B
phonemacro 26:33c0d3fd2a95 62 //#define MAXREFDES1319 // MAXM86161: Remove J7; For PIN1=ACC_INTN, J9 set to 2-3; For PIN13=OPT_INTN, J10 set to 2-3
phonemacro 24:064478ff33d2 63 /******************************************************************************
phonemacro 24:064478ff33d2 64 * MAX32630FTHR GPIOs
phonemacro 24:064478ff33d2 65 ******************************************************************************/
phonemacro 24:064478ff33d2 66 #ifdef MAXM86161_ADPTR_EVKIT_B
phonemacro 24:064478ff33d2 67 #define RST_PIN P5_6
phonemacro 24:064478ff33d2 68 #define MFIO_PIN P5_4
phonemacro 24:064478ff33d2 69 #else
phonemacro 24:064478ff33d2 70 #ifdef MAXREFDES1319
phonemacro 24:064478ff33d2 71 #define RST_PIN P3_0
phonemacro 24:064478ff33d2 72 #define MFIO_PIN P5_2
phonemacro 24:064478ff33d2 73 #endif
phonemacro 24:064478ff33d2 74 #endif
phonemacro 24:064478ff33d2 75
phonemacro 24:064478ff33d2 76 DigitalOut rst(RST_PIN, PullUp);
phonemacro 24:064478ff33d2 77 DigitalOut mfio(MFIO_PIN, PullUp);
phonemacro 24:064478ff33d2 78 I2C sh_i2c(P3_4, P3_5);
phonemacro 24:064478ff33d2 79
phonemacro 24:064478ff33d2 80 /*****************************************************************************/
phonemacro 26:33c0d3fd2a95 81 #if defined(MAXM86161_CFG) //|| defined(MAXM86146_CFG) // don't need 3.3V for MAXM86146EVSYS_sensorBrd+MAXM86161_ADAPTER_REVB+MAX32630FTHR
phonemacro 17:0d6e99a0fd8d 82 #include "max32630fthr.h"
phonemacro 17:0d6e99a0fd8d 83 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); // Enable J1-pin2, 3.3V and set GPIO to 3.3v
phonemacro 21:67d58af1ec56 84 #endif
phonemacro 26:33c0d3fd2a95 85
phonemacro 26:33c0d3fd2a95 86 /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/
phonemacro 14:c8cc6d7fd5f9 87 //#define RAW // define this if you only AFE+accel data, no algo
phonemacro 14:c8cc6d7fd5f9 88 #define ALGO_ONLY 1 // define this if you only want algo data, comment out if you want raw sensor+algo data
phonemacro 12:17a0bf823462 89 //#define EXTENDED_ALGO 1 // define this if you want the extended algo format
phonemacro 13:1baccc6275a7 90 //#define AGC 1 // define this for AGC, otherwise the default is AEC
phonemacro 6:e1b7190d6cb5 91
phonemacro 6:e1b7190d6cb5 92 #ifdef MAXREFDES103_CFG
phonemacro 5:7f5a012747a5 93 #include "MAX20303.h"
phonemacro 6:e1b7190d6cb5 94 I2C sh_i2c_pmic(P5_7, P6_0);
phonemacro 5:7f5a012747a5 95 #endif
phonemacro 5:7f5a012747a5 96
phonemacro 2:563d90a111b3 97 #ifdef MAXM86146_CFG
phonemacro 0:6f65cae31c54 98 #define PPG_SZ 36 //maxm86146
phonemacro 0:6f65cae31c54 99 #else
phonemacro 0:6f65cae31c54 100 #define PPG_SZ 18 //maxm86161, max86141
phonemacro 0:6f65cae31c54 101 #endif
phonemacro 0:6f65cae31c54 102 #define ACCEL_SZ 6 // accel
phonemacro 0:6f65cae31c54 103 #define SENSOR_SZ (PPG_SZ+ACCEL_SZ)
phonemacro 18:f4c95b1c0efc 104
phonemacro 21:67d58af1ec56 105 //#define old_msbl 1 // 3x.12.0 or earlier
phonemacro 18:f4c95b1c0efc 106 #ifdef old_msbl
phonemacro 18:f4c95b1c0efc 107 #ifdef EXTENDED_ALGO
phonemacro 18:f4c95b1c0efc 108 #define ALGO_SZ 52 // 52 bytes is the extended algo size for 3x.12.0
phonemacro 18:f4c95b1c0efc 109 #else
phonemacro 18:f4c95b1c0efc 110 #define ALGO_SZ 20 // 20 bytes is the algo normal size for 3x.12.0
phonemacro 18:f4c95b1c0efc 111 #endif
phonemacro 12:17a0bf823462 112 #else
phonemacro 18:f4c95b1c0efc 113 #ifdef EXTENDED_ALGO
phonemacro 21:67d58af1ec56 114 #define ALGO_SZ 56 // 56 bytes is the extended algo size for 3x.13.x+
phonemacro 18:f4c95b1c0efc 115 #else
phonemacro 21:67d58af1ec56 116 #define ALGO_SZ 24 // 24 bytes is the algo normal size for 3x.13.x+
phonemacro 18:f4c95b1c0efc 117 #endif
phonemacro 12:17a0bf823462 118 #endif
phonemacro 18:f4c95b1c0efc 119
phonemacro 0:6f65cae31c54 120 #ifdef ALGO_ONLY
phonemacro 0:6f65cae31c54 121 #define TTL_SZ (ALGO_SZ)
phonemacro 0:6f65cae31c54 122 #else
phonemacro 14:c8cc6d7fd5f9 123 #ifdef RAW
phonemacro 14:c8cc6d7fd5f9 124 #define TTL_SZ (PPG_SZ+ACCEL_SZ)
phonemacro 14:c8cc6d7fd5f9 125 #else
phonemacro 14:c8cc6d7fd5f9 126 #define TTL_SZ (PPG_SZ+ACCEL_SZ+ALGO_SZ)
phonemacro 14:c8cc6d7fd5f9 127 #endif
phonemacro 0:6f65cae31c54 128 #endif
phonemacro 0:6f65cae31c54 129
phonemacro 3:da975696b936 130 Serial pc(USBTX, USBRX, 115200);
phonemacro 0:6f65cae31c54 131 DigitalOut rLED(LED1);
phonemacro 0:6f65cae31c54 132 DigitalOut gLED(LED2);
phonemacro 0:6f65cae31c54 133 DigitalOut bLED(LED3);
phonemacro 6:e1b7190d6cb5 134
phonemacro 6:e1b7190d6cb5 135 //#define thread_sleep_for(x) wait_ms(x) // for older versions of mbed
phonemacro 0:6f65cae31c54 136
phonemacro 5:7f5a012747a5 137
phonemacro 6:e1b7190d6cb5 138 const int SH_ADDR = 0xAA;//0x55;
phonemacro 0:6f65cae31c54 139 int32_t Time_to_Read_PPG = 0;
phonemacro 0:6f65cae31c54 140
phonemacro 0:6f65cae31c54 141 #define BLINKING_RATE_MS 1000ms
phonemacro 0:6f65cae31c54 142 void blink_timer(void) {
phonemacro 0:6f65cae31c54 143 gLED = !gLED; /* blink the green LED */
phonemacro 0:6f65cae31c54 144 }
phonemacro 0:6f65cae31c54 145
phonemacro 0:6f65cae31c54 146 void fifo_timer(void) {
phonemacro 0:6f65cae31c54 147 Time_to_Read_PPG = 1;
phonemacro 0:6f65cae31c54 148 }
phonemacro 0:6f65cae31c54 149
phonemacro 14:c8cc6d7fd5f9 150 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 151 // read_sh_fifo
phonemacro 14:c8cc6d7fd5f9 152 /*****************************************************************************/
phonemacro 27:a45d6e38f2de 153 /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/
phonemacro 27:a45d6e38f2de 154 //#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 155 #ifdef OPTIMIZE_FIFO_READ // tested on MAXM86146EVSYS
phonemacro 27:a45d6e38f2de 156 int32_t check_fifo_countdown;
phonemacro 27:a45d6e38f2de 157 #define MAX_FIFO_CNT 20
phonemacro 27:a45d6e38f2de 158 #endif
phonemacro 10:192ea88e964b 159 void read_sh_fifo(void) {
phonemacro 0:6f65cae31c54 160 char cmd[8], i, j, samples;
phonemacro 0:6f65cae31c54 161 char rsp[3000];
phonemacro 0:6f65cae31c54 162 int32_t ppg[12];
phonemacro 5:7f5a012747a5 163 int16_t accel[3];
phonemacro 12:17a0bf823462 164 int32_t status, opmode, hr, hr_conf, ibi, ibi_conf;
phonemacro 12:17a0bf823462 165 #ifdef EXTENDED_ALGO
phonemacro 12:17a0bf823462 166 int32_t walk_stp, run_stp, energy, amr, iadj1_rqt, iadj1, iadj2_rqt, iadj2, iadj3_rqt, iadj3;
phonemacro 12:17a0bf823462 167 int32_t intadj_rqt, intadj, smpladj_rqt, smpladj, rqt_smplave, afestatehr, hr_motion;
phonemacro 12:17a0bf823462 168 #endif
phonemacro 12:17a0bf823462 169 int32_t act, r, spo2, spo2_conf;
phonemacro 4:4f1e9439f048 170 int32_t spo2_compl, spo2_lo, spo2_mo, spo2_lopi, spo2_unrel, spo2_state, ibi_offset, scd;
phonemacro 2:563d90a111b3 171 int32_t scnt = 0;
phonemacro 0:6f65cae31c54 172 int32_t ptr = 0;
phonemacro 0:6f65cae31c54 173 int32_t sptr = 0;
phonemacro 1:da792e46a385 174 mfio = 0; wait_us(300);
phonemacro 0:6f65cae31c54 175 Time_to_Read_PPG = 0;
phonemacro 27:a45d6e38f2de 176 #if defined(OPTIMIZE_FIFO_READ)
phonemacro 27:a45d6e38f2de 177 check_fifo_countdown--;
phonemacro 27:a45d6e38f2de 178 samples = 1;
phonemacro 27:a45d6e38f2de 179 scnt = 1;
phonemacro 27:a45d6e38f2de 180 if (check_fifo_countdown == 0) {
phonemacro 27:a45d6e38f2de 181 #endif
phonemacro 27:a45d6e38f2de 182
phonemacro 22:f6b366c3b954 183 #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG)
phonemacro 0:6f65cae31c54 184 // 2.1
phonemacro 27:a45d6e38f2de 185 cmd[0] = 0x00; cmd[1] = 0x00;
phonemacro 27:a45d6e38f2de 186 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 27:a45d6e38f2de 187 wait_us(100);
phonemacro 27:a45d6e38f2de 188 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 27:a45d6e38f2de 189 // pc.printf("2.1 Status: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 22:f6b366c3b954 190 #else
phonemacro 22:f6b366c3b954 191 // testd 33.13.12 doesn't need 2.1
phonemacro 0:6f65cae31c54 192 #endif
phonemacro 0:6f65cae31c54 193 // 2.2
phonemacro 27:a45d6e38f2de 194 cmd[0] = 0x12; cmd[1] = 0x00;
phonemacro 27:a45d6e38f2de 195 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 27:a45d6e38f2de 196 wait_us(100);
phonemacro 27:a45d6e38f2de 197 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 27:a45d6e38f2de 198 // pc.printf("2.2 Status: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 27:a45d6e38f2de 199 samples = rsp[1];
phonemacro 27:a45d6e38f2de 200 // pc.printf("num samples %d, (num*ttl)+1 %d\n\r", rsp[1], TTL_SZ*samples+1);
phonemacro 27:a45d6e38f2de 201 // pc.printf("num smpls %d \n\r", samples);
phonemacro 27:a45d6e38f2de 202 scnt = rsp[1];
phonemacro 27:a45d6e38f2de 203 #if defined(OPTIMIZE_FIFO_READ)
phonemacro 27:a45d6e38f2de 204 }
phonemacro 27:a45d6e38f2de 205 if (check_fifo_countdown <= 0)
phonemacro 27:a45d6e38f2de 206 check_fifo_countdown = MAX_FIFO_CNT;
phonemacro 27:a45d6e38f2de 207 #endif
phonemacro 27:a45d6e38f2de 208
phonemacro 0:6f65cae31c54 209 // 2.3
phonemacro 4:4f1e9439f048 210 cmd[0] = 0x12; cmd[1] = 0x01;
phonemacro 6:e1b7190d6cb5 211 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 22:f6b366c3b954 212 wait_us(100);
phonemacro 6:e1b7190d6cb5 213 sh_i2c.read(SH_ADDR, rsp, 1+(TTL_SZ*samples));
phonemacro 22:f6b366c3b954 214 mfio = 1;
phonemacro 21:67d58af1ec56 215
phonemacro 0:6f65cae31c54 216 status = rsp[0];
phonemacro 5:7f5a012747a5 217
phonemacro 0:6f65cae31c54 218 sptr = 1;
phonemacro 0:6f65cae31c54 219 for (i = 0; i < scnt; i++) {
phonemacro 0:6f65cae31c54 220 #ifdef ALGO_ONLY
phonemacro 0:6f65cae31c54 221 ptr = sptr;
phonemacro 0:6f65cae31c54 222 #else
phonemacro 2:563d90a111b3 223 ptr = sptr;
phonemacro 2:563d90a111b3 224 ppg[0] = (rsp[ptr+0] << 16) | (rsp[ptr+1] << 8) | (rsp[ptr+2]);
phonemacro 2:563d90a111b3 225 ppg[1] = (rsp[ptr+3] << 16) | (rsp[ptr+4] << 8) | (rsp[ptr+5]);
phonemacro 2:563d90a111b3 226 ppg[2] = (rsp[ptr+6] << 16) | (rsp[ptr+7] << 8) | (rsp[ptr+8]);
phonemacro 3:da975696b936 227 ppg[3] = (rsp[ptr+9] << 16) | (rsp[ptr+10] << 8) | (rsp[ptr+11]);
phonemacro 4:4f1e9439f048 228 ppg[4] = (rsp[ptr+12] << 16) | (rsp[ptr+13] << 8) | (rsp[ptr+14]);
phonemacro 4:4f1e9439f048 229 ppg[5] = (rsp[ptr+15] << 16) | (rsp[ptr+16] << 8) | (rsp[ptr+17]);
phonemacro 3:da975696b936 230 pc.printf("%d,%d,%d,%d,", ppg[0], ppg[1], ppg[2], ppg[3]);
phonemacro 14:c8cc6d7fd5f9 231 #ifdef MAXM86146_CFG
phonemacro 14:c8cc6d7fd5f9 232 #ifdef RAW
phonemacro 14:c8cc6d7fd5f9 233 pc.printf("%d,%d,", ppg[4], ppg[5]);
phonemacro 14:c8cc6d7fd5f9 234 ppg[6] = (rsp[ptr+18] << 16) | (rsp[ptr+19] << 8) | (rsp[ptr+20]);
phonemacro 14:c8cc6d7fd5f9 235 ppg[7] = (rsp[ptr+21] << 16) | (rsp[ptr+22] << 8) | (rsp[ptr+23]);
phonemacro 14:c8cc6d7fd5f9 236 ppg[8] = (rsp[ptr+24] << 16) | (rsp[ptr+25] << 8) | (rsp[ptr+26]);
phonemacro 14:c8cc6d7fd5f9 237 ppg[9] = (rsp[ptr+27] << 16) | (rsp[ptr+28] << 8) | (rsp[ptr+29]);
phonemacro 14:c8cc6d7fd5f9 238 ppg[10] = (rsp[ptr+30] << 16) | (rsp[ptr+31] << 8) | (rsp[ptr+32]);
phonemacro 14:c8cc6d7fd5f9 239 ppg[11] = (rsp[ptr+33] << 16) | (rsp[ptr+34] << 8) | (rsp[ptr+35]);
phonemacro 14:c8cc6d7fd5f9 240 pc.printf("%d,%d,%d,%d,%d,%d,", ppg[6], ppg[7],ppg[8], ppg[9],ppg[10], ppg[11]);
phonemacro 14:c8cc6d7fd5f9 241 #endif
phonemacro 14:c8cc6d7fd5f9 242 #endif
phonemacro 5:7f5a012747a5 243 accel[0] = (rsp[PPG_SZ+0] << 8) | (rsp[PPG_SZ+1]);
phonemacro 5:7f5a012747a5 244 accel[1] = (rsp[PPG_SZ+2] << 8) | (rsp[PPG_SZ+3]);
phonemacro 5:7f5a012747a5 245 accel[2] = (rsp[PPG_SZ+4] << 8) | (rsp[PPG_SZ+5]);
phonemacro 5:7f5a012747a5 246 pc.printf("%d,%d,%d,", accel[0], accel[1], accel[2]);
phonemacro 5:7f5a012747a5 247
phonemacro 0:6f65cae31c54 248 ptr = sptr + SENSOR_SZ;
phonemacro 0:6f65cae31c54 249 #endif
phonemacro 14:c8cc6d7fd5f9 250 #ifndef RAW
phonemacro 12:17a0bf823462 251 #ifdef EXTENDED_ALGO
phonemacro 3:da975696b936 252 // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ);
phonemacro 0:6f65cae31c54 253 opmode = rsp[ptr];
phonemacro 0:6f65cae31c54 254 hr = (rsp[ptr+1] << 8) + rsp[ptr+2];
phonemacro 0:6f65cae31c54 255 hr_conf = rsp[ptr+3];
phonemacro 12:17a0bf823462 256 ibi = (rsp[ptr+4] << 8) + rsp[ptr+5];
phonemacro 12:17a0bf823462 257
phonemacro 12:17a0bf823462 258 ibi_conf = rsp[ptr+6];
phonemacro 12:17a0bf823462 259 act = rsp[ptr+7];
phonemacro 12:17a0bf823462 260 walk_stp = (rsp[ptr+8] << 24) + (rsp[ptr+9] << 16) + (rsp[ptr+10] << 8) + rsp[ptr+11];
phonemacro 12:17a0bf823462 261 run_stp = (rsp[ptr+12] << 24) + (rsp[ptr+13] << 16) + (rsp[ptr+14] << 8) + rsp[ptr+15];
phonemacro 12:17a0bf823462 262
phonemacro 12:17a0bf823462 263 energy = (rsp[ptr+16] << 24) + (rsp[ptr+17] << 16) + (rsp[ptr+18] << 8) + rsp[ptr+19];
phonemacro 12:17a0bf823462 264 amr = (rsp[ptr+20] << 24) + (rsp[ptr+21] << 16) + (rsp[ptr+22] << 8) + rsp[ptr+23];
phonemacro 12:17a0bf823462 265 iadj1_rqt = rsp[ptr+24];
phonemacro 12:17a0bf823462 266 iadj1 = (rsp[ptr+25] << 8) + rsp[ptr+26];
phonemacro 12:17a0bf823462 267
phonemacro 12:17a0bf823462 268 iadj2_rqt = rsp[ptr+27];
phonemacro 12:17a0bf823462 269 iadj2 = (rsp[ptr+28] << 8) + rsp[ptr+29];
phonemacro 12:17a0bf823462 270 iadj3_rqt = rsp[ptr+30];
phonemacro 12:17a0bf823462 271 iadj3 = (rsp[ptr+31] << 8) + rsp[ptr+32];
phonemacro 12:17a0bf823462 272
phonemacro 12:17a0bf823462 273 intadj_rqt = rsp[ptr+33];
phonemacro 12:17a0bf823462 274 intadj = rsp[ptr+34];
phonemacro 12:17a0bf823462 275 smpladj_rqt = rsp[ptr+35];
phonemacro 12:17a0bf823462 276 smpladj = rsp[ptr+36];
phonemacro 12:17a0bf823462 277
phonemacro 12:17a0bf823462 278 rqt_smplave = rsp[ptr+37];
phonemacro 12:17a0bf823462 279 afestatehr = rsp[ptr+38];
phonemacro 12:17a0bf823462 280 hr_motion = rsp[ptr+39];
phonemacro 12:17a0bf823462 281 scd = rsp[ptr+40];
phonemacro 12:17a0bf823462 282
phonemacro 12:17a0bf823462 283
phonemacro 12:17a0bf823462 284 r = (rsp[ptr+41] << 8) + rsp[ptr+42];
phonemacro 12:17a0bf823462 285 spo2_conf = rsp[ptr+43];
phonemacro 12:17a0bf823462 286
phonemacro 12:17a0bf823462 287 spo2 = (rsp[ptr+44] << 8) + rsp[ptr+45];
phonemacro 12:17a0bf823462 288 spo2_compl = rsp[ptr+46];
phonemacro 12:17a0bf823462 289 spo2_lo = rsp[ptr+47];
phonemacro 12:17a0bf823462 290 spo2_mo = rsp[ptr+48];
phonemacro 12:17a0bf823462 291
phonemacro 12:17a0bf823462 292 spo2_lopi = rsp[ptr+49];
phonemacro 12:17a0bf823462 293 spo2_unrel = rsp[ptr+50];
phonemacro 12:17a0bf823462 294 spo2_state = rsp[ptr+51];
phonemacro 12:17a0bf823462 295
phonemacro 12:17a0bf823462 296 ibi_offset = rsp[ptr+52];
phonemacro 12:17a0bf823462 297
phonemacro 12:17a0bf823462 298 sptr += (TTL_SZ);
phonemacro 12:17a0bf823462 299 #if 1
phonemacro 12:17a0bf823462 300 pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi);
phonemacro 12:17a0bf823462 301 pc.printf("%d,%d,", ibi_conf, act);
phonemacro 12:17a0bf823462 302 pc.printf("%d,%d,%d,", walk_stp, run_stp, energy);
phonemacro 12:17a0bf823462 303 pc.printf("%d,%d,%d,%d,", amr, iadj1_rqt, iadj1, iadj2_rqt);
phonemacro 12:17a0bf823462 304 pc.printf("%d,%d,%d,%d,", iadj2, iadj3_rqt, iadj3, intadj_rqt);
phonemacro 12:17a0bf823462 305 pc.printf("%d,%d,%d,%d,", intadj, smpladj_rqt, smpladj, rqt_smplave);
phonemacro 12:17a0bf823462 306 pc.printf("%d,%d,", afestatehr, hr_motion);
phonemacro 12:17a0bf823462 307 pc.printf("%d,", scd);
phonemacro 12:17a0bf823462 308 pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo);
phonemacro 12:17a0bf823462 309 pc.printf("%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state);
phonemacro 12:17a0bf823462 310 pc.printf("%d,", ibi_offset);
phonemacro 12:17a0bf823462 311 #else
phonemacro 12:17a0bf823462 312 pc.printf("%d,%d,", hr, hr_conf);
phonemacro 12:17a0bf823462 313 pc.printf("%d,%d,", spo2, spo2_conf);
phonemacro 16:ff1122f0624a 314 pc.printf("%d,%d,%d,", spo2_lo, spo2_mo, spo2_lopi);
phonemacro 12:17a0bf823462 315 pc.printf("%d,%d,", spo2_unrel, scd);
phonemacro 12:17a0bf823462 316 #endif
phonemacro 12:17a0bf823462 317 #else // normal algo size
phonemacro 12:17a0bf823462 318 // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ);
phonemacro 12:17a0bf823462 319 opmode = rsp[ptr];
phonemacro 12:17a0bf823462 320 hr = (rsp[ptr+1] << 8) + rsp[ptr+2];
phonemacro 12:17a0bf823462 321 hr_conf = rsp[ptr+3];
phonemacro 12:17a0bf823462 322 ibi = (rsp[ptr+4] << 8) + rsp[ptr+5];
phonemacro 4:4f1e9439f048 323
phonemacro 11:a16b6bf38841 324 ibi_conf = rsp[ptr+6];
phonemacro 3:da975696b936 325 act = rsp[ptr+7];
phonemacro 3:da975696b936 326 r = (rsp[ptr+8] << 8) + rsp[ptr+9];
phonemacro 0:6f65cae31c54 327 spo2_conf = rsp[ptr+10];
phonemacro 4:4f1e9439f048 328
phonemacro 0:6f65cae31c54 329 spo2 = (rsp[ptr+11] << 8) + rsp[ptr+12];
phonemacro 4:4f1e9439f048 330 spo2_compl = rsp[ptr+13];
phonemacro 4:4f1e9439f048 331 spo2_lo = rsp[ptr+14];
phonemacro 4:4f1e9439f048 332 spo2_mo = rsp[ptr+15];
phonemacro 4:4f1e9439f048 333
phonemacro 4:4f1e9439f048 334 spo2_lopi = rsp[ptr+16];
phonemacro 4:4f1e9439f048 335 spo2_unrel = rsp[ptr+17];
phonemacro 4:4f1e9439f048 336 spo2_state = rsp[ptr+18];
phonemacro 2:563d90a111b3 337 scd = rsp[ptr+19];
phonemacro 0:6f65cae31c54 338
phonemacro 4:4f1e9439f048 339 ibi_offset = rsp[ptr+20];
phonemacro 0:6f65cae31c54 340
phonemacro 4:4f1e9439f048 341 sptr += (TTL_SZ);
phonemacro 27:a45d6e38f2de 342 #if 0
phonemacro 4:4f1e9439f048 343 pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi);
phonemacro 4:4f1e9439f048 344 pc.printf("%d,%d,%d,%d,", ibi_conf, act, r, spo2_conf);
phonemacro 4:4f1e9439f048 345 pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo);
phonemacro 4:4f1e9439f048 346 pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state, scd);
phonemacro 4:4f1e9439f048 347 pc.printf("%d,", ibi_offset);
phonemacro 4:4f1e9439f048 348 #else
phonemacro 4:4f1e9439f048 349 pc.printf("%d,%d,", hr, hr_conf);
phonemacro 4:4f1e9439f048 350 pc.printf("%d,%d,", spo2, spo2_conf);
phonemacro 4:4f1e9439f048 351 pc.printf("%d,", spo2_lo);
phonemacro 4:4f1e9439f048 352 pc.printf("%d,%d,", spo2_unrel, scd);
phonemacro 4:4f1e9439f048 353 #endif
phonemacro 12:17a0bf823462 354 #endif // end normal algo size
phonemacro 14:c8cc6d7fd5f9 355 #endif // !RAW
phonemacro 4:4f1e9439f048 356
phonemacro 3:da975696b936 357 pc.printf("\n\r");
phonemacro 0:6f65cae31c54 358 }
phonemacro 0:6f65cae31c54 359 }
phonemacro 0:6f65cae31c54 360
phonemacro 6:e1b7190d6cb5 361 #ifdef MAXREFDES103_CFG
phonemacro 14:c8cc6d7fd5f9 362 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 363 // init_max20303_pmic
phonemacro 14:c8cc6d7fd5f9 364 /*****************************************************************************/
phonemacro 6:e1b7190d6cb5 365 void init_max20303_pmic(void) {
phonemacro 5:7f5a012747a5 366 /* Wait for pmic to settle down */
phonemacro 5:7f5a012747a5 367 thread_sleep_for(800);
phonemacro 5:7f5a012747a5 368
phonemacro 5:7f5a012747a5 369 //set_time(1544787300); // Set RTC time to Wed, 28 Oct 2009 11:35:37
phonemacro 6:e1b7190d6cb5 370 MAX20303 max20303(&sh_i2c);
phonemacro 5:7f5a012747a5 371 /*Set LDO1 to 1.8v*/
phonemacro 5:7f5a012747a5 372 max20303.LDO1Config();
phonemacro 5:7f5a012747a5 373
phonemacro 5:7f5a012747a5 374 /*Set LDO2 to 3v*/
phonemacro 5:7f5a012747a5 375 max20303.LDO2Config();
phonemacro 5:7f5a012747a5 376
phonemacro 5:7f5a012747a5 377 //max20303.BoostEnable();
phonemacro 5:7f5a012747a5 378 max20303.BuckBoostEnable();
phonemacro 5:7f5a012747a5 379
phonemacro 5:7f5a012747a5 380 max20303.led0on(0);
phonemacro 5:7f5a012747a5 381 max20303.led1on(0);
phonemacro 5:7f5a012747a5 382 max20303.led2on(0);
phonemacro 5:7f5a012747a5 383
phonemacro 5:7f5a012747a5 384 /* Wait for pmic to settle down */
phonemacro 5:7f5a012747a5 385 thread_sleep_for(200);
phonemacro 6:e1b7190d6cb5 386
phonemacro 5:7f5a012747a5 387 }
phonemacro 6:e1b7190d6cb5 388 #endif // MAXREFDES103_CFG
phonemacro 14:c8cc6d7fd5f9 389
phonemacro 14:c8cc6d7fd5f9 390 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 391 // init_sh_algo
phonemacro 14:c8cc6d7fd5f9 392 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 393 void init_sh_algo(void) {
phonemacro 14:c8cc6d7fd5f9 394 char cmd[8];
phonemacro 0:6f65cae31c54 395 char rsp[256];
phonemacro 27:a45d6e38f2de 396
phonemacro 27:a45d6e38f2de 397 #ifdef OPTIMIZE_FIFO_READ
phonemacro 27:a45d6e38f2de 398 check_fifo_countdown = MAX_FIFO_CNT;
phonemacro 27:a45d6e38f2de 399 #endif
phonemacro 27:a45d6e38f2de 400
phonemacro 10:192ea88e964b 401 // switch to application mode
phonemacro 0:6f65cae31c54 402 rst = 0;
phonemacro 0:6f65cae31c54 403 mfio = 1;
phonemacro 0:6f65cae31c54 404 thread_sleep_for(10);
phonemacro 0:6f65cae31c54 405 rst = 1;
phonemacro 0:6f65cae31c54 406 thread_sleep_for(1500);
phonemacro 10:192ea88e964b 407 #ifdef MAXREFDES103_CFG
phonemacro 10:192ea88e964b 408 init_max20303_pmic();
phonemacro 10:192ea88e964b 409 #endif
phonemacro 23:e7ecf1416965 410 #if 0 // 1.5s is ok for 33.13.12
phonemacro 23:e7ecf1416965 411 thread_sleep_for(250);
phonemacro 20:7fc26287beb7 412 #endif
phonemacro 0:6f65cae31c54 413
phonemacro 1:da792e46a385 414 mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 415
phonemacro 4:4f1e9439f048 416 //read operating mode
phonemacro 4:4f1e9439f048 417 cmd[0] = 0x02; cmd[1] = 0x00;
phonemacro 6:e1b7190d6cb5 418 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 1:da792e46a385 419 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 420 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 6:e1b7190d6cb5 421 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 422 pc.printf("\n\r 0x02 0x00 Status, Read Operating Mode: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 5:7f5a012747a5 423 //1.11 rd ver
phonemacro 4:4f1e9439f048 424 cmd[0] = 0xFF; cmd[1] = 0x03;
phonemacro 6:e1b7190d6cb5 425 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 1:da792e46a385 426 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 427 sh_i2c.read(SH_ADDR, rsp, 4);
phonemacro 1:da792e46a385 428 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 429 pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]);
phonemacro 0:6f65cae31c54 430
phonemacro 17:0d6e99a0fd8d 431 #if 0
phonemacro 17:0d6e99a0fd8d 432 // algo sz
phonemacro 17:0d6e99a0fd8d 433 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x01;
phonemacro 17:0d6e99a0fd8d 434 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 17:0d6e99a0fd8d 435 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 436 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 17:0d6e99a0fd8d 437 mfio = 1; mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 438 pc.printf("algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 17:0d6e99a0fd8d 439
phonemacro 17:0d6e99a0fd8d 440 // algo sz
phonemacro 17:0d6e99a0fd8d 441 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x02;
phonemacro 17:0d6e99a0fd8d 442 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 17:0d6e99a0fd8d 443 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 444 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 17:0d6e99a0fd8d 445 mfio = 1; mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 446 pc.printf("algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 17:0d6e99a0fd8d 447
phonemacro 17:0d6e99a0fd8d 448 // algo sz
phonemacro 17:0d6e99a0fd8d 449 cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x03;
phonemacro 17:0d6e99a0fd8d 450 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 17:0d6e99a0fd8d 451 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 452 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 17:0d6e99a0fd8d 453 mfio = 1; mfio = 0; wait_us(300);
phonemacro 17:0d6e99a0fd8d 454 pc.printf("algo size: %d %d \n\r", rsp[0], rsp[1]);
phonemacro 17:0d6e99a0fd8d 455 #endif
phonemacro 17:0d6e99a0fd8d 456
phonemacro 17:0d6e99a0fd8d 457 #if 0
phonemacro 17:0d6e99a0fd8d 458 // set Perfusion Index threshold to .05 (3x.13.19+)
phonemacro 17:0d6e99a0fd8d 459 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x1D; cmd[3] = 50;
phonemacro 16:ff1122f0624a 460 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 16:ff1122f0624a 461 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 16:ff1122f0624a 462 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 16:ff1122f0624a 463 mfio = 1; mfio = 0; wait_us(300);
phonemacro 16:ff1122f0624a 464 pc.printf("pi set to 0x19 : %x \n\r", rsp[0]);
phonemacro 17:0d6e99a0fd8d 465 #endif
phonemacro 16:ff1122f0624a 466
phonemacro 0:6f65cae31c54 467 // 1.3 sensor and algo data
phonemacro 4:4f1e9439f048 468 cmd[0] = 0x10; cmd[1] = 0x00;
phonemacro 2:563d90a111b3 469 #ifdef ALGO_ONLY
phonemacro 0:6f65cae31c54 470 cmd[2] = 0x02; // algo data
phonemacro 4:4f1e9439f048 471 pc.printf("algo only \n\r");
phonemacro 2:563d90a111b3 472 #else
phonemacro 2:563d90a111b3 473 cmd[2] = 0x03; // sensor + algo data
phonemacro 4:4f1e9439f048 474 pc.printf("sens+algo \n\r");
phonemacro 2:563d90a111b3 475 #endif
phonemacro 6:e1b7190d6cb5 476 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 1:da792e46a385 477 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 478 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 479 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 480 pc.printf("1.3 Status: %x\n\r", rsp[0]);
phonemacro 3:da975696b936 481 // 1.7 cont hr, spo2
phonemacro 4:4f1e9439f048 482 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0A; cmd[3] = 0x00;
phonemacro 6:e1b7190d6cb5 483 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 3:da975696b936 484 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 485 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 486 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 487 pc.printf("1.7 Status: %x\n\r", rsp[0]);
phonemacro 4:4f1e9439f048 488 // 1.8 AEC enable (default)
phonemacro 4:4f1e9439f048 489 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0B; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 490 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 1:da792e46a385 491 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 492 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 493 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 494 pc.printf("1.8 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 495 #if AGC
phonemacro 13:1baccc6275a7 496 // AGC1.8 Disable auto PD (default
phonemacro 13:1baccc6275a7 497 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x12; cmd[3] = 0x00;
phonemacro 13:1baccc6275a7 498 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 13:1baccc6275a7 499 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 500 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 13:1baccc6275a7 501 mfio = 1; mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 502 pc.printf("AGC1.8 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 503 // AGC1.9 Disable SCD (default)
phonemacro 13:1baccc6275a7 504 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0C; cmd[3] = 0x00;
phonemacro 13:1baccc6275a7 505 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 13:1baccc6275a7 506 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 507 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 13:1baccc6275a7 508 mfio = 1; mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 509 pc.printf("AGC1.9 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 510 // AGC1.10 Set AGC target PD TO 10uA
phonemacro 13:1baccc6275a7 511 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x11; cmd[3] = 0x00; cmd[3] = 0x64;
phonemacro 13:1baccc6275a7 512 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 13:1baccc6275a7 513 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 514 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 13:1baccc6275a7 515 mfio = 1; mfio = 0; wait_us(300);
phonemacro 13:1baccc6275a7 516 pc.printf("AGC1.10 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 517 #else
phonemacro 4:4f1e9439f048 518 // 1.9 auto PD (default
phonemacro 4:4f1e9439f048 519 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x12; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 520 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 1:da792e46a385 521 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 522 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 523 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 524 pc.printf("1.9 Status: %x\n\r", rsp[0]);
phonemacro 4:4f1e9439f048 525 // 1.10 SCD (default)
phonemacro 4:4f1e9439f048 526 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0C; cmd[3] = 0x01;
phonemacro 6:e1b7190d6cb5 527 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 4:4f1e9439f048 528 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 529 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 4:4f1e9439f048 530 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 531 pc.printf("1.7 Status: %x\n\r", rsp[0]);
phonemacro 13:1baccc6275a7 532 #endif
phonemacro 3:da975696b936 533 #ifdef MAXM86146_CFG
phonemacro 3:da975696b936 534 //1.20 Sec 4.1 map leds to slots for MAXM86146
phonemacro 4:4f1e9439f048 535 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x13; cmd[4] = 0x56; cmd[5] = 0x00;
phonemacro 6:e1b7190d6cb5 536 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 3:da975696b936 537 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 538 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 539 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 540 pc.printf("map leds to slots %x\n\r", rsp[0]);
phonemacro 3:da975696b936 541 //1.21 map HR inputs to slots
phonemacro 4:4f1e9439f048 542 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x11;
phonemacro 6:e1b7190d6cb5 543 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 3:da975696b936 544 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 545 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 546 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 547 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 3:da975696b936 548 //1.22 map SpO2 inputs to slots
phonemacro 4:4f1e9439f048 549 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x30; cmd[4] = 0x20;
phonemacro 6:e1b7190d6cb5 550 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 3:da975696b936 551 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 552 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 553 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 554 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 26:33c0d3fd2a95 555
phonemacro 3:da975696b936 556 #if 0
phonemacro 2:563d90a111b3 557 //1.20 Sec 4.1 map leds to slots for MAXM86146
phonemacro 4:4f1e9439f048 558 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x15; cmd[4] = 0x60; cmd[5] = 0x00;
phonemacro 6:e1b7190d6cb5 559 sh_i2c.write(SH_ADDR, cmd, 6);
phonemacro 1:da792e46a385 560 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 561 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 562 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 563 pc.printf("map leds to slots%x\n\r", rsp[0]);
phonemacro 2:563d90a111b3 564 //1.21 map HR inputs to slots
phonemacro 4:4f1e9439f048 565 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x01;
phonemacro 6:e1b7190d6cb5 566 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 1:da792e46a385 567 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 568 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 569 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 570 pc.printf("map HR to slots/PDs %x\n\r", rsp[0]);
phonemacro 2:563d90a111b3 571 //1.22 map SpO2 inputs to slots
phonemacro 4:4f1e9439f048 572 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x20; cmd[4] = 0x10;
phonemacro 6:e1b7190d6cb5 573 sh_i2c.write(SH_ADDR, cmd, 5);
phonemacro 1:da792e46a385 574 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 575 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 1:da792e46a385 576 mfio = 1; mfio = 0; wait_us(300);
phonemacro 3:da975696b936 577 pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]);
phonemacro 3:da975696b936 578 #endif
phonemacro 3:da975696b936 579 #endif // MAXM86146_CFG
phonemacro 0:6f65cae31c54 580
phonemacro 4:4f1e9439f048 581 // 1.3 Enable HR, SpO2 algo
phonemacro 12:17a0bf823462 582 #ifdef EXTENDED_ALGO
phonemacro 12:17a0bf823462 583 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x02;
phonemacro 12:17a0bf823462 584 #else
phonemacro 4:4f1e9439f048 585 cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x01;
phonemacro 12:17a0bf823462 586 #endif
phonemacro 6:e1b7190d6cb5 587 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 26:33c0d3fd2a95 588 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 0:6f65cae31c54 589 thread_sleep_for(465);
phonemacro 26:33c0d3fd2a95 590 thread_sleep_for(465);
phonemacro 26:33c0d3fd2a95 591 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 592 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 3:da975696b936 593 pc.printf("1.14 status: %x\n\r", rsp[0]);
phonemacro 0:6f65cae31c54 594
phonemacro 4:4f1e9439f048 595 #if 1
phonemacro 4:4f1e9439f048 596 //1.31 rd AFE part id
phonemacro 4:4f1e9439f048 597 cmd[0] = 0x41; cmd[1] = 0x00; cmd[2] = 0xFF;
phonemacro 6:e1b7190d6cb5 598 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 4:4f1e9439f048 599 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 600 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 4:4f1e9439f048 601 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 602 pc.printf("1.31 part id afe %x %x\n\r", rsp[0], rsp[1]);
phonemacro 4:4f1e9439f048 603 //1.32 rd accel who
phonemacro 4:4f1e9439f048 604 cmd[0] = 0x41; cmd[1] = 0x04; cmd[2] = 0x0F;
phonemacro 6:e1b7190d6cb5 605 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 4:4f1e9439f048 606 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 6:e1b7190d6cb5 607 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 4:4f1e9439f048 608 mfio = 1; mfio = 0; wait_us(300);
phonemacro 4:4f1e9439f048 609 pc.printf("1.32 who accel %x %x\n\r", rsp[0], rsp[1]);
phonemacro 26:33c0d3fd2a95 610
phonemacro 26:33c0d3fd2a95 611 mfio = 1;
phonemacro 4:4f1e9439f048 612 #endif
phonemacro 10:192ea88e964b 613 }
phonemacro 10:192ea88e964b 614
phonemacro 14:c8cc6d7fd5f9 615 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 616 // init_sh_raw
phonemacro 14:c8cc6d7fd5f9 617 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 618 void init_sh_raw(void) {
phonemacro 14:c8cc6d7fd5f9 619 char cmd[8];
phonemacro 14:c8cc6d7fd5f9 620 char rsp[256];
phonemacro 14:c8cc6d7fd5f9 621 // switch to application mode
phonemacro 14:c8cc6d7fd5f9 622 rst = 0;
phonemacro 14:c8cc6d7fd5f9 623 mfio = 1;
phonemacro 14:c8cc6d7fd5f9 624 thread_sleep_for(10);
phonemacro 14:c8cc6d7fd5f9 625 rst = 1;
phonemacro 14:c8cc6d7fd5f9 626 thread_sleep_for(1500);
phonemacro 14:c8cc6d7fd5f9 627 #ifdef MAXREFDES103_CFG
phonemacro 14:c8cc6d7fd5f9 628 init_max20303_pmic();
phonemacro 14:c8cc6d7fd5f9 629 #endif
phonemacro 14:c8cc6d7fd5f9 630
phonemacro 14:c8cc6d7fd5f9 631 mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 632
phonemacro 14:c8cc6d7fd5f9 633 //read operating mode
phonemacro 14:c8cc6d7fd5f9 634 cmd[0] = 0x02; cmd[1] = 0x00;
phonemacro 14:c8cc6d7fd5f9 635 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 14:c8cc6d7fd5f9 636 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 637 sh_i2c.read(SH_ADDR, rsp, 2);
phonemacro 14:c8cc6d7fd5f9 638 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 639 pc.printf("\n\r 0x02 0x00 Status, Read Operating Mode: %x %x\n\r", rsp[0], rsp[1]);
phonemacro 14:c8cc6d7fd5f9 640 //1.11 rd ver
phonemacro 14:c8cc6d7fd5f9 641 cmd[0] = 0xFF; cmd[1] = 0x03;
phonemacro 14:c8cc6d7fd5f9 642 sh_i2c.write(SH_ADDR, cmd, 2);
phonemacro 14:c8cc6d7fd5f9 643 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 644 sh_i2c.read(SH_ADDR, rsp, 4);
phonemacro 14:c8cc6d7fd5f9 645 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 646 pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]);
phonemacro 14:c8cc6d7fd5f9 647
phonemacro 14:c8cc6d7fd5f9 648 // raw1.1 sensor data
phonemacro 14:c8cc6d7fd5f9 649 cmd[0] = 0x10; cmd[1] = 0x00; cmd[2] = 0x01;
phonemacro 14:c8cc6d7fd5f9 650 pc.printf("raw sensor data only \n\r");
phonemacro 14:c8cc6d7fd5f9 651 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 14:c8cc6d7fd5f9 652 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 653 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 654 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 655 pc.printf("raw1.1 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 656 // raw1.2 interrupt threshold
phonemacro 14:c8cc6d7fd5f9 657 cmd[0] = 0x10; cmd[1] = 0x01; cmd[2] = 0x01;
phonemacro 14:c8cc6d7fd5f9 658 sh_i2c.write(SH_ADDR, cmd, 3);
phonemacro 14:c8cc6d7fd5f9 659 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 660 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 661 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 662 pc.printf("raw1.2 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 663 // raw1.3 enable sh accel
phonemacro 14:c8cc6d7fd5f9 664 cmd[0] = 0x44; cmd[1] = 0x04; cmd[2] = 0x01; cmd[3] = 0x00;
phonemacro 14:c8cc6d7fd5f9 665 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 666 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 667 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 668 mfio = 1; thread_sleep_for(20); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 669 pc.printf("raw1.3 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 670 // raw1.4 enable AFE
phonemacro 14:c8cc6d7fd5f9 671 cmd[0] = 0x44; cmd[1] = 0x00; cmd[2] = 0x01; cmd[3] = 0x00;
phonemacro 14:c8cc6d7fd5f9 672 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 673 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 674 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 675 mfio = 1; thread_sleep_for(250); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 676 pc.printf("raw1.4 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 677 // raw1.5 sample rate 100 Hz, ave 1
phonemacro 14:c8cc6d7fd5f9 678 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x18; // set AFE reg 0x12 to 100 Hz
phonemacro 14:c8cc6d7fd5f9 679 // cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x20; // set AFE reg 0x12 to 200 Hz
phonemacro 14:c8cc6d7fd5f9 680 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 681 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 682 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 683 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 684 pc.printf("raw1.5 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 685 // raw1.6 LED1 current
phonemacro 14:c8cc6d7fd5f9 686 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x23; cmd[3] = 0x7F;
phonemacro 14:c8cc6d7fd5f9 687 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 688 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 689 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 690 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 691 pc.printf("raw1.6 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 692 #ifndef MAXM86146_CFG
phonemacro 14:c8cc6d7fd5f9 693 // raw1.7 LED2 current
phonemacro 14:c8cc6d7fd5f9 694 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x24; cmd[3] = 0x7F;
phonemacro 14:c8cc6d7fd5f9 695 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 696 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 697 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 698 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 699 pc.printf("raw1.7 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 700 #endif
phonemacro 14:c8cc6d7fd5f9 701 // raw1.8 LED3 current
phonemacro 14:c8cc6d7fd5f9 702 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x25; cmd[3] = 0x7F;
phonemacro 14:c8cc6d7fd5f9 703 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 704 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 705 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 706 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 707 pc.printf("raw1.8 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 708 #ifdef MAXM86146_CFG
phonemacro 14:c8cc6d7fd5f9 709 // LED5 current
phonemacro 14:c8cc6d7fd5f9 710 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x27; cmd[3] = 0x7F;
phonemacro 14:c8cc6d7fd5f9 711 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 712 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 713 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 714 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 715 pc.printf("led5 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 716 // LED6 current
phonemacro 14:c8cc6d7fd5f9 717 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x27; cmd[3] = 0x7F;
phonemacro 14:c8cc6d7fd5f9 718 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 719 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 720 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 721 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 722 pc.printf("led6 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 723
phonemacro 14:c8cc6d7fd5f9 724 // Set Seq cntrl1 LED2, LED1
phonemacro 14:c8cc6d7fd5f9 725 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x20; cmd[3] = 0x21;
phonemacro 14:c8cc6d7fd5f9 726 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 727 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 728 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 729 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 730 pc.printf("Seq cntrl1 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 731 // Set Seq cntrl2 LED4, LED3
phonemacro 14:c8cc6d7fd5f9 732 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x21; cmd[3] = 0xA3;
phonemacro 14:c8cc6d7fd5f9 733 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 734 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 735 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 736 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 737 pc.printf("Seq cntrl2 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 738 // Set Seq cntrl3 LED6, LED5
phonemacro 14:c8cc6d7fd5f9 739 cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x22; cmd[3] = 0x21;
phonemacro 14:c8cc6d7fd5f9 740 // cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x22; cmd[3] = 0x99; // Ambient
phonemacro 14:c8cc6d7fd5f9 741 sh_i2c.write(SH_ADDR, cmd, 4);
phonemacro 14:c8cc6d7fd5f9 742 mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 743 sh_i2c.read(SH_ADDR, rsp, 1);
phonemacro 14:c8cc6d7fd5f9 744 mfio = 1; mfio = 0; wait_us(300);
phonemacro 14:c8cc6d7fd5f9 745 pc.printf("Seq cntrl3 Status: %x\n\r", rsp[0]);
phonemacro 14:c8cc6d7fd5f9 746
phonemacro 14:c8cc6d7fd5f9 747 #endif
phonemacro 14:c8cc6d7fd5f9 748 }
phonemacro 14:c8cc6d7fd5f9 749
phonemacro 14:c8cc6d7fd5f9 750 /*****************************************************************************/
phonemacro 14:c8cc6d7fd5f9 751 // main
phonemacro 14:c8cc6d7fd5f9 752 /*****************************************************************************/
phonemacro 10:192ea88e964b 753 int main()
phonemacro 10:192ea88e964b 754 {
phonemacro 10:192ea88e964b 755 sh_i2c.frequency(400000);
phonemacro 10:192ea88e964b 756 int32_t ledcnt = 0;
phonemacro 10:192ea88e964b 757 rLED = LED_OFF; gLED = LED_ON; bLED = LED_OFF;
phonemacro 10:192ea88e964b 758 Ticker ticker; // calls a callback repeatedly with a timeout
phonemacro 10:192ea88e964b 759 //ticker.attach(callback(&blink_timer), BLINKING_RATE_MS); /* set timer for one second */
phonemacro 14:c8cc6d7fd5f9 760 #ifdef RAW
phonemacro 14:c8cc6d7fd5f9 761 init_sh_raw();
phonemacro 14:c8cc6d7fd5f9 762 #else
phonemacro 14:c8cc6d7fd5f9 763 init_sh_algo();
phonemacro 14:c8cc6d7fd5f9 764 #endif
phonemacro 8:e6ae69cfecbf 765 #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG) || defined(MAXM86146_CFG)
phonemacro 6:e1b7190d6cb5 766 Timer tmr1;
phonemacro 0:6f65cae31c54 767 while (1) {
phonemacro 6:e1b7190d6cb5 768 tmr1.start();
phonemacro 6:e1b7190d6cb5 769 if (tmr1.read_ms() > 40) {
phonemacro 7:23b067817ab8 770 tmr1.reset();
phonemacro 10:192ea88e964b 771 read_sh_fifo();
phonemacro 7:23b067817ab8 772 if ((ledcnt++ % 50) == 0)
phonemacro 6:e1b7190d6cb5 773 gLED = !gLED;
phonemacro 0:6f65cae31c54 774 }
phonemacro 0:6f65cae31c54 775 }
phonemacro 6:e1b7190d6cb5 776 #else
phonemacro 6:e1b7190d6cb5 777 ticker.attach(callback(&fifo_timer), 0.040f);
phonemacro 6:e1b7190d6cb5 778 while (1) {
phonemacro 6:e1b7190d6cb5 779 if (Time_to_Read_PPG) {
phonemacro 10:192ea88e964b 780 read_sh_fifo();
phonemacro 7:23b067817ab8 781 if ((ledcnt++ % 50) == 0)
phonemacro 6:e1b7190d6cb5 782 gLED = !gLED;
phonemacro 6:e1b7190d6cb5 783 }
phonemacro 6:e1b7190d6cb5 784 }
phonemacro 6:e1b7190d6cb5 785 #endif
phonemacro 0:6f65cae31c54 786 }