Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 13:0f663ca63342, committed 2019-11-13
- Comitter:
- AhmadAlkaff
- Date:
- Wed Nov 13 11:10:03 2019 +0000
- Parent:
- 12:2ad10c36f820
- Commit message:
- Reorganize Code
Changed in this revision
--- a/LIS2DH/LIS2DH.cpp Mon Nov 11 17:38:48 2019 +0000
+++ b/LIS2DH/LIS2DH.cpp Wed Nov 13 11:10:03 2019 +0000
@@ -1,46 +1,41 @@
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
*
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
*
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
- * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL MAXIM
+ * INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
- * Except as contained in this notice, the name of Maxim Integrated
- * Products, Inc. shall not be used except as stated in the Maxim Integrated
- * Products, Inc. Branding Policy.
+ * Except as contained in this notice, the name of Maxim Integrated Products,
+ * Inc. shall not be used except as stated in the Maxim Integrated Products,
+ * Inc. Branding Policy.
*
- * The mere transfer of this software does not imply any licenses
- * of trade secrets, proprietary technology, copyrights, patents,
- * trademarks, maskwork rights, or any other form of intellectual
- * property whatsoever. Maxim Integrated Products, Inc. retains all
- * ownership rights.
+ * The mere transfer of this software does not imply any licenses of trade
+ * secrets, proprietary technology, copyrights, patents, trademarks, maskwork
+ * rights, or any other form of intellectual property whatsoever. Maxim
+ * Integrated Products, Inc. retains all ownership rights.
*******************************************************************************
*/
#include "LIS2DH.h"
-//#include "Streaming.h"
-//#include "Peripherals.h"
void lis2dh_int_handler(void);
/**
* @brief buffer array to hold fifo contents for packetizing
*/
uint32_t lis2dh_buffer[LIS2DH_MAX_DATA_SIZE];
-
int16_t motion_cached[3];
LIS2DH *LIS2DH::instance = NULL;
@@ -64,9 +59,8 @@
//******************************************************************************
LIS2DH::~LIS2DH(void) {
- if (isOwner == true) {
+ if (isOwner == true)
delete i2c;
- }
}
//******************************************************************************
@@ -74,9 +68,8 @@
int result;
char cmdData[2] = {(char)reg, value};
result = i2c->write(slaveAddress, cmdData, 2);
- if (result != 0) {
+ if (result != 0)
return -1;
- }
return 0;
}
@@ -86,36 +79,30 @@
char cmdData[1] = {(char)reg};
result = i2c->write(slaveAddress, cmdData, 1);
- if (result != 0) {
- return -1;
- }
+ if (result != 0)
+ return -1;
result = i2c->read(slaveAddress, value, 1);
- if (result != 0) {
+ if (result != 0)
return -1;
- }
return 0;
}
//******************************************************************************
static void I2c_Reset(uint8_t index, int speed) {
mxc_i2cm_regs_t *regs = MXC_I2CM_GET_I2CM(index);
- /* reset module */
+ /* Reset module */
regs->ctrl = MXC_F_I2CM_CTRL_MSTR_RESET_EN;
regs->ctrl = 0;
- /* enable tx_fifo and rx_fifo */
+ /* Enable tx_fifo and rx_fifo */
regs->ctrl |= (MXC_F_I2CM_CTRL_TX_FIFO_EN | MXC_F_I2CM_CTRL_RX_FIFO_EN);
}
//******************************************************************************
-/// Interrupt handler, this empties the hardware fifo and packetizes it for
-/// streaming
+// Interrupt handler, empties the hardware fifo and packetizes it for streaming
void LIS2DH::int_handler(void) {
char fifo_src;
- int16_t valueX;
- int16_t valueY;
- int16_t valueZ;
- int num;
- int index;
+ int16_t valueX, valueY, valueZ;
+ int num, index;
I2c_Reset(2, 1);
num = 0;
@@ -128,15 +115,12 @@
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;
motion_cached[2] = valueZ;
-
- //StreamPacketUint32(PACKET_LIS2DH, lis2dh_buffer, index);
}
//******************************************************************************
@@ -147,39 +131,30 @@
//******************************************************************************
void LIS2DH::configure_interrupt(void) {
-
lis2dh_ctrl_reg6_t ctrl_reg6;
- ///< interrupt enabled on INT1, interrupt active low
+ // 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
+ 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
- ///
+ // 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
- ///
+ // 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;
@@ -188,42 +163,17 @@
__enable_irq();
return -1;
}
-
- ///
- /// set HR (high resolution)
- ///
- //if (writeReg(LIS2DH_CTRL_REG4, 0x8) == -1) {
- //__enable_irq();
- //return -1;
- //}
-
- ///
- /// set the data rate, enable all axis
- ///
- /*
- dataRate = dataRate & 0xF;
- if (dataRate > 0x9) {
- dataRate = 0x9;
- }
- */
-
- ctrl_reg1.bit.ODR = 5; ///< set the data rate
- //ctrl_reg.bit.ODR0 = 0x1;
- //ctrl_reg.bit.ODR1 = 0x0;
- //ctrl_reg.bit.ODR2 = 0x1;
- //ctrl_reg.bit.ODR3 = 0x0; //Low power mode at 100Hz ODR0-ODR3
- ctrl_reg1.bit.LPen = 0x1; ///< enable low power
- ctrl_reg1.bit.Zen = 0x1; ///< enable z
- ctrl_reg1.bit.Yen = 0x1; ///< enable y
- ctrl_reg1.bit.Xen = 0x1; ///< enable x
+ // Low power mode at 100Hz ODR0-ODR3
+ ctrl_reg1.bit.ODR = 5; // Set the data rate
+ ctrl_reg1.bit.LPen = 0x1; // Enable Low power
+ 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
- ///
+ // Enable watermark interrupt
ctrl_reg3.all = 0x00;
ctrl_reg3.bit.I1_WTM = 0x1;
if (writeReg(LIS2DH_CTRL_REG3, ctrl_reg3.all) == -1) {
@@ -231,7 +181,6 @@
return -1;
}
__enable_irq();
-
return 0;
}
@@ -239,14 +188,10 @@
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) {
+ if (val == LIS2DH_ID)
*detected = 1;
- }
-
return 0;
}
@@ -267,12 +212,10 @@
reg = LIS2DH_OUT_X_L;
for (i = 0; i < 6; i++) {
- if (readReg((LIS2DH_REG_map_t)reg, &values[i]) != 0) {
+ if (readReg((LIS2DH_REG_map_t)reg, &values[i]) != 0)
return -1;
- }
reg++;
}
-
*valueX = ((short)values[1] << 8) + values[0];
*valueY = ((short)values[3] << 8) + values[2];
*valueZ = ((short)values[5] << 8) + values[4];
@@ -292,23 +235,20 @@
//******************************************************************************
void LIS2DH::stop(void) {
__disable_irq();
- writeReg(LIS2DH_CTRL_REG3, 0x00); // Disable watermark interrupt
- writeReg(LIS2DH_CTRL_REG1, 0x00); // Data rate = 0Hz
- writeReg(LIS2DH_FIFO_CTRL_REG,
- 0x00); // set to bypass mode... clears FIFO_SRC_REG
+ writeReg(LIS2DH_CTRL_REG3, 0x00); // Disable watermark interrupt
+ writeReg(LIS2DH_CTRL_REG1, 0x00); // Data rate = 0Hz
+ writeReg(LIS2DH_FIFO_CTRL_REG, 0x00); // Set to bypass mode,
+ // clears FIFO_SRC_REG
__enable_irq();
}
//******************************************************************************
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
- ///
+ // 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) {
+ if (value == 0x0)
return;
- }
LIS2DH::instance->int_handler();
}
--- a/LIS2DH/LIS2DH.h Mon Nov 11 17:38:48 2019 +0000
+++ b/LIS2DH/LIS2DH.h Wed Nov 13 11:10:03 2019 +0000
@@ -40,10 +40,8 @@
* Driver for the LIS2DH on the HSP Platform
*
*/
-
void LIS2DHIntHandler(void);
-
#define LIS2DH_DATARATE_1HZ 0x1
#define LIS2DH_DATARATE_10HZ 0x2
#define LIS2DH_DATARATE_25HZ 0x3
@@ -70,10 +68,9 @@
class LIS2DH {
public:
-
- typedef enum { ///< LIS2DH registers
-
- LIS2DH_READID = 0x33,
+ // LIS2DH registers
+ typedef enum {
+ LIS2DH_READID = 0x33,
LIS2DH_STATUS_REG_AUX = 0x07,
LIS2DH_OUT_TEMP_L = 0x0C,
LIS2DH_OUT_TEMP_H = 0x0D,
@@ -112,11 +109,9 @@
LIS2DH_TIME_WINDOW = 0x3D,
LIS2DH_Act_THS = 0x3E,
LIS2DH_Act_DUR = 0x3F,
-
- }LIS2DH_REG_map_t;
+ }LIS2DH_REG_map_t;
-
- ///< @brief STATUS_AUX (07h)
+ // @brief STATUS_AUX (07h)
typedef union lis2dh_status_aux_reg {
char all;
struct {
@@ -128,17 +123,17 @@
} bit;
} lis2dh_status_aux_t;
- ///< @brief TEMP_CFG_REG (1Fh)
+ // @brief TEMP_CFG_REG (1Fh)
typedef union lis2dh_temp_cfg_reg {
char all;
struct {
char reserved1 : 6;
- char TEMP_EN0 : 1;
- char TEMP_EN1 : 1;
+ char TEMP_EN0 : 0;
+ char TEMP_EN1 : 0;
} bit;
} lis2dh_temp_cfg_t;
- ///< @brief CTRL_REG1 (20h)
+ // @brief CTRL_REG1 (20h)
typedef union lis2dh_ctrl_reg1_reg {
char all;
struct {
@@ -150,7 +145,7 @@
} bit;
} lis2dh_ctrl_reg1_t;
- ///< @brief CTRL_REG1 (21h)
+ // @brief CTRL_REG1 (21h)
typedef union lis2dh_ctrl_reg2_reg {
char all;
struct {
@@ -162,7 +157,7 @@
} bit;
} lis2dh_ctrl_reg2_t;
- ///< @brief CTRL_REG3 (22h)
+ // @brief CTRL_REG3 (22h)
typedef union lis2dh_ctrl_reg3_reg {
char all;
struct {
@@ -175,20 +170,17 @@
} bit;
} lis2dh_ctrl_reg3_t;
- ///< @brief CTRL_REG4 (23h)
+ // @brief CTRL_REG4 (23h)
typedef union lis2dh_ctrl_reg4_reg {
char all;
struct {
char SIM : 1;
char ST : 2;
- //char HR : 0;
- //char FS : 0; // Scale is 2g
- //char BLE : 0;
char BDU : 1;
} bit;
} lis2dh_ctrl_reg4_t;
- ///< @brief CTRL_REG5 (24h)
+ // @brief CTRL_REG5 (24h)
typedef union lis2dh_ctrl_reg5_reg {
char all;
struct {
@@ -202,7 +194,7 @@
} bit;
} lis2dh_ctrl_reg5_t;
- ///< @brief CTRL_REG6 (25h)
+ // @brief CTRL_REG6 (25h)
typedef union lis2dh_ctrl_reg6_reg {
char all;
struct {
@@ -217,12 +209,12 @@
} bit;
} lis2dh_ctrl_reg6_t;
- ///< @brief REFERENCE (26h)
+ // @brief REFERENCE (26h)
typedef union lis2dh_reference_reg {
char all;
} lis2dh_reference;
- ///< @brief STATUS_REG (27h)
+ // @brief STATUS_REG (27h)
typedef union lis2dh_status_reg_ {
char all;
struct {
@@ -238,7 +230,7 @@
} lis2dh_status_reg_t;
- ///< @brief FIFO_CTRL_REG (2Eh)
+ // @brief FIFO_CTRL_REG (2Eh)
typedef union lis2dh_fifo_ctrl_reg_ {
char all;
struct {
@@ -248,7 +240,7 @@
} bit;
} lis2dh_fifo_ctrl_reg_t;
- ///< @brief FIFO_CTRL_REG (2Fh)
+ // @brief FIFO_CTRL_REG (2Fh)
typedef union lis2dh_fifo_src_reg_ {
char all;
struct {
@@ -259,7 +251,7 @@
} bit;
} lis2dh_fifo_src_reg_t;
- ///< @brief INT1_CFG (30h)
+ // @brief INT1_CFG (30h)
typedef union lis2dh_int1_cfg_reg_ {
char all;
struct {
@@ -274,7 +266,7 @@
} bit;
} lis2dh_int1_cfg_t;
- ///< @brief INT1_SRC (31h)
+ // @brief INT1_SRC (31h)
typedef union lis2dh_int1_src_reg_ {
char all;
struct {
@@ -289,8 +281,7 @@
} bit;
} lis2dh_int1_src_t;
-
- ///< @brief INT2_CFG (34h)
+ // @brief INT2_CFG (34h)
typedef union lis2dh_int2_cfg_reg_ {
char all;
struct {
@@ -305,7 +296,7 @@
} bit;
} lis2dh_int2_cfg_t;
- ///< @brief INT2_SRC (35h)
+ // @brief INT2_SRC (35h)
typedef union lis2dh_int2_src_reg_ {
char all;
struct {
@@ -320,8 +311,6 @@
} bit;
} lis2dh_int2_src_t;
-
-
LIS2DH(PinName sda, PinName scl, int slaveAddress);
LIS2DH(I2C *i2c, int slaveAddress);
~LIS2DH(void);
@@ -369,16 +358,15 @@
char readId(void);
static LIS2DH *instance;
-
private:
/** @brief
*/
void configure_interrupt(void);
- ///< I2C pointer
+ // I2C pointer
I2C *i2c;
- ///< Is this object the owner of the I2C object
+ // Is this object the owner of the I2C object
bool isOwner;
- ///< Device slave address
+ // Device slave address
int slaveAddress;
};
--- a/MAX14720/MAX14720.cpp Mon Nov 11 17:38:48 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,227 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
- * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name of Maxim Integrated
- * Products, Inc. shall not be used except as stated in the Maxim Integrated
- * Products, Inc. Branding Policy.
- *
- * The mere transfer of this software does not imply any licenses
- * of trade secrets, proprietary technology, copyrights, patents,
- * trademarks, maskwork rights, or any other form of intellectual
- * property whatsoever. Maxim Integrated Products, Inc. retains all
- * ownership rights.
- *******************************************************************************
- */
-
-#include "MAX14720.h"
-
-//******************************************************************************
-MAX14720::MAX14720(PinName sda, PinName scl, int slaveAddress) :
- slaveAddress(slaveAddress)
-{
- i2c = new I2C(sda,scl);
- isOwner = true;
- clkDivEn = false;
- clkDivSet = 0;
- boostISet = BOOST_ISET_100mA;
- boostMillivolts = 3300;
- boostEn = BOOST_DISABLED;
- boostEMI = false;
- boostInd = false;
- boostHysOff = false;
- boostPasDsc = false;
- boostActDsc = false;
- buckMd = BUCK_BURST;
- buckFst = false;
- buckISet = BUCK_ISET_300mA;
- buckCfg = false;
- buckInd = false;
- buckHysOff = true;
- buckMinOT = true;
- buckInteg = true;
- buckPasDsc = false;
- buckActDsc = false;
- buckFScl = false;
-}
-//******************************************************************************
-MAX14720::MAX14720(I2C *i2c, int slaveAddress) :
- slaveAddress(slaveAddress)
-{
- this->i2c = i2c;
- isOwner = false;
- clkDivEn = false;
- clkDivSet = 0;
- boostISet = BOOST_ISET_100mA;
- boostMillivolts = 3300;
- boostEn = BOOST_DISABLED;
- boostEMI = false;
- boostInd = false;
- boostHysOff = false;
- boostPasDsc = false;
- boostActDsc = false;
- buckMd = BUCK_BURST;
- buckFst = false;
- buckISet = BUCK_ISET_300mA;
- buckCfg = false;
- buckInd = false;
- buckHysOff = true;
- buckMinOT = true;
- buckInteg = true;
- buckPasDsc = false;
- buckActDsc = false;
- buckFScl = false;
-}
-
-//******************************************************************************
-MAX14720::~MAX14720()
-{
- if (isOwner == true) {
- delete i2c;
- }
-}
-
-//******************************************************************************
-int MAX14720::boostSetMode(boostEn_t mode)
-{
- char data;
-
- boostEn = mode;
- data = (boostEn << 3) | (boostEMI << 1) | (boostInd);
- return writeReg(REG_BOOST_CFG, data);
-}
-
-//******************************************************************************
-int MAX14720::boostSetVoltage(int mV)
-{
- char data;
-
- if ((MAX14720_BOOST_MIN_MV <= mV) && (mV <= MAX14720_BOOST_MAX_MV)) {
- boostMillivolts = mV;
- data = (mV - MAX14720_BOOST_MIN_MV) / MAX14720_BOOST_STEP_MV;
- } else {
- return MAX14720_ERROR;
- }
-
- if (boostEn == BOOST_ENABLED) {
- if (writeReg(REG_BOOST_CFG, 0x00) != MAX14720_NO_ERROR) {
- return MAX14720_ERROR;
- }
- }
-
- if (writeReg(REG_BOOST_VSET, data) != MAX14720_NO_ERROR) {
- return MAX14720_ERROR;
- }
-
- if (boostEn == BOOST_ENABLED) {
- data = (boostEn << 3) | (boostEMI << 1) | (boostInd);
- if (writeReg(REG_BOOST_CFG, data) != MAX14720_NO_ERROR) {
- return MAX14720_ERROR;
- }
- }
-
- return MAX14720_NO_ERROR;
-}
-
-//******************************************************************************
-int MAX14720::init()
-{
- char data;
-
- data = (clkDivEn << 7) | (clkDivSet);
- if (writeReg(REG_BOOST_CDIV, data) != MAX14720_NO_ERROR) {
- return MAX14720_ERROR;
- }
-
- data = (boostISet);
- if (writeReg(REG_BOOST_ISET, data) != MAX14720_NO_ERROR) {
- return MAX14720_ERROR;
- }
-
- if ((MAX14720_BOOST_MIN_MV <= boostMillivolts) &&
- (boostMillivolts <= MAX14720_BOOST_MAX_MV)) {
- data = (boostMillivolts - MAX14720_BOOST_MIN_MV) / MAX14720_BOOST_STEP_MV;
- if (writeReg(REG_BOOST_VSET, data) != MAX14720_NO_ERROR) {
- return MAX14720_ERROR;
- }
- } else {
- return MAX14720_ERROR;
- }
-
- data = (buckMd << 1) | (buckFst);
- if (writeReg(REG_BUCK_CFG, data) != MAX14720_NO_ERROR) {
- return MAX14720_ERROR;
- }
-
- data = (boostHysOff << 7) | (boostPasDsc << 6) | (boostActDsc << 5) |
- (buckPasDsc << 2) | (buckActDsc << 1) | (buckFScl);
- if (writeReg(REG_BBB_EXTRA, data) != MAX14720_NO_ERROR) {
- return MAX14720_ERROR;
- }
-
- // Write Boost Enable Register Last
- data = (boostEn << 3) | (boostEMI << 1) | (boostInd);
- if (writeReg(REG_BOOST_CFG, data) != MAX14720_NO_ERROR) {
- return MAX14720_ERROR;
- }
-
- return MAX14720_NO_ERROR;
-}
-
-//******************************************************************************
-int MAX14720::monSet(monCfg_t monCfg)
-{
- return writeReg(REG_MON_CFG, monCfg);
-}
-
-//******************************************************************************
-int MAX14720::shutdown()
-{
- return writeReg(REG_PWR_OFF, 0xB2);
-}
-
-
-//******************************************************************************
-int MAX14720::writeReg(registers_t reg, char value)
-{
- char cmdData[2] = { (char)reg, value };
-
- if (i2c->write(slaveAddress, cmdData, sizeof(cmdData)) != 0) {
- return MAX14720_ERROR;
- }
-
- return MAX14720_NO_ERROR;
-}
-
-//******************************************************************************
-int MAX14720::readReg(registers_t reg, char *value)
-{
- char cmdData[1] = { (char)reg };
-
- if (i2c->write(slaveAddress, cmdData, sizeof(cmdData)) != 0) {
- return MAX14720_ERROR;
- }
-
- if (i2c->read(slaveAddress, value, 1) != 0) {
- return MAX14720_ERROR;
- }
-
- return MAX14720_NO_ERROR;
-}
--- a/MAX14720/MAX14720.h Mon Nov 11 17:38:48 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,355 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
- * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name of Maxim Integrated
- * Products, Inc. shall not be used except as stated in the Maxim Integrated
- * Products, Inc. Branding Policy.
- *
- * The mere transfer of this software does not imply any licenses
- * of trade secrets, proprietary technology, copyrights, patents,
- * trademarks, maskwork rights, or any other form of intellectual
- * property whatsoever. Maxim Integrated Products, Inc. retains all
- * ownership rights.
- *******************************************************************************
- */
-
-#ifndef _MAX14720_H_
-#define _MAX14720_H_
-
-#include "mbed.h"
-
-#define MAX14720_NO_ERROR 0
-#define MAX14720_ERROR -1
-
-#define MAX14720_BOOST_MIN_MV 2500
-#define MAX14720_BOOST_MAX_MV 5000
-#define MAX14720_BOOST_STEP_MV 100
-
-/**
- * @brief MAX14720 Power-Management Solution Driver
- *
- * @details The MAX14720/MAX14750 are compact power-management solutions for
- * space-constrained, battery-powered applications where size and efficiency are
- * critical. Both devices integrate a power switch, a linear regulator, a buck
- * regulator, and a buck-boost regulator.
- * <br>https://www.maximintegrated.com/en/products/power/battery-management/MAX14720.html
- *
- * @code
- * #include "mbed.h"
- * #include "MAX14720.h"
- *
- * // I2C Master 2
- * I2C i2c2(I2C2_SDA, I2C2_SCL);
- *
- * #define I2C_ADDR_PMIC (0x54)
- * MAX14720 max14720(&i2c2, I2C_ADDR_PMIC);
- *
- * DigitalOut led(LED1, 0);
- * InterruptIn button(SW1);
- *
- * void turnOff()
- * {
- * max14720.shutdown();
- * }
- *
- * int main()
- * {
- * button.fall(&turnOff);
- *
- * max14720.boostEn = MAX14720::BOOST_ENABLED;
- * if (max14720.init() == MAX14720_ERROR) {
- * printf("Error initializing MAX14720");
- * }
- *
- * wait(1);
- *
- * while(1) {
- * max14720.boostSetMode(MAX14720::BOOST_DISABLED);
- * max14720.boostEn = MAX14720::BOOST_ENABLED;
- * wait(0.5);
- * max14720.boostSetVoltage(2500);
- * wait(0.5);
- * max14720.boostSetVoltage(5000);
- * wait(0.5);
- * }
- * }
- * @endcode
- */
-class MAX14720
-{
-public:
-
- /**
- * @brief Register Addresses
- * @details Enumerated MAX14720 register addresses
- */
- typedef enum {
- REG_CHIP_ID = 0x00, ///< Chip ID
- REG_CHIP_REV = 0x01, ///< Chip Revision
- REG_BOOST_CDIV = 0x03, ///< Boost Clock Divider
- REG_BOOST_ISET = 0x04, ///< Boost Peak Current
- REG_BOOST_VSET = 0x05, ///< Boost Voltage Setting
- REG_BOOST_CFG = 0x06, ///< Boost Configuration
- REG_BUCK_VSET = 0x07, ///< Buck Voltage Setting
- REG_BUCK_CFG = 0x08, ///< Buck Configuration
- REG_BUCK_ISET = 0x09, ///< Buck Peak Current and Settings
- REG_LDO_VSET = 0x0A, ///< LDO Voltage Setting
- REG_LDO_CFG = 0x0B, ///< LDO Configuration
- REG_SWITCH_CFG = 0x0C, ///< Switch Configuration
- REG_BAT_TIME = 0x0D, ///< Battery Impedance Timing
- REG_BAT_CFG = 0x0E, ///< Battery Impedance Configuration
- REG_BAT_BCV = 0x0F, ///< Battery Cell Voltage
- REG_BAT_OCV = 0x10, ///< Open Cell Voltage
- REG_BAT_LCV = 0x11, ///< Loaded Cell Voltage
- REG_MON_CFG = 0x19, ///< Monitor Multiplexer Configuration
- REG_BOOT_CFG = 0x1A, ///< Boot Configuration
- REG_PIN_STAT = 0x1B, ///< Pin Status
- REG_BBB_EXTRA = 0x1C, ///< Buck/Buck-Boost Extra
- REG_HANDSHK = 0x1D, ///< Power-On Handshake
- REG_UVLO_CFG = 0x1E, ///< Under-Voltage Lock Out
- REG_PWR_OFF = 0x1F, ///< Power Off Command
- } registers_t;
-
- /**
- * @brief Boost Peak Current Settings
- * @details Enumerated peak current settings for boost regulator
- */
- typedef enum {
- BOOST_ISET_MIN, ///< Minimum On-Time
- BOOST_ISET_50mA, ///< 50mA Peak Current
- BOOST_ISET_100mA, ///< 100mA Peak Current
- BOOST_ISET_150mA, ///< 150mA Peak Current
- BOOST_ISET_200mA, ///< 200mA Peak Current
- BOOST_ISET_250mA, ///< 250mA Peak Current
- BOOST_ISET_300mA, ///< 300mA Peak Current
- BOOST_ISET_350mA, ///< 350mA Peak Current
- } boostISet_t;
-
- /**
- * @brief Boost Enable Mode
- * @details Enumerated enable modes for boost regulator
- */
- typedef enum {
- BOOST_DISABLED, ///< Boost Disabled
- BOOST_ENABLED, ///< Boost Enabled
- BOOST_EN_MPC, ///< Boost Enabled by MPC pin
- } boostEn_t;
-
- /**
- * @brief Buck Operating Modes
- * @details Enumerated operating modes for buck regulator
- */
- typedef enum {
- BUCK_BURST, ///< Burst Mode Operation
- BUCK_FPWM, ///< Forced PWM Operation
- BUCK_MPC_FPWM, ///< MPC activated Forced PWM
- } buckMd_t;
-
- /**
- * @brief Buck Peak Current Settings
- * @details Enumerated peak current settings for buck regulator
- */
- typedef enum {
- BUCK_ISET_50mA, ///< 50mA Peak Current
- BUCK_ISET_100mA, ///< 100mA Peak Current
- BUCK_ISET_150mA, ///< 150mA Peak Current
- BUCK_ISET_200mA, ///< 200mA Peak Current
- BUCK_ISET_250mA, ///< 250mA Peak Current
- BUCK_ISET_300mA, ///< 300mA Peak Current
- BUCK_ISET_350mA, ///< 350mA Peak Current
- BUCK_ISET_400mA, ///< 400mA Peak Current
- } buckISet_t;
-
- /**
- * @brief Monitor Configurations
- * @details Enumerated configuration modes for monitor multiplexer
- */
- typedef enum {
- MON_PULLDOWN = 0x00, ///< Pulled down by 100k Ohm
- MON_HI_Z = 0x08, ///< High Impedance
- MON_SWIN = 0x80, ///< SWIN Selected
- MON_SWOUT = 0x81, ///< SWOUT Selected
- MON_BIN = 0x82, ///< BIN Selected
- MON_BOUT = 0x83, ///< BOUT Selected
- MON_HVIN = 0x84, ///< HVIN Selected
- MON_HVOUT = 0x85, ///< HVOUT Selected
- MON_LIN = 0x86, ///< LIN Selected
- MON_LOUT = 0x87, ///< LOUT Selected
- } monCfg_t;
-
- /**
- * @brief Under-Voltage Lock Out Input
- * @details Enumerated input selection options for UVLO
- */
- typedef enum {
- LIN_UVLO, ///< LIN used to determine UVLO condition
- BIN_UVLO, ///< BIN used to determine UVLO condition
- } uvloIn_t;
-
- /**
- * MAX14720 constructor.
- *
- * @param sda mbed pin to use for SDA line of I2C interface.
- * @param scl mbed pin to use for SCL line of I2C interface.
- * @param slaveAddress Slave Address of the device.
- */
- MAX14720(PinName sda, PinName scl, int slaveAddress);
-
- /**
- * MAX14720 constructor.
- *
- * @param i2c I2C object to use.
- * @param slaveAddress Slave Address of the device.
- */
- MAX14720(I2C *i2c, int slaveAddress);
-
- /**
- * MAX14720 destructor.
- */
- ~MAX14720();
-
- /**
- * @brief Initialize MAX14720
- * @details Applies settings to MAX14720.
- * Settings are stored in public variables.
- * The variables are pre-loaded with the most common configuation.
- * Assign new values to the public variables before calling init.
- * This will update all the settings including the boost voltage
- * from boostMillivolts and the boost enable mode from boostEn.
- * @returns 0 if no errors, -1 if error.
- */
- int init();
-
- /**
- * @brief Set the Boost Voltage
- * @details Sets the voltage for the boost regulator.
- * The voltage is specified in millivolts.
- * The MAX14720 cannot update the voltage when enabled.
- * This function checks the local boostEn variable and if the
- * regualtor is enabled it will send the disable command before
- * sending the new voltage and re-enable the boost regulator after
- * the new voltage is written.
- * @param mV voltage for boost regualtor in millivolts
- * @returns 0 if no errors, -1 if error.
- */
- int boostSetVoltage(int mV);
-
- /**
- * @brief Set Boost Enable Mode
- * @details Sets the enable mode for the boost regulator
- * @param mode The enable mode for the boost regulator
- * @returns 0 if no errors, -1 if error.
- */
- int boostSetMode(boostEn_t mode);
-
- /**
- * @brief Configure Mon Pin
- * @details Configures the operating mode of the monitor multiplexer
- * @param monCfg The configuration mode for the monitor pin
- * @returns 0 if no errors, -1 if error.
- */
- int monSet(monCfg_t monCfg);
-
- /**
- * @brief Shutdown
- * @details Sends the command to turn off all supplies and put the part
- * in battery saving shelf mode.
- * @returns 0 if no errors, -1 if error.
- */
- int shutdown();
-
- /**
- * @brief Write Register
- * @details Writes the given value to the specified register.
- * Note, this function provides direct access to the registers
- * without any awareness or effect on the settings stored in
- * the public variables. This is used by the other functions to
- * set the values inside the MAX14720. Calling this outside of the
- * other functions can break the synchronization of the variables
- * to the state of the MAX14720.
- * @param reg The register to be written
- * @param value The data to be written
- * @returns 0 if no errors, -1 if error.
- */
- int writeReg(registers_t reg, char value);
-
- /**
- * @brief Read Register
- * @details Reads from the specified register
- * @param reg The register to be read
- * @param value Pointer for where to store the data
- * @returns 0 if no errors, -1 if error.
- */
- int readReg(registers_t reg, char *value);
-
- /// Boost Clock Divider Enable: default 0 - Disabled, 1 - Enabled
- bool clkDivEn;
- /// Boost Clock Divider Setting: default 0, The clock is divided by this value +10 when enabled
- int clkDivSet;
- /// Boost Peak Current Setting: default BOOST_ISET_100mA
- boostISet_t boostISet;
- /// Boost Voltage in millivolts: default 3300
- int boostMillivolts;
- /// Boost Enable Mode: default BOOST_DISABLED
- boostEn_t boostEn;
- /// Boost EMI Setting: default 0 - EMI damping active (lower noise), 1 - Damping disabled (more efficient)
- bool boostEMI;
- /// Boost Inductor Setting: default 0 - 4.7uH, 1 - 3.3uH
- bool boostInd;
- /// Boost Hysteresis Off: default 0 - Hysteresis enabled (more efficient), 1 - Hysteresis off (lower voltage ripple)
- bool boostHysOff;
- /// Boost Passive Discharge: default 0 - Disabled, 1 - Enabled when boost disabled
- bool boostPasDsc;
- /// Boost Active Discharge: default 0 - Disabled, 1 - Enabled when boost disabled
- bool boostActDsc;
- /// Buck Operating Mode: default BUCK_BURST
- buckMd_t buckMd;
- /// Buck Fast Start: default 0 - Normal startup current limit, 1 - Double startup current for fast start
- bool buckFst;
- /// Buck Peak Current Setting: default BUCK_ISET_300mA
- buckISet_t buckISet;
- /// Buck Configuration: default 0 - For burst mode, 1 - For FPWM mode
- bool buckCfg;
- /// Buck Inductor Setting: default 0 - 2.2uH, 1 - 4.7uH
- bool buckInd;
- /// Buck Hysteresis Off: default 0 - Hysteresis enabled (more efficient), 1 - Hysteresis off (lower voltage ripple)
- bool buckHysOff;
- /// Buck Minimum On Time: default 1 - Disable deglitch delay (lower voltage ripple), 0 - Enable deglitch dealy (more efficient)
- bool buckMinOT;
- /// Buck Integrate: default 1 - Better load regulation at higher current (recommended for output capacitance >6uF), 0 - More stable operation with smaller output capacitor
- bool buckInteg;
- /// Buck Passive Discharge: default 0 - Disabled, 1 - Enabled when buck disabled
- bool buckPasDsc;
- /// Buck Active Discharge: default 0 - Disabled, 1 - Enabled when buck disabled
- bool buckActDsc;
- /// Buck Fet Scaling: default 0 - Full buck FET after soft start (more efficient for larger loads), 1 - Reduced buck FET while active (lower quiescent current for light loads)
- bool buckFScl;
-
-private:
- /// I2C pointer
- I2C *i2c;
- /// Is this object the owner of the I2C object
- bool isOwner;
- /// Device slave address
- int slaveAddress;
-};
-
-#endif /* _MAX14720_H_ */
--- a/MAX30205/MAX30205.cpp Mon Nov 11 17:38:48 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,146 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
- * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name of Maxim Integrated
- * Products, Inc. shall not be used except as stated in the Maxim Integrated
- * Products, Inc. Branding Policy.
- *
- * The mere transfer of this software does not imply any licenses
- * of trade secrets, proprietary technology, copyrights, patents,
- * trademarks, maskwork rights, or any other form of intellectual
- * property whatsoever. Maxim Integrated Products, Inc. retains all
- * ownership rights.
- *******************************************************************************
- */
-#include "MAX30205.h"
-
-//******************************************************************************
-MAX30205::MAX30205(PinName sda, PinName scl, int slaveAddress) :
- slaveAddress(slaveAddress) {
- i2c = new I2C(sda, scl);
- isOwner = true;
- i2c->frequency(100000);
-}
-
-//******************************************************************************
-MAX30205::MAX30205(I2C *i2c, int slaveAddress) : slaveAddress(slaveAddress) {
- this->i2c = i2c;
- i2c->frequency(100000);
- isOwner = false;
-}
-
-//******************************************************************************
-MAX30205::~MAX30205(void) {
- if (isOwner == true) {
- delete i2c;
- }
-}
-
-//******************************************************************************
-int MAX30205::reg_write(char reg, char value) {
- int result;
- char cmdData[2] = {(char)reg, value};
- result = i2c->write(slaveAddress, cmdData, 2);
- if (result != 0){
- return -1;
- }
- return 0;
-}
-
-//******************************************************************************
-int MAX30205::reg_write16(char reg, uint16_t value) {
- int result;
- char hi = (value >> 8) & 0xFF;
- char lo = value & 0xFF;
- char cmdData[3] = {reg, hi, lo};
- result = i2c->write(slaveAddress, cmdData, 3);
- if (result != 0) {
- return -1;
- }
- return 0;
-}
-
-//******************************************************************************
-int MAX30205::reg_read(char reg, char *value) {
- int result;
- char cmdData[1] = {reg};
-
- result = i2c->write(slaveAddress, cmdData, 1);
- if (result != 0) {
- return -1;
- }
- result = i2c->read(slaveAddress, value, 1);
- if (result != 0){
- return -1;
- }
- return 0;
-}
-
-//******************************************************************************
-int MAX30205::reg_read16(char reg, uint16_t *value) {
- int result;
- char data[2];
- char cmdData[1] = {reg};
- result = i2c->write(slaveAddress, cmdData, 1);
- if (result != 0) {
- return -1;
- }
- result = i2c->read(slaveAddress, data, 2);
- if (result != 0) {
- return -1;
- }
- *value = (data[0] << 8) + data[1];
- return 0;
-}
-
-//******************************************************************************
-int MAX30205::readTemperature(uint16_t *value) {
- uint8_t data[2];
- int status;
- status = reg_read16(MAX30205_Temperature, (uint16_t *)&data);
- *value = (data[0] << 8) + data[1];
- return status;
-}
-
-//******************************************************************************
-float MAX30205::toCelsius(unsigned int rawTemp) {
- float val;
- float val1, val2;
- val1 = (float)(rawTemp >> 8);
- val2 = (float)(rawTemp & 0xFF);
- val = val2 + (val1 / 256.0f);
- return val;
-}
-
-//******************************************************************************
-float MAX30205::toFahrenheit(float temperatureC) {
- return temperatureC * 9.0f / 5.0f + 32.0f;
-}
-
-//******************************************************************************
-int MAX30205::reg_THYST_Read(uint16_t *value) {
- return reg_read16(MAX30205_THYST, value);
-}
-
-//******************************************************************************
-int MAX30205::reg_THYST_Write(uint16_t value) {
- return reg_write16(MAX30205_THYST, value);
-}
--- a/MAX30205/MAX30205.h Mon Nov 11 17:38:48 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,141 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
- * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name of Maxim Integrated
- * Products, Inc. shall not be used except as stated in the Maxim Integrated
- * Products, Inc. Branding Policy.
- *
- * The mere transfer of this software does not imply any licenses
- * of trade secrets, proprietary technology, copyrights, patents,
- * trademarks, maskwork rights, or any other form of intellectual
- * property whatsoever. Maxim Integrated Products, Inc. retains all
- * ownership rights.
- *******************************************************************************
- */
-#ifndef __MAX30205_H_
-#define __MAX30205_H_
-
-#include "mbed.h"
-
-/**
- * @brief Driver for the MAX30205 on the HSP Platform
- */
-
-class MAX30205 {
-public:
- ///< MAX30205 Register Addresses
- typedef enum Registers {
- MAX30205_Temperature = 0x00,
- MAX30205_Configuration = 0x01,
- MAX30205_THYST = 0x02,
- MAX30205_TOS = 0x03
- } Registers_t;
-
- /**
- * @brief Constructor using I2C PinNames
- * @param sda Pinname for sda
- * @param scl Pinname for scl
- */
- MAX30205(PinName sda, PinName scl, int slaveAddress);
- /**
- * @brief Constructor using pointer to I2C object
- * @param *i2c Pointer to I2C object
- */
- MAX30205(I2C *i2c, int slaveAddress);
-
- /** @brief Destructor */
- ~MAX30205(void);
-
- /** @brief Write a register into device at slave address
- * @param reg register address
- * @param value value to write
- */
- int reg_write(char reg, char value);
-
- /**
- * @brief Detect the second instance of the MAX30205
- * @param reg register address
- * @param value 8-bit value to writes
- */
- int reg_read(char reg, char *value);
-
- /**
- * @brief Write a 16-bit value into device at slave address
- * @param reg register address
- * @param value 16-bit value to write
- */
- int reg_write16(char reg, uint16_t value);
-
- /**
- * @brief Read a 16-bit value from a device at a slave address
- * @param reg register address
- * @param value pointer to store read value
- */
- int reg_read16(char reg, uint16_t *value);
-
- /**
- * @brief Read the temperature from the device into a 16 bit value
- * @param value pointer to a 16 bit short
- */
- int readTemperature(uint16_t *value);
-
- /**
- * @brief Read the THYST value from a specified device instance
- * @param value 16-bit pointer of value to read into
- */
- int reg_THYST_Read(uint16_t *value);
-
- /**
- * @brief Write the THYST to a device instance
- * @param value 16-bit value to write
- */
- int reg_THYST_Write(uint16_t value);
-
- /**
- * @brief Convert a raw temperature value into a float
- * @param rawTemp raw temperature value to convert
- * @return the convereted value in degrees C
- */
- float toCelsius(unsigned int rawTemp);
-
- /**
- * @brief Convert the passed in temperature in C to Fahrenheit
- * @param temperatureC Temperature in C to convert
- * @returns Returns the converted Fahrenheit value
- */
- float toFahrenheit(float temperatureC);
-
-private:
- /**
- * @brief I2C pointer
- */
- I2C *i2c;
- /**
- * @brief Is this object the owner of the I2C object
- */
- bool isOwner;
- /**
- * @brief Device slave address
- */
- int slaveAddress;
-};
-
-#endif /* __MAX30205_H_ */
--- a/main.cpp Mon Nov 11 17:38:48 2019 +0000
+++ b/main.cpp Wed Nov 13 11:10:03 2019 +0000
@@ -1,23 +1,11 @@
#include "mbed.h"
#include "LIS2DH.h"
-#include "MAX14720.h"
#include "MAX30001.h"
-#include "MAX30205.h"
#include "System.h"
-#include "USBSerial.h"
-//#include "unistd.h"
+#include "USBSerial.h"
-/************************************************************************************************************************************/
-// define the HVOUT Boost Voltage default for the MAX14720 PMIC
-#define HVOUT_VOLTAGE 4500 // set to 4500 mV
-
-// define all I2C addresses
-#define LIS2DH_I2C_SLAVE_ADDR (0x32)
-#define MAX14720_I2C_SLAVE_ADDR (0x54)
-#define MAX30101_I2C_SLAVE_ADDR (0xAE)
-#define MAX30205_I2C_SLAVE_ADDR_BOTTOM (0x90)
-#define MAX30205_I2C_SLAVE_ADDR_TOP (0x92)
-#define BMP280_I2C_SLAVE_ADDR (0xEC)
+/******************************************************************************/
+#define LIS2DH_I2C_SLAVE_ADDR (0x32)
// Settings for ECG Initialization
#define En_ecg 0x01
@@ -43,42 +31,19 @@
#define Rhsf 0x04
#define Clr_rrint 0x01
-// Settings for Lead Detection
-#define En_dcloff 0x01
-#define Ipol 0x00
-#define Imag 0x00
-#define Vth 0x00
-
-// Settings for the HR initialization
-#define FIFO_WATERLEVEL_MARK 15
-#define SAMPLE_AVG 2
-#define SAMPLE_RATE 1
-#define PULSE_WIDTH 2
-#define RED_LED_CURRENT 0x1F
-#define IR_LED_CURRENT 0X1F
-
-// Define with Maxim VID and a Maxim assigned PID, set to version 0x0001 and non-blocking
+// Define with Maxim VID and a Maxim assigned PID, set to version 0x0001 and
+// non-blocking
USBSerial usbSerial(0x0b6a, 0x0100, 0x0001, false);
-// I2C Masters
-I2C i2c1(I2C1_SDA, I2C1_SCL); // used by MAX30205
-I2C i2c2(I2C2_SDA, I2C2_SCL); // used by MAX14720, LIS2DH
+// LIS2DH I2C Master
+I2C i2c2(I2C2_SDA, I2C2_SCL);
// SPI Master 0 with SPI0_SS for use with MAX30001
SPI spi(SPI0_MOSI, SPI0_MISO, SPI0_SCK, SPI0_SS);
-// PMIC
-MAX14720 max14720(&i2c2, MAX14720_I2C_SLAVE_ADDR);
-
// Accelerometer
LIS2DH lis2dh(&i2c2, LIS2DH_I2C_SLAVE_ADDR);
InterruptIn lis2dh_Interrupt(P4_7);
-
-// Top Temperature Sensor
-MAX30205 MAX30205_top(&i2c1, MAX30205_I2C_SLAVE_ADDR_TOP);
-
-// Botttom Temperature Sensor
-MAX30205 MAX30205_bottom(&i2c1, MAX30205_I2C_SLAVE_ADDR_BOTTOM);
// ECG device
MAX30001 max30001(&spi);
@@ -91,54 +56,35 @@
DigitalOut led(LED1);
// Data of sensors
-int32_t ECG_Raw, ECG_cumul, SpO_Raw;
+int16_t Acc[3];
+int32_t ECG_Raw, ECG_cumul;
double ECG_converted = 0;
uint32_t index = 0;
-
-//Temperature sensor variables
-uint16_t rawTemp_top, rawTemp_bottom;
-float celsius_top, celsius_bottom, fahrenheit_top, fahrenheit_bottom;
-
-// Accelerometer sensor variables
-int16_t accel_value[3];
-
-//write the power down command to PMIC
-void turnOff() {
- max14720.shutdown();
-}
-//@brief Creates a packet that will be streamed via USB Serial
-//@brief the packet created will be inserted into a fifo to be streamed at a later time
-//@param id Streaming ID
-//@param buffer Pointer to a uint32 array that contains the data to include in the packet
+//@brief Creates a packet that will be streamed via USB Serial, the packet
+// created will be inserted into a fifo to be streamed at a later time
+//@param id Streaming ID
+//@param buffer Pointer to a uint32 array that contains the data to include in
+// the packet
//@param number Number of elements in the buffer
void StreamPacketUint32_ex(uint32_t id, uint32_t *buffer, uint32_t number) {
int k;
if(id == MAX30001_DATA_ECG) {
- for (k = 0; k < number ; k++) {
+ for (k = 0; k < number; k++) {
ECG_Raw = (int32_t)(buffer[k] << 8);
ECG_Raw = ECG_Raw >> 14;
- //usbSerial.printf("%s ECG", datetime.datetime.utcnow().strftime("%H:%M:%S"));
usbSerial.printf("ECG\r\n");
usbSerial.printf("%d\r\n", ECG_Raw);
- //usbSerial.printf("k is %d and number is %d\r\n", k, number);
index++;
}
}
}
int main() {
- // hold results for returning functions
+ // Hold results for returning functions
int result;
- // initialize HVOUT on the MAX14720 PMIC
- result = max14720.init();
- if (result == MAX14720_ERROR)
- printf("Error initializing MAX14720");
- max14720.boostEn = MAX14720::BOOST_ENABLED;
- max14720.boostSetVoltage(HVOUT_VOLTAGE);
-
// Interrupt priority
NVIC_SetPriority(GPIO_P0_IRQn, 5);
NVIC_SetPriority(GPIO_P1_IRQn, 5);
@@ -189,78 +135,15 @@
MAX30001::MAX30001_INT_ODNR); // int2b_Type
lis2dh.initStart(LIS2DH_DATARATE_50HZ, LIS2DH_FIFO_SIZE);
-
- max30001.max30001_ECG_InitStart(En_ecg, Openp, Openn, Pol, Calp_sel, Caln_sel, E_fit, Rate, Gain, Dhpf, Dlpf);
+ max30001.max30001_ECG_InitStart(En_ecg, Openp, Openn, Pol, Calp_sel,
+ Caln_sel, E_fit, Rate, Gain, Dhpf, Dlpf);
max30001.max30001_synch();
max30001.onDataAvailable(&StreamPacketUint32_ex);
while (1){
- // MAX30001 initialize interrupt
- // ECG READING
-
- // LIS2DH initialize interrupt
- //lis2dh.init();
- //lis2dh_Interrupt.fall(&LIS2DHIntHandler);
- //lis2dh_Interrupt.mode(PullUp);
-
int a;
- lis2dh.get_motion_fifo(&accel_value[0], &accel_value[1], &accel_value[2]);
+ lis2dh.get_motion_fifo(&Acc[0], &Acc[1], &Acc[2]);
usbSerial.printf("ACC\r\n");
-
- usbSerial.printf("X %d\r\nY %d\r\nZ %d\r\n", accel_value[0], accel_value[1], accel_value[2]);
-
- /*
- int child_pid = fork();
- int status;
-
-
- if (child_pid == 0) {
- while (1){
- a = usbSerial._getc();
- if (a==97){
- max30001.max30001_Stop_ECG();
- lis2dh.stop();
- return 0;
- }
- }
- }
- //LOOP-FOREVER READ ACCELEROTMETER
- else {
- pid_t result = waitpid(child_pid, &status, WNOHANG);
- if (result == 0) {
- while (1) {
- */
-
- /*
- wait(5);
- a = usbSerial._getc();
- usbSerial.printf("WAIT 5 LIAO\r\n");
-
- if (a == 98) {
- max30001.max30001_Stop_ECG();
- index = 0;
- }
- */
- /*
- lis2dh.int_handler();
-
- lis2dh.get_motion_fifo(&accel_value[0], &accel_value[1], &accel_value[2]);
-
- //usbSerial.printf("***** LIS2DH Acclerometer Sensor Reading *****\r\n");
- usbSerial.printf("X %d\r\nY %d\r\nZ %d\r\n", accel_value[0], accel_value[1], accel_value[2]);
- //usbSerial.printf("-------------------------------------------------\r\n");
- wait(1);
- }
- } else {
- while(1){
- usbSerial.printf("Press c to continue\r\n");
- a = usbSerial._getc();
- if (a==99){
- break;
- }
- }
- }
- }
- */
+ usbSerial.printf("X %d\r\nY %d\r\nZ %d\r\n", Acc[0], Acc[1], Acc[2]);
}
}
