Maxim Integrated / Mbed OS MAXREFDES220_HR_SPO2_MONITOR

Dependencies:   max32630fthr USBDevice

Fork of MAXREFDES220_HEART_RATE_MONITOR by Maxim Integrated

Finger Heart Rate Monitor and SpO2 Monitor

The MAXREFDES220 Smart Sensor FeatherWing board is a integrated solution for providing finger-based heart rate measurements and SpO2 (blood oxygen saturation). This evaluation board interfaces to the host computer using the I2C interface. Heart rate outpu is available in beats per minute (BPM) and SpO2 is reported in percentages.; the PPG (photoplethysmography) raw data is also available. The board has an MAX30101 chip which is a low power heart rate monitor with adjustable sample rates and adjustable LED currents. The low cost MAX32664 microcontroller is pre-flashed with C code for finger-based pulse rate and SpO2 monitoring. Bootloader software is included to allow for future algorithms or updates to the algorithm from Maxim Integrated.

Ordering information will be available soon.

Note: SpO2 values are not calibrated. Calibration should be performed using the final end product.

Warning

The MAXREFDES220 source code listed is dated and only compatible with the 1.2.8a.msbl. The latest sample host source code is available on the MAX32664 website.

MAXREFDES220 FeatherWing Pinout Connections

/media/uploads/phonemacro/maxrefdes220_pinouts_heart_rate_monitor.jpg

