David Jung
/
MAX32664C_MAXM86146_Mode1_Optical
Mode1 Optical Validation
Diff: main.cpp
- Revision:
- 14:c8cc6d7fd5f9
- Parent:
- 13:1baccc6275a7
- Child:
- 15:26dda33c2ef4
--- a/main.cpp Thu Apr 01 18:52:19 2021 +0000 +++ b/main.cpp Thu Apr 01 23:19:40 2021 +0000 @@ -54,7 +54,8 @@ //#define MAX86161_CFG 1 /*****************************************************************************/ -#define ALGO_ONLY 1 // define this if you only want the algo data, comment out if you want raw sensor+algo data +//#define RAW // define this if you only AFE+accel data, no algo +#define ALGO_ONLY 1 // define this if you only want algo data, comment out if you want raw sensor+algo data //#define EXTENDED_ALGO 1 // define this if you want the extended algo format //#define AGC 1 // define this for AGC, otherwise the default is AEC @@ -80,7 +81,11 @@ #ifdef ALGO_ONLY #define TTL_SZ (ALGO_SZ) #else - #define TTL_SZ (PPG_SZ+ACCEL_SZ+ALGO_SZ) + #ifdef RAW + #define TTL_SZ (PPG_SZ+ACCEL_SZ) + #else + #define TTL_SZ (PPG_SZ+ACCEL_SZ+ALGO_SZ) + #endif #endif Serial pc(USBTX, USBRX, 115200); @@ -111,6 +116,9 @@ Time_to_Read_PPG = 1; } +/*****************************************************************************/ +// read_sh_fifo +/*****************************************************************************/ void read_sh_fifo(void) { char cmd[8], i, j, samples; char rsp[3000]; @@ -167,7 +175,18 @@ ppg[4] = (rsp[ptr+12] << 16) | (rsp[ptr+13] << 8) | (rsp[ptr+14]); ppg[5] = (rsp[ptr+15] << 16) | (rsp[ptr+16] << 8) | (rsp[ptr+17]); pc.printf("%d,%d,%d,%d,", ppg[0], ppg[1], ppg[2], ppg[3]); -// pc.printf("%d,%d,", ppg[4], ppg[5]); +#ifdef MAXM86146_CFG +#ifdef RAW + pc.printf("%d,%d,", ppg[4], ppg[5]); + ppg[6] = (rsp[ptr+18] << 16) | (rsp[ptr+19] << 8) | (rsp[ptr+20]); + ppg[7] = (rsp[ptr+21] << 16) | (rsp[ptr+22] << 8) | (rsp[ptr+23]); + ppg[8] = (rsp[ptr+24] << 16) | (rsp[ptr+25] << 8) | (rsp[ptr+26]); + ppg[9] = (rsp[ptr+27] << 16) | (rsp[ptr+28] << 8) | (rsp[ptr+29]); + ppg[10] = (rsp[ptr+30] << 16) | (rsp[ptr+31] << 8) | (rsp[ptr+32]); + ppg[11] = (rsp[ptr+33] << 16) | (rsp[ptr+34] << 8) | (rsp[ptr+35]); + pc.printf("%d,%d,%d,%d,%d,%d,", ppg[6], ppg[7],ppg[8], ppg[9],ppg[10], ppg[11]); +#endif +#endif accel[0] = (rsp[PPG_SZ+0] << 8) | (rsp[PPG_SZ+1]); accel[1] = (rsp[PPG_SZ+2] << 8) | (rsp[PPG_SZ+3]); accel[2] = (rsp[PPG_SZ+4] << 8) | (rsp[PPG_SZ+5]); @@ -175,6 +194,7 @@ ptr = sptr + SENSOR_SZ; #endif +#ifndef RAW #ifdef EXTENDED_ALGO // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ); opmode = rsp[ptr]; @@ -279,7 +299,7 @@ pc.printf("%d,%d,", spo2_unrel, scd); #endif #endif // end normal algo size - +#endif // !RAW pc.printf("\n\r"); } @@ -287,6 +307,9 @@ } #ifdef MAXREFDES103_CFG +/*****************************************************************************/ +// init_max20303_pmic +/*****************************************************************************/ void init_max20303_pmic(void) { /* Wait for pmic to settle down */ thread_sleep_for(800); @@ -311,8 +334,12 @@ } #endif // MAXREFDES103_CFG -void init_sh(void) { - char cmd[8], i, j; + +/*****************************************************************************/ +// init_sh_algo +/*****************************************************************************/ +void init_sh_algo(void) { + char cmd[8]; char rsp[256]; // switch to application mode rst = 0; @@ -414,7 +441,7 @@ mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); sh_i2c.read(SH_ADDR, rsp, 1); mfio = 1; mfio = 0; wait_us(300); - pc.printf("map leds to slots%x\n\r", rsp[0]); + pc.printf("map leds to slots %x\n\r", rsp[0]); //1.21 map HR inputs to slots cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x11; sh_i2c.write(SH_ADDR, cmd, 5); @@ -484,6 +511,144 @@ #endif } +/*****************************************************************************/ +// init_sh_raw +/*****************************************************************************/ +void init_sh_raw(void) { + char cmd[8]; + char rsp[256]; + // switch to application mode + rst = 0; + mfio = 1; + thread_sleep_for(10); + rst = 1; + thread_sleep_for(1500); +#ifdef MAXREFDES103_CFG + init_max20303_pmic(); +#endif + + mfio = 0; wait_us(300); + +//read operating mode + cmd[0] = 0x02; cmd[1] = 0x00; + sh_i2c.write(SH_ADDR, cmd, 2); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 2); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + pc.printf("\n\r 0x02 0x00 Status, Read Operating Mode: %x %x\n\r", rsp[0], rsp[1]); +//1.11 rd ver + cmd[0] = 0xFF; cmd[1] = 0x03; + sh_i2c.write(SH_ADDR, cmd, 2); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 4); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]); + +// raw1.1 sensor data + cmd[0] = 0x10; cmd[1] = 0x00; cmd[2] = 0x01; + pc.printf("raw sensor data only \n\r"); + sh_i2c.write(SH_ADDR, cmd, 3); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 1); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("raw1.1 Status: %x\n\r", rsp[0]); +// raw1.2 interrupt threshold + cmd[0] = 0x10; cmd[1] = 0x01; cmd[2] = 0x01; + sh_i2c.write(SH_ADDR, cmd, 3); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 1); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("raw1.2 Status: %x\n\r", rsp[0]); +// raw1.3 enable sh accel + cmd[0] = 0x44; cmd[1] = 0x04; cmd[2] = 0x01; cmd[3] = 0x00; + sh_i2c.write(SH_ADDR, cmd, 4); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 1); + mfio = 1; thread_sleep_for(20); mfio = 0; wait_us(300); + pc.printf("raw1.3 Status: %x\n\r", rsp[0]); +// raw1.4 enable AFE + cmd[0] = 0x44; cmd[1] = 0x00; cmd[2] = 0x01; cmd[3] = 0x00; + sh_i2c.write(SH_ADDR, cmd, 4); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 1); + mfio = 1; thread_sleep_for(250); mfio = 0; wait_us(300); + pc.printf("raw1.4 Status: %x\n\r", rsp[0]); +// raw1.5 sample rate 100 Hz, ave 1 + cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x18; // set AFE reg 0x12 to 100 Hz +// cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x20; // set AFE reg 0x12 to 200 Hz + sh_i2c.write(SH_ADDR, cmd, 4); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 1); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("raw1.5 Status: %x\n\r", rsp[0]); +// raw1.6 LED1 current + cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x23; cmd[3] = 0x7F; + sh_i2c.write(SH_ADDR, cmd, 4); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 1); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("raw1.6 Status: %x\n\r", rsp[0]); +#ifndef MAXM86146_CFG +// raw1.7 LED2 current + cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x24; cmd[3] = 0x7F; + sh_i2c.write(SH_ADDR, cmd, 4); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 1); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("raw1.7 Status: %x\n\r", rsp[0]); +#endif +// raw1.8 LED3 current + cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x25; cmd[3] = 0x7F; + sh_i2c.write(SH_ADDR, cmd, 4); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 1); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("raw1.8 Status: %x\n\r", rsp[0]); +#ifdef MAXM86146_CFG +// LED5 current + cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x27; cmd[3] = 0x7F; + sh_i2c.write(SH_ADDR, cmd, 4); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 1); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("led5 Status: %x\n\r", rsp[0]); +// LED6 current + cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x27; cmd[3] = 0x7F; + sh_i2c.write(SH_ADDR, cmd, 4); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 1); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("led6 Status: %x\n\r", rsp[0]); + +// Set Seq cntrl1 LED2, LED1 + cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x20; cmd[3] = 0x21; + sh_i2c.write(SH_ADDR, cmd, 4); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 1); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("Seq cntrl1 Status: %x\n\r", rsp[0]); +// Set Seq cntrl2 LED4, LED3 + cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x21; cmd[3] = 0xA3; + sh_i2c.write(SH_ADDR, cmd, 4); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 1); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("Seq cntrl2 Status: %x\n\r", rsp[0]); +// Set Seq cntrl3 LED6, LED5 + cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x22; cmd[3] = 0x21; +// cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x22; cmd[3] = 0x99; // Ambient + sh_i2c.write(SH_ADDR, cmd, 4); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 1); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("Seq cntrl3 Status: %x\n\r", rsp[0]); + +#endif +} + +/*****************************************************************************/ +// main +/*****************************************************************************/ int main() { sh_i2c.frequency(400000); @@ -491,9 +656,11 @@ rLED = LED_OFF; gLED = LED_ON; bLED = LED_OFF; Ticker ticker; // calls a callback repeatedly with a timeout //ticker.attach(callback(&blink_timer), BLINKING_RATE_MS); /* set timer for one second */ - - init_sh(); - +#ifdef RAW + init_sh_raw(); +#else + init_sh_algo(); +#endif #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG) || defined(MAXM86146_CFG) Timer tmr1; while (1) {