Mode1 Optical Validation

Dependencies:   max32630fthr

Revision:
50:dd2f60ab5686
Parent:
49:ead542a403a3
Child:
51:e2214db671c0
diff -r ead542a403a3 -r dd2f60ab5686 main.cpp
--- a/main.cpp	Fri Apr 29 22:13:24 2022 +0000
+++ b/main.cpp	Tue May 03 02:06:40 2022 +0000
@@ -84,11 +84,14 @@
 #endif
 
 /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/
-// comment the three below if you want raw sensor+algo data
-//#define ALGO_ONLY 1  // define this if you only want algo data
+// comment the two below if you want raw sensor+algo data
+#define ALGO_ONLY 1  // define this if you only want algo data
 //#define RAW  // define this if you want AFE+accel data, no algorithm, tested on 33.13.31
-  //#define RAW_HZ 256   // Raw data rate
-  #define RAW_HZ 100   // Raw data rate
+  //#define RAW_HZ 25   // Raw data rate
+  #define RAW_HZ 50   // Raw data rate
+  //#define RAW_HZ 100   // Raw data rate
+  //#define RAW_HZ 200   // Raw data rate
+  //#define RAW_HZ 2004   // Raw data rate 200 Hz, ave 4
 //#define SPO2_CAL_RPT 1
 
 // Comment out both of the below for Normal Algorithm Samples Format
@@ -97,6 +100,7 @@
 //#define PCK_CFG_MASK  1 // define this and the above if you want to config mask out some of the packed data, 33.13.31
 //#define AGC 1 // define this for AGC, otherwise the default is AEC
 
+#define USE_SYN 1
 
 //#define REDUCE_RPT_PERIOD 0x19  // Report samples every 25 frame.
 //#define USE_FIFO_BUFFER_CNT 5  // Allow the FIFO to accumulate this many samples
@@ -214,7 +218,7 @@
     // tested w/ 33.13.12 don't need 2.1
 #endif
 // 2.2
-#if defined(PACKED_NORMAL_ALGO)
+#if defined(PACKED_NORMAL_ALGO) || defined(USE_SYN)
         cmd[0] = 0x20; 
         sh_i2c.write(SH_ADDR, cmd, 1);
 #else
@@ -236,7 +240,7 @@
 #endif
 
 // 2.3
-#if defined(PACKED_NORMAL_ALGO)
+#if defined(PACKED_NORMAL_ALGO) || defined(USE_SYN)
         cmd[0] = 0x21;;
         sh_i2c.write(SH_ADDR, cmd, 1);
 #else
@@ -263,18 +267,21 @@
             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]);
 #if defined(RAW) || defined(SPO2_CAL_RPT)
-   pc.printf("%d,%d,", ppg[4], ppg[5]);
+  #if RAW_HZ <= 100
+            pc.printf("%d,%d,", ppg[4], ppg[5]);
+  #endif
 #endif 
 #ifdef MAXM86146_CFG
 #if defined(RAW) || defined(SPO2_CAL_RPT)
-            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]);
+  #if RAW_HZ <= 100
             pc.printf("%d,%d,%d,%d,%d,%d,", ppg[6], ppg[7],ppg[8], ppg[9],ppg[10], ppg[11]);
+  #endif
 #endif  // raw
 #endif  // MAXM86146_CFG
             accel[0] = (rsp[1+PPG_SZ+0] << 8) | (rsp[1+PPG_SZ+1]);
@@ -892,14 +899,38 @@
     sh_i2c.read(SH_ADDR, rsp, 1);
     mfio = 1; mfio = 0; wait_us(300);
     pc.printf("raw1.3 Status: %x\n\r", rsp[0]);
-// raw1.4 enable sh accel
+#ifdef MAXM86146_CFG
+//1.20   map leds to slots for MAXM86146
+    cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x19; cmd[3] = 0x13; cmd[4] = 0x56; 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] = 0x11;
+    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] = 0x30; cmd[4] = 0x20;
+    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
+
+// raw 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(20); mfio = 0; wait_us(300);
     sh_i2c.read(SH_ADDR, rsp, 1);
     mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
     pc.printf("raw1.4 Status: %x\n\r", rsp[0]);
-// raw1.6 enable AFE
+// raw enable AFE
 //    cmd[0] = 0x44; cmd[1] = 0x00; cmd[2] = 0x01; cmd[3] = 0x00; 
 //    sh_i2c.write(SH_ADDR, cmd, 4);
     cmd[0] = 0x44; cmd[1] = 0x00; cmd[2] = 0x01;  // 3 bytes // tested on 33.13.31/12
