Mode1 Optical Validation

Dependencies:   max32630fthr

Revision:
42:6f980909371f
Parent:
41:950ace6b4ce9
Child:
43:81a5371eeb7e
--- a/main.cpp	Wed Apr 06 03:21:41 2022 +0000
+++ b/main.cpp	Fri Apr 08 20:12:45 2022 +0000
@@ -93,6 +93,10 @@
 //#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 REDUCE_RPT_PERIOD 0x19  // Report samples every 25 frame.
+//#define USE_FIFO_BUFFER_CNT 5  // Allow the FIFO to fill this many samples
+
 #ifdef MAXREFDES103_CFG
 #include "MAX20303.h"
 I2C sh_i2c_pmic(P5_7, P6_0);
@@ -116,7 +120,7 @@
   #elif defined(PACKED_NORMAL_ALGO)
     #define ALGO_SZ 16  // 16 bytes, packed algo normal size for 33.31.31
   #else
-    #define ALGO_SZ 1  // 20 bytes, normal algo size for 3x.12.0
+    #define ALGO_SZ 20  // 20 bytes, normal algo size for 3x.12.0
   #endif
 #else
   #ifdef EXTENDED_ALGO
@@ -166,8 +170,9 @@
 #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
+    #define MAX_FIFO_CNT 20   // Only send the 0x00 0x00 (step 2.0), and 0x12 0x00 (step 2.1) commands every MAX_FIFO_CNT frames.
 #endif
+
 void read_sh_fifo(void) {
     char cmd[8], i, j, k, samples;
     char rsp[3000];
@@ -181,15 +186,16 @@
 #endif
     int32_t act, r, spo2, spo2_conf;
     int32_t spo2_compl, spo2_lo, spo2_mo, spo2_lopi, spo2_unrel, spo2_state, ibi_offset, scd, inappro_ori;
-    int32_t scnt = 0;
     int32_t ptr = 0;
     int32_t sptr = 0;
     mfio = 0; wait_us(300);
     Time_to_Read_PPG = 0;
+    samples = 1;
+#ifdef USE_FIFO_BUFFER_CNT
+    samples = USE_FIFO_BUFFER_CNT;
+#endif
 #if defined(OPTIMIZE_FIFO_READ)
     check_fifo_countdown--;
-    samples = 1;
-    scnt = 1;
     if (check_fifo_countdown == 0) {
 #endif
 
@@ -219,7 +225,6 @@
         samples = rsp[1];
 //      pc.printf("num samples %d, (num*ttl)+1 %d\n\r",  rsp[1], TTL_SZ*samples+1);
 //      pc.printf("num smpls %d \n\r",  samples);
-        scnt = rsp[1];
 #if defined(OPTIMIZE_FIFO_READ)
     }
     if (check_fifo_countdown <= 0)
@@ -236,13 +241,14 @@
 #endif
         wait_us(100);
         sh_i2c.read(SH_ADDR, rsp, 1+(TTL_SZ*samples));
+        //pc.printf("num smpls %d ttlsiz %d\n\r",  samples, TTL_SZ);
 //    mfio = 1; mfio = 0; wait_us(300);
         mfio = 1;
 
         status = rsp[0];
 
         sptr = 1;
-        for (i = 0; i < scnt; i++) {
+        for (i = 0; i < samples; i++) {
             ptr = sptr;
 #if !defined(ALGO_ONLY)
             ppg[0] = (rsp[ptr+0] << 16) | (rsp[ptr+1] << 8) | (rsp[ptr+2]);
@@ -557,7 +563,15 @@
     sh_i2c.read(SH_ADDR, rsp, 13);
     mfio = 1; mfio = 0; wait_us(300);
     pc.printf("%x SpO2 Coeff %2X%2X%2X%2X  %2X%2X%2X%2X %2X%2X%2X%2X\n\r", rsp[0], rsp[1], rsp[2], rsp[3], rsp[4], rsp[5], rsp[6], rsp[7], rsp[8], rsp[9], rsp[10], rsp[11], rsp[12]);
-
+#ifdef REDUCE_RPT_PERIOD
+//Change report period to 25
+    cmd[0] = 0x10; cmd[1] = 0x02; cmd[2] = REDUCE_RPT_PERIOD; 
+    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("Wr report period 25 %x\n\r", rsp[0]);
+#endif
 //1.9 rd ver
     cmd[0] = 0xFF; cmd[1] = 0x03;
     sh_i2c.write(SH_ADDR, cmd, 2);
@@ -1018,7 +1032,19 @@
 #if defined(RAW) 
         if (tmr1.read_ms() >= 10) {
 #else
+  #ifdef REDUCE_RPT_PERIOD
+    #ifdef USE_FIFO_BUFFER_CNT
+        if (tmr1.read_ms() >= 40*REDUCE_RPT_PERIOD*USE_FIFO_BUFFER_CNT) {
+    #else
+        if (tmr1.read_ms() >= 40*REDUCE_RPT_PERIOD) {
+    #endif
+  #else
+    #ifdef USE_FIFO_BUFFER_CNT
+        if (tmr1.read_ms() >= 40*USE_FIFO_BUFFER_CNT) {
+    #else
         if (tmr1.read_ms() >= 40) {
+    #endif
+  #endif
 #endif
             tmr1.reset();
             read_sh_fifo();