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.
Dependents: LED_Demo LED_Demo2 LED_Demo
Fork of BMP180 by
MAX44000.h
00001 /******************************************************************************* 00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 ******************************************************************************* 00032 */ 00033 00034 #ifndef _MAX44000_H_ 00035 #define _MAX44000_H_ 00036 00037 #include "mbed.h" 00038 00039 /** 00040 * MAX44000 Ambient Light and Infrared Proximity Sensor 00041 * 00042 * @code 00043 * #include <stdio.h> 00044 * #include "mbed.h" 00045 * #include "MAX44000.h" 00046 * 00047 * I2C i2c(I2C_SDA, I2C_SCL); 00048 * MAX44000 max44000(&i2c); 00049 * 00050 * int main(void) { 00051 * 00052 * while(1) { 00053 * if (max44000.init(MAX44000::MODE_ALS_PROX, MAX44000::ALSTIM_1X, MAX44000::ALSPGA_128X, MAX44000::DRV_110) != 0) { 00054 * printf("Error communicating with MAX44000\n"); 00055 * } else { 00056 * printf("Initialized MAX44000\n"); 00057 * break; 00058 * } 00059 * wait(1); 00060 * } 00061 * 00062 * while(1) { 00063 * int alsValue = max44000.readALS(); 00064 * if(alsValue < 0) { 00065 * printf("Error reading ALS value\n"); 00066 * continue; 00067 * } 00068 * 00069 * int proxValue = max44000.readReg(MAX44000::REG_PRX_DATA); 00070 * if(proxValue < 0) { 00071 * printf("Error reading proximity value\n"); 00072 * continue; 00073 * } 00074 * 00075 * printf("ALS = 0x%04X Proximity = 0x%02X\n", alsValue, proxValue); 00076 * wait(1); 00077 * } 00078 * } 00079 * @endcode 00080 */ 00081 class MAX44000 00082 { 00083 00084 public: 00085 00086 /** 00087 * @brief Register Addresses 00088 * @details Enumerated MAX44000 register addresses 00089 */ 00090 typedef enum { 00091 REG_STATUS, ///< Interrupt Status 00092 REG_MAIN_CONFIG, ///< Main Configuration 00093 REG_RX_CONFIG, ///< Receive Configuration 00094 REG_TX_CONFIG, ///< Transmit Configuration 00095 REG_ALS_DATA_HIGH, ///< ADC High Byte (ALS) 00096 REG_ALS_DATA_LOW, ///< ADC Low Byte (ALS) 00097 REG_ALS_UPTHR_HIGH, ///< ALS Upper Threshold (High Byte) 00098 REG_ALS_UPTHR_LOW, ///< ALS Upper Threshold (Low Byte) 00099 REG_ALS_LOTHR_HIGH, ///< ALS Lower Threshold (High Byte) 00100 REG_ALS_LOTHR_LOW, ///< ALS Lower Threshold (Low Byte) 00101 REG_PST, ///< Threshold Persist Timer 00102 REG_PRX_IND, ///< PROX Threshold Indicator 00103 REG_PRX_THR, ///< PROX Threshold 00104 REG_TRIM_GAIN_GREEN, ///< Digital Gain Trim of Green Channel 00105 REG_TRIM_GAIN_IR = 0x0F, ///< Digital Gain Trim of Infrared Channel 00106 REG_PRX_DATA = 0x16 ///< ADC Byte (PROX) 00107 } registers_t; 00108 00109 00110 /** 00111 * @brief Operating Modes 00112 * @details Enumerated MAX44000 operating modes 00113 */ 00114 typedef enum { 00115 MODE_SHUTDOWN, ///< Analog circuits are shut down, but the digital register retains values 00116 MODE_ALS_GMIR, ///< Standard ALS mode, stores difference between green and IR channels 00117 MODE_ALS_G, ///< ALS green channel only 00118 MODE_ALS_IR, ///< Infrared channel only 00119 MODE_ALS_PROX, ///< ALS and PROX are interleaved continuously 00120 MODE_PROX, ///< PROX only 00121 MODE_RSVD_110, ///< Reserved, do not use 00122 MODE_RSVD_111 ///< Reserved, do not use 00123 } modes_t; 00124 00125 00126 /** 00127 * @brief ALS ADC Conversion Time 00128 * @details MAX44000 Ambient Light Sensor ADC Conversion Time 00129 */ 00130 typedef enum { 00131 ALSTIM_1X, ///< 100ms, 16,384 counts, 14 bit resolution 00132 ALSTIM_4X, ///< 25ms, 4096 counts, 12 bit resolution 00133 ALSTIM_16X, ///< 6.25ms, 1024 counts, 10 bit resolution 00134 ALSTIM_64X ///< 1.5625ms, 256 counts, 8 bit resolution 00135 } alstim_t; 00136 00137 00138 /** 00139 * alspga_t - MAX44000 Ambient Light Measurement Gain 00140 */ 00141 typedef enum { 00142 ALSPGA_1X, ///< 0.03125 lux/lsb 00143 ALSPGA_4X, ///< 0.125 lux/lsb 00144 ALSPGA_16X, ///< 0.5 lux/lsb 00145 ALSPGA_128X ///< 4 lux/lsb 00146 } alspga_t; 00147 00148 00149 /** 00150 * @brief LED Driver Current 00151 * @details MAX44000 LED Driver Current Settings 00152 */ 00153 typedef enum { 00154 DRV_0, ///< LED driver disabled 00155 DRV_10, ///< 10mA 00156 DRV_20, ///< 20mA 00157 DRV_30, ///< 30mA 00158 DRV_40, ///< 40mA 00159 DRV_50, ///< 50mA 00160 DRV_60, ///< 60mA 00161 DRV_70, ///< 70mA 00162 DUP_40, ///< 40mA 00163 DUP_50, ///< 50mA 00164 DUP_60, ///< 60mA 00165 DUP_70, ///< 70mA 00166 DRV_80, ///< 80mA 00167 DRV_90, ///< 90mA 00168 DRV_100, ///< 100mA 00169 DRV_110 ///< 110mA 00170 } drive_t; 00171 00172 00173 /** 00174 * @brief Persist Times 00175 * @details MAX44000 ALS/PROX Threshold Persist Timer Settings 00176 */ 00177 typedef enum { 00178 PST_1, ///< 1 trigger before interrupt 00179 PST_2, ///< 2 consecutive triggers before interrupt 00180 PST_4, ///< 4 consecutive triggers before interrupt 00181 PST_16 ///< 16 consecutive triggers before interrupt 00182 } persist_t; 00183 00184 00185 /** 00186 * MAX44000 constructor. 00187 * 00188 * @param sda mbed pin to use for SDA line of I2C interface. 00189 * @param scl mbed pin to use for SCL line of I2C interface. 00190 */ 00191 MAX44000(PinName sda, PinName scl); 00192 00193 /** 00194 * MAX44000 constructor. 00195 * 00196 * @param i2c I2C object to use. 00197 */ 00198 MAX44000(I2C *i2c); 00199 00200 /** 00201 * MAX44000 destructor. 00202 */ 00203 ~MAX44000(); 00204 00205 /** 00206 * @brief Initialize MAX44000. 00207 * @details Gets the device ID and saves the calibration values. 00208 * @param mode Operating Mode 00209 * @param alstim Ambient Light ADC Conversion Time 00210 * @param alspga Ambient Light Measurement Gain 00211 * @param drive LED Driver Current 00212 * @returns 0 if no errors, -1 if error. 00213 */ 00214 int init(MAX44000::modes_t mode, MAX44000::alstim_t alstim, MAX44000::alspga_t alspga, MAX44000::drive_t drive); 00215 00216 /** 00217 * @brief Write Register 00218 * @details Writes data to MAX44000 register 00219 * 00220 * @param reg_addr Register to write 00221 * @param reg_data Data to write 00222 * @returns 0 if no errors, -1 if error. 00223 */ 00224 int writeReg(MAX44000::registers_t reg_addr, char reg_data); 00225 00226 /** 00227 * @brief Read Register 00228 * @details Reads data from MAX44000 register 00229 * 00230 * @param reg_addr Register to read 00231 * @returns data if no errors, -1 if error. 00232 */ 00233 int readReg(MAX44000::registers_t reg_addr); 00234 00235 /** 00236 * @brief Read ALS Data 00237 * @details Reads both ALS data registers and returns combined value 00238 * 00239 * @returns data if no errors, -1 if error. 00240 */ 00241 int readALS(void); 00242 00243 00244 private: 00245 00246 I2C *i2c_; 00247 bool i2c_owner; 00248 00249 }; 00250 00251 #endif /* _MAX44000_H_ */
Generated on Thu Jul 21 2022 14:13:30 by
1.7.2

Ambient Light and Proximity Sensor MAX44000