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/MAX30101/MAX30101/MAX30101.h	Tue Oct 25 15:22:11 2016 +0000
+++ b/HSP/Devices/MAX30101/MAX30101/MAX30101.h	Fri Apr 21 12:12:30 2017 -0500
@@ -1,5 +1,5 @@
 /*******************************************************************************
-/ * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
+/ * 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"),
@@ -29,11 +29,107 @@
  * property whatsoever. Maxim Integrated Products, Inc. retains all
  * ownership rights.
  *******************************************************************************/
-/*
- * max30101.h
+/** 
+ * Maxim Integrated MAX30101 Oximeter chip
+ *  
+ * IMPORTANT: The code below will also need MAX14720.cpp and MAX14720.h
+ * 
+ * @code
+ * #include "mbed.h"
+ * #include "MAX14720.h"
+ * #include "MAX30101.h"
+ * 
+ * 
+ * /// define the HVOUT Boost Voltage default for the MAX14720 PMIC
+ * #define HVOUT_VOLTAGE 4500 // set to 4500 mV
+ * 
+ * /// define all I2C addresses
+ * #define MAX14720_I2C_SLAVE_ADDR (0x54)
+ * #define MAX30101_I2C_SLAVE_ADDR (0xAE)
+ * 
+ * /// Settings for the HR initialization
+ * #define FIFO_WATERLEVEL_MARK 15
+ * #define SAMPLE_AVG           2
+ * #define SAMPLE_RATE          1
+ * #define PULSE_WIDTH          2
+ * #define RED_LED_CURRENT      0x1F
+ *  
+ *  /// Buffer size for streaming data out.
+ * #define BUFFER_LENGTH 50 
+ * 
+ * 
+ * /// I2C Master 2
+ * I2C i2c2(I2C2_SDA, I2C2_SCL); // used by MAX14720, MAX30101, LIS2DH
+ * /// SPI Master 0 with SPI0_SS for use with MAX30001
+ *  SPI spi(SPI0_MOSI, SPI0_MISO, SPI0_SCK, SPI0_SS); // used by MAX30001
+ * 
+ * /// PMIC
+ * MAX14720 max14720(&i2c2, MAX14720_I2C_SLAVE_ADDR);
+ * /// Optical Oximeter
+ * MAX30101 max30101(&i2c2, MAX30101_I2C_SLAVE_ADDR);
+ * InterruptIn max30101_Interrupt(P4_0);
+ * 
+ * //@brief Creating a buffer to hold the data
+ * uint32_t oxiBuffer[BUFFER_LENGTH];
+ * int oxiIndex = 0;
+ * char data_trigger = 0;
+ *  
  *
- *  Created on: Aug 26, 2015
- *      Author: faisal.tariq
+ * //@brief Creates a packet that will be streamed via USB Serial
+ * //@brief 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_ex(uint32_t id, uint32_t *buffer, uint32_t number) {
+ *   int i;
+ *   if (id == MAX30101_OXIMETER_DATA + 1) {
+ * 
+ *     for (i = 0; i < number; i++) {
+ *       oxiBuffer[oxiIndex] = buffer[i];
+ *       oxiIndex++;
+ *           
+ *       if (oxiIndex > BUFFER_LENGTH)
+ *         {
+ *         data_trigger = 1;
+ *         oxiIndex = 0;
+ *         }
+ *     }
+ *   }
+ * }
+ * 
+ * int main() {
+ *   // hold results for returning functions
+ *   int result;
+ * 
+ *   // initialize HVOUT on the MAX14720 PMIC
+ *   result = max14720.init();
+ *   if (result == MAX14720_ERROR){
+ *     printf("Error initializing MAX14720");
+ *     }
+ *   max14720.boostEn = MAX14720::BOOST_ENABLED;
+ *   max14720.boostSetVoltage(HVOUT_VOLTAGE);
+ * 
+ *   // MAX30101 initialize interrupt
+ *   max30101.onDataAvailable(&StreamPacketUint32_ex);
+ *   max30101_Interrupt.fall(&MAX30101::MAX30101MidIntHandler);
+ *   
+ *   // This is the HR mode only (IR LED only)  
+ *   max30101.HRmode_init(FIFO_WATERLEVEL_MARK, SAMPLE_AVG, SAMPLE_RATE,PULSE_WIDTH, RED_LED_CURRENT); 
+ * 
+ *   printf("Please wait for data to start streaming\n");
+ *   fflush(stdout);
+ *   
+ *   while (1) {
+ *     if(data_trigger == 1)
+ *      {
+ *       printf("%ld ", oxiBuffer[oxiIndex]);  // Print the ECG data on a serial port terminal software
+ *       fflush(stdout);
+ *      }
+ *   } 
+ * }
+ * @endcode
+ *
  */
 
 #ifndef _MAX30101_H_
