Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Maxim_Sensor_Hub_Communications BMI160 demoUI max32630hsp3
Fork of Host_Software_MAX32664GWEC_SpO2_HR by
Diff: main.cpp
- Revision:
- 0:ddc2fef69ef9
diff -r 000000000000 -r ddc2fef69ef9 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Dec 17 10:34:32 2018 +0300
@@ -0,0 +1,208 @@
+/*******************************************************************************
+ * 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( HRM) and Blood
+ * Oxygen (SPo2) form sensor hub and display it on screen. Example starts by monitoring heart rate
+ * ans switches to blood oxygen monitoring via a button press (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
+ * Note: SPo2 requires stablity so do not move/shake senor when taking SPo2 data.
+ * 3. Parses buffer(1) data to extract numeric sensor and algorithm samples according to enabled algorithms.
+ * look: whrm_data_rx() , wspo2_data_rx() , max8614x_data_rx() and sample structs whrm_mode1_data, wspo2_mode1_data and max8614x_mode1_data
+ *
+ * 6. numeric values are written to HrmResult, SPO2Result ... 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 "SH_Max8614x_BareMetal.h"
+#include "bmi160.h"
+
+#include "demoUI.h"
+
+
+extern uint16_t HrmResult;
+extern uint16_t SPO2Result;
+extern uint8_t HrmConfidence;
+extern uint8_t SPo2Confidence;
+
+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;
+static bool isSpo2Initialized = false;
+
+int main() {
+
+ wait_ms(WAIT_SENSORHUB_STABLE_BOOTUP_MS);
+ //demoUI_display_set_algoMode(kAlgoModeHeartRate);
+
+ demoUI_init();
+
+ sh_init_hwcomm_interface();
+ sh_disable_irq_mfioevent();
+ sh_clear_mfio_event_flag();
+ sh_enable_irq_mfioevent();
+ int i = 0;
+
+#if 1
+
+ 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;
+ isSpo2Initialized = false;
+ wait_ms(1000); /* for display screen*/
+ }
+ resultToDisplay = HrmResult;
+ confidenceToDisplay = HrmConfidence;
+
+ }else{
+ if( !isSpo2Initialized){
+#if defined(DEBUG_INFO)
+ printf(" WSPo2 inititalized \r\n");
+#endif
+ SH_Max8614x_stop();
+ SH_Max8614x_default_init(kAlgoModeSPO2);
+ isWhrmInitialized = false;
+ isSpo2Initialized = true;
+ wait_ms(1000); /* for display screen*/
+ }
+ resultToDisplay = SPO2Result;
+ confidenceToDisplay = SPo2Confidence;
+ }
+
+ 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);
+ //printf(" Display Mode : %d \r\n", displayMode );
+ }
+
+
+
+ }
+
+
+
+
+
+#else
+
+ while(1) {
+ SH_Max8614x_default_init(kAlgoModeHeartRate);
+
+ while(1){
+ ++i;
+ int cumSampleCNt = SH_Max8614x_data_report_execute();
+ if(cumSampleCNt)
+ printf("hr_cttt=%d %d\r\n", HrmResult , HrmConfidence);
+ wait_ms(2);
+ led1 = !led1;
+ if(i == 24000) {
+ break;
+ }
+ }
+ i = 0;
+ SH_Max8614x_stop();
+ printf("Stopped\r\n");
+ while(1){
+ ++i;
+ SH_Max8614x_data_report_execute();
+ wait_ms(2);
+ led1 = !led1;
+ if(i == 4000) {
+ break;
+ }
+ }
+ i = 0;
+ }
+#endif
+
+}
