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.cpp	Tue Oct 25 15:22:11 2016 +0000
+++ b/HSP/Devices/MAX30101/MAX30101/MAX30101.cpp	Fri Apr 21 12:12:30 2017 -0500
@@ -1,4 +1,3 @@
-
 /*******************************************************************************
  * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
  *
@@ -77,56 +76,87 @@
   int loop = 1;
   static uint8_t cntr_int = 0;
 
+  max30101_Interrupt_Status_1_t   Interrupt_Status_1;
+  max30101_Interrupt_Status_2_t   Interrupt_Status_2;
+  max30101_mode_configuration_t   mode_configuration;
+  max30101_multiLED_mode_ctrl_1_t multiLED_mode_ctrl_1;
+  max30101_multiLED_mode_ctrl_2_t multiLED_mode_ctrl_2;
+  max30101_spo2_configuration_t   spo2_configuration;
+  max30101_fifo_configuration_t   fifo_configuration;
 
   cntr_int++;
 
   while (loop) {
-    if (i2c_reg_read(REG_INT_STAT_1, &max30101_Interrupt_Status_1.all) != 0) // Read Interrupt flag bits
-    {
+    if (i2c_reg_read(REG_INT_STAT_1, &Interrupt_Status_1.all) != 0) { ///< Read Interrupt flag bits
+      return -1;
+    }
+
+    if (i2c_reg_read(REG_INT_STAT_2, &Interrupt_Status_2.all) != 0) { ///< Read Interrupt flag bits
+      return -1;
+    }
+
+    /* Read all the relevant register bits */
+    if (i2c_reg_read(REG_MODE_CFG, &mode_configuration.all) != 0) {
       return -1;
     }
 
