This is the latest working repository used in our demo video for the Maxim to display temperature readings on Bluetooth

Dependencies:   USBDevice

Committer:
darienf
Date:
Sun May 02 23:09:04 2021 +0000
Revision:
5:bc128a16232f
Parent:
3:36de8b9e4b1a
This is the program that was last used, that has the working temperature and some comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
darienf 3:36de8b9e4b1a 1 /*******************************************************************************
darienf 3:36de8b9e4b1a 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
darienf 3:36de8b9e4b1a 3 *
darienf 3:36de8b9e4b1a 4 * Permission is hereby granted, free of charge, to any person obtaining a
darienf 3:36de8b9e4b1a 5 * copy of this software and associated documentation files (the "Software"),
darienf 3:36de8b9e4b1a 6 * to deal in the Software without restriction, including without limitation
darienf 3:36de8b9e4b1a 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
darienf 3:36de8b9e4b1a 8 * and/or sell copies of the Software, and to permit persons to whom the
darienf 3:36de8b9e4b1a 9 * Software is furnished to do so, subject to the following conditions:
darienf 3:36de8b9e4b1a 10 *
darienf 3:36de8b9e4b1a 11 * The above copyright notice and this permission notice shall be included
darienf 3:36de8b9e4b1a 12 * in all copies or substantial portions of the Software.
darienf 3:36de8b9e4b1a 13 *
darienf 3:36de8b9e4b1a 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
darienf 3:36de8b9e4b1a 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
darienf 3:36de8b9e4b1a 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
darienf 3:36de8b9e4b1a 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
darienf 3:36de8b9e4b1a 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
darienf 3:36de8b9e4b1a 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
darienf 3:36de8b9e4b1a 20 * OTHER DEALINGS IN THE SOFTWARE.
darienf 3:36de8b9e4b1a 21 *
darienf 3:36de8b9e4b1a 22 * Except as contained in this notice, the name of Maxim Integrated
darienf 3:36de8b9e4b1a 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
darienf 3:36de8b9e4b1a 24 * Products, Inc. Branding Policy.
darienf 3:36de8b9e4b1a 25 *
darienf 3:36de8b9e4b1a 26 * The mere transfer of this software does not imply any licenses
darienf 3:36de8b9e4b1a 27 * of trade secrets, proprietary technology, copyrights, patents,
darienf 3:36de8b9e4b1a 28 * trademarks, maskwork rights, or any other form of intellectual
darienf 3:36de8b9e4b1a 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
darienf 3:36de8b9e4b1a 30 * ownership rights.
darienf 3:36de8b9e4b1a 31 *******************************************************************************
darienf 3:36de8b9e4b1a 32 */
darienf 3:36de8b9e4b1a 33 #include "mbed.h"
darienf 3:36de8b9e4b1a 34 #include "MAX14720.h"
darienf 3:36de8b9e4b1a 35 #include "MAX30101.h"
darienf 3:36de8b9e4b1a 36 #include "MAX30205.h"
darienf 3:36de8b9e4b1a 37 #include "LIS2DH.h"
darienf 3:36de8b9e4b1a 38 #include "USBSerial.h"
darienf 3:36de8b9e4b1a 39 #include "RpcServer.h"
darienf 3:36de8b9e4b1a 40 #include "StringInOut.h"
darienf 3:36de8b9e4b1a 41 #include "Peripherals.h"
darienf 3:36de8b9e4b1a 42 #include "BMP280.h"
darienf 3:36de8b9e4b1a 43 #include "MAX30001.h"
darienf 3:36de8b9e4b1a 44 #include "DataLoggingService.h"
darienf 3:36de8b9e4b1a 45 #include "MAX30101_helper.h"
darienf 3:36de8b9e4b1a 46 #include "S25FS512.h"
darienf 3:36de8b9e4b1a 47 #include "QuadSpiInterface.h"
darienf 3:36de8b9e4b1a 48 #include "PushButton.h"
darienf 3:36de8b9e4b1a 49 #include "BLE.h"
darienf 3:36de8b9e4b1a 50 #include "HspBLE.h"
darienf 3:36de8b9e4b1a 51 #include "USBSerial.h"
darienf 3:36de8b9e4b1a 52 #include "Streaming.h"
darienf 3:36de8b9e4b1a 53
darienf 3:36de8b9e4b1a 54 /// define the HVOUT Boost Voltage default for the MAX14720 PMIC
darienf 3:36de8b9e4b1a 55 #define HVOUT_VOLTAGE 4500 // set to 4500 mV
darienf 3:36de8b9e4b1a 56
darienf 3:36de8b9e4b1a 57 /// define all I2C addresses
darienf 3:36de8b9e4b1a 58 #define MAX30205_I2C_SLAVE_ADDR_TOP (0x92)
darienf 3:36de8b9e4b1a 59 #define MAX30205_I2C_SLAVE_ADDR_BOTTOM (0x90)
darienf 3:36de8b9e4b1a 60 #define MAX14720_I2C_SLAVE_ADDR (0x54)
darienf 3:36de8b9e4b1a 61 #define BMP280_I2C_SLAVE_ADDR (0xEC)
darienf 3:36de8b9e4b1a 62 #define MAX30101_I2C_SLAVE_ADDR (0xAE)
darienf 3:36de8b9e4b1a 63 #define LIS2DH_I2C_SLAVE_ADDR (0x32)
darienf 3:36de8b9e4b1a 64
darienf 3:36de8b9e4b1a 65 ///
darienf 3:36de8b9e4b1a 66 /// wire Interfaces
darienf 3:36de8b9e4b1a 67 ///
darienf 3:36de8b9e4b1a 68 /// Define with Maxim VID and a Maxim assigned PID, set to version 0x0001 and non-blocking
darienf 3:36de8b9e4b1a 69 USBSerial usbSerial(0x0b6a, 0x0100, 0x0001, false);
darienf 3:36de8b9e4b1a 70 /// I2C Master 1
darienf 3:36de8b9e4b1a 71 I2C i2c1(I2C1_SDA, I2C1_SCL); // used by MAX30205 (1), MAX30205 (2), BMP280
darienf 3:36de8b9e4b1a 72 /// I2C Master 2
darienf 3:36de8b9e4b1a 73 I2C i2c2(I2C2_SDA, I2C2_SCL); // used by MAX14720, MAX30101, LIS2DH
darienf 3:36de8b9e4b1a 74 /// SPI Master 0 with SPI0_SS for use with MAX30001
darienf 3:36de8b9e4b1a 75 SPI spi(SPI0_MOSI, SPI0_MISO, SPI0_SCK, SPI0_SS); // used by MAX30001
darienf 3:36de8b9e4b1a 76 /// SPI Master 1
darienf 3:36de8b9e4b1a 77 QuadSpiInterface quadSpiInterface(SPI1_MOSI, SPI1_MISO, SPI1_SCK,
darienf 3:36de8b9e4b1a 78 SPI1_SS); // used by S25FS512
darienf 3:36de8b9e4b1a 79
darienf 3:36de8b9e4b1a 80 ///
darienf 3:36de8b9e4b1a 81 /// Devices
darienf 3:36de8b9e4b1a 82 ///
darienf 3:36de8b9e4b1a 83 /// Pressure Sensor
darienf 3:36de8b9e4b1a 84 BMP280 bmp280(&i2c1, BMP280_I2C_SLAVE_ADDR);
darienf 3:36de8b9e4b1a 85 /// Top Local Temperature Sensor
darienf 3:36de8b9e4b1a 86 MAX30205 MAX30205_top(&i2c1, MAX30205_I2C_SLAVE_ADDR_TOP);
darienf 3:36de8b9e4b1a 87 /// Bottom Local Temperature Sensor
darienf 3:36de8b9e4b1a 88 MAX30205 MAX30205_bottom(&i2c1, MAX30205_I2C_SLAVE_ADDR_BOTTOM);
darienf 3:36de8b9e4b1a 89 /// Accelerometer
darienf 3:36de8b9e4b1a 90 LIS2DH lis2dh(&i2c2, LIS2DH_I2C_SLAVE_ADDR);
darienf 3:36de8b9e4b1a 91 InterruptIn lis2dh_Interrupt(P4_7);
darienf 3:36de8b9e4b1a 92 /// PMIC
darienf 3:36de8b9e4b1a 93 MAX14720 max14720(&i2c2, MAX14720_I2C_SLAVE_ADDR);
darienf 3:36de8b9e4b1a 94 /// Optical Oximeter
darienf 3:36de8b9e4b1a 95 MAX30101 max30101(&i2c2, MAX30101_I2C_SLAVE_ADDR);
darienf 3:36de8b9e4b1a 96 InterruptIn max30101_Interrupt(P4_0);
darienf 3:36de8b9e4b1a 97 /// External Flash
darienf 3:36de8b9e4b1a 98 S25FS512 s25fs512(&quadSpiInterface);
darienf 3:36de8b9e4b1a 99 /// ECG device
darienf 3:36de8b9e4b1a 100 MAX30001 max30001(&spi);
darienf 3:36de8b9e4b1a 101 InterruptIn max30001_InterruptB(P3_6);
darienf 3:36de8b9e4b1a 102 InterruptIn max30001_Interrupt2B(P4_5);
darienf 3:36de8b9e4b1a 103 /// PWM used as fclk for the MAX30001
darienf 3:36de8b9e4b1a 104 PwmOut pwmout(P1_7);
darienf 3:36de8b9e4b1a 105 /// HSP platform LED
darienf 3:36de8b9e4b1a 106 HspLed hspLed(LED_RED);
darienf 3:36de8b9e4b1a 107 /// Packet TimeStamp Timer, set for 1uS
darienf 3:36de8b9e4b1a 108 Timer timestampTimer;
darienf 3:36de8b9e4b1a 109 /// HSP Platform push button
darienf 3:36de8b9e4b1a 110 PushButton pushButton(SW1);
darienf 3:36de8b9e4b1a 111
darienf 3:36de8b9e4b1a 112 /// BLE instance
darienf 3:36de8b9e4b1a 113 static BLE ble;
darienf 3:36de8b9e4b1a 114
darienf 3:36de8b9e4b1a 115 /// HSP BluetoothLE specific functions
darienf 3:36de8b9e4b1a 116 HspBLE hspBLE(&ble);
darienf 3:36de8b9e4b1a 117
darienf 3:36de8b9e4b1a 118 int main() {
darienf 3:36de8b9e4b1a 119 // hold results for returning funtcoins
darienf 3:36de8b9e4b1a 120 int result;
darienf 3:36de8b9e4b1a 121 // local input state of the RPC
darienf 3:36de8b9e4b1a 122 int inputState;
darienf 3:36de8b9e4b1a 123 // RPC request buffer
darienf 3:36de8b9e4b1a 124 char request[128];
darienf 3:36de8b9e4b1a 125 // RPC reply buffer
darienf 3:36de8b9e4b1a 126 char reply[128];
darienf 3:36de8b9e4b1a 127
darienf 3:36de8b9e4b1a 128 // display start banner
darienf 3:36de8b9e4b1a 129 printf("Maxim Integrated mbed hSensor 3.0.0 10/14/16\n");
darienf 3:36de8b9e4b1a 130 fflush(stdout);
darienf 3:36de8b9e4b1a 131
darienf 3:36de8b9e4b1a 132 // initialize HVOUT on the MAX14720 PMIC
darienf 3:36de8b9e4b1a 133 printf("Init MAX14720...\n");
darienf 3:36de8b9e4b1a 134 fflush(stdout);
darienf 3:36de8b9e4b1a 135 result = max14720.init();
darienf 3:36de8b9e4b1a 136 if (result == MAX14720_ERROR)
darienf 3:36de8b9e4b1a 137 printf("Error initializing MAX14720");
darienf 3:36de8b9e4b1a 138 max14720.boostEn = MAX14720::BOOST_ENABLED;
darienf 3:36de8b9e4b1a 139 max14720.boostSetVoltage(HVOUT_VOLTAGE);
darienf 3:36de8b9e4b1a 140
darienf 3:36de8b9e4b1a 141 // turn on red led
darienf 3:36de8b9e4b1a 142 printf("Init HSPLED...\n");
darienf 3:36de8b9e4b1a 143 fflush(stdout);
darienf 3:36de8b9e4b1a 144 hspLed.on();
darienf 3:36de8b9e4b1a 145
darienf 3:36de8b9e4b1a 146 // set NVIC priorities for GPIO to prevent priority inversion
darienf 3:36de8b9e4b1a 147 printf("Init NVIC Priorities...\n");
darienf 3:36de8b9e4b1a 148 fflush(stdout);
darienf 3:36de8b9e4b1a 149 NVIC_SetPriority(GPIO_P0_IRQn, 5);
darienf 3:36de8b9e4b1a 150 NVIC_SetPriority(GPIO_P1_IRQn, 5);
darienf 3:36de8b9e4b1a 151 NVIC_SetPriority(GPIO_P2_IRQn, 5);
darienf 3:36de8b9e4b1a 152 NVIC_SetPriority(GPIO_P3_IRQn, 5);
darienf 3:36de8b9e4b1a 153 NVIC_SetPriority(GPIO_P4_IRQn, 5);
darienf 3:36de8b9e4b1a 154 NVIC_SetPriority(GPIO_P5_IRQn, 5);
darienf 3:36de8b9e4b1a 155 NVIC_SetPriority(GPIO_P6_IRQn, 5);
darienf 3:36de8b9e4b1a 156 // used by the MAX30001
darienf 3:36de8b9e4b1a 157 NVIC_SetPriority(SPI1_IRQn, 0);
darienf 3:36de8b9e4b1a 158
darienf 3:36de8b9e4b1a 159 // Be able to statically reference these devices anywhere in the application
darienf 3:36de8b9e4b1a 160 Peripherals::setS25FS512(&s25fs512);
darienf 3:36de8b9e4b1a 161 Peripherals::setMAX30205_top(&MAX30205_top);
darienf 3:36de8b9e4b1a 162 Peripherals::setMAX30205_bottom(&MAX30205_bottom);
darienf 3:36de8b9e4b1a 163 Peripherals::setBMP280(&bmp280);
darienf 3:36de8b9e4b1a 164 Peripherals::setLIS2DH(&lis2dh);
darienf 3:36de8b9e4b1a 165 Peripherals::setUSBSerial(&usbSerial);
darienf 3:36de8b9e4b1a 166 Peripherals::setTimestampTimer(&timestampTimer);
darienf 3:36de8b9e4b1a 167 Peripherals::setHspLed(&hspLed);
darienf 3:36de8b9e4b1a 168 Peripherals::setMAX30101(&max30101);
darienf 3:36de8b9e4b1a 169 Peripherals::setI2c1(&i2c1);
darienf 3:36de8b9e4b1a 170 Peripherals::setI2c2(&i2c2);
darienf 3:36de8b9e4b1a 171 Peripherals::setPushButton(&pushButton);
darienf 3:36de8b9e4b1a 172 Peripherals::setBLE(&ble);
darienf 3:36de8b9e4b1a 173 Peripherals::setMAX14720(&max14720);
darienf 3:36de8b9e4b1a 174 Peripherals::setMAX30001(&max30001);
darienf 3:36de8b9e4b1a 175 Peripherals::setHspBLE(&hspBLE);
darienf 3:36de8b9e4b1a 176
darienf 3:36de8b9e4b1a 177 // init the S25FS256 external flash device
darienf 3:36de8b9e4b1a 178 printf("Init S25FS512...\n");
darienf 3:36de8b9e4b1a 179 fflush(stdout);
darienf 3:36de8b9e4b1a 180 s25fs512.init();
darienf 3:36de8b9e4b1a 181
darienf 3:36de8b9e4b1a 182 // init the BMP280
darienf 3:36de8b9e4b1a 183 printf("Init BMP280...\n");
darienf 3:36de8b9e4b1a 184 fflush(stdout);
darienf 3:36de8b9e4b1a 185 bmp280.init(BMP280::OVERSAMPLING_X2_P, BMP280::OVERSAMPLING_X1_T,
darienf 3:36de8b9e4b1a 186 BMP280::FILT_OFF, BMP280::NORMAL_MODE, BMP280::T_62_5);
darienf 3:36de8b9e4b1a 187
darienf 3:36de8b9e4b1a 188 // Initialize BLE base layer
darienf 3:36de8b9e4b1a 189 printf("Init HSPBLE...\n");
darienf 3:36de8b9e4b1a 190 fflush(stdout);
darienf 3:36de8b9e4b1a 191 hspBLE.init();
darienf 3:36de8b9e4b1a 192
darienf 3:36de8b9e4b1a 193 // start blinking led1
darienf 3:36de8b9e4b1a 194 printf("Init HSPLED Blink...\n");
darienf 3:36de8b9e4b1a 195 fflush(stdout);
darienf 3:36de8b9e4b1a 196 hspLed.blink(1000);
darienf 3:36de8b9e4b1a 197
darienf 3:36de8b9e4b1a 198 // MAX30101 initialize interrupt
darienf 3:36de8b9e4b1a 199 printf("Init MAX30101 callbacks, interrupt...\n");
darienf 3:36de8b9e4b1a 200 fflush(stdout);
darienf 3:36de8b9e4b1a 201 max30101.onInterrupt(&MAX30101_OnInterrupt);
darienf 3:36de8b9e4b1a 202 max30101.onDataAvailable(&StreamPacketUint32);
darienf 3:36de8b9e4b1a 203 max30101_Interrupt.fall(&MAX30101MidIntHandler);
darienf 3:36de8b9e4b1a 204
darienf 3:36de8b9e4b1a 205 //
darienf 3:36de8b9e4b1a 206 // MAX30001
darienf 3:36de8b9e4b1a 207 //
darienf 3:36de8b9e4b1a 208 printf("Init MAX30001 callbacks, interrupts...\n");
darienf 3:36de8b9e4b1a 209 fflush(stdout);
darienf 3:36de8b9e4b1a 210 max30001_InterruptB.disable_irq();
darienf 3:36de8b9e4b1a 211 max30001_Interrupt2B.disable_irq();
darienf 3:36de8b9e4b1a 212 max30001_InterruptB.mode(PullUp);
darienf 3:36de8b9e4b1a 213 max30001_InterruptB.fall(&MAX30001Mid_IntB_Handler);
darienf 3:36de8b9e4b1a 214 max30001_Interrupt2B.mode(PullUp);
darienf 3:36de8b9e4b1a 215 max30001_Interrupt2B.fall(&MAX30001Mid_Int2B_Handler);
darienf 3:36de8b9e4b1a 216 max30001_InterruptB.enable_irq();
darienf 3:36de8b9e4b1a 217 max30001_Interrupt2B.enable_irq();
darienf 3:36de8b9e4b1a 218 MAX30001_AllowInterrupts(1);
darienf 3:36de8b9e4b1a 219 // Configuring the FCLK for the ECG, set to 32.768KHZ
darienf 3:36de8b9e4b1a 220 printf("Init MAX30001 PWM...\n");
darienf 3:36de8b9e4b1a 221 fflush(stdout);
darienf 3:36de8b9e4b1a 222 pwmout.period_us(31);
darienf 3:36de8b9e4b1a 223 pwmout.write(0.5); // 0-1 is 0-100%, 0.5 = 50% duty cycle.
darienf 3:36de8b9e4b1a 224 max30001.max30001_sw_rst(); // Do a software reset of the MAX30001
darienf 3:36de8b9e4b1a 225 max30001.max30001_INT_assignment(MAX30001::MAX30001_INT_B, MAX30001::MAX30001_NO_INT, MAX30001::MAX30001_NO_INT, // en_enint_loc, en_eovf_loc, en_fstint_loc,
darienf 3:36de8b9e4b1a 226 MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_NO_INT, // en_dcloffint_loc, en_bint_loc, en_bovf_loc,
darienf 3:36de8b9e4b1a 227 MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_NO_INT, // en_bover_loc, en_bundr_loc, en_bcgmon_loc,
darienf 3:36de8b9e4b1a 228 MAX30001::MAX30001_INT_B, MAX30001::MAX30001_NO_INT, MAX30001::MAX30001_NO_INT, // en_pint_loc, en_povf_loc, en_pedge_loc,
darienf 3:36de8b9e4b1a 229 MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_INT_B, MAX30001::MAX30001_NO_INT, // en_lonint_loc, en_rrint_loc, en_samp_loc,
darienf 3:36de8b9e4b1a 230 MAX30001::MAX30001_INT_ODNR, MAX30001::MAX30001_INT_ODNR); // intb_Type, int2b_Type)
darienf 3:36de8b9e4b1a 231 max30001.onDataAvailable(&StreamPacketUint32);
darienf 3:36de8b9e4b1a 232
darienf 3:36de8b9e4b1a 233 // initialize the LIS2DH accelerometer and interrupts
darienf 3:36de8b9e4b1a 234 printf("Init LIS2DH interrupt...\n");
darienf 3:36de8b9e4b1a 235 fflush(stdout);
darienf 3:36de8b9e4b1a 236 lis2dh.init();
darienf 3:36de8b9e4b1a 237 lis2dh_Interrupt.fall(&LIS2DHIntHandler);
darienf 3:36de8b9e4b1a 238 lis2dh_Interrupt.mode(PullUp);
darienf 3:36de8b9e4b1a 239 // initialize the RPC server
darienf 3:36de8b9e4b1a 240 printf("Init RPC Server...\n");
darienf 3:36de8b9e4b1a 241 fflush(stdout);
darienf 3:36de8b9e4b1a 242 RPC_init();
darienf 3:36de8b9e4b1a 243 // initialize the logging service
darienf 3:36de8b9e4b1a 244 printf("Init LoggingService...\n");
darienf 3:36de8b9e4b1a 245 fflush(stdout);
darienf 3:36de8b9e4b1a 246 LoggingService_Init();
darienf 3:36de8b9e4b1a 247
darienf 3:36de8b9e4b1a 248 // start main loop
darienf 3:36de8b9e4b1a 249 printf("Start main loop...\n");
darienf 5:bc128a16232f 250 printf("Hello");
darienf 3:36de8b9e4b1a 251 fflush(stdout);
darienf 3:36de8b9e4b1a 252 while (1) {
darienf 3:36de8b9e4b1a 253 // get a RPC string if one is available
darienf 3:36de8b9e4b1a 254 inputState = getLine(request, sizeof(request));
darienf 3:36de8b9e4b1a 255 // if a string has been captured, process string
darienf 3:36de8b9e4b1a 256 if (inputState == GETLINE_DONE) {
darienf 3:36de8b9e4b1a 257 // process the RPC string
darienf 3:36de8b9e4b1a 258 RPC_call(request, reply);
darienf 3:36de8b9e4b1a 259 // output the reply
darienf 3:36de8b9e4b1a 260 putStr(reply);
darienf 3:36de8b9e4b1a 261 }
darienf 3:36de8b9e4b1a 262 // process any logging or streaming requests
darienf 3:36de8b9e4b1a 263 LoggingService_ServiceRoutine();
darienf 3:36de8b9e4b1a 264 // allow for ble processing
darienf 3:36de8b9e4b1a 265 ble.waitForEvent();
darienf 3:36de8b9e4b1a 266 }
darienf 3:36de8b9e4b1a 267 }