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.

Committer:
jbradshaw
Date:
Tue Apr 25 10:47:10 2017 -0500
Revision:
3:8e9b9f5818aa
Parent:
1:9490836294ea
Removed Bulk Erasing, instead a small number of bytes are sampled from each and every page to determine if sector is "dirty", if so sector is erased
Prevents device from sleeping when the firmware detects a series of binary flash page RPC transfers, this increases flash page transfers by %450
when 200mS elapse with the last flash page transfer, normal sleep behaviour is resumed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jbradshaw 0:e4a10ed6eb92 1 /*******************************************************************************
jbradshaw 0:e4a10ed6eb92 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
jbradshaw 0:e4a10ed6eb92 3 *
jbradshaw 0:e4a10ed6eb92 4 * Permission is hereby granted, free of charge, to any person obtaining a
jbradshaw 0:e4a10ed6eb92 5 * copy of this software and associated documentation files (the "Software"),
jbradshaw 0:e4a10ed6eb92 6 * to deal in the Software without restriction, including without limitation
jbradshaw 0:e4a10ed6eb92 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
jbradshaw 0:e4a10ed6eb92 8 * and/or sell copies of the Software, and to permit persons to whom the
jbradshaw 0:e4a10ed6eb92 9 * Software is furnished to do so, subject to the following conditions:
jbradshaw 0:e4a10ed6eb92 10 *
jbradshaw 0:e4a10ed6eb92 11 * The above copyright notice and this permission notice shall be included
jbradshaw 0:e4a10ed6eb92 12 * in all copies or substantial portions of the Software.
jbradshaw 0:e4a10ed6eb92 13 *
jbradshaw 0:e4a10ed6eb92 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
jbradshaw 0:e4a10ed6eb92 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
jbradshaw 0:e4a10ed6eb92 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
jbradshaw 0:e4a10ed6eb92 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
jbradshaw 0:e4a10ed6eb92 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
jbradshaw 0:e4a10ed6eb92 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
jbradshaw 0:e4a10ed6eb92 20 * OTHER DEALINGS IN THE SOFTWARE.
jbradshaw 0:e4a10ed6eb92 21 *
jbradshaw 0:e4a10ed6eb92 22 * Except as contained in this notice, the name of Maxim Integrated
jbradshaw 0:e4a10ed6eb92 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
jbradshaw 0:e4a10ed6eb92 24 * Products, Inc. Branding Policy.
jbradshaw 0:e4a10ed6eb92 25 *
jbradshaw 0:e4a10ed6eb92 26 * The mere transfer of this software does not imply any licenses
jbradshaw 0:e4a10ed6eb92 27 * of trade secrets, proprietary technology, copyrights, patents,
jbradshaw 0:e4a10ed6eb92 28 * trademarks, maskwork rights, or any other form of intellectual
jbradshaw 0:e4a10ed6eb92 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
jbradshaw 0:e4a10ed6eb92 30 * ownership rights.
jbradshaw 0:e4a10ed6eb92 31 *******************************************************************************
jbradshaw 0:e4a10ed6eb92 32 */
jbradshaw 0:e4a10ed6eb92 33 #include "HspBLE.h"
jbradshaw 0:e4a10ed6eb92 34 #include "Peripherals.h"
jbradshaw 0:e4a10ed6eb92 35 #include "MAX30001_helper.h"
jbradshaw 0:e4a10ed6eb92 36
jbradshaw 0:e4a10ed6eb92 37 #define LOW_BYTE(x) ((uint8_t)((x)&0xFF))
jbradshaw 0:e4a10ed6eb92 38 #define HIGH_BYTE(x) ((uint8_t)(((x) >> 8) & 0xFF))
jbradshaw 0:e4a10ed6eb92 39
jbradshaw 0:e4a10ed6eb92 40 /// define all of the characteristic UUIDs
jbradshaw 0:e4a10ed6eb92 41 uint8_t HspBLE::temperatureTopCharUUID[] = {0x35,0x44,0x53,0x1b,0x00,0xc3,0x43,0x42,0x97,0x55,0xb5,0x6a,0xbe,0x8e,0x6c,0x67};
jbradshaw 0:e4a10ed6eb92 42 uint8_t HspBLE::temperatureBottomCharUUID[] = {0x35,0x44,0x53,0x1b,0x00,0xc3,0x43,0x42,0x97,0x55,0xb5,0x6a,0xbe,0x8e,0x6a,0x66};
jbradshaw 0:e4a10ed6eb92 43 uint8_t HspBLE::accelerometerCharUUID[] = {0xe6,0xc9,0xda,0x1a,0x80,0x96,0x48,0xbc,0x83,0xa4,0x3f,0xca,0x38,0x37,0x05,0xaf};
jbradshaw 0:e4a10ed6eb92 44 uint8_t HspBLE::heartrateCharUUID[] = {0x62,0x1a,0x00,0xe3,0xb0,0x93,0x46,0xbf,0xaa,0xdc,0xab,0xe4,0xc6,0x48,0xc5,0x69};
jbradshaw 0:e4a10ed6eb92 45 uint8_t HspBLE::pressureCharUUID[] = {0x1d,0x8a,0x19,0x32,0xda,0x49,0x49,0xad,0x91,0xd8,0x80,0x08,0x32,0xe7,0xe9,0x40};
jbradshaw 0:e4a10ed6eb92 46 uint8_t HspBLE::dataCharUUID[] = {0xaa,0x8a,0x19,0x32,0xda,0x49,0x49,0xad,0x91,0xd8,0x80,0x08,0x32,0xe7,0xe9,0x40};
jbradshaw 0:e4a10ed6eb92 47 uint8_t HspBLE::commandCharUUID[] = {0x36,0xe5,0x5e,0x37,0x6b,0x5b,0x42,0x0b,0x91,0x07,0x0d,0x34,0xa0,0xe8,0x67,0x5a};
jbradshaw 0:e4a10ed6eb92 48
jbradshaw 0:e4a10ed6eb92 49
jbradshaw 0:e4a10ed6eb92 50 /// define the BLE device name
jbradshaw 0:e4a10ed6eb92 51 uint8_t HspBLE::deviceName[] = "MAXREFDES100";
jbradshaw 0:e4a10ed6eb92 52 /// define the BLE serial number
jbradshaw 0:e4a10ed6eb92 53 uint8_t HspBLE::serialNumber[] = {0x77, 0x22, 0x33, 0x45, 0x67, 0x89};
jbradshaw 0:e4a10ed6eb92 54 /// define the BLE service UUID
jbradshaw 0:e4a10ed6eb92 55 uint8_t HspBLE::envServiceUUID[] = {0x5c,0x6e,0x40,0xe8,0x3b,0x7f,0x42,0x86,0xa5,0x2f,0xda,0xec,0x46,0xab,0xe8,0x51};
jbradshaw 0:e4a10ed6eb92 56
jbradshaw 0:e4a10ed6eb92 57 HspBLE *HspBLE::instance = NULL;
jbradshaw 0:e4a10ed6eb92 58
jbradshaw 0:e4a10ed6eb92 59 /**
jbradshaw 0:e4a10ed6eb92 60 * @brief Constructor that inits the BLE helper object
jbradshaw 0:e4a10ed6eb92 61 * @param ble Pointer to the mbed BLE object
jbradshaw 0:e4a10ed6eb92 62 */
jbradshaw 0:e4a10ed6eb92 63 HspBLE::HspBLE(BLE *ble) {
jbradshaw 0:e4a10ed6eb92 64 bluetoothLE = new BluetoothLE(ble, NUMBER_OF_CHARACTERISTICS);
jbradshaw 0:e4a10ed6eb92 65 instance = this;
jbradshaw 0:e4a10ed6eb92 66 notificationUpdateRoundRobin = 0;
jbradshaw 0:e4a10ed6eb92 67 }
jbradshaw 0:e4a10ed6eb92 68
jbradshaw 0:e4a10ed6eb92 69 /**
jbradshaw 0:e4a10ed6eb92 70 * @brief Constructor that deletes the bluetoothLE object
jbradshaw 0:e4a10ed6eb92 71 */
jbradshaw 0:e4a10ed6eb92 72 HspBLE::~HspBLE(void) { delete bluetoothLE; }
jbradshaw 0:e4a10ed6eb92 73
jbradshaw 0:e4a10ed6eb92 74 /**
jbradshaw 0:e4a10ed6eb92 75 * @brief Initialize all of the HSP characteristics, initialize the ble service
jbradshaw 0:e4a10ed6eb92 76 * and attach callbacks
jbradshaw 0:e4a10ed6eb92 77 */
jbradshaw 0:e4a10ed6eb92 78 void HspBLE::init(void) {
jbradshaw 0:e4a10ed6eb92 79 uint8_t *serialNumberPtr;
jbradshaw 0:e4a10ed6eb92 80 // uint8_t serialNumberBuffer[6];
jbradshaw 0:e4a10ed6eb92 81 serialNumberPtr = MAX30001_Helper_getVersion();
jbradshaw 0:e4a10ed6eb92 82 printf("MAX30001 Version = %02X:%02X:%02X:%02X:%02X:%02X...\n",
jbradshaw 0:e4a10ed6eb92 83 serialNumberPtr[0], serialNumberPtr[1], serialNumberPtr[2],
jbradshaw 0:e4a10ed6eb92 84 serialNumberPtr[3], serialNumberPtr[4], serialNumberPtr[5]);
jbradshaw 0:e4a10ed6eb92 85 serialNumberPtr[3] = 0x00;
jbradshaw 0:e4a10ed6eb92 86 serialNumberPtr[4] = 0x00;
jbradshaw 0:e4a10ed6eb92 87 serialNumberPtr[5] = 0x03;
jbradshaw 0:e4a10ed6eb92 88 printf("BLE DeviceID = %02X:%02X:%02X:%02X:%02X:%02X...\n",
jbradshaw 0:e4a10ed6eb92 89 serialNumberPtr[0], serialNumberPtr[1], serialNumberPtr[2],
jbradshaw 0:e4a10ed6eb92 90 serialNumberPtr[3], serialNumberPtr[4], serialNumberPtr[5]);
jbradshaw 0:e4a10ed6eb92 91
jbradshaw 0:e4a10ed6eb92 92 bluetoothLE->addCharacteristic(new Characteristic(2 /* number of bytes */,temperatureTopCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY));
jbradshaw 0:e4a10ed6eb92 93 bluetoothLE->addCharacteristic(new Characteristic(2 /* number of bytes */,temperatureBottomCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY));
jbradshaw 0:e4a10ed6eb92 94 bluetoothLE->addCharacteristic(new Characteristic(6 /* number of bytes */,accelerometerCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY));
jbradshaw 0:e4a10ed6eb92 95 bluetoothLE->addCharacteristic(new Characteristic(4 /* number of bytes */,heartrateCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY));
jbradshaw 0:e4a10ed6eb92 96 bluetoothLE->addCharacteristic(new Characteristic(8 /* number of bytes */,pressureCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY));
jbradshaw 0:e4a10ed6eb92 97 bluetoothLE->addCharacteristic(new Characteristic(32 /* number of bytes */,dataCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE));
jbradshaw 0:e4a10ed6eb92 98 bluetoothLE->addCharacteristic(new Characteristic(1 /* number of bytes */,commandCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE));
jbradshaw 0:e4a10ed6eb92 99 bluetoothLE->initService(serialNumberPtr, deviceName, sizeof(deviceName),envServiceUUID);
jbradshaw 0:e4a10ed6eb92 100
jbradshaw 0:e4a10ed6eb92 101 bluetoothLE->onDataWritten(&HspBLE::_onDataWritten);
jbradshaw 1:9490836294ea 102 ticker.attach(callback(this, &HspBLE::tickerHandler), 1);
jbradshaw 0:e4a10ed6eb92 103 }
jbradshaw 0:e4a10ed6eb92 104
jbradshaw 0:e4a10ed6eb92 105 void HspBLE::_onDataWritten(int index) {
jbradshaw 0:e4a10ed6eb92 106 HspBLE::instance->onDataWritten(index);
jbradshaw 0:e4a10ed6eb92 107 }
jbradshaw 0:e4a10ed6eb92 108
jbradshaw 0:e4a10ed6eb92 109 /**
jbradshaw 0:e4a10ed6eb92 110 * @brief Callback for written characteristics
jbradshaw 0:e4a10ed6eb92 111 * @param index Index of whose characteristic is written to
jbradshaw 0:e4a10ed6eb92 112 */
jbradshaw 0:e4a10ed6eb92 113 void HspBLE::onDataWritten(int index) {
jbradshaw 0:e4a10ed6eb92 114 int length;
jbradshaw 0:e4a10ed6eb92 115 uint8_t *data;
jbradshaw 0:e4a10ed6eb92 116 printf("onDataWritten ");
jbradshaw 0:e4a10ed6eb92 117 if (index == CHARACTERISTIC_CMD) {
jbradshaw 0:e4a10ed6eb92 118 data = bluetoothLE->getDataWritten(index, &length);
jbradshaw 0:e4a10ed6eb92 119 if (length >= 1) {
jbradshaw 0:e4a10ed6eb92 120 if (data[0] == 0x00) startDataLogging = false;
jbradshaw 0:e4a10ed6eb92 121 if (data[0] == 0x01) startDataLogging = true;
jbradshaw 0:e4a10ed6eb92 122 printf("onDataWritten index %d, data %02X, length %d ",index,data[0],length); fflush(stdout);
jbradshaw 0:e4a10ed6eb92 123
jbradshaw 0:e4a10ed6eb92 124 }
jbradshaw 0:e4a10ed6eb92 125 }
jbradshaw 0:e4a10ed6eb92 126 }
jbradshaw 0:e4a10ed6eb92 127
jbradshaw 0:e4a10ed6eb92 128 void HspBLE::pollSensor(int sensorId, uint8_t *data) {
jbradshaw 0:e4a10ed6eb92 129
jbradshaw 0:e4a10ed6eb92 130 switch (sensorId) {
jbradshaw 0:e4a10ed6eb92 131 case CHARACTERISTIC_TEMP_TOP: {
jbradshaw 0:e4a10ed6eb92 132 uint16_t uShort;
jbradshaw 0:e4a10ed6eb92 133 Peripherals::max30205_top()->readTemperature(&uShort);
jbradshaw 0:e4a10ed6eb92 134 data[0] = HIGH_BYTE(uShort);
jbradshaw 0:e4a10ed6eb92 135 data[1] = LOW_BYTE(uShort);
jbradshaw 0:e4a10ed6eb92 136 } break;
jbradshaw 0:e4a10ed6eb92 137 case CHARACTERISTIC_TEMP_BOTTOM: {
jbradshaw 0:e4a10ed6eb92 138 uint16_t uShort;
jbradshaw 0:e4a10ed6eb92 139 Peripherals::max30205_bottom()->readTemperature(&uShort);
jbradshaw 0:e4a10ed6eb92 140 data[0] = HIGH_BYTE(uShort);
jbradshaw 0:e4a10ed6eb92 141 data[1] = LOW_BYTE(uShort);
jbradshaw 0:e4a10ed6eb92 142 } break;
jbradshaw 0:e4a10ed6eb92 143 case CHARACTERISTIC_ACCELEROMETER: {
jbradshaw 1:9490836294ea 144 unsigned int i;
jbradshaw 0:e4a10ed6eb92 145 uint8_t *bytePtr;
jbradshaw 0:e4a10ed6eb92 146 int16_t acclPtr[3];
jbradshaw 0:e4a10ed6eb92 147 Peripherals::lis2dh()->get_motion_cached(&acclPtr[0], &acclPtr[1],
jbradshaw 0:e4a10ed6eb92 148 &acclPtr[2]);
jbradshaw 0:e4a10ed6eb92 149 bytePtr = reinterpret_cast<uint8_t *>(&acclPtr);
jbradshaw 0:e4a10ed6eb92 150 for (i = 0; i < sizeof(acclPtr); i++)
jbradshaw 0:e4a10ed6eb92 151 data[i] = bytePtr[i];
jbradshaw 0:e4a10ed6eb92 152 } break;
jbradshaw 0:e4a10ed6eb92 153 case CHARACTERISTIC_PRESSURE: {
jbradshaw 1:9490836294ea 154 unsigned int i;
jbradshaw 0:e4a10ed6eb92 155 uint8_t *bytePtr;
jbradshaw 0:e4a10ed6eb92 156 float temperature;
jbradshaw 0:e4a10ed6eb92 157 float pressure;
jbradshaw 0:e4a10ed6eb92 158 Peripherals::bmp280()->ReadCompData(&temperature, &pressure);
jbradshaw 0:e4a10ed6eb92 159 bytePtr = reinterpret_cast<uint8_t *>(&temperature);
jbradshaw 0:e4a10ed6eb92 160 for (i = 0; i < sizeof(float); i++)
jbradshaw 0:e4a10ed6eb92 161 data[i] = bytePtr[i];
jbradshaw 0:e4a10ed6eb92 162 bytePtr = reinterpret_cast<uint8_t *>(&pressure);
jbradshaw 0:e4a10ed6eb92 163 for (i = 0; i < sizeof(float); i++)
jbradshaw 0:e4a10ed6eb92 164 data[i + sizeof(float)] = bytePtr[i];
jbradshaw 0:e4a10ed6eb92 165 } break;
jbradshaw 0:e4a10ed6eb92 166 case CHARACTERISTIC_HEARTRATE: {
jbradshaw 1:9490836294ea 167 unsigned int i;
jbradshaw 0:e4a10ed6eb92 168 uint8_t *bytePtr;
jbradshaw 1:9490836294ea 169 MAX30001::max30001_bledata_t heartrateData;
jbradshaw 1:9490836294ea 170 Peripherals::max30001()->ReadHeartrateData(&heartrateData);
jbradshaw 0:e4a10ed6eb92 171 bytePtr = reinterpret_cast<uint8_t *>(&heartrateData);
jbradshaw 1:9490836294ea 172 for (i = 0; i < sizeof(MAX30001::max30001_bledata_t); i++)
jbradshaw 0:e4a10ed6eb92 173 data[i] = bytePtr[i];
jbradshaw 0:e4a10ed6eb92 174 } break;
jbradshaw 0:e4a10ed6eb92 175 }
jbradshaw 0:e4a10ed6eb92 176 }
jbradshaw 0:e4a10ed6eb92 177
jbradshaw 0:e4a10ed6eb92 178 bool HspBLE::getStartDataLogging(void) { return startDataLogging; }
jbradshaw 0:e4a10ed6eb92 179
jbradshaw 0:e4a10ed6eb92 180 /**
jbradshaw 0:e4a10ed6eb92 181 * @brief Timer Callback that updates all sensor characteristic notifications
jbradshaw 0:e4a10ed6eb92 182 */
jbradshaw 0:e4a10ed6eb92 183 void HspBLE::tickerHandler(void) {
jbradshaw 0:e4a10ed6eb92 184 uint8_t data[8];
jbradshaw 0:e4a10ed6eb92 185 if (bluetoothLE->isConnected()) {
jbradshaw 0:e4a10ed6eb92 186 pollSensor(CHARACTERISTIC_TEMP_TOP, data);
jbradshaw 0:e4a10ed6eb92 187 bluetoothLE->notifyCharacteristic(CHARACTERISTIC_TEMP_TOP, data);
jbradshaw 0:e4a10ed6eb92 188 pollSensor(CHARACTERISTIC_TEMP_BOTTOM, data);
jbradshaw 0:e4a10ed6eb92 189 bluetoothLE->notifyCharacteristic(CHARACTERISTIC_TEMP_BOTTOM, data);
jbradshaw 0:e4a10ed6eb92 190 pollSensor(CHARACTERISTIC_ACCELEROMETER, data);
jbradshaw 0:e4a10ed6eb92 191 bluetoothLE->notifyCharacteristic(CHARACTERISTIC_ACCELEROMETER, data);
jbradshaw 0:e4a10ed6eb92 192 pollSensor(CHARACTERISTIC_HEARTRATE, data);
jbradshaw 0:e4a10ed6eb92 193 bluetoothLE->notifyCharacteristic(CHARACTERISTIC_HEARTRATE, data);
jbradshaw 0:e4a10ed6eb92 194 pollSensor(CHARACTERISTIC_PRESSURE, data);
jbradshaw 0:e4a10ed6eb92 195 bluetoothLE->notifyCharacteristic(CHARACTERISTIC_PRESSURE, data);
jbradshaw 0:e4a10ed6eb92 196 }
jbradshaw 0:e4a10ed6eb92 197 }