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