Mode1 Optical Validation

Dependencies:   max32630fthr

Revision:
10:192ea88e964b
Parent:
9:12720bbacfe2
Child:
11:a16b6bf38841
--- a/main.cpp	Fri Mar 26 01:08:41 2021 +0000
+++ b/main.cpp	Fri Mar 26 21:32:42 2021 +0000
@@ -49,8 +49,8 @@
 
 /*****************************************************************************/
 // 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  // tested on MAXREFDES103
+//#define MAXM86146_CFG 1  // tested on MAXM86146EVSYS_sensorBrd+MAXM86161_ADAPTER_REVB+MAX32630FTHR
+#define MAXREFDES103_CFG  // tested on MAXREFDES103
 //#define MAX86161_CFG 1
 /*****************************************************************************/
 
@@ -105,7 +105,7 @@
     Time_to_Read_PPG = 1;
 }
 
-void read_ppg(void) {
+void read_sh_fifo(void) {
     char cmd[8], i, j, samples;
     char rsp[3000];
     int32_t ppg[12];
@@ -232,29 +232,21 @@
    
 }
 #endif // MAXREFDES103_CFG
-int main()
-{
-    sh_i2c.frequency(400000);
+void init_sh(void) {
     char cmd[8], i, j;
     char rsp[256];
-    int32_t ppg[12];
-    int32_t ledcnt = 0;
-    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 */
-
-    // application
+    // 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);
 
-#ifdef MAXREFDES103_CFG
-    init_max20303_pmic();
-#endif
 //read operating mode
     cmd[0] = 0x02; cmd[1] = 0x00;
     sh_i2c.write(SH_ADDR, cmd, 2);
@@ -383,6 +375,17 @@
     mfio = 1; mfio = 0; wait_us(300);
     pc.printf("1.32 who accel %x %x\n\r", rsp[0], rsp[1]);
 #endif
+}
+
+int main()
+{
+    sh_i2c.frequency(400000);
+    int32_t ledcnt = 0;
+    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();
 
 #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG) || defined(MAXM86146_CFG)
     Timer tmr1;
@@ -390,7 +393,7 @@
         tmr1.start();
         if (tmr1.read_ms() > 40) {
             tmr1.reset();
-            read_ppg();
+            read_sh_fifo();
             if ((ledcnt++ % 50) == 0)
                 gLED = !gLED;
         }
@@ -399,7 +402,7 @@
     ticker.attach(callback(&fifo_timer), 0.040f);
     while (1) {
         if (Time_to_Read_PPG) {
-            read_ppg();
+            read_sh_fifo();
             if ((ledcnt++ % 50) == 0)
                 gLED = !gLED;
         }