Wilson Tang
/
HSP_RPC_GUI
Fork of the offical HSP_RPC_GUI firmware
Fork of MAXREFDES100 firmware for MAX32620HSP
HSP/Devices/MAX30001/MAX30001_helper.cpp@1:9490836294ea, 2017-04-21 (annotated)
- Committer:
- jbradshaw
- Date:
- Fri Apr 21 12:12:30 2017 -0500
- Revision:
- 1:9490836294ea
- Parent:
- 0:e4a10ed6eb92
Flash device is now fully utilized for datalog of sensor data
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jbradshaw | 0:e4a10ed6eb92 | 1 | /******************************************************************************* |
jbradshaw | 0:e4a10ed6eb92 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
jbradshaw | 0:e4a10ed6eb92 | 3 | * |
jbradshaw | 0:e4a10ed6eb92 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
jbradshaw | 0:e4a10ed6eb92 | 5 | * copy of this software and associated documentation files (the "Software"), |
jbradshaw | 0:e4a10ed6eb92 | 6 | * to deal in the Software without restriction, including without limitation |
jbradshaw | 0:e4a10ed6eb92 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
jbradshaw | 0:e4a10ed6eb92 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
jbradshaw | 0:e4a10ed6eb92 | 9 | * Software is furnished to do so, subject to the following conditions: |
jbradshaw | 0:e4a10ed6eb92 | 10 | * |
jbradshaw | 0:e4a10ed6eb92 | 11 | * The above copyright notice and this permission notice shall be included |
jbradshaw | 0:e4a10ed6eb92 | 12 | * in all copies or substantial portions of the Software. |
jbradshaw | 0:e4a10ed6eb92 | 13 | * |
jbradshaw | 0:e4a10ed6eb92 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
jbradshaw | 0:e4a10ed6eb92 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
jbradshaw | 0:e4a10ed6eb92 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
jbradshaw | 0:e4a10ed6eb92 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
jbradshaw | 0:e4a10ed6eb92 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
jbradshaw | 0:e4a10ed6eb92 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
jbradshaw | 0:e4a10ed6eb92 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
jbradshaw | 0:e4a10ed6eb92 | 21 | * |
jbradshaw | 0:e4a10ed6eb92 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
jbradshaw | 0:e4a10ed6eb92 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
jbradshaw | 0:e4a10ed6eb92 | 24 | * Products, Inc. Branding Policy. |
jbradshaw | 0:e4a10ed6eb92 | 25 | * |
jbradshaw | 0:e4a10ed6eb92 | 26 | * The mere transfer of this software does not imply any licenses |
jbradshaw | 0:e4a10ed6eb92 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
jbradshaw | 0:e4a10ed6eb92 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
jbradshaw | 0:e4a10ed6eb92 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
jbradshaw | 0:e4a10ed6eb92 | 30 | * ownership rights. |
jbradshaw | 0:e4a10ed6eb92 | 31 | ******************************************************************************* |
jbradshaw | 0:e4a10ed6eb92 | 32 | */ |
jbradshaw | 0:e4a10ed6eb92 | 33 | |
jbradshaw | 0:e4a10ed6eb92 | 34 | #include "MAX30001_helper.h" |
jbradshaw | 0:e4a10ed6eb92 | 35 | #include "MAX30001.h" |
jbradshaw | 0:e4a10ed6eb92 | 36 | #include "StringInOut.h" |
jbradshaw | 0:e4a10ed6eb92 | 37 | #include "Peripherals.h" |
jbradshaw | 0:e4a10ed6eb92 | 38 | |
jbradshaw | 0:e4a10ed6eb92 | 39 | static uint8_t flags[4]; |
jbradshaw | 0:e4a10ed6eb92 | 40 | |
jbradshaw | 0:e4a10ed6eb92 | 41 | int MAX30001_Helper_IsStreaming(eFlags flag) { |
jbradshaw | 0:e4a10ed6eb92 | 42 | return flags[(uint32_t)flag]; |
jbradshaw | 0:e4a10ed6eb92 | 43 | } |
jbradshaw | 0:e4a10ed6eb92 | 44 | |
jbradshaw | 0:e4a10ed6eb92 | 45 | void MAX30001_Helper_SetStreamingFlag(eFlags flag, uint8_t state) { |
jbradshaw | 0:e4a10ed6eb92 | 46 | flags[(uint32_t)flag] = state; |
jbradshaw | 0:e4a10ed6eb92 | 47 | } |
jbradshaw | 0:e4a10ed6eb92 | 48 | |
jbradshaw | 0:e4a10ed6eb92 | 49 | void MAX30001_Helper_Stop(void) { |
jbradshaw | 0:e4a10ed6eb92 | 50 | if (flags[(uint32_t)eStreaming_ECG] == 1) { |
jbradshaw | 1:9490836294ea | 51 | Peripherals::max30001()->Stop_ECG(); |
jbradshaw | 0:e4a10ed6eb92 | 52 | } |
jbradshaw | 0:e4a10ed6eb92 | 53 | if (flags[(uint32_t)eStreaming_PACE] == 1) { |
jbradshaw | 1:9490836294ea | 54 | Peripherals::max30001()->Stop_PACE(); |
jbradshaw | 0:e4a10ed6eb92 | 55 | } |
jbradshaw | 0:e4a10ed6eb92 | 56 | if (flags[(uint32_t)eStreaming_BIOZ] == 1) { |
jbradshaw | 1:9490836294ea | 57 | Peripherals::max30001()->Stop_BIOZ(); |
jbradshaw | 0:e4a10ed6eb92 | 58 | } |
jbradshaw | 0:e4a10ed6eb92 | 59 | if (flags[(uint32_t)eStreaming_RtoR] == 1) { |
jbradshaw | 1:9490836294ea | 60 | Peripherals::max30001()->Stop_RtoR(); |
jbradshaw | 0:e4a10ed6eb92 | 61 | } |
jbradshaw | 0:e4a10ed6eb92 | 62 | MAX30001_Helper_ClearStreamingFlags(); |
jbradshaw | 0:e4a10ed6eb92 | 63 | } |
jbradshaw | 0:e4a10ed6eb92 | 64 | |
jbradshaw | 0:e4a10ed6eb92 | 65 | int MAX30001_AnyStreamingSet(void) { |
jbradshaw | 0:e4a10ed6eb92 | 66 | uint32_t i; |
jbradshaw | 0:e4a10ed6eb92 | 67 | for (i = 0; i < 4; i++) { |
jbradshaw | 0:e4a10ed6eb92 | 68 | if (flags[i] == 1) return 1; |
jbradshaw | 0:e4a10ed6eb92 | 69 | } |
jbradshaw | 0:e4a10ed6eb92 | 70 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 71 | } |
jbradshaw | 0:e4a10ed6eb92 | 72 | |
jbradshaw | 0:e4a10ed6eb92 | 73 | void MAX30001_Helper_StartSync(void) { |
jbradshaw | 0:e4a10ed6eb92 | 74 | if (MAX30001_AnyStreamingSet() == 1) { |
jbradshaw | 1:9490836294ea | 75 | Peripherals::max30001()->synch(); |
jbradshaw | 0:e4a10ed6eb92 | 76 | } |
jbradshaw | 0:e4a10ed6eb92 | 77 | } |
jbradshaw | 0:e4a10ed6eb92 | 78 | |
jbradshaw | 0:e4a10ed6eb92 | 79 | void MAX30001_Helper_ClearStreamingFlags(void) { |
jbradshaw | 0:e4a10ed6eb92 | 80 | uint32_t i; |
jbradshaw | 0:e4a10ed6eb92 | 81 | for (i = 0; i < 4; i++) { |
jbradshaw | 0:e4a10ed6eb92 | 82 | flags[i] = 0; |
jbradshaw | 0:e4a10ed6eb92 | 83 | } |
jbradshaw | 0:e4a10ed6eb92 | 84 | } |
jbradshaw | 0:e4a10ed6eb92 | 85 | |
jbradshaw | 0:e4a10ed6eb92 | 86 | void MAX30001_Helper_Debug_ShowStreamFlags(void) { |
jbradshaw | 0:e4a10ed6eb92 | 87 | putStr("\r\n"); |
jbradshaw | 0:e4a10ed6eb92 | 88 | if (flags[(uint32_t)eStreaming_ECG] == 1) { |
jbradshaw | 0:e4a10ed6eb92 | 89 | putStr("eStreaming_ECG, "); |
jbradshaw | 0:e4a10ed6eb92 | 90 | } |
jbradshaw | 0:e4a10ed6eb92 | 91 | if (flags[(uint32_t)eStreaming_PACE] == 1) { |
jbradshaw | 0:e4a10ed6eb92 | 92 | putStr("eStreaming_PACE, "); |
jbradshaw | 0:e4a10ed6eb92 | 93 | } |
jbradshaw | 0:e4a10ed6eb92 | 94 | if (flags[(uint32_t)eStreaming_BIOZ] == 1) { |
jbradshaw | 0:e4a10ed6eb92 | 95 | putStr("eStreaming_BIOZ, "); |
jbradshaw | 0:e4a10ed6eb92 | 96 | } |
jbradshaw | 0:e4a10ed6eb92 | 97 | if (flags[(uint32_t)eStreaming_RtoR] == 1) { |
jbradshaw | 0:e4a10ed6eb92 | 98 | putStr("eStreaming_RtoR, "); |
jbradshaw | 0:e4a10ed6eb92 | 99 | } |
jbradshaw | 0:e4a10ed6eb92 | 100 | putStr("\r\n"); |
jbradshaw | 0:e4a10ed6eb92 | 101 | } |
jbradshaw | 0:e4a10ed6eb92 | 102 | |
jbradshaw | 0:e4a10ed6eb92 | 103 | void MAX30001_Helper_SetupInterrupts() { |
jbradshaw | 1:9490836294ea | 104 | Peripherals::max30001()->INT_assignment(MAX30001::MAX30001_INT_B, MAX30001::MAX30001_NO_INT, MAX30001::MAX30001_NO_INT, ///< en_enint_loc, en_eovf_loc, en_fstint_loc, |
jbradshaw | 1:9490836294ea | 105 | MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_NO_INT, ///< en_dcloffint_loc, en_bint_loc, en_bovf_loc, |
jbradshaw | 1:9490836294ea | 106 | MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_NO_INT, ///< en_bover_loc, en_bundr_loc, en_bcgmon_loc, |
jbradshaw | 1:9490836294ea | 107 | MAX30001::MAX30001_INT_B, MAX30001::MAX30001_NO_INT, MAX30001::MAX30001_NO_INT, ///< en_pint_loc, en_povf_loc, en_pedge_loc, |
jbradshaw | 1:9490836294ea | 108 | MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_INT_B, MAX30001::MAX30001_NO_INT, ///< en_lonint_loc, en_rrint_loc, en_samp_loc, |
jbradshaw | 1:9490836294ea | 109 | MAX30001::MAX30001_INT_ODNR, MAX30001::MAX30001_INT_ODNR); ///< intb_Type, int2b_Type) |
jbradshaw | 0:e4a10ed6eb92 | 110 | } |
jbradshaw | 0:e4a10ed6eb92 | 111 | |
jbradshaw | 0:e4a10ed6eb92 | 112 | |
jbradshaw | 0:e4a10ed6eb92 | 113 | |
jbradshaw | 0:e4a10ed6eb92 | 114 | static uint8_t serialNumber[6]; |
jbradshaw | 0:e4a10ed6eb92 | 115 | uint8_t *MAX30001_Helper_getVersion(void) { |
jbradshaw | 0:e4a10ed6eb92 | 116 | // read the id |
jbradshaw | 1:9490836294ea | 117 | Peripherals::max30001()->reg_read(MAX30001::INFO, (uint32_t *)serialNumber); |
jbradshaw | 0:e4a10ed6eb92 | 118 | // read id twice because it needs to be read twice |
jbradshaw | 1:9490836294ea | 119 | Peripherals::max30001()->reg_read(MAX30001::INFO, (uint32_t *)serialNumber); |
jbradshaw | 0:e4a10ed6eb92 | 120 | return serialNumber; |
jbradshaw | 0:e4a10ed6eb92 | 121 | } |