Maxim Integrated / Mbed OS MAXREFDES220_HEART_RATE_MONITOR

Dependencies:   USBDevice max32630fthr

Fork of MAXREFDES220# by Maxim Integrated

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SSMAX30101Comm.h Source File

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 whrm_data_rx(uint8_t *data_ptr);
00112     void accel_data_rx(uint8_t *data_ptr);
00113 
00114     /* PRIVATE TYPE DEFINITIONS */
00115     typedef enum _cmd_state_t {
00116         get_format_ppg_0,
00117         read_ppg_0,
00118         get_reg_ppg,
00119         set_reg_ppg,
00120         dump_reg_ppg,
00121         self_test_ppg_os24,
00122         self_test_ppg_acc,
00123         NUM_CMDS,
00124     } cmd_state_t;
00125 
00126     typedef struct {
00127         uint32_t led1;
00128         uint32_t led2;
00129         uint32_t led3;
00130         uint32_t led4;
00131     } max30101_mode1_data;
00132 
00133     typedef struct {
00134         uint16_t hr;
00135         uint8_t hr_conf;
00136         uint16_t spo2;
00137         uint8_t status;
00138     } whrm_mode1_data;
00139 
00140     typedef struct {
00141         int16_t x;
00142         int16_t y;
00143         int16_t z;
00144     } accel_mode1_data;
00145 
00146     typedef struct __attribute__((packed)) {
00147         uint32_t start_byte :8;
00148 
00149         uint32_t sample_cnt :32;
00150         uint32_t led1   :20;
00151         uint32_t led2   :20;
00152         uint32_t led3   :20;
00153         uint32_t led4   :20;
00154         uint32_t x  :14;    //Represent values of 0.000 through 8.191
00155         uint32_t y  :14;    //Represent values of 0.000 through 8.191
00156         uint32_t z  :14;    //Represent values of 0.000 through 8.191
00157         uint32_t hr :12;    //Represent values of 0.0 through 204.7
00158         uint32_t spo2   :11;    //Represent values of 0.0 through 102.3 (only need up to 100.0)
00159         uint32_t status :8;
00160 
00161         uint8_t :0;         //Align CRC byte on byte boundary
00162         uint8_t crc8:8;
00163     } ds_pkt_data_mode1;
00164 
00165     /* PRIVATE VARIABLES */
00166     USBSerial *m_USB;
00167     SSInterface *ss_int;
00168     DSInterface *ds_int;
00169 
00170     char charbuf[512];
00171     addr_val_pair reg_vals[64];
00172 
00173     queue_t max30101_queue;
00174     uint8_t max30101_queue_buf[64 * sizeof(max30101_mode1_data)];
00175 
00176     queue_t whrm_queue;
00177     uint8_t whrm_queue_buf[64 * sizeof(whrm_mode1_data)];
00178 
00179     queue_t accel_queue;
00180     uint8_t accel_queue_buf[64 * sizeof(accel_mode1_data)];
00181 
00182     ss_data_req max30101_mode1_data_req;
00183     ss_data_req whrm_mode1_data_req;
00184     ss_data_req accel_mode1_data_req;
00185 
00186     /* PRIVATE CONST VARIABLES */
00187     static const int SSMAX30101_REG_SIZE = 1;
00188     static const int SSMAX30101_MODE1_DATASIZE = 12;    //Taken from API doc
00189     static const int SSWHRM_MODE1_DATASIZE = 6;         //Taken from API doc
00190     static const int SSACCEL_MODE1_DATASIZE = 6;        //Taken from API doc
00191 };
00192 
00193 #endif /* _SSMAX30101COMM_H_ */