@@ -911,76 +942,84 @@
     mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
     pc.printf("raw1.6 Status: %x\n\r", rsp[0]);
 
-// raw1.7 rd accel WHO reg
+/// raw 1.20  AFE part id
+    cmd[0] = 0x41; cmd[1] = 0x00; cmd[2] = 0xFF;
+    sh_i2c.write(SH_ADDR, cmd, 3);
+    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("raw1.6 part id Status: %x %x\n\r", rsp[0], rsp[1]);
+// raw1.21 rd accel WHO reg
     cmd[0] = 0x41; cmd[1] = 0x04; cmd[2] = 0x0F;
     sh_i2c.write(SH_ADDR, cmd, 3);
     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("1.7 Who Status: %x %x\n\r", rsp[0], rsp[1]);
-// rd1.6  AFE part id
-    cmd[0] = 0x41; cmd[1] = 0x00; cmd[2] = 0xFF;
-    sh_i2c.write(SH_ADDR, cmd, 3);
-    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("raw1.6 part id Status: %x %x\n\r", rsp[0], rsp[1]);
 
-// raw1.8 sample rate 100 Hz, ave 1
-#if RAW_HZ == 100
+// raw1.8 sample rate 
+#if RAW_HZ == 25
+    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x00;  // set AFE reg 0x12 to 25 Hz, ave 1
+#elif RAW_HZ == 50
+    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x40;  // set AFE reg 0x12 to 50 Hz
+#elif RAW_HZ == 100
     cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x18;  // set AFE reg 0x12 to 100 Hz
-#elif RAW_HZ == 256
-    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x78;  // set AFE reg 0x12 to 256 Hz
+#elif RAW_HZ == 200
+    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x20;  // set AFE reg 0x12 to 200 Hz
+#elif RAW_HZ == 2004
+    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x22;  // set AFE reg 0x12 to 200 Hz, ave 4
 #else
     cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x18;  // set AFE reg 0x12 to 100 Hz
 #endif
-//    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x12; cmd[3] = 0x00;  // set AFE reg 0x12 to 25 Hz
-    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.8 Status: %x\n\r", rsp[0]);
-// raw1.9 LED1 current
-    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x23; cmd[3] = 0x3F;
+//  LED1 current
+    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x23; cmd[3] = 0x19;
     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.9 Status: %x\n\r", rsp[0]);
-#ifndef MAXM86146_CFG
-// raw1.10 LED2 current
-    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x24; cmd[3] = 0x3F;
+    pc.printf("LED1 Status: %x\n\r", rsp[0]);
+//  LED2 current
+    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x24; cmd[3] = 0x19;
+    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("LED2 Status: %x\n\r", rsp[0]);
+//  LED3 current
+    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x25; cmd[3] = 0x19;
     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.10 Status: %x\n\r", rsp[0]);
-#endif
-// raw1.11 LED3 current
-    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x25; cmd[3] = 0x3F;
+    pc.printf("LED3 Status: %x\n\r", rsp[0]);
+//  LED4 current
+    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x26; cmd[3] = 0x19;
     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.11 Status: %x\n\r", rsp[0]);
-#ifdef MAXM86146_CFG
+    pc.printf("LED4 Status: %x\n\r", rsp[0]);
 //       LED5 current
-    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x27; cmd[3] = 0x7F;
+    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x27; cmd[3] = 0x19;
     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]);
+    pc.printf("LED5 Status: %x\n\r", rsp[0]);
 //       LED6 current
-    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x27; cmd[3] = 0x7F;
+    cmd[0] = 0x40; cmd[1] = 0x00; cmd[2] = 0x28; cmd[3] = 0x19;
     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]);
-
+    pc.printf("LED6 Status: %x\n\r", rsp[0]);
+#if 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);
@@ -1003,7 +1042,6 @@
     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
 mfio = 1;
 }
@@ -1044,10 +1082,14 @@
     while (1) {
         tmr1.start();
 #if defined(RAW) 
-  #if RAW_HZ == 100
+  #if RAW_HZ == 25
+        if (tmr1.read_ms() >= 40) {
+  #elif RAW_HZ == 50
+        if (tmr1.read_ms() >= 20) {
+  #elif RAW_HZ == 100
         if (tmr1.read_ms() >= 10) {
-  #elif RAW_HZ == 256
-        if (tmr1.read_ms() >= 4) {
+  #elif RAW_HZ == 200 || RAW_HZ == 2004
+        if (tmr1.read_ms() >= 5) {
   #else
         if (tmr1.read_ms() >= 10) {
   #endif