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