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: USBDevice max32630fthr
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 Execute the smart sensor self test routine 00086 * 00087 * @return SS_SUCCESS or error code 00088 */ 00089 int selftest_max30101(); 00090 00091 /** 00092 * @brief Execute the accelerometer self test routine 00093 * @return SS_SUCCESS or error code 00094 */ 00095 int selftest_accelerometer(); 00096 00097 /** 00098 * @brief Evaluate the accelerometer self test routine 00099 * 00100 * @param message - message to be printed in the failure cases 00101 * @param value - result of the self test passed as parameter 00102 * @return true if result is SUCCESSFULL false otherwise 00103 */ 00104 bool self_test_result_evaluate(const char *message, uint8_t value); 00105 00106 00107 private: 00108 00109 /* PRIVATE METHODS */ 00110 void max30101_data_rx(uint8_t *data_ptr); 00111 void bpt_data_rx(uint8_t *data_ptr); 00112 void whrm_data_rx(uint8_t *data_ptr); 00113 void accel_data_rx(uint8_t *data_ptr); 00114 void agc_data_rx(uint8_t *data_ptr); 00115 00116 int parse_cal_str(const char *ptr_ch, const char *cmd, uint8_t *cal_data, int cal_data_sz); 00117 00118 /* PRIVATE TYPE DEFINITIONS */ 00119 typedef enum _cmd_state_t { 00120 get_format_ppg_0, 00121 get_format_bpt_0, 00122 get_format_bpt_1, 00123 read_ppg_0, 00124 read_bpt_0, 00125 read_bpt_1, 00126 get_reg_ppg, 00127 set_reg_ppg, 00128 dump_reg_ppg, 00129 set_agc_dis, 00130 set_agc_en, 00131 set_cfg_bpt_med, 00132 set_cfg_bpt_sys_bp, 00133 set_cfg_bpt_dia_bp, 00134 get_cfg_bpt_cal_data, 00135 set_cfg_bpt_cal_data, 00136 set_cfg_bpt_date, 00137 set_cfg_bpt_nonrest, 00138 self_test_ppg_os24, 00139 self_test_ppg_acc, 00140 NUM_CMDS, 00141 } cmd_state_t; 00142 00143 typedef struct { 00144 uint32_t led1; 00145 uint32_t led2; 00146 uint32_t led3; 00147 uint32_t led4; 00148 } max30101_mode1_data; 00149 00150 typedef struct { 00151 uint16_t hr; 00152 uint8_t hr_conf; 00153 uint16_t spo2; 00154 uint8_t status; 00155 } whrm_mode1_data; 00156 00157 typedef struct { 00158 int16_t x; 00159 int16_t y; 00160 int16_t z; 00161 } accel_mode1_data; 00162 00163 typedef struct { 00164 uint8_t status; 00165 uint16_t sys_bp; 00166 uint16_t dia_bp; 00167 uint16_t hr; 00168 uint16_t prog; 00169 } bpt_mode1_2_data; 00170 00171 typedef struct __attribute__((packed)) { 00172 uint32_t start_byte :8; 00173 00174 uint32_t sample_cnt :32; 00175 uint32_t led1 :20; 00176 uint32_t led2 :20; 00177 uint32_t led3 :20; 00178 uint32_t led4 :20; 00179 uint32_t x :14; //Represent values of 0.000 through 8.191 00180 uint32_t y :14; //Represent values of 0.000 through 8.191 00181 uint32_t z :14; //Represent values of 0.000 through 8.191 00182 uint32_t hr :12; //Represent values of 0.0 through 204.7 00183 uint32_t spo2 :11; //Represent values of 0.0 through 102.3 (only need up to 100.0) 00184 uint32_t status :8; 00185 00186 uint8_t :0; //Align CRC byte on byte boundary 00187 uint8_t crc8:8; 00188 } ds_pkt_data_mode1; 00189 00190 typedef struct __attribute__((packed)) { 00191 uint32_t start_byte:8; 00192 00193 uint32_t status:4; 00194 uint32_t irCnt:19; 00195 uint32_t hr:9; 00196 uint32_t prog:9; 00197 uint32_t sys_bp:9; 00198 uint32_t dia_bp:9; 00199 00200 uint8_t :0; //Align to next byte 00201 uint8_t crc8:8; 00202 } ds_pkt_bpt_data; 00203 00204 /* PRIVATE VARIABLES */ 00205 USBSerial *m_USB; 00206 SSInterface *ss_int; 00207 DSInterface *ds_int; 00208 00209 char charbuf[512]; 00210 addr_val_pair reg_vals[64]; 00211 00212 queue_t max30101_queue; 00213 uint8_t max30101_queue_buf[64 * sizeof(max30101_mode1_data)]; 00214 00215 queue_t whrm_queue; 00216 uint8_t whrm_queue_buf[64 * sizeof(whrm_mode1_data)]; 00217 00218 queue_t accel_queue; 00219 uint8_t accel_queue_buf[64 * sizeof(accel_mode1_data)]; 00220 00221 queue_t bpt_queue; 00222 uint8_t bpt_queue_buf[64 * sizeof(bpt_mode1_2_data)]; 00223 00224 ss_data_req max30101_mode1_data_req; 00225 ss_data_req whrm_mode1_data_req; 00226 ss_data_req accel_mode1_data_req; 00227 ss_data_req agc_mode1_data_req; 00228 ss_data_req bpt_mode1_2_data_req; 00229 00230 bool agc_enabled; 00231 00232 /* PRIVATE CONST VARIABLES */ 00233 static const int SSMAX30101_REG_SIZE = 1; 00234 static const int SSMAX30101_MODE1_DATASIZE = 12; //Taken from API doc 00235 static const int SSWHRM_MODE1_DATASIZE = 6; //Taken from API doc 00236 static const int SSACCEL_MODE1_DATASIZE = 6; //Taken from API doc 00237 static const int SSAGC_MODE1_DATASIZE = 0; //Taken from API doc 00238 static const int SSBPT_MODE1_2_DATASIZE = 6; //Taken from API doc 00239 }; 00240 00241 #endif /* _SSMAX30101COMM_H_ */
Generated on Sat Jul 16 2022 17:57:31 by
1.7.2
Heart Rate SpO2 Algorithm EvKit Health Monitor Development System Board MAXREFDES220