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
- Committer:
- Rhyme
- Date:
- 2017-04-26
- Revision:
- 0:cf922a073b7f
- Child:
- 1:238c76a37054
File content as of revision 0:cf922a073b7f:
#ifndef _VCNL4010_H_
#define _VCNL4010_H_
/**
* Register #0 Command Register (0x80)
* bit[7] config_lock
* bit[6] als_data_rdy
* bit[5] prox_data_rdy
* bit[4] als_od
* bit[3] prox_od
* bit[2] als_en
* bit[1] prox_en
* bit[0] selftimed_en
*
* Register #1 Product ID Revision Register (0x81)
* bit[7:4] Product ID
* bit[3:0] Revision ID
*
* Register #2 Rate of Proximity Measurement (0x82)
* bit[7:3] (n/a)
* bit[2:0] Rate of Proximity Measurement
* 000 - 1.95 measurements/s (DEFAULT)
* 001 - 3.960625 measurements/s
* 010 - 7.8125 measurements/s
* 011 - 16.625 measurements/s
* 100 - 31.25 measurements/s
* 101 - 62.5 measurements/s
* 110 - 125 measurements/s
* 111 - 250 measurements/s
*
* Register #3 LED Current Setting for Proximity Mode (0x83)
* bit[7:6] Fuse prog ID
* bit[5:0] IR LED current value
* IR LED current = value(dec.) x 10mA
* Valid Range = 0 to 20d.
* 0 = 0mA, 1 = 10mA .. 20 = 200mA ((DEFAULT: 2 = 20mA)
*
* Register #4 Ambient Light Parameter Register (0x84)
* bit[7] Continuous conversion mode 0: Disable = DEFAULT 1: Enable
* bit[6:4] als_rate
* bit[3] Auto offset compensation 0: Disable 1: Enable = DEFAULT
* bit[2:0] Averaging function (number of measurements per run)
* als_rate Ambient light measurement rate
* 000 - 1 samples/s
* 001 - 2 samples/s = DEFUAULT
* 010 - 3 samples/s
* 011 - 4 samples/s
* 100 - 5 samples/s
* 101 - 6 samples/s
* 110 - 8 samples/s
* 111 - 10 samples/s
* Averaging function
* Number of conversions = 2^decimal_value
* 0 = 1 conv, 1 = 2 conv, 2 = 4 conv, .. t = 32 conv (DEFAULT) .. 7 = 128 conv
*
* Register #5 and #6 Ambient Light Result Register (0x85, 0x86)
* bit[15:8] MSB (address 0x85)
* bit[7:0] LSB (address 0x86)
*
* Register #7 and #8 Proximity Measurement Result Register (0x87, 0x88)
* bit[15:8] MSB (address 0x87)
* bit[7:0] LSB (address 0x88)
*
* Register #9 Interrupt Control Register (0x89)
* bit[7:5] Interrupt Count Exceed
* bit[4] (n/a)
* bit[3] INT_PROX_ready_EN Eneables interrupt generation at proximity data ready
* bit[2] INT_ALS_ready_EN Enables interrupt generation at ambient data ready
* bit[1] INT_THRES_EN Enables interrupt generation when high or low threshold is exceeded
* bit[0] INT_THRES_SEL Thresholds are applied to 0:proximity 1:als measurement
* Interrupt Count Exceed
* 000 - 1 count = DEFAULT
* 001 - 2 count
* 010 - 4 count
* 011 - 8 count
* 100 - 16 count
* 101 - 32 count
* 110 - 64 count
* 111 - 128 count
*
* Register #10 and #11 Low Threshold (0x8A, 0x8B)
* bit[15:8] MSB (address 0x8A)
* bit[7:0] LSB (address 0x8B)
*
* Register #12 and #13 High Threshold (0x8C, 0x8D)
* bit[15:8] MSB (address 0x8C)
* bit[7:0] LSB (address 0x8D)
*
* Register #14 Interrupt Status (0x8E)
* bit[7:4] (n/a)
* bit[3] int_prox_ready
* bit[2] int_als_ready
* bit[1] int_th_low
* bit[0] int_th_hi
* Once an interrupt is generated the corresponding status bit
* goes to 1 and stays there unless it is cleared by writing a 1
* in the corresponding bit.
*
* Register #15 Proximity Modulator Timing Adjustment (0x8F)
* bit[7:5] Modulation delay time
* bit[4:3] Proximity frequency
* bit[2:0] Modulation deat time
* The settings for best performance will be provided by Vishay.
* With first samples this is evaluated to:
* delay time = 0
* frequency = 0
* deat time = 1
* With that Register #15 should be programmed with 1 (= default value).
*
*/
class VCNL4010
{
public:
/**
* VCNL4010 constructor
*
* @param sda SDA pin
* @param sdl SCL pin
* @param addr addr of the I2C peripheral
*/
VCNL4010(PinName sda, PinName scl, int addr);
/**
* VCNL4010 destructor
*/
~VCNL4010();
uint8_t getCommandReg(void) ;
void setCommandReg(uint8_t cmd) ;
uint8_t getProductID(void) ;
uint8_t getProxRate(void) ;
void setProxRate(uint8_t rate) ;
uint8_t getIrLedCurrent(void) ;
void setIrLedCurrent(uint8_t IrLedCur) ;
uint8_t getAlsParam(void) ;
void setAlsParam(uint8_t param) ;
uint16_t getAls(void) ;
uint16_t getProx(void) ;
uint8_t getIntCtrl(void) ;
void setIntCtrl(uint8_t ctrl) ;
uint16_t getLowThreshold(void) ;
void setLowThreshold(uint16_t thr) ;
uint16_t getHighThreshold(void) ;
void setHighThreshold(uint16_t thr) ;
uint8_t getIntStatus(void) ;
void setIntStatus(uint8_t status) ;
uint8_t getProxModTiming(void) ;
void setProxModTiming(uint8_t timing) ;
private:
I2C m_i2c;
int m_addr;
void readRegs(int addr, uint8_t * data, int len);
void writeRegs(uint8_t * data, int len);
};
#endif /* _VCNL4010_H_ */