Committer:
Shaun Kelsey
Date:
Wed Apr 11 16:01:32 2018 -0700
Revision:
0:da5f5b56060a
Child:
5:e458409e913f
Initial commit of Pegasus OS24 SmartSensor Host

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Shaun Kelsey 0:da5f5b56060a 1 /*******************************************************************************
Shaun Kelsey 0:da5f5b56060a 2 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
Shaun Kelsey 0:da5f5b56060a 3 *
Shaun Kelsey 0:da5f5b56060a 4 * Permission is hereby granted, free of charge, to any person obtaining a
Shaun Kelsey 0:da5f5b56060a 5 * copy of this software and associated documentation files (the "Software"),
Shaun Kelsey 0:da5f5b56060a 6 * to deal in the Software without restriction, including without limitation
Shaun Kelsey 0:da5f5b56060a 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Shaun Kelsey 0:da5f5b56060a 8 * and/or sell copies of the Software, and to permit persons to whom the
Shaun Kelsey 0:da5f5b56060a 9 * Software is furnished to do so, subject to the following conditions:
Shaun Kelsey 0:da5f5b56060a 10 *
Shaun Kelsey 0:da5f5b56060a 11 * The above copyright notice and this permission notice shall be included
Shaun Kelsey 0:da5f5b56060a 12 * in all copies or substantial portions of the Software.
Shaun Kelsey 0:da5f5b56060a 13 *
Shaun Kelsey 0:da5f5b56060a 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
Shaun Kelsey 0:da5f5b56060a 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Shaun Kelsey 0:da5f5b56060a 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Shaun Kelsey 0:da5f5b56060a 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
Shaun Kelsey 0:da5f5b56060a 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
Shaun Kelsey 0:da5f5b56060a 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
Shaun Kelsey 0:da5f5b56060a 20 * OTHER DEALINGS IN THE SOFTWARE.
Shaun Kelsey 0:da5f5b56060a 21 *
Shaun Kelsey 0:da5f5b56060a 22 * Except as contained in this notice, the name of Maxim Integrated
Shaun Kelsey 0:da5f5b56060a 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
Shaun Kelsey 0:da5f5b56060a 24 * Products, Inc. Branding Policy.
Shaun Kelsey 0:da5f5b56060a 25 *
Shaun Kelsey 0:da5f5b56060a 26 * The mere transfer of this software does not imply any licenses
Shaun Kelsey 0:da5f5b56060a 27 * of trade secrets, proprietary technology, copyrights, patents,
Shaun Kelsey 0:da5f5b56060a 28 * trademarks, maskwork rights, or any other form of intellectual
Shaun Kelsey 0:da5f5b56060a 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
Shaun Kelsey 0:da5f5b56060a 30 * ownership rights.
Shaun Kelsey 0:da5f5b56060a 31 *******************************************************************************
Shaun Kelsey 0:da5f5b56060a 32 */
Shaun Kelsey 0:da5f5b56060a 33
Shaun Kelsey 0:da5f5b56060a 34 #ifndef _SSMAX30101COMM_H_
Shaun Kelsey 0:da5f5b56060a 35 #define _SSMAX30101COMM_H_
Shaun Kelsey 0:da5f5b56060a 36
Shaun Kelsey 0:da5f5b56060a 37 #include "mbed.h"
Shaun Kelsey 0:da5f5b56060a 38 #include "SensorComm.h"
Shaun Kelsey 0:da5f5b56060a 39 #include "USBSerial.h"
Shaun Kelsey 0:da5f5b56060a 40 #include "SSInterface.h"
Shaun Kelsey 0:da5f5b56060a 41 #include "queue.h"
Shaun Kelsey 0:da5f5b56060a 42
Shaun Kelsey 0:da5f5b56060a 43 /**
Shaun Kelsey 0:da5f5b56060a 44 * @brief SSMAX30101Comm Command handler class for communication with MAX30101 on SmartSensor board
Shaun Kelsey 0:da5f5b56060a 45 * @details
Shaun Kelsey 0:da5f5b56060a 46 */
Shaun Kelsey 0:da5f5b56060a 47 class SSMAX30101Comm: public SensorComm
Shaun Kelsey 0:da5f5b56060a 48 {
Shaun Kelsey 0:da5f5b56060a 49 public:
Shaun Kelsey 0:da5f5b56060a 50
Shaun Kelsey 0:da5f5b56060a 51 /* PUBLIC FUNCTION DECLARATIONS */
Shaun Kelsey 0:da5f5b56060a 52 /**
Shaun Kelsey 0:da5f5b56060a 53 * @brief SSMAX30101Comm constructor.
Shaun Kelsey 0:da5f5b56060a 54 *
Shaun Kelsey 0:da5f5b56060a 55 */
Shaun Kelsey 0:da5f5b56060a 56 SSMAX30101Comm(USBSerial* USB, SSInterface* ssInterface, DSInterface* dsInterface);
Shaun Kelsey 0:da5f5b56060a 57
Shaun Kelsey 0:da5f5b56060a 58 /**
Shaun Kelsey 0:da5f5b56060a 59 * @brief Parses DeviceStudio-style commands.
Shaun Kelsey 0:da5f5b56060a 60 * @details Parses and executes commands. Prints return code to i/o device.
Shaun Kelsey 0:da5f5b56060a 61 * @returns true if sensor acted upon the command, false if command was unknown
Shaun Kelsey 0:da5f5b56060a 62 */
Shaun Kelsey 0:da5f5b56060a 63 bool parse_command(const char* cmd);
Shaun Kelsey 0:da5f5b56060a 64
Shaun Kelsey 0:da5f5b56060a 65 /**
Shaun Kelsey 0:da5f5b56060a 66 * @brief Fill in buffer with sensor data
Shaun Kelsey 0:da5f5b56060a 67 *
Shaun Kelsey 0:da5f5b56060a 68 * @param[in] buf Buffer to fill data into
Shaun Kelsey 0:da5f5b56060a 69 * @param[in] size Maximum size of buffer
Shaun Kelsey 0:da5f5b56060a 70 * @param[out] Number of bytes written to buffer
Shaun Kelsey 0:da5f5b56060a 71 */
Shaun Kelsey 0:da5f5b56060a 72 int data_report_execute(char* buf, int size);
Shaun Kelsey 0:da5f5b56060a 73
Shaun Kelsey 0:da5f5b56060a 74 /**
Shaun Kelsey 0:da5f5b56060a 75 * @brief Stop collecting data and disable sensor
Shaun Kelsey 0:da5f5b56060a 76 */
Shaun Kelsey 0:da5f5b56060a 77 void stop();
Shaun Kelsey 0:da5f5b56060a 78
Shaun Kelsey 0:da5f5b56060a 79 /**
Shaun Kelsey 0:da5f5b56060a 80 * @brief Get the maxim part number of the device
Shaun Kelsey 0:da5f5b56060a 81 */
Shaun Kelsey 0:da5f5b56060a 82 const char* get_part_name() { return "max30101"; }
Shaun Kelsey 0:da5f5b56060a 83
Shaun Kelsey 0:da5f5b56060a 84 /**
Shaun Kelsey 0:da5f5b56060a 85 * @brief Execute the smart sensor self test routine
Shaun Kelsey 0:da5f5b56060a 86 *
Shaun Kelsey 0:da5f5b56060a 87 * @return SS_SUCCESS or error code
Shaun Kelsey 0:da5f5b56060a 88 */
Shaun Kelsey 0:da5f5b56060a 89 int selftest_max30101();
Shaun Kelsey 0:da5f5b56060a 90
Shaun Kelsey 0:da5f5b56060a 91 /**
Shaun Kelsey 0:da5f5b56060a 92 * @brief Execute the accelerometer self test routine
Shaun Kelsey 0:da5f5b56060a 93 * @return SS_SUCCESS or error code
Shaun Kelsey 0:da5f5b56060a 94 */
Shaun Kelsey 0:da5f5b56060a 95 int selftest_accelerometer();
Shaun Kelsey 0:da5f5b56060a 96
Shaun Kelsey 0:da5f5b56060a 97 /**
Shaun Kelsey 0:da5f5b56060a 98 * @brief Evaluate the accelerometer self test routine
Shaun Kelsey 0:da5f5b56060a 99 *
Shaun Kelsey 0:da5f5b56060a 100 * @param message - message to be printed in the failure cases
Shaun Kelsey 0:da5f5b56060a 101 * @param value - result of the self test passed as parameter
Shaun Kelsey 0:da5f5b56060a 102 * @return true if result is SUCCESSFULL false otherwise
Shaun Kelsey 0:da5f5b56060a 103 */
Shaun Kelsey 0:da5f5b56060a 104 bool self_test_result_evaluate(const char *message, uint8_t value);
Shaun Kelsey 0:da5f5b56060a 105
Shaun Kelsey 0:da5f5b56060a 106
Shaun Kelsey 0:da5f5b56060a 107 private:
Shaun Kelsey 0:da5f5b56060a 108
Shaun Kelsey 0:da5f5b56060a 109 /* PRIVATE METHODS */
Shaun Kelsey 0:da5f5b56060a 110 void max30101_data_rx(uint8_t *data_ptr);
Shaun Kelsey 0:da5f5b56060a 111 void whrm_data_rx(uint8_t *data_ptr);
Shaun Kelsey 0:da5f5b56060a 112 void accel_data_rx(uint8_t *data_ptr);
Shaun Kelsey 0:da5f5b56060a 113
Shaun Kelsey 0:da5f5b56060a 114 /* PRIVATE TYPE DEFINITIONS */
Shaun Kelsey 0:da5f5b56060a 115 typedef enum _cmd_state_t {
Shaun Kelsey 0:da5f5b56060a 116 get_format_ppg_0,
Shaun Kelsey 0:da5f5b56060a 117 read_ppg_0,
Shaun Kelsey 0:da5f5b56060a 118 get_reg_ppg,
Shaun Kelsey 0:da5f5b56060a 119 set_reg_ppg,
Shaun Kelsey 0:da5f5b56060a 120 dump_reg_ppg,
Shaun Kelsey 0:da5f5b56060a 121 self_test_ppg_os24,
Shaun Kelsey 0:da5f5b56060a 122 self_test_ppg_acc,
Shaun Kelsey 0:da5f5b56060a 123 NUM_CMDS,
Shaun Kelsey 0:da5f5b56060a 124 } cmd_state_t;
Shaun Kelsey 0:da5f5b56060a 125
Shaun Kelsey 0:da5f5b56060a 126 typedef struct {
Shaun Kelsey 0:da5f5b56060a 127 uint32_t led1;
Shaun Kelsey 0:da5f5b56060a 128 uint32_t led2;
Shaun Kelsey 0:da5f5b56060a 129 uint32_t led3;
Shaun Kelsey 0:da5f5b56060a 130 uint32_t led4;
Shaun Kelsey 0:da5f5b56060a 131 } max30101_mode1_data;
Shaun Kelsey 0:da5f5b56060a 132
Shaun Kelsey 0:da5f5b56060a 133 typedef struct {
Shaun Kelsey 0:da5f5b56060a 134 uint16_t hr;
Shaun Kelsey 0:da5f5b56060a 135 uint8_t hr_conf;
Shaun Kelsey 0:da5f5b56060a 136 uint16_t spo2;
Shaun Kelsey 0:da5f5b56060a 137 uint8_t status;
Shaun Kelsey 0:da5f5b56060a 138 } whrm_mode1_data;
Shaun Kelsey 0:da5f5b56060a 139
Shaun Kelsey 0:da5f5b56060a 140 typedef struct {
Shaun Kelsey 0:da5f5b56060a 141 int16_t x;
Shaun Kelsey 0:da5f5b56060a 142 int16_t y;
Shaun Kelsey 0:da5f5b56060a 143 int16_t z;
Shaun Kelsey 0:da5f5b56060a 144 } accel_mode1_data;
Shaun Kelsey 0:da5f5b56060a 145
Shaun Kelsey 0:da5f5b56060a 146 typedef struct __attribute__((packed)) {
Shaun Kelsey 0:da5f5b56060a 147 uint32_t start_byte :8;
Shaun Kelsey 0:da5f5b56060a 148
Shaun Kelsey 0:da5f5b56060a 149 uint32_t sample_cnt :32;
Shaun Kelsey 0:da5f5b56060a 150 uint32_t led1 :20;
Shaun Kelsey 0:da5f5b56060a 151 uint32_t led2 :20;
Shaun Kelsey 0:da5f5b56060a 152 uint32_t led3 :20;
Shaun Kelsey 0:da5f5b56060a 153 uint32_t led4 :20;
Shaun Kelsey 0:da5f5b56060a 154 uint32_t x :14; //Represent values of 0.000 through 8.191
Shaun Kelsey 0:da5f5b56060a 155 uint32_t y :14; //Represent values of 0.000 through 8.191
Shaun Kelsey 0:da5f5b56060a 156 uint32_t z :14; //Represent values of 0.000 through 8.191
Shaun Kelsey 0:da5f5b56060a 157 uint32_t hr :12; //Represent values of 0.0 through 204.7
Shaun Kelsey 0:da5f5b56060a 158 uint32_t spo2 :11; //Represent values of 0.0 through 102.3 (only need up to 100.0)
Shaun Kelsey 0:da5f5b56060a 159 uint32_t status :8;
Shaun Kelsey 0:da5f5b56060a 160
Shaun Kelsey 0:da5f5b56060a 161 uint8_t :0; //Align CRC byte on byte boundary
Shaun Kelsey 0:da5f5b56060a 162 uint8_t crc8:8;
Shaun Kelsey 0:da5f5b56060a 163 } ds_pkt_data_mode1;
Shaun Kelsey 0:da5f5b56060a 164
Shaun Kelsey 0:da5f5b56060a 165 /* PRIVATE VARIABLES */
Shaun Kelsey 0:da5f5b56060a 166 USBSerial *m_USB;
Shaun Kelsey 0:da5f5b56060a 167 SSInterface *ss_int;
Shaun Kelsey 0:da5f5b56060a 168 DSInterface *ds_int;
Shaun Kelsey 0:da5f5b56060a 169
Shaun Kelsey 0:da5f5b56060a 170 char charbuf[512];
Shaun Kelsey 0:da5f5b56060a 171 addr_val_pair reg_vals[64];
Shaun Kelsey 0:da5f5b56060a 172
Shaun Kelsey 0:da5f5b56060a 173 queue_t max30101_queue;
Shaun Kelsey 0:da5f5b56060a 174 uint8_t max30101_queue_buf[64 * sizeof(max30101_mode1_data)];
Shaun Kelsey 0:da5f5b56060a 175
Shaun Kelsey 0:da5f5b56060a 176 queue_t whrm_queue;
Shaun Kelsey 0:da5f5b56060a 177 uint8_t whrm_queue_buf[64 * sizeof(whrm_mode1_data)];
Shaun Kelsey 0:da5f5b56060a 178
Shaun Kelsey 0:da5f5b56060a 179 queue_t accel_queue;
Shaun Kelsey 0:da5f5b56060a 180 uint8_t accel_queue_buf[64 * sizeof(accel_mode1_data)];
Shaun Kelsey 0:da5f5b56060a 181
Shaun Kelsey 0:da5f5b56060a 182 ss_data_req max30101_mode1_data_req;
Shaun Kelsey 0:da5f5b56060a 183 ss_data_req whrm_mode1_data_req;
Shaun Kelsey 0:da5f5b56060a 184 ss_data_req accel_mode1_data_req;
Shaun Kelsey 0:da5f5b56060a 185
Shaun Kelsey 0:da5f5b56060a 186 /* PRIVATE CONST VARIABLES */
Shaun Kelsey 0:da5f5b56060a 187 static const int SSMAX30101_REG_SIZE = 1;
Shaun Kelsey 0:da5f5b56060a 188 static const int SSMAX30101_MODE1_DATASIZE = 12; //Taken from API doc
Shaun Kelsey 0:da5f5b56060a 189 static const int SSWHRM_MODE1_DATASIZE = 6; //Taken from API doc
Shaun Kelsey 0:da5f5b56060a 190 static const int SSACCEL_MODE1_DATASIZE = 6; //Taken from API doc
Shaun Kelsey 0:da5f5b56060a 191 };
Shaun Kelsey 0:da5f5b56060a 192
Shaun Kelsey 0:da5f5b56060a 193 #endif /* _SSMAX30101COMM_H_ */