-    if (i2c_reg_read(REG_INT_STAT_2, &max30101_Interrupt_Status_2.all) != 0) // Read Interrupt flag bits
-    {
+
+    if (i2c_reg_read(REG_SLT2_SLT1, &multiLED_mode_ctrl_1.all) != 0) {
       return -1;
     }
+    
 
-    if (max30101_Interrupt_Status_1.bit.a_full) {
-      /* Read the sample(s) */
+    if (i2c_reg_read(REG_SLT4_SLT3, &multiLED_mode_ctrl_2.all) != 0) {
+      return -1;
+    }    
+    
+
+    if (i2c_reg_read(REG_SPO2_CFG, &spo2_configuration.all) != 0) {
+      return -1;
+    }  
+    
+
+    if (i2c_reg_read(REG_FIFO_CFG, &fifo_configuration.all) != 0) {
+      return -1;
+    }     
+    
+    
+
+    if (Interrupt_Status_1.bit.a_full) {
+      ///< Read the sample(s)
       char reg = REG_FIFO_DATA;
 
       num_active_led = 0;
 
-      if (max30101_mode_configuration.bit.mode == 0x02) // Heart Rate mode, i.e. 1 led
-      {
+     if (mode_configuration.bit.mode == 0x02) {///< Heart Rate mode, i.e. 1 led    
         num_active_led = 1;
-      } else if (max30101_mode_configuration.bit.mode == 0x03) // SpO2 mode, i.e. 2 led
-      {
+      } else if (mode_configuration.bit.mode == 0x03) { ///< SpO2 mode, i.e. 2 led
         num_active_led = 2;
-      } else if (max30101_mode_configuration.bit.mode == 0x07) // Multi-LED mode, i.e. 1-4 led
-      {
-        if (max30101_multiLED_mode_ctrl_1.bit.slot1 != 0) {
+      } else if (mode_configuration.bit.mode == 0x07) { ///< Multi-LED mode, i.e. 1-4 led
+        if (multiLED_mode_ctrl_1.bit.slot1 != 0) {
+          num_active_led++;
+        }
+
+        if (multiLED_mode_ctrl_1.bit.slot2 != 0) {
           num_active_led++;
         }
 
-        if (max30101_multiLED_mode_ctrl_1.bit.slot2 != 0) {
-          num_active_led++;
-        }
-
-        if (max30101_multiLED_mode_ctrl_2.bit.slot3 != 0) {
+        if (multiLED_mode_ctrl_2.bit.slot3 != 0) {
           num_active_led++;
         }
 
-        if (max30101_multiLED_mode_ctrl_2.bit.slot4 != 0) {
+        if (multiLED_mode_ctrl_2.bit.slot4 != 0) {
           num_active_led++;
         }
       }
-               // 3bytes/LED x Number of Active LED x FIFO level selected
-        rx_bytes =  3 * num_active_led * (32-max30101_fifo_configuration.bit.fifo_a_full);   
+               ///< 3bytes/LED x Number of Active LED x FIFO level selected
+        rx_bytes =  3 * num_active_led * (32-fifo_configuration.bit.fifo_a_full);   
 
       second_rx_bytes = rx_bytes;
-
-      /*  The FIFO Size is determined by the Sample size.  The number of bytes
+      
+      /**
+       * @brief: 
+       * The FIFO Size is determined by the Sample size.  The number of bytes
        * in a Sample is dictated by number of LED's
        *
        *   #LED Selected     Bytes in "1" sample
@@ -135,24 +165,22 @@
        *        3                  9
        *        4                  12
        *
-       *  The I2C API function limits the number of bytes to read to 256 (i.e.
-       * char).  Therefore, when set for
-       *  Multiple LED's and the FIFO size is set to 32.  It would mean there is
-       * more than 256 bytes.
+       *  The I2C API function limits the number of bytes to read, to 256 (i.e.
+       *  char).  Therefore, when set for Multiple LED's and the FIFO
+       *  size is set to 32.  It would mean there is more than 256 bytes.
        *  In that case two I2C reads have to be made.  However It is important
-       * to not that each "Sample"
-       *  must be read completely and reading only partial number of bytes from
-       * a sample will result in erroneous data.
+       *  to note that each "Sample" must be read completely and reading only
+       *  partial number of bytes from a sample will result in erroneous data.
+       * 
        *
        *  For example:
        *  Num of LED selected = 3 and FIFO size is set to 32 (i.e. 0 value in
-       * register), then the number of bytes
-       *  will be 3bytes/Led * 3led's * 32 = 288 bytes in all.  Since there are
-       * 3 LED's each sample will contain (3 * 3)
-       *  9bytes.  Therefore Sample 1 = 9bytes, Sample 2 = 18,... Sample 28 =
-       * 252.  Therefore the first
-       *  I2C read should be 252 bytes and the second read should be 288-252 =
-       * 36.
+       *  register), then the number of bytes will be
+       *  3bytes/Led * 3led's * 32 = 288 bytes in all.  Since there are
+       *  3 LED's each sample will contain (3 * 3) 9bytes.  
+       *  Therefore Sample 1 = 9bytes, Sample 2 = 18,... Sample 28 = 252. 
+       *  Therefore the first I2C read should be 252 bytes and the second
+       *  read should be 288-252 = 36.
        *
        *  It turns out that this size issue comes up only when number of LED
        * selected is 3 or 4 and choosing 252bytes
@@ -175,10 +203,8 @@
       for (i = 0; i < rx_bytes; i += 3) {
         sample = ((uint32_t)(max30101_rawData[i] & 0x03) << 16) | (max30101_rawData[i + 1] << 8) | max30101_rawData[i + 2];
 
-        // Right shift the data based on the LED_PW setting
-        sample = sample >>
-                 (3 -
-                  max30101_spo2_configuration.bit.led_pw); // 0=shift 3, 1=shift 2, 2=shift 1, 3=no shift
+        ///< Right shift the data based on the LED_PW setting
+        sample = sample >> (3 - spo2_configuration.bit.led_pw); // 0=shift 3, 1=shift 2, 2=shift 1, 3=no shift
 
         max30101_buffer[index++] = sample;
       }
@@ -186,19 +212,9 @@
       onDataAvailableCallback(MAX30101_OXIMETER_DATA + num_active_led, max30101_buffer, index);
     }
 
-// This interrupt handles the proximity interrupt, for future enhancements
-#if 0
-   if(max30101_Interrupt_Status_1.bit.prox_int)
-     {
-     max30101_mode_configuration.full=0;
-     max30101_mode_configuration.bit.mode=0x03;     // SpO2 mode
-     i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.full);
 
-     }
-#endif
-
-    // This interrupt handles the temperature interrupt
-    if (max30101_Interrupt_Status_2.bit.die_temp_rdy) {
+    ///< This interrupt handles the temperature interrupt
+    if (Interrupt_Status_2.bit.die_temp_rdy) {
       char reg;
 
       reg = REG_TINT;
@@ -211,19 +227,18 @@
         return -1;
       }
 
-      max30101_final_temp = (int8_t)temp_int + 0.0625 * temp_frac;
+      max30101_final_temp = (int8_t)temp_int + 0.0625f * temp_frac;
 
-      if (i2c_reg_write(REG_TEMP_EN, 0x00) != 0) // Die Temperature Config, Temp disable... after one read...
-      {
+      if (i2c_reg_write(REG_TEMP_EN, 0x00) != 0) { ///< Die Temperature Config, Temp disable... after one read...
         return -1;
       }
     }
 
-    if (i2c_reg_read(REG_INT_STAT_1, &max30101_Interrupt_Status_1.all) != 0) // Read Interrupt flag bits
-    {
+    if (i2c_reg_read(REG_INT_STAT_1, &Interrupt_Status_1.all) != 0) { ///< Read Interrupt flag bits
+
       return -1;
     }
-    if (max30101_Interrupt_Status_1.bit.a_full != 1) {
+    if (Interrupt_Status_1.bit.a_full != 1) {
       loop = 0;
     }
   }
@@ -241,77 +256,81 @@
 
   char status;
 
-  max30101_mode_configuration.all = 0;
-  max30101_mode_configuration.bit.reset = 1;
-  if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) // Reset the device, Mode = don't use...
+  max30101_mode_configuration_t  mode_configuration;
+  max30101_fifo_configuration_t  fifo_configuration;
+  max30101_spo2_configuration_t  spo2_configuration;
+  max30101_Interrupt_Enable_1_t  Interrupt_Enable_1;
+
+  mode_configuration.all = 0;
+  mode_configuration.bit.reset = 1;
+  if (i2c_reg_write(REG_MODE_CFG, mode_configuration.all) != 0) // Reset the device
   {
     return -1;
   }
 
-  /* Give it some settle time (100ms) */
-  wait(1.0 / 10.0); // Let things settle down a bit
+  ///< Give it some settle time (100ms)
+  wait(1.0 / 10.0); ///< Let things settle down a bit
 
-  max30101_fifo_configuration.all = 0;
-  max30101_fifo_configuration.bit.smp_ave = sample_avg; // Sample averaging;
-  max30101_fifo_configuration.bit.fifo_roll_over_en = 1; // FIFO Roll over enabled
-  max30101_fifo_configuration.bit.fifo_a_full = fifo_waterlevel_mark; // Interrupt when certain level is filled
-  if (i2c_reg_write(REG_FIFO_CFG, max30101_fifo_configuration.all) != 0) {
+  fifo_configuration.all = 0;
+  fifo_configuration.bit.smp_ave = sample_avg; ///< Sample averaging;
+  fifo_configuration.bit.fifo_roll_over_en = 1; ///< FIFO Roll over enabled
+  fifo_configuration.bit.fifo_a_full = fifo_waterlevel_mark; ///< Interrupt when certain level is filled
+
+  if (i2c_reg_write(REG_FIFO_CFG, fifo_configuration.all) != 0) {
     return -1;
   }
 
-  max30101_spo2_configuration.bit.spo2_adc_rge = 0x2; // ADC Range 8192 fullscale
-  max30101_spo2_configuration.bit.spo2_sr = sample_rate; // 100 Samp/sec.
-  max30101_spo2_configuration.bit.led_pw = pulse_width; // Pulse Width=411us and ADC Resolution=18
-  if (i2c_reg_write(REG_SPO2_CFG, max30101_spo2_configuration.all) != 0) {
+  spo2_configuration.bit.spo2_adc_rge = 0x2; ///< ADC Range 8192 fullscale
+  spo2_configuration.bit.spo2_sr = sample_rate; ///< 100 Samp/sec.
+  spo2_configuration.bit.led_pw = pulse_width; ///< Pulse Width=411us and ADC Resolution=18
+  if (i2c_reg_write(REG_SPO2_CFG, spo2_configuration.all) != 0) {
     return -1;
   }
 
-  max30101_led1_pa = red_led_current; // RED LED current
-  if (i2c_reg_write(REG_LED1_PA, max30101_led1_pa) != 0) {
+  if (i2c_reg_write(REG_LED1_PA, red_led_current) != 0) {
     return -1;
   }
 
-  max30101_led2_pa = ir_led_current; // IR LED current
-  if (i2c_reg_write(REG_LED2_PA, max30101_led2_pa) != 0) {
+  if (i2c_reg_write(REG_LED2_PA, ir_led_current) != 0) {
     return -1;
   }
 
   /************/
 
-  if (i2c_reg_read(REG_INT_STAT_1, &status) != 0) //  Clear INT1 by reading the status
+  if (i2c_reg_read(REG_INT_STAT_1, &status) != 0) ///<  Clear INT1 by reading the status
   {
     return -1;
   }
 
-  if (i2c_reg_read(REG_INT_STAT_2, &status) != 0) //  Clear INT2 by reading the status
+  if (i2c_reg_read(REG_INT_STAT_2, &status) != 0) ///<  Clear INT2 by reading the status
   {
     return -1;
   }
 
-  if (i2c_reg_write(REG_FIFO_W_PTR, 0x00) != 0) //  Clear FIFO ptr
+  if (i2c_reg_write(REG_FIFO_W_PTR, 0x00) != 0) ///<  Clear FIFO ptr
   {
     return -1;
   }
 
-  if (i2c_reg_write(REG_FIFO_OVF_CNT, 0x00) != 0) //  Clear FIFO ptr
+  if (i2c_reg_write(REG_FIFO_OVF_CNT, 0x00) != 0) ///<  Clear FIFO ptr
   {
     return -1;
   }
 
-  if (i2c_reg_write(REG_FIFO_R_PTR, 0x00) != 0) //  Clear FIFO ptr
+  if (i2c_reg_write(REG_FIFO_R_PTR, 0x00) != 0) ///<  Clear FIFO ptr
   {
     return -1;
   }
 
-  max30101_Interrupt_Enable_1.all = 0;
-  max30101_Interrupt_Enable_1.bit.a_full_en = 1; //  Enable FIFO almost full interrupt
-  if (i2c_reg_write(REG_INT_EN_1, max30101_Interrupt_Enable_1.all) != 0) {
+  Interrupt_Enable_1.all = 0;
+  Interrupt_Enable_1.bit.a_full_en = 1; ///<  Enable FIFO almost full interrupt
+  if (i2c_reg_write(REG_INT_EN_1, Interrupt_Enable_1.all) != 0) {
     return -1;
   }
 
-  max30101_mode_configuration.all = 0;
-  max30101_mode_configuration.bit.mode = 0x03; // SpO2 mode
-  if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) {
+  mode_configuration.all = 0;
+  mode_configuration.bit.mode = 0x03; ///< SpO2 mode
+  if (i2c_reg_write(REG_MODE_CFG, mode_configuration.all) != 0) {
     return -1;
   }
 
@@ -321,25 +340,30 @@
 //******************************************************************************
 int MAX30101::SpO2mode_stop(void) {
 
-  max30101_Interrupt_Enable_1.all = 0;
-  max30101_Interrupt_Enable_1.bit.a_full_en = 0; //  Disable FIFO almost full interrupt
-  if (i2c_reg_write(REG_INT_EN_1, max30101_Interrupt_Enable_1.all) != 0) {
+  max30101_Interrupt_Enable_1_t  Interrupt_Enable_1;
+  max30101_mode_configuration_t  mode_configuration;
+  uint8_t                      led1_pa;
+  uint8_t                      led2_pa;
+
+  Interrupt_Enable_1.all = 0;
+  Interrupt_Enable_1.bit.a_full_en = 0; ///<  Disable FIFO almost full interrupt
+  if (i2c_reg_write(REG_INT_EN_1, Interrupt_Enable_1.all) != 0) {
     return -1;
   }
 
-  max30101_mode_configuration.all = 0;
-  max30101_mode_configuration.bit.mode = 0x00; // SpO2 mode off
-  if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) {
+  mode_configuration.all = 0;
+  mode_configuration.bit.mode = 0x00; ///< SpO2 mode off
+  if (i2c_reg_write(REG_MODE_CFG, mode_configuration.all) != 0) {
     return -1;
   }
 
-  max30101_led1_pa = 0; // RED LED current, 0.0
-  if (i2c_reg_write(REG_LED1_PA, max30101_led1_pa) != 0) {
+  led1_pa = 0; ///< RED LED current, 0.0
+  if (i2c_reg_write(REG_LED1_PA, led1_pa) != 0) {
     return -1;
   }
 
-  max30101_led2_pa = 0; // IR LED current, 0.0
-  if (i2c_reg_write(REG_LED2_PA, max30101_led2_pa) != 0) {
+  led2_pa = 0; ///< IR LED current, 0.0
+  if (i2c_reg_write(REG_LED2_PA, led2_pa) != 0) {
     return -1;
   }
 
@@ -353,74 +377,78 @@
 
   /*uint8_t*/ char status;
 
-  max30101_mode_configuration.all = 0;
-  max30101_mode_configuration.bit.reset = 1;
-  if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) // Reset the device, Mode = don't use...
+  max30101_mode_configuration_t  mode_configuration;
+  max30101_fifo_configuration_t  fifo_configuration;
+  max30101_spo2_configuration_t  spo2_configuration;
+  max30101_Interrupt_Enable_1_t  Interrupt_Enable_1;
+
+  mode_configuration.all = 0;
+  mode_configuration.bit.reset = 1;
+  if (i2c_reg_write(REG_MODE_CFG, mode_configuration.all) != 0) ///< Reset the device, Mode = don't use...
   {
     return -1;
   }
 
-  /* Give it some settle time (100ms) */
-  wait(1.0 / 10.0); // Let things settle down a bit
+  ///< Give it some settle time (100ms)
+  wait(1.0 / 10.0); ///< Let things settle down a bit
 
-  max30101_fifo_configuration.all = 0;
-  max30101_fifo_configuration.bit.smp_ave = sample_avg; // Sample averaging;
-  max30101_fifo_configuration.bit.fifo_roll_over_en = 1; // FIFO Roll over enabled
-  max30101_fifo_configuration.bit.fifo_a_full = fifo_waterlevel_mark; // Interrupt when certain level is filled
-  if (i2c_reg_write(REG_FIFO_CFG, max30101_fifo_configuration.all) != 0) {
+  fifo_configuration.all = 0;
+  fifo_configuration.bit.smp_ave = sample_avg;  ///< Sample averaging;
+  fifo_configuration.bit.fifo_roll_over_en = 1; ///< FIFO Roll over enabled
+  fifo_configuration.bit.fifo_a_full = fifo_waterlevel_mark; ///< Interrupt when certain level is filled
+  if (i2c_reg_write(REG_FIFO_CFG, fifo_configuration.all) != 0) {
     return -1;
   }
 
-  max30101_spo2_configuration.bit.spo2_adc_rge = 0x2; // ADC Range 8192 fullscale
-  max30101_spo2_configuration.bit.spo2_sr = sample_rate; // 100 Samp/sec.
-  max30101_spo2_configuration.bit.led_pw = pulse_width; // Pulse Width=411us and ADC Resolution=18
-  if (i2c_reg_write(REG_SPO2_CFG, max30101_spo2_configuration.all) != 0) {
+  spo2_configuration.bit.spo2_adc_rge = 0x2;    ///< ADC Range 8192 fullscale
+  spo2_configuration.bit.spo2_sr = sample_rate; ///< 100 Samp/sec.
+  spo2_configuration.bit.led_pw = pulse_width;  ///< Pulse Width=411us and ADC Resolution=18
+  if (i2c_reg_write(REG_SPO2_CFG, spo2_configuration.all) != 0) {
     return -1;
   }
 
-  max30101_led1_pa = red_led_current; // RED LED current, 0.0
-  if (i2c_reg_write(REG_LED1_PA, max30101_led1_pa) != 0) {
+  if (i2c_reg_write(REG_LED1_PA, red_led_current) != 0) {
     return -1;
   }
 
   /************/
 
-  if (i2c_reg_read(REG_INT_STAT_1, &status) != 0) //  Clear INT1 by reading the status
+  if (i2c_reg_read(REG_INT_STAT_1, &status) != 0) ///<  Clear INT1 by reading the status
   {
     return -1;
   }
 
-  if (i2c_reg_read(REG_INT_STAT_2, &status) != 0) //  Clear INT2 by reading the status
+  if (i2c_reg_read(REG_INT_STAT_2, &status) != 0) ///< Clear INT2 by reading the status
   {
     return -1;
   }
 
-  if (i2c_reg_write(REG_FIFO_W_PTR, 0x00) != 0) //  Clear FIFO ptr
+  if (i2c_reg_write(REG_FIFO_W_PTR, 0x00) != 0) ///<  Clear FIFO ptr
   {
     return -1;
   }
 
-  if (i2c_reg_write(REG_FIFO_OVF_CNT, 0x00) != 0) //  Clear FIFO ptr
+  if (i2c_reg_write(REG_FIFO_OVF_CNT, 0x00) != 0) ///<  Clear FIFO ptr
   {
     return -1;
   }
 
-  if (i2c_reg_write(REG_FIFO_R_PTR, 0x00) != 0) //  Clear FIFO ptr
+  if (i2c_reg_write(REG_FIFO_R_PTR, 0x00) != 0) ///<  Clear FIFO ptr
   {
     return -1;
   }
 
-  max30101_Interrupt_Enable_1.all = 0;
-  max30101_Interrupt_Enable_1.bit.a_full_en = 1;
-  // max30101_Interrupt_Enable_1.bit.prox_int_en=0;   //  Enable Proximity
+  Interrupt_Enable_1.all = 0;
+  Interrupt_Enable_1.bit.a_full_en = 1;
+  
   // Interrupt
-  if (i2c_reg_write(REG_INT_EN_1, max30101_Interrupt_Enable_1.all) != 0) {
+  if (i2c_reg_write(REG_INT_EN_1, Interrupt_Enable_1.all) != 0) {
     return -1;
   }
 
-  max30101_mode_configuration.all = 0;
-  max30101_mode_configuration.bit.mode = 0x02; // HR mode
-  if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) {
+  mode_configuration.all = 0;
+  mode_configuration.bit.mode = 0x02; ///< HR mode
+  if (i2c_reg_write(REG_MODE_CFG, mode_configuration.all) != 0) {
     return -1;
   }
 
@@ -430,20 +458,22 @@
 //******************************************************************************
 int MAX30101::HRmode_stop(void) {
 
-  max30101_Interrupt_Enable_1.all = 0;
-  max30101_Interrupt_Enable_1.bit.a_full_en = 0; //  Disable FIFO almost full interrupt
-  if (i2c_reg_write(REG_INT_EN_1, max30101_Interrupt_Enable_1.all) != 0) {
+  max30101_Interrupt_Enable_1_t  Interrupt_Enable_1;
+  max30101_mode_configuration_t  mode_configuration;
+
+  Interrupt_Enable_1.all = 0;
+  Interrupt_Enable_1.bit.a_full_en = 0; ///< Disable FIFO almost full interrupt
+  if (i2c_reg_write(REG_INT_EN_1, Interrupt_Enable_1.all) != 0) {
     return -1;
   }
 
-  max30101_mode_configuration.all = 0;
-  max30101_mode_configuration.bit.mode = 0x00; // HR mode off
-  if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) {
+  mode_configuration.all = 0;
+  mode_configuration.bit.mode = 0x00; ///< HR mode off
+  if (i2c_reg_write(REG_MODE_CFG, mode_configuration.all) != 0) {
     return -1;
   }
 
-  max30101_led1_pa = 0; // RED LED current, 0.0
-  if (i2c_reg_write(REG_LED1_PA, max30101_led1_pa) != 0) {
+  if (i2c_reg_write(REG_LED1_PA, 0) != 0) {
     return -1;
   }
 
@@ -456,100 +486,105 @@
                              uint8_t red_led_current, uint8_t ir_led_current,
                              uint8_t green_led_current, uint8_t slot_1,
                              uint8_t slot_2, uint8_t slot_3, uint8_t slot_4) {
+
   char status;
-  max30101_mode_configuration.all = 0;
-  max30101_mode_configuration.bit.reset = 1;
-  if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) // Reset the device, Mode = don't use...
+  max30101_mode_configuration_t    mode_configuration;
+  max30101_fifo_configuration_t    fifo_configuration;
+  max30101_spo2_configuration_t    spo2_configuration;
+  max30101_multiLED_mode_ctrl_1_t  multiLED_mode_ctrl_1;
+  max30101_multiLED_mode_ctrl_2_t  multiLED_mode_ctrl_2;
+  max30101_Interrupt_Enable_1_t    Interrupt_Enable_1;
+  
+  mode_configuration.all = 0;
+  mode_configuration.bit.reset = 1;
+  if (i2c_reg_write(REG_MODE_CFG, mode_configuration.all) != 0) ///< Reset the device, Mode = don't use...
   {
     return -1;
   }
 
-  /* Give it some settle time (100ms) */ // Let things settle down a bit
+  /* Give it some settle time (100ms) */ ///< Let things settle down a bit
   wait(1.0 / 10.0);
 
-  max30101_fifo_configuration.all = 0;
-  max30101_fifo_configuration.bit.smp_ave = sample_avg; // Sample averaging;
-  max30101_fifo_configuration.bit.fifo_roll_over_en = 1; // FIFO Roll over enabled
-  max30101_fifo_configuration.bit.fifo_a_full =
-      fifo_waterlevel_mark; // Interrupt when certain level is filled
-  if (i2c_reg_write(REG_FIFO_CFG, max30101_fifo_configuration.all) != 0) {
+  fifo_configuration.all = 0;
+  fifo_configuration.bit.smp_ave = sample_avg; ///< Sample averaging;
+  fifo_configuration.bit.fifo_roll_over_en = 1; ///< FIFO Roll over enabled
+  fifo_configuration.bit.fifo_a_full =
+      fifo_waterlevel_mark; ///< Interrupt when certain level is filled
+  if (i2c_reg_write(REG_FIFO_CFG, fifo_configuration.all) != 0) {
     return -1;
   }
 
-  max30101_spo2_configuration.bit.spo2_adc_rge = 0x2; // ADC Range 8192 fullscale
-  max30101_spo2_configuration.bit.spo2_sr = sample_rate; // 100 Samp/sec.
-  max30101_spo2_configuration.bit.led_pw = pulse_width; // Pulse Width=411us and ADC Resolution=18
-  if (i2c_reg_write(REG_SPO2_CFG, max30101_spo2_configuration.all) != 0) {
-    return -1;
-  }
-
-  max30101_led1_pa = red_led_current; // RED LED current
-  if (i2c_reg_write(REG_LED1_PA, max30101_led1_pa) != 0) {
+  spo2_configuration.bit.spo2_adc_rge = 0x2;    ///< ADC Range 8192 fullscale
+  spo2_configuration.bit.spo2_sr = sample_rate; ///< 100 Samp/sec.
+  spo2_configuration.bit.led_pw = pulse_width;  ///< Pulse Width=411us and ADC Resolution=18
+  if (i2c_reg_write(REG_SPO2_CFG, spo2_configuration.all) != 0) {
     return -1;
   }
 
-  max30101_led2_pa = ir_led_current; // IR LED current
-  if (i2c_reg_write(REG_LED2_PA, max30101_led2_pa) != 0) {
+  if (i2c_reg_write(REG_LED1_PA, red_led_current) != 0) {
     return -1;
   }
 
-  max30101_led3_pa = green_led_current; // Green LED current
-  if (i2c_reg_write(REG_LED3_PA, max30101_led3_pa) != 0) {
+  if (i2c_reg_write(REG_LED2_PA, ir_led_current) != 0) {
+    return -1;
+  }
+
+  if (i2c_reg_write(REG_LED3_PA, green_led_current) != 0) {
     return -1;
   }
 
-  // 0x01=Red(LED1), 0x02=IR(LED2), 0x03=Green(LED3) : Use LEDn_PA to adjust the intensity
-  // 0x05=Red      , 0x06=IR      , 0x07=Green       : Use PILOT_PA to adjust the intensity DO NOT USE THIS ROW...
+  ///< 0x01=Red(LED1), 0x02=IR(LED2), 0x03=Green(LED3) : Use LEDn_PA to adjust the intensity
+  ///< 0x05=Red      , 0x06=IR      , 0x07=Green       : Use PILOT_PA to adjust the intensity DO NOT USE THIS ROW...
 
-  max30101_multiLED_mode_ctrl_1.bit.slot1 = slot_1;
-  max30101_multiLED_mode_ctrl_1.bit.slot2 = slot_2;
-  if (i2c_reg_write(REG_SLT2_SLT1, max30101_multiLED_mode_ctrl_1.all)) {
+  multiLED_mode_ctrl_1.bit.slot1 = slot_1;
+  multiLED_mode_ctrl_1.bit.slot2 = slot_2;
+  if (i2c_reg_write(REG_SLT2_SLT1, multiLED_mode_ctrl_1.all)) {
     return -1;
   }
 
-  max30101_multiLED_mode_ctrl_2.all = 0;
-  max30101_multiLED_mode_ctrl_2.bit.slot3 = slot_3;
-  max30101_multiLED_mode_ctrl_2.bit.slot4 = slot_4;
-  if (i2c_reg_write(REG_SLT4_SLT3, max30101_multiLED_mode_ctrl_2.all)) {
+  multiLED_mode_ctrl_2.all = 0;
+  multiLED_mode_ctrl_2.bit.slot3 = slot_3;
+  multiLED_mode_ctrl_2.bit.slot4 = slot_4;
+  if (i2c_reg_write(REG_SLT4_SLT3, multiLED_mode_ctrl_2.all)) {
     return -1;
   }
 
   /************/
 
-  if (i2c_reg_read(REG_INT_STAT_1, &status) != 0) //  Clear INT1 by reading the status
+  if (i2c_reg_read(REG_INT_STAT_1, &status) != 0) ///<  Clear INT1 by reading the status
   {
     return -1;
   }
 
-  if (i2c_reg_read(REG_INT_STAT_2, &status) != 0) //  Clear INT2 by reading the status
+  if (i2c_reg_read(REG_INT_STAT_2, &status) != 0) ///<  Clear INT2 by reading the status
   {
     return -1;
   }
 
-  if (i2c_reg_write(REG_FIFO_W_PTR, 0x00) != 0) //  Clear FIFO ptr
+  if (i2c_reg_write(REG_FIFO_W_PTR, 0x00) != 0) ///<  Clear FIFO ptr
   {
     return -1;
   }
 
-  if (i2c_reg_write(REG_FIFO_OVF_CNT, 0x00) != 0) //  Clear FIFO ptr
+  if (i2c_reg_write(REG_FIFO_OVF_CNT, 0x00) != 0) ///<  Clear FIFO ptr
   {
     return -1;
   }
 
-  if (i2c_reg_write(REG_FIFO_R_PTR, 0x00) != 0) //  Clear FIFO ptr
+  if (i2c_reg_write(REG_FIFO_R_PTR, 0x00) != 0) ///<  Clear FIFO ptr
   {
     return -1;
   }
 
-  max30101_Interrupt_Enable_1.all = 0;
-  max30101_Interrupt_Enable_1.bit.a_full_en = 1; //  Enable FIFO almost full interrupt
-  if (i2c_reg_write(REG_INT_EN_1, max30101_Interrupt_Enable_1.all) != 0) {
+  Interrupt_Enable_1.all = 0;
+  Interrupt_Enable_1.bit.a_full_en = 1; ///<  Enable FIFO almost full interrupt
+  if (i2c_reg_write(REG_INT_EN_1, Interrupt_Enable_1.all) != 0) {
     return -1;
   }
 
-  max30101_mode_configuration.all = 0;
-  max30101_mode_configuration.bit.mode = 0x07; // Multi-LED mode
-  if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) {
+  mode_configuration.all = 0;
+  mode_configuration.bit.mode = 0x07; ///< Multi-LED mode
+  if (i2c_reg_write(REG_MODE_CFG, mode_configuration.all) != 0) {
     return -1;
   }
 
@@ -559,30 +594,31 @@
 //******************************************************************************
 int MAX30101::Multimode_stop(void) {
 
-  max30101_Interrupt_Enable_1.all = 0;
-  max30101_Interrupt_Enable_1.bit.a_full_en = 0; //  Disable FIFO almost full interrupt
-  if (i2c_reg_write(REG_INT_EN_1, max30101_Interrupt_Enable_1.all) != 0) {
-    return -1;
-  }
+max30101_Interrupt_Enable_1_t  Interrupt_Enable_1;
+max30101_mode_configuration_t  mode_configuration;
+
 
-  max30101_mode_configuration.all = 0;
-  max30101_mode_configuration.bit.mode = 0x00; // Multi-LED mode off
-  if (i2c_reg_write(REG_MODE_CFG, max30101_mode_configuration.all) != 0) {
+  Interrupt_Enable_1.all = 0;
+  Interrupt_Enable_1.bit.a_full_en = 0; ///< Disable FIFO almost full interrupt
+  if (i2c_reg_write(REG_INT_EN_1, Interrupt_Enable_1.all) != 0) {
     return -1;
   }
 
-  max30101_led1_pa = 0; // RED LED current, 0.0
-  if (i2c_reg_write(REG_LED1_PA, max30101_led1_pa) != 0) {
+  mode_configuration.all = 0;
+  mode_configuration.bit.mode = 0x00; ///< Multi-LED mode off
+  if (i2c_reg_write(REG_MODE_CFG, mode_configuration.all) != 0) {
     return -1;
   }
 
-  max30101_led2_pa = 0; // IR LED current, 0.0
-  if (i2c_reg_write(REG_LED2_PA, max30101_led2_pa) != 0) {
+  if (i2c_reg_write(REG_LED1_PA, 0) != 0) {
     return -1;
   }
 
-  max30101_led3_pa = 0; // Green LED current, 0.0
-  if (i2c_reg_write(REG_LED3_PA, max30101_led3_pa) != 0) {
+  if (i2c_reg_write(REG_LED2_PA, 0) != 0) {
+    return -1;
+  }
+
+  if (i2c_reg_write(REG_LED3_PA, 0) != 0) {
     return -1;
   }
   return 0;
@@ -590,15 +626,13 @@
 
 //******************************************************************************
 int MAX30101::tempread(void) {
-  max30101_Interrupt_Enable_2.all = 0;
-  max30101_Interrupt_Enable_2.bit.die_temp_rdy_en = 1; // Enable the Temp Rdy;
-  if (i2c_reg_write(REG_INT_EN_2, 0x02) != 0) // Interrupt Enable 2, Temperature Interrupt
-  {
+   
+  if (i2c_reg_write(REG_INT_EN_2, 0x02) != 0) {///< Interrupt Enable 2, Temperature Interrupt
     return -1;
   }
 
-  if (i2c_reg_write(REG_TEMP_EN, 0x01) != 0) // Die Temperature Config, Temp enable...
-  {
+  if (i2c_reg_write(REG_TEMP_EN, 0x01) != 0) {///< Die Temperature Config, Temp enable...
+
     return -1;
   }
   return 0;
@@ -606,9 +640,10 @@
 
 //******************************************************************************
 int MAX30101::i2c_reg_write(MAX30101_REG_map_t reg, char value) {
+
   char cmdData[2] = {reg, value};
 
-  if (I2CM_Write(slaveAddress, NULL, 0, cmdData, 2) != 0 /*2*/) {
+  if (I2CM_Write(slaveAddress, NULL, 0, cmdData, 2) != 0) {
     return -1;
   }
 
@@ -624,16 +659,10 @@
   return 0;
 }
 
-/**
-* @brief Read from an I2C device
-* @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 MAX30101::I2CM_Read(int slaveAddress, char *writeData, char writeCount,
                         char *readData, char readCount) {
+
   if (writeData != NULL && writeCount != 0) {
     i2c->write(slaveAddress, writeData, writeCount, true);
   }
@@ -643,16 +672,10 @@
   return 0;
 }
 
-/**
-* @brief Write to an I2C device
-* @param slaveAddress slave address to use with transaction
-* @param writeData 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 MAX30101::I2CM_Write(int slaveAddress, char *writeData1, char writeCount1,
                          char *writeData2, char writeCount2) {
+ 
   if (writeData1 != NULL && writeCount1 != 0) {
     i2c->write(slaveAddress, writeData1, writeCount1);
   }
@@ -664,16 +687,13 @@
 
 //******************************************************************************
 void MAX30101::onDataAvailable(DataCallbackFunction _onDataAvailable) {
+
   onDataAvailableCallback = _onDataAvailable;
 }
 
-/**
-* @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 MAX30101::dataAvailable(uint32_t id, uint32_t *buffer, uint32_t length) {
+
   if (onDataAvailableCallback != NULL) {
     (*onDataAvailableCallback)(id, buffer, length);
   }
@@ -681,23 +701,21 @@
 
 //******************************************************************************
 void MAX30101::onInterrupt(InterruptFunction _onInterrupt) {
+
   onInterruptCallback = _onInterrupt;
 }
 
-/**
-* @brief Executed on 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 MAX30101::interruptPostCallback(void) {
+
   if (onInterruptCallback != NULL) {
+
     (*onInterruptCallback)();
   }
 }
 
-int max30101_enableInterrupts = 0;
-/**************************************************************************************************************/
-void MAX30101MidIntHandler(void) { 
-  MAX30101::instance->int_handler(); 
+//******************************************************************************
+void MAX30101::MidIntHandler(void) { 
+
+  MAX30101::instance->int_handler();
 }