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