vl6180x.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Gunar Schorcht
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
393 #ifndef VL6180X_H
394 #define VL6180X_H
395 
396 #ifdef __cplusplus
397 extern "C"
398 {
399 #endif
400 
401 #include <stdbool.h>
402 #include <stdint.h>
403 
404 #include "periph/gpio.h"
405 #include "periph/i2c.h"
406 
407 #include "vl6180x_regs.h"
408 
409 #define VL6180X_I2C_ADDR (0x29)
414 typedef enum {
424 
428 typedef enum {
438 
442 typedef enum {
458 
462 typedef enum {
467 
485 typedef enum {
488  VL6180X_INT_LOW = 1,
490  VL6180X_INT_HIGH = 2,
492  VL6180X_INT_OUT = 3,
495  VL6180X_INT_DRDY = 4,
498 
512 typedef struct {
513 #if IS_USED(MODULE_VL6180X_RNG) || DOXYGEN
515 #endif
516 #if IS_USED(MODULE_VL6180X_ALS) || DOXYGEN
518 #endif
520 
535 typedef struct {
536 #if IS_USED(MODULE_VL6180X_RNG) || DOXYGEN
537  uint8_t rng_high;
538  uint8_t rng_low;
539 #endif
540 #if IS_USED(MODULE_VL6180X_ALS) || DOXYGEN
541  uint16_t als_high;
542  uint16_t als_low;
543 #endif
545 
549 typedef struct {
554  unsigned i2c_dev;
555  uint8_t i2c_addr;
557 #if IS_USED(MODULE_VL6180X_SHUTDOWN) || DOXYGEN
558  gpio_t shutdown_pin;
559 #endif /* IS_USED(MODULE_VL6180X_SHUTDOWN) || DOXYGEN */
560 
561 #if IS_USED(MODULE_VL6180X_IRQ) || DOXYGEN
562  gpio_t int_pin;
565 #endif /* IS_USED(MODULE_VL6180X_IRQ) || DOXYGEN */
566 
588  uint8_t period;
589 
590 #if IS_USED(MODULE_VL6180X_RNG) || DOXYGEN
595  uint8_t rng_max_time;
599 #endif /* IS_USED(MODULE_VL6180X_RNG) || DOXYGEN */
600 
601 #if IS_USED(MODULE_VL6180X_ALS) || DOXYGEN
606  uint16_t als_int_time;
608  uint16_t als_lux_res;
614 #endif /* IS_USED(MODULE_VL6180X_ALS) || DOXYGEN */
615 
617 
621 typedef struct {
622 
624  bool cont_meas;
625 #if IS_USED(MODULE_VL6180X_RNG) || DOXYGEN
627 #endif /* IS_USED(MODULE_VL6180X_RNG) || DOXYGEN */
628 #if IS_USED(MODULE_VL6180X_ALS) || DOXYGEN
630 #endif /* IS_USED(MODULE_VL6180X_ALS) || DOXYGEN */
631 } vl6180x_t;
632 
653 int vl6180x_init(vl6180x_t *dev, const vl6180x_params_t *params);
654 
676 
696 
697 #if IS_USED(MODULE_VL6180X_RNG) || DOXYGEN
713 
735 int vl6180x_rng_read(vl6180x_t *dev, uint8_t *mm);
736 
746 
761 
762 #if IS_USED(MODULE_VL6180X_CONFIG) || DOXYGEN
793 int vl6180x_rng_config(vl6180x_t *dev, uint8_t period, uint8_t max_time);
794 
795 #endif /* IS_USED(MODULE_VL6180X_CONFIG) || DOXYGEN */
796 #endif /* IS_USED(MODULE_VL6180X_RNG) || DOXYGEN */
797 
798 #if IS_USED(MODULE_VL6180X_ALS) || DOXYGEN
812 
845 int vl6180x_als_read(vl6180x_t *dev, uint16_t *raw, uint16_t *lux);
846 
856 
871 
872 #if IS_USED(MODULE_VL6180X_CONFIG) || DOXYGEN
904 int vl6180x_als_config(vl6180x_t *dev, uint8_t period, uint8_t int_time,
905  vl6180x_als_gain_t gain);
906 
907 #endif /* IS_USED(MODULE_VL6180X_CONFIG) || DOXYGEN */
908 #endif /* IS_USED(MODULE_VL6180X_ALS) || DOXYGEN */
909 
910 #if IS_USED(MODULE_VL6180X_SHUTDOWN) || DOXYGEN
927 
944 
945 #endif /* IS_USED(MODULE_VL6180X_SHUTDOWN) || DOXYGEN */
946 
947 #if IS_USED(MODULE_VL6180X_IRQ) || DOXYGEN
948 
980 
1005 
1006 #if IS_USED(MODULE_VL6180X_CONFIG) || DOXYGEN
1022 
1023 #endif /* IS_USED(MODULE_VL6180X_CONFIG) || DOXYGEN */
1024 #endif /* IS_USED(MODULE_VL6180X_IRQ) || DOXYGEN */
1025 
1049  uint16_t reg, const uint8_t *data, uint8_t len);
1050 
1069  uint16_t reg, uint8_t *data, uint8_t len);
1071 #ifdef __cplusplus
1072 }
1073 #endif
1074 
1075 #endif /* VL6180X_H */
Low-level GPIO peripheral driver interface definitions.
int vl6180x_rng_read(vl6180x_t *dev, uint8_t *mm)
Read one ranging data sample in mm.
vl6180x_rng_status_t vl6180x_rng_status(const vl6180x_t *dev)
Get status of last range measurement.
int vl6180x_int_enable(vl6180x_t *dev, vl6180x_int_config_t mode)
Enable and disable interrupts.
int vl6180x_reg_read(const vl6180x_t *dev, uint16_t reg, uint8_t *data, uint8_t len)
Direct read from register.
vl6180x_als_status_t
Ambient light sensing (ALS) status.
Definition: vl6180x.h:462
int vl6180x_int_config(vl6180x_t *dev, vl6180x_int_thresh_t thresh)
Configure thresholds for event interrupts at runtime.
int vl6180x_start_cont(vl6180x_t *dev)
Start measurements in continuous mode.
int vl6180x_als_data_ready(const vl6180x_t *dev)
ALS data ready status function.
vl6180x_als_status_t vl6180x_als_status(const vl6180x_t *dev)
Get status of last ALS measurement.
int vl6180x_stop_cont(vl6180x_t *dev)
Stop measurements in continuous mode.
int vl6180x_als_read(vl6180x_t *dev, uint16_t *raw, uint16_t *lux)
Read one ambient light sensing (ALS) data sample.
int vl6180x_int_wait(const vl6180x_t *dev, vl6180x_int_config_t *src)
Wait for configured interrupts and return the interrupt sources.
int vl6180x_power_up(vl6180x_t *dev)
Power down the sensor.
int vl6180x_als_start_single(const vl6180x_t *dev)
Start a single-shot ALS measurement.
vl6180x_int_mode_t
Interrupt mode.
Definition: vl6180x.h:485
int vl6180x_rng_config(vl6180x_t *dev, uint8_t period, uint8_t max_time)
Reconfigure range measurements at runtime.
int vl6180x_rng_start_single(const vl6180x_t *dev)
Start a single-shot range measurement.
vl6180x_als_gain_t
Analogue gain for ALS measurements.
Definition: vl6180x.h:428
int vl6180x_reg_write(const vl6180x_t *dev, uint16_t reg, const uint8_t *data, uint8_t len)
Direct write to register.
int vl6180x_rng_data_ready(const vl6180x_t *dev)
Range data ready status function.
int vl6180x_init(vl6180x_t *dev, const vl6180x_params_t *params)
Initialize the VL6180X sensor device.
vl6180x_error_t
Error codes.
Definition: vl6180x.h:414
int vl6180x_als_config(vl6180x_t *dev, uint8_t period, uint8_t int_time, vl6180x_als_gain_t gain)
Reconfigure ambient light sensing (ALS) during runtime.
vl6180x_rng_status_t
Range measurement status.
Definition: vl6180x.h:442
int vl6180x_power_down(const vl6180x_t *dev)
Power down the sensor.
@ VL6180X_ALS_OVERFLOW
ALS measurement overflow.
Definition: vl6180x.h:464
@ VL6180X_ALS_UNDERFLOW
ALS measurement underflow.
Definition: vl6180x.h:465
@ VL6180X_ALS_OK
No error.
Definition: vl6180x.h:463
@ VL6180X_INT_LOW
Interrupt is triggered when values are below the lower threshold.
Definition: vl6180x.h:488
@ VL6180X_INT_DRDY
Interrupt is triggered when new data are ready to be read.
Definition: vl6180x.h:495
@ VL6180X_INT_HIGH
Interrupt is triggered when values are above the upper threshold.
Definition: vl6180x.h:490
@ VL6180X_INT_NONE
Interrupt is disabled.
Definition: vl6180x.h:486
@ VL6180X_INT_OUT
Interrupt is triggered when values are below the lower threshold or above the upper threshold (value ...
Definition: vl6180x.h:492
@ VL6180X_ALS_GAIN_5
5 x gain (actual analogue gain of 5.21)
Definition: vl6180x.h:431
@ VL6180X_ALS_GAIN_2_5
2.5 x gain (actual analogue gain of 2.6)
Definition: vl6180x.h:432
@ VL6180X_ALS_GAIN_1
1 x gain (actual analogue gain of 1.01), default
Definition: vl6180x.h:435
@ VL6180X_ALS_GAIN_1_67
1.67 x gain (actual analogue gain of 1.72)
Definition: vl6180x.h:433
@ VL6180X_ALS_GAIN_40
40 x gain (actual analogue gain of 40)
Definition: vl6180x.h:436
@ VL6180X_ALS_GAIN_20
20 x gain (actual analogue gain of 20)
Definition: vl6180x.h:429
@ VL6180X_ALS_GAIN_10
10 x gain (actual analogue gain of 10.32)
Definition: vl6180x.h:430
@ VL6180X_ALS_GAIN_1_25
1.25 x gain (actual analogue gain of 1.28)
Definition: vl6180x.h:434
@ VL6180X_ERROR_NOT_READY
Device not ready.
Definition: vl6180x.h:422
@ VL6180X_ERROR_NO_DATA
No data available.
Definition: vl6180x.h:419
@ VL6180X_ERROR_WRONG_ID
Wrong id read.
Definition: vl6180x.h:417
@ VL6180X_ERROR_ALS
Ambient light sensing (ALS) error.
Definition: vl6180x.h:421
@ VL6180X_ERROR_RNG
Ranging error.
Definition: vl6180x.h:420
@ VL6180X_OK
Success.
Definition: vl6180x.h:415
@ VL6180X_ERROR_NO_PIN
Pin not defined.
Definition: vl6180x.h:418
@ VL6180X_ERROR_I2C
I2C communication error.
Definition: vl6180x.h:416
@ VL6180X_RNG_ALGO_UNDERFLOW
Ranging algorithm underflow.
Definition: vl6180x.h:455
@ VL6180X_RNG_EARLY_CONV_EST
Early convergence estimate.
Definition: vl6180x.h:449
@ VL6180X_RNG_ALGO_OVERFLOW
Ranging algorithm overflow.
Definition: vl6180x.h:456
@ VL6180X_RNG_NO_TARGET
No target, ignore.
Definition: vl6180x.h:451
@ VL6180X_RNG_RAW_ALGO_OVERFLOW
Raw ranging algorithn overflow.
Definition: vl6180x.h:454
@ VL6180X_RNG_VCSEL_WD_TEST
VCSEL watchdog test.
Definition: vl6180x.h:445
@ VL6180X_RNG_PLL1_LOCK
PLL1 lock.
Definition: vl6180x.h:447
@ VL6180X_RNG_MAX_CONV
Maximum convergence time reached.
Definition: vl6180x.h:450
@ VL6180X_RNG_MAX_SNR
Maximum SNR reached.
Definition: vl6180x.h:452
@ VL6180X_RNG_VCSEL_CONT_TEST
VCSEL continuity Test.
Definition: vl6180x.h:444
@ VL6180X_RNG_PLL2_LOCK
PLL2 lock.
Definition: vl6180x.h:448
@ VL6180X_RNG_VCSEL_WD
VCSEL watchdog.
Definition: vl6180x.h:446
@ VL6180X_RNG_OK
No error.
Definition: vl6180x.h:443
@ VL6180X_RNG_RAW_ALGO_UNDERFLOW
Raw ranging algorithm underflow.
Definition: vl6180x.h:453
Low-level I2C peripheral driver interface definition.
Interrupt config.
Definition: vl6180x.h:512
vl6180x_int_mode_t als_int
Interrupt mode for ALS measurements.
Definition: vl6180x.h:517
vl6180x_int_mode_t rng_int
Interrupt mode for range measurements.
Definition: vl6180x.h:514
Interrupt threshold configuration.
Definition: vl6180x.h:535
uint8_t rng_high
upper threshold for range values
Definition: vl6180x.h:537
uint8_t rng_low
lower threshold for range values
Definition: vl6180x.h:538
uint16_t als_high
upper threshold for ALS values
Definition: vl6180x.h:541
uint16_t als_low
lower threshold for ALS values
Definition: vl6180x.h:542
VL6180X device configuration.
Definition: vl6180x.h:549
uint16_t als_int_time
ALS integration time in ms [1...512] (default 100 = 100 ms, recommended)
Definition: vl6180x.h:606
gpio_t shutdown_pin
Shutdown pin, LOW active.
Definition: vl6180x.h:558
uint8_t rng_max_time
Maximum convergence time in ms [1...63] given to the sensor to perform a range measurement (default 5...
Definition: vl6180x.h:595
vl6180x_int_config_t int_cfg
Interrupt mode configuration.
Definition: vl6180x.h:563
uint16_t als_lux_res
ALS lux resolution multiplied by factor 1000 (default 0.32 lux/count is the factory calibrated lux re...
Definition: vl6180x.h:608
uint8_t i2c_addr
I2C slave address.
Definition: vl6180x.h:555
uint8_t period
Measurement period in continuous mode in steps of 10 ms (default 20 = 200 ms).
Definition: vl6180x.h:588
vl6180x_als_gain_t als_gain
ALS analogue gain for light channel (default VL6180X_ALS_GAIN_1_0)
Definition: vl6180x.h:611
vl6180x_int_thresh_t int_thresh
Interrupt threshold configuration.
Definition: vl6180x.h:564
gpio_t int_pin
Interrupt pin, LOW active.
Definition: vl6180x.h:562
unsigned i2c_dev
I2C device, default I2C_DEV(0)
Definition: vl6180x.h:554
VL6180X sensor device data structure type.
Definition: vl6180x.h:621
vl6180x_als_status_t als_status
Status of last ALS measurement.
Definition: vl6180x.h:629
vl6180x_rng_status_t rng_status
Status of last range measurement.
Definition: vl6180x.h:626
vl6180x_params_t params
Device initialization parameters.
Definition: vl6180x.h:623
bool cont_meas
Continuous mode running.
Definition: vl6180x.h:624
Register definitions for ST VL6180X Ranging and Ambient Light Sensing (ALS) module.