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/LIS2DH/LIS2DH/LIS2DH.cpp	Tue Oct 25 15:22:11 2016 +0000
+++ b/HSP/Devices/LIS2DH/LIS2DH/LIS2DH.cpp	Fri Apr 21 12:12:30 2017 -0500
@@ -36,11 +36,11 @@
 #include "Peripherals.h"
 
 void lis2dh_int_handler(void);
-/** buffer array to hold fifo contents for packetizing
-*/
+ /** 
+  * @brief buffer array to hold fifo contents for packetizing
+  */
 uint32_t lis2dh_buffer[LIS2DH_MAX_DATA_SIZE];
 
-static int debug_int_count = 0;
 int16_t motion_cached[3];
 LIS2DH *LIS2DH::instance = NULL;
 
@@ -70,26 +70,29 @@
 }
 
 //******************************************************************************
-int LIS2DH::writeReg(char reg, char value) {
+int LIS2DH::writeReg(LIS2DH_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 LIS2DH::readReg(char reg, char *value) {
+int LIS2DH::readReg(LIS2DH_REG_map_t reg, char *value) {
   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, 1);
-  if (result != 0)
+  if (result != 0) {
     return -1;
+  }
   return 0;
 }
 
@@ -104,8 +107,8 @@
 }
 
 //******************************************************************************
-//  Interrupt handler, this empties the hardware fifo and packetizes it for
-//  streaming
+///  Interrupt handler, this empties the hardware fifo and packetizes it for
+///  streaming
 void LIS2DH::int_handler(void) {
   char fifo_src;
   int16_t valueX;
@@ -125,8 +128,9 @@
     lis2dh_buffer[index++] = valueZ;
     readReg(LIS2DH_FIFO_SRC_REG, &fifo_src);
     num++;
-    if (num >= 32)
+    if (num >= 32) {
       break;
+    }
   }
   motion_cached[0] = valueX;
   motion_cached[1] = valueY;
@@ -143,60 +147,80 @@
 
 //******************************************************************************
 void LIS2DH::configure_interrupt(void) {
-  // interrupt enabled on INT1, interrupt active low
-  lis2dh_ctrl_reg6.all = 0;
-  lis2dh_ctrl_reg6.bit.I2_INT1 = 1;      // interrupt 1 function enabled on int1 pin
-  lis2dh_ctrl_reg6.bit.H_LACTIVE = 1;    // interrupt active low
-  writeReg(LIS2DH_CTRL_REG6, lis2dh_ctrl_reg6.all);
+  
+  lis2dh_ctrl_reg6_t ctrl_reg6;
+  ///< interrupt enabled on INT1, interrupt active low
+  ctrl_reg6.all = 0;
+  ctrl_reg6.bit.I2_INT1 = 1;      ///< interrupt 1 function enabled on int1 pin
+  ctrl_reg6.bit.H_LACTIVE = 1;    ///< interrupt active low
+  writeReg(LIS2DH_CTRL_REG6, ctrl_reg6.all);
 }
 
 //******************************************************************************
 int LIS2DH::initStart(int dataRate, int fifoThreshold) {
+  
+  lis2dh_ctrl_reg5_t     ctrl_reg5;
+  lis2dh_fifo_ctrl_reg_t fifo_ctrl_reg;
+  lis2dh_ctrl_reg1_t     ctrl_reg1;
+  lis2dh_ctrl_reg3_t     ctrl_reg3;
+  
   __disable_irq();
 
   configure_interrupt();
-
-  // enable FIFO
-  lis2dh_ctrl_reg5.all = 0x0;
-  lis2dh_ctrl_reg5.bit.FIFO_EN = 0x1;
-  if (writeReg(LIS2DH_CTRL_REG5, lis2dh_ctrl_reg5.all) == -1) {
+  ///
+  /// enable FIFO
+  ///
+  ctrl_reg5.all = 0x0;
+  ctrl_reg5.bit.FIFO_EN = 0x1;
+  if (writeReg(LIS2DH_CTRL_REG5, ctrl_reg5.all) == -1) {
+    __enable_irq();
+    return -1;
+  }
+  
+  ///
+  /// set FIFO to stream mode, trigger select INT1
+  ///
+  fifo_ctrl_reg.all = 0x0;
+  fifo_ctrl_reg.bit.FTH = fifoThreshold;
+  fifo_ctrl_reg.bit.FM = LIS2DH_FIFOMODE_STREAM;
+  fifo_ctrl_reg.bit.TR = 0x0;
+  if (writeReg(LIS2DH_FIFO_CTRL_REG, fifo_ctrl_reg.all) == -1) {
     __enable_irq();
     return -1;
   }
 
-  // set FIFO to stream mode, trigger select INT1
-  lis2dh_fifo_ctrl_reg.all = 0x0;
-  lis2dh_fifo_ctrl_reg.bit.FTH = fifoThreshold;
-  lis2dh_fifo_ctrl_reg.bit.FM = LIS2DH_FIFOMODE_STREAM;
-  lis2dh_fifo_ctrl_reg.bit.TR = 0x0;
-  if (writeReg(LIS2DH_FIFO_CTRL_REG, lis2dh_fifo_ctrl_reg.all) == -1) {
-    __enable_irq();
-    return -1;
-  }
-
-  // set HR (high resolution)
+  ///
+  /// set HR (high resolution)
+  ///
   if (writeReg(LIS2DH_CTRL_REG4, 0x8) == -1) {
     __enable_irq();
     return -1;
   }
 
-  // set the data rate, enable all axis
+  ///
+  /// set the data rate, enable all axis
+  ///
   dataRate = dataRate & 0xF;
-  if (dataRate > 0x9) dataRate = 0x9;
-  lis2dh_ctrl_reg1.bit.ODR = dataRate; // set the data rate
-  lis2dh_ctrl_reg1.bit.LPen = 0x0;     // disable low power mode
-  lis2dh_ctrl_reg1.bit.Zen = 0x1;      // enable z
-  lis2dh_ctrl_reg1.bit.Yen = 0x1;      // enable y
-  lis2dh_ctrl_reg1.bit.Xen = 0x1;      // enable x
-  if (writeReg(LIS2DH_CTRL_REG1, lis2dh_ctrl_reg1.all) == -1) {
+  if (dataRate > 0x9) {
+    dataRate = 0x9;
+  }
+  
+  ctrl_reg1.bit.ODR = dataRate; ///< set the data rate
+  ctrl_reg1.bit.LPen = 0x0;     ///< disable low power mode
+  ctrl_reg1.bit.Zen = 0x1;      ///< enable z
+  ctrl_reg1.bit.Yen = 0x1;      ///< enable y
+  ctrl_reg1.bit.Xen = 0x1;      ///< enable x
+  if (writeReg(LIS2DH_CTRL_REG1, ctrl_reg1.all) == -1) {
     __enable_irq();
     return -1;
   }
 
-  // enable watermark interrupt
-  lis2dh_ctrl_reg3.all = 0x00;
-  lis2dh_ctrl_reg3.bit.I1_WTM = 0x1;
-  if (writeReg(LIS2DH_CTRL_REG3, lis2dh_ctrl_reg3.all) == -1) {
+  ///
+  /// enable watermark interrupt
+  ///
+  ctrl_reg3.all = 0x00;
+  ctrl_reg3.bit.I1_WTM = 0x1;
+  if (writeReg(LIS2DH_CTRL_REG3, ctrl_reg3.all) == -1) {
     __enable_irq();
     return -1;
   }
@@ -209,9 +233,14 @@
 int LIS2DH::detect(char *detected) {
   char val;
   *detected = 0;
-  if (readReg(LIS2DH_WHO_AM_I, &val) == -1)
+  if (readReg(LIS2DH_WHO_AM_I, &val) == -1) {
     return -1;
-  if (val == LIS2DH_ID) *detected = 1;
+  }
+  
+  if (val == LIS2DH_ID) {
+    *detected = 1;
+  }
+  
   return 0;
 }
 
@@ -232,7 +261,7 @@
 
   reg = LIS2DH_OUT_X_L;
   for (i = 0; i < 6; i++) {
-    if (readReg(reg, &values[i]) != 0) {
+    if (readReg((LIS2DH_REG_map_t)reg, &values[i]) != 0) {
       return -1;
     }
     reg++;
@@ -248,7 +277,6 @@
 }
 
 //******************************************************************************
-// 0x33 = read ID
 char LIS2DH::readId(void) {
   char val;
   readReg(LIS2DH_WHO_AM_I, &val);
@@ -268,9 +296,11 @@
 //******************************************************************************
 void LIS2DHIntHandler(void) {
   char value;
-  // read the data rate axis enable register, if this is zero then just return,
-  // we are not ready for interrupts
-  LIS2DH::instance->readReg(LIS2DH_CTRL_REG1, &value);
+  ///
+  /// read the data rate axis enable register, if this is zero then just return,
+  /// we are not ready for interrupts
+  ///
+  LIS2DH::instance->readReg(LIS2DH::LIS2DH_CTRL_REG1, &value);
   if (value == 0x0) {
     return;
   }