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

Committer:
gmehmet
Date:
Thu Jan 10 08:30:00 2019 +0000
Revision:
15:c1d7fdf5d55a
Parent:
13:3d1a6b947396
ready to export/fork

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gmehmet 13:3d1a6b947396 1 /*******************************************************************************
gmehmet 13:3d1a6b947396 2 * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
gmehmet 13:3d1a6b947396 3 *
gmehmet 13:3d1a6b947396 4 * Permission is hereby granted, free of charge, to any person obtaining a
gmehmet 13:3d1a6b947396 5 * copy of this software and associated documentation files (the "Software"),
gmehmet 13:3d1a6b947396 6 * to deal in the Software without restriction, including without limitation
gmehmet 13:3d1a6b947396 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
gmehmet 13:3d1a6b947396 8 * and/or sell copies of the Software, and to permit persons to whom the
gmehmet 13:3d1a6b947396 9 * Software is furnished to do so, subject to the following conditions:
gmehmet 13:3d1a6b947396 10 *
gmehmet 13:3d1a6b947396 11 * The above copyright notice and this permission notice shall be included
gmehmet 13:3d1a6b947396 12 * in all copies or substantial portions of the Software.
gmehmet 13:3d1a6b947396 13 *
gmehmet 13:3d1a6b947396 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
gmehmet 13:3d1a6b947396 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
gmehmet 13:3d1a6b947396 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
gmehmet 13:3d1a6b947396 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
gmehmet 13:3d1a6b947396 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
gmehmet 13:3d1a6b947396 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
gmehmet 13:3d1a6b947396 20 * OTHER DEALINGS IN THE SOFTWARE.
gmehmet 13:3d1a6b947396 21 *
gmehmet 13:3d1a6b947396 22 * Except as contained in this notice, the name of Maxim Integrated
gmehmet 13:3d1a6b947396 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
gmehmet 13:3d1a6b947396 24 * Products, Inc. Branding Policy.
gmehmet 13:3d1a6b947396 25 *
gmehmet 13:3d1a6b947396 26 * The mere transfer of this software does not imply any licenses
gmehmet 13:3d1a6b947396 27 * of trade secrets, proprietary technology, copyrights, patents,
gmehmet 13:3d1a6b947396 28 * trademarks, maskwork rights, or any other form of intellectual
gmehmet 13:3d1a6b947396 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
gmehmet 13:3d1a6b947396 30 * ownership rights.
gmehmet 13:3d1a6b947396 31 *******************************************************************************
gmehmet 13:3d1a6b947396 32 */
gmehmet 13:3d1a6b947396 33
gmehmet 13:3d1a6b947396 34
gmehmet 13:3d1a6b947396 35 /**********************************************************************************
gmehmet 13:3d1a6b947396 36 *
gmehmet 13:3d1a6b947396 37 * Desc: Example Code to get algorithm estimation results of Heart rate( WHRM) from sensor hub and display
gmehmet 13:3d1a6b947396 38 * it on screen. Example starts by monitoring heart rate
gmehmet 13:3d1a6b947396 39 * and reinits algorithm via two consecutive button presses (switch button)
gmehmet 13:3d1a6b947396 40 *
gmehmet 13:3d1a6b947396 41 * Example,
gmehmet 13:3d1a6b947396 42 *
gmehmet 13:3d1a6b947396 43 * 1. Initializes user interface
gmehmet 13:3d1a6b947396 44 * initialize display screen and switch button for algo selection.
gmehmet 13:3d1a6b947396 45 *
gmehmet 13:3d1a6b947396 46 * 2. Initializes underlying hardware port for sensor hub communication:
gmehmet 13:3d1a6b947396 47 * setup i2c comm. inits reset pin and mfio event pin and connects interrupt to mfio pin.
gmehmet 13:3d1a6b947396 48 *
gmehmet 13:3d1a6b947396 49 * 3. When switched to a minitoring mode
gmehmet 13:3d1a6b947396 50 * disables previous algorithm, clears mfio event
gmehmet 13:3d1a6b947396 51 * calls default init function for the sensor whose data is used by enabled algorithms. Algorithms are
gmehmet 13:3d1a6b947396 52 * registered under sesnor instance for this example. Fcunction
gmehmet 13:3d1a6b947396 53 * 1. initialize algorithm config struct enabled
gmehmet 13:3d1a6b947396 54 * 2. enable data type to both raw sensor and algorithm data
gmehmet 13:3d1a6b947396 55 * 3. get input fifo size to learn fifo capacity
gmehmet 13:3d1a6b947396 56 * 4. set fifo threshold for mfio event frequency
gmehmet 13:3d1a6b947396 57 * 5. reaenable sensor to acquire ppg data
gmehmet 13:3d1a6b947396 58 * 6. enable accompanying accel sensor
gmehmet 13:3d1a6b947396 59 * 7. enable switched algorithm
gmehmet 13:3d1a6b947396 60 *
gmehmet 13:3d1a6b947396 61 * 4. Sensor Hub now starts to write raw sensor/algorithm data to its data report FIFO which
gmehmet 13:3d1a6b947396 62 * reports mfio event when data size determined by fifo threshold is written to report fifo.
gmehmet 13:3d1a6b947396 63 *
gmehmet 13:3d1a6b947396 64 * 5. Example calls SH_Max8614x_data_report_execute() which
gmehmet 13:3d1a6b947396 65 * 1. calls SH API's sh_ss_execute_once() function which:
gmehmet 13:3d1a6b947396 66 * writes sensor hub's report fifo content (sensor/algorithm data samples) to a buffer(1).
gmehmet 13:3d1a6b947396 67 * 2. calls CSTMR_SH_FeedAccDataIntoSH() to send accelerometer data to sensor hub which os required for heart rate
gmehmet 13:3d1a6b947396 68 * 3. Parses buffer(1) data to extract numeric sensor and algorithm samples according to enabled algorithms.
gmehmet 13:3d1a6b947396 69 * look: whrm_data_rx() , max8614x_data_rx() and sample structs whrm_mode1_data and max8614x_mode1_data
gmehmet 13:3d1a6b947396 70 *
gmehmet 13:3d1a6b947396 71 * 6. numeric values are written to HrmResult, within MAX8614x whrm_data_rx() and included as extern in main.cpp
gmehmet 13:3d1a6b947396 72 *
gmehmet 13:3d1a6b947396 73 * 7. Example calls demoUI_display_algo_estimations() to display result on watch screen
gmehmet 13:3d1a6b947396 74 *
gmehmet 13:3d1a6b947396 75 *
gmehmet 13:3d1a6b947396 76 ***********************************************************************************/
gmehmet 13:3d1a6b947396 77
gmehmet 13:3d1a6b947396 78 #include <events/mbed_events.h>
gmehmet 13:3d1a6b947396 79 #include <mbed.h>
gmehmet 13:3d1a6b947396 80 #include "max32630hsp.h"
gmehmet 13:3d1a6b947396 81 #include "SHComm.h"
gmehmet 13:3d1a6b947396 82 #include "bmi160.h"
gmehmet 13:3d1a6b947396 83 #include "whrmDemoUI.h"
gmehmet 13:3d1a6b947396 84
gmehmet 13:3d1a6b947396 85 #include "SH_Max8614x_WHRM.h"
gmehmet 13:3d1a6b947396 86
gmehmet 13:3d1a6b947396 87
gmehmet 13:3d1a6b947396 88 extern uint16_t HrmResult;
gmehmet 13:3d1a6b947396 89 extern uint8_t HrmConfidence;
gmehmet 13:3d1a6b947396 90
gmehmet 13:3d1a6b947396 91
gmehmet 13:3d1a6b947396 92 DigitalOut led1(LED1, 1);
gmehmet 13:3d1a6b947396 93 // Hardware serial port over DAPLink
gmehmet 13:3d1a6b947396 94 Serial daplink(USBTX, USBRX, 115200);
gmehmet 13:3d1a6b947396 95 // ICARUS Board initialization
gmehmet 13:3d1a6b947396 96 InterruptIn interruptIn_PowerButton(P7_6);
gmehmet 13:3d1a6b947396 97 MAX32630HSP icarus(MAX32630HSP::VIO_1V8, &interruptIn_PowerButton);
gmehmet 13:3d1a6b947396 98
gmehmet 13:3d1a6b947396 99 #define WAIT_SENSORHUB_STABLE_BOOTUP_MS ((uint32_t)2000)
gmehmet 13:3d1a6b947396 100
gmehmet 13:3d1a6b947396 101
gmehmet 13:3d1a6b947396 102 static bool isWhrmInitialized = false;
gmehmet 13:3d1a6b947396 103
gmehmet 13:3d1a6b947396 104
gmehmet 13:3d1a6b947396 105 int main() {
gmehmet 13:3d1a6b947396 106
gmehmet 13:3d1a6b947396 107 wait_ms(WAIT_SENSORHUB_STABLE_BOOTUP_MS);
gmehmet 13:3d1a6b947396 108 demoUI_init();
gmehmet 13:3d1a6b947396 109
gmehmet 13:3d1a6b947396 110 sh_init_hwcomm_interface();
gmehmet 13:3d1a6b947396 111 sh_disable_irq_mfioevent();
gmehmet 13:3d1a6b947396 112 sh_clear_mfio_event_flag();
gmehmet 13:3d1a6b947396 113 sh_enable_irq_mfioevent();
gmehmet 13:3d1a6b947396 114 int i = 0;
gmehmet 13:3d1a6b947396 115
gmehmet 13:3d1a6b947396 116 int displayMode;
gmehmet 13:3d1a6b947396 117 uint16_t resultToDisplay;
gmehmet 13:3d1a6b947396 118 uint8_t confidenceToDisplay;
gmehmet 13:3d1a6b947396 119
gmehmet 13:3d1a6b947396 120 while(1) {
gmehmet 13:3d1a6b947396 121
gmehmet 13:3d1a6b947396 122 displayMode = demoUI_display_get_mode();
gmehmet 13:3d1a6b947396 123
gmehmet 13:3d1a6b947396 124 if( displayMode == kAlgoModeHeartRate ){
gmehmet 13:3d1a6b947396 125 if( !isWhrmInitialized){
gmehmet 13:3d1a6b947396 126 #if defined(DEBUG_INFO)
gmehmet 13:3d1a6b947396 127 printf(" WHRM inititalized \r\n");
gmehmet 13:3d1a6b947396 128 #endif
gmehmet 13:3d1a6b947396 129 SH_Max8614x_stop();
gmehmet 13:3d1a6b947396 130 SH_Max8614x_default_init(kAlgoModeHeartRate);
gmehmet 13:3d1a6b947396 131 isWhrmInitialized = true;
gmehmet 13:3d1a6b947396 132 wait_ms(1000); /* for display screen*/
gmehmet 13:3d1a6b947396 133 }
gmehmet 13:3d1a6b947396 134 resultToDisplay = HrmResult;
gmehmet 13:3d1a6b947396 135 confidenceToDisplay = HrmConfidence;
gmehmet 13:3d1a6b947396 136
gmehmet 13:3d1a6b947396 137 }else{
gmehmet 13:3d1a6b947396 138
gmehmet 13:3d1a6b947396 139 demoUI_display_set_algoMode(kAlgoModeHeartRate);
gmehmet 13:3d1a6b947396 140 isWhrmInitialized = false;
gmehmet 13:3d1a6b947396 141 }
gmehmet 13:3d1a6b947396 142
gmehmet 13:3d1a6b947396 143 int cumSampleCNt = SH_Max8614x_data_report_execute();
gmehmet 13:3d1a6b947396 144 if(cumSampleCNt){
gmehmet 13:3d1a6b947396 145 #if defined(DEBUG_INFO)
gmehmet 13:3d1a6b947396 146 printf("estimate: =%d conf: %d dispMode: %d \r\n", resultToDisplay , confidenceToDisplay, displayMode);
gmehmet 13:3d1a6b947396 147 #endif
gmehmet 13:3d1a6b947396 148 demoUI_display_algo_estimations(resultToDisplay);
gmehmet 13:3d1a6b947396 149
gmehmet 13:3d1a6b947396 150 }
gmehmet 13:3d1a6b947396 151
gmehmet 13:3d1a6b947396 152
gmehmet 13:3d1a6b947396 153
gmehmet 13:3d1a6b947396 154 }
gmehmet 13:3d1a6b947396 155
gmehmet 13:3d1a6b947396 156 }