@@ -48,7 +144,7 @@
 
 #define CHUNK_SIZE 252
 
-// MAX30101 Register addresses
+///< MAX30101 Register addresses
 
 #define MAX30101_INT_PORT 4
 #define MAX30101_INT_PIN 0
@@ -59,13 +155,13 @@
 */
 class MAX30101 {
 public:
-  float max30101_final_temp;                         // Global declaration
-  uint32_t max30101_buffer[MAX30101_PROC_DATA_SIZE]; // final Processed data
-  char max30101_rawData[MAX30101_RAW_DATA_SIZE];     //  raw data from the chip
+  float max30101_final_temp;                         ///< Global declaration
+  uint32_t max30101_buffer[MAX30101_PROC_DATA_SIZE]; ///< final Processed data
+  char max30101_rawData[MAX30101_RAW_DATA_SIZE];     ///<  raw data from the chip
 
-  typedef enum { // MAX30101 Register addresses
+  typedef enum { ///< MAX30101 Register addresses
 
-    /*Status */
+    ///< Status
     REG_INT_STAT_1 = 0x00,
     REG_INT_STAT_2 = 0x01,
     REG_INT_EN_1   = 0x02,
@@ -75,7 +171,7 @@
     REG_FIFO_OVF_CNT = 0x05,
     REG_FIFO_R_PTR   = 0x06,
     REG_FIFO_DATA    = 0x07,
-    /* Configuration */
+    ///< Configuration
     REG_FIFO_CFG  = 0x08,
     REG_MODE_CFG  = 0x09,
     REG_SPO2_CFG  = 0x0A,
@@ -85,11 +181,11 @@
     REG_PILOT_PA  = 0x10,
     REG_SLT2_SLT1 = 0x11,
     REG_SLT4_SLT3 = 0x12,
-    /* Die Temp    */
+    ///< Die Temp
     REG_TINT    = 0x1F,
     REG_TFRAC   = 0x20,
     REG_TEMP_EN = 0x21,
-    /* Proximity Func */
+    ///< Proximity Func
     REG_PROX_INT_THR = 0x30,
     /* Part ID        */
     REG_REV_ID = 0xFE,
@@ -100,7 +196,7 @@
   /* STATUS */
   /**********/
   /// @brief STATUS1 (0x00)
-  union max30101_Interrupt_Status_1_reg {
+  typedef union max30101_Interrupt_Status_1_reg {
     char all;
     struct {
       char pwr_rdy  : 1;
@@ -110,185 +206,167 @@
       char ppg_rdy  : 1;
       char a_full   : 1;
     } bit;
-  } max30101_Interrupt_Status_1;
+  } max30101_Interrupt_Status_1_t;
 
   /// @brief STATUS2 (0x01)
-  union max30101_Interrupt_Status_2_reg {
+  typedef union max30101_Interrupt_Status_2_reg {
     char all;
     struct {
       char reserved1    : 1;
       char die_temp_rdy : 1;
       char reserved2    : 6;
     } bit;
-  } max30101_Interrupt_Status_2;
+  } max30101_Interrupt_Status_2_t;
 
   /// @brief INTERRUPT_ENABLE1 (0x02)
-  volatile union max30101_Interrupt_Enable_1_reg {
-    uint8_t all;
+  typedef union max30101_Interrupt_Enable_1_reg {
+    char all;
     struct {
-      uint8_t reserved1   : 4;
-      uint8_t prox_int_en : 1;
-      uint8_t alc_ovf_en  : 1;
-      uint8_t ppg_rdy_en  : 1;
-      uint8_t a_full_en   : 1;
+      char reserved1   : 4;
+      char prox_int_en : 1;
+      char alc_ovf_en  : 1;
+      char ppg_rdy_en  : 1;
+      char a_full_en   : 1;
     } bit;
-  } max30101_Interrupt_Enable_1;
+  } max30101_Interrupt_Enable_1_t;
 
   /// @brief INTERRUPT_ENABLE2 (0x03)
-  volatile union max30101_Interrupt_Enable_2_reg {
-    uint8_t all;
+  typedef union max30101_Interrupt_Enable_2_reg {
+    char all;
     struct {
-      uint8_t reserved1       : 1;
-      uint8_t die_temp_rdy_en : 1;
-      uint8_t reserved2       : 6;
+      char reserved1       : 1;
+      char die_temp_rdy_en : 1;
+      char reserved2       : 6;
     } bit;
-  } max30101_Interrupt_Enable_2;
+  } max30101_Interrupt_Enable_2_t;
 
   /*********/
   /* FIFO  */
   /*********/
   // 0x04
   /// @brief FIFO_WR_PTR (0x04)
-  volatile union max30101_fifo_wr_ptr_reg {
-    uint8_t all;
+  typedef union max30101_fifo_wr_ptr_reg {
+    char all;
     struct {
-      uint8_t fifo_wr_ptr : 5;
-      uint8_t reserved1   : 3;
+      char fifo_wr_ptr : 5;
+      char reserved1   : 3;
     } bit;
-  } max30101_fifo_wr_ptr;
+  } max30101_fifo_wr_ptr_t;
 
   /// @brief OVF_COUNTER (0x05)
-  volatile union max30101_ovf_counter_reg {
-    uint8_t all;
+  typedef union max30101_ovf_counter_reg {
+    char all;
     struct {
-      uint8_t fifo_ovf_counter : 5;
-      uint8_t reserved1        : 3;
+      char fifo_ovf_counter : 5;
+      char reserved1        : 3;
     } bit;
-  } max30101_ovf_counter_reg;
+  } max30101_ovf_counter_reg_t;
 
   /// @brief FIFO_READ_PTR (0x06)
-  volatile union max30101_fifo_rd_ptr_reg {
-    uint8_t all;
+  typedef union max30101_fifo_rd_ptr_reg {
+    char all;
     struct {
-      uint8_t fifo_rd_ptr : 5;
-      uint8_t reserved1   : 3;
+      char fifo_rd_ptr : 5;
+      char reserved1   : 3;
     } bit;
-  } max30101_fifo_rd_ptr;
-
-  // 0x07
-  uint8_t max30101_fifo_data;
+  } max30101_fifo_rd_ptr_t;
 
   /********************/
   /* Configuration    */
   /********************/
   // 0x08
   /// @brief FIFO_CONFIGURATION (0x08)
-  volatile union max30101_fifo_configuration_reg {
-    uint8_t all;
+  typedef union max30101_fifo_configuration_reg {
+    char all;
     struct {
-      uint8_t fifo_a_full       : 4;
-      uint8_t fifo_roll_over_en : 1;
-      uint8_t smp_ave           : 3;
+      char fifo_a_full       : 4;
+      char fifo_roll_over_en : 1;
+      char smp_ave           : 3;
     } bit;
-  } max30101_fifo_configuration;
+  } max30101_fifo_configuration_t;
 
   /// @brief MODE_CONFIGURATION (0x09)
-  volatile union max30101_mode_configuration_reg {
-    uint8_t all;
+  typedef union max30101_mode_configuration_reg {
+    char all;
     struct {
-      uint8_t mode      : 3;
-      uint8_t reserved1 : 3;
-      uint8_t reset     : 1;
-      uint8_t shdn      : 1;
+      char mode      : 3;
+      char reserved1 : 3;
+      char reset     : 1;
+      char shdn      : 1;
     } bit;
-  } max30101_mode_configuration;
+  } max30101_mode_configuration_t;
 
   /// @brief SPO2_CONGIGURATION (0x0A)
-  volatile union max30101_spo2_configuration_reg {
-    uint8_t all;
+  typedef union max30101_spo2_configuration_reg {
+    char all;
     struct {
-      uint8_t led_pw       : 2;
-      uint8_t spo2_sr      : 3;
-      uint8_t spo2_adc_rge : 2;
-      uint8_t reserved1    : 1;
+      char led_pw       : 2;
+      char spo2_sr      : 3;
+      char spo2_adc_rge : 2;
+      char reserved1    : 1;
     } bit;
-  } max30101_spo2_configuration;
-
-  /// @brief LED1_PA (0x0C)
-  uint8_t max30101_led1_pa;
-
-  /// @brief LED2_PA (0x0D)
-  uint8_t max30101_led2_pa;
-
-  /// @brief LED3_PA (0x0E)
-  uint8_t max30101_led3_pa;
+  } max30101_spo2_configuration_t;
 
-  /// @brief PILOT_PA (0x10)
-  uint8_t max30101_pilot_pa;
-
-  volatile union max30101_multiLED_mode_ctrl_1_reg {
-    uint8_t all;
+  typedef union max30101_multiLED_mode_ctrl_1_reg {
+    char all;
     struct {
-      uint8_t slot1     : 3;
-      uint8_t reserved  : 1;
-      uint8_t slot2     : 3;
-      uint8_t reserved1 : 1;
+      char slot1     : 3;
+      char reserved  : 1;
+      char slot2     : 3;
+      char reserved1 : 1;
     } bit;
-  } max30101_multiLED_mode_ctrl_1;
+  } max30101_multiLED_mode_ctrl_1_t;
 
-  volatile union max30101_multiLED_mode_ctrl_2_reg {
-    uint8_t all;
+  typedef union max30101_multiLED_mode_ctrl_2_reg {
+    char all;
     struct {
-      uint8_t slot3     : 3;
-      uint8_t reserved  : 1;
-      uint8_t slot4     : 3;
-      uint8_t reserved1 : 1;
+      char slot3     : 3;
+      char reserved  : 1;
+      char slot4     : 3;
+      char reserved1 : 1;
     } bit;
-  } max30101_multiLED_mode_ctrl_2;
+  } max30101_multiLED_mode_ctrl_2_t;
 
   /********************/
   /* Die Temperature  */
   /********************/
 
-  uint8_t max30101_tinit;
+  char max30101_tinit;
 
-  uint8_t max30101_tfrac;
+  char max30101_tfrac;
 
-  volatile union max30101_die_temp_config {
-    uint8_t all;
+  typedef union max30101_die_temp_config {
+    char all;
     struct {
-      uint8_t temp_en  : 1;
-      uint8_t reserved : 7;
+      char temp_en  : 1;
+      char reserved : 7;
     } bit;
-  } max30101_die_temp_config;
-  /*******************************/
+  } max30101_die_temp_config_t;
+
   /***** Function Prototypes *****/
-  /*******************************/
 
-  uint8_t max30101_prox_int_thresh;
+  char max30101_prox_int_thresh;
 
   /**
-  * MAX30101 constructor.
-  *
+  * @brief MAX30101 constructor.
   * @param sda mbed pin to use for SDA line of I2C interface.
   * @param scl mbed pin to use for SCL line of I2C interface.
   */
   MAX30101(PinName sda, PinName scl, int slaveAddress);
 
   /**
-  *  MAX30101 constructor.
-  *
+  * @brief MAX30101 constructor.
   * @param i2c I2C object to use.
   */
   MAX30101(I2C *i2c, int slaveAddress);
 
   /**
-  * MAX30101 destructor.
+  * @brief MAX30101 destructor.
   */
   ~MAX30101(void);
 
   /**
-       * @brief Allows reading from MAX30101 register
+   * @brief Allows reading from MAX30101 register
    * @param reg: is the register address, to read from (look at max30101.h and the
    *             data sheet for details)
    * @param value: is the pointer to the value read from the register
@@ -299,8 +377,7 @@
   /**
    * @brief Allows writing to MAX30101 register
    * @param reg: is the register address, to read from (look at max30101.h and
-   * the
-   *        data sheet for details)
+   * the data sheet for details)
    * @param value: is the value to write to the register
    * @returns  0-if if no error.  A non-zero value indicates an error.
    */
@@ -324,7 +401,7 @@
                     uint8_t red_led_current, uint8_t ir_led_current);
 
   /**
-   * @brief This function will stop the SpO2 mode and turn off all operating LEDâs.
+   * @brief This function will stop the SpO2 mode and turn off all operating LED�s.
    * @return  0-if if no error.  A non-zero value indicates an error.
    */
   int SpO2mode_stop(void);
@@ -398,6 +475,12 @@
    *@returns  0-if everything is good.  A non-zero value indicates an error.
    */
   int int_handler(void);
+  
+   /**
+  * @brief encapsulates the int_handler above
+  */
+  static void MidIntHandler(void);
+  
   /**
   * @brief type definition for data interrupt
   */
@@ -421,34 +504,65 @@
   static MAX30101 *instance;
 
 private:
-  /// called when interrupt data is available
+  /**
+   * @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);
-  /// callback function at the end of the interrupt
+
+
+  /**
+   * @brief Executed on interrupt (callback function at the end of the interrupt)
+   * @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 interruptPostCallback(void);
+
   /// callback function when interrupt data is available
   DataCallbackFunction onDataAvailableCallback;
+
   /// callback function when interrupt data is available
   InterruptFunction onInterruptCallback;
-  /// Read I2c wrapper method
+
+  /**
+   * @brief Read from an I2C device (Read I2c wrapper method)
+   * @param slaveAddress slave address to use with transaction
+   * @param writeData pointer of data to write
+   * @param writeCount number of data to write
+   * @param readData pointer to buffer to read to
+   * @param readCount number of bytes to read
+   */
+
   int I2CM_Read(int slaveAddress, char *writeData, char writeCount, char *readData, char readCount);
-  /// Write I2c wrapper method
+  
+  /**
+   * @brief Write to an I2C device (I2C wrapper method)
+   * @param slaveAddress slave address to use with transaction
+   * @param writeData1 pointer of data to write
+   * @param writeCount1 number of data to write
+   * @param writeData2 pointer to buffer to read to
+   * @param writeCount2 number of bytes to read
+   */
   int I2CM_Write(int slaveAddress, char *writeData1, char writeCount1, char *writeData2, char writeCount2);
-  /// pointer to I2C object
+
+  /// @brief pointer to I2C object
   I2C *i2c;
-  /// flag to track if this object is the owner (created) the I2C object
+
+  /// @brief flag to track if this object is the owner (created) the I2C object
   bool i2c_owner;
-  /// Device slave address
+
+  /// @brief Device slave address
   int slaveAddress;
 };
 
-/**
-*  @brief Resets the I2C block, when needed
-*/
+  /**
+   *  @brief Resets the I2C block, when needed
+   */
 extern void I2CM_Init_Reset(uint8_t index, int speed);
 
- /**
-  * @brief Used for debugging, if needed
-  */
-void MAX30101MidIntHandler(void);
+
 
 #endif /* _MAX30101_H_ */