Example host software to display SpO2 or Heart Rate on wrist using the MAX32664GWEC or MAXREFDES101 with IR/Red LED board. It is recommended that the MAX32664 be loaded with the latest Maxim supplied algorithm (.msbl file).

Dependencies:   Maxim_Sensor_Hub_Communications BMI160 demoUI max32630hsp3

Fork of Host_Software_MAX32664GWEC_SpO2_HR by mehmet gok

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*******************************************************************************
00002  * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * Except as contained in this notice, the name of Maxim Integrated
00023  * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024  * Products, Inc. Branding Policy.
00025  *
00026  * The mere transfer of this software does not imply any licenses
00027  * of trade secrets, proprietary technology, copyrights, patents,
00028  * trademarks, maskwork rights, or any other form of intellectual
00029  * property whatsoever. Maxim Integrated Products, Inc. retains all
00030  * ownership rights.
00031  *******************************************************************************
00032  */
00033 
00034 
00035 /**********************************************************************************
00036  *
00037  *  Desc: Example Code to get algorithm estimation results of Heart rate( HRM) and Blood
00038  *        Oxygen (SPo2) form sensor hub and display it on screen. Example starts by monitoring heart rate
00039  *        ans switches to blood oxygen monitoring via a button press (switch button)
00040  *
00041  *        Example,
00042  *
00043  *        1. Initializes user interface
00044  *                   initialize display screen and switch button for algo selection.
00045  *
00046  *        2. Initializes underlying hardware port for sensor hub communication:
00047  *                   setup i2c comm. inits reset pin and mfio event pin and connects interrupt to mfio pin.
00048  *
00049  *        3. When switched to a minitoring mode
00050  *                   disables previous algorithm, clears mfio event
00051  *                   calls default init function for the sensor whose data is used by enabled algorithms. Algorithms are
00052  *                   registered under sesnor instance for this example. Fcunction
00053  *                              1. initialize algorithm config struct enabled
00054  *                              2. enable data type to both raw sensor and algorithm data
00055  *                              3. get input fifo size to learn fifo capacity
00056  *                              4. set fifo threshold for mfio event frequency
00057  *                              5. reaenable sensor to acquire ppg data
00058  *                              6. enable accompanying accel sensor
00059  *                              7. enable switched algorithm
00060  *
00061  *     4. Sensor Hub now starts to write raw sensor/algorithm data to its data report FIFO which
00062  *        reports mfio event when data size determined by fifo threshold is written to report fifo.
00063  *
00064  *     5. Example calls SH_Max8614x_data_report_execute() which
00065  *                 1. calls SH API's sh_ss_execute_once() function which:
00066  *                            writes sensor hub's report fifo content (sensor/algorithm data samples) to a buffer(1).
00067  *                 2. calls CSTMR_SH_FeedAccDataIntoSH() to send accelerometer data to sensor hub which os required for heart rate
00068  *                    Note: SPo2 requires stablity so do not move/shake senor when taking SPo2 data.
00069  *                 3. Parses buffer(1) data to extract numeric sensor and algorithm samples according to enabled algorithms.
00070  *                    look: whrm_data_rx() , wspo2_data_rx() , max8614x_data_rx() and sample structs whrm_mode1_data, wspo2_mode1_data and max8614x_mode1_data
00071  *
00072  *     6. numeric values  are written to HrmResult, SPO2Result ... within MAX8614x  whrm_data_rx() ... and included as extern in main.cpp
00073  *
00074  *     7. Example calls demoUI_display_algo_estimations() to display result on watch screen
00075  *
00076  *
00077  ***********************************************************************************/
00078 
00079 #include <events/mbed_events.h>
00080 #include <mbed.h>
00081 #include "max32630hsp.h"
00082 #include "SHComm.h"
00083 #include "SH_Max8614x_BareMetal.h"
00084 #include "bmi160.h"
00085 
00086 #include "demoUI.h"
00087 
00088 
00089 extern uint16_t HrmResult;
00090 extern uint16_t SPO2Result;
00091 extern uint8_t  HrmConfidence;
00092 extern uint8_t  SPo2Confidence;
00093 
00094 DigitalOut led1(LED1, 1);
00095 // Hardware serial port over DAPLink
00096 Serial daplink(USBTX, USBRX, 115200);
00097 // ICARUS Board initialization
00098 InterruptIn interruptIn_PowerButton(P7_6);
00099 MAX32630HSP icarus(MAX32630HSP::VIO_1V8, &interruptIn_PowerButton);
00100 
00101 #define WAIT_SENSORHUB_STABLE_BOOTUP_MS  ((uint32_t)2000)
00102 
00103 
00104 static bool isWhrmInitialized = false;
00105 static bool isSpo2Initialized = false;
00106 
00107 int main() {
00108 
00109     wait_ms(WAIT_SENSORHUB_STABLE_BOOTUP_MS);
00110     //demoUI_display_set_algoMode(kAlgoModeHeartRate);
00111 
00112     demoUI_init();
00113 
00114     sh_init_hwcomm_interface();
00115     sh_disable_irq_mfioevent();
00116     sh_clear_mfio_event_flag();
00117     sh_enable_irq_mfioevent();
00118     int i = 0;
00119 
00120 #if 1
00121 
00122     int displayMode;
00123     uint16_t resultToDisplay;
00124     uint8_t  confidenceToDisplay;
00125 
00126     while(1) {
00127 
00128         displayMode = demoUI_display_get_mode();
00129 
00130         if( displayMode == kAlgoModeHeartRate ){
00131              if( !isWhrmInitialized){
00132 #if defined(DEBUG_INFO)
00133                  printf(" WHRM inititalized \r\n");
00134 #endif
00135                  SH_Max8614x_stop();
00136                  SH_Max8614x_default_init(kAlgoModeHeartRate);
00137                  isWhrmInitialized = true;
00138                  isSpo2Initialized = false;
00139                  wait_ms(1000); /* for display screen*/
00140              }
00141              resultToDisplay     = HrmResult;
00142              confidenceToDisplay = HrmConfidence;
00143 
00144         }else{
00145             if( !isSpo2Initialized){
00146 #if defined(DEBUG_INFO)
00147                 printf(" WSPo2 inititalized \r\n");
00148 #endif
00149                 SH_Max8614x_stop();
00150                 SH_Max8614x_default_init(kAlgoModeSPO2);
00151                 isWhrmInitialized = false;
00152                 isSpo2Initialized = true;
00153                 wait_ms(1000); /* for display screen*/
00154             }
00155             resultToDisplay = SPO2Result;
00156             confidenceToDisplay = SPo2Confidence;
00157         }
00158 
00159         int cumSampleCNt = SH_Max8614x_data_report_execute();
00160         if(cumSampleCNt){
00161 #if defined(DEBUG_INFO)
00162             printf("estimate: =%d conf: %d dispMode: %d \r\n", resultToDisplay , confidenceToDisplay, displayMode);
00163 #endif
00164             demoUI_display_algo_estimations(resultToDisplay);
00165             //printf(" Display Mode : %d \r\n", displayMode );
00166         }
00167 
00168 
00169 
00170     }
00171 
00172 
00173 
00174 
00175 
00176 #else
00177 
00178     while(1) {
00179         SH_Max8614x_default_init(kAlgoModeHeartRate);
00180 
00181         while(1){
00182             ++i;
00183             int cumSampleCNt = SH_Max8614x_data_report_execute();
00184             if(cumSampleCNt)
00185                 printf("hr_cttt=%d   %d\r\n", HrmResult , HrmConfidence);
00186             wait_ms(2);
00187             led1 = !led1;
00188             if(i == 24000) {
00189                 break;
00190             }
00191         }
00192         i = 0;
00193         SH_Max8614x_stop();
00194         printf("Stopped\r\n");
00195         while(1){
00196             ++i;
00197             SH_Max8614x_data_report_execute();
00198             wait_ms(2);
00199             led1 = !led1;
00200             if(i == 4000) {
00201                 break;
00202             }
00203         }
00204         i = 0;
00205     }
00206 #endif
00207 
00208 }