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: max32630fthr USBDevice
Fork of MAXREFDES220_HEART_RATE_MONITOR by
SSMAX30101Comm.h
00001 /******************************************************************************* 00002 * Copyright (C) 2017 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 #ifndef _SSMAX30101COMM_H_ 00035 #define _SSMAX30101COMM_H_ 00036 00037 #include "mbed.h" 00038 #include "SensorComm.h" 00039 #include "USBSerial.h" 00040 #include "SSInterface.h" 00041 #include "queue.h" 00042 00043 /** 00044 * @brief SSMAX30101Comm Command handler class for communication with MAX30101 on SmartSensor board 00045 * @details 00046 */ 00047 class SSMAX30101Comm: public SensorComm 00048 { 00049 public: 00050 00051 /* PUBLIC FUNCTION DECLARATIONS */ 00052 /** 00053 * @brief SSMAX30101Comm constructor. 00054 * 00055 */ 00056 SSMAX30101Comm(USBSerial* USB, SSInterface* ssInterface, DSInterface* dsInterface); 00057 00058 /** 00059 * @brief Parses DeviceStudio-style commands. 00060 * @details Parses and executes commands. Prints return code to i/o device. 00061 * @returns true if sensor acted upon the command, false if command was unknown 00062 */ 00063 bool parse_command(const char* cmd); 00064 00065 /** 00066 * @brief Fill in buffer with sensor data 00067 * 00068 * @param[in] buf Buffer to fill data into 00069 * @param[in] size Maximum size of buffer 00070 * @param[out] Number of bytes written to buffer 00071 */ 00072 int data_report_execute(char* buf, int size); 00073 00074 /** 00075 * @brief Stop collecting data and disable sensor 00076 */ 00077 void stop(); 00078 00079 /** 00080 * @brief Get the maxim part number of the device 00081 */ 00082 const char* get_part_name() { return "max30101"; } 00083 00084 /** 00085 * @brief Get the algorithm version of the device 00086 */ 00087 const char* get_algo_ver(); 00088 00089 /** 00090 * @brief Execute the smart sensor self test routine 00091 * 00092 * @return SS_SUCCESS or error code 00093 */ 00094 int selftest_max30101(); 00095 00096 /** 00097 * @brief Execute the accelerometer self test routine 00098 * @return SS_SUCCESS or error code 00099 */ 00100 int selftest_accelerometer(); 00101 00102 /** 00103 * @brief Evaluate the accelerometer self test routine 00104 * 00105 * @param message - message to be printed in the failure cases 00106 * @param value - result of the self test passed as parameter 00107 * @return true if result is SUCCESSFULL false otherwise 00108 */ 00109 bool self_test_result_evaluate(const char *message, uint8_t value); 00110 00111 00112 private: 00113 00114 /* PRIVATE METHODS */ 00115 void max30101_data_rx(uint8_t *data_ptr); 00116 void bpt_data_rx(uint8_t *data_ptr); 00117 void whrm_data_rx(uint8_t *data_ptr); 00118 void accel_data_rx(uint8_t *data_ptr); 00119 void agc_data_rx(uint8_t *data_ptr); 00120 00121 int parse_cal_str(const char *ptr_ch, const char *cmd, uint8_t *cal_data, int cal_data_sz); 00122 00123 /* PRIVATE TYPE DEFINITIONS */ 00124 typedef enum _cmd_state_t { 00125 get_format_ppg_0, 00126 get_format_bpt_0, 00127 get_format_bpt_1, 00128 read_ppg_0, 00129 read_bpt_0, 00130 read_bpt_1, 00131 get_reg_ppg, 00132 set_reg_ppg, 00133 dump_reg_ppg, 00134 set_agc_dis, 00135 set_agc_en, 00136 set_cfg_bpt_med, 00137 set_cfg_bpt_sys_bp, 00138 set_cfg_bpt_dia_bp, 00139 set_cfg_bpt_date, 00140 set_cfg_bpt_nonrest, 00141 self_test_ppg_os24, 00142 self_test_ppg_acc, 00143 NUM_CMDS, 00144 } cmd_state_t; 00145 00146 typedef struct { 00147 uint32_t led1; 00148 uint32_t led2; 00149 uint32_t led3; 00150 uint32_t led4; 00151 } max30101_mode1_data; 00152 00153 typedef struct { 00154 uint16_t hr; 00155 uint8_t hr_conf; 00156 uint16_t spo2; 00157 uint8_t status; 00158 } whrm_mode1_data; 00159 00160 typedef struct { 00161 int16_t x; 00162 int16_t y; 00163 int16_t z; 00164 } accel_mode1_data; 00165 00166 typedef struct { 00167 uint8_t status; 00168 uint16_t sys_bp; 00169 uint16_t dia_bp; 00170 uint16_t hr; 00171 uint16_t prog; 00172 } bpt_mode1_2_data; 00173 00174 typedef struct __attribute__((packed)) { 00175 uint32_t start_byte :8; 00176 00177 uint32_t sample_cnt :32; 00178 uint32_t led1 :20; 00179 uint32_t led2 :20; 00180 uint32_t led3 :20; 00181 uint32_t led4 :20; 00182 uint32_t x :14; //Represent values of 0.000 through 8.191 00183 uint32_t y :14; //Represent values of 0.000 through 8.191 00184 uint32_t z :14; //Represent values of 0.000 through 8.191 00185 uint32_t hr :12; //Represent values of 0.0 through 204.7 00186 uint32_t spo2 :11; //Represent values of 0.0 through 102.3 (only need up to 100.0) 00187 uint32_t status :8; 00188 00189 uint8_t :0; //Align CRC byte on byte boundary 00190 uint8_t crc8:8; 00191 } ds_pkt_data_mode1; 00192 00193 typedef struct __attribute__((packed)) { 00194 uint32_t start_byte:8; 00195 00196 uint32_t status:4; 00197 uint32_t irCnt:19; 00198 uint32_t hr:9; 00199 uint32_t prog:9; 00200 uint32_t sys_bp:9; 00201 uint32_t dia_bp:9; 00202 00203 uint8_t :0; //Align to next byte 00204 uint8_t crc8:8; 00205 } ds_pkt_bpt_data; 00206 00207 /* PRIVATE VARIABLES */ 00208 USBSerial *m_USB; 00209 SSInterface *ss_int; 00210 DSInterface *ds_int; 00211 00212 char charbuf[512]; 00213 addr_val_pair reg_vals[64]; 00214 00215 queue_t max30101_queue; 00216 uint8_t max30101_queue_buf[64 * sizeof(max30101_mode1_data)]; 00217 00218 queue_t whrm_queue; 00219 uint8_t whrm_queue_buf[64 * sizeof(whrm_mode1_data)]; 00220 00221 queue_t accel_queue; 00222 uint8_t accel_queue_buf[64 * sizeof(accel_mode1_data)]; 00223 00224 queue_t bpt_queue; 00225 uint8_t bpt_queue_buf[64 * sizeof(bpt_mode1_2_data)]; 00226 00227 ss_data_req max30101_mode1_data_req; 00228 ss_data_req whrm_mode1_data_req; 00229 ss_data_req accel_mode1_data_req; 00230 ss_data_req agc_mode1_data_req; 00231 ss_data_req bpt_mode1_2_data_req; 00232 00233 bool agc_enabled; 00234 00235 /* PRIVATE CONST VARIABLES */ 00236 static const int SSMAX30101_REG_SIZE = 1; 00237 static const int SSMAX30101_MODE1_DATASIZE = 12; //Taken from API doc 00238 static const int SSWHRM_MODE1_DATASIZE = 6; //Taken from API doc 00239 static const int SSACCEL_MODE1_DATASIZE = 6; //Taken from API doc 00240 static const int SSAGC_MODE1_DATASIZE = 0; //Taken from API doc 00241 static const int SSBPT_MODE1_2_DATASIZE = 6; //Taken from API doc 00242 }; 00243 00244 #endif /* _SSMAX30101COMM_H_ */
Generated on Tue Jul 12 2022 10:59:32 by
1.7.2

Heart Rate SpO2 Algorithm EvKit Health Monitor Development System Board MAXREFDES220