David Jung
/
MAX32664C_MAXM86146_Mode1_Optical
Mode1 Optical Validation
main.cpp@10:192ea88e964b, 2021-03-26 (annotated)
- Committer:
- phonemacro
- Date:
- Fri Mar 26 21:32:42 2021 +0000
- Revision:
- 10:192ea88e964b
- Parent:
- 9:12720bbacfe2
- Child:
- 11:a16b6bf38841
move sh initialization to init_sh
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 | 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 | 6:e1b7190d6cb5 | 47 | * ver: 210325 |
phonemacro | 5:7f5a012747a5 | 48 | ******************************************************************************/ |
phonemacro | 5:7f5a012747a5 | 49 | |
phonemacro | 6:e1b7190d6cb5 | 50 | /*****************************************************************************/ |
phonemacro | 6:e1b7190d6cb5 | 51 | // define one and only one of the following three platforms |
phonemacro | 10:192ea88e964b | 52 | //#define MAXM86146_CFG 1 // tested on MAXM86146EVSYS_sensorBrd+MAXM86161_ADAPTER_REVB+MAX32630FTHR |
phonemacro | 10:192ea88e964b | 53 | #define MAXREFDES103_CFG // tested on MAXREFDES103 |
phonemacro | 6:e1b7190d6cb5 | 54 | //#define MAX86161_CFG 1 |
phonemacro | 6:e1b7190d6cb5 | 55 | /*****************************************************************************/ |
phonemacro | 6:e1b7190d6cb5 | 56 | |
phonemacro | 6:e1b7190d6cb5 | 57 | #define ALGO_ONLY 1 // define this if you only want the algo data, comment out if you want raw sensor+algo data |
phonemacro | 6:e1b7190d6cb5 | 58 | |
phonemacro | 6:e1b7190d6cb5 | 59 | |
phonemacro | 6:e1b7190d6cb5 | 60 | #ifdef MAXREFDES103_CFG |
phonemacro | 5:7f5a012747a5 | 61 | #include "MAX20303.h" |
phonemacro | 6:e1b7190d6cb5 | 62 | I2C sh_i2c_pmic(P5_7, P6_0); |
phonemacro | 5:7f5a012747a5 | 63 | #endif |
phonemacro | 5:7f5a012747a5 | 64 | |
phonemacro | 2:563d90a111b3 | 65 | #ifdef MAXM86146_CFG |
phonemacro | 0:6f65cae31c54 | 66 | #define PPG_SZ 36 //maxm86146 |
phonemacro | 0:6f65cae31c54 | 67 | #else |
phonemacro | 0:6f65cae31c54 | 68 | #define PPG_SZ 18 //maxm86161, max86141 |
phonemacro | 0:6f65cae31c54 | 69 | #endif |
phonemacro | 0:6f65cae31c54 | 70 | #define ACCEL_SZ 6 // accel |
phonemacro | 0:6f65cae31c54 | 71 | #define SENSOR_SZ (PPG_SZ+ACCEL_SZ) |
phonemacro | 3:da975696b936 | 72 | //#define ALGO_SZ 20 // 24 bytes is the algo normal size for 3x.12.0 |
phonemacro | 3:da975696b936 | 73 | #define ALGO_SZ 24 // 24 bytes is the algo normal size for 3x.13.x |
phonemacro | 0:6f65cae31c54 | 74 | #ifdef ALGO_ONLY |
phonemacro | 0:6f65cae31c54 | 75 | #define TTL_SZ (ALGO_SZ) |
phonemacro | 0:6f65cae31c54 | 76 | #else |
phonemacro | 0:6f65cae31c54 | 77 | #define TTL_SZ (PPG_SZ+ACCEL_SZ+ALGO_SZ) |
phonemacro | 0:6f65cae31c54 | 78 | #endif |
phonemacro | 0:6f65cae31c54 | 79 | |
phonemacro | 3:da975696b936 | 80 | Serial pc(USBTX, USBRX, 115200); |
phonemacro | 0:6f65cae31c54 | 81 | DigitalOut rLED(LED1); |
phonemacro | 0:6f65cae31c54 | 82 | DigitalOut gLED(LED2); |
phonemacro | 0:6f65cae31c54 | 83 | DigitalOut bLED(LED3); |
phonemacro | 5:7f5a012747a5 | 84 | /****************************************************************************** |
phonemacro | 5:7f5a012747a5 | 85 | * MAX32630FTHR GPIOs |
phonemacro | 5:7f5a012747a5 | 86 | ******************************************************************************/ |
phonemacro | 0:6f65cae31c54 | 87 | #define RST_PIN P5_6 |
phonemacro | 0:6f65cae31c54 | 88 | #define MFIO_PIN P5_4 |
phonemacro | 0:6f65cae31c54 | 89 | DigitalOut rst(RST_PIN, PullUp); |
phonemacro | 0:6f65cae31c54 | 90 | DigitalOut mfio(MFIO_PIN, PullUp); |
phonemacro | 6:e1b7190d6cb5 | 91 | I2C sh_i2c(P3_4, P3_5); |
phonemacro | 6:e1b7190d6cb5 | 92 | |
phonemacro | 6:e1b7190d6cb5 | 93 | //#define thread_sleep_for(x) wait_ms(x) // for older versions of mbed |
phonemacro | 0:6f65cae31c54 | 94 | |
phonemacro | 5:7f5a012747a5 | 95 | |
phonemacro | 6:e1b7190d6cb5 | 96 | const int SH_ADDR = 0xAA;//0x55; |
phonemacro | 0:6f65cae31c54 | 97 | int32_t Time_to_Read_PPG = 0; |
phonemacro | 0:6f65cae31c54 | 98 | |
phonemacro | 0:6f65cae31c54 | 99 | #define BLINKING_RATE_MS 1000ms |
phonemacro | 0:6f65cae31c54 | 100 | void blink_timer(void) { |
phonemacro | 0:6f65cae31c54 | 101 | gLED = !gLED; /* blink the green LED */ |
phonemacro | 0:6f65cae31c54 | 102 | } |
phonemacro | 0:6f65cae31c54 | 103 | |
phonemacro | 0:6f65cae31c54 | 104 | void fifo_timer(void) { |
phonemacro | 0:6f65cae31c54 | 105 | Time_to_Read_PPG = 1; |
phonemacro | 0:6f65cae31c54 | 106 | } |
phonemacro | 0:6f65cae31c54 | 107 | |
phonemacro | 10:192ea88e964b | 108 | void read_sh_fifo(void) { |
phonemacro | 0:6f65cae31c54 | 109 | char cmd[8], i, j, samples; |
phonemacro | 0:6f65cae31c54 | 110 | char rsp[3000]; |
phonemacro | 0:6f65cae31c54 | 111 | int32_t ppg[12]; |
phonemacro | 5:7f5a012747a5 | 112 | int16_t accel[3]; |
phonemacro | 4:4f1e9439f048 | 113 | int32_t status, opmode, hr, hr_conf, ibi, ibi_conf, act, r, spo2, spo2_conf; |
phonemacro | 4:4f1e9439f048 | 114 | int32_t spo2_compl, spo2_lo, spo2_mo, spo2_lopi, spo2_unrel, spo2_state, ibi_offset, scd; |
phonemacro | 2:563d90a111b3 | 115 | int32_t scnt = 0; |
phonemacro | 0:6f65cae31c54 | 116 | int32_t ptr = 0; |
phonemacro | 0:6f65cae31c54 | 117 | int32_t sptr = 0; |
phonemacro | 1:da792e46a385 | 118 | mfio = 0; wait_us(300); |
phonemacro | 0:6f65cae31c54 | 119 | Time_to_Read_PPG = 0; |
phonemacro | 0:6f65cae31c54 | 120 | #if 0 |
phonemacro | 0:6f65cae31c54 | 121 | // 2.1 |
phonemacro | 4:4f1e9439f048 | 122 | cmd[0] = 0x00; cmd[1] = 0x00; |
phonemacro | 6:e1b7190d6cb5 | 123 | sh_i2c.write(SH_ADDR, cmd, 2); |
phonemacro | 0:6f65cae31c54 | 124 | wait_us(100); |
phonemacro | 6:e1b7190d6cb5 | 125 | sh_i2c.read(SH_ADDR, rsp, 2); |
phonemacro | 3:da975696b936 | 126 | // pc.printf("2.1 Status: %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 127 | #endif |
phonemacro | 0:6f65cae31c54 | 128 | // 2.2 |
phonemacro | 4:4f1e9439f048 | 129 | cmd[0] = 0x12; cmd[1] = 0x00; |
phonemacro | 6:e1b7190d6cb5 | 130 | sh_i2c.write(SH_ADDR, cmd, 2); |
phonemacro | 0:6f65cae31c54 | 131 | wait_us(100); |
phonemacro | 6:e1b7190d6cb5 | 132 | sh_i2c.read(SH_ADDR, rsp, 2); |
phonemacro | 3:da975696b936 | 133 | // pc.printf("2.2 Status: %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 0:6f65cae31c54 | 134 | samples = rsp[1]; |
phonemacro | 3:da975696b936 | 135 | // pc.printf("num samples %d, (num*ttl)+1 %d\n\r", rsp[1], TTL_SZ*samples+1); |
phonemacro | 3:da975696b936 | 136 | // pc.printf("num smpls %d \n\r", samples); |
phonemacro | 0:6f65cae31c54 | 137 | scnt = rsp[1]; |
phonemacro | 0:6f65cae31c54 | 138 | // 2.3 |
phonemacro | 4:4f1e9439f048 | 139 | cmd[0] = 0x12; cmd[1] = 0x01; |
phonemacro | 6:e1b7190d6cb5 | 140 | sh_i2c.write(SH_ADDR, cmd, 2); |
phonemacro | 0:6f65cae31c54 | 141 | wait_us(100); |
phonemacro | 0:6f65cae31c54 | 142 | // thread_sleep_for(1); |
phonemacro | 6:e1b7190d6cb5 | 143 | sh_i2c.read(SH_ADDR, rsp, 1+(TTL_SZ*samples)); |
phonemacro | 0:6f65cae31c54 | 144 | status = rsp[0]; |
phonemacro | 5:7f5a012747a5 | 145 | |
phonemacro | 0:6f65cae31c54 | 146 | sptr = 1; |
phonemacro | 0:6f65cae31c54 | 147 | for (i = 0; i < scnt; i++) { |
phonemacro | 0:6f65cae31c54 | 148 | #ifdef ALGO_ONLY |
phonemacro | 0:6f65cae31c54 | 149 | ptr = sptr; |
phonemacro | 0:6f65cae31c54 | 150 | #else |
phonemacro | 2:563d90a111b3 | 151 | ptr = sptr; |
phonemacro | 2:563d90a111b3 | 152 | ppg[0] = (rsp[ptr+0] << 16) | (rsp[ptr+1] << 8) | (rsp[ptr+2]); |
phonemacro | 2:563d90a111b3 | 153 | ppg[1] = (rsp[ptr+3] << 16) | (rsp[ptr+4] << 8) | (rsp[ptr+5]); |
phonemacro | 2:563d90a111b3 | 154 | ppg[2] = (rsp[ptr+6] << 16) | (rsp[ptr+7] << 8) | (rsp[ptr+8]); |
phonemacro | 3:da975696b936 | 155 | ppg[3] = (rsp[ptr+9] << 16) | (rsp[ptr+10] << 8) | (rsp[ptr+11]); |
phonemacro | 4:4f1e9439f048 | 156 | ppg[4] = (rsp[ptr+12] << 16) | (rsp[ptr+13] << 8) | (rsp[ptr+14]); |
phonemacro | 4:4f1e9439f048 | 157 | ppg[5] = (rsp[ptr+15] << 16) | (rsp[ptr+16] << 8) | (rsp[ptr+17]); |
phonemacro | 3:da975696b936 | 158 | pc.printf("%d,%d,%d,%d,", ppg[0], ppg[1], ppg[2], ppg[3]); |
phonemacro | 4:4f1e9439f048 | 159 | // pc.printf("%d,%d,", ppg[4], ppg[5]); |
phonemacro | 5:7f5a012747a5 | 160 | accel[0] = (rsp[PPG_SZ+0] << 8) | (rsp[PPG_SZ+1]); |
phonemacro | 5:7f5a012747a5 | 161 | accel[1] = (rsp[PPG_SZ+2] << 8) | (rsp[PPG_SZ+3]); |
phonemacro | 5:7f5a012747a5 | 162 | accel[2] = (rsp[PPG_SZ+4] << 8) | (rsp[PPG_SZ+5]); |
phonemacro | 5:7f5a012747a5 | 163 | pc.printf("%d,%d,%d,", accel[0], accel[1], accel[2]); |
phonemacro | 5:7f5a012747a5 | 164 | |
phonemacro | 0:6f65cae31c54 | 165 | ptr = sptr + SENSOR_SZ; |
phonemacro | 0:6f65cae31c54 | 166 | #endif |
phonemacro | 3:da975696b936 | 167 | // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ); |
phonemacro | 0:6f65cae31c54 | 168 | opmode = rsp[ptr]; |
phonemacro | 0:6f65cae31c54 | 169 | hr = (rsp[ptr+1] << 8) + rsp[ptr+2]; |
phonemacro | 0:6f65cae31c54 | 170 | hr_conf = rsp[ptr+3]; |
phonemacro | 3:da975696b936 | 171 | ibi = rsp[ptr+4]; |
phonemacro | 4:4f1e9439f048 | 172 | |
phonemacro | 3:da975696b936 | 173 | ibi_conf = (rsp[ptr+5] << 8) + rsp[ptr+6]; |
phonemacro | 3:da975696b936 | 174 | act = rsp[ptr+7]; |
phonemacro | 3:da975696b936 | 175 | r = (rsp[ptr+8] << 8) + rsp[ptr+9]; |
phonemacro | 0:6f65cae31c54 | 176 | spo2_conf = rsp[ptr+10]; |
phonemacro | 4:4f1e9439f048 | 177 | |
phonemacro | 0:6f65cae31c54 | 178 | spo2 = (rsp[ptr+11] << 8) + rsp[ptr+12]; |
phonemacro | 4:4f1e9439f048 | 179 | spo2_compl = rsp[ptr+13]; |
phonemacro | 4:4f1e9439f048 | 180 | spo2_lo = rsp[ptr+14]; |
phonemacro | 4:4f1e9439f048 | 181 | spo2_mo = rsp[ptr+15]; |
phonemacro | 4:4f1e9439f048 | 182 | |
phonemacro | 4:4f1e9439f048 | 183 | spo2_lopi = rsp[ptr+16]; |
phonemacro | 4:4f1e9439f048 | 184 | spo2_unrel = rsp[ptr+17]; |
phonemacro | 4:4f1e9439f048 | 185 | spo2_state = rsp[ptr+18]; |
phonemacro | 2:563d90a111b3 | 186 | scd = rsp[ptr+19]; |
phonemacro | 0:6f65cae31c54 | 187 | |
phonemacro | 4:4f1e9439f048 | 188 | ibi_offset = rsp[ptr+20]; |
phonemacro | 0:6f65cae31c54 | 189 | |
phonemacro | 4:4f1e9439f048 | 190 | sptr += (TTL_SZ); |
phonemacro | 4:4f1e9439f048 | 191 | #if 0 |
phonemacro | 4:4f1e9439f048 | 192 | pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi); |
phonemacro | 4:4f1e9439f048 | 193 | pc.printf("%d,%d,%d,%d,", ibi_conf, act, r, spo2_conf); |
phonemacro | 4:4f1e9439f048 | 194 | pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo); |
phonemacro | 4:4f1e9439f048 | 195 | pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state, scd); |
phonemacro | 4:4f1e9439f048 | 196 | pc.printf("%d,", ibi_offset); |
phonemacro | 4:4f1e9439f048 | 197 | #else |
phonemacro | 4:4f1e9439f048 | 198 | pc.printf("%d,%d,", hr, hr_conf); |
phonemacro | 4:4f1e9439f048 | 199 | pc.printf("%d,%d,", spo2, spo2_conf); |
phonemacro | 4:4f1e9439f048 | 200 | pc.printf("%d,", spo2_lo); |
phonemacro | 4:4f1e9439f048 | 201 | pc.printf("%d,%d,", spo2_unrel, scd); |
phonemacro | 4:4f1e9439f048 | 202 | #endif |
phonemacro | 4:4f1e9439f048 | 203 | |
phonemacro | 4:4f1e9439f048 | 204 | |
phonemacro | 3:da975696b936 | 205 | pc.printf("\n\r"); |
phonemacro | 0:6f65cae31c54 | 206 | } |
phonemacro | 0:6f65cae31c54 | 207 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 208 | } |
phonemacro | 0:6f65cae31c54 | 209 | |
phonemacro | 6:e1b7190d6cb5 | 210 | #ifdef MAXREFDES103_CFG |
phonemacro | 6:e1b7190d6cb5 | 211 | void init_max20303_pmic(void) { |
phonemacro | 5:7f5a012747a5 | 212 | /* Wait for pmic to settle down */ |
phonemacro | 5:7f5a012747a5 | 213 | thread_sleep_for(800); |
phonemacro | 5:7f5a012747a5 | 214 | |
phonemacro | 5:7f5a012747a5 | 215 | //set_time(1544787300); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
phonemacro | 6:e1b7190d6cb5 | 216 | MAX20303 max20303(&sh_i2c); |
phonemacro | 5:7f5a012747a5 | 217 | /*Set LDO1 to 1.8v*/ |
phonemacro | 5:7f5a012747a5 | 218 | max20303.LDO1Config(); |
phonemacro | 5:7f5a012747a5 | 219 | |
phonemacro | 5:7f5a012747a5 | 220 | /*Set LDO2 to 3v*/ |
phonemacro | 5:7f5a012747a5 | 221 | max20303.LDO2Config(); |
phonemacro | 5:7f5a012747a5 | 222 | |
phonemacro | 5:7f5a012747a5 | 223 | //max20303.BoostEnable(); |
phonemacro | 5:7f5a012747a5 | 224 | max20303.BuckBoostEnable(); |
phonemacro | 5:7f5a012747a5 | 225 | |
phonemacro | 5:7f5a012747a5 | 226 | max20303.led0on(0); |
phonemacro | 5:7f5a012747a5 | 227 | max20303.led1on(0); |
phonemacro | 5:7f5a012747a5 | 228 | max20303.led2on(0); |
phonemacro | 5:7f5a012747a5 | 229 | |
phonemacro | 5:7f5a012747a5 | 230 | /* Wait for pmic to settle down */ |
phonemacro | 5:7f5a012747a5 | 231 | thread_sleep_for(200); |
phonemacro | 6:e1b7190d6cb5 | 232 | |
phonemacro | 5:7f5a012747a5 | 233 | } |
phonemacro | 6:e1b7190d6cb5 | 234 | #endif // MAXREFDES103_CFG |
phonemacro | 10:192ea88e964b | 235 | void init_sh(void) { |
phonemacro | 0:6f65cae31c54 | 236 | char cmd[8], i, j; |
phonemacro | 0:6f65cae31c54 | 237 | char rsp[256]; |
phonemacro | 10:192ea88e964b | 238 | // switch to application mode |
phonemacro | 0:6f65cae31c54 | 239 | rst = 0; |
phonemacro | 0:6f65cae31c54 | 240 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 241 | thread_sleep_for(10); |
phonemacro | 0:6f65cae31c54 | 242 | rst = 1; |
phonemacro | 0:6f65cae31c54 | 243 | thread_sleep_for(1500); |
phonemacro | 10:192ea88e964b | 244 | #ifdef MAXREFDES103_CFG |
phonemacro | 10:192ea88e964b | 245 | init_max20303_pmic(); |
phonemacro | 10:192ea88e964b | 246 | #endif |
phonemacro | 0:6f65cae31c54 | 247 | |
phonemacro | 1:da792e46a385 | 248 | mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 249 | |
phonemacro | 4:4f1e9439f048 | 250 | //read operating mode |
phonemacro | 4:4f1e9439f048 | 251 | cmd[0] = 0x02; cmd[1] = 0x00; |
phonemacro | 6:e1b7190d6cb5 | 252 | sh_i2c.write(SH_ADDR, cmd, 2); |
phonemacro | 1:da792e46a385 | 253 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 254 | sh_i2c.read(SH_ADDR, rsp, 2); |
phonemacro | 6:e1b7190d6cb5 | 255 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 256 | pc.printf("\n\r 0x02 0x00 Status, Read Operating Mode: %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 5:7f5a012747a5 | 257 | //1.11 rd ver |
phonemacro | 4:4f1e9439f048 | 258 | cmd[0] = 0xFF; cmd[1] = 0x03; |
phonemacro | 6:e1b7190d6cb5 | 259 | sh_i2c.write(SH_ADDR, cmd, 2); |
phonemacro | 1:da792e46a385 | 260 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 261 | sh_i2c.read(SH_ADDR, rsp, 4); |
phonemacro | 1:da792e46a385 | 262 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 263 | pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]); |
phonemacro | 0:6f65cae31c54 | 264 | |
phonemacro | 0:6f65cae31c54 | 265 | // 1.3 sensor and algo data |
phonemacro | 4:4f1e9439f048 | 266 | cmd[0] = 0x10; cmd[1] = 0x00; |
phonemacro | 2:563d90a111b3 | 267 | #ifdef ALGO_ONLY |
phonemacro | 0:6f65cae31c54 | 268 | cmd[2] = 0x02; // algo data |
phonemacro | 4:4f1e9439f048 | 269 | pc.printf("algo only \n\r"); |
phonemacro | 2:563d90a111b3 | 270 | #else |
phonemacro | 2:563d90a111b3 | 271 | cmd[2] = 0x03; // sensor + algo data |
phonemacro | 4:4f1e9439f048 | 272 | pc.printf("sens+algo \n\r"); |
phonemacro | 2:563d90a111b3 | 273 | #endif |
phonemacro | 6:e1b7190d6cb5 | 274 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 1:da792e46a385 | 275 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 276 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 1:da792e46a385 | 277 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 278 | pc.printf("1.3 Status: %x\n\r", rsp[0]); |
phonemacro | 3:da975696b936 | 279 | // 1.7 cont hr, spo2 |
phonemacro | 4:4f1e9439f048 | 280 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0A; cmd[3] = 0x00; |
phonemacro | 6:e1b7190d6cb5 | 281 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 3:da975696b936 | 282 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 283 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 3:da975696b936 | 284 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 285 | pc.printf("1.7 Status: %x\n\r", rsp[0]); |
phonemacro | 4:4f1e9439f048 | 286 | // 1.8 AEC enable (default) |
phonemacro | 4:4f1e9439f048 | 287 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0B; cmd[3] = 0x01; |
phonemacro | 6:e1b7190d6cb5 | 288 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 1:da792e46a385 | 289 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 290 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 1:da792e46a385 | 291 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 292 | pc.printf("1.8 Status: %x\n\r", rsp[0]); |
phonemacro | 4:4f1e9439f048 | 293 | // 1.9 auto PD (default |
phonemacro | 4:4f1e9439f048 | 294 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x12; cmd[3] = 0x01; |
phonemacro | 6:e1b7190d6cb5 | 295 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 1:da792e46a385 | 296 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 297 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 1:da792e46a385 | 298 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 299 | pc.printf("1.9 Status: %x\n\r", rsp[0]); |
phonemacro | 4:4f1e9439f048 | 300 | // 1.10 SCD (default) |
phonemacro | 4:4f1e9439f048 | 301 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x0C; cmd[3] = 0x01; |
phonemacro | 6:e1b7190d6cb5 | 302 | sh_i2c.write(SH_ADDR, cmd, 4); |
phonemacro | 4:4f1e9439f048 | 303 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 304 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 4:4f1e9439f048 | 305 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 306 | pc.printf("1.7 Status: %x\n\r", rsp[0]); |
phonemacro | 3:da975696b936 | 307 | #ifdef MAXM86146_CFG |
phonemacro | 3:da975696b936 | 308 | //1.20 Sec 4.1 map leds to slots for MAXM86146 |
phonemacro | 4:4f1e9439f048 | 309 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x13; cmd[4] = 0x56; cmd[5] = 0x00; |
phonemacro | 6:e1b7190d6cb5 | 310 | sh_i2c.write(SH_ADDR, cmd, 6); |
phonemacro | 3:da975696b936 | 311 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 312 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 3:da975696b936 | 313 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 314 | pc.printf("map leds to slots%x\n\r", rsp[0]); |
phonemacro | 3:da975696b936 | 315 | //1.21 map HR inputs to slots |
phonemacro | 4:4f1e9439f048 | 316 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x11; |
phonemacro | 6:e1b7190d6cb5 | 317 | sh_i2c.write(SH_ADDR, cmd, 5); |
phonemacro | 3:da975696b936 | 318 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 319 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 3:da975696b936 | 320 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 321 | pc.printf("map HR to slots/PDs %x\n\r", rsp[0]); |
phonemacro | 3:da975696b936 | 322 | //1.22 map SpO2 inputs to slots |
phonemacro | 4:4f1e9439f048 | 323 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x30; cmd[4] = 0x20; |
phonemacro | 6:e1b7190d6cb5 | 324 | sh_i2c.write(SH_ADDR, cmd, 5); |
phonemacro | 3:da975696b936 | 325 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 326 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 3:da975696b936 | 327 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 328 | pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]); |
phonemacro | 3:da975696b936 | 329 | #if 0 |
phonemacro | 2:563d90a111b3 | 330 | //1.20 Sec 4.1 map leds to slots for MAXM86146 |
phonemacro | 4:4f1e9439f048 | 331 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x15; cmd[4] = 0x60; cmd[5] = 0x00; |
phonemacro | 6:e1b7190d6cb5 | 332 | sh_i2c.write(SH_ADDR, cmd, 6); |
phonemacro | 1:da792e46a385 | 333 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 334 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 1:da792e46a385 | 335 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 336 | pc.printf("map leds to slots%x\n\r", rsp[0]); |
phonemacro | 2:563d90a111b3 | 337 | //1.21 map HR inputs to slots |
phonemacro | 4:4f1e9439f048 | 338 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x01; |
phonemacro | 6:e1b7190d6cb5 | 339 | sh_i2c.write(SH_ADDR, cmd, 5); |
phonemacro | 1:da792e46a385 | 340 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 341 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 1:da792e46a385 | 342 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 343 | pc.printf("map HR to slots/PDs %x\n\r", rsp[0]); |
phonemacro | 2:563d90a111b3 | 344 | //1.22 map SpO2 inputs to slots |
phonemacro | 4:4f1e9439f048 | 345 | cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x20; cmd[4] = 0x10; |
phonemacro | 6:e1b7190d6cb5 | 346 | sh_i2c.write(SH_ADDR, cmd, 5); |
phonemacro | 1:da792e46a385 | 347 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 348 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 1:da792e46a385 | 349 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 3:da975696b936 | 350 | pc.printf("map SpO2 to slots/PDs %x\n\r", rsp[0]); |
phonemacro | 3:da975696b936 | 351 | #endif |
phonemacro | 3:da975696b936 | 352 | #endif // MAXM86146_CFG |
phonemacro | 0:6f65cae31c54 | 353 | |
phonemacro | 4:4f1e9439f048 | 354 | // 1.3 Enable HR, SpO2 algo |
phonemacro | 4:4f1e9439f048 | 355 | cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x01; |
phonemacro | 6:e1b7190d6cb5 | 356 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 0:6f65cae31c54 | 357 | thread_sleep_for(465); |
phonemacro | 6:e1b7190d6cb5 | 358 | sh_i2c.read(SH_ADDR, rsp, 1); |
phonemacro | 3:da975696b936 | 359 | pc.printf("1.14 status: %x\n\r", rsp[0]); |
phonemacro | 0:6f65cae31c54 | 360 | mfio = 1; |
phonemacro | 0:6f65cae31c54 | 361 | |
phonemacro | 4:4f1e9439f048 | 362 | #if 1 |
phonemacro | 4:4f1e9439f048 | 363 | //1.31 rd AFE part id |
phonemacro | 4:4f1e9439f048 | 364 | cmd[0] = 0x41; cmd[1] = 0x00; cmd[2] = 0xFF; |
phonemacro | 6:e1b7190d6cb5 | 365 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 4:4f1e9439f048 | 366 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 367 | sh_i2c.read(SH_ADDR, rsp, 2); |
phonemacro | 4:4f1e9439f048 | 368 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 369 | pc.printf("1.31 part id afe %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 4:4f1e9439f048 | 370 | //1.32 rd accel who |
phonemacro | 4:4f1e9439f048 | 371 | cmd[0] = 0x41; cmd[1] = 0x04; cmd[2] = 0x0F; |
phonemacro | 6:e1b7190d6cb5 | 372 | sh_i2c.write(SH_ADDR, cmd, 3); |
phonemacro | 4:4f1e9439f048 | 373 | mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); |
phonemacro | 6:e1b7190d6cb5 | 374 | sh_i2c.read(SH_ADDR, rsp, 2); |
phonemacro | 4:4f1e9439f048 | 375 | mfio = 1; mfio = 0; wait_us(300); |
phonemacro | 4:4f1e9439f048 | 376 | pc.printf("1.32 who accel %x %x\n\r", rsp[0], rsp[1]); |
phonemacro | 4:4f1e9439f048 | 377 | #endif |
phonemacro | 10:192ea88e964b | 378 | } |
phonemacro | 10:192ea88e964b | 379 | |
phonemacro | 10:192ea88e964b | 380 | int main() |
phonemacro | 10:192ea88e964b | 381 | { |
phonemacro | 10:192ea88e964b | 382 | sh_i2c.frequency(400000); |
phonemacro | 10:192ea88e964b | 383 | int32_t ledcnt = 0; |
phonemacro | 10:192ea88e964b | 384 | rLED = LED_OFF; gLED = LED_ON; bLED = LED_OFF; |
phonemacro | 10:192ea88e964b | 385 | Ticker ticker; // calls a callback repeatedly with a timeout |
phonemacro | 10:192ea88e964b | 386 | //ticker.attach(callback(&blink_timer), BLINKING_RATE_MS); /* set timer for one second */ |
phonemacro | 10:192ea88e964b | 387 | |
phonemacro | 10:192ea88e964b | 388 | init_sh(); |
phonemacro | 4:4f1e9439f048 | 389 | |
phonemacro | 8:e6ae69cfecbf | 390 | #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG) || defined(MAXM86146_CFG) |
phonemacro | 6:e1b7190d6cb5 | 391 | Timer tmr1; |
phonemacro | 0:6f65cae31c54 | 392 | while (1) { |
phonemacro | 6:e1b7190d6cb5 | 393 | tmr1.start(); |
phonemacro | 6:e1b7190d6cb5 | 394 | if (tmr1.read_ms() > 40) { |
phonemacro | 7:23b067817ab8 | 395 | tmr1.reset(); |
phonemacro | 10:192ea88e964b | 396 | read_sh_fifo(); |
phonemacro | 7:23b067817ab8 | 397 | if ((ledcnt++ % 50) == 0) |
phonemacro | 6:e1b7190d6cb5 | 398 | gLED = !gLED; |
phonemacro | 0:6f65cae31c54 | 399 | } |
phonemacro | 0:6f65cae31c54 | 400 | } |
phonemacro | 6:e1b7190d6cb5 | 401 | #else |
phonemacro | 6:e1b7190d6cb5 | 402 | ticker.attach(callback(&fifo_timer), 0.040f); |
phonemacro | 6:e1b7190d6cb5 | 403 | while (1) { |
phonemacro | 6:e1b7190d6cb5 | 404 | if (Time_to_Read_PPG) { |
phonemacro | 10:192ea88e964b | 405 | read_sh_fifo(); |
phonemacro | 7:23b067817ab8 | 406 | if ((ledcnt++ % 50) == 0) |
phonemacro | 6:e1b7190d6cb5 | 407 | gLED = !gLED; |
phonemacro | 6:e1b7190d6cb5 | 408 | } |
phonemacro | 6:e1b7190d6cb5 | 409 | } |
phonemacro | 6:e1b7190d6cb5 | 410 | #endif |
phonemacro | 0:6f65cae31c54 | 411 | } |