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/BMP280/BMP280/BMP280.cpp	Tue Oct 25 15:22:11 2016 +0000
+++ b/HSP/Devices/BMP280/BMP280/BMP280.cpp	Fri Apr 21 12:12:30 2017 -0500
@@ -30,20 +30,21 @@
  * ownership rights.
  *******************************************************************************
  */
-
-
 #include "mbed.h"
 #include "BMP280.h"
 
 //******************************************************************************
 BMP280::BMP280(PinName sda, PinName scl, int slaveAddress) : 
         slaveAddress(slaveAddress) {
+
   i2c = new I2C(sda, scl);
   isOwner = true;
 }
+
 //******************************************************************************
 BMP280::BMP280(I2C *i2c, int slaveAddress) : 
         slaveAddress(slaveAddress) {
+
   this->i2c = i2c;
   isOwner = false;
 
@@ -51,8 +52,10 @@
   loggingEnabled = 0;
   loggingSampleRate = 5;
 }
+
 //******************************************************************************
 BMP280::~BMP280(void) {
+
   if (isOwner == true) {
     delete i2c;
   }
@@ -61,17 +64,19 @@
 //******************************************************************************
 int BMP280::init(BMP280::bmp280_osrs_P_t Osrs_p, BMP280::bmp280_osrs_T_t Osrs_t,
                  BMP280::bmp280_FILT_t Filter, BMP280::bmp280_MODE_t Mode,
-                 BMP280::bmp280_TSB_t T_sb)
+                 BMP280::bmp280_TSB_t T_sb) {
 
-{
-  char reg;
   char raw_Tn[6];
   char raw_Pn[20];
+  
+  bmp280_ctrl_meas_t ctrl_meas;
+  bmp280_config_t    config;
 
-  // Read all the temp coeffecients from the BMP280 memory. It will be used in
-  // calculation
-  reg = 0x88;
-  if (reg_read(reg, raw_Tn, 6) != 0) {
+  ///
+  /// Read all the temp coeffecients from the BMP280 memory. It will be used in
+  /// calculation
+  ///
+  if (reg_read(BMP280_CALIB00, raw_Tn, 6) != 0) { 
     return -1;
   }
 
@@ -79,10 +84,11 @@
   dig_T2 = (((int16_t)raw_Tn[3]) << 8) | raw_Tn[2];
   dig_T3 = (((int16_t)raw_Tn[5]) << 8) | raw_Tn[4];
 
-  // Read all the press coeffecients from the BMP280 memory. It will be used in
-  // calculation
-  reg = 0x8E;
-  if (reg_read(reg, raw_Pn, 20) != 0) {
+  ///
+  /// Read all the press coeffecients from the BMP280 memory. It will be used in
+  /// calculation
+  ///
+  if (reg_read((BMP280_REG_map_t)(BMP280_CALIB00+6) /*reg*/, raw_Pn, 20) != 0) {
     return -1;
   }
 
@@ -100,32 +106,32 @@
   wait(1.0 / 10.0);
 
   /****/
-  if (reg_read(BMP280_CTRL_MEAS, &bmp280_ctrl_meas.all, 1) != 0) {
+  if (reg_read(BMP280_CTRL_MEAS, &ctrl_meas.all, 1) != 0) {
     return -1;
   }
 
-  bmp280_ctrl_meas.bit.osrs_p = Osrs_p;
-  bmp280_ctrl_meas.bit.osrs_t = Osrs_t;
+  ctrl_meas.bit.osrs_p = Osrs_p;
+  ctrl_meas.bit.osrs_t = Osrs_t;
 
-  bmp280_ctrl_meas.bit.mode = Mode;
+  ctrl_meas.bit.mode = Mode;
 
-  if (reg_write(BMP280_CTRL_MEAS, bmp280_ctrl_meas.all) != 0) {
+  if (reg_write(BMP280_CTRL_MEAS, ctrl_meas.all) != 0) {
     return -1;
   }
 
   /****/
 
-  if (reg_read(BMP280_CONFIG, &bmp280_config.all, 1) != 0) {
+  if (reg_read(BMP280_CONFIG, &config.all, 1) != 0) {
     return -1;
   }
 
-  bmp280_config.bit.filter = Filter;
+  config.bit.filter = Filter;
 
   if (Mode == 0b11) {
-    bmp280_config.bit.t_sb = T_sb;
+    config.bit.t_sb = T_sb;
   }
 
-  if (reg_write(BMP280_CONFIG, bmp280_config.all) != 0) {
+  if (reg_write(BMP280_CONFIG, config.all) != 0) {
     return -1;
   }
 
@@ -134,11 +140,13 @@
 
 //******************************************************************************
 float BMP280::ToFahrenheit(float temperature) {
-  return temperature * 9 / 5 + 32;
+
+  return temperature * (9 / 5.0f) + 32;
 }
 
 //******************************************************************************
 int BMP280::ReadCompDataRaw2(char *bmp280_rawData) {
+
   int i;
   char data[6];
   float temp;
@@ -157,13 +165,8 @@
 
 //******************************************************************************
 int BMP280::ReadCompDataRaw(char *bmp280_rawData) {
-  char reg;
-  char rxbytes;
 
-  reg = BMP280_PRESS_MSB;
-  rxbytes = 6;
-
-  if (reg_read(reg, bmp280_rawData, rxbytes) != 0) {
+  if (reg_read(BMP280_PRESS_MSB, bmp280_rawData, 6) != 0) {
     return -1;
   }
   return 0;
@@ -171,6 +174,7 @@
 
 //******************************************************************************
 void BMP280::ToFloat(char *bmp280_rawData, float *Temp_degC, float *Press_Pa) {
+
   bmp280_rawPress = (uint32_t)(bmp280_rawData[0] << 12) |
                     (bmp280_rawData[1] << 4) | (bmp280_rawData[2] >> 4);
 
@@ -183,6 +187,7 @@
 
 //******************************************************************************
 int BMP280::ReadCompData(float *Temp_degC, float *Press_Pa) {
+
   char bmp280_rawData[6];
 
   if (ReadCompDataRaw(bmp280_rawData) != 0) {
@@ -193,39 +198,45 @@
 }
 
 //******************************************************************************
-int BMP280::reg_write(char reg, char value) {
+int BMP280::reg_write(BMP280_REG_map_t reg, char value) {
+
   int result;
   char cmdData[2] = {(char)reg, value};
   result = i2c->write(slaveAddress, cmdData, 2);
-  if (result != 0)
+  if (result != 0) {
     return -1;
+  }
   return 0;
 }
 
 //******************************************************************************
-int BMP280::reg_read(char reg, char *value, char number) {
+int BMP280::reg_read(BMP280_REG_map_t reg, char *value, char number) {
+
   int result;
   char cmdData[1] = {(char)reg};
 
   result = i2c->write(slaveAddress, cmdData, 1);
-  if (result != 0)
+  if (result != 0) {
     return -1;
+  }
   result = i2c->read(slaveAddress, value, number);
-  if (result != 0)
+  if (result != 0) {
     return -1;
+  }
   return 0;
 }
 
 //******************************************************************************
 int BMP280::Sleep(void) {
-  // Configure the I2C interface
+  
+  bmp280_ctrl_meas_t ctrl_meas;
 
-  if (reg_read(BMP280_CTRL_MEAS, &bmp280_ctrl_meas.all, 1) != 0) {
+  if (reg_read(BMP280_CTRL_MEAS, &ctrl_meas.all, 1) != 0) {
     return -1;
   }
-  bmp280_ctrl_meas.bit.mode = 0b00; // put everything to sleep mode...
+  ctrl_meas.bit.mode = 0b00; // put everything to sleep mode...
 
-  if (reg_write(BMP280_CTRL_MEAS, bmp280_ctrl_meas.all) != 0) {
+  if (reg_write(BMP280_CTRL_MEAS, ctrl_meas.all) != 0) {
     return -1;
   }
   return 0;
@@ -233,11 +244,13 @@
 
 //******************************************************************************
 void BMP280::Reset(void) {
+
   reg_write(BMP280_RESET, 0xB6); // Initiate a Soft Reset
 }
 
 //******************************************************************************
 int BMP280::Detect(void) {
+
   if (reg_read(BMP280_ID, &bmp280_id, 1) != 0) {
     return -1;
   }
@@ -250,6 +263,7 @@
 
 //******************************************************************************
 int BMP280::ReadId(void) {
+
   if (reg_read(BMP280_ID, &bmp280_id, 1) != 0) {
     return -1;
   }
@@ -258,37 +272,39 @@
 
 //******************************************************************************
 float BMP280::compensate_T_float(int32_t adc_T) {
+
   float var1, var2, T;
   var1 =
-      (((float)adc_T) / 16384.0 - ((float)dig_T1) / 1024.0) * ((float)dig_T2);
+      (((float)adc_T) / 16384.0f - ((float)dig_T1) / 1024.0f) * ((float)dig_T2);
 
-  var2 = ((((float)adc_T) / 131072.0 - ((float)dig_T1) / 8192.0) *
-          (((float)adc_T) / 131072.0 - ((float)dig_T1) / 8192.0)) *
+  var2 = ((((float)adc_T) / 131072.0f - ((float)dig_T1) / 8192.0f) *
+          (((float)adc_T) / 131072.0f - ((float)dig_T1) / 8192.0f)) *
          ((float)dig_T3);
 
   t_fine = (int32_t)(var1 + var2);
 
-  T = (var1 + var2) / 5120.0;
+  T = (var1 + var2) / 5120.0f;
 
   return T;
 }
 
 //******************************************************************************
 float BMP280::compensate_P_float(int32_t adc_P) {
+
   float var1, var2, p;
-  var1 = ((float)t_fine / 2.0) - 64000.0;
-  var2 = var1 * var1 * ((float)dig_P6) / 32768.0;
-  var2 = var2 + var1 * ((float)dig_P5) * 2.0;
-  var2 = (var2 / 4.0) + (((float)dig_P4) * 65536.0);
-  var1 = (((float)dig_P3) * var1 * var1 / 524288.0 + ((float)dig_P2) * var1) / 524288.0;
-  var1 = (1.0 + var1 / 32768.0) * ((float)dig_P1);
-  if (var1 == 0.0) {
+  var1 = ((float)t_fine / 2.0f) - 64000.0f;
+  var2 = var1 * var1 * ((float)dig_P6) / 32768.0f;
+  var2 = var2 + var1 * ((float)dig_P5) * 2.0f;
+  var2 = (var2 / 4.0f) + (((float)dig_P4) * 65536.0f);
+  var1 = (((float)dig_P3) * var1 * var1 / 524288.0f + ((float)dig_P2) * var1) / 524288.0f;
+  var1 = (1.0f + var1 / 32768.0f) * ((float)dig_P1);
+  if (var1 == 0.0f) {
     return 0; // avoid exception caused by division by zero
   }
-  p = 1048576.0 - (float)adc_P;
-  p = (p - (var2 / 4096.0)) * 6250.0 / var1;
-  var1 = ((float)dig_P9) * p * p / 2147483648.0;
-  var2 = p * ((float)dig_P8) / 32768.0;
-  p = p + (var1 + var2 + ((float)dig_P7)) / 16.0;
+  p = 1048576.0f - (float)adc_P;
+  p = (p - (var2 / 4096.0f)) * 6250.0f / var1;
+  var1 = ((float)dig_P9) * p * p / 2147483648.0f;
+  var2 = p * ((float)dig_P8) / 32768.0f;
+  p = p + (var1 + var2 + ((float)dig_P7)) / 16.0f;
   return p;
 }