David Jung
/
MAX32664C_MAXM86146_Mode1_Optical
Mode1 Optical Validation
main.cpp@4:4f1e9439f048, 2021-03-24 (annotated)
- Committer:
- phonemacro
- Date:
- Wed Mar 24 01:32:34 2021 +0000
- Revision:
- 4:4f1e9439f048
- Parent:
- 3:da975696b936
- Child:
- 5:7f5a012747a5
Updated for MAXREFDES103, MAX86141.
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 | |
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 | 4:4f1e9439f048 | 38 | * Warning, if using the either |
phonemacro | 4:4f1e9439f048 | 39 | * MAX32630FTHR+MAXM86161_ADPTER_REVB+MAXM86146EVSYS sensor brd or |
phonemacro | 4:4f1e9439f048 | 40 | * MAX32630FTHR+MAXM86161_ADPTER_REVB+MAXM86161EVSYS sensor brd, |
phonemacro | 4:4f1e9439f048 | 41 | * The VLED is connected to USB power which is noisy. The VLED should be |
phonemacro | 4:4f1e9439f048 | 42 | * connected to a regulated power supply if you are testing accuracy. |
phonemacro | 4:4f1e9439f048 | 43 | ******************************************************************************* |
phonemacro | 4:4f1e9439f048 | 44 | */ |
phonemacro | 4:4f1e9439f048 | 45 | /****************************************************************************** |
phonemacro | 4:4f1e9439f048 | 46 | * Tera Term output is set to 115200 baud rate. |
phonemacro | 4:4f1e9439f048 | 47 | ******************************************************************************* |
phonemacro | 4:4f1e9439f048 | 48 | */ |
phonemacro | 4:4f1e9439f048 | 49 | //#define MAXM86146_CFG 1 |
phonemacro | 2:563d90a111b3 | 50 | #ifdef MAXM86146_CFG |
phonemacro | 0:6f65cae31c54 | 51 | #define PPG_SZ 36 //maxm86146 |
phonemacro | 0:6f65cae31c54 | 52 | #else |
phonemacro | 0:6f65cae31c54 | 53 | #define PPG_SZ 18 //maxm86161, max86141 |
phonemacro | 0:6f65cae31c54 | 54 | #endif |
phonemacro | 0:6f65cae31c54 | 55 | #define ACCEL_SZ 6 // accel |
phonemacro | 0:6f65cae31c54 | 56 | #define SENSOR_SZ (PPG_SZ+ACCEL_SZ) |
phonemacro | 3:da975696b936 | 57 | //#define ALGO_SZ 20 // 24 bytes is the algo normal size for 3x.12.0 |
phonemacro | 3:da975696b936 | 58 | #define ALGO_SZ 24 // 24 bytes is the algo normal size for 3x.13.x |
phonemacro | 2:563d90a111b3 | 59 | //#define ALGO_ONLY 1 |
phonemacro | 0:6f65cae31c54 | 60 | #ifdef ALGO_ONLY |
phonemacro | 0:6f65cae31c54 | 61 | #define TTL_SZ (ALGO_SZ) |
phonemacro | 0:6f65cae31c54 | 62 | #else |
phonemacro | 0:6f65cae31c54 | 63 | #define TTL_SZ (PPG_SZ+ACCEL_SZ+ALGO_SZ) |
phonemacro | 0:6f65cae31c54 | 64 | #endif |
phonemacro | 0:6f65cae31c54 | 65 | |
phonemacro | 3:da975696b936 | 66 | Serial pc(USBTX, USBRX, 115200); |
phonemacro | 0:6f65cae31c54 | 67 | DigitalOut rLED(LED1); |
phonemacro | 0:6f65cae31c54 | 68 | DigitalOut gLED(LED2); |
phonemacro | 0:6f65cae31c54 | 69 | DigitalOut bLED(LED3); |
phonemacro | 0:6f65cae31c54 | 70 | #define RST_PIN P5_6 |
phonemacro | 0:6f65cae31c54 | 71 | #define MFIO_PIN P5_4 |
phonemacro | 0:6f65cae31c54 | 72 | DigitalOut rst(RST_PIN, PullUp); |
phonemacro | 0:6f65cae31c54 | 73 | DigitalOut mfio(MFIO_PIN, PullUp); |
phonemacro | 0:6f65cae31c54 | 74 | I2C i2c(P3_4, P3_5); |
phonemacro | 0:6f65cae31c54 | 75 | |
phonemacro | 0:6f65cae31c54 | 76 | const int addr = 0xAA;//0x55; |
phonemacro | 0:6f65cae31c54 | 77 | int32_t Time_to_Read_PPG = 0; |
phonemacro | 0:6f65cae31c54 | 78 | |
phonemacro | 0:6f65cae31c54 | 79 | #define BLINKING_RATE_MS 1000ms |
phonemacro | 0:6f65cae31c54 | 80 | void blink_timer(void) { |
phonemacro | 0:6f65cae31c54 | 81 | gLED = !gLED; /* blink the green LED */ |
phonemacro | 0:6f65cae31c54 | 82 | } |
phonemacro | 0:6f65cae31c54 | 83 | |
phonemacro | 0:6f65cae31c54 | 84 | void fifo_timer(void) { |
phonemacro | 0:6f65cae31c54 | 85 | Time_to_Read_PPG = 1; |
phonemacro | 0:6f65cae31c54 | 86 | } |
phonemacro | 0:6f65cae31c54 | 87 | |
phonemacro | 0:6f65cae31c54 | 88 | void read_ppg(void) { |
phonemacro | 0:6f65cae31c54 | 89 | char cmd[8], i, j, samples; |
phonemacro | 0:6f65cae31c54 | 90 | char rsp[3000]; |
phonemacro | 0:6f65cae31c54 | 91 | int32_t ppg[12]; |
phonemacro | 0:6f65cae31c54 | 92 | int32_t accel[3]; |
phonemacro | 4:4f1e9439f048 | 93 | int32_t status, opmode, hr, hr_conf, ibi, ibi_conf, act, r, spo2, spo2_conf; |
phonemacro | 4:4f1e9439f048 | 94 | int32_t spo2_compl, spo2_lo, spo2_mo, spo2_lopi, spo2_unrel, spo2_state, ibi_offset, scd; |
phonemacro | 2:563d90a111b3 | 95 | int32_t scnt = 0; |
phonemacro | 0:6f65cae31c54 | 96 | int32_t ptr = 0; |
phonemacro | 0:6f65cae31c54 | 97 | int32_t sptr = 0; |
phonemacro | 1:da792e46a385 | 98 | mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 99 | Time_to_Read_PPG = 0; |
phonemacro | 0:6f65cae31c54 | 100 | #if 0 |
phonemacro | 0:6f65cae31c54 | 101 | // 2.1 |
phonemacro | 4:4f1e9439f048 | 102 | cmd[0] = 0x00; cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 103 | i2c.write(addr, cmd, 2); |
phonemacro | 0:6f65cae31c54 | 104 | wait_us(100); |
phonemacro | 0:6f65cae31c54 | 105 | i2c.read(addr, rsp, 2); |
phonemacro | 3:da975696b936 | 106 | // pc.printf("2.1 Status: %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 107 | #endif |
phonemacro | 0:6f65cae31c54 | 108 | // 2.2 |
phonemacro | 4:4f1e9439f048 | 109 | cmd[0] = 0x12; cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 110 | i2c.write(addr, cmd, 2); |
phonemacro | 0:6f65cae31c54 | 111 | wait_us(100); |
phonemacro | 0:6f65cae31c54 | 112 | i2c.read(addr, rsp, 2); |
phonemacro | 3:da975696b936 | 113 | // pc.printf("2.2 Status: %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 114 | samples = rsp[1]; |
phonemacro | 3:da975696b936 | 115 | // pc.printf("num samples %d, (num*ttl)+1 %d\n\r", rsp[1], TTL_SZ*samples+1); |
phonemacro | 3:da975696b936 | 116 | // pc.printf("num smpls %d \n\r", samples); |
phonemacro | 0:6f65cae31c54 | 117 | scnt = rsp[1]; |
phonemacro | 0:6f65cae31c54 | 118 | // 2.3 |
phonemacro | 4:4f1e9439f048 | 119 | cmd[0] = 0x12; cmd[1] = 0x01; |
phonemacro | 0:6f65cae31c54 | 120 | i2c.write(addr, cmd, 2); |
phonemacro | 0:6f65cae31c54 | 121 | wait_us(100); |
phonemacro | 0:6f65cae31c54 | 122 | // thread_sleep_for(1); |
phonemacro | 0:6f65cae31c54 | 123 | i2c.read(addr, rsp, 1+(TTL_SZ*samples)); |
phonemacro | 0:6f65cae31c54 | 124 | status = rsp[0]; |
phonemacro | 0:6f65cae31c54 | 125 | |
phonemacro | 0:6f65cae31c54 | 126 | sptr = 1; |
phonemacro | 0:6f65cae31c54 | 127 | for (i = 0; i < scnt; i++) { |
phonemacro | 0:6f65cae31c54 | 128 | #ifdef ALGO_ONLY |
phonemacro | 0:6f65cae31c54 | 129 | ptr = sptr; |
phonemacro | 0:6f65cae31c54 | 130 | #else |
phonemacro | 2:563d90a111b3 | 131 | ptr = sptr; |
phonemacro | 2:563d90a111b3 | 132 | ppg[0] = (rsp[ptr+0] << 16) | (rsp[ptr+1] << 8) | (rsp[ptr+2]); |
phonemacro | 2:563d90a111b3 | 133 | ppg[1] = (rsp[ptr+3] << 16) | (rsp[ptr+4] << 8) | (rsp[ptr+5]); |
phonemacro | 2:563d90a111b3 | 134 | ppg[2] = (rsp[ptr+6] << 16) | (rsp[ptr+7] << 8) | (rsp[ptr+8]); |
phonemacro | 3:da975696b936 | 135 | ppg[3] = (rsp[ptr+9] << 16) | (rsp[ptr+10] << 8) | (rsp[ptr+11]); |
phonemacro | 4:4f1e9439f048 | 136 | ppg[4] = (rsp[ptr+12] << 16) | (rsp[ptr+13] << 8) | (rsp[ptr+14]); |
phonemacro | 4:4f1e9439f048 | 137 | ppg[5] = (rsp[ptr+15] << 16) | (rsp[ptr+16] << 8) | (rsp[ptr+17]); |
phonemacro | 3:da975696b936 | 138 | pc.printf("%d,%d,%d,%d,", ppg[0], ppg[1], ppg[2], ppg[3]); |
phonemacro | 4:4f1e9439f048 | 139 | // pc.printf("%d,%d,", ppg[4], ppg[5]); |
phonemacro | 0:6f65cae31c54 | 140 | ptr = sptr + SENSOR_SZ; |
phonemacro | 0:6f65cae31c54 | 141 | #endif |
phonemacro | 3:da975696b936 | 142 | // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ); |
phonemacro | 0:6f65cae31c54 | 143 | opmode = rsp[ptr]; |
phonemacro | 0:6f65cae31c54 | 144 | hr = (rsp[ptr+1] << 8) + rsp[ptr+2]; |
phonemacro | 0:6f65cae31c54 | 145 | hr_conf = rsp[ptr+3]; |
phonemacro | 3:da975696b936 | 146 | ibi = rsp[ptr+4]; |
phonemacro | 4:4f1e9439f048 | 147 | |
phonemacro | 3:da975696b936 | 148 | ibi_conf = (rsp[ptr+5] << 8) + rsp[ptr+6]; |
phonemacro | 3:da975696b936 | 149 | act = rsp[ptr+7]; |
phonemacro | 3:da975696b936 | 150 | r = (rsp[ptr+8] << 8) + rsp[ptr+9]; |
phonemacro | 0:6f65cae31c54 | 151 | spo2_conf = rsp[ptr+10]; |
phonemacro | 4:4f1e9439f048 | 152 | |
phonemacro | 0:6f65cae31c54 | 153 | spo2 = (rsp[ptr+11] << 8) + rsp[ptr+12]; |
phonemacro | 4:4f1e9439f048 | 154 | spo2_compl = rsp[ptr+13]; |
phonemacro | 4:4f1e9439f048 | 155 | spo2_lo = rsp[ptr+14]; |
phonemacro | 4:4f1e9439f048 | 156 | spo2_mo = rsp[ptr+15]; |
phonemacro | 4:4f1e9439f048 | 157 | |
phonemacro | 4:4f1e9439f048 | 158 | spo2_lopi = rsp[ptr+16]; |
phonemacro | 4:4f1e9439f048 | 159 | spo2_unrel = rsp[ptr+17]; |
phonemacro | 4:4f1e9439f048 | 160 | spo2_state = rsp[ptr+18]; |
phonemacro | 2:563d90a111b3 | 161 | scd = rsp[ptr+19]; |
phonemacro | 0:6f65cae31c54 | 162 | |
phonemacro | 4:4f1e9439f048 | 163 | ibi_offset = rsp[ptr+20]; |
phonemacro | 0:6f65cae31c54 | 164 | |
phonemacro | 4:4f1e9439f048 | 165 | sptr += (TTL_SZ); |
phonemacro | 4:4f1e9439f048 | 166 | #if 0 |
phonemacro | 4:4f1e9439f048 | 167 | pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi); |
phonemacro | 4:4f1e9439f048 | 168 | pc.printf("%d,%d,%d,%d,", ibi_conf, act, r, spo2_conf); |
phonemacro | 4:4f1e9439f048 | 169 | pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo); |
phonemacro | 4:4f1e9439f048 | 170 | pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state, scd); |
phonemacro | 4:4f1e9439f048 | 171 | pc.printf("%d,", ibi_offset); |
phonemacro | 4:4f1e9439f048 | 172 | #else |
phonemacro | 4:4f1e9439f048 | 173 | pc.printf("%d,%d,", hr, hr_conf); |
phonemacro | 4:4f1e9439f048 | 174 | pc.printf("%d,%d,", spo2, spo2_conf); |
phonemacro | 4:4f1e9439f048 | 175 | pc.printf("%d,", spo2_lo); |
phonemacro | 4:4f1e9439f048 | 176 | pc.printf("%d,%d,", spo2_unrel, scd); |
phonemacro | 4:4f1e9439f048 | 177 | #endif |
phonemacro | 4:4f1e9439f048 | 178 | |
phonemacro | 4:4f1e9439f048 | 179 | |
phonemacro | 3:da975696b936 | 180 | pc.printf("\n\r"); |
phonemacro | 0:6f65cae31c54 | 181 | } |
phonemacro | 0:6f65cae31c54 | 182 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 183 | } |
phonemacro | 0:6f65cae31c54 | 184 | |
phonemacro | 0:6f65cae31c54 | 185 | int main() |
phonemacro | 0:6f65cae31c54 | 186 | { |
phonemacro | 3:da975696b936 | 187 | i2c.frequency(400000); |
phonemacro | 0:6f65cae31c54 | 188 | char cmd[8], i, j; |
phonemacro | 0:6f65cae31c54 | 189 | char rsp[256]; |
phonemacro | 0:6f65cae31c54 | 190 | int32_t ppg[12]; |
phonemacro | 3:da975696b936 | 191 | |
phonemacro | 4:4f1e9439f048 | 192 | rLED = LED_OFF; gLED = LED_ON; bLED = LED_OFF; |
phonemacro | 0:6f65cae31c54 | 193 | Ticker ticker; // calls a callback repeatedly with a timeout |
phonemacro | 0:6f65cae31c54 | 194 | //ticker.attach(callback(&blink_timer), BLINKING_RATE_MS); /* set timer for one second */ |
phonemacro | 0:6f65cae31c54 | 195 | |
phonemacro | 0:6f65cae31c54 | 196 | // application |
phonemacro | 0:6f65cae31c54 | 197 | rst = 0; |
phonemacro | 0:6f65cae31c54 | 198 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 199 | thread_sleep_for(10); |
phonemacro | 0:6f65cae31c54 | 200 | rst = 1; |
phonemacro | 0:6f65cae31c54 | 201 | thread_sleep_for(1500); |
phonemacro | 0:6f65cae31c54 | 202 | |
phonemacro | 1:da792e46a385 | 203 | mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 204 | |
phonemacro | 4:4f1e9439f048 | 205 | //read operating mode |
phonemacro | 4:4f1e9439f048 | 206 | cmd[0] = 0x02; cmd[1] = 0x00; |
phonemacro | 0:6f65cae31c54 | 207 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 208 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 209 | i2c.read(addr, rsp, 2); |
phonemacro | 1:da792e46a385 | 210 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 211 | pc.printf("02 00 Status, Operating Mode: %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 4:4f1e9439f048 | 212 | //1.11 rd ver |
phonemacro | 4:4f1e9439f048 | 213 | cmd[0] = 0xFF; cmd[1] = 0x03; |
phonemacro | 0:6f65cae31c54 | 214 | i2c.write(addr, cmd, 2); |
phonemacro | 1:da792e46a385 | 215 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 216 | wait_us(300); |
phonemacro | 0:6f65cae31c54 | 217 | i2c.read(addr, rsp, 4); |
phonemacro | 1:da792e46a385 | 218 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 219 | pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]); |
phonemacro | 0:6f65cae31c54 | 220 | |
phonemacro | 0:6f65cae31c54 | 221 | // 1.3 sensor and algo data |
phonemacro | 4:4f1e9439f048 | 222 | cmd[0] = 0x10; cmd[1] = 0x00; |
phonemacro | 2:563d90a111b3 | 223 | #ifdef ALGO_ONLY |
phonemacro | 0:6f65cae31c54 | 224 | cmd[2] = 0x02; // algo data |
phonemacro | 4:4f1e9439f048 | 225 | pc.printf("algo only \n\r"); |
phonemacro | 2:563d90a111b3 | 226 | #else |
phonemacro | 2:563d90a111b3 | 227 | cmd[2] = 0x03; // sensor + algo data |
phonemacro | 4:4f1e9439f048 | 228 | pc.printf("sens+algo \n\r"); |
phonemacro | 2:563d90a111b3 | 229 | #endif |
phonemacro | 0:6f65cae31c54 | 230 | i2c.write(addr, cmd, 3); |
phonemacro | 1:da792e46a385 | 231 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 232 | i2c.read(addr, rsp, 1); |
phonemacro | 1:da792e46a385 | 233 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 234 | pc.printf("1.3 Status: %x\n\r", rsp[0]); |
phonemacro | 3:da975696b936 | 235 | // 1.7 cont hr, spo2 |
phonemacro | 4:4f1e9439f048 | 236 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0A; cmd[3] = 0x00; |
phonemacro | 3:da975696b936 | 237 | i2c.write(addr, cmd, 4); |
phonemacro | 3:da975696b936 | 238 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 239 | i2c.read(addr, rsp, 1); |
phonemacro | 3:da975696b936 | 240 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 241 | pc.printf("1.7 Status: %x\n\r", rsp[0]); |
phonemacro | 4:4f1e9439f048 | 242 | // 1.8 AEC enable (default) |
phonemacro | 4:4f1e9439f048 | 243 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0B; cmd[3] = 0x01; |
phonemacro | 4:4f1e9439f048 | 244 | i2c.write(addr, cmd, 4); |
phonemacro | 1:da792e46a385 | 245 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 246 | i2c.read(addr, rsp, 1); |
phonemacro | 1:da792e46a385 | 247 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 248 | pc.printf("1.8 Status: %x\n\r", rsp[0]); |
phonemacro | 4:4f1e9439f048 | 249 | // 1.9 auto PD (default |
phonemacro | 4:4f1e9439f048 | 250 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x12; cmd[3] = 0x01; |
phonemacro | 4:4f1e9439f048 | 251 | i2c.write(addr, cmd, 4); |
phonemacro | 1:da792e46a385 | 252 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 253 | i2c.read(addr, rsp, 1); |
phonemacro | 1:da792e46a385 | 254 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 255 | pc.printf("1.9 Status: %x\n\r", rsp[0]); |
phonemacro | 4:4f1e9439f048 | 256 | // 1.10 SCD (default) |
phonemacro | 4:4f1e9439f048 | 257 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0C; cmd[3] = 0x01; |
phonemacro | 4:4f1e9439f048 | 258 | i2c.write(addr, cmd, 4); |
phonemacro | 4:4f1e9439f048 | 259 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 260 | i2c.read(addr, rsp, 1); |
phonemacro | 4:4f1e9439f048 | 261 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 262 | pc.printf("1.7 Status: %x\n\r", rsp[0]); |
phonemacro | 3:da975696b936 | 263 | #ifdef MAXM86146_CFG |
phonemacro | 3:da975696b936 | 264 | //1.20 Sec 4.1 map leds to slots for MAXM86146 |
phonemacro | 4:4f1e9439f048 | 265 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x13; cmd[4] = 0x56; cmd[5] = 0x00; |
phonemacro | 3:da975696b936 | 266 | i2c.write(addr, cmd, 6); |
phonemacro | 3:da975696b936 | 267 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 268 | i2c.read(addr, rsp, 1); |
phonemacro | 3:da975696b936 | 269 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 270 | pc.printf("map leds to slots%x\n\r", rsp[0]); |
phonemacro | 3:da975696b936 | 271 | //1.21 map HR inputs to slots |
phonemacro | 4:4f1e9439f048 | 272 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x11; |
phonemacro | 3:da975696b936 | 273 | i2c.write(addr, cmd, 5); |
phonemacro | 3:da975696b936 | 274 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 275 | i2c.read(addr, rsp, 1); |
phonemacro | 3:da975696b936 | 276 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 277 | pc.printf("map HR to slots/PDs %x\n\r", rsp[0]); |
phonemacro | 3:da975696b936 | 278 | //1.22 map SpO2 inputs to slots |
phonemacro | 4:4f1e9439f048 | 279 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x30; cmd[4] = 0x20; |
phonemacro | 3:da975696b936 | 280 | i2c.write(addr, cmd, 5); |
phonemacro | 3:da975696b936 | 281 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 282 | i2c.read(addr, rsp, 1); |
phonemacro | 3:da975696b936 | 283 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 284 | pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]); |
phonemacro | 3:da975696b936 | 285 | #if 0 |
phonemacro | 2:563d90a111b3 | 286 | //1.20 Sec 4.1 map leds to slots for MAXM86146 |
phonemacro | 4:4f1e9439f048 | 287 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x15; cmd[4] = 0x60; cmd[5] = 0x00; |
phonemacro | 0:6f65cae31c54 | 288 | i2c.write(addr, cmd, 6); |
phonemacro | 1:da792e46a385 | 289 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 290 | i2c.read(addr, rsp, 1); |
phonemacro | 1:da792e46a385 | 291 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 292 | pc.printf("map leds to slots%x\n\r", rsp[0]); |
phonemacro | 2:563d90a111b3 | 293 | //1.21 map HR inputs to slots |
phonemacro | 4:4f1e9439f048 | 294 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x01; |
phonemacro | 0:6f65cae31c54 | 295 | i2c.write(addr, cmd, 5); |
phonemacro | 1:da792e46a385 | 296 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 297 | i2c.read(addr, rsp, 1); |
phonemacro | 1:da792e46a385 | 298 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 299 | pc.printf("map HR to slots/PDs %x\n\r", rsp[0]); |
phonemacro | 2:563d90a111b3 | 300 | //1.22 map SpO2 inputs to slots |
phonemacro | 4:4f1e9439f048 | 301 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x20; cmd[4] = 0x10; |
phonemacro | 0:6f65cae31c54 | 302 | i2c.write(addr, cmd, 5); |
phonemacro | 1:da792e46a385 | 303 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 304 | i2c.read(addr, rsp, 1); |
phonemacro | 1:da792e46a385 | 305 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 306 | pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]); |
phonemacro | 3:da975696b936 | 307 | #endif |
phonemacro | 3:da975696b936 | 308 | #endif // MAXM86146_CFG |
phonemacro | 0:6f65cae31c54 | 309 | |
phonemacro | 4:4f1e9439f048 | 310 | // 1.3 Enable HR, SpO2 algo |
phonemacro | 4:4f1e9439f048 | 311 | cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x01; |
phonemacro | 0:6f65cae31c54 | 312 | i2c.write(addr, cmd, 3); |
phonemacro | 0:6f65cae31c54 | 313 | thread_sleep_for(465); |
phonemacro | 0:6f65cae31c54 | 314 | i2c.read(addr, rsp, 1); |
phonemacro | 3:da975696b936 | 315 | pc.printf("1.14 status: %x\n\r", rsp[0]); |
phonemacro | 0:6f65cae31c54 | 316 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 317 | |
phonemacro | 4:4f1e9439f048 | 318 | #if 1 |
phonemacro | 4:4f1e9439f048 | 319 | //1.31 rd AFE part id |
phonemacro | 4:4f1e9439f048 | 320 | cmd[0] = 0x41; cmd[1] = 0x00; cmd[2] = 0xFF; |
phonemacro | 4:4f1e9439f048 | 321 | i2c.write(addr, cmd, 3); |
phonemacro | 4:4f1e9439f048 | 322 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 323 | i2c.read(addr, rsp, 2); |
phonemacro | 4:4f1e9439f048 | 324 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 325 | pc.printf("1.31 part id afe %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 4:4f1e9439f048 | 326 | //1.32 rd accel who |
phonemacro | 4:4f1e9439f048 | 327 | cmd[0] = 0x41; cmd[1] = 0x04; cmd[2] = 0x0F; |
phonemacro | 4:4f1e9439f048 | 328 | i2c.write(addr, cmd, 3); |
phonemacro | 4:4f1e9439f048 | 329 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 330 | i2c.read(addr, rsp, 2); |
phonemacro | 4:4f1e9439f048 | 331 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 332 | pc.printf("1.32 who accel %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 4:4f1e9439f048 | 333 | #endif |
phonemacro | 4:4f1e9439f048 | 334 | |
phonemacro | 3:da975696b936 | 335 | ticker.attach(callback(&fifo_timer), 0.040f); |
phonemacro | 3:da975696b936 | 336 | // Timer tmr1; |
phonemacro | 0:6f65cae31c54 | 337 | while (1) { |
phonemacro | 4:4f1e9439f048 | 338 | read_ppg(); |
phonemacro | 0:6f65cae31c54 | 339 | if (Time_to_Read_PPG) { |
phonemacro | 0:6f65cae31c54 | 340 | } |
phonemacro | 0:6f65cae31c54 | 341 | } |
phonemacro | 0:6f65cae31c54 | 342 | } |