Library for the MAX44000 Ambient Light Sensor / Proximity Detector

Dependents:   LED_Demo LED_Demo2 LED_Demo

Fork of BMP180 by Kevin Gillepsie

MAX44000 Device Driver

Files at this revision

API Documentation at this revision

Comitter:
switches
Date:
Wed May 04 15:47:32 2016 +0000
Parent:
0:b2219e6e444b
Child:
2:91f97c274e89
Commit message:
Initial Commit of MAX44000 Library

Changed in this revision

BMP180.cpp Show diff for this revision Revisions of this file
BMP180.h Show diff for this revision Revisions of this file
MAX44000.cpp Show annotated file Show diff for this revision Revisions of this file
MAX44000.h Show annotated file Show diff for this revision Revisions of this file
--- a/BMP180.cpp	Fri Apr 17 09:31:09 2015 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,268 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2015 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 "BMP180.h"
-
-/***** Definitions *****/
-#define I2C_ADDR            (0xEE) // 1110111x
-
-#define REG_ADDR_RESET      (0xE0)
-#define REG_ADDR_ID         (0xD0)
-#define REG_ADDR_CTRL       (0xF4)
-#define REG_ADDR_DATA       (0xF6)
-#define REG_ADDR_AC1        (0xAA)
-
-#define CTRL_REG_TEMP       (0x2E)
-#define CTRL_REG_PRESS_0    (0x34)
-#define CTRL_REG_PRESS_1    (0x74)
-#define CTRL_REG_PRESS_2    (0xB4)
-#define CTRL_REG_PRESS_3    (0xF4)
-
-//******************************************************************************
-BMP180::BMP180(PinName sda, PinName scl)
-{
-    i2c_ = new I2C(sda, scl);
-    i2c_owner = true;
-
-    i2c_->frequency(400000);
-}
-
-//******************************************************************************
-BMP180::BMP180(I2C *i2c) :
-    i2c_(i2c)
-{
-    i2c_owner = false;
-}
-
-//******************************************************************************
-BMP180::~BMP180()
-{
-    if(i2c_owner) {
-        delete i2c_;
-    }
-}
-
-//******************************************************************************
-int BMP180::init(void)
-{
-    char addr;
-    char data[22];
-    int i;
-
-    if (checkId() != 0) {
-        return -1;
-    }
-
-    addr = REG_ADDR_AC1;
-    if (i2c_->write(I2C_ADDR, &addr, 1) != 0) {
-        return -1;
-    }
-
-    if (i2c_->read(I2C_ADDR, data, 22) != 0) {
-        return -1;
-    }
-
-    for (i = 0; i < 11; i++) {
-        calib.value[i] = (data[2*i] << 8) | data[(2*i)+1];
-    }
-
-    return 0;
-}
-
-//******************************************************************************
-int BMP180::reset(void)
-{
-    char data;
-
-    data = REG_ADDR_RESET;
-    if (i2c_->write(I2C_ADDR, &data, 1) != 0) {
-        return -1;
-    }
-
-    data = 0xB6;
-    if (i2c_->write(I2C_ADDR, &data, 1) != 0) {
-        return -1;
-    }
-
-    return 0;
-}
-
-//******************************************************************************
-int BMP180::checkId(void)
-{
-    char addr;
-    char data;
-
-    addr = REG_ADDR_ID;
-    if (i2c_->write(I2C_ADDR, &addr, 1) != 0) {
-        return -1;
-    }
-
-    if (i2c_->read(I2C_ADDR, &data, 1) != 0) {
-        return -1;
-    }
-
-    if (data != 0x55) {
-        return -1;
-    }
-
-    return 0;
-}
-
-//******************************************************************************
-int BMP180::startPressure(BMP180::oversampling_t oss)
-{
-    char data[2];
-
-    data[0] = REG_ADDR_CTRL;
-    data[1] = CTRL_REG_PRESS_0 | ((oss & 0x3) << 6);
-    oss_ = oss;
-
-    if (i2c_->write(I2C_ADDR, data, 2) != 0) {
-        return -1;
-    }
-
-    return 0;
-}
-
-//******************************************************************************
-int BMP180::getPressure(int *pressure)
-{
-    char addr, byte[3];
-    uint32_t up;
-    int32_t b6, x1, x2, x3, b3, p;
-    uint32_t b4, b7;
-
-    addr = REG_ADDR_DATA;
-    if (i2c_->write(I2C_ADDR, &addr, 1) != 0) {
-        return -1;
-    }
-
-    if (i2c_->read(I2C_ADDR, byte, 3) != 0) {
-        return -1;
-    }
-
-    up = ((byte[0] << 16) | (byte[1] << 8) | byte[2]) >> (8 - oss_);
-
-    b6 = b5 - 4000;
-    x1 = (b6 * b6) >> 12;
-    x1 *= calib.b2;
-    x1 >>= 11;
-    x2 = calib.ac2 * b6;
-    x2 >>= 11;
-    x3 = x1 + x2;
-    b3 = (((((int32_t)calib.ac1) * 4 + x3) << oss_) + 2);
-    b3 >>= 2;
-
-    x1 = (calib.ac3 * b6) >> 13;
-    x2 = (calib.b1 * ((b6 * b6) >> 12)) >> 16;
-    x3 = (x1 + x2 + 2) >> 2;
-    b4 = (calib.ac4 * (uint32_t)(x3 + 32768)) >> 15;
-    b7 = ((uint32_t)up - b3) * (50000 >> oss_);
-    p = ((b7 < 0x80000000) ? ((b7 << 1) / b4) : ((b7 / b4) * 2));
-    x1 = p >> 8;
-    x1 *= x1;
-    x1 = (x1 * 3038) >> 16;
-    x2 = (-7357 * p) >> 16;
-    p += (x1 + x2 + 3791) >> 4;
-
-    *pressure = p;
-
-    return 0;
-}
-
-//******************************************************************************
-int BMP180::startTemperature(void)
-{
-    char data[2] = { REG_ADDR_CTRL, CTRL_REG_TEMP };
-
-    if (i2c_->write(I2C_ADDR, data, 2) != 0) {
-        return -1;
-    }
-
-    return 0;
-}
-
-//******************************************************************************
-int BMP180::getTemperature(float *tempC)
-{
-    char addr, byte[2];
-    uint16_t ut;
-    int32_t x1, x2;
-
-    addr = REG_ADDR_DATA;
-    if (i2c_->write(I2C_ADDR, &addr, 1) != 0) {
-        return -1;
-    }
-
-    if (i2c_->read(I2C_ADDR, byte, 2) != 0) {
-        return -1;
-    }
-
-    ut = (byte[0] << 8) | byte[1];
-
-    x1 = ((ut - calib.ac6) * calib.ac5) >> 15;
-    x2 = (calib.mc << 11) / (x1 + calib.md);
-    b5 = x1 + x2;
-
-    *tempC = (float)(b5 + 8) / 160;
-
-    return 0;
-}
-
-//******************************************************************************
-int BMP180::getTemperature(int16_t *tempCx10)
-{
-    char addr, byte[2];
-    uint16_t ut;
-    int32_t x1, x2;
-
-    addr = REG_ADDR_DATA;
-    if (i2c_->write(I2C_ADDR, &addr, 1) != 0) {
-        return -1;
-    }
-
-    if (i2c_->read(I2C_ADDR, byte, 2) != 0) {
-        return -1;
-    }
-
-    ut = (byte[0] << 8) | byte[1];
-
-    x1 = ((ut - calib.ac6) * calib.ac5) >> 15;
-    x2 = (calib.mc << 11) / (x1 + calib.md);
-    b5 = x1 + x2;
-
-    *tempCx10 = (b5 + 8) >> 4;
-
-    return 0;
-}
--- a/BMP180.h	Fri Apr 17 09:31:09 2015 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,230 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2015 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 _BMP180_H_
-#define _BMP180_H_
-
-#include "mbed.h"
-
-/**
- * Bosch BMP180 Digital Pressure Sensor
- *
- * @code
- * #include <stdio.h>
- * #include "mbed.h"
- * #include "BMP180.h"
- *
- * I2C i2c(I2C_SDA, I2C_SCL);
- * BMP180 bmp180(&i2c);
- *
- * int main(void) {
- *
- *     while(1) {
- *         if (bmp180.init() != 0) {
- *             printf("Error communicating with BMP180\n");
- *         } else {
- *             printf("Initialized BMP180\n");
- *             break;
- *         }
- *         wait(1);
- *     }
- *
- *     while(1) {
- *         bmp180.startTemperature();
- *         wait_ms(5);     // Wait for conversion to complete
- *         float temp;
- *         if(bmp180.getTemperature(&temp) != 0) {
- *             printf("Error getting temperature\n");
- *             continue;
- *         }
- *
- *         bmp180.startPressure(BMP180::ULTRA_LOW_POWER);
- *         wait_ms(10);    // Wait for conversion to complete
- *         int pressure;
- *         if(bmp180.getPressure(&pressure) != 0) {
- *             printf("Error getting pressure\n");
- *             continue;
- *         }
- *
- *         printf("Pressure = %d Pa Temperature = %f C\n", pressure, temp);
- *         wait(1);
- *     }
- * }
- * @endcode
- */
-class BMP180
-{
-
-public:
-
-    /**
-     * @brief   Oversampling ratio.
-     * @details Dictates how many pressure samples to take. Conversion time varies
-     *          depending on the number of samples taken. Refer to data sheet
-     *          for timing specifications.
-     */
-    typedef enum {
-        ULTRA_LOW_POWER       = 0, ///< 1 pressure sample
-        STANDARD              = 1, ///< 2 pressure samples
-        HIGH_RESOLUTION       = 2, ///< 4 pressure samples
-        ULTRA_HIGH_RESOLUTION = 3, ///< 8 pressure samples
-    } oversampling_t;
-
-    /**
-     * BMP180 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.
-     */
-    BMP180(PinName sda, PinName scl);
-
-    /**
-     * BMP180 constructor.
-     *
-     * @param i2c I2C object to use.
-     */
-    BMP180(I2C *i2c);
-
-    /**
-     * BMP180 destructor.
-     */
-    ~BMP180();
-
-    /**
-     * @brief   Initialize BMP180.
-     * @details Gets the device ID and saves the calibration values.
-     * @returns 0 if no errors, -1 if error.
-     */
-    int init(void);
-
-    /**
-     * @brief   Reset BMP180.
-     * @details Performs a soft reset of the device. Same sequence as power on reset.
-     * @returns 0 if no errors, -1 if error.
-     */
-    int reset(void);
-
-    /**
-     * @brief   Check ID.
-     * @details Checks the device ID, should be 0x55 on reset.
-     * @returns 0 if no errors, -1 if error.
-     */
-    int checkId(void);
-
-    /**
-     * @brief   Start pressure conversion.
-     * @details Initiates the pressure conversion sequence. Refer to data sheet
-     *          for timing specifications.
-     *
-     * @param   oss Number of samples to take.
-     * @returns 0 if no errors, -1 if error.
-     */
-    int startPressure(BMP180::oversampling_t oss);
-
-    /**
-     * @brief   Get pressure reading.
-     * @details Calculates the pressure using the data calibration data and formula.
-     *          Pressure is reported in Pascals.
-     * @note    This function should be called after calling startPressure().
-     *          Refer to the data sheet for the timing requirements. Calling this
-     *          function too soon can result in oversampling.
-     *
-     * @param   pressure Pointer to store pressure reading.
-     * @returns 0 if no errors, -1 if error.
-     */
-    int getPressure(int *pressure);
-
-    /**
-     * @brief   Start temperature conversion.
-     * @details Initiates the temperature conversion sequence. Refer to data
-     *          sheet for timing specifications.
-     * @returns 0 if no errors, -1 if error.
-     */
-    int startTemperature(void);
-
-    /**
-     * @brief   Get temperature reading.
-     * @details Calculates the temperature using the data calibration data and formula.
-     *          Temperature is reported in degrees Celcius.
-     *
-     * @note    This function should be called after calling startTemperature().
-     *          Refer to the data sheet for the timing requirements. Calling this
-     *          function too soon can result in oversampling.
-     *
-     * @param   tempC Pointer to store temperature reading.
-     * @returns 0 if no errors, -1 if error.
-     */
-    int getTemperature(float *tempC);
-
-    /**
-     * @brief   Get temperature reading.
-     * @details Calculates the temperature using the data calibration data and formula.
-     *          Temperature is reported in 1/10ths degrees Celcius.
-     *
-     * @note    This function should be called after calling startTemperature().
-     *          Refer to the data sheet for the timing requirements. Calling this
-     *          function too soon can result in oversampling.
-     *
-     * @param   tempCx10 Pointer to store temperature reading.
-     * @returns 0 if no errors, -1 if error.
-     */
-    int getTemperature(int16_t *tempCx10);
-
-private:
-
-    typedef union {
-        uint16_t value[11];
-        struct {
-            int16_t ac1;
-            int16_t ac2;
-            int16_t ac3;
-            uint16_t ac4;
-            uint16_t ac5;
-            uint16_t ac6;
-            int16_t b1;
-            int16_t b2;
-            int16_t mb;
-            int16_t mc;
-            int16_t md;
-        };
-    } calibration_t;
-
-    I2C *i2c_;
-    bool i2c_owner;
-
-    BMP180::calibration_t calib;
-    int32_t b5;
-    BMP180::oversampling_t oss_;
-};
-
-#endif /* _BMP180_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX44000.cpp	Wed May 04 15:47:32 2016 +0000
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * 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 "MAX44000.h"
+
+/***** Definitions *****/
+#define I2C_ADDR            (0x94) // 1001_010x
+
+//******************************************************************************
+MAX44000::MAX44000(PinName sda, PinName scl)
+{
+    i2c_ = new I2C(sda, scl);
+    i2c_owner = true;
+
+    i2c_->frequency(400000);
+}
+
+//******************************************************************************
+MAX44000::MAX44000(I2C *i2c) :
+    i2c_(i2c)
+{
+    i2c_owner = false;
+}
+
+//******************************************************************************
+MAX44000::~MAX44000()
+{
+    if(i2c_owner) {
+        delete i2c_;
+    }
+}
+
+//******************************************************************************
+int MAX44000::init(MAX44000::modes_t mode, MAX44000::alstim_t alstim, MAX44000::alspga_t alspga, MAX44000::drive_t drive)
+{
+    char data[2];
+
+    data[0] = REG_RX_CONFIG;
+    data[1] = 0xF0 | ((alstim & 0x03)<<2) | (alspga & 0x03);
+    if (i2c_->write(I2C_ADDR, data, 2) != 0) {
+        return -1;
+    }
+
+    data[0] = REG_TX_CONFIG;
+    data[1] = (drive & 0x0F);
+    if (i2c_->write(I2C_ADDR, data, 2) != 0) {
+        return -1;
+    }
+
+    data[0] = REG_MAIN_CONFIG;
+    data[1] = ((mode & 0x07)<<2);
+    if (i2c_->write(I2C_ADDR, data, 2) != 0) {
+        return -1;
+    }
+
+    return 0;
+}
+
+//******************************************************************************
+int MAX44000::writeReg(MAX44000::registers_t reg_addr, char reg_data)
+{
+    char data[2];
+
+    data[0] = reg_addr;
+    data[1] = reg_data;
+    if (i2c_->write(I2C_ADDR, data, 2) != 0) {
+        return -1;
+    }
+
+    return 0;
+}
+
+//******************************************************************************
+int MAX44000::readReg(MAX44000::registers_t reg_addr)
+{
+    char data;
+
+    data = reg_addr;
+    if (i2c_->write(I2C_ADDR, &data, 1, true) != 0) {
+        return -1;
+    }
+
+    if (i2c_->read(I2C_ADDR, &data, 1) != 0) {
+        return -1;
+    }
+
+    return (0x0 + data);
+}
+
+//******************************************************************************
+int MAX44000::readALS(void)
+{
+    char data;
+    int alsData;
+
+    data = REG_ALS_DATA_HIGH;
+    if (i2c_->write(I2C_ADDR, &data, 1, true) != 0) {
+        return -1;
+    }
+
+    if (i2c_->read(I2C_ADDR, &data, 1, true) != 0) {  // must use repeated start to protect low byte data
+        return -1;
+    }
+
+    if (data & 0x40) { // if the overflow bit is set
+        return -1;
+    }
+    
+    alsData = (data << 8);
+    data = REG_ALS_DATA_LOW;
+    if (i2c_->write(I2C_ADDR, &data, 1, true) != 0) {
+        return -1;
+    }
+
+    if (i2c_->read(I2C_ADDR, &data, 1) != 0) {
+        return -1;
+    }
+
+    alsData += data;
+    return alsData;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX44000.h	Wed May 04 15:47:32 2016 +0000
@@ -0,0 +1,251 @@
+/*******************************************************************************
+ * 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 _MAX44000_H_
+#define _MAX44000_H_
+
+#include "mbed.h"
+
+/**
+ * Bosch MAX44000 Digital Pressure Sensor
+ *
+ * @code
+ * #include <stdio.h>
+ * #include "mbed.h"
+ * #include "MAX44000.h"
+ *
+ * I2C i2c(I2C_SDA, I2C_SCL);
+ * MAX44000 max44000(&i2c);
+ *
+ * int main(void) {
+ *
+ *     while(1) {
+ *         if (max44000.init(MAX44000::MODE_ALS_PROX, MAX44000::ALSTIM_1X, MAX44000::ALSPGA_128X, MAX44000::DRV_110) != 0) {
+ *             printf("Error communicating with MAX44000\n");
+ *         } else {
+ *             printf("Initialized MAX44000\n");
+ *             break;
+ *         }
+ *         wait(1);
+ *     }
+ *
+ *     while(1) {
+ *         int alsValue = max44000.readALS();
+ *         if(alsValue < 0) {
+ *             printf("Error reading ALS value\n");
+ *             continue;
+ *         }
+ *
+ *         int proxValue = max44000.readReg(MAX44000::REG_PRX_DATA);
+ *         if(proxValue < 0) {
+ *             printf("Error reading proximity value\n");
+ *             continue;
+ *         }
+ *
+ *         printf("ALS = 0x%04X  Proximity = 0x%02X\n", alsValue, proxValue);
+ *         wait(1);
+ *     }
+ * }
+ * @endcode
+ */
+class MAX44000
+{
+
+public:
+
+    /**
+     * @brief   Register Addresses
+     * @details Enumerated MAX44000 register addresses
+     */
+    typedef enum {
+        REG_STATUS,         // Interrupt Status
+        REG_MAIN_CONFIG,    // Main Configuration
+        REG_RX_CONFIG,      // Receive Configuration
+        REG_TX_CONFIG,      // Transmit Configuration
+        REG_ALS_DATA_HIGH,  // ADC High Byte (ALS)
+        REG_ALS_DATA_LOW,   // ADC Low Byte (ALS)
+        REG_ALS_UPTHR_HIGH, // ALS Upper Threshold (High Byte)
+        REG_ALS_UPTHR_LOW,  // ALS Upper Threshold (Low Byte)
+        REG_ALS_LOTHR_HIGH, // ALS Lower Threshold (High Byte)
+        REG_ALS_LOTHR_LOW,  // ALS Lower Threshold (Low Byte)
+        REG_PST,            // Threshold Persist Timer
+        REG_PRX_IND,        // PROX Threshold Indicator
+        REG_PRX_THR,        // PROX Threshold
+        REG_TRIM_GAIN_GREEN,// Digital Gain Trim of Green Channel
+        REG_TRIM_GAIN_IR = 0x0F, // Digital Gain Trim of Infrared Channel
+        REG_PRX_DATA     = 0x16  // ADC Byte (PROX)
+    } registers_t;
+
+
+    /**
+     * @brief   Operating Modes
+     * @details Enumerated MAX44000 operating modes
+     */
+    typedef enum {
+        MODE_SHUTDOWN, // Analog circuits are shut down, but the digital register retains values
+        MODE_ALS_GMIR, // Standard ALS mode, stores difference between green and IR channels
+        MODE_ALS_G,    // ALS green channel only
+        MODE_ALS_IR,   // Infrared channel only
+        MODE_ALS_PROX, // ALS and PROX are interleaved continuously
+        MODE_PROX,     // PROX only
+        MODE_RSVD_110, // Reserved, do not use
+        MODE_RSVD_111  // Reserved, do not use
+    } modes_t;
+
+
+    /**
+     * @brief   ALS ADC Conversion Time
+     * @details MAX44000 Ambient Light Sensor ADC Conversion Time
+     */
+    typedef enum {
+        ALSTIM_1X,  // 100ms, 16,384 counts, 14 bit resolution
+        ALSTIM_4X,  // 25ms,    4096 counts, 12 bit resolution
+        ALSTIM_16X, // 6.25ms,  1024 counts, 10 bit resolution
+        ALSTIM_64X  // 1.5625ms, 256 counts,  8 bit resolution
+    } alstim_t;
+
+
+    /**
+    * alspga_t - MAX44000 Ambient Light Measurement Gain
+    */
+    typedef enum {
+        ALSPGA_1X,  // 0.03125 lux/lsb
+        ALSPGA_4X,  // 0.125 lux/lsb
+        ALSPGA_16X, // 0.5 lux/lsb
+        ALSPGA_128X // 4 lux/lsb
+    } alspga_t;
+
+
+    /**
+     * @brief   LED Driver Current
+     * @details MAX44000 LED Driver Current Settings
+     */
+    typedef enum {
+        DRV_0,   // LED driver disabled
+        DRV_10,  // 10mA
+        DRV_20,  // 20mA
+        DRV_30,  // 30mA
+        DRV_40,  // 40mA
+        DRV_50,  // 50mA
+        DRV_60,  // 60mA
+        DRV_70,  // 70mA
+        DUP_40,  // 40mA
+        DUP_50,  // 50mA
+        DUP_60,  // 60mA
+        DUP_70,  // 70mA
+        DRV_80,  // 80mA
+        DRV_90,  // 90mA
+        DRV_100, // 100mA
+        DRV_110  // 110mA
+    } drive_t;
+
+
+    /**
+     * @brief   Persist Times
+     * @details MAX44000 ALS/PROX Threshold Persist Timer Settings
+     */
+    typedef enum {
+        PST_1, // 1 trigger before interrupt
+        PST_2, // 2 consecutive triggers before interrupt
+        PST_4, // 4 consecutive triggers before interrupt
+        PST_16 // 16 consecutive triggers before interrupt
+    } persist_t;
+
+
+    /**
+     * MAX44000 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.
+     */
+    MAX44000(PinName sda, PinName scl);
+
+    /**
+     * MAX44000 constructor.
+     *
+     * @param i2c I2C object to use.
+     */
+    MAX44000(I2C *i2c);
+
+    /**
+     * MAX44000 destructor.
+     */
+    ~MAX44000();
+
+    /**
+     * @brief   Initialize MAX44000.
+     * @details Gets the device ID and saves the calibration values.
+     * @param   mode Operating Mode
+     * @param   alstim Ambient Light ADC Conversion Time
+     * @param   alspga Ambient Light Measurement Gain
+     * @param   drive LED Driver Current
+     * @returns 0 if no errors, -1 if error.
+     */
+    int init(MAX44000::modes_t mode, MAX44000::alstim_t alstim, MAX44000::alspga_t alspga, MAX44000::drive_t drive); 
+
+    /**
+     * @brief   Write Register
+     * @details Writes data to MAX44000 register
+     *
+     * @param   reg_addr Register to write
+     * @param   reg_data Data to write
+     * @returns 0 if no errors, -1 if error.
+     */
+    int writeReg(MAX44000::registers_t reg_addr, char reg_data);
+
+    /**
+     * @brief   Read Register
+     * @details Reads data from MAX44000 register
+     *
+     * @param   reg_addr Register to read
+     * @returns data if no errors, -1 if error.
+     */
+    int readReg(MAX44000::registers_t reg_addr);
+
+    /**
+     * @brief   Read ALS Data
+     * @details Reads both ALS data registers and returns combined value
+     *
+     * @returns data if no errors, -1 if error.
+     */
+    int readALS(void);
+
+
+private:
+
+    I2C *i2c_;
+    bool i2c_owner;
+
+};
+
+#endif /* _MAX44000_H_ */