David Jung
/
MAX32664C_MAXM86146_Mode1_Optical
Mode1 Optical Validation
Diff: main.cpp
- Revision:
- 28:315604f4b374
- Parent:
- 27:a45d6e38f2de
- Child:
- 29:a7dd81450b35
--- a/main.cpp Wed Jun 23 22:05:36 2021 +0000 +++ b/main.cpp Mon Oct 11 23:11:33 2021 +0000 @@ -37,7 +37,7 @@ /****************************************************************************** * https://os.mbed.com/users/phonemacro/code/MAX32664C_Example_Host_Code * Tera Term output is set to 115200 baud rate. -* ver: 210622 +* ver: 211011 ******************************************************************************/ /****************************************************************************** @@ -51,9 +51,9 @@ /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/ // define one and only one of the following three platforms -#define MAXM86146_CFG 1 // tested on MAXM86146EVSYS_sensorBrd+MAXM86161_ADAPTER_REVB+MAX32630FTHR 33.13.12 +//#define MAXM86146_CFG 1 // tested on MAXM86146EVSYS_sensorBrd+MAXM86161_ADAPTER_REVB+MAX32630FTHR 33.13.12 //#define MAXREFDES103_CFG // not tested -//#define MAXM86161_CFG 1 // tested on MAXM86161+MAX32630FTHR v32.9.22, 32.13.12 +#define MAXM86161_CFG 1 // tested on MAXM86161+MAX32630FTHR v32.9.22, 32.13.12 /*****************************************************************************/ /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/ @@ -102,7 +102,9 @@ #define ACCEL_SZ 6 // accel #define SENSOR_SZ (PPG_SZ+ACCEL_SZ) -//#define old_msbl 1 // 3x.12.0 or earlier +#if defined(MAXM86161_CFG) +#define old_msbl 1 // 3x.12.0 or earlier; 32.9.x +#endif #ifdef old_msbl #ifdef EXTENDED_ALGO #define ALGO_SZ 52 // 52 bytes is the extended algo size for 3x.12.0 @@ -151,7 +153,7 @@ // read_sh_fifo /*****************************************************************************/ /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/ -//#define OPTIMIZE_FIFO_READ 1 // Assume that the FIFO is filled at the specified rate, so just periodically check then number of samples in the FIFO to save power +#define OPTIMIZE_FIFO_READ 1 // Assume that the FIFO is filled at the specified rate, so just periodically check then number of samples in the FIFO to save power #ifdef OPTIMIZE_FIFO_READ // tested on MAXM86146EVSYS int32_t check_fifo_countdown; #define MAX_FIFO_CNT 20 @@ -383,7 +385,7 @@ /* Wait for pmic to settle down */ thread_sleep_for(200); - + } #endif // MAXREFDES103_CFG @@ -428,8 +430,8 @@ mfio = 1; mfio = 0; wait_us(300); pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]); -#if 0 -// algo sz +#if defined(MAXM86161_CFG) +// algo sz normal cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x01; sh_i2c.write(SH_ADDR, cmd, 3); mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); @@ -437,7 +439,7 @@ mfio = 1; mfio = 0; wait_us(300); pc.printf("algo size: %d %d \n\r", rsp[0], rsp[1]); -// algo sz +// algo sz extended cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x02; sh_i2c.write(SH_ADDR, cmd, 3); mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); @@ -445,7 +447,7 @@ mfio = 1; mfio = 0; wait_us(300); pc.printf("algo size: %d %d \n\r", rsp[0], rsp[1]); -// algo sz +// algo sz scd cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x03; sh_i2c.write(SH_ADDR, cmd, 3); mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); @@ -530,6 +532,31 @@ mfio = 1; mfio = 0; wait_us(300); pc.printf("1.7 Status: %x\n\r", rsp[0]); #endif + +#if defined(MAXM86161_CFG) //only use Red and IR +//1.20 Sec 4.1 map leds to slots for MAXM86146 + cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x23; cmd[4] = 0x00; cmd[5] = 0x00; + sh_i2c.write(SH_ADDR, cmd, 6); + 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]); +//1.21 map HR inputs to slots + cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x17; cmd[3] = 0x00; cmd[4] = 0x73; + sh_i2c.write(SH_ADDR, cmd, 5); + 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 HR to slots/PDs %x\n\r", rsp[0]); +//1.22 map SpO2 inputs to slots + cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x18; cmd[3] = 0x00; cmd[4] = 0x10; + sh_i2c.write(SH_ADDR, cmd, 5); + 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 SpO2 to slots/PDs %x\n\r", rsp[0]); +#endif + #ifdef MAXM86146_CFG //1.20 Sec 4.1 map leds to slots for MAXM86146 cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x13; cmd[4] = 0x56; cmd[5] = 0x00; @@ -578,6 +605,25 @@ #endif #endif // MAXM86146_CFG + +#if 0 // MAXM86161 test new commands +// LDO enable + cmd[0] = 0x10; cmd[1] = 0x12; cmd[2] = 0x01; + //cmd[0] = 0x10; cmd[1] = 0x12; cmd[2] = 0x00; + sh_i2c.write(SH_ADDR, cmd, 3); + thread_sleep_for(2); + sh_i2c.read(SH_ADDR, rsp, 1); + pc.printf("\n\r ldo en %x\n\r", rsp[0]); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); +// GPIO enable + cmd[0] = 0x10; cmd[1] = 0x13; cmd[2] = 0x01; + sh_i2c.write(SH_ADDR, cmd, 3); + thread_sleep_for(2); + sh_i2c.read(SH_ADDR, rsp, 1); + pc.printf("\n\r gpio en %x\n\r", rsp[0]); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); +#endif + // 1.3 Enable HR, SpO2 algo #ifdef EXTENDED_ALGO cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x02; @@ -585,10 +631,9 @@ cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x01; #endif sh_i2c.write(SH_ADDR, cmd, 3); - mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + mfio = 1; thread_sleep_for(465); - thread_sleep_for(465); - mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + mfio = 0; wait_us(300); sh_i2c.read(SH_ADDR, rsp, 1); pc.printf("1.14 status: %x\n\r", rsp[0]); @@ -607,9 +652,8 @@ sh_i2c.read(SH_ADDR, rsp, 2); mfio = 1; mfio = 0; wait_us(300); pc.printf("1.32 who accel %x %x\n\r", rsp[0], rsp[1]); - +#endif mfio = 1; -#endif } /*****************************************************************************/ @@ -745,7 +789,8 @@ pc.printf("Seq cntrl3 Status: %x\n\r", rsp[0]); #endif -} +mfio = 1; +} /*****************************************************************************/ // main @@ -756,17 +801,32 @@ int32_t ledcnt = 0; rLED = LED_OFF; gLED = LED_ON; bLED = LED_OFF; Ticker ticker; // calls a callback repeatedly with a timeout + +#if 0 // test disable algo + char cmd[8]; + char rsp[256]; + // 3.1 Disable algo + mfio = 1; mfio = 0; wait_us(300); + cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x00; + sh_i2c.write(SH_ADDR, cmd, 3); + thread_sleep_for(465); + sh_i2c.read(SH_ADDR, rsp, 1); + pc.printf("3.1 disable algo: %x\n\r", rsp[0]); + mfio = 1; +#endif + //ticker.attach(callback(&blink_timer), BLINKING_RATE_MS); /* set timer for one second */ #ifdef RAW init_sh_raw(); #else init_sh_algo(); #endif + mfio = 1; #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG) || defined(MAXM86146_CFG) Timer tmr1; while (1) { tmr1.start(); - if (tmr1.read_ms() > 40) { + if (tmr1.read_ms() >= 40) { tmr1.reset(); read_sh_fifo(); if ((ledcnt++ % 50) == 0)