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