A feature complete driver for the MAX17048 lithium fuel gauge from Maxim.

Dependents:   MAX17048_HelloWorld ECGAFE_copy MAX17048_HelloWorld Orion_newPCB_test_LV ... more

Now fully tested!

Files at this revision

API Documentation at this revision

Comitter:
neilt6
Date:
Thu Nov 07 17:53:44 2013 +0000
Parent:
4:e61b2723d2cf
Child:
6:6927c72b2923
Commit message:
Minor improvements

Changed in this revision

MAX17048.cpp Show annotated file Show diff for this revision Revisions of this file
MAX17048.h Show annotated file Show diff for this revision Revisions of this file
--- a/MAX17048.cpp	Mon Sep 16 22:02:40 2013 +0000
+++ b/MAX17048.cpp	Thu Nov 07 17:53:44 2013 +0000
@@ -18,10 +18,11 @@
 
 MAX17048::MAX17048(PinName sda, PinName scl) : m_I2C(sda, scl)
 {
-    //Nothing else to initialize
+    //Set the I2C bus frequency to 400kHz
+    m_I2C.frequency(400000);
 }
 
-bool MAX17048::open(void)
+bool MAX17048::open()
 {
     //Probe for the MAX17048 using a Zero Length Transfer
     if (!m_I2C.write(m_ADDR, NULL, 0)) {
@@ -36,13 +37,13 @@
     }
 }
 
-void MAX17048::reset(void)
+void MAX17048::reset()
 {
     //Write the POR command
     write(REG_CMD, 0x5400);
 }
 
-void MAX17048::quickStart(void)
+void MAX17048::quickStart()
 {
     //Read the current 16-bit register value
     unsigned short value = read(REG_MODE);
@@ -54,7 +55,7 @@
     write(REG_MODE, value);
 }
 
-bool MAX17048::sleepEnabled(void)
+bool MAX17048::sleepEnabled()
 {
     //Read the 16-bit register value
     unsigned short value = read(REG_MODE);
@@ -81,7 +82,7 @@
     write(REG_MODE, value);
 }
 
-bool MAX17048::hibernating(void)
+bool MAX17048::hibernating()
 {
     //Read the 16-bit register value
     unsigned short value = read(REG_MODE);
@@ -93,7 +94,7 @@
         return false;
 }
 
-float MAX17048::hibernateThreshold(void)
+float MAX17048::hibernateThreshold()
 {
     //Read the 16-bit register value
     unsigned short value = read(REG_HIBRT);
@@ -122,7 +123,7 @@
     write(REG_HIBRT, value);
 }
 
-float MAX17048::activeThreshold(void)
+float MAX17048::activeThreshold()
 {
     //Read the 16-bit register value
     unsigned short value = read(REG_HIBRT);
@@ -151,7 +152,7 @@
     write(REG_HIBRT, value);
 }
 
-unsigned short MAX17048::version(void)
+unsigned short MAX17048::version()
 {
     //Return the 16-bit production version
     return read(REG_VERSION);
@@ -171,7 +172,7 @@
     writeRCOMP(rcomp);
 }
 
-bool MAX17048::sleeping(void)
+bool MAX17048::sleeping()
 {
     //Read the 16-bit register value
     unsigned short value = read(REG_CONFIG);
@@ -198,7 +199,7 @@
     write(REG_CONFIG, value);
 }
 
-bool MAX17048::socChangeAlertEnabled(void)
+bool MAX17048::socChangeAlertEnabled()
 {
     //Read the 16-bit register value
     unsigned short value = read(REG_CONFIG);
@@ -225,7 +226,7 @@
     write(REG_CONFIG, value);
 }
 
-bool MAX17048::alerting(void)
+bool MAX17048::alerting()
 {
     //Read the 16-bit register value
     unsigned short value = read(REG_CONFIG);
@@ -237,7 +238,7 @@
         return false;
 }
 
-void MAX17048::clearAlert(void)
+void MAX17048::clearAlert()
 {
     //Read the current 16-bit register value
     unsigned short value = read(REG_CONFIG);
@@ -249,7 +250,7 @@
     write(REG_CONFIG, value);
 }
 
-char MAX17048::emptyAlertThreshold(void)
+char MAX17048::emptyAlertThreshold()
 {
     //Read the 16-bit register value
     unsigned short value = read(REG_CONFIG);
@@ -277,7 +278,7 @@
     write(REG_CONFIG, value);
 }
 
