Arun Raj / Mbed OS MAXREFDES101_SOURCE

Dependencies:   max32630fthr Adafruit_FeatherOLED USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MAX30001_Helper.h Source File

MAX30001_Helper.h

00001 #ifndef _MAX30001_HELPER_H_
00002 #define _MAX30001_HELPER_H_
00003 
00004 
00005 #include "mbed.h"
00006 #include "MaximSensor.h"
00007 #include "MAX30001.h"
00008 #include "queue.h"
00009 #include "EcgComm.h"
00010 
00011 #define SENSOR_ID_MAX30001  0x02
00012 
00013 class MAX30001_Helper: public MaximSensor
00014 {
00015 public:
00016     MAX30001_Helper(MAX30001 *m, InterruptIn *ir_B, InterruptIn *ir_2B);
00017     // Inherited function implementations from MaximSensor
00018     virtual int readRegister(uint8_t reg, uint8_t *data, int len);
00019 
00020     virtual int writeRegister(uint8_t reg,  const uint8_t data);
00021 
00022     /**
00023     * @brief    Get Maxim Sensor part and revision info.
00024     * @details  Reads Maxim Sensor part and revision info from device.
00025     *
00026     * @param[in]    reg Beginning address of a register to be read.
00027     * @param[out]   data Buffer space to save result value.
00028     * @param[in]    len Number of consecutive bytes to be read.
00029     *
00030     * @returns  0 on success, negative error code on failure.
00031     */
00032     virtual int get_part_info(uint8_t *part_id, uint8_t *rev_id);
00033 
00034     /**
00035     * @brief    Enables Maxim Sensor.
00036     * @details  Enable IRQ, enable LEDs, enable AGC
00037     *
00038     * @param[in]    enable Any value to enable, 0 to disable.
00039     *
00040     * @returns  0 on success, negative error code on failure.
00041     */
00042     virtual int sensor_enable(int enable);
00043 
00044     /**
00045     * @brief    Enables AGC.
00046     * @details  Enable Maxim Sensor automatic gain controller.
00047     *   AGC automatically adjusts sampling rates and LED currents to save energy.
00048     *
00049     * @param[in]    agc_enable Any value to enable, 0 to disable.
00050     *
00051     * @returns  0 on success, negative error code on failure.
00052     */
00053     virtual int agc_enable(int agc_enable);
00054 
00055     /**
00056     * @brief    Get sensor part name.
00057     *
00058     * @returns  Sensor part name string.
00059     */
00060     virtual const char *get_sensor_part_name();
00061 
00062     /**
00063     * @brief    Get sensor name.
00064     *
00065     * @returns  Sensor name string.
00066     */
00067     virtual const char *get_sensor_name();
00068 
00069     /**
00070     * @brief    Get sensor data
00071     *
00072     * @param[in]    data_report sensor_report struct to fill out
00073     # @returns      0 on success, less than 0 otherwise
00074     */
00075     virtual int get_sensor_report(ecg_sensor_report  &data_report);
00076 
00077     /**
00078     * @brief    Dump Maxim Sensor registers.
00079     * @details  Fill out register values into list
00080     *
00081     * @returns  0 on success, negative error code on failure.
00082     */
00083     virtual int dump_registers(addr_val_pair *reg_values);
00084 
00085 
00086     /**
00087     * @brief    Get sensor ID.
00088     *
00089     * @returns  Sensor ID number.
00090     */
00091     unsigned char get_sensor_id();
00092 
00093     // Implemented functions transferred mostly from HSP....
00094 
00095     virtual int MS_max30001readRegister(uint8_t addr, uint32_t *return_data);
00096 
00097     virtual int MS_max30001writeRegister(uint8_t addr, uint32_t data);
00098 
00099     virtual int MS_Max30001_ECG_InitStart(uint8_t En_ecg, uint8_t Openp, uint8_t Openn,
00100                          uint8_t Pol, uint8_t Calp_sel, uint8_t Caln_sel,
00101                                          uint8_t E_fit, uint8_t Rate, uint8_t Gain,
00102                                          uint8_t Dhpf, uint8_t Dlpf);
00103 
00104     virtual int MS_Max30001_ECG_Stop();
00105 
00106     // ECG Max30001 RtoR Initialization Function
00107     virtual  int MS_Max30001_RtoR_InitStart(uint8_t En_rtor, uint8_t Wndw, uint8_t Gain,
00108             uint8_t Pavg, uint8_t Ptsf, uint8_t Hoff,
00109             uint8_t Ravg, uint8_t Rhsf, uint8_t Clr_rrint);
00110 
00111     virtual int MS_Max30001_RtoR_Stop();
00112 
00113     // This function enables the interrupts for specific parameters
00114     virtual int MS_max30001_INT_assignment(uint8_t en_enint_loc,     uint8_t en_eovf_loc,  uint8_t en_fstint_loc,
00115                                            uint8_t en_dcloffint_loc, uint8_t en_bint_loc,  uint8_t en_bovf_loc,
00116                                            uint8_t en_bover_loc,     uint8_t en_bundr_loc, uint8_t en_bcgmon_loc,
00117                                            uint8_t en_pint_loc,      uint8_t en_povf_loc,  uint8_t en_pedge_loc,
00118                                            uint8_t en_lonint_loc,    uint8_t en_rrint_loc, uint8_t en_samp_loc,
00119                                            uint8_t intb_Type,        uint8_t int2b_Type);
00120 
00121     // call sync function of the sensor
00122     int MS_max30001sync();
00123 
00124     // That Function Should Only Be called from interrupt context
00125     void Max30001Helper_AddDataToQueue(uint32_t id, uint32_t *buffer, uint32_t number);
00126 
00127 
00128    /**
00129     *
00130     * @param[in] status the value to set the interrupt status
00131     *                   variable
00132     */
00133     void  Max30001Helper_setInterruptStatus(bool status);
00134 
00135     /**
00136      *
00137      * @return status of the interrupt
00138      */
00139     bool  Max30001Helper_getInterruptStatus();
00140 
00141     /**
00142      * @brief Call the interrupt handler of Max30001
00143      */
00144     void Max30001Helper_max30001_int_handler(void);
00145 
00146     int MAX30001_Helper_Queue_Size(void);
00147 
00148     int  MAX30001_Helper_Invert_Waveform(void);
00149 
00150     enum Max30001_Helper_ECG_Sample_Rate {
00151         k512SPS = 0b00,
00152         k256SPS = 0b01,
00153         k128SPS = 0b10
00154     };
00155 
00156     /**
00157      *
00158      * @param ecg_rate
00159      * @return
00160      */
00161     int Max30001Helper_SetECGSampleRate(Max30001_Helper_ECG_Sample_Rate ecg_rate);
00162 
00163 private:
00164 
00165     /***
00166      *
00167      * @return
00168      */
00169     void Max30001_Helper_ConvertRtoRtoBPM(uint16_t rtor_val);
00170 
00171     uint8_t m_rtor_last_bpm_;
00172 
00173     void Max30001_Helper_SetInterrupts(char en);
00174 
00175     /**
00176      *
00177      */
00178     int Max30001Helper_InitializeECGandRtoR();
00179 
00180     ecg_sensor_report  m_ecg_packet_;
00181     MAX30001 *m_max30001;
00182     InterruptIn *m_max30001_InterruptB;
00183     InterruptIn *m_max30001_Interrupt2B;
00184     queue_t mmax30001_queue;
00185 };
00186 
00187 
00188 void StreamPacketUint32(uint32_t id, uint32_t *buffer, uint32_t number);
00189 
00190 #endif