Example Host software for integration of MAX3266x chips (, MAX32664GWEB) equipped with Heart Rate from Wrist Algorithm. This is “stand-alone” software that runs on the MAX32630 low-power microcontroller to display heart rate on the display of the MAXREFDES101 reference design. It is intended provide a simple example of how to initialize and communicate with the sensor hub. Windows and Android communications are not supported.

Dependencies:   Maxim_Sensor_Hub_Communications BMI160 whrmDemoUI max32630hsp3

Fork of Host_Software_MAX32664GWEB_HR_wrist by mehmet gok

Revision:
13:3d1a6b947396
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/whrmMain.cpp	Thu Jan 10 11:06:01 2019 +0300
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Maxim Integrated
+ * Products, Inc. shall not be used except as stated in the Maxim Integrated
+ * Products, Inc. Branding Policy.
+ *
+ * The mere transfer of this software does not imply any licenses
+ * of trade secrets, proprietary technology, copyrights, patents,
+ * trademarks, maskwork rights, or any other form of intellectual
+ * property whatsoever. Maxim Integrated Products, Inc. retains all
+ * ownership rights.
+ *******************************************************************************
+ */
+
+
+/**********************************************************************************
+ *
+ *  Desc: Example Code to get algorithm estimation results of Heart rate( WHRM) from sensor hub and display
+ *        it on screen. Example starts by monitoring heart rate
+ *        and reinits algorithm  via two consecutive button presses (switch button)
+ *
+ *        Example,
+ *
+ *        1. Initializes user interface
+ *                   initialize display screen and switch button for algo selection.
+ *
+ *        2. Initializes underlying hardware port for sensor hub communication:
+ *                   setup i2c comm. inits reset pin and mfio event pin and connects interrupt to mfio pin.
+ *
+ *        3. When switched to a minitoring mode
+ *                   disables previous algorithm, clears mfio event
+ *                   calls default init function for the sensor whose data is used by enabled algorithms. Algorithms are
+ *                   registered under sesnor instance for this example. Fcunction
+ *                   	        1. initialize algorithm config struct enabled
+ *                              2. enable data type to both raw sensor and algorithm data
+ *                              3. get input fifo size to learn fifo capacity
+ *                              4. set fifo threshold for mfio event frequency
+ *                              5. reaenable sensor to acquire ppg data
+ *                              6. enable accompanying accel sensor
+ *                              7. enable switched algorithm
+ *
+ *     4. Sensor Hub now starts to write raw sensor/algorithm data to its data report FIFO which
+ *        reports mfio event when data size determined by fifo threshold is written to report fifo.
+ *
+ *     5. Example calls SH_Max8614x_data_report_execute() which
+ *                 1. calls SH API's sh_ss_execute_once() function which:
+ *                            writes sensor hub's report fifo content (sensor/algorithm data samples) to a buffer(1).
+ *                 2. calls CSTMR_SH_FeedAccDataIntoSH() to send accelerometer data to sensor hub which os required for heart rate
+ *                 3. Parses buffer(1) data to extract numeric sensor and algorithm samples according to enabled algorithms.
+ *                    look: whrm_data_rx() , max8614x_data_rx() and sample structs whrm_mode1_data and max8614x_mode1_data
+ *
+ *     6. numeric values  are written to HrmResult,  within MAX8614x  whrm_data_rx() and included as extern in main.cpp
+ *
+ *     7. Example calls demoUI_display_algo_estimations() to display result on watch screen
+ *
+ *
+ ***********************************************************************************/
+
+#include <events/mbed_events.h>
+#include <mbed.h>
+#include "max32630hsp.h"
+#include "SHComm.h"
+#include "bmi160.h"
+#include "whrmDemoUI.h"
+
+#include "SH_Max8614x_WHRM.h"
+
+
+extern uint16_t HrmResult;
+extern uint8_t  HrmConfidence;
+
+
+DigitalOut led1(LED1, 1);
+// Hardware serial port over DAPLink
+Serial daplink(USBTX, USBRX, 115200);
+// ICARUS Board initialization
+InterruptIn interruptIn_PowerButton(P7_6);
+MAX32630HSP icarus(MAX32630HSP::VIO_1V8, &interruptIn_PowerButton);
+
+#define WAIT_SENSORHUB_STABLE_BOOTUP_MS  ((uint32_t)2000)
+
+
+static bool isWhrmInitialized = false;
+
+
+int main() {
+
+	wait_ms(WAIT_SENSORHUB_STABLE_BOOTUP_MS);
+	demoUI_init();
+
+	sh_init_hwcomm_interface();
+	sh_disable_irq_mfioevent();
+	sh_clear_mfio_event_flag();
+	sh_enable_irq_mfioevent();
+	int i = 0;
+
+	int displayMode;
+	uint16_t resultToDisplay;
+	uint8_t  confidenceToDisplay;
+
+	while(1) {
+
+		displayMode = demoUI_display_get_mode();
+
+        if( displayMode == kAlgoModeHeartRate ){
+             if( !isWhrmInitialized){
+#if defined(DEBUG_INFO)
+            	 printf(" WHRM inititalized \r\n");
+#endif
+            	 SH_Max8614x_stop();
+            	 SH_Max8614x_default_init(kAlgoModeHeartRate);
+            	 isWhrmInitialized = true;
+            	 wait_ms(1000); /* for display screen*/
+             }
+             resultToDisplay     = HrmResult;
+             confidenceToDisplay = HrmConfidence;
+
+        }else{
+
+        	demoUI_display_set_algoMode(kAlgoModeHeartRate);
+        	isWhrmInitialized = false;
+        }
+
+		int cumSampleCNt = SH_Max8614x_data_report_execute();
+		if(cumSampleCNt){
+#if defined(DEBUG_INFO)
+			printf("estimate: =%d conf: %d dispMode: %d \r\n", resultToDisplay , confidenceToDisplay, displayMode);
+#endif
+            demoUI_display_algo_estimations(resultToDisplay);
+
+		}
+
+
+
+	}
+
+}