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.
Fork of MAX14690 by
Revision 13:666b6c505289, committed 2016-12-16
- Comitter:
- switches
- Date:
- Fri Dec 16 00:56:48 2016 +0000
- Parent:
- 12:1ca110017930
- Child:
- 14:cbd2a00ff28f
- Commit message:
- Cleaning up library. Removed typedef, passing I2C by reference.
Changed in this revision
| MAX14690.cpp | Show annotated file Show diff for this revision Revisions of this file |
| MAX14690.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MAX14690.cpp Sat Nov 19 00:32:54 2016 +0000
+++ b/MAX14690.cpp Fri Dec 16 00:56:48 2016 +0000
@@ -34,26 +34,14 @@
#include "MAX14690.h"
//******************************************************************************
-MAX14690::MAX14690(PinName sda, PinName scl)
+MAX14690::MAX14690(I2C &i2c): _i2c(i2c)
{
- i2c = new I2C(sda,scl);
- isOwner = true;
- resetToDefaults();
-}
-//******************************************************************************
-MAX14690::MAX14690(I2C *i2c)
-{
- this->i2c = i2c;
- isOwner = false;
resetToDefaults();
}
//******************************************************************************
MAX14690::~MAX14690()
{
- if (isOwner == true) {
- delete i2c;
- }
}
//******************************************************************************
@@ -322,7 +310,7 @@
{
char cmdData[2] = { (char)reg, value };
- if (i2c->write(MAX14690_I2C_ADDR, cmdData, sizeof(cmdData)) != 0) {
+ if (_i2c.write(MAX14690_I2C_ADDR, cmdData, sizeof(cmdData)) != 0) {
return MAX14690_ERROR;
}
@@ -334,11 +322,11 @@
{
char cmdData[1] = { (char)reg };
- if (i2c->write(MAX14690_I2C_ADDR, cmdData, sizeof(cmdData)) != 0) {
+ if (_i2c.write(MAX14690_I2C_ADDR, cmdData, sizeof(cmdData)) != 0) {
return MAX14690_ERROR;
}
- if (i2c->read(MAX14690_I2C_ADDR, value, 1) != 0) {
+ if (_i2c.read(MAX14690_I2C_ADDR, value, 1) != 0) {
return MAX14690_ERROR;
}
--- a/MAX14690.h Sat Nov 19 00:32:54 2016 +0000
+++ b/MAX14690.h Fri Dec 16 00:56:48 2016 +0000
@@ -103,7 +103,7 @@
* @brief Register Addresses
* @details Enumerated MAX14690 register addresses
*/
- typedef enum {
+ enum registers_t {
REG_CHIP_ID = 0x00, ///< Chip ID
REG_CHIP_REV = 0x01, ///< Chip Revision
REG_STATUS_A = 0x02, ///< Status Register A
@@ -136,13 +136,13 @@
REG_PWR_CFG = 0x1D, ///< Power Configuration
REG_NULL = 0x1E, ///< Reserved 0x1E
REG_PWR_OFF = 0x1F, ///< Power Off Register
- } registers_t;
+ };
/**
* @brief Thermal Status
* @details Thermal status determined by thermistor
*/
- typedef enum {
+ enum thermStat_t {
THMSTAT_000, ///< T < T1
THMSTAT_001, ///< T1 < T < T2
THMSTAT_010, ///< T2 < T < T3
@@ -151,13 +151,13 @@
THMSTAT_101, ///< No theremistor detected
THMSTAT_110, ///< Thermistor Disabled by ThermEn
THMSTAT_111, ///< CHGIN not present
- } thermStat_t;
+ };
/**
* @brief Charge Status
* @details Current operating mode of charger
*/
- typedef enum {
+ enum chgStat_t {
CHGSTAT_000, ///< Charger off
CHGSTAT_001, ///< Charging suspended by temperature
CHGSTAT_010, ///< Pre-charge
@@ -166,35 +166,35 @@
CHGSTAT_101, ///< Maintain charge
CHGSTAT_110, ///< Done
CHGSTAT_111, ///< Charger fault
- } chgStat_t;
+ };
/**
* @brief Input Current Limit
* @details CHGIN input current limit values
*/
- typedef enum {
+ enum iLimCntl_t {
ILIM_0mA, ///< 0mA
ILIM_100mA, ///< 100mA
ILIM_500mA, ///< 500mA
ILIM_1000mA, ///< 1000mA
- } iLimCntl_t;
+ };
/**
* @brief Recharge Threshold
* @details Battery recharge voltage threshold
*/
- typedef enum {
+ enum batReChg_t {
BAT_RECHG_70mV, ///< 70mV
BAT_RECHG_120mV, ///< 120mV
BAT_RECHG_170mV, ///< 170mV
BAT_RECHG_220mV, ///< 220mV
- } batReChg_t;
+ };
/**
* @brief Battery Regulation Voltage
* @details Battery regulation voltages set point
*/
- typedef enum {
+ enum batReg_t {
BAT_REG_4050mV, ///< 4.05V
BAT_REG_4100mV, ///< 4.10V
BAT_REG_4150mV, ///< 4.15V
@@ -203,13 +203,13 @@
BAT_REG_4300mV, ///< 4.30V
BAT_REG_4350mV, ///< 4.35V
BAT_REG_RSVD, ///< reserved
- } batReg_t;
+ };
/**
* @brief Precharge Voltage
* @details Battery precharge voltage threshold
*/
- typedef enum {
+ enum vPChg_t {
VPCHG_2100mV, ///< 2.10V
VPCHG_2250mV, ///< 2.25V
VPCHG_2400mV, ///< 2.40V
@@ -218,68 +218,68 @@
VPCHG_2850mV, ///< 2.85V
VPCHG_3000mV, ///< 3.00V
VPCHG_3150mV, ///< 3.15V
- } vPChg_t;
+ };
/**
* @brief Precharge Current
* @details Battery precharge current value
*/
- typedef enum {
+ enum iPChg_t {
IPCHG_5, ///< 5% of Ifchg
IPCHG_10, ///< 10% of Ifchg
IPCHG_20, ///< 20% of Ifchg
IPCHG_30, ///< 30% of Ifchg
- } iPChg_t;
+ };
/**
* @brief Done Current
* @details Charger done current where charging stops
*/
- typedef enum {
+ enum chgDone_t {
CHGDONE_5, ///< 5% of Ifchg
CHGDONE_10, ///< 10% of Ifchg
CHGDONE_20, ///< 20% of Ifchg
CHGDONE_30, ///< 30% of Ifchg
- } chgDone_t;
+ };
/**
* @brief Maintain Charge Timer
* @details Timeout settings for maintain charge mode
*/
- typedef enum {
+ enum mtChgTmr_t {
MTCHGTMR_0min, ///< 0 min
MTCHGTMR_15min, ///< 15 min
MTCHGTMR_30min, ///< 30 min
MTCHGTMR_60min, ///< 60 min
- } mtChgTmr_t;
+ };
/**
* @brief Fast Charge Timer
* @details Timeout settings for fast charge mode
*/
- typedef enum {
+ enum fChgTmr_t {
FCHGTMR_75min, ///< 75 min
FCHGTMR_150min, ///< 150 min
FCHGTMR_300min, ///< 300 min
FCHGTMR_600min, ///< 600 min
- } fChgTmr_t;
+ };
/**
* @brief Precharge Timer
* @details Timeout settings for precharge mode
*/
- typedef enum {
+ enum pChgTmr_t {
PCHGTMR_30min, ///< 30 min
PCHGTMR_60min, ///< 60 min
PCHGTMR_120min, ///< 120 min
PCHGTMR_240min, ///< 240 min
- } pChgTmr_t;
+ };
/**
* @brief LDO Enable Mode
* @details Enumerated enable modes for voltage regulators
*/
- typedef enum {
+ enum ldoMode_t {
LDO_DISABLED, ///< Disabled, Regulator Mode
SW_DISABLED, ///< Disabled, Switch Mode
LDO_ENABLED, ///< Enabled, Regulator Mode
@@ -296,35 +296,35 @@
SW_EN_MPC0_DSC, ///< Switch Enabled by MPC pin
LDO_EN_MPC1_DSC, ///< Regulator Enabled by MPC pin
SW_EN_MPC1_DSC, ///< Switch Enabled by MPC pin
- } ldoMode_t;
+ };
/**
* @brief Buck Operating Modes
* @details Enumerated operating modes for buck regulator
*/
- typedef enum {
+ enum buckMd_t {
BUCK_BURST, ///< Burst Mode Operation
BUCK_FPWM, ///< Forced PWM Operation
BUCK_MPC0_FPWM, ///< MPC activated Forced PWM
BUCK_MPC1_FPWM, ///< MPC activated Forced PWM
- } buckMd_t;
+ };
/**
* @brief Thermistor Configuration
* @details Enumerated thermistor operating modes
*/
- typedef enum {
+ enum thrmCfg_t {
THRM_DISABLED, ///< Thermistor monitoring disabled
THRM_ENABLED, ///< Basic thermistor monitoring
THRM_RSVD, ///< reserved, do not use
THRM_JEITA, ///< JEITA thermistor monitoring
- } thrmCfg_t;
+ };
/**
* @brief Monitor Configurations
* @details Enumerated configuration modes for monitor multiplexer
*/
- typedef enum {
+ enum monCfg_t {
MON_PULLDOWN = 0x0, ///< Pulled down by 100k Ohm
MON_BAT = 0x1, ///< BAT Selected
MON_SYS = 0x2, ///< SYS Selected
@@ -334,33 +334,25 @@
MON_LDO2 = 0x6, ///< LDO2 Selected
MON_LDO3 = 0x7, ///< LDO3nSelected
MON_HI_Z = 0x8, ///< High Impedance
- } monCfg_t;
+ };
/**
* @brief Monitor Divide Ratio
* @details Ratio settings for monitor divider
*/
- typedef enum {
+ enum monRatio_t {
MON_DIV4, ///< 4:1 Monitor Ratio
MON_DIV3, ///< 3:1 Monitor Ratio
MON_DIV2, ///< 2:1 Monitor Ratio
MON_DIV1, ///< 1:1 Monitor Ratio
- } monRatio_t;
-
- /**
- * MAX14690 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.
- */
- MAX14690(PinName sda, PinName scl);
+ };
/**
* MAX14690 constructor.
*
* @param i2c I2C object to use.
*/
- MAX14690(I2C *i2c);
+ MAX14690(I2C &i2c);
/**
* MAX14690 destructor.
@@ -559,10 +551,8 @@
bool stayOn;
private:
- /// I2C pointer
- I2C *i2c;
- /// Is this object the owner of the I2C object
- bool isOwner;
+ // Internal Resources
+ I2C _i2c;
/**
* @brief Converts mV to register bits
