David Jung
/
MAX32664C_MAXM86146_Mode1_Optical
Mode1 Optical Validation
main.cpp@32:92adfbe18ab6, 2022-03-14 (annotated)
- Committer:
- phonemacro
- Date:
- Mon Mar 14 23:53:46 2022 +0000
- Revision:
- 32:92adfbe18ab6
- Parent:
- 31:92e1bcdb7b1e
- Child:
- 33:c8fbd904df3e
Updated comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
phonemacro | 0:6f65cae31c54 | 1 | /******************************************************************************* |
phonemacro | 30:77a30ea425da | 2 | * Copyright (C) 2021-22 Maxim Integrated Products, Inc., All Rights Reserved. |
phonemacro | 0:6f65cae31c54 | 3 | * |
phonemacro | 0:6f65cae31c54 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
phonemacro | 0:6f65cae31c54 | 5 | * copy of this software and associated documentation files (the "Software"), |
phonemacro | 0:6f65cae31c54 | 6 | * to deal in the Software without restriction, including without limitation |
phonemacro | 0:6f65cae31c54 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
phonemacro | 0:6f65cae31c54 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
phonemacro | 0:6f65cae31c54 | 9 | * Software is furnished to do so, subject to the following conditions: |
phonemacro | 0:6f65cae31c54 | 10 | * |
phonemacro | 0:6f65cae31c54 | 11 | * The above copyright notice and this permission notice shall be included |
phonemacro | 0:6f65cae31c54 | 12 | * in all copies or substantial portions of the Software. |
phonemacro | 0:6f65cae31c54 | 13 | * |
phonemacro | 0:6f65cae31c54 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
phonemacro | 0:6f65cae31c54 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
phonemacro | 0:6f65cae31c54 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
phonemacro | 0:6f65cae31c54 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
phonemacro | 0:6f65cae31c54 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
phonemacro | 0:6f65cae31c54 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
phonemacro | 0:6f65cae31c54 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
phonemacro | 0:6f65cae31c54 | 21 | * |
phonemacro | 0:6f65cae31c54 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
phonemacro | 0:6f65cae31c54 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
phonemacro | 0:6f65cae31c54 | 24 | * Products, Inc. Branding Policy. |
phonemacro | 0:6f65cae31c54 | 25 | * |
phonemacro | 0:6f65cae31c54 | 26 | * The mere transfer of this software does not imply any licenses |
phonemacro | 0:6f65cae31c54 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
phonemacro | 0:6f65cae31c54 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
phonemacro | 0:6f65cae31c54 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
phonemacro | 0:6f65cae31c54 | 30 | * ownership rights. |
phonemacro | 0:6f65cae31c54 | 31 | ******************************************************************************* |
phonemacro | 0:6f65cae31c54 | 32 | */ |
phonemacro | 0:6f65cae31c54 | 33 | |
phonemacro | 0:6f65cae31c54 | 34 | #include "mbed.h" |
phonemacro | 0:6f65cae31c54 | 35 | #include "platform/mbed_thread.h" |
phonemacro | 3:da975696b936 | 36 | #include "mbed.h" |
phonemacro | 4:4f1e9439f048 | 37 | /****************************************************************************** |
phonemacro | 16:ff1122f0624a | 38 | * https://os.mbed.com/users/phonemacro/code/MAX32664C_Example_Host_Code |
phonemacro | 16:ff1122f0624a | 39 | * Tera Term output is set to 115200 baud rate. |
phonemacro | 32:92adfbe18ab6 | 40 | * ver: 220310 |
phonemacro | 16:ff1122f0624a | 41 | ******************************************************************************/ |
phonemacro | 16:ff1122f0624a | 42 | |
phonemacro | 16:ff1122f0624a | 43 | /****************************************************************************** |
phonemacro | 4:4f1e9439f048 | 44 | * Warning, if using the either |
phonemacro | 4:4f1e9439f048 | 45 | * MAX32630FTHR+MAXM86161_ADPTER_REVB+MAXM86146EVSYS sensor brd or |
phonemacro | 4:4f1e9439f048 | 46 | * MAX32630FTHR+MAXM86161_ADPTER_REVB+MAXM86161EVSYS sensor brd, |
phonemacro | 4:4f1e9439f048 | 47 | * The VLED is connected to USB power which is noisy. The VLED should be |
phonemacro | 4:4f1e9439f048 | 48 | * connected to a regulated power supply if you are testing accuracy. |
phonemacro | 4:4f1e9439f048 | 49 | ******************************************************************************* |
phonemacro | 4:4f1e9439f048 | 50 | */ |
phonemacro | 5:7f5a012747a5 | 51 | |
phonemacro | 24:064478ff33d2 | 52 | /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/ |
phonemacro | 6:e1b7190d6cb5 | 53 | // define one and only one of the following three platforms |
phonemacro | 32:92adfbe18ab6 | 54 | #define MAXM86146_CFG 1 // tested on MAXM86146EVSYS_sensorBrd+MAXM86161_ADAPTER_REVB+MAX32630FTHR 33.13.31/12 |
phonemacro | 21:67d58af1ec56 | 55 | //#define MAXREFDES103_CFG // not tested |
phonemacro | 32:92adfbe18ab6 | 56 | //#define MAXM86161_CFG 1 // tested on MAXM86161+MAX32630FTHR v32.9.23, 32.13.12 |
phonemacro | 6:e1b7190d6cb5 | 57 | /*****************************************************************************/ |
phonemacro | 24:064478ff33d2 | 58 | |
phonemacro | 24:064478ff33d2 | 59 | /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/ |
phonemacro | 24:064478ff33d2 | 60 | // define which adaptor board is being used |
phonemacro | 26:33c0d3fd2a95 | 61 | #define MAXM86161_ADPTR_EVKIT_B |
phonemacro | 26:33c0d3fd2a95 | 62 | //#define MAXREFDES1319 // MAXM86161: Remove J7; For PIN1=ACC_INTN, J9 set to 2-3; For PIN13=OPT_INTN, J10 set to 2-3 |
phonemacro | 24:064478ff33d2 | 63 | /****************************************************************************** |
phonemacro | 24:064478ff33d2 | 64 | * MAX32630FTHR GPIOs |
phonemacro | 24:064478ff33d2 | 65 | ******************************************************************************/ |
phonemacro | 24:064478ff33d2 | 66 | #ifdef MAXM86161_ADPTR_EVKIT_B |
phonemacro | 24:064478ff33d2 | 67 | #define RST_PIN P5_6 |
phonemacro | 24:064478ff33d2 | 68 | #define MFIO_PIN P5_4 |
phonemacro | 24:064478ff33d2 | 69 | #else |
phonemacro | 24:064478ff33d2 | 70 | #ifdef MAXREFDES1319 |
phonemacro | 24:064478ff33d2 | 71 | #define RST_PIN P3_0 |
phonemacro | 24:064478ff33d2 | 72 | #define MFIO_PIN P5_2 |
phonemacro | 24:064478ff33d2 | 73 | #endif |
phonemacro | 24:064478ff33d2 | 74 | #endif |
phonemacro | 24:064478ff33d2 | 75 | |
phonemacro | 24:064478ff33d2 | 76 | DigitalOut rst(RST_PIN, PullUp); |
phonemacro | 24:064478ff33d2 | 77 | DigitalOut mfio(MFIO_PIN, PullUp); |
phonemacro | 24:064478ff33d2 | 78 | I2C sh_i2c(P3_4, P3_5); |
phonemacro | 24:064478ff33d2 | 79 | |
phonemacro | 24:064478ff33d2 | 80 | /*****************************************************************************/ |
phonemacro | 26:33c0d3fd2a95 | 81 | #if defined(MAXM86161_CFG) //|| defined(MAXM86146_CFG) // don't need 3.3V for MAXM86146EVSYS_sensorBrd+MAXM86161_ADAPTER_REVB+MAX32630FTHR |
phonemacro | 17:0d6e99a0fd8d | 82 | #include "max32630fthr.h" |
phonemacro | 17:0d6e99a0fd8d | 83 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); // Enable J1-pin2, 3.3V and set GPIO to 3.3v |
phonemacro | 21:67d58af1ec56 | 84 | #endif |
phonemacro | 26:33c0d3fd2a95 | 85 | |
phonemacro | 26:33c0d3fd2a95 | 86 | /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/ |
phonemacro | 32:92adfbe18ab6 | 87 | //#define RAW // define this if you want AFE+accel data, no algorithm |
phonemacro | 30:77a30ea425da | 88 | #define ALGO_ONLY 1 // define this if you only want algo data, comment out if you want raw sensor+algo data |
phonemacro | 30:77a30ea425da | 89 | //#define EXTENDED_ALGO 1 // define this if you want the extended algo format |
phonemacro | 13:1baccc6275a7 | 90 | //#define AGC 1 // define this for AGC, otherwise the default is AEC |
phonemacro | 6:e1b7190d6cb5 | 91 | |
phonemacro | 6:e1b7190d6cb5 | 92 | #ifdef MAXREFDES103_CFG |
phonemacro | 5:7f5a012747a5 | 93 | #include "MAX20303.h" |
phonemacro | 6:e1b7190d6cb5 | 94 | I2C sh_i2c_pmic(P5_7, P6_0); |
phonemacro | 5:7f5a012747a5 | 95 | #endif |
phonemacro | 5:7f5a012747a5 | 96 | |
phonemacro | 32:92adfbe18ab6 | 97 | #ifdef MAXM86146_CFG |
phonemacro | 32:92adfbe18ab6 | 98 | #define PPG_SZ 36 //maxm86146 |
phonemacro | 32:92adfbe18ab6 | 99 | #else |
phonemacro | 32:92adfbe18ab6 | 100 | #define PPG_SZ 18 //maxm86161, max86141 |
phonemacro | 32:92adfbe18ab6 | 101 | #endif |
phonemacro | 32:92adfbe18ab6 | 102 | #define ACCEL_SZ 6 // accel |
phonemacro | 32:92adfbe18ab6 | 103 | #define SENSOR_SZ (PPG_SZ+ACCEL_SZ) |
phonemacro | 32:92adfbe18ab6 | 104 | |
phonemacro | 32:92adfbe18ab6 | 105 | #if defined(MAXM86161_CFG) || defined(MAXM86146_CFG) // MAXM86161, MAXM86146, keep algo Fifo size as 52, 20 to keep compatible w/ the GUI |
phonemacro | 28:315604f4b374 | 106 | #define old_msbl 1 // 3x.12.0 or earlier; 32.9.x |
phonemacro | 28:315604f4b374 | 107 | #endif |
phonemacro | 30:77a30ea425da | 108 | |
phonemacro | 18:f4c95b1c0efc | 109 | #ifdef old_msbl |
phonemacro | 18:f4c95b1c0efc | 110 | #ifdef EXTENDED_ALGO |
phonemacro | 18:f4c95b1c0efc | 111 | #define ALGO_SZ 52 // 52 bytes is the extended algo size for 3x.12.0 |
phonemacro | 18:f4c95b1c0efc | 112 | #else |
phonemacro | 18:f4c95b1c0efc | 113 | #define ALGO_SZ 20 // 20 bytes is the algo normal size for 3x.12.0 |
phonemacro | 18:f4c95b1c0efc | 114 | #endif |
phonemacro | 12:17a0bf823462 | 115 | #else |
phonemacro | 18:f4c95b1c0efc | 116 | #ifdef EXTENDED_ALGO |
phonemacro | 21:67d58af1ec56 | 117 | #define ALGO_SZ 56 // 56 bytes is the extended algo size for 3x.13.x+ |
phonemacro | 18:f4c95b1c0efc | 118 | #else |
phonemacro | 21:67d58af1ec56 | 119 | #define ALGO_SZ 24 // 24 bytes is the algo normal size for 3x.13.x+ |
phonemacro | 18:f4c95b1c0efc | 120 | #endif |
phonemacro | 12:17a0bf823462 | 121 | #endif |
phonemacro | 18:f4c95b1c0efc | 122 | |
phonemacro | 0:6f65cae31c54 | 123 | #ifdef ALGO_ONLY |
phonemacro | 0:6f65cae31c54 | 124 | #define TTL_SZ (ALGO_SZ) |
phonemacro | 0:6f65cae31c54 | 125 | #else |
phonemacro | 14:c8cc6d7fd5f9 | 126 | #ifdef RAW |
phonemacro | 14:c8cc6d7fd5f9 | 127 | #define TTL_SZ (PPG_SZ+ACCEL_SZ) |
phonemacro | 14:c8cc6d7fd5f9 | 128 | #else |
phonemacro | 14:c8cc6d7fd5f9 | 129 | #define TTL_SZ (PPG_SZ+ACCEL_SZ+ALGO_SZ) |
phonemacro | 14:c8cc6d7fd5f9 | 130 | #endif |
phonemacro | 0:6f65cae31c54 | 131 | #endif |
phonemacro | 0:6f65cae31c54 | 132 | |
phonemacro | 3:da975696b936 | 133 | Serial pc(USBTX, USBRX, 115200); |
phonemacro | 0:6f65cae31c54 | 134 | DigitalOut rLED(LED1); |
phonemacro | 0:6f65cae31c54 | 135 | DigitalOut gLED(LED2); |
phonemacro | 0:6f65cae31c54 | 136 | DigitalOut bLED(LED3); |
phonemacro | 6:e1b7190d6cb5 | 137 | |
phonemacro | 6:e1b7190d6cb5 | 138 | //#define thread_sleep_for(x) wait_ms(x) // for older versions of mbed |
phonemacro | 0:6f65cae31c54 | 139 | |
phonemacro | 5:7f5a012747a5 | 140 | |
phonemacro | 6:e1b7190d6cb5 | 141 | const int SH_ADDR = 0xAA;//0x55; |
phonemacro | 0:6f65cae31c54 | 142 | int32_t Time_to_Read_PPG = 0; |
phonemacro | 0:6f65cae31c54 | 143 | |
phonemacro | 0:6f65cae31c54 | 144 | #define BLINKING_RATE_MS 1000ms |
phonemacro | 0:6f65cae31c54 | 145 | void blink_timer(void) { |
phonemacro | 0:6f65cae31c54 | 146 | gLED = !gLED; /* blink the green LED */ |
phonemacro | 0:6f65cae31c54 | 147 | } |
phonemacro | 0:6f65cae31c54 | 148 | |
phonemacro | 0:6f65cae31c54 | 149 | void fifo_timer(void) { |
phonemacro | 0:6f65cae31c54 | 150 | Time_to_Read_PPG = 1; |
phonemacro | 0:6f65cae31c54 | 151 | } |
phonemacro | 0:6f65cae31c54 | 152 | |
phonemacro | 14:c8cc6d7fd5f9 | 153 | /*****************************************************************************/ |
phonemacro | 14:c8cc6d7fd5f9 | 154 | // read_sh_fifo |
phonemacro | 14:c8cc6d7fd5f9 | 155 | /*****************************************************************************/ |
phonemacro | 27:a45d6e38f2de | 156 | /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/ |
phonemacro | 28:315604f4b374 | 157 | #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 | 158 | #ifdef OPTIMIZE_FIFO_READ // tested on MAXM86146EVSYS |
phonemacro | 27:a45d6e38f2de | 159 | int32_t check_fifo_countdown; |
phonemacro | 27:a45d6e38f2de | 160 | #define MAX_FIFO_CNT 20 |
phonemacro | 27:a45d6e38f2de | 161 | #endif |
phonemacro | 10:192ea88e964b | 162 | void read_sh_fifo(void) { |
phonemacro | 0:6f65cae31c54 | 163 | char cmd[8], i, j, samples; |
phonemacro | 0:6f65cae31c54 | 164 | char rsp[3000]; |
phonemacro | 0:6f65cae31c54 | 165 | int32_t ppg[12]; |
phonemacro | 5:7f5a012747a5 | 166 | int16_t accel[3]; |
phonemacro | 12:17a0bf823462 | 167 | int32_t status, opmode, hr, hr_conf, ibi, ibi_conf; |
phonemacro | 12:17a0bf823462 | 168 | #ifdef EXTENDED_ALGO |
phonemacro | 12:17a0bf823462 | 169 | int32_t walk_stp, run_stp, energy, amr, iadj1_rqt, iadj1, iadj2_rqt, iadj2, iadj3_rqt, iadj3; |
phonemacro | 12:17a0bf823462 | 170 | int32_t intadj_rqt, intadj, smpladj_rqt, smpladj, rqt_smplave, afestatehr, hr_motion; |
phonemacro | 12:17a0bf823462 | 171 | #endif |
phonemacro | 12:17a0bf823462 | 172 | int32_t act, r, spo2, spo2_conf; |
phonemacro | 4:4f1e9439f048 | 173 | int32_t spo2_compl, spo2_lo, spo2_mo, spo2_lopi, spo2_unrel, spo2_state, ibi_offset, scd; |
phonemacro | 2:563d90a111b3 | 174 | int32_t scnt = 0; |
phonemacro | 0:6f65cae31c54 | 175 | int32_t ptr = 0; |
phonemacro | 0:6f65cae31c54 | 176 | int32_t sptr = 0; |
phonemacro | 1:da792e46a385 | 177 | mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 178 | Time_to_Read_PPG = 0; |
phonemacro | 27:a45d6e38f2de | 179 | #if defined(OPTIMIZE_FIFO_READ) |
phonemacro | 27:a45d6e38f2de | 180 | check_fifo_countdown--; |
phonemacro | 27:a45d6e38f2de | 181 | samples = 1; |
phonemacro | 27:a45d6e38f2de | 182 | scnt = 1; |
phonemacro | 27:a45d6e38f2de | 183 | if (check_fifo_countdown == 0) { |
phonemacro | 27:a45d6e38f2de | 184 | #endif |
phonemacro | 27:a45d6e38f2de | 185 | |
phonemacro | 22:f6b366c3b954 | 186 | #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG) |
phonemacro | 0:6f65cae31c54 | 187 | // 2.1 |
phonemacro | 27:a45d6e38f2de | 188 | cmd[0] = 0x00; cmd[1] = 0x00; |
phonemacro | 27:a45d6e38f2de | 189 | sh_i2c.write(SH_ADDR, cmd, 2); |
phonemacro | 27:a45d6e38f2de | 190 | wait_us(100); |
phonemacro | 27:a45d6e38f2de | 191 | sh_i2c.read(SH_ADDR, rsp, 2); |
phonemacro | 27:a45d6e38f2de | 192 | // pc.printf("2.1 Status: %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 22:f6b366c3b954 | 193 | #else |
phonemacro | 22:f6b366c3b954 | 194 | // testd 33.13.12 doesn't need 2.1 |
phonemacro | 0:6f65cae31c54 | 195 | #endif |
phonemacro | 0:6f65cae31c54 | 196 | // 2.2 |
phonemacro | 27:a45d6e38f2de | 197 | cmd[0] = 0x12; cmd[1] = 0x00; |
phonemacro | 27:a45d6e38f2de | 198 | sh_i2c.write(SH_ADDR, cmd, 2); |
phonemacro | 27:a45d6e38f2de | 199 | wait_us(100); |
phonemacro | 27:a45d6e38f2de | 200 | sh_i2c.read(SH_ADDR, rsp, 2); |
phonemacro | 27:a45d6e38f2de | 201 | // pc.printf("2.2 Status: %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 27:a45d6e38f2de | 202 | samples = rsp[1]; |
phonemacro | 27:a45d6e38f2de | 203 | // pc.printf("num samples %d, (num*ttl)+1 %d\n\r", rsp[1], TTL_SZ*samples+1); |
phonemacro | 27:a45d6e38f2de | 204 | // pc.printf("num smpls %d \n\r", samples); |
phonemacro | 27:a45d6e38f2de | 205 | scnt = rsp[1]; |
phonemacro | 27:a45d6e38f2de | 206 | #if defined(OPTIMIZE_FIFO_READ) |
phonemacro | 27:a45d6e38f2de | 207 | } |
phonemacro | 27:a45d6e38f2de | 208 | if (check_fifo_countdown <= 0) |
phonemacro | 27:a45d6e38f2de | 209 | check_fifo_countdown = MAX_FIFO_CNT; |
phonemacro | 27:a45d6e38f2de | 210 | #endif |
phonemacro | 27:a45d6e38f2de | 211 | |
phonemacro | 0:6f65cae31c54 | 212 | // 2.3 |
phonemacro | 4:4f1e9439f048 | 213 | cmd[0] = 0x12; cmd[1] = 0x01; |
phonemacro | 6:e1b7190d6cb5 | 214 | sh_i2c.write(SH_ADDR, cmd, 2); |
phonemacro | 22:f6b366c3b954 | 215 | wait_us(100); |
phonemacro | 6:e1b7190d6cb5 | 216 | sh_i2c.read(SH_ADDR, rsp, 1+(TTL_SZ*samples)); |
phonemacro | 22:f6b366c3b954 | 217 | mfio = 1; |
phonemacro | 21:67d58af1ec56 | 218 | |
phonemacro | 0:6f65cae31c54 | 219 | status = rsp[0]; |
phonemacro | 5:7f5a012747a5 | 220 | |
phonemacro | 0:6f65cae31c54 | 221 | sptr = 1; |
phonemacro | 0:6f65cae31c54 | 222 | for (i = 0; i < scnt; i++) { |
phonemacro | 0:6f65cae31c54 | 223 | #ifdef ALGO_ONLY |
phonemacro | 0:6f65cae31c54 | 224 | ptr = sptr; |
phonemacro | 0:6f65cae31c54 | 225 | #else |
phonemacro | 2:563d90a111b3 | 226 | ptr = sptr; |
phonemacro | 2:563d90a111b3 | 227 | ppg[0] = (rsp[ptr+0] << 16) | (rsp[ptr+1] << 8) | (rsp[ptr+2]); |
phonemacro | 2:563d90a111b3 | 228 | ppg[1] = (rsp[ptr+3] << 16) | (rsp[ptr+4] << 8) | (rsp[ptr+5]); |
phonemacro | 2:563d90a111b3 | 229 | ppg[2] = (rsp[ptr+6] << 16) | (rsp[ptr+7] << 8) | (rsp[ptr+8]); |
phonemacro | 3:da975696b936 | 230 | ppg[3] = (rsp[ptr+9] << 16) | (rsp[ptr+10] << 8) | (rsp[ptr+11]); |
phonemacro | 4:4f1e9439f048 | 231 | ppg[4] = (rsp[ptr+12] << 16) | (rsp[ptr+13] << 8) | (rsp[ptr+14]); |
phonemacro | 4:4f1e9439f048 | 232 | ppg[5] = (rsp[ptr+15] << 16) | (rsp[ptr+16] << 8) | (rsp[ptr+17]); |
phonemacro | 3:da975696b936 | 233 | pc.printf("%d,%d,%d,%d,", ppg[0], ppg[1], ppg[2], ppg[3]); |
phonemacro | 14:c8cc6d7fd5f9 | 234 | #ifdef MAXM86146_CFG |
phonemacro | 32:92adfbe18ab6 | 235 | #ifdef RAW |
phonemacro | 14:c8cc6d7fd5f9 | 236 | pc.printf("%d,%d,", ppg[4], ppg[5]); |
phonemacro | 14:c8cc6d7fd5f9 | 237 | ppg[6] = (rsp[ptr+18] << 16) | (rsp[ptr+19] << 8) | (rsp[ptr+20]); |
phonemacro | 14:c8cc6d7fd5f9 | 238 | ppg[7] = (rsp[ptr+21] << 16) | (rsp[ptr+22] << 8) | (rsp[ptr+23]); |
phonemacro | 14:c8cc6d7fd5f9 | 239 | ppg[8] = (rsp[ptr+24] << 16) | (rsp[ptr+25] << 8) | (rsp[ptr+26]); |
phonemacro | 14:c8cc6d7fd5f9 | 240 | ppg[9] = (rsp[ptr+27] << 16) | (rsp[ptr+28] << 8) | (rsp[ptr+29]); |
phonemacro | 14:c8cc6d7fd5f9 | 241 | ppg[10] = (rsp[ptr+30] << 16) | (rsp[ptr+31] << 8) | (rsp[ptr+32]); |
phonemacro | 14:c8cc6d7fd5f9 | 242 | ppg[11] = (rsp[ptr+33] << 16) | (rsp[ptr+34] << 8) | (rsp[ptr+35]); |
phonemacro | 14:c8cc6d7fd5f9 | 243 | pc.printf("%d,%d,%d,%d,%d,%d,", ppg[6], ppg[7],ppg[8], ppg[9],ppg[10], ppg[11]); |
phonemacro | 14:c8cc6d7fd5f9 | 244 | #endif |
phonemacro | 32:92adfbe18ab6 | 245 | #endif |
phonemacro | 5:7f5a012747a5 | 246 | accel[0] = (rsp[PPG_SZ+0] << 8) | (rsp[PPG_SZ+1]); |
phonemacro | 5:7f5a012747a5 | 247 | accel[1] = (rsp[PPG_SZ+2] << 8) | (rsp[PPG_SZ+3]); |
phonemacro | 5:7f5a012747a5 | 248 | accel[2] = (rsp[PPG_SZ+4] << 8) | (rsp[PPG_SZ+5]); |
phonemacro | 5:7f5a012747a5 | 249 | pc.printf("%d,%d,%d,", accel[0], accel[1], accel[2]); |
phonemacro | 5:7f5a012747a5 | 250 | |
phonemacro | 0:6f65cae31c54 | 251 | ptr = sptr + SENSOR_SZ; |
phonemacro | 0:6f65cae31c54 | 252 | #endif |
phonemacro | 29:a7dd81450b35 | 253 | |
phonemacro | 14:c8cc6d7fd5f9 | 254 | #ifndef RAW |
phonemacro | 12:17a0bf823462 | 255 | #ifdef EXTENDED_ALGO |
phonemacro | 3:da975696b936 | 256 | // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ); |
phonemacro | 0:6f65cae31c54 | 257 | opmode = rsp[ptr]; |
phonemacro | 0:6f65cae31c54 | 258 | hr = (rsp[ptr+1] << 8) + rsp[ptr+2]; |
phonemacro | 0:6f65cae31c54 | 259 | hr_conf = rsp[ptr+3]; |
phonemacro | 12:17a0bf823462 | 260 | ibi = (rsp[ptr+4] << 8) + rsp[ptr+5]; |
phonemacro | 12:17a0bf823462 | 261 | |
phonemacro | 12:17a0bf823462 | 262 | ibi_conf = rsp[ptr+6]; |
phonemacro | 12:17a0bf823462 | 263 | act = rsp[ptr+7]; |
phonemacro | 12:17a0bf823462 | 264 | walk_stp = (rsp[ptr+8] << 24) + (rsp[ptr+9] << 16) + (rsp[ptr+10] << 8) + rsp[ptr+11]; |
phonemacro | 12:17a0bf823462 | 265 | run_stp = (rsp[ptr+12] << 24) + (rsp[ptr+13] << 16) + (rsp[ptr+14] << 8) + rsp[ptr+15]; |
phonemacro | 12:17a0bf823462 | 266 | |
phonemacro | 12:17a0bf823462 | 267 | energy = (rsp[ptr+16] << 24) + (rsp[ptr+17] << 16) + (rsp[ptr+18] << 8) + rsp[ptr+19]; |
phonemacro | 12:17a0bf823462 | 268 | amr = (rsp[ptr+20] << 24) + (rsp[ptr+21] << 16) + (rsp[ptr+22] << 8) + rsp[ptr+23]; |
phonemacro | 12:17a0bf823462 | 269 | iadj1_rqt = rsp[ptr+24]; |
phonemacro | 12:17a0bf823462 | 270 | iadj1 = (rsp[ptr+25] << 8) + rsp[ptr+26]; |
phonemacro | 12:17a0bf823462 | 271 | |
phonemacro | 12:17a0bf823462 | 272 | iadj2_rqt = rsp[ptr+27]; |
phonemacro | 12:17a0bf823462 | 273 | iadj2 = (rsp[ptr+28] << 8) + rsp[ptr+29]; |
phonemacro | 12:17a0bf823462 | 274 | iadj3_rqt = rsp[ptr+30]; |
phonemacro | 12:17a0bf823462 | 275 | iadj3 = (rsp[ptr+31] << 8) + rsp[ptr+32]; |
phonemacro | 12:17a0bf823462 | 276 | |
phonemacro | 12:17a0bf823462 | 277 | intadj_rqt = rsp[ptr+33]; |
phonemacro | 12:17a0bf823462 | 278 | intadj = rsp[ptr+34]; |
phonemacro | 12:17a0bf823462 | 279 | smpladj_rqt = rsp[ptr+35]; |
phonemacro | 12:17a0bf823462 | 280 | smpladj = rsp[ptr+36]; |
phonemacro | 12:17a0bf823462 | 281 | |
phonemacro | 12:17a0bf823462 | 282 | rqt_smplave = rsp[ptr+37]; |
phonemacro | 12:17a0bf823462 | 283 | afestatehr = rsp[ptr+38]; |
phonemacro | 12:17a0bf823462 | 284 | hr_motion = rsp[ptr+39]; |
phonemacro | 12:17a0bf823462 | 285 | scd = rsp[ptr+40]; |
phonemacro | 12:17a0bf823462 | 286 | |
phonemacro | 12:17a0bf823462 | 287 | |
phonemacro | 12:17a0bf823462 | 288 | r = (rsp[ptr+41] << 8) + rsp[ptr+42]; |
phonemacro | 12:17a0bf823462 | 289 | spo2_conf = rsp[ptr+43]; |
phonemacro | 12:17a0bf823462 | 290 | |
phonemacro | 12:17a0bf823462 | 291 | spo2 = (rsp[ptr+44] << 8) + rsp[ptr+45]; |
phonemacro | 12:17a0bf823462 | 292 | spo2_compl = rsp[ptr+46]; |
phonemacro | 12:17a0bf823462 | 293 | spo2_lo = rsp[ptr+47]; |
phonemacro | 12:17a0bf823462 | 294 | spo2_mo = rsp[ptr+48]; |
phonemacro | 12:17a0bf823462 | 295 | |
phonemacro | 12:17a0bf823462 | 296 | spo2_lopi = rsp[ptr+49]; |
phonemacro | 12:17a0bf823462 | 297 | spo2_unrel = rsp[ptr+50]; |
phonemacro | 12:17a0bf823462 | 298 | spo2_state = rsp[ptr+51]; |
phonemacro | 12:17a0bf823462 | 299 | |
phonemacro | 12:17a0bf823462 | 300 | ibi_offset = rsp[ptr+52]; |
phonemacro | 12:17a0bf823462 | 301 | |
phonemacro | 12:17a0bf823462 | 302 | sptr += (TTL_SZ); |
phonemacro | 12:17a0bf823462 | 303 | #if 1 |
phonemacro | 12:17a0bf823462 | 304 | pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi); |
phonemacro | 12:17a0bf823462 | 305 | pc.printf("%d,%d,", ibi_conf, act); |
phonemacro | 12:17a0bf823462 | 306 | pc.printf("%d,%d,%d,", walk_stp, run_stp, energy); |
phonemacro | 12:17a0bf823462 | 307 | pc.printf("%d,%d,%d,%d,", amr, iadj1_rqt, iadj1, iadj2_rqt); |
phonemacro | 12:17a0bf823462 | 308 | pc.printf("%d,%d,%d,%d,", iadj2, iadj3_rqt, iadj3, intadj_rqt); |
phonemacro | 12:17a0bf823462 | 309 | pc.printf("%d,%d,%d,%d,", intadj, smpladj_rqt, smpladj, rqt_smplave); |
phonemacro | 12:17a0bf823462 | 310 | pc.printf("%d,%d,", afestatehr, hr_motion); |
phonemacro | 12:17a0bf823462 | 311 | pc.printf("%d,", scd); |
phonemacro | 12:17a0bf823462 | 312 | pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo); |
phonemacro | 12:17a0bf823462 | 313 | pc.printf("%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state); |
phonemacro | 12:17a0bf823462 | 314 | pc.printf("%d,", ibi_offset); |
phonemacro | 12:17a0bf823462 | 315 | #else |
phonemacro | 12:17a0bf823462 | 316 | pc.printf("%d,%d,", hr, hr_conf); |
phonemacro | 12:17a0bf823462 | 317 | pc.printf("%d,%d,", spo2, spo2_conf); |
phonemacro | 16:ff1122f0624a | 318 | pc.printf("%d,%d,%d,", spo2_lo, spo2_mo, spo2_lopi); |
phonemacro | 12:17a0bf823462 | 319 | pc.printf("%d,%d,", spo2_unrel, scd); |
phonemacro | 12:17a0bf823462 | 320 | #endif |
phonemacro | 12:17a0bf823462 | 321 | #else // normal algo size |
phonemacro | 12:17a0bf823462 | 322 | // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ); |
phonemacro | 12:17a0bf823462 | 323 | opmode = rsp[ptr]; |
phonemacro | 12:17a0bf823462 | 324 | hr = (rsp[ptr+1] << 8) + rsp[ptr+2]; |
phonemacro | 12:17a0bf823462 | 325 | hr_conf = rsp[ptr+3]; |
phonemacro | 12:17a0bf823462 | 326 | ibi = (rsp[ptr+4] << 8) + rsp[ptr+5]; |
phonemacro | 4:4f1e9439f048 | 327 | |
phonemacro | 11:a16b6bf38841 | 328 | ibi_conf = rsp[ptr+6]; |
phonemacro | 3:da975696b936 | 329 | act = rsp[ptr+7]; |
phonemacro | 3:da975696b936 | 330 | r = (rsp[ptr+8] << 8) + rsp[ptr+9]; |
phonemacro | 0:6f65cae31c54 | 331 | spo2_conf = rsp[ptr+10]; |
phonemacro | 4:4f1e9439f048 | 332 | |
phonemacro | 0:6f65cae31c54 | 333 | spo2 = (rsp[ptr+11] << 8) + rsp[ptr+12]; |
phonemacro | 4:4f1e9439f048 | 334 | spo2_compl = rsp[ptr+13]; |
phonemacro | 4:4f1e9439f048 | 335 | spo2_lo = rsp[ptr+14]; |
phonemacro | 4:4f1e9439f048 | 336 | spo2_mo = rsp[ptr+15]; |
phonemacro | 4:4f1e9439f048 | 337 | |
phonemacro | 4:4f1e9439f048 | 338 | spo2_lopi = rsp[ptr+16]; |
phonemacro | 4:4f1e9439f048 | 339 | spo2_unrel = rsp[ptr+17]; |
phonemacro | 4:4f1e9439f048 | 340 | spo2_state = rsp[ptr+18]; |
phonemacro | 2:563d90a111b3 | 341 | scd = rsp[ptr+19]; |
phonemacro | 0:6f65cae31c54 | 342 | |
phonemacro | 4:4f1e9439f048 | 343 | ibi_offset = rsp[ptr+20]; |
phonemacro | 0:6f65cae31c54 | 344 | |
phonemacro | 4:4f1e9439f048 | 345 | sptr += (TTL_SZ); |
phonemacro | 27:a45d6e38f2de | 346 | #if 0 |
phonemacro | 4:4f1e9439f048 | 347 | pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi); |
phonemacro | 4:4f1e9439f048 | 348 | pc.printf("%d,%d,%d,%d,", ibi_conf, act, r, spo2_conf); |
phonemacro | 4:4f1e9439f048 | 349 | pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo); |
phonemacro | 4:4f1e9439f048 | 350 | pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state, scd); |
phonemacro | 4:4f1e9439f048 | 351 | pc.printf("%d,", ibi_offset); |
phonemacro | 4:4f1e9439f048 | 352 | #else |
phonemacro | 4:4f1e9439f048 | 353 | pc.printf("%d,%d,", hr, hr_conf); |
phonemacro | 4:4f1e9439f048 | 354 | pc.printf("%d,%d,", spo2, spo2_conf); |
phonemacro | 4:4f1e9439f048 | 355 | pc.printf("%d,", spo2_lo); |
phonemacro | 4:4f1e9439f048 | 356 | pc.printf("%d,%d,", spo2_unrel, scd); |
phonemacro | 4:4f1e9439f048 | 357 | #endif |
phonemacro | 12:17a0bf823462 | 358 | #endif // end normal algo size |
phonemacro | 14:c8cc6d7fd5f9 | 359 | #endif // !RAW |
phonemacro | 4:4f1e9439f048 | 360 | |
phonemacro | 3:da975696b936 | 361 | pc.printf("\n\r"); |
phonemacro | 0:6f65cae31c54 | 362 | } |
phonemacro | 0:6f65cae31c54 | 363 | } |
phonemacro | 0:6f65cae31c54 | 364 | |
phonemacro | 6:e1b7190d6cb5 | 365 | #ifdef MAXREFDES103_CFG |
phonemacro | 14:c8cc6d7fd5f9 | 366 | /*****************************************************************************/ |
phonemacro | 14:c8cc6d7fd5f9 | 367 | // init_max20303_pmic |
phonemacro | 14:c8cc6d7fd5f9 | 368 | /*****************************************************************************/ |
phonemacro | 6:e1b7190d6cb5 | 369 | void init_max20303_pmic(void) { |
phonemacro | 5:7f5a012747a5 | 370 | /* Wait for pmic to settle down */ |
phonemacro | 5:7f5a012747a5 | 371 | thread_sleep_for(800); |
phonemacro | 5:7f5a012747a5 | 372 | |
phonemacro | 5:7f5a012747a5 | 373 | //set_time(1544787300); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
phonemacro | 6:e1b7190d6cb5 | 374 | MAX20303 max20303(&sh_i2c); |
phonemacro | 5:7f5a012747a5 | 375 | /*Set LDO1 to 1.8v*/ |
phonemacro | 5:7f5a012747a5 | 376 | max20303.LDO1Config(); |
phonemacro | 5:7f5a012747a5 | 377 | |
phonemacro | 5:7f5a012747a5 | 378 | /*Set LDO2 to 3v*/ |
phonemacro | 5:7f5a012747a5 | 379 | max20303.LDO2Config(); |
phonemacro | 5:7f5a012747a5 | 380 | |
phonemacro | 5:7f5a012747a5 | 381 | //max20303.BoostEnable(); |
phonemacro | 5:7f5a012747a5 | 382 | max20303.BuckBoostEnable(); |
phonemacro | 5:7f5a012747a5 | 383 | |
phonemacro | 5:7f5a012747a5 | 384 | max20303.led0on(0); |
phonemacro | 5:7f5a012747a5 | 385 | max20303.led1on(0); |
phonemacro | 5:7f5a012747a5 | 386 | max20303.led2on(0); |
phonemacro | 5:7f5a012747a5 | 387 | |
phonemacro | 5:7f5a012747a5 | 388 | /* Wait for pmic to settle down */ |
phonemacro | 5:7f5a012747a5 | 389 | thread_sleep_for(200); |
phonemacro | 28:315604f4b374 | 390 | |
phonemacro | 5:7f5a012747a5 | 391 | } |
phonemacro | 6:e1b7190d6cb5 | 392 | #endif // MAXREFDES103_CFG |
phonemacro | 14:c8cc6d7fd5f9 | 393 | |
phonemacro | 14:c8cc6d7fd5f9 | 394 | /*****************************************************************************/ |
phonemacro | 14:c8cc6d7fd5f9 | 395 | // init_sh_algo |
phonemacro | 14:c8cc6d7fd5f9 | 396 | /*****************************************************************************/ |
phonemacro | 14:c8cc6d7fd5f9 | 397 | void init_sh_algo(void) { |
phonemacro | 14:c8cc6d7fd5f9 | 398 | char cmd[8]; |
phonemacro | 0:6f65cae31c54 | 399 | char rsp[256]; |
phonemacro | 27:a45d6e38f2de | 400 | |
phonemacro | 27:a45d6e38f2de | 401 | #ifdef OPTIMIZE_FIFO_READ |
phonemacro | 27:a45d6e38f2de | 402 | check_fifo_countdown = MAX_FIFO_CNT; |
phonemacro | 27:a45d6e38f2de | 403 | #endif |
phonemacro | 27:a45d6e38f2de | 404 | |
phonemacro | 10:192ea88e964b | 405 | // switch to application mode |
phonemacro | 0:6f65cae31c54 | 406 | rst = 0; |
phonemacro | 0:6f65cae31c54 | 407 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 408 | thread_sleep_for(10); |
phonemacro | 0:6f65cae31c54 | 409 | rst = 1; |
phonemacro | 0:6f65cae31c54 | 410 | thread_sleep_for(1500); |
phonemacro | 10:192ea88e964b | 411 | #ifdef MAXREFDES103_CFG |
phonemacro | 10:192ea88e964b | 412 | init_max20303_pmic(); |
phonemacro | 10:192ea88e964b | 413 | #endif |
phonemacro | 23:e7ecf1416965 | 414 | #if 0 // 1.5s is ok for 33.13.12 |
phonemacro | 23:e7ecf1416965 | 415 | thread_sleep_for(250); |
phonemacro | 20:7fc26287beb7 | 416 | #endif |
phonemacro | 0:6f65cae31c54 | 417 | |
phonemacro | 1:da792e46a385 | 418 | mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 419 | |
phonemacro | 4:4f1e9439f048 | 420 | //read operating mode |
phonemacro | 4:4f1e9439f048 | 421 | cmd[0] = 0x02; cmd[1] = 0x00; |
phonemacro | 6:e1b7190d6cb5 | 422 | sh_i2c.write(SH_ADDR, cmd, 2); |
phonemacro | 1:da792e46a385 | 423 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 424 | sh_i2c.read(SH_ADDR, rsp, 2); |
phonemacro | 6:e1b7190d6cb5 | 425 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 426 | pc.printf("\n\r 0x02 0x00 Status, Read Operating Mode: %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 32:92adfbe18ab6 | 427 | //1.1 rd ver |
phonemacro | 4:4f1e9439f048 | 428 | cmd[0] = 0xFF; cmd[1] = 0x03; |
phonemacro | 6:e1b7190d6cb5 | 429 | sh_i2c.write(SH_ADDR, cmd, 2); |
phonemacro | 1:da792e46a385 | 430 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 431 | sh_i2c.read(SH_ADDR, rsp, 4); |
phonemacro | 1:da792e46a385 | 432 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 433 | pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]); |
phonemacro | 0:6f65cae31c54 | 434 | |
phonemacro | 28:315604f4b374 | 435 | #if defined(MAXM86161_CFG) |
phonemacro | 28:315604f4b374 | 436 | // algo sz normal |
phonemacro | 17:0d6e99a0fd8d | 437 | cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x01; |
phonemacro | 17:0d6e99a0fd8d | 438 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 17:0d6e99a0fd8d | 439 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 17:0d6e99a0fd8d | 440 | sh_i2c.read(SH_ADDR, rsp, 2); |
phonemacro | 17:0d6e99a0fd8d | 441 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 17:0d6e99a0fd8d | 442 | pc.printf("algo size: %d %d \n\r", rsp[0], rsp[1]); |
phonemacro | 17:0d6e99a0fd8d | 443 | |
phonemacro | 28:315604f4b374 | 444 | // algo sz extended |
phonemacro | 17:0d6e99a0fd8d | 445 | cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x02; |
phonemacro | 17:0d6e99a0fd8d | 446 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 17:0d6e99a0fd8d | 447 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 17:0d6e99a0fd8d | 448 | sh_i2c.read(SH_ADDR, rsp, 2); |
phonemacro | 17:0d6e99a0fd8d | 449 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 17:0d6e99a0fd8d | 450 | pc.printf("algo size: %d %d \n\r", rsp[0], rsp[1]); |
phonemacro | 17:0d6e99a0fd8d | 451 | |
phonemacro | 28:315604f4b374 | 452 | // algo sz scd |
phonemacro | 17:0d6e99a0fd8d | 453 | cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x03; |
phonemacro | 17:0d6e99a0fd8d | 454 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 17:0d6e99a0fd8d | 455 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 17:0d6e99a0fd8d | 456 | sh_i2c.read(SH_ADDR, rsp, 2); |
phonemacro | 17:0d6e99a0fd8d | 457 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 17:0d6e99a0fd8d | 458 | pc.printf("algo size: %d %d \n\r", rsp[0], rsp[1]); |
phonemacro | 17:0d6e99a0fd8d | 459 | #endif |
phonemacro | 17:0d6e99a0fd8d | 460 | |
phonemacro | 17:0d6e99a0fd8d | 461 | #if 0 |
phonemacro | 17:0d6e99a0fd8d | 462 | // set Perfusion Index threshold to .05 (3x.13.19+) |
phonemacro | 17:0d6e99a0fd8d | 463 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x1D; cmd[3] = 50; |
phonemacro | 16:ff1122f0624a | 464 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 16:ff1122f0624a | 465 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 16:ff1122f0624a | 466 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 16:ff1122f0624a | 467 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 16:ff1122f0624a | 468 | pc.printf("pi set to 0x19 : %x \n\r", rsp[0]); |
phonemacro | 17:0d6e99a0fd8d | 469 | #endif |
phonemacro | 16:ff1122f0624a | 470 | |
phonemacro | 32:92adfbe18ab6 | 471 | // 1.2 sensor and algo data |
phonemacro | 4:4f1e9439f048 | 472 | cmd[0] = 0x10; cmd[1] = 0x00; |
phonemacro | 2:563d90a111b3 | 473 | #ifdef ALGO_ONLY |
phonemacro | 0:6f65cae31c54 | 474 | cmd[2] = 0x02; // algo data |
phonemacro | 4:4f1e9439f048 | 475 | pc.printf("algo only \n\r"); |
phonemacro | 2:563d90a111b3 | 476 | #else |
phonemacro | 2:563d90a111b3 | 477 | cmd[2] = 0x03; // sensor + algo data |
phonemacro | 4:4f1e9439f048 | 478 | pc.printf("sens+algo \n\r"); |
phonemacro | 2:563d90a111b3 | 479 | #endif |
phonemacro | 6:e1b7190d6cb5 | 480 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 1:da792e46a385 | 481 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 482 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 1:da792e46a385 | 483 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 484 | pc.printf("1.2 Status: %x\n\r", rsp[0]); |
phonemacro | 32:92adfbe18ab6 | 485 | // 1.5 cont hr, spo2 |
phonemacro | 32:92adfbe18ab6 | 486 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0A; cmd[3] = 0x00; |
phonemacro | 32:92adfbe18ab6 | 487 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 32:92adfbe18ab6 | 488 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 489 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 32:92adfbe18ab6 | 490 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 491 | pc.printf("1.5 Status: %x\n\r", rsp[0]); |
phonemacro | 32:92adfbe18ab6 | 492 | // 1.6 AEC enable (default) |
phonemacro | 4:4f1e9439f048 | 493 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0B; cmd[3] = 0x01; |
phonemacro | 6:e1b7190d6cb5 | 494 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 1:da792e46a385 | 495 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 496 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 1:da792e46a385 | 497 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 498 | pc.printf("1.6 Status: %x\n\r", rsp[0]); |
phonemacro | 13:1baccc6275a7 | 499 | #if AGC |
phonemacro | 32:92adfbe18ab6 | 500 | // AGC1.7 Disable auto PD (default |
phonemacro | 13:1baccc6275a7 | 501 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x12; cmd[3] = 0x00; |
phonemacro | 13:1baccc6275a7 | 502 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 13:1baccc6275a7 | 503 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 13:1baccc6275a7 | 504 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 13:1baccc6275a7 | 505 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 506 | pc.printf("AGC1.7 Status: %x\n\r", rsp[0]); |
phonemacro | 32:92adfbe18ab6 | 507 | // AGC1.8 Disable SCD (default) |
phonemacro | 13:1baccc6275a7 | 508 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0C; cmd[3] = 0x00; |
phonemacro | 13:1baccc6275a7 | 509 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 13:1baccc6275a7 | 510 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 13:1baccc6275a7 | 511 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 13:1baccc6275a7 | 512 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 513 | pc.printf("AGC1.8 Status: %x\n\r", rsp[0]); |
phonemacro | 32:92adfbe18ab6 | 514 | // AGC1.9 Set AGC target PD TO 10uA |
phonemacro | 13:1baccc6275a7 | 515 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x11; cmd[3] = 0x00; cmd[3] = 0x64; |
phonemacro | 13:1baccc6275a7 | 516 | sh_i2c.write(SH_ADDR, cmd, 5); |
phonemacro | 13:1baccc6275a7 | 517 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 13:1baccc6275a7 | 518 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 13:1baccc6275a7 | 519 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 520 | pc.printf("AGC1.9 Status: %x\n\r", rsp[0]); |
phonemacro | 13:1baccc6275a7 | 521 | #else |
phonemacro | 32:92adfbe18ab6 | 522 | // 1.7 auto PD (default |
phonemacro | 4:4f1e9439f048 | 523 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x12; cmd[3] = 0x01; |
phonemacro | 6:e1b7190d6cb5 | 524 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 1:da792e46a385 | 525 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 526 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 1:da792e46a385 | 527 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 528 | pc.printf("1.7 Status: %x\n\r", rsp[0]); |
phonemacro | 32:92adfbe18ab6 | 529 | // 1.8 SCD (default) |
phonemacro | 4:4f1e9439f048 | 530 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0C; cmd[3] = 0x01; |
phonemacro | 6:e1b7190d6cb5 | 531 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 4:4f1e9439f048 | 532 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 533 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 4:4f1e9439f048 | 534 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 535 | pc.printf("1.8 Status: %x\n\r", rsp[0]); |
phonemacro | 13:1baccc6275a7 | 536 | #endif |
phonemacro | 28:315604f4b374 | 537 | |
phonemacro | 28:315604f4b374 | 538 | #if defined(MAXM86161_CFG) //only use Red and IR |
phonemacro | 32:92adfbe18ab6 | 539 | //1.20 map leds to slots |
phonemacro | 28:315604f4b374 | 540 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x23; cmd[4] = 0x00; cmd[5] = 0x00; |
phonemacro | 28:315604f4b374 | 541 | sh_i2c.write(SH_ADDR, cmd, 6); |
phonemacro | 28:315604f4b374 | 542 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 28:315604f4b374 | 543 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 28:315604f4b374 | 544 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 28:315604f4b374 | 545 | pc.printf("map leds to slots %x\n\r", rsp[0]); |
phonemacro | 30:77a30ea425da | 546 | //1.21 map HR inputs to slots, default is 0x0073 for MAXM86161 |
phonemacro | 30:77a30ea425da | 547 | #if 0 // NA for MAXM86161 |
phonemacro | 28:315604f4b374 | 548 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x73; |
phonemacro | 28:315604f4b374 | 549 | sh_i2c.write(SH_ADDR, cmd, 5); |
phonemacro | 28:315604f4b374 | 550 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 28:315604f4b374 | 551 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 28:315604f4b374 | 552 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 28:315604f4b374 | 553 | pc.printf("map HR to slots/PDs %x\n\r", rsp[0]); |
phonemacro | 30:77a30ea425da | 554 | #endif |
phonemacro | 28:315604f4b374 | 555 | //1.22 map SpO2 inputs to slots |
phonemacro | 28:315604f4b374 | 556 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x00; cmd[4] = 0x10; |
phonemacro | 28:315604f4b374 | 557 | sh_i2c.write(SH_ADDR, cmd, 5); |
phonemacro | 28:315604f4b374 | 558 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 28:315604f4b374 | 559 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 28:315604f4b374 | 560 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 28:315604f4b374 | 561 | pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]); |
phonemacro | 28:315604f4b374 | 562 | #endif |
phonemacro | 28:315604f4b374 | 563 | |
phonemacro | 3:da975696b936 | 564 | #ifdef MAXM86146_CFG |
phonemacro | 32:92adfbe18ab6 | 565 | //1.20 map leds to slots for MAXM86146 |
phonemacro | 4:4f1e9439f048 | 566 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x13; cmd[4] = 0x56; cmd[5] = 0x00; |
phonemacro | 6:e1b7190d6cb5 | 567 | sh_i2c.write(SH_ADDR, cmd, 6); |
phonemacro | 3:da975696b936 | 568 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 569 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 3:da975696b936 | 570 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 571 | pc.printf("map leds to slots %x\n\r", rsp[0]); |
phonemacro | 3:da975696b936 | 572 | //1.21 map HR inputs to slots |
phonemacro | 4:4f1e9439f048 | 573 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x11; |
phonemacro | 6:e1b7190d6cb5 | 574 | sh_i2c.write(SH_ADDR, cmd, 5); |
phonemacro | 3:da975696b936 | 575 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 576 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 3:da975696b936 | 577 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 578 | pc.printf("map HR to slots/PDs %x\n\r", rsp[0]); |
phonemacro | 3:da975696b936 | 579 | //1.22 map SpO2 inputs to slots |
phonemacro | 4:4f1e9439f048 | 580 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x30; cmd[4] = 0x20; |
phonemacro | 6:e1b7190d6cb5 | 581 | sh_i2c.write(SH_ADDR, cmd, 5); |
phonemacro | 3:da975696b936 | 582 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 583 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 3:da975696b936 | 584 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 585 | pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]); |
phonemacro | 26:33c0d3fd2a95 | 586 | |
phonemacro | 3:da975696b936 | 587 | #if 0 |
phonemacro | 2:563d90a111b3 | 588 | //1.20 Sec 4.1 map leds to slots for MAXM86146 |
phonemacro | 4:4f1e9439f048 | 589 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x15; cmd[4] = 0x60; cmd[5] = 0x00; |
phonemacro | 6:e1b7190d6cb5 | 590 | sh_i2c.write(SH_ADDR, cmd, 6); |
phonemacro | 1:da792e46a385 | 591 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 592 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 1:da792e46a385 | 593 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 594 | pc.printf("map leds to slots%x\n\r", rsp[0]); |
phonemacro | 2:563d90a111b3 | 595 | //1.21 map HR inputs to slots |
phonemacro | 4:4f1e9439f048 | 596 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x01; |
phonemacro | 6:e1b7190d6cb5 | 597 | sh_i2c.write(SH_ADDR, cmd, 5); |
phonemacro | 1:da792e46a385 | 598 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 599 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 1:da792e46a385 | 600 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 601 | pc.printf("map HR to slots/PDs %x\n\r", rsp[0]); |
phonemacro | 2:563d90a111b3 | 602 | //1.22 map SpO2 inputs to slots |
phonemacro | 4:4f1e9439f048 | 603 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x20; cmd[4] = 0x10; |
phonemacro | 6:e1b7190d6cb5 | 604 | sh_i2c.write(SH_ADDR, cmd, 5); |
phonemacro | 1:da792e46a385 | 605 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 606 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 1:da792e46a385 | 607 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 608 | pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]); |
phonemacro | 3:da975696b936 | 609 | #endif |
phonemacro | 3:da975696b936 | 610 | #endif // MAXM86146_CFG |
phonemacro | 0:6f65cae31c54 | 611 | |
phonemacro | 28:315604f4b374 | 612 | #if 0 // MAXM86161 test new commands |
phonemacro | 28:315604f4b374 | 613 | // LDO enable |
phonemacro | 28:315604f4b374 | 614 | cmd[0] = 0x10; cmd[1] = 0x12; cmd[2] = 0x01; |
phonemacro | 28:315604f4b374 | 615 | //cmd[0] = 0x10; cmd[1] = 0x12; cmd[2] = 0x00; |
phonemacro | 28:315604f4b374 | 616 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 28:315604f4b374 | 617 | thread_sleep_for(2); |
phonemacro | 28:315604f4b374 | 618 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 28:315604f4b374 | 619 | pc.printf("\n\r ldo en %x\n\r", rsp[0]); |
phonemacro | 28:315604f4b374 | 620 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 28:315604f4b374 | 621 | // GPIO enable |
phonemacro | 28:315604f4b374 | 622 | cmd[0] = 0x10; cmd[1] = 0x13; cmd[2] = 0x01; |
phonemacro | 28:315604f4b374 | 623 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 28:315604f4b374 | 624 | thread_sleep_for(2); |
phonemacro | 28:315604f4b374 | 625 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 28:315604f4b374 | 626 | pc.printf("\n\r gpio en %x\n\r", rsp[0]); |
phonemacro | 28:315604f4b374 | 627 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 28:315604f4b374 | 628 | #endif |
phonemacro | 28:315604f4b374 | 629 | |
phonemacro | 32:92adfbe18ab6 | 630 | // 1.30 Enable HR, SpO2 algo |
phonemacro | 12:17a0bf823462 | 631 | #ifdef EXTENDED_ALGO |
phonemacro | 12:17a0bf823462 | 632 | cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x02; |
phonemacro | 12:17a0bf823462 | 633 | #else |
phonemacro | 4:4f1e9439f048 | 634 | cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x01; |
phonemacro | 12:17a0bf823462 | 635 | #endif |
phonemacro | 6:e1b7190d6cb5 | 636 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 28:315604f4b374 | 637 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 638 | thread_sleep_for(465); |
phonemacro | 28:315604f4b374 | 639 | mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 640 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 3:da975696b936 | 641 | pc.printf("1.14 status: %x\n\r", rsp[0]); |
phonemacro | 0:6f65cae31c54 | 642 | |
phonemacro | 4:4f1e9439f048 | 643 | #if 1 |
phonemacro | 4:4f1e9439f048 | 644 | //1.31 rd AFE part id |
phonemacro | 4:4f1e9439f048 | 645 | cmd[0] = 0x41; cmd[1] = 0x00; cmd[2] = 0xFF; |
phonemacro | 6:e1b7190d6cb5 | 646 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 4:4f1e9439f048 | 647 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 648 | sh_i2c.read(SH_ADDR, rsp, 2); |
phonemacro | 4:4f1e9439f048 | 649 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 650 | pc.printf("1.31 part id afe %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 4:4f1e9439f048 | 651 | //1.32 rd accel who |
phonemacro | 4:4f1e9439f048 | 652 | cmd[0] = 0x41; cmd[1] = 0x04; cmd[2] = 0x0F; |
phonemacro | 6:e1b7190d6cb5 | 653 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 4:4f1e9439f048 | 654 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 655 | sh_i2c.read(SH_ADDR, rsp, 2); |
phonemacro | 4:4f1e9439f048 | 656 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 657 | pc.printf("1.32 who accel %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 28:315604f4b374 | 658 | #endif |
phonemacro | 26:33c0d3fd2a95 | 659 | mfio = 1; |
phonemacro | 10:192ea88e964b | 660 | } |
phonemacro | 10:192ea88e964b | 661 | |
phonemacro | 14:c8cc6d7fd5f9 | 662 | /*****************************************************************************/ |
phonemacro | 14:c8cc6d7fd5f9 | 663 | // init_sh_raw |
phonemacro | 14:c8cc6d7fd5f9 | 664 | /*****************************************************************************/ |
phonemacro | 14:c8cc6d7fd5f9 | 665 | void init_sh_raw(void) { |
phonemacro | 29:a7dd81450b35 | 666 | char cmd[16]; |
phonemacro | 14:c8cc6d7fd5f9 | 667 | char rsp[256]; |
phonemacro | 14:c8cc6d7fd5f9 | 668 | // switch to application mode |
phonemacro | 14:c8cc6d7fd5f9 | 669 | rst = 0; |
phonemacro | 14:c8cc6d7fd5f9 | 670 | mfio = 1; |
phonemacro | 14:c8cc6d7fd5f9 | 671 | thread_sleep_for(10); |
phonemacro | 14:c8cc6d7fd5f9 | 672 | rst = 1; |
phonemacro | 14:c8cc6d7fd5f9 | 673 | thread_sleep_for(1500); |
phonemacro | 14:c8cc6d7fd5f9 | 674 | #ifdef MAXREFDES103_CFG |
phonemacro | 14:c8cc6d7fd5f9 | 675 | init_max20303_pmic(); |
phonemacro | 14:c8cc6d7fd5f9 | 676 | #endif |
phonemacro | 14:c8cc6d7fd5f9 | 677 | |
phonemacro | 14:c8cc6d7fd5f9 | 678 | mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 679 | |
phonemacro | 32:92adfbe18ab6 | 680 | //1.0 read operating mode |
phonemacro | 14:c8cc6d7fd5f9 | 681 | cmd[0] = 0x02; cmd[1] = 0x00; |
phonemacro | 14:c8cc6d7fd5f9 | 682 | sh_i2c.write(SH_ADDR, cmd, 2); |
phonemacro | 14:c8cc6d7fd5f9 | 683 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 684 | sh_i2c.read(SH_ADDR, rsp, 2); |
phonemacro | 14:c8cc6d7fd5f9 | 685 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 686 | pc.printf("\n\r 0x02 0x00 Status, Read Operating Mode: %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 32:92adfbe18ab6 | 687 | //1.1 rd ver |
phonemacro | 14:c8cc6d7fd5f9 | 688 | cmd[0] = 0xFF; cmd[1] = 0x03; |
phonemacro | 14:c8cc6d7fd5f9 | 689 | sh_i2c.write(SH_ADDR, cmd, 2); |
phonemacro | 14:c8cc6d7fd5f9 | 690 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 691 | sh_i2c.read(SH_ADDR, rsp, 4); |
phonemacro | 14:c8cc6d7fd5f9 | 692 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 693 | pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]); |
phonemacro | 14:c8cc6d7fd5f9 | 694 | |
phonemacro | 32:92adfbe18ab6 | 695 | // raw1.2 sensor data |
phonemacro | 14:c8cc6d7fd5f9 | 696 | cmd[0] = 0x10; cmd[1] = 0x00; cmd[2] = 0x01; |
phonemacro | 14:c8cc6d7fd5f9 | 697 | pc.printf("raw sensor data only \n\r"); |
phonemacro | 14:c8cc6d7fd5f9 | 698 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 14:c8cc6d7fd5f9 | 699 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 700 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 14:c8cc6d7fd5f9 | 701 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 702 | pc.printf("raw1.2 Status: %x\n\r", rsp[0]); |
phonemacro | 32:92adfbe18ab6 | 703 | // raw1.3 interrupt threshold |
phonemacro | 14:c8cc6d7fd5f9 | 704 | cmd[0] = 0x10; cmd[1] = 0x01; cmd[2] = 0x01; |
phonemacro | 14:c8cc6d7fd5f9 | 705 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 14:c8cc6d7fd5f9 | 706 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 707 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 14:c8cc6d7fd5f9 | 708 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 709 | pc.printf("raw1.3 Status: %x\n\r", rsp[0]); |
phonemacro | 32:92adfbe18ab6 | 710 | // raw1.4 enable sh accel |
phonemacro | 14:c8cc6d7fd5f9 | 711 | cmd[0] = 0x44; cmd[1] = 0x04; cmd[2] = 0x01; cmd[3] = 0x00; |
phonemacro | 14:c8cc6d7fd5f9 | 712 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 29:a7dd81450b35 | 713 | mfio = 1; thread_sleep_for(20); mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 714 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 29:a7dd81450b35 | 715 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 716 | pc.printf("raw1.4 Status: %x\n\r", rsp[0]); |
phonemacro | 32:92adfbe18ab6 | 717 | // raw1.6 enable AFE |
phonemacro | 32:92adfbe18ab6 | 718 | cmd[0] = 0x44; cmd[1] = 0x00; cmd[2] = 0x01; // 3 bytes // tested on 33.13.31/12 |
phonemacro | 29:a7dd81450b35 | 719 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 30:77a30ea425da | 720 | // cmd[0] = 0x44; cmd[1] = 0x00; cmd[2] = 0x01; cmd[3] = 0x00; |
phonemacro | 30:77a30ea425da | 721 | // sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 30:77a30ea425da | 722 | // cmd[0] = 0x44; cmd[1] = 0xFF; cmd[2] = 0x02; cmd[3] = 0x04; cmd[4] = 0x01; cmd[5] = 0x00; cmd[6] = 0x00; cmd[7] = 0x01; cmd[8] = 0x00; |
phonemacro | 30:77a30ea425da | 723 | // sh_i2c.write(SH_ADDR, cmd, 9); |
phonemacro | 29:a7dd81450b35 | 724 | mfio = 1; thread_sleep_for(250); mfio = 0; wait_us(300); |
phonemacro | 29:a7dd81450b35 | 725 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 14:c8cc6d7fd5f9 | 726 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 727 | pc.printf("raw1.6 Status: %x\n\r", rsp[0]); |
phonemacro | 32:92adfbe18ab6 | 728 | |
phonemacro | 32:92adfbe18ab6 | 729 | // raw1.7 rd accel WHO reg |
phonemacro | 30:77a30ea425da | 730 | cmd[0] = 0x41; cmd[1] = 0x04; cmd[2] = 0x0F; |
phonemacro | 30:77a30ea425da | 731 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 30:77a30ea425da | 732 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 30:77a30ea425da | 733 | sh_i2c.read(SH_ADDR, rsp, 2); |
phonemacro | 30:77a30ea425da | 734 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 735 | pc.printf("1.7 Who Status: %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 32:92adfbe18ab6 | 736 | // rd1.6 AFE part id |
phonemacro | 30:77a30ea425da | 737 | cmd[0] = 0x41; cmd[1] = 0x00; cmd[2] = 0xFF; |
phonemacro | 30:77a30ea425da | 738 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 30:77a30ea425da | 739 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 30:77a30ea425da | 740 | sh_i2c.read(SH_ADDR, rsp, 2); |
phonemacro | 30:77a30ea425da | 741 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 742 | pc.printf("raw1.6 part id Status: %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 32:92adfbe18ab6 | 743 | |
phonemacro | 32:92adfbe18ab6 | 744 | // raw1.8 sample rate 100 Hz, ave 1 |
phonemacro | 14:c8cc6d7fd5f9 | 745 | cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x18; // set AFE reg 0x12 to 100 Hz |
phonemacro | 14:c8cc6d7fd5f9 | 746 | // cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x20; // set AFE reg 0x12 to 200 Hz |
phonemacro | 14:c8cc6d7fd5f9 | 747 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 14:c8cc6d7fd5f9 | 748 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 749 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 14:c8cc6d7fd5f9 | 750 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 751 | pc.printf("raw1.8 Status: %x\n\r", rsp[0]); |
phonemacro | 32:92adfbe18ab6 | 752 | // raw1.9 LED1 current |
phonemacro | 29:a7dd81450b35 | 753 | cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x23; cmd[3] = 0x3F; |
phonemacro | 14:c8cc6d7fd5f9 | 754 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 14:c8cc6d7fd5f9 | 755 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 756 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 14:c8cc6d7fd5f9 | 757 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 758 | pc.printf("raw1.9 Status: %x\n\r", rsp[0]); |
phonemacro | 14:c8cc6d7fd5f9 | 759 | #ifndef MAXM86146_CFG |
phonemacro | 32:92adfbe18ab6 | 760 | // raw1.10 LED2 current |
phonemacro | 14:c8cc6d7fd5f9 | 761 | cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x24; cmd[3] = 0x7F; |
phonemacro | 14:c8cc6d7fd5f9 | 762 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 14:c8cc6d7fd5f9 | 763 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 764 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 14:c8cc6d7fd5f9 | 765 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 766 | pc.printf("raw1.10 Status: %x\n\r", rsp[0]); |
phonemacro | 14:c8cc6d7fd5f9 | 767 | #endif |
phonemacro | 32:92adfbe18ab6 | 768 | // raw1.11 LED3 current |
phonemacro | 14:c8cc6d7fd5f9 | 769 | cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x25; cmd[3] = 0x7F; |
phonemacro | 14:c8cc6d7fd5f9 | 770 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 14:c8cc6d7fd5f9 | 771 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 772 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 14:c8cc6d7fd5f9 | 773 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 32:92adfbe18ab6 | 774 | pc.printf("raw1.11 Status: %x\n\r", rsp[0]); |
phonemacro | 14:c8cc6d7fd5f9 | 775 | #ifdef MAXM86146_CFG |
phonemacro | 14:c8cc6d7fd5f9 | 776 | // LED5 current |
phonemacro | 14:c8cc6d7fd5f9 | 777 | cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x27; cmd[3] = 0x7F; |
phonemacro | 14:c8cc6d7fd5f9 | 778 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 14:c8cc6d7fd5f9 | 779 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 780 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 14:c8cc6d7fd5f9 | 781 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 782 | pc.printf("led5 Status: %x\n\r", rsp[0]); |
phonemacro | 14:c8cc6d7fd5f9 | 783 | // LED6 current |
phonemacro | 14:c8cc6d7fd5f9 | 784 | cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x27; cmd[3] = 0x7F; |
phonemacro | 14:c8cc6d7fd5f9 | 785 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 14:c8cc6d7fd5f9 | 786 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 787 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 14:c8cc6d7fd5f9 | 788 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 789 | pc.printf("led6 Status: %x\n\r", rsp[0]); |
phonemacro | 14:c8cc6d7fd5f9 | 790 | |
phonemacro | 14:c8cc6d7fd5f9 | 791 | // Set Seq cntrl1 LED2, LED1 |
phonemacro | 14:c8cc6d7fd5f9 | 792 | cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x20; cmd[3] = 0x21; |
phonemacro | 14:c8cc6d7fd5f9 | 793 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 14:c8cc6d7fd5f9 | 794 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 795 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 14:c8cc6d7fd5f9 | 796 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 797 | pc.printf("Seq cntrl1 Status: %x\n\r", rsp[0]); |
phonemacro | 14:c8cc6d7fd5f9 | 798 | // Set Seq cntrl2 LED4, LED3 |
phonemacro | 14:c8cc6d7fd5f9 | 799 | cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x21; cmd[3] = 0xA3; |
phonemacro | 14:c8cc6d7fd5f9 | 800 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 14:c8cc6d7fd5f9 | 801 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 802 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 14:c8cc6d7fd5f9 | 803 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 804 | pc.printf("Seq cntrl2 Status: %x\n\r", rsp[0]); |
phonemacro | 14:c8cc6d7fd5f9 | 805 | // Set Seq cntrl3 LED6, LED5 |
phonemacro | 14:c8cc6d7fd5f9 | 806 | cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x22; cmd[3] = 0x21; |
phonemacro | 14:c8cc6d7fd5f9 | 807 | // cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x22; cmd[3] = 0x99; // Ambient |
phonemacro | 14:c8cc6d7fd5f9 | 808 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 14:c8cc6d7fd5f9 | 809 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 810 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 14:c8cc6d7fd5f9 | 811 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 14:c8cc6d7fd5f9 | 812 | pc.printf("Seq cntrl3 Status: %x\n\r", rsp[0]); |
phonemacro | 14:c8cc6d7fd5f9 | 813 | |
phonemacro | 14:c8cc6d7fd5f9 | 814 | #endif |
phonemacro | 28:315604f4b374 | 815 | mfio = 1; |
phonemacro | 28:315604f4b374 | 816 | } |
phonemacro | 14:c8cc6d7fd5f9 | 817 | |
phonemacro | 14:c8cc6d7fd5f9 | 818 | /*****************************************************************************/ |
phonemacro | 14:c8cc6d7fd5f9 | 819 | // main |
phonemacro | 14:c8cc6d7fd5f9 | 820 | /*****************************************************************************/ |
phonemacro | 10:192ea88e964b | 821 | int main() |
phonemacro | 10:192ea88e964b | 822 | { |
phonemacro | 10:192ea88e964b | 823 | sh_i2c.frequency(400000); |
phonemacro | 10:192ea88e964b | 824 | int32_t ledcnt = 0; |
phonemacro | 10:192ea88e964b | 825 | rLED = LED_OFF; gLED = LED_ON; bLED = LED_OFF; |
phonemacro | 10:192ea88e964b | 826 | Ticker ticker; // calls a callback repeatedly with a timeout |
phonemacro | 28:315604f4b374 | 827 | |
phonemacro | 28:315604f4b374 | 828 | #if 0 // test disable algo |
phonemacro | 28:315604f4b374 | 829 | char cmd[8]; |
phonemacro | 28:315604f4b374 | 830 | char rsp[256]; |
phonemacro | 28:315604f4b374 | 831 | // 3.1 Disable algo |
phonemacro | 28:315604f4b374 | 832 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 28:315604f4b374 | 833 | cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x00; |
phonemacro | 28:315604f4b374 | 834 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 28:315604f4b374 | 835 | thread_sleep_for(465); |
phonemacro | 28:315604f4b374 | 836 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 28:315604f4b374 | 837 | pc.printf("3.1 disable algo: %x\n\r", rsp[0]); |
phonemacro | 28:315604f4b374 | 838 | mfio = 1; |
phonemacro | 28:315604f4b374 | 839 | #endif |
phonemacro | 28:315604f4b374 | 840 | |
phonemacro | 10:192ea88e964b | 841 | //ticker.attach(callback(&blink_timer), BLINKING_RATE_MS); /* set timer for one second */ |
phonemacro | 14:c8cc6d7fd5f9 | 842 | #ifdef RAW |
phonemacro | 14:c8cc6d7fd5f9 | 843 | init_sh_raw(); |
phonemacro | 14:c8cc6d7fd5f9 | 844 | #else |
phonemacro | 14:c8cc6d7fd5f9 | 845 | init_sh_algo(); |
phonemacro | 14:c8cc6d7fd5f9 | 846 | #endif |
phonemacro | 28:315604f4b374 | 847 | mfio = 1; |
phonemacro | 8:e6ae69cfecbf | 848 | #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG) || defined(MAXM86146_CFG) |
phonemacro | 6:e1b7190d6cb5 | 849 | Timer tmr1; |
phonemacro | 0:6f65cae31c54 | 850 | while (1) { |
phonemacro | 6:e1b7190d6cb5 | 851 | tmr1.start(); |
phonemacro | 29:a7dd81450b35 | 852 | #if defined(RAW) |
phonemacro | 29:a7dd81450b35 | 853 | if (tmr1.read_ms() >= 10) { |
phonemacro | 29:a7dd81450b35 | 854 | #else |
phonemacro | 28:315604f4b374 | 855 | if (tmr1.read_ms() >= 40) { |
phonemacro | 29:a7dd81450b35 | 856 | #endif |
phonemacro | 7:23b067817ab8 | 857 | tmr1.reset(); |
phonemacro | 10:192ea88e964b | 858 | read_sh_fifo(); |
phonemacro | 7:23b067817ab8 | 859 | if ((ledcnt++ % 50) == 0) |
phonemacro | 6:e1b7190d6cb5 | 860 | gLED = !gLED; |
phonemacro | 0:6f65cae31c54 | 861 | } |
phonemacro | 0:6f65cae31c54 | 862 | } |
phonemacro | 6:e1b7190d6cb5 | 863 | #else |
phonemacro | 6:e1b7190d6cb5 | 864 | ticker.attach(callback(&fifo_timer), 0.040f); |
phonemacro | 6:e1b7190d6cb5 | 865 | while (1) { |
phonemacro | 6:e1b7190d6cb5 | 866 | if (Time_to_Read_PPG) { |
phonemacro | 10:192ea88e964b | 867 | read_sh_fifo(); |
phonemacro | 7:23b067817ab8 | 868 | if ((ledcnt++ % 50) == 0) |
phonemacro | 6:e1b7190d6cb5 | 869 | gLED = !gLED; |
phonemacro | 6:e1b7190d6cb5 | 870 | } |
phonemacro | 6:e1b7190d6cb5 | 871 | } |
phonemacro | 6:e1b7190d6cb5 | 872 | #endif |
phonemacro | 0:6f65cae31c54 | 873 | } |