-float MAX17048::vAlertMinThreshold(void)
+float MAX17048::vAlertMinThreshold()
 {
     //Read the 16-bit register value
     unsigned short value = read(REG_VALRT);
@@ -306,7 +307,7 @@
     write(REG_VALRT, value);
 }
 
-float MAX17048::vAlertMaxThreshold(void)
+float MAX17048::vAlertMaxThreshold()
 {
     //Read the 16-bit register value
     unsigned short value = read(REG_VALRT);
@@ -335,7 +336,7 @@
     write(REG_VALRT, value);
 }
 
-float MAX17048::vResetThreshold(void)
+float MAX17048::vResetThreshold()
 {
     //Read the 16-bit register value
     unsigned short value = read(REG_VRESET_ID);
@@ -364,7 +365,7 @@
     write(REG_VRESET_ID, value);
 }
 
-bool MAX17048::comparatorEnabled(void)
+bool MAX17048::comparatorEnabled()
 {
     //Read the 16-bit register value
     unsigned short value = read(REG_VRESET_ID);
@@ -391,7 +392,7 @@
     write(REG_VRESET_ID, value);
 }
 
-char MAX17048::id(void)
+char MAX17048::id()
 {
     //Read the 16-bit register value
     unsigned short value = read(REG_VRESET_ID);
@@ -400,7 +401,7 @@
     return value;
 }
 
-bool MAX17048::vResetAlertEnabled(void)
+bool MAX17048::vResetAlertEnabled()
 {
     //Read the 16-bit register value
     unsigned short value = read(REG_STATUS);
@@ -427,7 +428,7 @@
     write(REG_STATUS, value);
 }
 
-char MAX17048::alertFlags(void)
+char MAX17048::alertFlags()
 {
     //Read the 16-bit register value
     unsigned short value = read(REG_STATUS);
@@ -448,7 +449,7 @@
     write(REG_STATUS, value);
 }
 
-float MAX17048::vcell(void)
+float MAX17048::vcell()
 {
     //Read the 16-bit raw Vcell value
     unsigned short value = read(REG_VCELL);
@@ -457,7 +458,7 @@
     return value * 0.000078125;
 }
 
-float MAX17048::soc(void)
+float MAX17048::soc()
 {
     //Read the 16-bit raw SOC value
     unsigned short value = read(REG_SOC);
@@ -466,7 +467,7 @@
     return value * 0.00390625;
 }
 
-int MAX17048::socInt(void)
+int MAX17048::soc_int()
 {
     //Read the 16-bit raw SOC value
     unsigned short value = read(REG_SOC);
@@ -475,7 +476,7 @@
     return value >> 8;
 }
 
-float MAX17048::crate(void)
+float MAX17048::crate()
 {
     //Read the 16-bit raw C/Rate value
     short value = read(REG_CRATE);
@@ -484,6 +485,18 @@
     return value * 0.208;
 }
 
