MAX32620HSP (MAXREFDES100) RPC Example for Graphical User Interface

Dependencies:   USBDevice

Fork of HSP_Release by Jerry Bradshaw

This is an example program for the MAX32620HSP (MAXREFDES100 Health Sensor Platform). It demonstrates all the features of the platform and works with a companion graphical user interface (GUI) to help evaluate/configure/monitor the board. Go to the MAXREFDES100 product page and click on "design resources" to download the companion software. The GUI connects to the board through an RPC interface on a virtual serial port over the USB interface.

The RPC interface provides access to all the features of the board and is available to interface with other development environments such Matlab. This firmware provides realtime data streaming through the RPC interface over USB, and also provides the ability to log the data to flash for untethered battery operation. The data logging settings are configured through the GUI, and the GUI also provides the interface to download logged data.

Details on the RPC interface can be found here: HSP RPC Interface Documentation

Windows

With this program loaded, the MAX32620HSP will appear on your computer as a serial port. On Mac and Linux, this will happen by default. For Windows, you need to install a driver: HSP serial port windows driver

For more details about this platform and how to use it, see the MAXREFDES100 product page.

Revision:
1:9490836294ea
Parent:
0:e4a10ed6eb92
--- a/HSP/Devices/MAX30001/MAX30001/MAX30001.h	Tue Oct 25 15:22:11 2016 +0000
+++ b/HSP/Devices/MAX30001/MAX30001/MAX30001.h	Fri Apr 21 12:12:30 2017 -0500
@@ -1,52 +1,209 @@
 /*******************************************************************************
-* Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
-*
-* Permission is hereby granted, free of charge, to any person obtaining a
-* copy of this software and associated documentation files (the "Software"),
-* to deal in the Software without restriction, including without limitation
-* the rights to use, copy, modify, merge, publish, distribute, sublicense,
-* and/or sell copies of the Software, and to permit persons to whom the
-* Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice shall be included
-* in all copies or substantial portions of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
-* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-* OTHER DEALINGS IN THE SOFTWARE.
-*
-* Except as contained in this notice, the name of Maxim Integrated
-* Products, Inc. shall not be used except as stated in the Maxim Integrated
-* Products, Inc. Branding Policy.
-*
-* The mere transfer of this software does not imply any licenses
-* of trade secrets, proprietary technology, copyrights, patents,
-* trademarks, maskwork rights, or any other form of intellectual
-* property whatsoever. Maxim Integrated Products, Inc. retains all
-* ownership rights.
-*******************************************************************************/
-/*
- * max30001.h
+ * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Maxim Integrated
+ * Products, Inc. shall not be used except as stated in the Maxim Integrated
+ * Products, Inc. Branding Policy.
+ *
+ * The mere transfer of this software does not imply any licenses
+ * of trade secrets, proprietary technology, copyrights, patents,
+ * trademarks, maskwork rights, or any other form of intellectual
+ * property whatsoever. Maxim Integrated Products, Inc. retains all
+ * ownership rights.
+ *******************************************************************************/
+/**
+ *
+ * Maxim Integrated MAX30001 ECG/BIOZ chip 
  *
- *  Created on: Oct 9, 2015
- *      Author: faisal.tariq
+ * @code
+ * #include "mbed.h"
+ * #include "MAX30001.h"
+ * 
+ * /// Initialization values for ECG_InitStart()
+ * #define EN_ECG     0b1
+ * #define OPENP      0b1
+ * #define OPENN      0b1
+ * #define POL        0b0
+ * #define CALP_SEL   0b10
+ * #define CALN_SEL   0b11
+ * #define E_FIT      31
+ * #define RATE       0b00
+ * #define GAIN       0b00
+ * #define DHPF       0b0
+ * #define DLPF       0b01
+ * 
+ * /// Initialization values for CAL_InitStart() 
+ * #define EN_VCAL  0b1
+ * #define VMODE    0b1
+ * #define VMAG     0b1
+ * #define FCAL     0b011
+ * #define THIGH    0x7FF
+ * #define FIFTY    0b0
+ * 
+ * /// Initializaton values for Rbias_FMSTR_Init()
+ * #define EN_RBIAS 0b01 
+ * #define RBIASV   0b10
+ * #define RBIASP   0b1
+ * #define RBIASN   0b1
+ * #define FMSTR    0b00
+ * 
+ * #define BUFFER_LENGTH 50
+ * 
+ * // @brief SPI Master 0 with SPI0_SS for use with MAX30001
+ * SPI spi(SPI0_MOSI, SPI0_MISO, SPI0_SCK, SPI0_SS); // used by MAX30001
+ * 
+ * //@brief ECG device
+ * MAX30001 max30001(&spi);
+ * InterruptIn max30001_InterruptB(P3_6);
+ * InterruptIn max30001_Interrupt2B(P4_5);
+ * //@brief PWM used as fclk for the MAX30001
+ * PwmOut pwmout(P1_7);
+ * 
+ * //@brief Creating a buffer to hold the data
+ * uint32_t ecgBuffer[BUFFER_LENGTH];
+ * int ecgIndex = 0;
+ * char data_trigger = 0;
+ * 
+ * 
+ * //
+ * // @brief Creates a packet that will be streamed via USB Serial
+ * //       the packet created will be inserted into a fifo to be streamed at a later time
+ * // @param id Streaming ID
+ * // @param buffer Pointer to a uint32 array that contains the data to include in the packet
+ * // @param number Number of elements in the buffer
+ * //
+ * void StreamPacketUint32_ecg(uint32_t id, uint32_t *buffer, uint32_t number) {
+ *   int i;
+ *   if (id == MAX30001_DATA_ECG) {
+ *     for (i = 0; i < number; i++) {
+ *       ecgBuffer[ecgIndex] = buffer[i];
+ *       ecgIndex++;
+ *       if (ecgIndex > BUFFER_LENGTH)
+ *         {
+ *         data_trigger = 1;
+ *         ecgIndex = 0;
+ *         }
+ *     }
+ *   }
+ *   if (id == MAX30001_DATA_BIOZ) {
+ *         /// Add code for reading BIOZ data
+ *   }
+ *   if (id == MAX30001_DATA_PACE) {
+ *         ///  Add code for reading Pace data
+ *   }
+ *   if (id == MAX30001_DATA_RTOR) {
+ *         /// Add code for reading RtoR data
+ *   }
+ * }
+ * 
+ * 
+ * int main() {
+ * 
+ *   uint32_t all;
+ * 
+ *   /// set NVIC priorities for GPIO to prevent priority inversion
+ *   NVIC_SetPriority(GPIO_P0_IRQn, 5);
+ *   NVIC_SetPriority(GPIO_P1_IRQn, 5);
+ *   NVIC_SetPriority(GPIO_P2_IRQn, 5);
+ *   NVIC_SetPriority(GPIO_P3_IRQn, 5);
+ *   NVIC_SetPriority(GPIO_P4_IRQn, 5);
+ *   NVIC_SetPriority(GPIO_P5_IRQn, 5);
+ *   NVIC_SetPriority(GPIO_P6_IRQn, 5);
+ *   // used by the MAX30001
+ *   NVIC_SetPriority(SPI1_IRQn, 0);
+ * 
+ * 
+ *   /// Setup interrupts and callback functions
+ *   max30001_InterruptB.disable_irq();
+ *   max30001_Interrupt2B.disable_irq();
+ * 
+ *   max30001_InterruptB.mode(PullUp);
+ *   max30001_InterruptB.fall(&MAX30001::Mid_IntB_Handler);
+ * 
+ *   max30001_Interrupt2B.mode(PullUp);
+ *   max30001_Interrupt2B.fall(&MAX30001::Mid_Int2B_Handler);
+ * 
+ *   max30001_InterruptB.enable_irq();
+ *   max30001_Interrupt2B.enable_irq();
+ * 
+ *   max30001.AllowInterrupts(1);
+ * 
+ *   // Configuring the FCLK for the ECG, set to 32.768KHZ
+ *   pwmout.period_us(31);
+ *   pwmout.write(0.5);     // 0-1 is 0-100%, 0.5 = 50% duty cycle.
+ *   max30001.sw_rst();     // Do a software reset of the MAX30001
+ *   
+ *   max30001.INT_assignment(MAX30001::MAX30001_INT_B,    MAX30001::MAX30001_NO_INT,   MAX30001::MAX30001_NO_INT,  //  en_enint_loc,      en_eovf_loc,   en_fstint_loc,
+ *                           MAX30001::MAX30001_INT_2B,   MAX30001::MAX30001_INT_2B,   MAX30001::MAX30001_NO_INT,  //  en_dcloffint_loc,  en_bint_loc,   en_bovf_loc,
+ *                           MAX30001::MAX30001_INT_2B,   MAX30001::MAX30001_INT_2B,   MAX30001::MAX30001_NO_INT,  //  en_bover_loc,      en_bundr_loc,  en_bcgmon_loc,
+ *                           MAX30001::MAX30001_INT_B,    MAX30001::MAX30001_NO_INT,   MAX30001::MAX30001_NO_INT,  //  en_pint_loc,       en_povf_loc,   en_pedge_loc,
+ *                           MAX30001::MAX30001_INT_2B,   MAX30001::MAX30001_INT_B,    MAX30001::MAX30001_NO_INT,  //  en_lonint_loc,     en_rrint_loc,  en_samp_loc,
+ *                           MAX30001::MAX30001_INT_ODNR, MAX30001::MAX30001_INT_ODNR);                            //  intb_Type,         int2b_Type)
+ * 
+ *   max30001.onDataAvailable(&StreamPacketUint32_ecg);  
+ * 
+ *   /// Set and Start the VCAL input
+ *   /// @brief NOTE VCAL must be set first if VCAL is to be used 
+ *     max30001.CAL_InitStart(EN_VCAL , VMODE, VMAG, FCAL, THIGH, FIFTY);
+ *           
+ *   /// ECG Initialization
+ *     max30001.ECG_InitStart(EN_ECG, OPENP, OPENN, POL, CALP_SEL, CALN_SEL, E_FIT, RATE, GAIN, DHPF, DLPF);
+ * 
+ *   /// @details The user can call any of the InitStart functions for Pace, BIOZ and RtoR
+ * 
+ * 
+ *   /// @brief Set Rbias & FMSTR over here
+ *       max30001.Rbias_FMSTR_Init(EN_RBIAS, RBIASV, RBIASP, RBIASN,FMSTR);
+ * 
+ *   max30001.synch();
+ * 
+ *   /// clear the status register for a clean start
+ *   max30001.reg_read(MAX30001::STATUS, &all);  
+ *   
+ *   printf("Please wait for data to start streaming\n");
+ *   fflush(stdout);
+ *     
+ *   while (1) {
+ *     if(data_trigger == 1){
+ *     printf("%ld ", ecgBuffer[ecgIndex]);  // Print the ECG data on a serial port terminal software
+ *     fflush(stdout);
+ *     }
+ *   }
+ * }
+ * @endcode 
+ *
  */
 
+
 #ifndef MAX30001_H_
 #define MAX30001_H_
 
 #include "mbed.h"
 
-#define mbed_COMPLIANT // Uncomment to Use timer for MAX30001 FCLK (for mbed)
-                       // Comment to use the RTC clock
+#define mbed_COMPLIANT ///< Uncomment to Use timer for MAX30001 FCLK (for mbed)
+                       ///< Comment to use the RTC clock
 
-#define ASYNC_SPI_BUFFER_SIZE (32 * 3) // Maximimum buffer size for async byte transfers
+#define ASYNC_SPI_BUFFER_SIZE (32 * 3) ///< Maximimum buffer size for async byte transfers
 
-// Defines for data callbacks
+///< Defines for data callbacks
 #define MAX30001_DATA_ECG        0x30
 #define MAX30001_DATA_PACE       0x31
 #define MAX30001_DATA_RTOR       0x32
@@ -68,7 +225,7 @@
 #define MAX30001_INT_PORT_FCLK   1
 #define MAX30001_INT_PIN_FCLK    7
 
-#define MAX30001_FUNC_SEL_TMR    2 // 0=FW Control, 1= Pulse Train, 2=Timer
+#define MAX30001_FUNC_SEL_TMR    2 ///< 0=FW Control, 1= Pulse Train, 2=Timer
 
 #define MAX30001_INDEX    3
 #define MAX30001_POLARITY 0
@@ -96,12 +253,12 @@
 void MAX30001_AllowInterrupts(int state);
 
 /**
-* Maxim Integrated MAX30001 ECG/BIOZ chip
+* @brief Maxim Integrated MAX30001 ECG/BIOZ chip
 */
 class MAX30001 {
 
 public:
-  typedef enum { // MAX30001 Register addresses
+  typedef enum { ///< MAX30001 Register addresses
     STATUS     = 0x01,
     EN_INT     = 0x02,
     EN_INT2    = 0x03,
@@ -163,7 +320,7 @@
   /**
    * @brief STATUS (0x01) 
    */
-  union max30001_status_reg {
+  typedef union max30001_status_reg {
     uint32_t all;
 
     struct {
@@ -201,14 +358,14 @@
 
     } bit;
 
-  } max30001_status;
+  } max30001_status_t;
 
   
   /**
    * @brief EN_INT (0x02) 
    */
 
-  union max30001_en_int_reg {
+  typedef union max30001_en_int_reg {
     uint32_t all;
 
     struct {
@@ -245,13 +402,13 @@
 
     } bit;
 
-  } max30001_en_int;
+  } max30001_en_int_t;
 
   
   /**
    * @brief EN_INT2 (0x03) 
    */  
-  union max30001_en_int2_reg {
+  typedef union max30001_en_int2_reg {
     uint32_t all;
 
     struct {
@@ -288,12 +445,12 @@
 
     } bit;
 
-  } max30001_en_int2;
+  } max30001_en_int2_t;
 
   /**
    * @brief MNGR_INT (0x04) 
    */  
-  union max30001_mngr_int_reg {
+  typedef union max30001_mngr_int_reg {
     uint32_t all;
 
     struct {
@@ -313,12 +470,12 @@
 
     } bit;
 
-  } max30001_mngr_int;
+  } max30001_mngr_int_t;
 
    /**
    * @brief MNGR_DYN (0x05) 
    */ 
-  union max30001_mngr_dyn_reg {
+  typedef union max30001_mngr_dyn_reg {
     uint32_t all;
 
     struct {
@@ -329,22 +486,13 @@
       uint32_t reserved    : 8;
     } bit;
 
-  } max30001_mngr_dyn;
-
-  // 0x08
-  // uint32_t max30001_sw_rst;
-
-  // 0x09
-  // uint32_t max30001_synch;
-
-  // 0x0A
-  // uint32_t max30001_fifo_rst;
+  } max30001_mngr_dyn_t;
 
   
    /**
    * @brief INFO (0x0F) 
    */
-  union max30001_info_reg {
+  typedef union max30001_info_reg {
     uint32_t all;
     struct {
       uint32_t serial    : 12;
@@ -356,12 +504,12 @@
       uint32_t reserved  : 8;
     } bit;
 
-  } max30001_info;
+  } max30001_info_t;
 
    /**
    * @brief CNFG_GEN (0x10) 
    */
-  union max30001_cnfg_gen_reg {
+  typedef union max30001_cnfg_gen_reg {
     uint32_t all;
     struct {
       uint32_t rbiasn     : 1;
@@ -382,13 +530,13 @@
       uint32_t reserved : 8;
     } bit;
 
-  } max30001_cnfg_gen;
+  } max30001_cnfg_gen_t;
 
   
    /**
    * @brief CNFG_CAL (0x12) 
    */  
-  union max30001_cnfg_cal_reg {
+  typedef union max30001_cnfg_cal_reg {
     uint32_t all;
     struct {
       uint32_t thigh     : 11;
@@ -402,12 +550,12 @@
       uint32_t reserved  : 8;
     } bit;
 
-  } max30001_cnfg_cal;
+  } max30001_cnfg_cal_t;
 
    /**
    * @brief CNFG_EMUX  (0x14) 
    */
-  union max30001_cnfg_emux_reg {
+  typedef union max30001_cnfg_emux_reg {
     uint32_t all;
     struct {
       uint32_t reserved1 : 16;
@@ -420,13 +568,13 @@
       uint32_t reserved : 8;
     } bit;
 
-  } max30001_cnfg_emux;
+  } max30001_cnfg_emux_t;
 
   
    /**
    * @brief CNFG_ECG   (0x15) 
    */  
-  union max30001_cnfg_ecg_reg {
+  typedef union max30001_cnfg_ecg_reg {
     uint32_t all;
     struct {
       uint32_t reserved1 : 12;
@@ -440,12 +588,12 @@
       uint32_t reserved  : 8;
     } bit;
 
-  } max30001_cnfg_ecg;
+  } max30001_cnfg_ecg_t;
 
    /**
    * @brief CNFG_BMUX   (0x17) 
    */  
-  union max30001_cnfg_bmux_reg {
+  typedef union max30001_cnfg_bmux_reg {
     uint32_t all;
     struct {
       uint32_t fbist     : 2;
@@ -461,15 +609,15 @@
       uint32_t openn     : 1;
       uint32_t openp     : 1;
       uint32_t reserved4 : 2;
-      uint32_t reserved : 8;
+      uint32_t reserved  : 8;
     } bit;
 
-  } max30001_cnfg_bmux;
+  } max30001_cnfg_bmux_t;
 
    /**
    * @brief CNFG_BIOZ   (0x18) 
    */ 
-  union max30001_bioz_reg {
+  typedef union max30001_bioz_reg {
     uint32_t all;
     struct {
       uint32_t phoff     : 4;
@@ -483,16 +631,16 @@
       uint32_t ext_rbias : 1;
       uint32_t ahpf      : 3;
       uint32_t rate      : 1;
-      uint32_t reserved : 8;
+      uint32_t reserved  : 8;
     } bit;
 
-  } max30001_cnfg_bioz;
+  } max30001_cnfg_bioz_t;
 
   
    /**
    * @brief CNFG_PACE   (0x1A) 
    */   
-  union max30001_cnfg_pace_reg {
+  typedef union max30001_cnfg_pace_reg {
     uint32_t all;
 
     struct {
@@ -509,12 +657,12 @@
       uint32_t reserved    : 8;
     } bit;
 
-  } max30001_cnfg_pace;
+  } max30001_cnfg_pace_t;
 
    /**
    * @brief CNFG_RTOR1   (0x1D) 
    */   
-  union max30001_cnfg_rtor1_reg {
+  typedef union max30001_cnfg_rtor1_reg {
     uint32_t all;
     struct {
       uint32_t reserved1 : 8;
@@ -524,15 +672,15 @@
       uint32_t en_rtor   : 1;
       uint32_t gain      : 4;
       uint32_t wndw      : 4;
-      uint32_t reserved : 8;
+      uint32_t reserved  : 8;
     } bit;
 
-  } max30001_cnfg_rtor1;
+  } max30001_cnfg_rtor1_t;
 
    /**
    * @brief CNFG_RTOR2 (0x1E) 
    */   
-  union max30001_cnfg_rtor2_reg {
+  typedef union max30001_cnfg_rtor2_reg {
     uint32_t all;
     struct {
       uint32_t reserved1 : 8;
@@ -545,14 +693,14 @@
       uint32_t reserved : 8;
     } bit;
 
-  } max30001_cnfg_rtor2;
+  } max30001_cnfg_rtor2_t;
 
   /*********************************************************************************/
 
   typedef enum {
-    MAX30001_NO_INT = 0, // No interrupt
-    MAX30001_INT_B  = 1,  // INTB selected for interrupt
-    MAX30001_INT_2B = 2  // INT2B selected for interrupt
+    MAX30001_NO_INT = 0, ///< No interrupt
+    MAX30001_INT_B  = 1, ///< INTB selected for interrupt
+    MAX30001_INT_2B = 2  ///< INT2B selected for interrupt
   } max30001_intrpt_Location_t;
 
   typedef enum {
@@ -562,60 +710,62 @@
     MAX30001_INT_ODNR     = 0b11
   } max30001_intrpt_type_t;
 
-  typedef enum {          // Input Polarity selection
-    MAX30001_NON_INV = 0, // Non-Inverted
-    MAX30001_INV     = 1      // Inverted
-  } max30001_emux_pol;
+  typedef enum {          ///< Input Polarity selection
+    MAX30001_NON_INV = 0, ///< Non-Inverted
+    MAX30001_INV     = 1  ///< Inverted
+  } max30001_emux_pol_t;
 
-  typedef enum {              // OPENP and OPENN setting
-    MAX30001_ECG_CON_AFE = 0, // ECGx is connected to AFE channel
-    MAX30001_ECG_ISO_AFE = 1  // ECGx is isolated from AFE channel
-  } max30001_emux_openx;
+  typedef enum {              ///< OPENP and OPENN setting
+    MAX30001_ECG_CON_AFE = 0, ///< ECGx is connected to AFE channel
+    MAX30001_ECG_ISO_AFE = 1  ///< ECGx is isolated from AFE channel
+  } max30001_emux_openx_t;
 
-  typedef enum {                // EMUX_CALP_SEL & EMUX_CALN_SEL
-    MAX30001_NO_CAL_SIG = 0b00, // No calibration signal is applied
-    MAX30001_INPT_VMID  = 0b01,  // Input is connected to VMID
-    MAX30001_INPT_VCALP = 0b10, // Input is connected to VCALP
-    MAX30001_INPT_VCALN = 0b11  // Input is connected to VCALN
-  } max30001_emux_calx_sel;
+  typedef enum {                ///< EMUX_CALP_SEL & EMUX_CALN_SEL
+    MAX30001_NO_CAL_SIG = 0b00, ///< No calibration signal is applied
+    MAX30001_INPT_VMID  = 0b01, ///< Input is connected to VMID
+    MAX30001_INPT_VCALP = 0b10, ///< Input is connected to VCALP
+    MAX30001_INPT_VCALN = 0b11  ///< Input is connected to VCALN
+  } max30001_emux_calx_sel_t;
 
-  typedef enum {                     // EN_ECG, EN_BIOZ, EN_PACE
-    MAX30001_CHANNEL_DISABLED = 0b0, //
+  typedef enum {                     ///< EN_ECG, EN_BIOZ, EN_PACE
+    MAX30001_CHANNEL_DISABLED = 0b0,
     MAX30001_CHANNEL_ENABLED = 0b1
-  } max30001_en_feature;
+  } max30001_en_feature_t;
 
   /*********************************************************************************/
   // Data
-  uint32_t max30001_ECG_FIFO_buffer[32]; // (303 for internal test)
-  uint32_t max30001_BIOZ_FIFO_buffer[8]; // (303 for internal test)
+  uint32_t max30001_ECG_FIFO_buffer[32]; ///< (303 for internal test)
+  uint32_t max30001_BIOZ_FIFO_buffer[8]; ///< (303 for internal test)
 
-  uint32_t max30001_PACE[18]; // Pace Data 0-5
+  uint32_t max30001_PACE[18]; ///< Pace Data 0-5
 
-  uint32_t max30001_RtoR_data; // This holds the RtoR data
+  uint32_t max30001_RtoR_data; ///< This holds the RtoR data
 
-  uint32_t max30001_DCLeadOff; // This holds the LeadOff data, Last 4 bits give
-                               // the status, BIT3=LOFF_PH, BIT2=LOFF_PL,
-                               // BIT1=LOFF_NH, BIT0=LOFF_NL
-                               // 8th and 9th bits tell Lead off is due to ECG or BIOZ.  
-                               // 0b01 = ECG Lead Off and 0b10 = BIOZ Lead off
+  uint32_t max30001_DCLeadOff; ///< This holds the LeadOff data, Last 4 bits give
+                               ///< the status, BIT3=LOFF_PH, BIT2=LOFF_PL,
+                               ///< BIT1=LOFF_NH, BIT0=LOFF_NL
+                               ///< 8th and 9th bits tell Lead off is due to ECG or BIOZ.  
+                               ///< 0b01 = ECG Lead Off and 0b10 = BIOZ Lead off
 
-  uint32_t max30001_ACLeadOff; // This gives the state of the BIOZ AC Lead Off
-                               // state.  BIT 1 = BOVER,   BIT 0 = BUNDR
+  uint32_t max30001_ACLeadOff; ///< This gives the state of the BIOZ AC Lead Off
+                               ///< state.  BIT 1 = BOVER,   BIT 0 = BUNDR
 
-  uint32_t max30001_bcgmon; // This holds the BCGMON data, BIT 1 = BCGMP, BIT0 =
-                            // BCGMN
+  uint32_t max30001_bcgmon; ///< This holds the BCGMON data, BIT 1 = BCGMP, BIT0 =
+                            ///< BCGMN
 
-  uint32_t max30001_LeadOn; // This holds the LeadOn data, BIT1 = BIOZ Lead ON,
-                            // BIT0 = ECG Lead ON, BIT8= Lead On Status Bit
+  uint32_t max30001_LeadOn; ///< This holds the LeadOn data, BIT1 = BIOZ Lead ON,
+                            ///< BIT0 = ECG Lead ON, BIT8= Lead On Status Bit
 
-  uint32_t max30001_timeout; // If the PLL does not respond, timeout and get out.
+  uint32_t max30001_timeout; ///< If the PLL does not respond, timeout and get out.
 
-  typedef struct { // Creating a structure for BLE data
+  typedef struct { ///< Creating a structure for BLE data
     int16_t R2R;
     int16_t fmstr;
-  } max30001_t;
+  } max30001_bledata_t;
 
-  max30001_t hspValMax30001; // R2R, FMSTR
+  max30001_bledata_t hspValMax30001; // R2R, FMSTR
+
+  max30001_status_t global_status;
 
   /**
   * @brief Constructor that accepts pin names for the SPI interface
@@ -636,7 +786,13 @@
    * MAX30001 destructor
    */
   ~MAX30001(void);
-
+  
+  /**
+   * @brief This function is MAXIM Proprietary.  It channels the RTC crystal
+   * @brief clock to P1.7.  Thus providing 32768Hz on FCLK pin of the MAX30001-3
+   */ 
+  void FCLK_MaximOnly(void);   
+  
   /**
    * @brief This function sets up the Resistive Bias mode and also selects the master clock frequency.
    * @brief Uses Register: CNFG_GEN-0x10
@@ -648,7 +804,7 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
   */
-  int max30001_Rbias_FMSTR_Init(uint8_t En_rbias, uint8_t Rbiasv,
+  int Rbias_FMSTR_Init(uint8_t En_rbias, uint8_t Rbiasv,
                                 uint8_t Rbiasp, uint8_t Rbiasn, uint8_t Fmstr);
 
   /**
@@ -665,14 +821,14 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_CAL_InitStart(uint8_t En_Vcal, uint8_t Vmode, uint8_t Vmag,
+  int CAL_InitStart(uint8_t En_Vcal, uint8_t Vmode, uint8_t Vmag,
                              uint8_t Fcal, uint16_t Thigh, uint8_t Fifty);
 
   /**
    * @brief This function disables the VCAL signal
    * @returns 0-if no error.  A non-zero value indicates an error.
    */
-  int max30001_CAL_Stop(void);
+  int CAL_Stop(void);
 
   /**
    * @brief This function handles the assignment of the two interrupt pins (INTB & INT2B) with various
@@ -685,7 +841,7 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-     int max30001_INT_assignment(max30001_intrpt_Location_t en_enint_loc,     max30001_intrpt_Location_t en_eovf_loc,  max30001_intrpt_Location_t en_fstint_loc,
+     int INT_assignment(max30001_intrpt_Location_t en_enint_loc,     max30001_intrpt_Location_t en_eovf_loc,  max30001_intrpt_Location_t en_fstint_loc,
 		                 max30001_intrpt_Location_t en_dcloffint_loc, max30001_intrpt_Location_t en_bint_loc,  max30001_intrpt_Location_t en_bovf_loc,
 		                 max30001_intrpt_Location_t en_bover_loc,     max30001_intrpt_Location_t en_bundr_loc, max30001_intrpt_Location_t en_bcgmon_loc,
 		                 max30001_intrpt_Location_t en_pint_loc,      max30001_intrpt_Location_t en_povf_loc,  max30001_intrpt_Location_t en_pedge_loc,
@@ -712,10 +868,10 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_ECG_InitStart(uint8_t En_ecg, uint8_t Openp, uint8_t Openn,
-                             uint8_t Pol, uint8_t Calp_sel, uint8_t Caln_sel,
-                             uint8_t E_fit, uint8_t Rate, uint8_t Gain,
-                             uint8_t Dhpf, uint8_t Dlpf);
+  int ECG_InitStart(uint8_t En_ecg, uint8_t Openp, uint8_t Openn,
+                    uint8_t Pol, uint8_t Calp_sel, uint8_t Caln_sel,
+                    uint8_t E_fit, uint8_t Rate, uint8_t Gain,
+                    uint8_t Dhpf, uint8_t Dlpf);
 
   /**
    * @brief For MAX30001/3 ONLY
@@ -727,7 +883,7 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_ECGFast_Init(uint8_t Clr_Fast, uint8_t Fast, uint8_t Fast_Th);
+  int ECGFast_Init(uint8_t Clr_Fast, uint8_t Fast, uint8_t Fast_Th);
 
   /**
   * @brief For MAX30001/3 ONLY
@@ -736,7 +892,7 @@
   * @returns 0-if no error.  A non-zero value indicates an error.
   *
   */
-  int max30001_Stop_ECG(void);
+  int Stop_ECG(void);
 
   /**
    *  @brief For MAX30001 ONLY
@@ -757,7 +913,7 @@
    *  @returns 0-if no error.  A non-zero value indicates an error <CNFG_PACE Register>
    *
    */
-  int max30001_PACE_InitStart(uint8_t En_pace, uint8_t Clr_pedge, uint8_t Pol,
+  int PACE_InitStart(uint8_t En_pace, uint8_t Clr_pedge, uint8_t Pol,
                               uint8_t Gn_diff_off, uint8_t Gain,
                               uint8_t Aout_lbw, uint8_t Aout, uint8_t Dacp,
                               uint8_t Dacn);
@@ -768,7 +924,7 @@
    *@returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_Stop_PACE(void);
+  int Stop_PACE(void);
 
   /**
    * @brief For MAX30001/2 ONLY
@@ -794,7 +950,7 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_BIOZ_InitStart(uint8_t En_bioz, uint8_t Openp, uint8_t Openn,
+  int BIOZ_InitStart(uint8_t En_bioz, uint8_t Openp, uint8_t Openn,
                               uint8_t Calp_sel, uint8_t Caln_sel,
                               uint8_t CG_mode,
                               /* uint8_t En_bioz,*/ uint8_t B_fit, uint8_t Rate,
@@ -809,7 +965,7 @@
        * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_Stop_BIOZ(void);
+  int Stop_BIOZ(void);
 
   /**
    * @brief For MAX30001/2 ONLY
@@ -821,7 +977,7 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_BIOZ_InitBist(uint8_t En_bist, uint8_t Rnom, uint8_t Rmod,
+  int BIOZ_InitBist(uint8_t En_bist, uint8_t Rnom, uint8_t Rmod,
                              uint8_t Fbist);
 
   /**
@@ -839,7 +995,7 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_RtoR_InitStart(uint8_t En_rtor, uint8_t Wndw, uint8_t Gain,
+  int RtoR_InitStart(uint8_t En_rtor, uint8_t Wndw, uint8_t Gain,
                               uint8_t Pavg, uint8_t Ptsf, uint8_t Hoff,
                               uint8_t Ravg, uint8_t Rhsf, uint8_t Clr_rrint);
 
@@ -849,21 +1005,21 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_Stop_RtoR(void);
+  int Stop_RtoR(void);
 
   /**
    * @brief This is a function that waits for the PLL to lock; once a lock is achieved it exits out. (For convenience only)
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_PLL_lock(void);
+  int PLL_lock(void);
 
   /**
    * @brief This function causes the MAX30001 to reset.  Uses Register SW_RST-0x08
    * @return 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_sw_rst(void);
+  int sw_rst(void);
 
   /**
    * @brief This function provides a SYNCH operation.  Uses Register SYCNH-0x09. Please refer to the data sheet for
@@ -871,14 +1027,14 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_synch(void);
+  int synch(void);
 
   /**
    * @brief This function performs a FIFO Reset.  Uses Register FIFO_RST-0x0A. Please refer to the data sheet
    * @brief for the details on how to use this.
    * @returns 0-if no error.  A non-zero value indicates an error.
    */
-  int max300001_fifo_rst(void);
+  int fifo_rst(void);
 
   /**
    *
@@ -887,7 +1043,7 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_int_handler(void);
+  int int_handler(void);
 
   /**
    * @brief This is function called from the max30001_int_handler() function and processes all the ECG, BIOZ, PACE
@@ -906,7 +1062,7 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_FIFO_LeadONOff_Read(void);
+  int FIFO_LeadONOff_Read(void);
 
   /**
    * @brief This function allows writing to a register.
@@ -915,7 +1071,7 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_reg_write(MAX30001_REG_map_t addr, uint32_t data);
+  int reg_write(MAX30001_REG_map_t addr, uint32_t data);
 
   /**
    * @brief This function allows reading from a register
@@ -924,7 +1080,7 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_reg_read(MAX30001_REG_map_t addr, uint32_t *return_data);
+  int reg_read(MAX30001_REG_map_t addr, uint32_t *return_data);
 
   /**
    * @brief This function enables the DC Lead Off detection. Either ECG or BIOZ can be detected, one at a time.
@@ -936,7 +1092,7 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_Enable_DcLeadOFF_Init(int8_t En_dcloff, int8_t Ipol, int8_t Imag,
+  int Enable_DcLeadOFF_Init(int8_t En_dcloff, int8_t Ipol, int8_t Imag,
                                      int8_t Vth);
 
   /**
@@ -944,7 +1100,7 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_Disable_DcLeadOFF(void);
+  int Disable_DcLeadOFF(void);
 
   /**
    * @brief This function sets up the BIOZ for AC Lead Off test.
@@ -955,7 +1111,7 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_BIOZ_Enable_ACLeadOFF_Init(uint8_t En_bloff, uint8_t Bloff_hi_it,
+  int BIOZ_Enable_ACLeadOFF_Init(uint8_t En_bloff, uint8_t Bloff_hi_it,
                                           uint8_t Bloff_lo_it);
 
   /**
@@ -964,7 +1120,7 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_BIOZ_Disable_ACleadOFF(void);
+  int BIOZ_Disable_ACleadOFF(void);
 
   /**
    * @brief This function enables the Current Gnerator Monitor
@@ -972,7 +1128,7 @@
    * @returns 0-if no error.  A non-zero value indicates an error.
    *
    */
-  int max30001_BIOZ_Enable_BCGMON(void);
+  int BIOZ_Enable_BCGMON(void);
 
   /**
    *
@@ -983,7 +1139,7 @@
    * @returns 0-if everything is good.  A non-zero value indicates an error.
    *
    */
-  int max30001_Enable_LeadON(int8_t Channel);
+  int Enable_LeadON(int8_t Channel);
 
   /**
    * @brief This function turns off the Lead ON feature, whichever one is active.  Also, retrieves the en_bioz,
@@ -991,7 +1147,7 @@
    * @param 0-if everything is good.  A non-zero value indicates an error.
    *
    */
-  int max30001_Disable_LeadON(void);
+  int Disable_LeadON(void);
 
   /**
    *
@@ -1000,7 +1156,7 @@
    * @param CurrentTime - This gets fed the time by RTC_GetValue function
    *
    */
-  void max30001_ServiceLeadON(uint32_t currentTime);
+  void ServiceLeadON(uint32_t currentTime);
 
   /**
    *
@@ -1009,7 +1165,7 @@
    * @param CurrentTime - This gets fed the time by RTC_GetValue function
    *
    */
-  void max30001_ServiceLeadoff(uint32_t currentTime);
+  void ServiceLeadoff(uint32_t currentTime);
 
   /**
    *
@@ -1017,7 +1173,7 @@
    * @param hspValMax30001 - Pointer to a structure where to store the values
    *
    */
-  void max30001_ReadHeartrateData(max30001_t *_hspValMax30001);
+  void ReadHeartrateData(max30001_bledata_t *_hspValMax30001);
 
   /**
    * @brief type definition for data interrupt
@@ -1029,13 +1185,62 @@
    */
   void onDataAvailable(PtrFunction _onDataAvailable);
 
+
+
+  /**
+   * @brief Preventive measure used to dismiss interrupts that fire too early during
+   * @brief initialization on INTB line
+   *
+   */
+  static void Mid_IntB_Handler(void);
+
+  /**
+   * @brief Preventive measure used to dismiss interrupts that fire too early during
+   * @brief initialization on INT2B line
+   *
+   */
+  static void Mid_Int2B_Handler(void);
+
+  /**
+   * @brief Allows Interrupts to be accepted as valid.
+   * @param state: 1-Allow interrupts, Any-Don't allow interrupts.
+   *
+   */
+  void AllowInterrupts(int state);
+
+
+  /// @brief function pointer to the async callback
+  static event_callback_t functionpointer;
+  
+  /// @brief flag used to indicate an async xfer has taken place
+  static volatile int xferFlag;
+
+  /**
+   * @brief Callback handler for SPI async events
+   * @param events description of event that occurred
+   */
+  static void spiHandler(int events);
+
+
   static MAX30001 *instance;
 
 private:
+
+  /**
+   * @brief Used to notify an external function that interrupt data is available
+   * @param id type of data available
+   * @param buffer 32-bit buffer that points to the data
+   * @param length length of 32-bit elements available
+   */
   void dataAvailable(uint32_t id, uint32_t *buffer, uint32_t length);
-  /// interrupt handler for async spi events
-  static void spiHandler(int events);
-  /// wrapper method to transmit and recieve SPI data
+  
+  /**
+   * @brief Transmit and recieve QUAD SPI data
+   * @param tx_buf pointer to transmit byte buffer
+   * @param tx_size number of bytes to transmit
+   * @param rx_buf pointer to the recieve buffer
+   * @param rx_size number of bytes to recieve
+   */
   int SPI_Transmit(const uint8_t *tx_buf, uint32_t tx_size, uint8_t *rx_buf,
                    uint32_t rx_size);
 
@@ -1046,31 +1251,11 @@
   /// buffer to use for async transfers
   uint8_t buffer[ASYNC_SPI_BUFFER_SIZE];
   /// function pointer to the async callback
-  event_callback_t functionpointer;
+ // event_callback_t functionpointer;
   /// callback function when interrupt data is available
   PtrFunction onDataAvailableCallback;
 
 }; // End of MAX30001 Class
 
-/**
- * @brief Preventive measure used to dismiss interrupts that fire too early during
- * @brief initialization on INTB line
- *
- */
-void MAX30001Mid_IntB_Handler(void);
-
-/**
- * @brief Preventive measure used to dismiss interrupts that fire too early during
- * @brief initialization on INT2B line
- *
- */
-void MAX30001Mid_Int2B_Handler(void);
-
-/**
- * @brief Allows Interrupts to be accepted as valid.
- * @param state: 1-Allow interrupts, Any-Don't allow interrupts.
- *
- */
-void MAX30001_AllowInterrupts(int state);
 
 #endif /* MAX30001_H_ */