David Jung
/
MAX32664C_MAXM86146_Mode1_Optical
Mode1 Optical Validation
main.cpp@1:da792e46a385, 2021-03-18 (annotated)
- Committer:
- phonemacro
- Date:
- Thu Mar 18 01:01:42 2021 +0000
- Revision:
- 1:da792e46a385
- Parent:
- 0:6f65cae31c54
- Child:
- 2:563d90a111b3
updated mfio wake
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 | 0:6f65cae31c54 | 39 | #define OB07 1 |
phonemacro | 0:6f65cae31c54 | 40 | #ifdef OB07 |
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 | 0:6f65cae31c54 | 48 | //#define ALGO_SZ 24 // 24 bytes is the algo normal size fifo output |
phonemacro | 0:6f65cae31c54 | 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 | 0:6f65cae31c54 | 82 | int32_t status, opmode, hr, hr_conf, spo2, spo2_conf; |
phonemacro | 0:6f65cae31c54 | 83 | int32_t scnt = 0; // sample set count |
phonemacro | 0:6f65cae31c54 | 84 | int32_t ptr = 0; |
phonemacro | 0:6f65cae31c54 | 85 | int32_t sptr = 0; |
phonemacro | 0:6f65cae31c54 | 86 | |
phonemacro | 1:da792e46a385 | 87 | mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 88 | Time_to_Read_PPG = 0; |
phonemacro | 0:6f65cae31c54 | 89 | #if 0 |
phonemacro | 0:6f65cae31c54 | 90 | // 2.1 |
phonemacro | 0:6f65cae31c54 | 91 | cmd[0] = 0x00; |
phonemacro | 0:6f65cae31c54 | 92 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 93 | i2c.write(addr, cmd, 2); |
phonemacro | 0:6f65cae31c54 | 94 | wait_us(100); |
phonemacro | 0:6f65cae31c54 | 95 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 96 | rsp[1] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 97 | i2c.read(addr, rsp, 2); |
phonemacro | 0:6f65cae31c54 | 98 | // printf("2.1 Status: %x %x\n", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 99 | #endif |
phonemacro | 0:6f65cae31c54 | 100 | // 2.2 |
phonemacro | 0:6f65cae31c54 | 101 | cmd[0] = 0x12; |
phonemacro | 0:6f65cae31c54 | 102 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 103 | i2c.write(addr, cmd, 2); |
phonemacro | 0:6f65cae31c54 | 104 | wait_us(100); |
phonemacro | 0:6f65cae31c54 | 105 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 106 | rsp[1] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 107 | i2c.read(addr, rsp, 2); |
phonemacro | 0:6f65cae31c54 | 108 | // printf("2.2 Status: %x %x\n", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 109 | samples = rsp[1]; |
phonemacro | 0:6f65cae31c54 | 110 | // printf("num samples %d, (num*ttl)+1 %d\n", rsp[1], TTL_SZ*samples+1); |
phonemacro | 0:6f65cae31c54 | 111 | // printf("num smpls %d \n", samples); |
phonemacro | 0:6f65cae31c54 | 112 | scnt = rsp[1]; |
phonemacro | 0:6f65cae31c54 | 113 | // 2.3 |
phonemacro | 0:6f65cae31c54 | 114 | cmd[0] = 0x12; |
phonemacro | 0:6f65cae31c54 | 115 | cmd[1] = 0x01; |
phonemacro | 0:6f65cae31c54 | 116 | i2c.write(addr, cmd, 2); |
phonemacro | 0:6f65cae31c54 | 117 | wait_us(100); |
phonemacro | 0:6f65cae31c54 | 118 | // thread_sleep_for(1); |
phonemacro | 0:6f65cae31c54 | 119 | i2c.read(addr, rsp, 1+(TTL_SZ*samples)); |
phonemacro | 0:6f65cae31c54 | 120 | status = rsp[0]; |
phonemacro | 0:6f65cae31c54 | 121 | |
phonemacro | 0:6f65cae31c54 | 122 | sptr = 1; |
phonemacro | 0:6f65cae31c54 | 123 | for (i = 0; i < scnt; i++) { |
phonemacro | 0:6f65cae31c54 | 124 | // printf("ptr %d ttlsiz %d ", ptr, TTL_SZ); |
phonemacro | 0:6f65cae31c54 | 125 | #ifdef ALGO_ONLY |
phonemacro | 0:6f65cae31c54 | 126 | ptr = sptr; |
phonemacro | 0:6f65cae31c54 | 127 | #else |
phonemacro | 0:6f65cae31c54 | 128 | ptr = sptr + SENSOR_SZ; |
phonemacro | 0:6f65cae31c54 | 129 | #endif |
phonemacro | 0:6f65cae31c54 | 130 | opmode = rsp[ptr]; |
phonemacro | 0:6f65cae31c54 | 131 | hr = (rsp[ptr+1] << 8) + rsp[ptr+2]; |
phonemacro | 0:6f65cae31c54 | 132 | hr_conf = rsp[ptr+3]; |
phonemacro | 0:6f65cae31c54 | 133 | spo2_conf = rsp[ptr+10]; |
phonemacro | 0:6f65cae31c54 | 134 | spo2 = (rsp[ptr+11] << 8) + rsp[ptr+12]; |
phonemacro | 0:6f65cae31c54 | 135 | |
phonemacro | 0:6f65cae31c54 | 136 | sptr += (TTL_SZ); |
phonemacro | 0:6f65cae31c54 | 137 | |
phonemacro | 0:6f65cae31c54 | 138 | // printf("HR %d, HR Conf %d, SpO2 %d, Spo2 Conf %d,", hr, hr_conf, spo2, spo2_conf); |
phonemacro | 0:6f65cae31c54 | 139 | printf("%d, %d, %d, %d,", hr, hr_conf, spo2, spo2_conf); |
phonemacro | 0:6f65cae31c54 | 140 | printf("\n"); |
phonemacro | 0:6f65cae31c54 | 141 | } |
phonemacro | 0:6f65cae31c54 | 142 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 143 | } |
phonemacro | 0:6f65cae31c54 | 144 | |
phonemacro | 0:6f65cae31c54 | 145 | |
phonemacro | 0:6f65cae31c54 | 146 | |
phonemacro | 0:6f65cae31c54 | 147 | int main() |
phonemacro | 0:6f65cae31c54 | 148 | { |
phonemacro | 0:6f65cae31c54 | 149 | i2c.frequency(200000); |
phonemacro | 0:6f65cae31c54 | 150 | char cmd[8], i, j; |
phonemacro | 0:6f65cae31c54 | 151 | char rsp[256]; |
phonemacro | 0:6f65cae31c54 | 152 | int32_t ppg[12]; |
phonemacro | 0:6f65cae31c54 | 153 | |
phonemacro | 0:6f65cae31c54 | 154 | rLED = LED_OFF; |
phonemacro | 0:6f65cae31c54 | 155 | gLED = LED_ON; |
phonemacro | 0:6f65cae31c54 | 156 | bLED = LED_OFF; |
phonemacro | 0:6f65cae31c54 | 157 | Ticker ticker; // calls a callback repeatedly with a timeout |
phonemacro | 0:6f65cae31c54 | 158 | //ticker.attach(callback(&blink_timer), BLINKING_RATE_MS); /* set timer for one second */ |
phonemacro | 0:6f65cae31c54 | 159 | |
phonemacro | 0:6f65cae31c54 | 160 | //========================================== |
phonemacro | 0:6f65cae31c54 | 161 | #if 0 // BL, app switching |
phonemacro | 0:6f65cae31c54 | 162 | // BL |
phonemacro | 0:6f65cae31c54 | 163 | rst = 0; |
phonemacro | 0:6f65cae31c54 | 164 | mfio = 0; |
phonemacro | 0:6f65cae31c54 | 165 | thread_sleep_for(10); |
phonemacro | 0:6f65cae31c54 | 166 | rst = 1; |
phonemacro | 0:6f65cae31c54 | 167 | thread_sleep_for(50); |
phonemacro | 0:6f65cae31c54 | 168 | |
phonemacro | 1:da792e46a385 | 169 | mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 170 | cmd[0] = 0x02; |
phonemacro | 0:6f65cae31c54 | 171 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 172 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 173 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 174 | thread_sleep_for(2); |
phonemacro | 0:6f65cae31c54 | 175 | rsp[0] = 0x00; |
phonemacro | 0:6f65cae31c54 | 176 | rsp[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 177 | i2c.read(addr, rsp, 2); |
phonemacro | 1:da792e46a385 | 178 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 179 | printf("02 00 Status, Operating Mode: %x %x\n", rsp[0], rsp[1]); |
phonemacro | 1:da792e46a385 | 180 | |
phonemacro | 0:6f65cae31c54 | 181 | // rd BL ver |
phonemacro | 0:6f65cae31c54 | 182 | cmd[0] = 0x81; |
phonemacro | 0:6f65cae31c54 | 183 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 184 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 185 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 186 | thread_sleep_for(2); |
phonemacro | 0:6f65cae31c54 | 187 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 188 | rsp[1] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 189 | rsp[2] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 190 | rsp[3] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 191 | i2c.read(addr, rsp, 4); |
phonemacro | 1:da792e46a385 | 192 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 193 | printf("Ver: %d %d %d %d\n", rsp[0], rsp[1], rsp[2], rsp[3]); |
phonemacro | 0:6f65cae31c54 | 194 | |
phonemacro | 0:6f65cae31c54 | 195 | // application |
phonemacro | 0:6f65cae31c54 | 196 | rst = 0; |
phonemacro | 0:6f65cae31c54 | 197 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 198 | thread_sleep_for(10); |
phonemacro | 0:6f65cae31c54 | 199 | rst = 1; |
phonemacro | 0:6f65cae31c54 | 200 | thread_sleep_for(1500); |
phonemacro | 0:6f65cae31c54 | 201 | |
phonemacro | 1:da792e46a385 | 202 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 203 | cmd[0] = 0x02; |
phonemacro | 0:6f65cae31c54 | 204 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 205 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 206 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 207 | rsp[0] = 0x00; |
phonemacro | 0:6f65cae31c54 | 208 | rsp[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 209 | i2c.read(addr, rsp, 2); |
phonemacro | 1:da792e46a385 | 210 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 211 | printf("02 00 Status, Operating Mode: %x %x\n", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 212 | // rd ver |
phonemacro | 0:6f65cae31c54 | 213 | cmd[0] = 0xFF; |
phonemacro | 0:6f65cae31c54 | 214 | cmd[1] = 0x03; |
phonemacro | 0:6f65cae31c54 | 215 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 216 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 217 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 218 | rsp[1] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 219 | rsp[2] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 220 | rsp[3] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 221 | i2c.read(addr, rsp, 4); |
phonemacro | 1:da792e46a385 | 222 | printf("Ver: %d %d %d %d\n", rsp[0], rsp[1], rsp[2], rsp[3]); |
phonemacro | 0:6f65cae31c54 | 223 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 224 | |
phonemacro | 0:6f65cae31c54 | 225 | |
phonemacro | 0:6f65cae31c54 | 226 | // BL |
phonemacro | 0:6f65cae31c54 | 227 | rst = 0; |
phonemacro | 0:6f65cae31c54 | 228 | mfio = 0; |
phonemacro | 0:6f65cae31c54 | 229 | thread_sleep_for(10); |
phonemacro | 0:6f65cae31c54 | 230 | rst = 1; |
phonemacro | 0:6f65cae31c54 | 231 | thread_sleep_for(50); |
phonemacro | 0:6f65cae31c54 | 232 | |
phonemacro | 0:6f65cae31c54 | 233 | cmd[0] = 0x02; |
phonemacro | 0:6f65cae31c54 | 234 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 235 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 236 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 237 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 238 | rsp[1] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 239 | i2c.read(addr, rsp, 2); |
phonemacro | 0:6f65cae31c54 | 240 | printf("02 00 Status, Operating Mode: %x %x\n", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 241 | // rd BL ver |
phonemacro | 1:da792e46a385 | 242 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 243 | cmd[0] = 0x81; |
phonemacro | 0:6f65cae31c54 | 244 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 245 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 246 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 247 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 248 | rsp[1] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 249 | rsp[2] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 250 | rsp[3] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 251 | i2c.read(addr, rsp, 4); |
phonemacro | 0:6f65cae31c54 | 252 | printf("Ver: %d %d %d %d\n", rsp[0], rsp[1], rsp[2], rsp[3]); |
phonemacro | 1:da792e46a385 | 253 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 254 | #endif // end BL app switching |
phonemacro | 0:6f65cae31c54 | 255 | //========================================== |
phonemacro | 0:6f65cae31c54 | 256 | // application |
phonemacro | 0:6f65cae31c54 | 257 | rst = 0; |
phonemacro | 0:6f65cae31c54 | 258 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 259 | thread_sleep_for(10); |
phonemacro | 0:6f65cae31c54 | 260 | rst = 1; |
phonemacro | 0:6f65cae31c54 | 261 | thread_sleep_for(1500); |
phonemacro | 0:6f65cae31c54 | 262 | |
phonemacro | 1:da792e46a385 | 263 | mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 264 | cmd[0] = 0x02; |
phonemacro | 0:6f65cae31c54 | 265 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 266 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 267 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 268 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 269 | rsp[1] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 270 | i2c.read(addr, rsp, 2); |
phonemacro | 1:da792e46a385 | 271 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 272 | printf("02 00 Status, Operating Mode: %x %x\n", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 273 | // rd ver |
phonemacro | 0:6f65cae31c54 | 274 | cmd[0] = 0xFF; |
phonemacro | 0:6f65cae31c54 | 275 | cmd[1] = 0x03; |
phonemacro | 0:6f65cae31c54 | 276 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 277 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 278 | wait_us(300); |
phonemacro | 0:6f65cae31c54 | 279 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 280 | rsp[1] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 281 | rsp[2] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 282 | rsp[3] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 283 | i2c.read(addr, rsp, 4); |
phonemacro | 1:da792e46a385 | 284 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 285 | printf("Ver: %d %d %d %d\n", rsp[0], rsp[1], rsp[2], rsp[3]); |
phonemacro | 0:6f65cae31c54 | 286 | |
phonemacro | 0:6f65cae31c54 | 287 | |
phonemacro | 0:6f65cae31c54 | 288 | // aec mode |
phonemacro | 0:6f65cae31c54 | 289 | // 1.3 sensor and algo data |
phonemacro | 0:6f65cae31c54 | 290 | cmd[0] = 0x10; |
phonemacro | 0:6f65cae31c54 | 291 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 292 | // cmd[2] = 0x03; // sensor + algo data |
phonemacro | 0:6f65cae31c54 | 293 | cmd[2] = 0x02; // algo data |
phonemacro | 0:6f65cae31c54 | 294 | i2c.write(addr, cmd, 3); |
phonemacro | 1:da792e46a385 | 295 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 296 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 297 | i2c.read(addr, rsp, 1); |
phonemacro | 1:da792e46a385 | 298 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 299 | printf("1.3 Status: %x\n", rsp[0]); |
phonemacro | 0:6f65cae31c54 | 300 | //1.11 rd AFE part id |
phonemacro | 0:6f65cae31c54 | 301 | cmd[0] = 0x41; |
phonemacro | 0:6f65cae31c54 | 302 | cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 303 | cmd[2] = 0xFF; |
phonemacro | 0:6f65cae31c54 | 304 | i2c.write(addr, cmd, 3); |
phonemacro | 1:da792e46a385 | 305 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 306 | i2c.read(addr, rsp, 2); |
phonemacro | 1:da792e46a385 | 307 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 308 | printf("1.11 part id afe %x %x\n", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 309 | //1.13 rd accel who |
phonemacro | 0:6f65cae31c54 | 310 | cmd[0] = 0x41; |
phonemacro | 0:6f65cae31c54 | 311 | cmd[1] = 0x04; |
phonemacro | 0:6f65cae31c54 | 312 | cmd[2] = 0x0F; |
phonemacro | 0:6f65cae31c54 | 313 | i2c.write(addr, cmd, 3); |
phonemacro | 1:da792e46a385 | 314 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 315 | i2c.read(addr, rsp, 2); |
phonemacro | 1:da792e46a385 | 316 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 317 | printf("1.12 who accel %x %x\n", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 318 | |
phonemacro | 0:6f65cae31c54 | 319 | //Sec 4.1 map leds to slots for MAXM86146 |
phonemacro | 0:6f65cae31c54 | 320 | cmd[0] = 0x50; |
phonemacro | 0:6f65cae31c54 | 321 | cmd[1] = 0x07; |
phonemacro | 0:6f65cae31c54 | 322 | cmd[2] = 0x19; |
phonemacro | 0:6f65cae31c54 | 323 | cmd[3] = 0x13; |
phonemacro | 0:6f65cae31c54 | 324 | cmd[4] = 0x56; |
phonemacro | 0:6f65cae31c54 | 325 | cmd[5] = 0x00; |
phonemacro | 0:6f65cae31c54 | 326 | i2c.write(addr, cmd, 6); |
phonemacro | 1:da792e46a385 | 327 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 328 | i2c.read(addr, rsp, 1); |
phonemacro | 1:da792e46a385 | 329 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 330 | printf("map leds to slots%x\n", rsp[0]); |
phonemacro | 0:6f65cae31c54 | 331 | // map HR inputs to slots |
phonemacro | 0:6f65cae31c54 | 332 | cmd[0] = 0x50; |
phonemacro | 0:6f65cae31c54 | 333 | cmd[1] = 0x07; |
phonemacro | 0:6f65cae31c54 | 334 | cmd[2] = 0x17; |
phonemacro | 0:6f65cae31c54 | 335 | cmd[3] = 0x00; |
phonemacro | 0:6f65cae31c54 | 336 | cmd[4] = 0x11; |
phonemacro | 0:6f65cae31c54 | 337 | i2c.write(addr, cmd, 5); |
phonemacro | 1:da792e46a385 | 338 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 339 | i2c.read(addr, rsp, 1); |
phonemacro | 1:da792e46a385 | 340 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 341 | printf("map HR to slots/PDs %x\n", rsp[0]); |
phonemacro | 0:6f65cae31c54 | 342 | |
phonemacro | 0:6f65cae31c54 | 343 | // map SpO2 inputs to slots |
phonemacro | 0:6f65cae31c54 | 344 | cmd[0] = 0x50; |
phonemacro | 0:6f65cae31c54 | 345 | cmd[1] = 0x07; |
phonemacro | 0:6f65cae31c54 | 346 | cmd[2] = 0x18; |
phonemacro | 0:6f65cae31c54 | 347 | cmd[3] = 0x30; |
phonemacro | 0:6f65cae31c54 | 348 | cmd[4] = 0x20; |
phonemacro | 0:6f65cae31c54 | 349 | i2c.write(addr, cmd, 5); |
phonemacro | 1:da792e46a385 | 350 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 351 | i2c.read(addr, rsp, 1); |
phonemacro | 1:da792e46a385 | 352 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 353 | printf("map SpO2 to slots/PDs %x\n", rsp[0]); |
phonemacro | 0:6f65cae31c54 | 354 | |
phonemacro | 0:6f65cae31c54 | 355 | // 1.14 |
phonemacro | 0:6f65cae31c54 | 356 | cmd[0] = 0x52; |
phonemacro | 0:6f65cae31c54 | 357 | cmd[1] = 0x07; |
phonemacro | 0:6f65cae31c54 | 358 | cmd[2] = 0x01; |
phonemacro | 0:6f65cae31c54 | 359 | i2c.write(addr, cmd, 3); |
phonemacro | 0:6f65cae31c54 | 360 | thread_sleep_for(465); |
phonemacro | 0:6f65cae31c54 | 361 | rsp[0] = 0xAA; |
phonemacro | 0:6f65cae31c54 | 362 | i2c.read(addr, rsp, 1); |
phonemacro | 0:6f65cae31c54 | 363 | printf("1.14 status: %x\n", rsp[0]); |
phonemacro | 0:6f65cae31c54 | 364 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 365 | wait_us(300); |
phonemacro | 0:6f65cae31c54 | 366 | |
phonemacro | 0:6f65cae31c54 | 367 | ticker.attach(callback(&fifo_timer), 40ms); |
phonemacro | 0:6f65cae31c54 | 368 | while (1) { |
phonemacro | 0:6f65cae31c54 | 369 | if (Time_to_Read_PPG) { |
phonemacro | 0:6f65cae31c54 | 370 | read_ppg(); |
phonemacro | 0:6f65cae31c54 | 371 | } |
phonemacro | 0:6f65cae31c54 | 372 | } |
phonemacro | 0:6f65cae31c54 | 373 | } |