Mode1 Optical Validation

Dependencies:   max32630fthr

Revision:
21:67d58af1ec56
Parent:
20:7fc26287beb7
Child:
22:f6b366c3b954
diff -r 7fc26287beb7 -r 67d58af1ec56 main.cpp
--- a/main.cpp	Tue Jun 15 23:15:34 2021 +0000
+++ b/main.cpp	Thu Jun 17 20:46:18 2021 +0000
@@ -51,12 +51,14 @@
 
 /*****************************************************************************/
 // define one and only one of the following three platforms
-//#define MAXM86146_CFG 1  // tested on MAXM86146EVSYS_sensorBrd+MAXM86161_ADAPTER_REVB+MAX32630FTHR
-//#define MAXREFDES103_CFG
-#define MAXM86161_CFG 1  // tested on MAXM86161+MAX32630FTHR+v32.9.22, 32.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
 /*****************************************************************************/
+#if defined(MAXM86161_CFG) // || defined(MAXM86146_CFG)  // don't need 3.3V for MAXM86146EVSYS_sensorBrd+MAXM86161_ADAPTER_REVB+MAX32630FTHR
 #include "max32630fthr.h"
 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); // Enable J1-pin2, 3.3V and set GPIO to 3.3v
+#endif
 //#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
@@ -75,7 +77,7 @@
 #define ACCEL_SZ 6  // accel
 #define SENSOR_SZ (PPG_SZ+ACCEL_SZ)
 
-//#define old_msbl 1 // 3x.12.0
+//#define old_msbl 1 // 3x.12.0 or earlier
 #ifdef old_msbl
   #ifdef EXTENDED_ALGO
     #define ALGO_SZ 52  // 52 bytes is the extended algo size for 3x.12.0
@@ -84,9 +86,9 @@
   #endif
 #else
   #ifdef EXTENDED_ALGO
-    #define ALGO_SZ 56  // 56 bytes is the extended algo size for 3x.13.x
+    #define ALGO_SZ 56  // 56 bytes is the extended algo size for 3x.13.x+
   #else
-    #define ALGO_SZ 24  // 24 bytes is the algo normal size for 3x.13.x
+    #define ALGO_SZ 24  // 24 bytes is the algo normal size for 3x.13.x+
   #endif
 #endif
 
@@ -152,15 +154,19 @@
 // 2.1
     cmd[0] = 0x00; cmd[1] = 0x00;
     sh_i2c.write(SH_ADDR, cmd, 2);
-    wait_us(100);
+    mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
+//    wait_us(100);
     sh_i2c.read(SH_ADDR, rsp, 2);
+    mfio = 1; mfio = 0; wait_us(300);
 //    pc.printf("2.1 Status: %x %x\n\r", rsp[0], rsp[1]);
 #endif
 // 2.2
     cmd[0] = 0x12; cmd[1] = 0x00;
     sh_i2c.write(SH_ADDR, cmd, 2);
-    wait_us(100);
+    mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
+//    wait_us(100);
     sh_i2c.read(SH_ADDR, rsp, 2);
+    mfio = 1; mfio = 0; wait_us(300);
 //    pc.printf("2.2 Status: %x %x\n\r", rsp[0], rsp[1]);
     samples = rsp[1];
 //    pc.printf("num samples %d, (num*ttl)+1 %d\n\r",  rsp[1], TTL_SZ*samples+1);
@@ -169,9 +175,13 @@
 // 2.3
     cmd[0] = 0x12; cmd[1] = 0x01;
     sh_i2c.write(SH_ADDR, cmd, 2);
-    wait_us(100);
+    mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);
+//    wait_us(100);
 //    thread_sleep_for(1);
     sh_i2c.read(SH_ADDR, rsp, 1+(TTL_SZ*samples));
+    mfio = 1; mfio = 0; wait_us(300);
+//    mfio = 1;
+
         status = rsp[0];
 
         sptr = 1;
@@ -315,7 +325,6 @@
 
             pc.printf("\n\r");
         }
-        mfio = 1;
 }
 
 #ifdef MAXREFDES103_CFG
@@ -362,7 +371,7 @@
 #ifdef MAXREFDES103_CFG
     init_max20303_pmic();
 #endif
-#if defined(MAXM86161_CFG)  // 32.13.12+ needs extra delay
+#if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG) || defined(MAXM86146_CFG)  // 32.13.19+
     thread_sleep_for(250);
 #endif