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.
VCNL4010.h
00001 #ifndef _VCNL4010_H_ 00002 #define _VCNL4010_H_ 00003 /** 00004 * VCNL4010 Fully Integrated Proximity and Ambient Light Sensor with 00005 * Infrared Emitter, I2C Interface, and Interrupt Function 00006 */ 00007 00008 class VCNL4010 00009 { 00010 public: 00011 /** 00012 * VCNL4010 constructor 00013 * 00014 * @param sda SDA pin 00015 * @param sdl SCL pin 00016 * @param addr addr of the I2C peripheral 00017 */ 00018 VCNL4010(PinName sda, PinName scl, int addr); 00019 00020 /** 00021 * VCNL4010 destructor 00022 */ 00023 ~VCNL4010(); 00024 00025 /** 00026 * Get Command Register 00027 * @param none 00028 * @returns uint8_t command register value (Register #0) 00029 * @note Register #0 Command Register (0x80) 00030 * @note bit[7] config_lock 00031 * @note bit[6] als_data_rdy 00032 * @note bit[5] prox_data_rdy 00033 * @note bit[4] als_od 00034 * @note bit[3] prox_od 00035 * @note bit[2] als_en 00036 * @note bit[1] prox_en 00037 * @note bit[0] selftimed_en 00038 */ 00039 uint8_t getCommandReg(void) ; 00040 00041 /** 00042 * Set Command Register 00043 * @param uint8_t value to set 00044 * @returns none 00045 */ 00046 void setCommandReg(uint8_t cmd) ; 00047 00048 /** 00049 * Get Prodcut ID (and Revision) 00050 * @param none 00051 * @returns Product ID and Revision Register (Register #1) 00052 * @note Register #1 Product ID Revision Register (0x81) 00053 * @note bit[7:4] Product ID 00054 * @note bit[3:0] Revision ID 00055 */ 00056 uint8_t getProductID(void) ; 00057 00058 /** 00059 * Get Rate of Proximity Measurement 00060 * @param none 00061 * @returns Rate of Proximity Measurement (Register #2) 00062 * @note Register #2 Rate of Proximity Measurement (0x82) 00063 * @note bit[7:3] (n/a) 00064 * @note bit[2:0] Rate of Proximity Measurement 00065 * @note 000 - 1.95 measurements/s (DEFAULT) 00066 * @note 001 - 3.960625 measurements/s 00067 * @note 010 - 7.8125 measurements/s 00068 * @note 011 - 16.625 measurements/s 00069 * @note 100 - 31.25 measurements/s 00070 * @note 101 - 62.5 measurements/s 00071 * @note 110 - 125 measurements/s 00072 * @note 111 - 250 measurements/s 00073 */ 00074 uint8_t getProxRate(void) ; 00075 00076 /** 00077 * Set Rate of Proximity Measurement 00078 * @param Rate of Proximity Measurement 00079 * @returns none 00080 */ 00081 void setProxRate(uint8_t rate) ; 00082 00083 /** 00084 * Get IR LED Current Setting for Proximity Mode 00085 * @param none 00086 * @returns IR LED Current Settings (Register #3) 00087 * @note bit[7:6] Fuse prog ID 00088 * @note bit[5:0] IR LED current value 00089 * @note IR LED current = value(dec.) x 10mA 00090 * @note Valid Range = 0 to 20d. 00091 * @note 0 = 0mA, 1 = 10mA .. 20 = 200mA ((DEFAULT: 2 = 20mA) 00092 */ 00093 uint8_t getIrLedCurrent(void) ; 00094 00095 /** 00096 * Set IR LED Current Setting for Proximity Mode 00097 * @param value to set 00098 * @returns none 00099 */ 00100 void setIrLedCurrent(uint8_t IrLedCur) ; 00101 00102 /** 00103 * Get Ambient Light Parameter 00104 * @param none 00105 * @returns Ambient Light Parameter (Register #4) 00106 * @note Register #4 Ambient Light Parameter Register (0x84) 00107 * @note bit[7] Continuous conversion mode 0: Disable = DEFAULT 1: Enable 00108 * @note bit[6:4] als_rate 00109 * @note bit[3] Auto offset compensation 0: Disable 1: Enable = DEFAULT 00110 * @note bit[2:0] Averaging function (number of measurements per run) 00111 * @note als_rate Ambient light measurement rate 00112 * @note 000 - 1 samples/s 00113 * @note 001 - 2 samples/s = DEFUAULT 00114 * @note 010 - 3 samples/s 00115 * @note 011 - 4 samples/s 00116 * @note 100 - 5 samples/s 00117 * @note 101 - 6 samples/s 00118 * @note 110 - 8 samples/s 00119 * @note 111 - 10 samples/s 00120 * @note Averaging function 00121 * @note Number of conversions = 2^decimal_value 00122 * @note 0 = 1 conv, 1 = 2 conv, 2 = 4 conv, .. t = 32 conv (DEFAULT) .. 7 = 128 conv 00123 */ 00124 uint8_t getAlsParam(void) ; 00125 00126 /** 00127 * Set Ambient Light Parameter 00128 * @param uint8_t value to set 00129 * @returns none 00130 */ 00131 void setAlsParam(uint8_t param) ; 00132 00133 /** 00134 * Get Ambient Light Result 00135 * @param none 00136 * @returns uint16_t the value of Ambient Light Result (Register #5, #6) 00137 * @note Register #5 and #6 Ambient Light Result Register (0x85, 0x86) 00138 * @note bit[15:8] MSB (address 0x85) 00139 * @note bit[7:0] LSB (address 0x86) 00140 */ 00141 uint16_t getAls(void) ; 00142 00143 /** 00144 * Get Proximity Measurement Result 00145 * @param none 00146 * @returns uint16_t the value of Proximity Measurement Result (Register #7, #8) 00147 * @note Register #7 and #8 Proximity Measurement Result Register (0x87, 0x88) 00148 * @note bit[15:8] MSB (address 0x87) 00149 * @note bit[7:0] LSB (address 0x88) 00150 */ 00151 uint16_t getProx(void) ; 00152 00153 /** 00154 * Get Interrupt Control Register value 00155 * @param none 00156 * @returns uint8_t the value of Interraupt Control (Register #9) 00157 * @note Register #9 Interrupt Control Register (0x89) 00158 * @note bit[7:5] Interrupt Count Exceed 00159 * @note bit[4] (n/a) 00160 * @note bit[3] INT_PROX_ready_EN Eneables interrupt generation at proximity data ready 00161 * @note bit[2] INT_ALS_ready_EN Enables interrupt generation at ambient data ready 00162 * @note bit[1] INT_THRES_EN Enables interrupt generation when high or low threshold is exceeded 00163 * @note bit[0] INT_THRES_SEL Thresholds are applied to 0:proximity 1:als measurement 00164 * @note Interrupt Count Exceed 00165 * @note 000 - 1 count = DEFAULT 00166 * @note 001 - 2 count 00167 * @note 010 - 4 count 00168 * @note 011 - 8 count 00169 * @note 100 - 16 count 00170 * @note 101 - 32 count 00171 * @note 110 - 64 count 00172 * @note 111 - 128 count 00173 */ 00174 uint8_t getIntCtrl(void) ; 00175 00176 /** 00177 * Set Interrupt Control Register 00178 * @param uint8_t the value to set 00179 * @returns none 00180 */ 00181 void setIntCtrl(uint8_t ctrl) ; 00182 00183 /** 00184 * Get Low Threshold 00185 * @param none 00186 * @returns uint16_t Low Threshold (Register #10, #11) 00187 * @note Register #10 and #11 Low Threshold (0x8A, 0x8B) 00188 * @note bit[15:8] MSB (address 0x8A) 00189 * @note bit[7:0] LSB (address 0x8B) 00190 */ 00191 uint16_t getLowThreshold(void) ; 00192 00193 /** 00194 * Set Low Threshold 00195 * @param uint16_t value to set 00196 * @returns none 00197 */ 00198 void setLowThreshold(uint16_t thr) ; 00199 00200 /** 00201 * Get High Threshold 00202 * @param none 00203 * @returns uint16_t High Threshold (Register #12, #13) 00204 * @note Register #12 and #13 High Threshold (0x8C, 0x8D) 00205 * @note bit[15:8] MSB (address 0x8C) 00206 * @note bit[7:0] LSB (address 0x8D) 00207 */ 00208 uint16_t getHighThreshold(void) ; 00209 00210 /** 00211 * Set High Threshold 00212 * @param uint16_t value to set 00213 * @returns none 00214 */ 00215 void setHighThreshold(uint16_t thr) ; 00216 00217 /** 00218 * Get Interrupt Status 00219 * @param none 00220 * @returns uint8_t Interrupt Status (Register #14) 00221 * @note Register #14 Interrupt Status (0x8E) 00222 * @note bit[7:4] (n/a) 00223 * @note bit[3] int_prox_ready 00224 * @note bit[2] int_als_ready 00225 * @note bit[1] int_th_low 00226 * @note bit[0] int_th_hi 00227 * @note Once an interrupt is generated the corresponding status bit 00228 * @note goes to 1 and stays there unless it is cleared by writing a 1 00229 * @note in the corresponding bit. 00230 */ 00231 uint8_t getIntStatus(void) ; 00232 00233 /** 00234 * Set Interrupt Status 00235 * @param uint8_t value to set 00236 * @returns none 00237 */ 00238 void setIntStatus(uint8_t status) ; 00239 00240 /** 00241 * Get Proximity Modulator Timing Adjustment 00242 * @param none 00243 * @returns Proximity Modulator Timing Adjustment (Register #15) 00244 * @note Register #15 Proximity Modulator Timing Adjustment (0x8F) 00245 * @note bit[7:5] Modulation delay time 00246 * @note bit[4:3] Proximity frequency 00247 * @note bit[2:0] Modulation deat time 00248 * @note The settings for best performance will be provided by Vishay. 00249 * @note With first samples this is evaluated to: 00250 * @note delay time = 0 00251 * @note frequency = 0 00252 * @note deat time = 1 00253 * @note With that Register #15 should be programmed with 1 (= default value). 00254 */ 00255 uint8_t getProxModTiming(void) ; 00256 00257 /** 00258 * Set Proximity Modulator Timing Adjustment 00259 * @param uint8_t value to set 00260 * @returns none 00261 */ 00262 void setProxModTiming(uint8_t timing) ; 00263 00264 private: 00265 I2C m_i2c; 00266 int m_addr; 00267 void readRegs(int addr, uint8_t * data, int len); 00268 void writeRegs(uint8_t * data, int len); 00269 }; 00270 00271 #endif /* _VCNL4010_H_ */
Generated on Fri Jul 15 2022 22:38:25 by
