YOSHIHISA TABUCHI / Mbed OS Host_Software_MAX32664GWEB_HR_EXTENDEDtest

Dependencies:   BMI160 max32630hsp3 MemoryLCD USBDevice

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) from sensor hub and display it on screen.
00038  *        Example starts by monitoring heart rate and reinits WHRM algorithm via a button press (switch button)
00039  *
00040  *        Example,
00041  *
00042  *        1. Initializes user interface
00043  *                   initialize display screen and switch button for algo selection.
00044  *
00045  *        2. Initializes underlying hardware port for sensor hub communication:
00046  *                   setup i2c comm. inits reset pin and mfio event pin and connects interrupt to mfio pin.
00047  *
00048  *        3. When switched to a minitoring mode
00049  *                   disables previous algorithm, clears mfio event
00050  *                   calls default init function for the sensor whose data is used by enabled algorithms. Algorithms are
00051  *                   registered under sesnor instance for this example. Fcunction
00052  *                              1. initialize algorithm config struct enabled
00053  *                              2. enable data type to both raw sensor and algorithm data
00054  *                              3. get input fifo size to learn fifo capacity
00055  *                              4. set fifo threshold for mfio event frequency
00056  *                              5. reaenable sensor to acquire ppg data
00057  *                              6. enable accompanying accel sensor
00058  *                              7. enable switched algorithm
00059  *
00060  *     4. Sensor Hub now starts to write raw sensor/algorithm data to its data report FIFO which
00061  *        reports mfio event when data size determined by fifo threshold is written to report fifo.
00062  *
00063  *     5. Example calls SH_Max8614x_data_report_execute() which
00064  *                 1. calls SH API's sh_ss_execute_once() function which:
00065  *                            writes sensor hub's report fifo content (sensor/algorithm data samples) to a buffer(1).
00066  *                 2. calls CSTMR_SH_FeedAccDataIntoSH() to send accelerometer data to sensor hub which os required for heart rate
00067  *                 3. Parses buffer(1) data to extract numeric sensor and algorithm samples according to enabled algorithms.
00068  *                    look: whrm_data_rx() , max8614x_data_rx() and sample structs whrm_mode1_data and max8614x_mode1_data
00069  *
00070  *     6. numeric values  are written to HrmResult  within MAX8614x  whrm_data_rx() ... and included as extern in main.cpp
00071  *
00072  *     7. Example calls demoUI_display_algo_estimations() to display result on watch screen
00073  *
00074  *
00075  ***********************************************************************************/
00076 
00077 #include <events/mbed_events.h>
00078 #include <mbed.h>
00079 #include "max32630hsp.h"
00080 #include "SHComm.h"
00081 #include "SH_Max8614x_BareMetal.h"
00082 #include "bmi160.h"
00083 #include "cmdInterface.h"
00084 #include "demoUI.h"
00085 #include "demoDefinitions.h"
00086 
00087 extern uint16_t HrmResult;
00088 extern uint8_t  HrmConfidence;
00089 
00090 DigitalOut debugled(LED1, 1);
00091 // Hardware serial port over DAPLink
00092 Serial daplink(USBTX, USBRX, 115200);
00093 
00094 #include "USBSerial.h"
00095 USBSerial microUSB(0x1f00, 0x2012, 0x0001, false);
00096 
00097 
00098 
00099 // ICARUS Board initialization
00100 InterruptIn interruptIn_PowerButton(P7_6);
00101 MAX32630HSP icarus(MAX32630HSP::VIO_1V8, &interruptIn_PowerButton);
00102 
00103 #define WAIT_SENSORHUB_STABLE_BOOTUP_MS  ((uint32_t)2000)
00104 
00105 
00106 static bool isWhrmInitialized     = false;
00107 
00108 int main() {
00109 
00110     wait_ms(WAIT_SENSORHUB_STABLE_BOOTUP_MS);
00111 
00112     int hostMode = HOSTMODEAPPLICATION;
00113 
00114     demoUI_init();
00115 
00116     sh_init_hwcomm_interface();
00117     sh_disable_irq_mfioevent();
00118     sh_clear_mfio_event_flag();
00119     sh_enable_irq_mfioevent();
00120     int i = 0;
00121 
00122     int displayMode;
00123     uint16_t resultToDisplay;
00124     uint8_t  confidenceToDisplay;
00125 
00126     while(1) {
00127 
00128         char ch;
00129         while ( SERIAL_AVAILABLE()) {
00130 
00131             ch = SERIALIN();
00132             cmdIntf_build_command(ch);
00133         }
00134 
00135         hostMode  = get_internal_operating_mode();
00136         if( hostMode  == HOSTMODEAPPLICATION) {
00137 
00138                 displayMode = demoUI_display_get_mode();
00139 
00140                 if( displayMode == kAlgoModeHeartRate ){
00141                      if( !isWhrmInitialized){
00142 #if defined(DEBUG_INFO)
00143                          SERIALOUT(" WHRM inititalized \r\n");
00144 #endif
00145                          SH_Max8614x_stop();
00146                          SH_Max8614x_default_init(kAlgoModeHeartRate);
00147                          isWhrmInitialized = true;
00148                          wait_ms(100); /* for display screen*/
00149                      }
00150                      resultToDisplay     = HrmResult;
00151                      confidenceToDisplay = HrmConfidence;
00152 
00153                 }else if( displayMode == reinitHeartRate ){
00154                     isWhrmInitialized = false;
00155                 }
00156 
00157                 int cumSampleCNt = SH_Max8614x_data_report_execute();
00158 
00159                 if(cumSampleCNt){ /* If data samples ara avaliable display on screen*/
00160 #if defined(DEBUG_INFO)
00161                     //SERIALOUT("estimate: =%d conf: %d dispMode: %d \r\n", resultToDisplay , confidenceToDisplay, displayMode);
00162 #endif                  if( displayMode == kAlgoModeHeartRate)
00163                              demoUI_display_algo_estimations(resultToDisplay, -1);
00164 
00165                 }
00166 
00167 
00168         }else {
00169 
00170                 demoUI_display_bootldr_screen();
00171                //wait_ms(10);
00172         }
00173 
00174     }
00175 
00176 
00177 }
00178