David Jung
/
MAX32664C_MAXM86146_Mode1_Optical
Mode1 Optical Validation
main.cpp@2:563d90a111b3, 2021-03-18 (annotated)
- Committer:
- phonemacro
- Date:
- Thu Mar 18 20:48:49 2021 +0000
- Revision:
- 2:563d90a111b3
- Parent:
- 1:da792e46a385
- Child:
- 3:da975696b936
add ppg
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
phonemacro | 0:6f65cae31c54 | 1 | /******************************************************************************* |
phonemacro | 0:6f65cae31c54 | 2 | * Copyright (C) 2018 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 | //#include "max32630fthr.h" |
phonemacro | 0:6f65cae31c54 | 34 | //#include "USBSerial.h" |
phonemacro | 0:6f65cae31c54 | 35 | |
phonemacro | 0:6f65cae31c54 | 36 | #include "mbed.h" |
phonemacro | 0:6f65cae31c54 | 37 | #include "platform/mbed_thread.h" |
phonemacro | 0:6f65cae31c54 | 38 | |
phonemacro | 2:563d90a111b3 | 39 | #define MAXM86146_CFG 1 |
phonemacro | 2:563d90a111b3 | 40 | #ifdef MAXM86146_CFG |
phonemacro | 0:6f65cae31c54 | 41 | #define PPG_SZ 36 //maxm86146 |
phonemacro | 0:6f65cae31c54 | 42 | #else |
phonemacro | 0:6f65cae31c54 | 43 | #define PPG_SZ 18 //maxm86161, max86141 |
phonemacro | 0:6f65cae31c54 | 44 | #endif |
phonemacro | 0:6f65cae31c54 | 45 | #define ACCEL_SZ 6 // accel |
phonemacro | 0:6f65cae31c54 | 46 | #define SENSOR_SZ (PPG_SZ+ACCEL_SZ) |
phonemacro | 0:6f65cae31c54 | 47 | #define ALGO_SZ 20 // 24 bytes is the algo normal size for 3x.12.0 |
phonemacro | 2:563d90a111b3 | 48 | //#define ALGO_SZ 24 // 24 bytes is the algo normal size for 3x.13.x |
phonemacro | 2:563d90a111b3 | 49 | //#define ALGO_ONLY 1 |
phonemacro | 0:6f65cae31c54 | 50 | #ifdef ALGO_ONLY |
phonemacro | 0:6f65cae31c54 | 51 | #define TTL_SZ (ALGO_SZ) |
phonemacro | 0:6f65cae31c54 | 52 | #else |
phonemacro | 0:6f65cae31c54 | 53 | #define TTL_SZ (PPG_SZ+ACCEL_SZ+ALGO_SZ) |
phonemacro | 0:6f65cae31c54 | 54 | #endif |
phonemacro | 0:6f65cae31c54 | 55 | |
phonemacro | 0:6f65cae31c54 | 56 | DigitalOut rLED(LED1); |
phonemacro | 0:6f65cae31c54 | 57 | DigitalOut gLED(LED2); |
phonemacro | 0:6f65cae31c54 | 58 | DigitalOut bLED(LED3); |
phonemacro | 0:6f65cae31c54 | 59 | #define RST_PIN P5_6 |
phonemacro | 0:6f65cae31c54 | 60 | #define MFIO_PIN P5_4 |
phonemacro | 0:6f65cae31c54 | 61 | DigitalOut rst(RST_PIN, PullUp); |
phonemacro | 0:6f65cae31c54 | 62 | DigitalOut mfio(MFIO_PIN, PullUp); |
phonemacro | 0:6f65cae31c54 | 63 | I2C i2c(P3_4, P3_5); |
phonemacro | 0:6f65cae31c54 | 64 | |
phonemacro | 0:6f65cae31c54 | 65 | const int addr = 0xAA;//0x55; |
phonemacro | 0:6f65cae31c54 | 66 | int32_t Time_to_Read_PPG = 0; |
phonemacro | 0:6f65cae31c54 | 67 | |
phonemacro | 0:6f65cae31c54 | 68 | #define BLINKING_RATE_MS 1000ms |
phonemacro | 0:6f65cae31c54 | 69 | void blink_timer(void) { |
phonemacro | 0:6f65cae31c54 | 70 | gLED = !gLED; /* blink the green LED */ |
phonemacro | 0:6f65cae31c54 | 71 | } |
phonemacro | 0:6f65cae31c54 | 72 | |
phonemacro | 0:6f65cae31c54 | 73 | void fifo_timer(void) { |
phonemacro | 0:6f65cae31c54 | 74 | Time_to_Read_PPG = 1; |
phonemacro | 0:6f65cae31c54 | 75 | } |
phonemacro | 0:6f65cae31c54 | 76 | |
phonemacro | 0:6f65cae31c54 | 77 | void read_ppg(void) { |
phonemacro | 0:6f65cae31c54 | 78 | char cmd[8], i, j, samples; |
phonemacro | 0:6f65cae31c54 | 79 | char rsp[3000]; |
phonemacro | 0:6f65cae31c54 | 80 | int32_t ppg[12]; |
phonemacro | 0:6f65cae31c54 | 81 | int32_t accel[3]; |
phonemacro | 2:563d90a111b3 | 82 | int32_t status, opmode, hr, hr_conf, spo2, spo2_conf, scd; |
phonemacro | 2:563d90a111b3 | 83 | int32_t scnt = 0; |
phonemacro | 0:6f65cae31c54 | 84 | int32_t ptr = 0; |
phonemacro | 0:6f65cae31c54 | 85 | int32_t sptr = 0; |
phonemacro | 1:da792e46a385 | 86 | mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 87 | Time_to_Read_PPG = 0; |
phonemacro | 0:6f65cae31c54 | 88 | #if 0 |
phonemacro | 0:6f65cae31c54 | 89 | // 2.1 |
phonemacro | 0:6f65cae31c54 | 90 | cmd[0] = 0x00; |
phonemacro | 0:6f65cae31c54 | 91 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 92 | i2c.write(addr, cmd, 2); |
phonemacro | 0:6f65cae31c54 | 93 | wait_us(100); |
phonemacro | 0:6f65cae31c54 | 94 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 95 | rsp[1] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 96 | i2c.read(addr, rsp, 2); |
phonemacro | 0:6f65cae31c54 | 97 | // printf("2.1 Status: %x %x\n", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 98 | #endif |
phonemacro | 0:6f65cae31c54 | 99 | // 2.2 |
phonemacro | 0:6f65cae31c54 | 100 | cmd[0] = 0x12; |
phonemacro | 0:6f65cae31c54 | 101 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 102 | i2c.write(addr, cmd, 2); |
phonemacro | 0:6f65cae31c54 | 103 | wait_us(100); |
phonemacro | 0:6f65cae31c54 | 104 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 105 | rsp[1] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 106 | i2c.read(addr, rsp, 2); |
phonemacro | 0:6f65cae31c54 | 107 | // printf("2.2 Status: %x %x\n", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 108 | samples = rsp[1]; |
phonemacro | 0:6f65cae31c54 | 109 | // printf("num samples %d, (num*ttl)+1 %d\n", rsp[1], TTL_SZ*samples+1); |
phonemacro | 0:6f65cae31c54 | 110 | // printf("num smpls %d \n", samples); |
phonemacro | 0:6f65cae31c54 | 111 | scnt = rsp[1]; |
phonemacro | 0:6f65cae31c54 | 112 | // 2.3 |
phonemacro | 0:6f65cae31c54 | 113 | cmd[0] = 0x12; |
phonemacro | 0:6f65cae31c54 | 114 | cmd[1] = 0x01; |
phonemacro | 0:6f65cae31c54 | 115 | i2c.write(addr, cmd, 2); |
phonemacro | 0:6f65cae31c54 | 116 | wait_us(100); |
phonemacro | 0:6f65cae31c54 | 117 | // thread_sleep_for(1); |
phonemacro | 0:6f65cae31c54 | 118 | i2c.read(addr, rsp, 1+(TTL_SZ*samples)); |
phonemacro | 0:6f65cae31c54 | 119 | status = rsp[0]; |
phonemacro | 0:6f65cae31c54 | 120 | |
phonemacro | 0:6f65cae31c54 | 121 | sptr = 1; |
phonemacro | 0:6f65cae31c54 | 122 | for (i = 0; i < scnt; i++) { |
phonemacro | 0:6f65cae31c54 | 123 | #ifdef ALGO_ONLY |
phonemacro | 0:6f65cae31c54 | 124 | ptr = sptr; |
phonemacro | 0:6f65cae31c54 | 125 | #else |
phonemacro | 2:563d90a111b3 | 126 | ptr = sptr; |
phonemacro | 2:563d90a111b3 | 127 | ppg[0] = (rsp[ptr+0] << 16) | (rsp[ptr+1] << 8) | (rsp[ptr+2]); |
phonemacro | 2:563d90a111b3 | 128 | ppg[1] = (rsp[ptr+3] << 16) | (rsp[ptr+4] << 8) | (rsp[ptr+5]); |
phonemacro | 2:563d90a111b3 | 129 | ppg[2] = (rsp[ptr+6] << 16) | (rsp[ptr+7] << 8) | (rsp[ptr+8]); |
phonemacro | 2:563d90a111b3 | 130 | printf("%d,%d,%d,", ppg[0], ppg[1], ppg[2]); |
phonemacro | 0:6f65cae31c54 | 131 | ptr = sptr + SENSOR_SZ; |
phonemacro | 0:6f65cae31c54 | 132 | #endif |
phonemacro | 2:563d90a111b3 | 133 | // printf("ptr %d ttlsiz %d ", ptr, TTL_SZ); |
phonemacro | 0:6f65cae31c54 | 134 | opmode = rsp[ptr]; |
phonemacro | 0:6f65cae31c54 | 135 | hr = (rsp[ptr+1] << 8) + rsp[ptr+2]; |
phonemacro | 0:6f65cae31c54 | 136 | hr_conf = rsp[ptr+3]; |
phonemacro | 0:6f65cae31c54 | 137 | spo2_conf = rsp[ptr+10]; |
phonemacro | 0:6f65cae31c54 | 138 | spo2 = (rsp[ptr+11] << 8) + rsp[ptr+12]; |
phonemacro | 2:563d90a111b3 | 139 | scd = rsp[ptr+19]; |
phonemacro | 0:6f65cae31c54 | 140 | |
phonemacro | 0:6f65cae31c54 | 141 | sptr += (TTL_SZ); |
phonemacro | 0:6f65cae31c54 | 142 | |
phonemacro | 2:563d90a111b3 | 143 | printf("%d,%d,%d,%d,%d", hr, hr_conf, spo2, spo2_conf, scd); |
phonemacro | 0:6f65cae31c54 | 144 | printf("\n"); |
phonemacro | 0:6f65cae31c54 | 145 | } |
phonemacro | 0:6f65cae31c54 | 146 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 147 | } |
phonemacro | 0:6f65cae31c54 | 148 | |
phonemacro | 0:6f65cae31c54 | 149 | |
phonemacro | 0:6f65cae31c54 | 150 | |
phonemacro | 0:6f65cae31c54 | 151 | int main() |
phonemacro | 0:6f65cae31c54 | 152 | { |
phonemacro | 0:6f65cae31c54 | 153 | i2c.frequency(200000); |
phonemacro | 0:6f65cae31c54 | 154 | char cmd[8], i, j; |
phonemacro | 0:6f65cae31c54 | 155 | char rsp[256]; |
phonemacro | 0:6f65cae31c54 | 156 | int32_t ppg[12]; |
phonemacro | 0:6f65cae31c54 | 157 | |
phonemacro | 0:6f65cae31c54 | 158 | rLED = LED_OFF; |
phonemacro | 0:6f65cae31c54 | 159 | gLED = LED_ON; |
phonemacro | 0:6f65cae31c54 | 160 | bLED = LED_OFF; |
phonemacro | 0:6f65cae31c54 | 161 | Ticker ticker; // calls a callback repeatedly with a timeout |
phonemacro | 0:6f65cae31c54 | 162 | //ticker.attach(callback(&blink_timer), BLINKING_RATE_MS); /* set timer for one second */ |
phonemacro | 0:6f65cae31c54 | 163 | |
phonemacro | 0:6f65cae31c54 | 164 | //========================================== |
phonemacro | 0:6f65cae31c54 | 165 | #if 0 // BL, app switching |
phonemacro | 0:6f65cae31c54 | 166 | // BL |
phonemacro | 0:6f65cae31c54 | 167 | rst = 0; |
phonemacro | 0:6f65cae31c54 | 168 | mfio = 0; |
phonemacro | 0:6f65cae31c54 | 169 | thread_sleep_for(10); |
phonemacro | 0:6f65cae31c54 | 170 | rst = 1; |
phonemacro | 0:6f65cae31c54 | 171 | thread_sleep_for(50); |
phonemacro | 0:6f65cae31c54 | 172 | |
phonemacro | 1:da792e46a385 | 173 | mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 174 | cmd[0] = 0x02; |
phonemacro | 0:6f65cae31c54 | 175 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 176 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 177 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 178 | thread_sleep_for(2); |
phonemacro | 0:6f65cae31c54 | 179 | rsp[0] = 0x00; |
phonemacro | 0:6f65cae31c54 | 180 | rsp[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 181 | i2c.read(addr, rsp, 2); |
phonemacro | 1:da792e46a385 | 182 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 183 | printf("02 00 Status, Operating Mode: %x %x\n", rsp[0], rsp[1]); |
phonemacro | 1:da792e46a385 | 184 | |
phonemacro | 0:6f65cae31c54 | 185 | // rd BL ver |
phonemacro | 0:6f65cae31c54 | 186 | cmd[0] = 0x81; |
phonemacro | 0:6f65cae31c54 | 187 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 188 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 189 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 190 | thread_sleep_for(2); |
phonemacro | 0:6f65cae31c54 | 191 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 192 | rsp[1] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 193 | rsp[2] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 194 | rsp[3] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 195 | i2c.read(addr, rsp, 4); |
phonemacro | 1:da792e46a385 | 196 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 197 | printf("Ver: %d %d %d %d\n", rsp[0], rsp[1], rsp[2], rsp[3]); |
phonemacro | 0:6f65cae31c54 | 198 | |
phonemacro | 0:6f65cae31c54 | 199 | // application |
phonemacro | 0:6f65cae31c54 | 200 | rst = 0; |
phonemacro | 0:6f65cae31c54 | 201 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 202 | thread_sleep_for(10); |
phonemacro | 0:6f65cae31c54 | 203 | rst = 1; |
phonemacro | 0:6f65cae31c54 | 204 | thread_sleep_for(1500); |
phonemacro | 0:6f65cae31c54 | 205 | |
phonemacro | 1:da792e46a385 | 206 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 207 | cmd[0] = 0x02; |
phonemacro | 0:6f65cae31c54 | 208 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 209 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 210 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 211 | rsp[0] = 0x00; |
phonemacro | 0:6f65cae31c54 | 212 | rsp[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 213 | i2c.read(addr, rsp, 2); |
phonemacro | 1:da792e46a385 | 214 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 215 | printf("02 00 Status, Operating Mode: %x %x\n", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 216 | // rd ver |
phonemacro | 0:6f65cae31c54 | 217 | cmd[0] = 0xFF; |
phonemacro | 0:6f65cae31c54 | 218 | cmd[1] = 0x03; |
phonemacro | 0:6f65cae31c54 | 219 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 220 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 221 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 222 | rsp[1] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 223 | rsp[2] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 224 | rsp[3] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 225 | i2c.read(addr, rsp, 4); |
phonemacro | 1:da792e46a385 | 226 | printf("Ver: %d %d %d %d\n", rsp[0], rsp[1], rsp[2], rsp[3]); |
phonemacro | 0:6f65cae31c54 | 227 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 228 | |
phonemacro | 0:6f65cae31c54 | 229 | |
phonemacro | 0:6f65cae31c54 | 230 | // BL |
phonemacro | 0:6f65cae31c54 | 231 | rst = 0; |
phonemacro | 0:6f65cae31c54 | 232 | mfio = 0; |
phonemacro | 0:6f65cae31c54 | 233 | thread_sleep_for(10); |
phonemacro | 0:6f65cae31c54 | 234 | rst = 1; |
phonemacro | 0:6f65cae31c54 | 235 | thread_sleep_for(50); |
phonemacro | 0:6f65cae31c54 | 236 | |
phonemacro | 0:6f65cae31c54 | 237 | cmd[0] = 0x02; |
phonemacro | 0:6f65cae31c54 | 238 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 239 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 240 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 241 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 242 | rsp[1] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 243 | i2c.read(addr, rsp, 2); |
phonemacro | 0:6f65cae31c54 | 244 | printf("02 00 Status, Operating Mode: %x %x\n", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 245 | // rd BL ver |
phonemacro | 1:da792e46a385 | 246 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 247 | cmd[0] = 0x81; |
phonemacro | 0:6f65cae31c54 | 248 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 249 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 250 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 251 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 252 | rsp[1] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 253 | rsp[2] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 254 | rsp[3] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 255 | i2c.read(addr, rsp, 4); |
phonemacro | 0:6f65cae31c54 | 256 | printf("Ver: %d %d %d %d\n", rsp[0], rsp[1], rsp[2], rsp[3]); |
phonemacro | 1:da792e46a385 | 257 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 258 | #endif // end BL app switching |
phonemacro | 0:6f65cae31c54 | 259 | //========================================== |
phonemacro | 0:6f65cae31c54 | 260 | // application |
phonemacro | 0:6f65cae31c54 | 261 | rst = 0; |
phonemacro | 0:6f65cae31c54 | 262 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 263 | thread_sleep_for(10); |
phonemacro | 0:6f65cae31c54 | 264 | rst = 1; |
phonemacro | 0:6f65cae31c54 | 265 | thread_sleep_for(1500); |
phonemacro | 0:6f65cae31c54 | 266 | |
phonemacro | 1:da792e46a385 | 267 | mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 268 | cmd[0] = 0x02; |
phonemacro | 0:6f65cae31c54 | 269 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 270 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 271 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 272 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 273 | rsp[1] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 274 | i2c.read(addr, rsp, 2); |
phonemacro | 1:da792e46a385 | 275 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 276 | printf("02 00 Status, Operating Mode: %x %x\n", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 277 | // rd ver |
phonemacro | 0:6f65cae31c54 | 278 | cmd[0] = 0xFF; |
phonemacro | 0:6f65cae31c54 | 279 | cmd[1] = 0x03; |
phonemacro | 0:6f65cae31c54 | 280 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 281 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 282 | wait_us(300); |
phonemacro | 0:6f65cae31c54 | 283 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 284 | rsp[1] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 285 | rsp[2] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 286 | rsp[3] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 287 | i2c.read(addr, rsp, 4); |
phonemacro | 1:da792e46a385 | 288 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 289 | printf("Ver: %d %d %d %d\n", rsp[0], rsp[1], rsp[2], rsp[3]); |
phonemacro | 0:6f65cae31c54 | 290 | |
phonemacro | 0:6f65cae31c54 | 291 | |
phonemacro | 0:6f65cae31c54 | 292 | // aec mode |
phonemacro | 0:6f65cae31c54 | 293 | // 1.3 sensor and algo data |
phonemacro | 0:6f65cae31c54 | 294 | cmd[0] = 0x10; |
phonemacro | 0:6f65cae31c54 | 295 | cmd[1] = 0x00; |
phonemacro | 2:563d90a111b3 | 296 | #ifdef ALGO_ONLY |
phonemacro | 0:6f65cae31c54 | 297 | cmd[2] = 0x02; // algo data |
phonemacro | 2:563d90a111b3 | 298 | #else |
phonemacro | 2:563d90a111b3 | 299 | cmd[2] = 0x03; // sensor + algo data |
phonemacro | 2:563d90a111b3 | 300 | #endif |
phonemacro | 0:6f65cae31c54 | 301 | i2c.write(addr, cmd, 3); |
phonemacro | 1:da792e46a385 | 302 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 303 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 304 | i2c.read(addr, rsp, 1); |
phonemacro | 1:da792e46a385 | 305 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 306 | printf("1.3 Status: %x\n", rsp[0]); |
phonemacro | 0:6f65cae31c54 | 307 | //1.11 rd AFE part id |
phonemacro | 0:6f65cae31c54 | 308 | cmd[0] = 0x41; |
phonemacro | 0:6f65cae31c54 | 309 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 310 | cmd[2] = 0xFF; |
phonemacro | 0:6f65cae31c54 | 311 | i2c.write(addr, cmd, 3); |
phonemacro | 1:da792e46a385 | 312 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 313 | i2c.read(addr, rsp, 2); |
phonemacro | 1:da792e46a385 | 314 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 315 | printf("1.11 part id afe %x %x\n", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 316 | //1.13 rd accel who |
phonemacro | 0:6f65cae31c54 | 317 | cmd[0] = 0x41; |
phonemacro | 0:6f65cae31c54 | 318 | cmd[1] = 0x04; |
phonemacro | 0:6f65cae31c54 | 319 | cmd[2] = 0x0F; |
phonemacro | 0:6f65cae31c54 | 320 | i2c.write(addr, cmd, 3); |
phonemacro | 1:da792e46a385 | 321 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 322 | i2c.read(addr, rsp, 2); |
phonemacro | 1:da792e46a385 | 323 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 324 | printf("1.12 who accel %x %x\n", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 325 | |
phonemacro | 2:563d90a111b3 | 326 | //1.20 Sec 4.1 map leds to slots for MAXM86146 |
phonemacro | 0:6f65cae31c54 | 327 | cmd[0] = 0x50; |
phonemacro | 0:6f65cae31c54 | 328 | cmd[1] = 0x07; |
phonemacro | 0:6f65cae31c54 | 329 | cmd[2] = 0x19; |
phonemacro | 2:563d90a111b3 | 330 | cmd[3] = 0x15; |
phonemacro | 2:563d90a111b3 | 331 | cmd[4] = 0x60; |
phonemacro | 0:6f65cae31c54 | 332 | cmd[5] = 0x00; |
phonemacro | 0:6f65cae31c54 | 333 | i2c.write(addr, cmd, 6); |
phonemacro | 1:da792e46a385 | 334 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 335 | i2c.read(addr, rsp, 1); |
phonemacro | 1:da792e46a385 | 336 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 337 | printf("map leds to slots%x\n", rsp[0]); |
phonemacro | 2:563d90a111b3 | 338 | //1.21 map HR inputs to slots |
phonemacro | 0:6f65cae31c54 | 339 | cmd[0] = 0x50; |
phonemacro | 0:6f65cae31c54 | 340 | cmd[1] = 0x07; |
phonemacro | 0:6f65cae31c54 | 341 | cmd[2] = 0x17; |
phonemacro | 0:6f65cae31c54 | 342 | cmd[3] = 0x00; |
phonemacro | 2:563d90a111b3 | 343 | cmd[4] = 0x01; |
phonemacro | 0:6f65cae31c54 | 344 | i2c.write(addr, cmd, 5); |
phonemacro | 1:da792e46a385 | 345 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 346 | i2c.read(addr, rsp, 1); |
phonemacro | 1:da792e46a385 | 347 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 348 | printf("map HR to slots/PDs %x\n", rsp[0]); |
phonemacro | 0:6f65cae31c54 | 349 | |
phonemacro | 2:563d90a111b3 | 350 | //1.22 map SpO2 inputs to slots |
phonemacro | 0:6f65cae31c54 | 351 | cmd[0] = 0x50; |
phonemacro | 0:6f65cae31c54 | 352 | cmd[1] = 0x07; |
phonemacro | 0:6f65cae31c54 | 353 | cmd[2] = 0x18; |
phonemacro | 2:563d90a111b3 | 354 | cmd[3] = 0x20; |
phonemacro | 2:563d90a111b3 | 355 | cmd[4] = 0x10; |
phonemacro | 0:6f65cae31c54 | 356 | i2c.write(addr, cmd, 5); |
phonemacro | 1:da792e46a385 | 357 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 358 | i2c.read(addr, rsp, 1); |
phonemacro | 1:da792e46a385 | 359 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 360 | printf("map SpO2 to slots/PDs %x\n", rsp[0]); |
phonemacro | 0:6f65cae31c54 | 361 | |
phonemacro | 2:563d90a111b3 | 362 | // 1.3 |
phonemacro | 0:6f65cae31c54 | 363 | cmd[0] = 0x52; |
phonemacro | 0:6f65cae31c54 | 364 | cmd[1] = 0x07; |
phonemacro | 0:6f65cae31c54 | 365 | cmd[2] = 0x01; |
phonemacro | 0:6f65cae31c54 | 366 | i2c.write(addr, cmd, 3); |
phonemacro | 0:6f65cae31c54 | 367 | thread_sleep_for(465); |
phonemacro | 0:6f65cae31c54 | 368 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 369 | i2c.read(addr, rsp, 1); |
phonemacro | 0:6f65cae31c54 | 370 | printf("1.14 status: %x\n", rsp[0]); |
phonemacro | 0:6f65cae31c54 | 371 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 372 | wait_us(300); |
phonemacro | 0:6f65cae31c54 | 373 | |
phonemacro | 0:6f65cae31c54 | 374 | ticker.attach(callback(&fifo_timer), 40ms); |
phonemacro | 0:6f65cae31c54 | 375 | while (1) { |
phonemacro | 0:6f65cae31c54 | 376 | if (Time_to_Read_PPG) { |
phonemacro | 0:6f65cae31c54 | 377 | read_ppg(); |
phonemacro | 0:6f65cae31c54 | 378 | } |
phonemacro | 0:6f65cae31c54 | 379 | } |
phonemacro | 0:6f65cae31c54 | 380 | } |