+MAX17048::operator float()
+{
+    //Return the current floating point SOC reading
+    return soc();
+}
+
+MAX17048::operator int()
+{
+    //Return the current integer SOC reading
+    return soc_int();
+}
+
 unsigned short MAX17048::read(char reg)
 {
     //Create a temporary buffer
--- a/MAX17048.h	Mon Sep 16 22:02:40 2013 +0000
+++ b/MAX17048.h	Thu Nov 07 17:53:44 2013 +0000
@@ -75,15 +75,15 @@
      *   'true' if the device exists on the bus,
      *   'false' if the device doesn't exist on the bus.
      */
-    bool open(void);
+    bool open();
 
     /** Command the MAX17048 to perform a power-on reset
      */
-    void reset(void);
+    void reset();
 
     /** Command the MAX17048 to perform a QuickStart
      */
-    void quickStart(void);
+    void quickStart();
 
     /** Determine whether sleep mode is enabled on the MAX17048
     *
@@ -91,7 +91,7 @@
     *   'true' if sleep mode is enabled,
     *   'false' if sleep mode is disabled.
     */
-    bool sleepEnabled(void);
+    bool sleepEnabled();
 
     /** Enable or disable sleep mode on the MAX17048
      *
@@ -105,13 +105,13 @@
     *   'true' if hibernating,
     *   'false' if not hibernating.
     */
-    bool hibernating(void);
+    bool hibernating();
 
     /** Get the current hibernate threshold of the MAX17048
     *
     * @returns The current hibernate threshold in \%/hr.
     */
-    float hibernateThreshold(void);
+    float hibernateThreshold();
 
     /** Set the hibernate threshold of the MAX17048
      *
@@ -123,7 +123,7 @@
     *
     * @returns The current active threshold in volts.
     */
-    float activeThreshold(void);
+    float activeThreshold();
 
     /** Set the active threshold of the MAX17048
      *
@@ -135,7 +135,7 @@
     *
     * @returns The 16-bit production version.
     */
-    unsigned short version(void);
+    unsigned short version();
 
     /** Set the cell temperature compensation of the MAX17048
      *
@@ -149,7 +149,7 @@
     *   'true' if in sleep mode,
     *   'false' if not in sleep mode.
     */
-    bool sleeping(void);
+    bool sleeping();
 
     /** Enter or exit sleep mode on the MAX17048 (sleep mode must be enabled first)
      *
@@ -163,7 +163,7 @@
     *   'true' if enabled,
     *   'false' if not enabled.
     */
-    bool socChangeAlertEnabled(void);
+    bool socChangeAlertEnabled();
 
     /** Enable or disable the SOC 1% change alert on the MAX17048
      *
@@ -177,17 +177,17 @@
     *   'true' if alerting,
     *   'false' if not alerting.
     */
-    bool alerting(void);
+    bool alerting();
 
     /** Command the MAX17048 to de-assert the ALRT pin
     */
-    void clearAlert(void);
+    void clearAlert();
 
     /** Get the current SOC empty alert threshold of the MAX17048
     *
     * @returns The current SOC empty alert threshold in %.
     */
-    char emptyAlertThreshold(void);
+    char emptyAlertThreshold();
 
     /** Set the SOC empty alert threshold of the MAX17048
      *
@@ -199,7 +199,7 @@
     *
     * @returns The current low voltage alert threshold in volts.
     */
-    float vAlertMinThreshold(void);
+    float vAlertMinThreshold();
 
     /** Set the low voltage alert threshold of the MAX17048
      *
@@ -211,7 +211,7 @@
     *
     * @returns The current high voltage alert threshold in volts.
     */
-    float vAlertMaxThreshold(void);
+    float vAlertMaxThreshold();
 
     /** Set the high voltage alert threshold of the MAX17048
      *
@@ -223,7 +223,7 @@
     *
     * @returns The current reset voltage threshold in volts.
     */
-    float vResetThreshold(void);
+    float vResetThreshold();
 
     /** Set the reset voltage threshold of the MAX17048
      *
@@ -237,7 +237,7 @@
     *   'true' if enabled,
     *   'false' if not enabled.
     */
-    bool comparatorEnabled(void);
+    bool comparatorEnabled();
 
     /** Enable or disable the reset voltage comparator on the MAX17048
      *
@@ -249,7 +249,7 @@
     *
     * @returns The 8-bit ID.
     */
-    char id(void);
+    char id();
 
     /** Determine whether or not the voltage reset alert is enabled on the MAX17048
     *
@@ -257,7 +257,7 @@
     *   'true' if enabled,
     *   'false' if not enabled.
     */
-    bool vResetAlertEnabled(void);
+    bool vResetAlertEnabled();
 
     /** Enable or disable the voltage reset alert on the MAX17048
      *
@@ -269,7 +269,7 @@
     *
     * @returns The current alert flags as AlertFlags enum values OR'd together.
     */
-    char alertFlags(void);
+    char alertFlags();
 
     /** Clear the specified alert flags on the MAX17048
      *
@@ -281,42 +281,38 @@
     *
     * @returns The cell voltage measurement as a float.
     */
-    float vcell(void);
+    float vcell();
 
     /** Get the current state of charge measurement of the MAX17048 as a float
      *
      * @returns The state of charge measurement as a float.
      */
-    float soc(void);
+    float soc();
 
     /** Get the current state of charge measurement of the MAX17048 as an int
      *
      * @returns The state of charge measurement as an int.
      */
-    int socInt(void);
+    int soc_int();
 
     /** Get the current C rate measurement of the MAX17048
      *
      * @returns The C rate measurement as a float.
      */
-    float crate(void);
+    float crate();
 
 #ifdef MBED_OPERATORS
     /** A shorthand for soc()
      *
      * @returns The state of charge measurement as a float.
      */
-    operator float() {
-        return soc();
-    }
+    operator float();
 
-    /** A shorthand for socInt()
+    /** A shorthand for soc_int()
      *
      * @returns The state of charge measurement as an int.
      */
-    operator int() {
-        return socInt();
-    }
+    operator int();
 #endif
 
 private: