Vishay VCNL4010 Fully Integrated Proximity and Ambient Light Sensor with Infrared Emitter, I2C Interface, and Interrupt Function

Dependents:   test_VCNL4010

Committer:
Rhyme
Date:
Wed Apr 26 09:39:24 2017 +0000
Revision:
1:238c76a37054
Parent:
0:cf922a073b7f
Documentation added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:cf922a073b7f 1 #ifndef _VCNL4010_H_
Rhyme 0:cf922a073b7f 2 #define _VCNL4010_H_
Rhyme 0:cf922a073b7f 3 /**
Rhyme 1:238c76a37054 4 * VCNL4010 Fully Integrated Proximity and Ambient Light Sensor with
Rhyme 1:238c76a37054 5 * Infrared Emitter, I2C Interface, and Interrupt Function
Rhyme 0:cf922a073b7f 6 */
Rhyme 1:238c76a37054 7
Rhyme 0:cf922a073b7f 8 class VCNL4010
Rhyme 0:cf922a073b7f 9 {
Rhyme 0:cf922a073b7f 10 public:
Rhyme 0:cf922a073b7f 11 /**
Rhyme 0:cf922a073b7f 12 * VCNL4010 constructor
Rhyme 0:cf922a073b7f 13 *
Rhyme 0:cf922a073b7f 14 * @param sda SDA pin
Rhyme 0:cf922a073b7f 15 * @param sdl SCL pin
Rhyme 0:cf922a073b7f 16 * @param addr addr of the I2C peripheral
Rhyme 0:cf922a073b7f 17 */
Rhyme 0:cf922a073b7f 18 VCNL4010(PinName sda, PinName scl, int addr);
Rhyme 0:cf922a073b7f 19
Rhyme 0:cf922a073b7f 20 /**
Rhyme 0:cf922a073b7f 21 * VCNL4010 destructor
Rhyme 0:cf922a073b7f 22 */
Rhyme 0:cf922a073b7f 23 ~VCNL4010();
Rhyme 1:238c76a37054 24
Rhyme 1:238c76a37054 25 /**
Rhyme 1:238c76a37054 26 * Get Command Register
Rhyme 1:238c76a37054 27 * @param none
Rhyme 1:238c76a37054 28 * @returns uint8_t command register value (Register #0)
Rhyme 1:238c76a37054 29 * @note Register #0 Command Register (0x80)
Rhyme 1:238c76a37054 30 * @note bit[7] config_lock
Rhyme 1:238c76a37054 31 * @note bit[6] als_data_rdy
Rhyme 1:238c76a37054 32 * @note bit[5] prox_data_rdy
Rhyme 1:238c76a37054 33 * @note bit[4] als_od
Rhyme 1:238c76a37054 34 * @note bit[3] prox_od
Rhyme 1:238c76a37054 35 * @note bit[2] als_en
Rhyme 1:238c76a37054 36 * @note bit[1] prox_en
Rhyme 1:238c76a37054 37 * @note bit[0] selftimed_en
Rhyme 1:238c76a37054 38 */
Rhyme 0:cf922a073b7f 39 uint8_t getCommandReg(void) ;
Rhyme 1:238c76a37054 40
Rhyme 1:238c76a37054 41 /**
Rhyme 1:238c76a37054 42 * Set Command Register
Rhyme 1:238c76a37054 43 * @param uint8_t value to set
Rhyme 1:238c76a37054 44 * @returns none
Rhyme 1:238c76a37054 45 */
Rhyme 0:cf922a073b7f 46 void setCommandReg(uint8_t cmd) ;
Rhyme 1:238c76a37054 47
Rhyme 1:238c76a37054 48 /**
Rhyme 1:238c76a37054 49 * Get Prodcut ID (and Revision)
Rhyme 1:238c76a37054 50 * @param none
Rhyme 1:238c76a37054 51 * @returns Product ID and Revision Register (Register #1)
Rhyme 1:238c76a37054 52 * @note Register #1 Product ID Revision Register (0x81)
Rhyme 1:238c76a37054 53 * @note bit[7:4] Product ID
Rhyme 1:238c76a37054 54 * @note bit[3:0] Revision ID
Rhyme 1:238c76a37054 55 */
Rhyme 0:cf922a073b7f 56 uint8_t getProductID(void) ;
Rhyme 1:238c76a37054 57
Rhyme 1:238c76a37054 58 /**
Rhyme 1:238c76a37054 59 * Get Rate of Proximity Measurement
Rhyme 1:238c76a37054 60 * @param none
Rhyme 1:238c76a37054 61 * @returns Rate of Proximity Measurement (Register #2)
Rhyme 1:238c76a37054 62 * @note Register #2 Rate of Proximity Measurement (0x82)
Rhyme 1:238c76a37054 63 * @note bit[7:3] (n/a)
Rhyme 1:238c76a37054 64 * @note bit[2:0] Rate of Proximity Measurement
Rhyme 1:238c76a37054 65 * @note 000 - 1.95 measurements/s (DEFAULT)
Rhyme 1:238c76a37054 66 * @note 001 - 3.960625 measurements/s
Rhyme 1:238c76a37054 67 * @note 010 - 7.8125 measurements/s
Rhyme 1:238c76a37054 68 * @note 011 - 16.625 measurements/s
Rhyme 1:238c76a37054 69 * @note 100 - 31.25 measurements/s
Rhyme 1:238c76a37054 70 * @note 101 - 62.5 measurements/s
Rhyme 1:238c76a37054 71 * @note 110 - 125 measurements/s
Rhyme 1:238c76a37054 72 * @note 111 - 250 measurements/s
Rhyme 1:238c76a37054 73 */
Rhyme 0:cf922a073b7f 74 uint8_t getProxRate(void) ;
Rhyme 1:238c76a37054 75
Rhyme 1:238c76a37054 76 /**
Rhyme 1:238c76a37054 77 * Set Rate of Proximity Measurement
Rhyme 1:238c76a37054 78 * @param Rate of Proximity Measurement
Rhyme 1:238c76a37054 79 * @returns none
Rhyme 1:238c76a37054 80 */
Rhyme 0:cf922a073b7f 81 void setProxRate(uint8_t rate) ;
Rhyme 1:238c76a37054 82
Rhyme 1:238c76a37054 83 /**
Rhyme 1:238c76a37054 84 * Get IR LED Current Setting for Proximity Mode
Rhyme 1:238c76a37054 85 * @param none
Rhyme 1:238c76a37054 86 * @returns IR LED Current Settings (Register #3)
Rhyme 1:238c76a37054 87 * @note bit[7:6] Fuse prog ID
Rhyme 1:238c76a37054 88 * @note bit[5:0] IR LED current value
Rhyme 1:238c76a37054 89 * @note IR LED current = value(dec.) x 10mA
Rhyme 1:238c76a37054 90 * @note Valid Range = 0 to 20d.
Rhyme 1:238c76a37054 91 * @note 0 = 0mA, 1 = 10mA .. 20 = 200mA ((DEFAULT: 2 = 20mA)
Rhyme 1:238c76a37054 92 */
Rhyme 0:cf922a073b7f 93 uint8_t getIrLedCurrent(void) ;
Rhyme 1:238c76a37054 94
Rhyme 1:238c76a37054 95 /**
Rhyme 1:238c76a37054 96 * Set IR LED Current Setting for Proximity Mode
Rhyme 1:238c76a37054 97 * @param value to set
Rhyme 1:238c76a37054 98 * @returns none
Rhyme 1:238c76a37054 99 */
Rhyme 0:cf922a073b7f 100 void setIrLedCurrent(uint8_t IrLedCur) ;
Rhyme 1:238c76a37054 101
Rhyme 1:238c76a37054 102 /**
Rhyme 1:238c76a37054 103 * Get Ambient Light Parameter
Rhyme 1:238c76a37054 104 * @param none
Rhyme 1:238c76a37054 105 * @returns Ambient Light Parameter (Register #4)
Rhyme 1:238c76a37054 106 * @note Register #4 Ambient Light Parameter Register (0x84)
Rhyme 1:238c76a37054 107 * @note bit[7] Continuous conversion mode 0: Disable = DEFAULT 1: Enable
Rhyme 1:238c76a37054 108 * @note bit[6:4] als_rate
Rhyme 1:238c76a37054 109 * @note bit[3] Auto offset compensation 0: Disable 1: Enable = DEFAULT
Rhyme 1:238c76a37054 110 * @note bit[2:0] Averaging function (number of measurements per run)
Rhyme 1:238c76a37054 111 * @note als_rate Ambient light measurement rate
Rhyme 1:238c76a37054 112 * @note 000 - 1 samples/s
Rhyme 1:238c76a37054 113 * @note 001 - 2 samples/s = DEFUAULT
Rhyme 1:238c76a37054 114 * @note 010 - 3 samples/s
Rhyme 1:238c76a37054 115 * @note 011 - 4 samples/s
Rhyme 1:238c76a37054 116 * @note 100 - 5 samples/s
Rhyme 1:238c76a37054 117 * @note 101 - 6 samples/s
Rhyme 1:238c76a37054 118 * @note 110 - 8 samples/s
Rhyme 1:238c76a37054 119 * @note 111 - 10 samples/s
Rhyme 1:238c76a37054 120 * @note Averaging function
Rhyme 1:238c76a37054 121 * @note Number of conversions = 2^decimal_value
Rhyme 1:238c76a37054 122 * @note 0 = 1 conv, 1 = 2 conv, 2 = 4 conv, .. t = 32 conv (DEFAULT) .. 7 = 128 conv
Rhyme 1:238c76a37054 123 */
Rhyme 0:cf922a073b7f 124 uint8_t getAlsParam(void) ;
Rhyme 1:238c76a37054 125
Rhyme 1:238c76a37054 126 /**
Rhyme 1:238c76a37054 127 * Set Ambient Light Parameter
Rhyme 1:238c76a37054 128 * @param uint8_t value to set
Rhyme 1:238c76a37054 129 * @returns none
Rhyme 1:238c76a37054 130 */
Rhyme 0:cf922a073b7f 131 void setAlsParam(uint8_t param) ;
Rhyme 1:238c76a37054 132
Rhyme 1:238c76a37054 133 /**
Rhyme 1:238c76a37054 134 * Get Ambient Light Result
Rhyme 1:238c76a37054 135 * @param none
Rhyme 1:238c76a37054 136 * @returns uint16_t the value of Ambient Light Result (Register #5, #6)
Rhyme 1:238c76a37054 137 * @note Register #5 and #6 Ambient Light Result Register (0x85, 0x86)
Rhyme 1:238c76a37054 138 * @note bit[15:8] MSB (address 0x85)
Rhyme 1:238c76a37054 139 * @note bit[7:0] LSB (address 0x86)
Rhyme 1:238c76a37054 140 */
Rhyme 0:cf922a073b7f 141 uint16_t getAls(void) ;
Rhyme 1:238c76a37054 142
Rhyme 1:238c76a37054 143 /**
Rhyme 1:238c76a37054 144 * Get Proximity Measurement Result
Rhyme 1:238c76a37054 145 * @param none
Rhyme 1:238c76a37054 146 * @returns uint16_t the value of Proximity Measurement Result (Register #7, #8)
Rhyme 1:238c76a37054 147 * @note Register #7 and #8 Proximity Measurement Result Register (0x87, 0x88)
Rhyme 1:238c76a37054 148 * @note bit[15:8] MSB (address 0x87)
Rhyme 1:238c76a37054 149 * @note bit[7:0] LSB (address 0x88)
Rhyme 1:238c76a37054 150 */
Rhyme 0:cf922a073b7f 151 uint16_t getProx(void) ;
Rhyme 1:238c76a37054 152
Rhyme 1:238c76a37054 153 /**
Rhyme 1:238c76a37054 154 * Get Interrupt Control Register value
Rhyme 1:238c76a37054 155 * @param none
Rhyme 1:238c76a37054 156 * @returns uint8_t the value of Interraupt Control (Register #9)
Rhyme 1:238c76a37054 157 * @note Register #9 Interrupt Control Register (0x89)
Rhyme 1:238c76a37054 158 * @note bit[7:5] Interrupt Count Exceed
Rhyme 1:238c76a37054 159 * @note bit[4] (n/a)
Rhyme 1:238c76a37054 160 * @note bit[3] INT_PROX_ready_EN Eneables interrupt generation at proximity data ready
Rhyme 1:238c76a37054 161 * @note bit[2] INT_ALS_ready_EN Enables interrupt generation at ambient data ready
Rhyme 1:238c76a37054 162 * @note bit[1] INT_THRES_EN Enables interrupt generation when high or low threshold is exceeded
Rhyme 1:238c76a37054 163 * @note bit[0] INT_THRES_SEL Thresholds are applied to 0:proximity 1:als measurement
Rhyme 1:238c76a37054 164 * @note Interrupt Count Exceed
Rhyme 1:238c76a37054 165 * @note 000 - 1 count = DEFAULT
Rhyme 1:238c76a37054 166 * @note 001 - 2 count
Rhyme 1:238c76a37054 167 * @note 010 - 4 count
Rhyme 1:238c76a37054 168 * @note 011 - 8 count
Rhyme 1:238c76a37054 169 * @note 100 - 16 count
Rhyme 1:238c76a37054 170 * @note 101 - 32 count
Rhyme 1:238c76a37054 171 * @note 110 - 64 count
Rhyme 1:238c76a37054 172 * @note 111 - 128 count
Rhyme 1:238c76a37054 173 */
Rhyme 0:cf922a073b7f 174 uint8_t getIntCtrl(void) ;
Rhyme 1:238c76a37054 175
Rhyme 1:238c76a37054 176 /**
Rhyme 1:238c76a37054 177 * Set Interrupt Control Register
Rhyme 1:238c76a37054 178 * @param uint8_t the value to set
Rhyme 1:238c76a37054 179 * @returns none
Rhyme 1:238c76a37054 180 */
Rhyme 0:cf922a073b7f 181 void setIntCtrl(uint8_t ctrl) ;
Rhyme 1:238c76a37054 182
Rhyme 1:238c76a37054 183 /**
Rhyme 1:238c76a37054 184 * Get Low Threshold
Rhyme 1:238c76a37054 185 * @param none
Rhyme 1:238c76a37054 186 * @returns uint16_t Low Threshold (Register #10, #11)
Rhyme 1:238c76a37054 187 * @note Register #10 and #11 Low Threshold (0x8A, 0x8B)
Rhyme 1:238c76a37054 188 * @note bit[15:8] MSB (address 0x8A)
Rhyme 1:238c76a37054 189 * @note bit[7:0] LSB (address 0x8B)
Rhyme 1:238c76a37054 190 */
Rhyme 0:cf922a073b7f 191 uint16_t getLowThreshold(void) ;
Rhyme 1:238c76a37054 192
Rhyme 1:238c76a37054 193 /**
Rhyme 1:238c76a37054 194 * Set Low Threshold
Rhyme 1:238c76a37054 195 * @param uint16_t value to set
Rhyme 1:238c76a37054 196 * @returns none
Rhyme 1:238c76a37054 197 */
Rhyme 0:cf922a073b7f 198 void setLowThreshold(uint16_t thr) ;
Rhyme 1:238c76a37054 199
Rhyme 1:238c76a37054 200 /**
Rhyme 1:238c76a37054 201 * Get High Threshold
Rhyme 1:238c76a37054 202 * @param none
Rhyme 1:238c76a37054 203 * @returns uint16_t High Threshold (Register #12, #13)
Rhyme 1:238c76a37054 204 * @note Register #12 and #13 High Threshold (0x8C, 0x8D)
Rhyme 1:238c76a37054 205 * @note bit[15:8] MSB (address 0x8C)
Rhyme 1:238c76a37054 206 * @note bit[7:0] LSB (address 0x8D)
Rhyme 1:238c76a37054 207 */
Rhyme 0:cf922a073b7f 208 uint16_t getHighThreshold(void) ;
Rhyme 1:238c76a37054 209
Rhyme 1:238c76a37054 210 /**
Rhyme 1:238c76a37054 211 * Set High Threshold
Rhyme 1:238c76a37054 212 * @param uint16_t value to set
Rhyme 1:238c76a37054 213 * @returns none
Rhyme 1:238c76a37054 214 */
Rhyme 0:cf922a073b7f 215 void setHighThreshold(uint16_t thr) ;
Rhyme 1:238c76a37054 216
Rhyme 1:238c76a37054 217 /**
Rhyme 1:238c76a37054 218 * Get Interrupt Status
Rhyme 1:238c76a37054 219 * @param none
Rhyme 1:238c76a37054 220 * @returns uint8_t Interrupt Status (Register #14)
Rhyme 1:238c76a37054 221 * @note Register #14 Interrupt Status (0x8E)
Rhyme 1:238c76a37054 222 * @note bit[7:4] (n/a)
Rhyme 1:238c76a37054 223 * @note bit[3] int_prox_ready
Rhyme 1:238c76a37054 224 * @note bit[2] int_als_ready
Rhyme 1:238c76a37054 225 * @note bit[1] int_th_low
Rhyme 1:238c76a37054 226 * @note bit[0] int_th_hi
Rhyme 1:238c76a37054 227 * @note Once an interrupt is generated the corresponding status bit
Rhyme 1:238c76a37054 228 * @note goes to 1 and stays there unless it is cleared by writing a 1
Rhyme 1:238c76a37054 229 * @note in the corresponding bit.
Rhyme 1:238c76a37054 230 */
Rhyme 0:cf922a073b7f 231 uint8_t getIntStatus(void) ;
Rhyme 1:238c76a37054 232
Rhyme 1:238c76a37054 233 /**
Rhyme 1:238c76a37054 234 * Set Interrupt Status
Rhyme 1:238c76a37054 235 * @param uint8_t value to set
Rhyme 1:238c76a37054 236 * @returns none
Rhyme 1:238c76a37054 237 */
Rhyme 0:cf922a073b7f 238 void setIntStatus(uint8_t status) ;
Rhyme 1:238c76a37054 239
Rhyme 1:238c76a37054 240 /**
Rhyme 1:238c76a37054 241 * Get Proximity Modulator Timing Adjustment
Rhyme 1:238c76a37054 242 * @param none
Rhyme 1:238c76a37054 243 * @returns Proximity Modulator Timing Adjustment (Register #15)
Rhyme 1:238c76a37054 244 * @note Register #15 Proximity Modulator Timing Adjustment (0x8F)
Rhyme 1:238c76a37054 245 * @note bit[7:5] Modulation delay time
Rhyme 1:238c76a37054 246 * @note bit[4:3] Proximity frequency
Rhyme 1:238c76a37054 247 * @note bit[2:0] Modulation deat time
Rhyme 1:238c76a37054 248 * @note The settings for best performance will be provided by Vishay.
Rhyme 1:238c76a37054 249 * @note With first samples this is evaluated to:
Rhyme 1:238c76a37054 250 * @note delay time = 0
Rhyme 1:238c76a37054 251 * @note frequency = 0
Rhyme 1:238c76a37054 252 * @note deat time = 1
Rhyme 1:238c76a37054 253 * @note With that Register #15 should be programmed with 1 (= default value).
Rhyme 1:238c76a37054 254 */
Rhyme 0:cf922a073b7f 255 uint8_t getProxModTiming(void) ;
Rhyme 1:238c76a37054 256
Rhyme 1:238c76a37054 257 /**
Rhyme 1:238c76a37054 258 * Set Proximity Modulator Timing Adjustment
Rhyme 1:238c76a37054 259 * @param uint8_t value to set
Rhyme 1:238c76a37054 260 * @returns none
Rhyme 1:238c76a37054 261 */
Rhyme 0:cf922a073b7f 262 void setProxModTiming(uint8_t timing) ;
Rhyme 0:cf922a073b7f 263
Rhyme 0:cf922a073b7f 264 private:
Rhyme 0:cf922a073b7f 265 I2C m_i2c;
Rhyme 0:cf922a073b7f 266 int m_addr;
Rhyme 0:cf922a073b7f 267 void readRegs(int addr, uint8_t * data, int len);
Rhyme 0:cf922a073b7f 268 void writeRegs(uint8_t * data, int len);
Rhyme 0:cf922a073b7f 269 };
Rhyme 0:cf922a073b7f 270
Rhyme 0:cf922a073b7f 271 #endif /* _VCNL4010_H_ */