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