MSS / VCNL4100

Dependents:   test_VCNL4100 testSensor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers VCNL4100.h Source File

VCNL4100.h

00001 #ifndef _VCNL4100_H_
00002 #define _VCNL4100_H_
00003 /**
00004  * Vishay VCNL4100
00005  * High Sensitivity Long Distance Proximity and
00006  * Ambient Light Sensor with I2C Interface
00007  */
00008  /*
00009  * @code
00010 * @endcode
00011 */
00012 class VCNL4100
00013 {
00014 public:
00015   /**
00016   * VCNL4100 constructor
00017   *
00018   * @param sda SDA pin
00019   * @param sdl SCL pin
00020   * @param addr addr of the I2C peripheral
00021   */
00022   VCNL4100(PinName sda, PinName scl, int addr);
00023 
00024   /**
00025   * VCNL4100 destructor
00026   */
00027   ~VCNL4100();
00028   
00029 /**
00030  * get ALS configuration 
00031  * @param none
00032  * @return uint8_t ALS CONF
00033  *
00034  * @note bit[7:6] ALS_IT ASL integration time setting,
00035  * @note longer integration time has higher sensitivity 
00036  * @note 00=80ms, 01=160ms, 10=320ms, 11=640ms
00037  * @note -
00038  * @note bit[5:4] (reserved)
00039  * @note -
00040  * @note bit[3:2] ALS interrupt persistence setting
00041  * @note 00=1, 01=2, 10=4, 11=8
00042  * @note -
00043  * @note bit[1] ALS_INT_EN 0=ALS interrupt disable, 1=ALS interrupt enable
00044  * @note -
00045  * @note bit[0] ALS_SD 0=ALS power on, 1=ALS Shut Down
00046  */
00047 uint8_t  getAlsConf(void) ;
00048 
00049 /**
00050  * set ALS configuration
00051  * @param uint8_t conf, value to assign
00052  * @returns none
00053  */
00054 void     setAlsConf(uint8_t conf) ;
00055 
00056 /**
00057  * Get ALS high interrupt threshold 
00058  * @param none
00059  * @returns uint16_t ALS high interrupt threshold
00060  */
00061 uint16_t getAlsThdh(void) ;
00062 
00063 /**
00064  * Set ALS high interrupt threshold
00065  * @param uint16_t thdh, value to assign
00066  * @returns none
00067  */
00068 void     setAlsThdh(uint16_t thdh) ;
00069 
00070 /**
00071  * Get ALS low interrupt threshold
00072  * @param none
00073  * @returns uint16_t ALS low interrupt threshold
00074  */
00075 uint16_t getAlsThdl(void) ;
00076 
00077 /**
00078  * Set ALS low interrupt threshold
00079  * @param uint16_t thdl, value to assign
00080  * @returns none
00081  */
00082 void     setAlsThdl(uint16_t thdl) ;
00083 
00084 /**
00085  * Get PS CONF1 and PS CONF2
00086  * @param none
00087  * @returns uint16_t PS_CONF2 as MSB, PS_CONF1 as LSB
00088  */
00089 uint16_t getPsConf12(void) ;
00090 
00091 /**
00092  * Set PS CONF1 and PS CONF2
00093  * @param uint16_t PS_CONF2 as MSB, PS_CONF1 as LSB
00094  * @returns none
00095  */
00096 void     setPsConf12(uint16_t conf12) ;
00097 
00098 /**
00099  * get PS CONF1
00100  * @param none
00101  * @returns Register value of PS_CONF1
00102  *
00103  * @note bit[7:6] PS_Duty PS IRED on/off duty ratio setting
00104  * @note 00=1/5120, 01=1/640, 10=1/80, 11=1/20
00105  * @note -
00106  * @note bit[5:4] PS_IT PS integration time setting
00107  * @note 00=1T, 01=1.3T, 10=1.6T, 11=2T
00108  * @note -
00109  * @note bit[3:2] PS_PERS PS interrupt persistence setting
00110  * @note 00=1, 01=2, 10=3, 11=4
00111  * @note -
00112  * @note bit[1] (reserved)
00113  * @note -
00114  * @note bit[0] PS_SD 0=PS power on, 1=PS shut down
00115  */
00116 uint8_t  getPsConf1(void) ;
00117 
00118 /**
00119  * set PS_CONF1
00120  *
00121  * @param uint8_t conf1 value to set
00122  * @returns none
00123  */
00124 void     setPsConf1(uint8_t conf1) ;
00125 
00126 /**
00127  * get PS_CONF2
00128  *
00129  * @note bit[7:6] PS_ITB PS IT bank setting
00130  * @note 00=1/2T, 01=1T, 10=2T, 11=4T
00131  * @note -
00132  * @note bit[5:4] PS_GAIN
00133  * @note 00=1/4, 01=1/2, 10=1, 11=2
00134  * @note -
00135  * @note bit[3] (reserved)
00136  * @note -
00137  * @note bit[2] PS_SP_INT_EN 
00138  * @note 0 = disable INT function for PS enter/leave sunlight protection mode
00139  * @note 1 = issue INT while PS enter/leave sunlight protection mode.
00140  * @note  While PS enter sunlight protection mode, the PS output will keep 0xFF
00141  * @note -
00142  * @note bit[1] (reserved)
00143  * @note -
00144  * @note bit[0] PS_INT_EN
00145  * @note 0 = PS INT function disable, 1 = PS INT function enable
00146  */
00147 uint8_t  getPsConf2(void) ;
00148 
00149 /**
00150  * set PS_CONF2
00151  *
00152  * @param uint8_t conf2 value to set
00153  * @returns none
00154  */
00155 void     setPsConf2(uint8_t conf2) ;
00156 
00157 /**
00158  * get PS_CONF3 and PS_SPO
00159  *
00160  * @param none
00161  * @returns uint16_t PS_CONF3 as LSB, PS_SPO as MSB
00162  */
00163 uint16_t getPsConf3Spo(void) ;
00164 
00165 /**
00166  * set PS_CONF3 and PS_SPO
00167  * 
00168  * @param uint16_t con3spo PS_CONF3 as LSB, PS_SPO as MSB
00169  * @returns none
00170  */
00171 void     setPsConf3Spo(uint16_t conf3spo) ;
00172 
00173 /**
00174  * get PS_CONF3
00175  *
00176  * @param none
00177  * @returns uint8_t PS_CONF3
00178  *
00179  * @note bit[7:6] PS_AV 
00180  * @note 00=1/2, 01=1/4, 10=1/8, 11=1/16
00181  * @note -
00182  * @note bit[5] PS_AV_EN 
00183  * @note 0= PS average function disable, 1= PS average function enable
00184  * @note -
00185  * @note bit[4] (reserved)
00186  * @note -
00187  * @note bit[3] PS_AF
00188  * @note 0= active force mode disable (normal mode), 1= active force mode enable
00189  * @note -
00190  * @note bit[2] PS_TRIG
00191  * @note 0= no PS active force mode trigger, 1= trigger one time cycle
00192  * @note VCNL4100 output once cycle data every time host writes in "1" to sensor.
00193  * @note The state returns to "0" automatically.
00194  * @note -
00195  * @note bit[1] PS_MPULSE 0= disable, 1= enable
00196  * @note PS multi pulse mode setting; PS multi puse number set by PS_AV[1:0]
00197  * @note -
00198  * @note bit[0] (reserved)
00199  */
00200 uint8_t  getPsConf3(void) ;
00201 
00202 /**
00203  * set PS_CONF3
00204  *
00205  * @param uint8_t conf3 value to set
00206  * @returns none
00207  */
00208 void     setPsConf3(uint8_t conf3) ;
00209 
00210 /**
00211  * get PS_SPO
00212  *
00213  * @param none
00214  * @returns uint8_t PS_SPO
00215  *
00216  * @note Set initial value to "0xA0" or "0x20"
00217  * @note bit[7:0] PS_SPO
00218  * @note Set initial value = 0xA0 (PS_OUT = 0xFF while PS into sunlight protection)
00219  * @note Set initial value = 0x20 (PS_OUT = 0x00 while PS into sunlight protection)
00220  *
00221  */
00222 uint8_t  getSpo(void) ;
00223 
00224 /**
00225  * set PS_SPO
00226  * 
00227  * @param uint8_t spo value to set (0xA0 or 0x20)
00228  * @returns none
00229  */
00230 void     setSpo(uint8_t spo) ;
00231 
00232 /**
00233  * get PS_THDL as LSB and PS_THDH as MSB
00234  *
00235  * @param none
00236  * @return uint16_t PS_THDL as LSB, PS_THDH as MSB
00237  */
00238 uint16_t getPsThd(void) ;
00239 
00240 /**
00241  * set PS_THDL as LSB and PS_THDH as MSB
00242  *
00243  * @param uint16_t PS_THDL as LSB, PS_THDH as MSB
00244  * @returns none
00245  */
00246 void     setPsThd(uint16_t psthd) ;
00247 
00248 /**
00249  * get PS_THDL
00250  * 
00251  * @param none
00252  * @returns uint8_t PS_THDL
00253  *
00254  * @note bit[7:0] PS_THDL 0x00 to 0xFF, PS low interrupt threshold setting
00255  */
00256 uint8_t getPsThdl(void) ;
00257 
00258 /**
00259  * set PS_THDL
00260  *
00261  * @param uint8_t thdl value to set
00262  * @returns none
00263  */
00264 void setPsThdl(uint8_t thdl) ;
00265 
00266 /**
00267  * get PS_THDH
00268  *
00269  * @param none
00270  * @returns uint8_t PS_THDH
00271  *
00272  * @note bit[7:0] PS_THDH 0x00 to 0xFF, PS high interrupt threshold setting
00273  */
00274  uint8_t getPsThdh(void) ;
00275  
00276  /**
00277   * set PS_THDH
00278   *
00279   * @param uint8_t thdh value to set
00280   * @returns none
00281   */
00282 void setPsThdh(uint8_t thdh) ;
00283 
00284 /**
00285  * get PS_DATA
00286  *
00287  * @param none
00288  * @returns uint8_t PS_DATA
00289  *
00290  * @note bit[7:0] 0x00 to 0xFF, PS output data
00291  */
00292 uint8_t  getPsData(void) ;
00293 
00294 /**
00295  * get ALS output data
00296  *
00297  * @param none
00298  * @returns uint16_t ALS output data
00299  */
00300 uint16_t getAlsData(void) ;
00301 
00302 /**
00303  * get INT_FLAG
00304  *
00305  * @param none
00306  * @returns uint8_t INT_FLAG
00307  *
00308  * @note bit[7] PS_SPF_LEAVE, PS leaving protection mode
00309  * @note bit[6] PS_SPF_ENTER, PS entering protection mode
00310  * @note bit[5] ALS_IF_L, ALS crossing low THD INT trigger event
00311  * @note bit[4] ALS_IF_H, ALS crossing high THD INT trigger event
00312  * @note bit[3:2] (reserved)
00313  * @note bit[1] PS_IF_CLOSE, PS rise above PS_THDH INT trigger event
00314  * @note bit[0] PS_IF_AWAY, PS drop below PS_THDL INT trigger event
00315  */
00316 uint8_t  getIntFlag(void) ;
00317     
00318 private:
00319   I2C m_i2c;
00320   int m_addr;
00321   void readRegs(int addr, uint8_t * data, int len);
00322   void writeRegs(uint8_t * data, int len);
00323 
00324 };
00325 
00326 #endif /* _VCNL4100_H_ */