Mode1 Optical Validation

Dependencies:   max32630fthr

Revision:
5:7f5a012747a5
Parent:
4:4f1e9439f048
Child:
6:e1b7190d6cb5
--- a/main.cpp	Wed Mar 24 01:32:34 2021 +0000
+++ b/main.cpp	Thu Mar 25 04:08:19 2021 +0000
@@ -44,9 +44,16 @@
 */
 /******************************************************************************
 * Tera Term output is set to 115200 baud rate.
-*******************************************************************************
-*/
-//#define MAXM86146_CFG 1
+* ver: 210324
+******************************************************************************/
+
+//#define MAXM86146_CFG 1  // tested on MAXM86146+MAX32630FTHR
+//#define HSP2  // MAXREFDES103 not debugged yet
+#ifdef HSP2
+#include "MAX20303.h"
+I2C i2c_pmic(P5_7, P6_0);
+#endif
+
 #ifdef MAXM86146_CFG
   #define PPG_SZ 36  //maxm86146
 #else
@@ -67,12 +74,16 @@
 DigitalOut rLED(LED1);
 DigitalOut gLED(LED2);
 DigitalOut bLED(LED3);
+/******************************************************************************
+* MAX32630FTHR GPIOs
+******************************************************************************/
 #define RST_PIN   P5_6
 #define MFIO_PIN  P5_4
 DigitalOut rst(RST_PIN, PullUp);
 DigitalOut mfio(MFIO_PIN, PullUp);
 I2C i2c(P3_4, P3_5);
 
+
 const int addr = 0xAA;//0x55;
 int32_t Time_to_Read_PPG = 0;
 
@@ -89,7 +100,7 @@
     char cmd[8], i, j, samples;
     char rsp[3000];
     int32_t ppg[12];
-    int32_t accel[3];
+    int16_t accel[3];
     int32_t status, opmode, hr, hr_conf, ibi, ibi_conf, act, r, spo2, spo2_conf;
     int32_t spo2_compl, spo2_lo, spo2_mo, spo2_lopi, spo2_unrel, spo2_state, ibi_offset, scd;
     int32_t scnt = 0;
@@ -122,7 +133,7 @@
 //    thread_sleep_for(1);
     i2c.read(addr, rsp, 1+(TTL_SZ*samples));
         status = rsp[0];
-        
+
         sptr = 1;
         for (i = 0; i < scnt; i++) {
 #ifdef ALGO_ONLY
@@ -137,6 +148,11 @@
             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]);
 //            pc.printf("%d,%d,", ppg[4], ppg[5]);
+            accel[0] = (rsp[PPG_SZ+0] << 8) | (rsp[PPG_SZ+1]);
+            accel[1] = (rsp[PPG_SZ+2] << 8) | (rsp[PPG_SZ+3]);
+            accel[2] = (rsp[PPG_SZ+4] << 8) | (rsp[PPG_SZ+5]);
+            pc.printf("%d,%d,%d,", accel[0], accel[1], accel[2]);
+
             ptr = sptr + SENSOR_SZ;
 #endif
 //            pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ);
@@ -182,13 +198,41 @@
         mfio = 1;
 }
 
+#ifdef HSP2
+void init_pmic(void) {
+    /* Wait for pmic to settle down */
+    thread_sleep_for(800);
+
+    //set_time(1544787300);  // Set RTC time to Wed, 28 Oct 2009 11:35:37
+    MAX20303 max20303(&i2c);
+    /*Set LDO1 to 1.8v*/
+    max20303.LDO1Config();
+
+    /*Set LDO2 to 3v*/
+    max20303.LDO2Config();
+
+    //max20303.BoostEnable();
+    max20303.BuckBoostEnable();
+
+
+    max20303.led0on(0);
+    max20303.led1on(0);
+    max20303.led2on(0);
+
+    /* Wait for pmic to settle down */
+    thread_sleep_for(200);
+    
+}
+#endif // HSP2
 int main()
-{   
+{
     i2c.frequency(400000);
     char cmd[8], i, j;
     char rsp[256];
     int32_t ppg[12];
-
+#ifdef HSP2
+    init_pmic();
+#endif
     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 */
@@ -209,7 +253,7 @@
     i2c.read(addr, rsp, 2);
     mfio = 1; mfio = 0; wait_us(300);
     pc.printf("02 00 Status, Operating Mode: %x %x\n\r", rsp[0], rsp[1]);
-//1.11 rd ver    
+//1.11 rd ver
     cmd[0] = 0xFF; cmd[1] = 0x03;
     i2c.write(addr, cmd, 2);
     mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);