VCNL4010/VCNL4020/VCNL4040 Proximity and Ambient Light Sensors

Device driver interface for the VCNL40X0 Proximity and Ambient Light Sensors. More...

Detailed Description

Device driver interface for the VCNL40X0 Proximity and Ambient Light Sensors.

Files

file  vcnl40x0.h
 Device driver interface for the VCNL40X0 sensors family.
 
file  vcnl40x0_internals.h
 Internal addresses, registers, constants for the VCNL40X0 devices.
 
file  vcnl40x0_params.h
 Default configuration for VCNL40X0 devices.
 

Data Structures

struct  vcnl40x0_params_t
 Device initialization parameters. More...
 
struct  vcnl40x0_t
 Device descriptor for the VCNL40X0 sensor. More...
 

Enumerations

enum  {
  VCNL40X0_PROXIMITY_RATE_2 = 0, VCNL40X0_PROXIMITY_RATE_4, VCNL40X0_PROXIMITY_RATE_8, VCNL40X0_PROXIMITY_RATE_16,
  VCNL40X0_PROXIMITY_RATE_31, VCNL40X0_PROXIMITY_RATE_62, VCNL40X0_PROXIMITY_RATE_125, VCNL40X0_PROXIMITY_RATE_250
}
 Proximity measure rate. More...
 
enum  {
  VCNL40X0_AMBIENT_RATE_1 = 0, VCNL40X0_AMBIENT_RATE_2, VCNL40X0_AMBIENT_RATE_3, VCNL40X0_AMBIENT_RATE_4,
  VCNL40X0_AMBIENT_RATE_5, VCNL40X0_AMBIENT_RATE_6, VCNL40X0_AMBIENT_RATE_8, VCNL40X0_AMBIENT_RATE_10
}
 Ambient light measurement rate. More...
 
enum  {
  VCNL40X0_AMBIENT_AVERAGE_1 = 0, VCNL40X0_AMBIENT_AVERAGE_2, VCNL40X0_AMBIENT_AVERAGE_4, VCNL40X0_AMBIENT_AVERAGE_8,
  VCNL40X0_AMBIENT_AVERAGE_16, VCNL40X0_AMBIENT_AVERAGE_32, VCNL40X0_AMBIENT_AVERAGE_64, VCNL40X0_AMBIENT_AVERAGE_128
}
 Ambient light number of conversions during one measurement cycle. More...
 
enum  { VCNL40X0_OK = 0, VCNL40X0_ERR_I2C, VCNL40X0_ERR_NODEV }
 Status and error return codes. More...
 

Functions

int vcnl40x0_init (vcnl40x0_t *dev, const vcnl40x0_params_t *params)
 Initialize the given VCNL40X0 device. More...
 
uint16_t vcnl40x0_read_proximity (const vcnl40x0_t *dev)
 Read proximity value from the vcnl40X0 device. More...
 
uint16_t vcnl40x0_read_ambient_light (const vcnl40x0_t *dev)
 Read ambient light value from the vcnl40X0 device. More...
 
uint16_t vcnl40x0_read_illuminance (const vcnl40x0_t *dev)
 Read illuminance value from the vcnl40X0 device. More...
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Proximity measure rate.

Enumerator
VCNL40X0_PROXIMITY_RATE_2 

1.95 measurements/s (default)

VCNL40X0_PROXIMITY_RATE_4 

3.90625 measurements/s

VCNL40X0_PROXIMITY_RATE_8 

7.8125 measurements/s

VCNL40X0_PROXIMITY_RATE_16 

16.625 measurements/s

VCNL40X0_PROXIMITY_RATE_31 

31.25 measurements/s

VCNL40X0_PROXIMITY_RATE_62 

62.5 measurements/s

VCNL40X0_PROXIMITY_RATE_125 

125 measurements/s

VCNL40X0_PROXIMITY_RATE_250 

250 measurements/s

Definition at line 36 of file vcnl40x0.h.

◆ anonymous enum

anonymous enum

Ambient light measurement rate.

Enumerator
VCNL40X0_AMBIENT_RATE_1 

1 sample/s

VCNL40X0_AMBIENT_RATE_2 

2 sample/s (default)

VCNL40X0_AMBIENT_RATE_3 

3 sample/s

VCNL40X0_AMBIENT_RATE_4 

4 sample/s

VCNL40X0_AMBIENT_RATE_5 

5 sample/s

VCNL40X0_AMBIENT_RATE_6 

6 sample/s

VCNL40X0_AMBIENT_RATE_8 

8 sample/s

VCNL40X0_AMBIENT_RATE_10 

10 sample/s

Definition at line 50 of file vcnl40x0.h.

◆ anonymous enum

anonymous enum

Ambient light number of conversions during one measurement cycle.

Number of conversions = 2^decimal value

Enumerator
VCNL40X0_AMBIENT_AVERAGE_1 

Decimal value 1.

VCNL40X0_AMBIENT_AVERAGE_2 

Decimal value 2.

VCNL40X0_AMBIENT_AVERAGE_4 

Decimal value 4.

VCNL40X0_AMBIENT_AVERAGE_8 

Decimal value 8.

VCNL40X0_AMBIENT_AVERAGE_16 

Decimal value 16.

VCNL40X0_AMBIENT_AVERAGE_32 

Decimal value 32 (default)

VCNL40X0_AMBIENT_AVERAGE_64 

Decimal value 64.

VCNL40X0_AMBIENT_AVERAGE_128 

Decimal value 128.

Definition at line 66 of file vcnl40x0.h.

◆ anonymous enum

anonymous enum

Status and error return codes.

Enumerator
VCNL40X0_OK 

Everything was fine.

VCNL40X0_ERR_I2C 

Error initializing the I2C bus.

VCNL40X0_ERR_NODEV 

Error wrong device.

Definition at line 80 of file vcnl40x0.h.

Function Documentation

◆ vcnl40x0_init()

int vcnl40x0_init ( vcnl40x0_t dev,
const vcnl40x0_params_t params 
)

Initialize the given VCNL40X0 device.

Parameters
[out]devInitialized device descriptor of VCNL40X0 device
[in]paramsThe parameters for the VCNL40X0 device
Returns
VCNL40X0_OK on success
-VCNL40X0_ERR_I2C if given I2C is not enabled in board config
-VCNL40X0_ERR_NODEV if not a vcnl40X0 device

◆ vcnl40x0_read_ambient_light()

uint16_t vcnl40x0_read_ambient_light ( const vcnl40x0_t dev)

Read ambient light value from the vcnl40X0 device.

Parameters
[in]devDevice descriptor of VCNL40X0 device to read from
Returns
Ambient light in counts

◆ vcnl40x0_read_illuminance()

uint16_t vcnl40x0_read_illuminance ( const vcnl40x0_t dev)

Read illuminance value from the vcnl40X0 device.

Parameters
[in]devDevice descriptor of VCNL40X0 device to read from
Returns
Illuminance in lux

◆ vcnl40x0_read_proximity()

uint16_t vcnl40x0_read_proximity ( const vcnl40x0_t dev)

Read proximity value from the vcnl40X0 device.

Parameters
[in]devDevice descriptor of VCNL40X0 device to read from
Returns
Proximity in counts