Maxim Integrated / Mbed OS MAX30101WING_HR_SPO2

Dependencies:   MAX30101 max32630fthr

Fork of MAX30101_HR_SPO2 by John Greene

Committer:
johnGreeneMaxim
Date:
Sun Oct 15 19:22:36 2017 +0000
Revision:
9:affd4e6372a0
Parent:
8:a1538e8a3fd9
Child:
10:fcfa9adc99a9
added algorithm for MAXREFDES117--issues with memory

Who changed what in which revision?

UserRevisionLine numberNew contents of line
coreyharris 5:2f708191f1bd 1 /*******************************************************************************
coreyharris 5:2f708191f1bd 2 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
coreyharris 5:2f708191f1bd 3 *
coreyharris 5:2f708191f1bd 4 * Permission is hereby granted, free of charge, to any person obtaining a
coreyharris 5:2f708191f1bd 5 * copy of this software and associated documentation files (the "Software"),
coreyharris 5:2f708191f1bd 6 * to deal in the Software without restriction, including without limitation
coreyharris 5:2f708191f1bd 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
coreyharris 5:2f708191f1bd 8 * and/or sell copies of the Software, and to permit persons to whom the
coreyharris 5:2f708191f1bd 9 * Software is furnished to do so, subject to the following conditions:
coreyharris 5:2f708191f1bd 10 *
coreyharris 5:2f708191f1bd 11 * The above copyright notice and this permission notice shall be included
coreyharris 5:2f708191f1bd 12 * in all copies or substantial portions of the Software.
coreyharris 5:2f708191f1bd 13 *
coreyharris 5:2f708191f1bd 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
coreyharris 5:2f708191f1bd 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
coreyharris 5:2f708191f1bd 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
coreyharris 5:2f708191f1bd 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
coreyharris 5:2f708191f1bd 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
coreyharris 5:2f708191f1bd 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
coreyharris 5:2f708191f1bd 20 * OTHER DEALINGS IN THE SOFTWARE.
coreyharris 5:2f708191f1bd 21 *
coreyharris 5:2f708191f1bd 22 * Except as contained in this notice, the name of Maxim Integrated
coreyharris 5:2f708191f1bd 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
coreyharris 5:2f708191f1bd 24 * Products, Inc. Branding Policy.
coreyharris 5:2f708191f1bd 25 *
coreyharris 5:2f708191f1bd 26 * The mere transfer of this software does not imply any licenses
coreyharris 5:2f708191f1bd 27 * of trade secrets, proprietary technology, copyrights, patents,
coreyharris 5:2f708191f1bd 28 * trademarks, maskwork rights, or any other form of intellectual
coreyharris 5:2f708191f1bd 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
coreyharris 5:2f708191f1bd 30 * ownership rights.
coreyharris 5:2f708191f1bd 31 *******************************************************************************
coreyharris 5:2f708191f1bd 32 */
coreyharris 5:2f708191f1bd 33
coreyharris 5:2f708191f1bd 34
coreyharris 0:0bd4103885bf 35 #include "mbed.h"
coreyharris 0:0bd4103885bf 36 #include "max32630fthr.h"
coreyharris 0:0bd4103885bf 37 #include "MAX30101.h"
johnGreeneMaxim 9:affd4e6372a0 38 #include "algorithm.h"
johnGreeneMaxim 9:affd4e6372a0 39
johnGreeneMaxim 9:affd4e6372a0 40 //equals 3*number of LEDS used
johnGreeneMaxim 9:affd4e6372a0 41 #define DIV_SAMPLE 6
johnGreeneMaxim 9:affd4e6372a0 42 //sets the number of samples sent to the heart rate and SPO2 calculation
johnGreeneMaxim 9:affd4e6372a0 43 #define CALC_SAMPLE 500
coreyharris 0:0bd4103885bf 44
coreyharris 0:0bd4103885bf 45 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
coreyharris 0:0bd4103885bf 46
coreyharris 0:0bd4103885bf 47 bool op_sensor_config(MAX30101 &op_sensor);
johnGreeneMaxim 8:a1538e8a3fd9 48 void pmic_config(I2C & i2c_bus, DigitalOut & pmic_en);
coreyharris 0:0bd4103885bf 49
coreyharris 0:0bd4103885bf 50 /* Op Sensor FIFO nearly full callback */
coreyharris 1:471e2b722d24 51 volatile bool op_sensorIntFlag = 0;
coreyharris 0:0bd4103885bf 52 void op_sensor_callback()
coreyharris 0:0bd4103885bf 53 {
coreyharris 1:471e2b722d24 54 op_sensorIntFlag = 1;
coreyharris 0:0bd4103885bf 55 }
coreyharris 0:0bd4103885bf 56
coreyharris 0:0bd4103885bf 57 int main()
coreyharris 0:0bd4103885bf 58 {
coreyharris 1:471e2b722d24 59 Serial pc(USBTX, USBRX); // Use USB debug probe for serial link
coreyharris 1:471e2b722d24 60 pc.baud(115200); // Baud rate = 115200
coreyharris 0:0bd4103885bf 61
coreyharris 1:471e2b722d24 62 DigitalOut rLed(LED1, LED_OFF); // Debug LEDs
coreyharris 0:0bd4103885bf 63 DigitalOut gLed(LED2, LED_OFF);
coreyharris 0:0bd4103885bf 64 DigitalOut bLed(LED3, LED_OFF);
coreyharris 0:0bd4103885bf 65
coreyharris 1:471e2b722d24 66 InterruptIn op_sensor_int(P3_2); // Config P3_2 as int. in for
coreyharris 1:471e2b722d24 67 op_sensor_int.fall(&op_sensor_callback); // FIFO ready interrupt
coreyharris 0:0bd4103885bf 68
coreyharris 4:14d1b87cd3c4 69 I2C i2cBus(I2C1_SDA, I2C1_SCL); // I2C bus, P3_4 = SDA, P3_5 = SCL
coreyharris 0:0bd4103885bf 70
johnGreeneMaxim 8:a1538e8a3fd9 71 DigitalOut VLED_EN(P3_3,0); //Enable for VLEDs
johnGreeneMaxim 8:a1538e8a3fd9 72 pmic_config(i2cBus, VLED_EN);
johnGreeneMaxim 8:a1538e8a3fd9 73
coreyharris 4:14d1b87cd3c4 74 MAX30101 op_sensor(i2cBus); // Create new MAX30101 on i2cBus
coreyharris 4:14d1b87cd3c4 75 int rc = op_sensor_config(op_sensor); // Config sensor, return 0 on success
coreyharris 0:0bd4103885bf 76
coreyharris 5:2f708191f1bd 77 MAX30101::InterruptBitField_u ints; // Read interrupt status to clear
coreyharris 5:2f708191f1bd 78 rc = op_sensor.getInterruptStatus(ints); // power on interrupt
coreyharris 5:2f708191f1bd 79
coreyharris 0:0bd4103885bf 80 uint8_t fifoData[MAX30101::MAX_FIFO_BYTES];
coreyharris 0:0bd4103885bf 81 uint16_t idx, readBytes;
coreyharris 7:6075af57668e 82 int32_t opSample;
coreyharris 2:54182d6a168f 83 uint32_t sample;
johnGreeneMaxim 9:affd4e6372a0 84 uint32_t redData[500];//set array to max fifo size
johnGreeneMaxim 9:affd4e6372a0 85 uint32_t irData[500];//set array to max fifo size
johnGreeneMaxim 9:affd4e6372a0 86 int r=0; //counter for redData position
johnGreeneMaxim 9:affd4e6372a0 87 int ir=0; //counter for irData position
johnGreeneMaxim 9:affd4e6372a0 88 int c=0; //counter to print values
johnGreeneMaxim 9:affd4e6372a0 89 int i =0; //second counter
johnGreeneMaxim 9:affd4e6372a0 90 int32_t spo2 =0;
johnGreeneMaxim 9:affd4e6372a0 91 int8_t spo2Valid = 0;
johnGreeneMaxim 9:affd4e6372a0 92 int32_t heartRate = 0;
johnGreeneMaxim 9:affd4e6372a0 93 int8_t heartRateValid = 0;
johnGreeneMaxim 9:affd4e6372a0 94 int32_t numSamples = 0;
johnGreeneMaxim 9:affd4e6372a0 95 uint32_t fifoIR[MAX30101::MAX_FIFO_BYTES];
johnGreeneMaxim 9:affd4e6372a0 96 uint32_t fifoRED[MAX30101::MAX_FIFO_BYTES];
johnGreeneMaxim 9:affd4e6372a0 97
johnGreeneMaxim 9:affd4e6372a0 98
johnGreeneMaxim 9:affd4e6372a0 99 while(1)
johnGreeneMaxim 9:affd4e6372a0 100 {
johnGreeneMaxim 9:affd4e6372a0 101
johnGreeneMaxim 9:affd4e6372a0 102
johnGreeneMaxim 9:affd4e6372a0 103 if( rc == 0 )
johnGreeneMaxim 9:affd4e6372a0 104 {
coreyharris 4:14d1b87cd3c4 105
coreyharris 4:14d1b87cd3c4 106 // Check if op_sensor interrupt asserted
johnGreeneMaxim 9:affd4e6372a0 107 if(op_sensorIntFlag)
johnGreeneMaxim 9:affd4e6372a0 108 {
johnGreeneMaxim 9:affd4e6372a0 109 pc.printf("Entered op_sensorIntFlag check\r\n");
coreyharris 1:471e2b722d24 110 op_sensorIntFlag = 0; // Lower interrupt flag
coreyharris 4:14d1b87cd3c4 111 rc = op_sensor.getInterruptStatus(ints); // Read interrupt status
coreyharris 0:0bd4103885bf 112
coreyharris 4:14d1b87cd3c4 113 // Check if FIFO almost full interrupt asserted
johnGreeneMaxim 9:affd4e6372a0 114 if((rc == 0) && (ints.bits.a_full))
johnGreeneMaxim 9:affd4e6372a0 115 {
johnGreeneMaxim 9:affd4e6372a0 116 pc.printf("about to read fifo\r\n");
coreyharris 4:14d1b87cd3c4 117 // Read FIFO
johnGreeneMaxim 9:affd4e6372a0 118 rc = op_sensor.readFIFO(MAX30101::TwoLedChannels, fifoData, readBytes);
coreyharris 0:0bd4103885bf 119
johnGreeneMaxim 9:affd4e6372a0 120 numSamples = readBytes/DIV_SAMPLE; //calcualtes number of smaples read
johnGreeneMaxim 9:affd4e6372a0 121
johnGreeneMaxim 9:affd4e6372a0 122 if(rc == 0)
johnGreeneMaxim 9:affd4e6372a0 123 {
coreyharris 4:14d1b87cd3c4 124
coreyharris 4:14d1b87cd3c4 125 // Convert read bytes into samples
johnGreeneMaxim 9:affd4e6372a0 126 for(idx = 0, c=0, i=0; idx < readBytes; idx+=3)
johnGreeneMaxim 9:affd4e6372a0 127 {
johnGreeneMaxim 9:affd4e6372a0 128 //pc.printf("In sample adjustment \r\n");
coreyharris 2:54182d6a168f 129 sample = (fifoData[idx]<<16) | (fifoData[idx+1]<<8) | (fifoData[idx+2]);
coreyharris 7:6075af57668e 130 opSample = sample << 14; // Sign extends sample
coreyharris 7:6075af57668e 131 opSample = opSample >> 14;
johnGreeneMaxim 9:affd4e6372a0 132 if(idx%2==0)
johnGreeneMaxim 9:affd4e6372a0 133 {
johnGreeneMaxim 9:affd4e6372a0 134 //pc.printf("end red allocation\r\n");
johnGreeneMaxim 9:affd4e6372a0 135 redData[r] = opSample;//saves to buff for calculations
johnGreeneMaxim 9:affd4e6372a0 136 fifoRED[i] = opSample;//saves to buff to print values just obtained
johnGreeneMaxim 9:affd4e6372a0 137 r++;
johnGreeneMaxim 9:affd4e6372a0 138 i++;
johnGreeneMaxim 9:affd4e6372a0 139
johnGreeneMaxim 9:affd4e6372a0 140 }
johnGreeneMaxim 9:affd4e6372a0 141 else
johnGreeneMaxim 9:affd4e6372a0 142 {
johnGreeneMaxim 9:affd4e6372a0 143 //pc.printf("end ir allocation\r\n");
johnGreeneMaxim 9:affd4e6372a0 144 irData[ir] = opSample; //saves to buff for calculations
johnGreeneMaxim 9:affd4e6372a0 145 fifoIR[c] = opSample;//saves to buff to print values just obtained
johnGreeneMaxim 9:affd4e6372a0 146 ir++;
johnGreeneMaxim 9:affd4e6372a0 147 c++;
johnGreeneMaxim 9:affd4e6372a0 148
johnGreeneMaxim 9:affd4e6372a0 149 }
johnGreeneMaxim 9:affd4e6372a0 150 pc.printf("Red count = %i\r\n IR count = %i\r\n",r,ir);
johnGreeneMaxim 9:affd4e6372a0 151 //pc.printf("idx = %i and readbytes = %i\r\n", idx,readBytes);
johnGreeneMaxim 9:affd4e6372a0 152
coreyharris 0:0bd4103885bf 153 }
coreyharris 4:14d1b87cd3c4 154
johnGreeneMaxim 9:affd4e6372a0 155 if(r>=200 & ir>=200)//checks to make sure there are 200 samples in data buffers
johnGreeneMaxim 9:affd4e6372a0 156 {
johnGreeneMaxim 9:affd4e6372a0 157 pc.printf("In Calculation Function\r\n");
johnGreeneMaxim 9:affd4e6372a0 158 //calculate heart rate and spo2
johnGreeneMaxim 9:affd4e6372a0 159 maxim_heart_rate_and_oxygen_saturation( irData, CALC_SAMPLE,
johnGreeneMaxim 9:affd4e6372a0 160 redData, &spo2, &spo2Valid, &heartRate, &heartRateValid);
johnGreeneMaxim 9:affd4e6372a0 161
johnGreeneMaxim 9:affd4e6372a0 162 for(c=100;c<200;c++)//dump first hundred samples after calculations
johnGreeneMaxim 9:affd4e6372a0 163 {
johnGreeneMaxim 9:affd4e6372a0 164 redData[c-100]=redData[c];
johnGreeneMaxim 9:affd4e6372a0 165 irData[c-100]=irData[c];
johnGreeneMaxim 9:affd4e6372a0 166
johnGreeneMaxim 9:affd4e6372a0 167 }
johnGreeneMaxim 9:affd4e6372a0 168 r=50;
johnGreeneMaxim 9:affd4e6372a0 169 ir=50;
johnGreeneMaxim 9:affd4e6372a0 170
johnGreeneMaxim 9:affd4e6372a0 171
johnGreeneMaxim 9:affd4e6372a0 172 }
johnGreeneMaxim 9:affd4e6372a0 173
johnGreeneMaxim 9:affd4e6372a0 174
johnGreeneMaxim 9:affd4e6372a0 175
johnGreeneMaxim 9:affd4e6372a0 176 pc.printf("Read Samples %i\r\n",numSamples);
johnGreeneMaxim 9:affd4e6372a0 177 //prints the Red LED data
johnGreeneMaxim 9:affd4e6372a0 178 pc.printf("RED LED DATA\r\n");
johnGreeneMaxim 9:affd4e6372a0 179 for(c=0; c<numSamples; c++)
johnGreeneMaxim 9:affd4e6372a0 180 {
johnGreeneMaxim 9:affd4e6372a0 181 pc.printf("%i\r\n",fifoRED[c]);
johnGreeneMaxim 9:affd4e6372a0 182 }
johnGreeneMaxim 9:affd4e6372a0 183
johnGreeneMaxim 9:affd4e6372a0 184 //prints the IR LED data
johnGreeneMaxim 9:affd4e6372a0 185 pc.printf("IR LED DATA\r\n");
johnGreeneMaxim 9:affd4e6372a0 186 for(c=0; c<numSamples; c++)
johnGreeneMaxim 9:affd4e6372a0 187 {
johnGreeneMaxim 9:affd4e6372a0 188 pc.printf("%i\r\n",fifoIR[c]);
johnGreeneMaxim 9:affd4e6372a0 189 }
johnGreeneMaxim 9:affd4e6372a0 190
johnGreeneMaxim 9:affd4e6372a0 191 if(spo2Valid==1)
johnGreeneMaxim 9:affd4e6372a0 192 {
johnGreeneMaxim 9:affd4e6372a0 193 pc.printf("SPO2 = %i\r\n",spo2);
johnGreeneMaxim 9:affd4e6372a0 194 spo2Valid=0;
johnGreeneMaxim 9:affd4e6372a0 195 }
johnGreeneMaxim 9:affd4e6372a0 196 else
johnGreeneMaxim 9:affd4e6372a0 197 {
johnGreeneMaxim 9:affd4e6372a0 198 pc.printf("SPO2 calculation waiting for enough samples\r\n");
johnGreeneMaxim 9:affd4e6372a0 199 }
johnGreeneMaxim 9:affd4e6372a0 200 if(heartRateValid==1)
johnGreeneMaxim 9:affd4e6372a0 201 {
johnGreeneMaxim 9:affd4e6372a0 202 pc.printf("Heart Rate = %i\r\n",heartRate);
johnGreeneMaxim 9:affd4e6372a0 203 heartRateValid=0;
johnGreeneMaxim 9:affd4e6372a0 204 }else
johnGreeneMaxim 9:affd4e6372a0 205 {
johnGreeneMaxim 9:affd4e6372a0 206 pc.printf("Heart rate calculation waiting for enough samples\r\n");
johnGreeneMaxim 9:affd4e6372a0 207 }
johnGreeneMaxim 9:affd4e6372a0 208
johnGreeneMaxim 9:affd4e6372a0 209
coreyharris 0:0bd4103885bf 210 }
coreyharris 0:0bd4103885bf 211 }
coreyharris 0:0bd4103885bf 212 }
coreyharris 3:a580414c44ce 213
coreyharris 5:2f708191f1bd 214 // If rc != 0, a communication error has occurred
coreyharris 3:a580414c44ce 215 } else {
coreyharris 0:0bd4103885bf 216
coreyharris 4:14d1b87cd3c4 217 pc.printf("Something went wrong, "
coreyharris 4:14d1b87cd3c4 218 "check the I2C bus or power connections... \r\n");
coreyharris 0:0bd4103885bf 219 bLed = LED_OFF;
coreyharris 0:0bd4103885bf 220 gLed = LED_OFF;
coreyharris 0:0bd4103885bf 221
coreyharris 0:0bd4103885bf 222 while(1)
coreyharris 0:0bd4103885bf 223 {
coreyharris 0:0bd4103885bf 224 rLed = !rLed;
coreyharris 0:0bd4103885bf 225 wait(0.5);
coreyharris 3:a580414c44ce 226 }
coreyharris 3:a580414c44ce 227 }
coreyharris 0:0bd4103885bf 228
coreyharris 3:a580414c44ce 229 }
coreyharris 0:0bd4103885bf 230 }
coreyharris 0:0bd4103885bf 231
coreyharris 0:0bd4103885bf 232
coreyharris 0:0bd4103885bf 233 bool op_sensor_config(MAX30101 &op_sensor) {
coreyharris 0:0bd4103885bf 234
coreyharris 0:0bd4103885bf 235 //Reset Device
coreyharris 0:0bd4103885bf 236 MAX30101::ModeConfiguration_u modeConfig;
coreyharris 0:0bd4103885bf 237 modeConfig.all = 0;
coreyharris 0:0bd4103885bf 238 modeConfig.bits.reset = 1;
coreyharris 0:0bd4103885bf 239 int32_t rc = op_sensor.setModeConfiguration(modeConfig);
coreyharris 0:0bd4103885bf 240
coreyharris 0:0bd4103885bf 241
coreyharris 0:0bd4103885bf 242 //enable MAX30101 interrupts
coreyharris 0:0bd4103885bf 243 MAX30101::InterruptBitField_u ints;
coreyharris 0:0bd4103885bf 244 if(rc == 0)
coreyharris 0:0bd4103885bf 245 {
coreyharris 0:0bd4103885bf 246 ints.all = 0;
johnGreeneMaxim 9:affd4e6372a0 247 ints.bits.die_temp = 1; // Enable internal die temp. interrupt
johnGreeneMaxim 9:affd4e6372a0 248 ints.bits.a_full = 1; // Enable FIFO almost full interrupt
coreyharris 0:0bd4103885bf 249 rc = op_sensor.enableInterrupts(ints);
coreyharris 0:0bd4103885bf 250 }
coreyharris 0:0bd4103885bf 251
coreyharris 0:0bd4103885bf 252 //configure FIFO
coreyharris 0:0bd4103885bf 253 MAX30101::FIFO_Configuration_u fifoConfig;
coreyharris 0:0bd4103885bf 254 if(rc == 0)
coreyharris 0:0bd4103885bf 255 {
coreyharris 0:0bd4103885bf 256 fifoConfig.all = 0;
johnGreeneMaxim 9:affd4e6372a0 257 fifoConfig.bits.fifo_a_full = 15; // Max level of 15 samples
coreyharris 5:2f708191f1bd 258 fifoConfig.bits.sample_average = MAX30101::AveragedSamples_8; // Average 8 samples
coreyharris 0:0bd4103885bf 259 rc = op_sensor.setFIFOConfiguration(fifoConfig);
coreyharris 0:0bd4103885bf 260 }
coreyharris 0:0bd4103885bf 261
coreyharris 0:0bd4103885bf 262 MAX30101::SpO2Configuration_u spo2Config;
coreyharris 0:0bd4103885bf 263 if(rc == 0)
coreyharris 0:0bd4103885bf 264 {
johnGreeneMaxim 9:affd4e6372a0 265 spo2Config.all = 0; // sets smallest LSB size
johnGreeneMaxim 9:affd4e6372a0 266 spo2Config.bits.spo2_sr = MAX30101::SR_3200_Hz; // SpO2 SR = 3200Hz
coreyharris 7:6075af57668e 267 spo2Config.bits.led_pw = MAX30101::PW_3; // 18-bit ADC resolution
coreyharris 0:0bd4103885bf 268 rc = op_sensor.setSpO2Configuration(spo2Config);
coreyharris 0:0bd4103885bf 269 }
coreyharris 0:0bd4103885bf 270
johnGreeneMaxim 9:affd4e6372a0 271 //Set LED drive currents
coreyharris 0:0bd4103885bf 272 if(rc == 0)
coreyharris 0:0bd4103885bf 273 {
coreyharris 5:2f708191f1bd 274 // Heart Rate only, 1 LED channel, Pulse amp. = 0x1F
coreyharris 2:54182d6a168f 275 rc = op_sensor.setLEDPulseAmplitude(MAX30101::LED1_PA, 0x1F);
johnGreeneMaxim 9:affd4e6372a0 276 //To include SPO2, 2 LED channel, Pulse amp. 0x1F
johnGreeneMaxim 9:affd4e6372a0 277 if(rc==0)
johnGreeneMaxim 9:affd4e6372a0 278 {
johnGreeneMaxim 9:affd4e6372a0 279 rc = op_sensor.setLEDPulseAmplitude(MAX30101::LED2_PA, 0x1F);
johnGreeneMaxim 9:affd4e6372a0 280 }
coreyharris 0:0bd4103885bf 281 }
coreyharris 0:0bd4103885bf 282
coreyharris 0:0bd4103885bf 283 //Set operating mode
coreyharris 0:0bd4103885bf 284 modeConfig.all = 0;
coreyharris 0:0bd4103885bf 285 if(rc == 0)
coreyharris 0:0bd4103885bf 286 {
johnGreeneMaxim 9:affd4e6372a0 287 modeConfig.bits.mode = MAX30101::SpO2Mode; // Sets SPO2 Mode
coreyharris 0:0bd4103885bf 288 rc = op_sensor.setModeConfiguration(modeConfig);
coreyharris 0:0bd4103885bf 289 }
coreyharris 0:0bd4103885bf 290
coreyharris 0:0bd4103885bf 291
coreyharris 0:0bd4103885bf 292 return rc;
coreyharris 0:0bd4103885bf 293 }
johnGreeneMaxim 8:a1538e8a3fd9 294
johnGreeneMaxim 8:a1538e8a3fd9 295 void pmic_config(I2C & i2c_bus, DigitalOut & pmic_en)
johnGreeneMaxim 8:a1538e8a3fd9 296 {
johnGreeneMaxim 8:a1538e8a3fd9 297
johnGreeneMaxim 8:a1538e8a3fd9 298 const uint8_t PMIC_ADRS = 0x54;
johnGreeneMaxim 8:a1538e8a3fd9 299 const uint8_t BBB_EXTRA_ADRS = 0x1C;
johnGreeneMaxim 8:a1538e8a3fd9 300 const uint8_t BOOST_VOLTAGE = 0x05;
johnGreeneMaxim 8:a1538e8a3fd9 301
johnGreeneMaxim 8:a1538e8a3fd9 302 char data_buff[] = {BBB_EXTRA_ADRS, 0x40}; //BBBExtra register address
johnGreeneMaxim 8:a1538e8a3fd9 303 //and data to enable passive
johnGreeneMaxim 8:a1538e8a3fd9 304 //pull down.
johnGreeneMaxim 8:a1538e8a3fd9 305 i2c_bus.write(PMIC_ADRS, data_buff,2); //write to BBBExtra register
johnGreeneMaxim 8:a1538e8a3fd9 306
johnGreeneMaxim 8:a1538e8a3fd9 307 data_buff[0] = BOOST_VOLTAGE;
johnGreeneMaxim 8:a1538e8a3fd9 308 data_buff[1] = 0x14; //Boost voltage configuration
johnGreeneMaxim 8:a1538e8a3fd9 309 //register followed by data
johnGreeneMaxim 8:a1538e8a3fd9 310 //to set voltage to 4.5V
johnGreeneMaxim 8:a1538e8a3fd9 311 pmic_en = 0; //disables VLED
johnGreeneMaxim 8:a1538e8a3fd9 312 i2c_bus.write(PMIC_ADRS, data_buff,2); //write to BBBExtra register
johnGreeneMaxim 8:a1538e8a3fd9 313 pmic_en = 1; //enables VLED
johnGreeneMaxim 8:a1538e8a3fd9 314 }