ESP32-P4 OBC Firmware
ESP-IDF firmware for Plant-B CubeSat OBC
 
Loading...
Searching...
No Matches
VEML7700 Sensor

Data Structures

struct  veml7700_config_t
 Configuration structure for the VEML7700 sensor. More...
 
struct  veml7700_dev_t
 Device handle structure for the VEML7700 sensor. More...
 

Macros

#define VEML7700_I2C_ADDR   (0x10)
 Default I²C address for VEML7700 sensors.
 

Typedefs

typedef uint8_t i2c_addr_t
 Type for I²C addresses.
 
typedef uint32_t ill_lx_t
 Type for illuminance [lx].
 
typedef void * veml7700_handle_t
 Opaque handle for a VEML7700 sensor.
 

Functions

veml7700_handle_t veml7700_i2c_create (i2c_bus_handle_t bus, i2c_addr_t dev_addr)
 Create a VEML7700 device handle for I²C communication.
 
veml7700_handle_t veml7700_i2c_init (i2c_bus_handle_t bus, i2c_addr_t dev_addr)
 Initialize the VEML7700 sensor over I²C.
 
void veml7700_i2c_delete (veml7700_handle_t sensor)
 Deinitialize the VEML7700 sensor and free resources.
 
esp_err_t veml7700_i2c_probe (veml7700_handle_t sensor)
 Probe if the sensor exist on the I²C bus.
 
esp_err_t veml7700_i2c_write_config (veml7700_handle_t sensor, veml7700_config_t *cfg)
 Write the configuration to the sensor.
 
esp_err_t veml7700_i2c_read_config (veml7700_handle_t sensor, veml7700_config_t *cfg)
 Read the sensor configuration.
 
esp_err_t veml7700_i2c_read_ambient_light (veml7700_handle_t sensor, ill_lx_t *val)
 Read ambiant light value from the sensor.
 
esp_err_t veml7700_i2c_read_white_channel (veml7700_handle_t sensor, ill_lx_t *val)
 Read white channel value from the sensor.
 
esp_err_t veml7700_i2c_read_interrupt_status (veml7700_handle_t sensor, bool *low, bool *high)
 Read the interrupt status from the sensor.
 

Integration Time Constants

Integration times for the VEML7700 sensor.

#define VEML7700_INTEGRATION_TIME_25MS   (0b1100)
 25 ms
 
#define VEML7700_INTEGRATION_TIME_50MS   (0b1000)
 50 ms
 
#define VEML7700_INTEGRATION_TIME_100MS   (0b0000)
 100 ms
 
#define VEML7700_INTEGRATION_TIME_200MS   (0b0001)
 200 ms
 
#define VEML7700_INTEGRATION_TIME_400MS   (0b0010)
 400 ms
 
#define VEML7700_INTEGRATION_TIME_800MS   (0b0011)
 800 ms
 

Gain Constants

Gain settings for the VEML7700 sensor.

#define VEML7700_GAIN_1   (0b00)
 x1 gain
 
#define VEML7700_GAIN_2   (0b01)
 x2 gain
 
#define VEML7700_GAIN_DIV_8   (0b10)
 /8 gain
 
#define VEML7700_GAIN_DIV_4   (0b11)
 /4 gain
 

Power Saving Mode Constants

Power saving modes for the sensor.

#define VEML7700_POWER_SAVING_MODE_500MS   (0b00)
 500 ms interval
 
#define VEML7700_POWER_SAVING_MODE_1000MS   (0b01)
 1000 ms interval
 
#define VEML7700_POWER_SAVING_MODE_2000MS   (0b10)
 2000 ms interval
 
#define VEML7700_POWER_SAVING_MODE_4000MS   (0b11)
 4000 ms interval
 

Persistence Protection Constants

Number of consecutive samples before triggering an interrupt.

#define VEML7700_PERSISTENCE_PROTECTION_1   (0b00)
 1 sample
 
#define VEML7700_PERSISTENCE_PROTECTION_2   (0b01)
 2 samples
 
#define VEML7700_PERSISTENCE_PROTECTION_4   (0b10)
 4 samples
 
#define VEML7700_PERSISTENCE_PROTECTION_8   (0b11)
 8 samples
 

Detailed Description

I²C ESP-IDF driver for the Vishay VEML7700 ambiant light sensor.

Adapted from https://github.com/esp-idf-lib/veml7700/tree/78c39579d6d5b1a0cc06e3af6da78fe41e181792 under ISC license.

Uses the new ESP-IDF I²C interface.


Data Structure Documentation

◆ veml7700_config_t

struct veml7700_config_t

Configuration structure for the VEML7700 sensor.

Data Fields
uint16_t gain: 2 Sensor sensitivity control.
uint16_t integration_time: 4 Integration time setting.
uint16_t interrupt_enable: 1 Enable/disable threshold interrupt.
uint16_t persistence_protect: 2 Samples before interrupt triggers.
uint16_t power_saving_enable: 1 Enable/disable power saving mode.
uint16_t power_saving_mode: 2 Power saving mode selection.
uint16_t shutdown: 1 Set to 1 to shutdown, 0 to wakeup.
uint16_t threshold_high High threshold for interrupt.
uint16_t threshold_low Low threshold for interrupt.

◆ veml7700_dev_t

struct veml7700_dev_t

Device handle structure for the VEML7700 sensor.

Data Fields
veml7700_config_t cfg Sensor configuration.
i2c_addr_t dev_addr I²C address of the sensor.
i2c_bus_device_handle_t i2c_dev I²C device handle.

Macro Definition Documentation

◆ VEML7700_GAIN_1

#define VEML7700_GAIN_1   (0b00)

x1 gain

◆ VEML7700_GAIN_2

#define VEML7700_GAIN_2   (0b01)

x2 gain

◆ VEML7700_GAIN_DIV_4

#define VEML7700_GAIN_DIV_4   (0b11)

/4 gain

◆ VEML7700_GAIN_DIV_8

#define VEML7700_GAIN_DIV_8   (0b10)

/8 gain

◆ VEML7700_I2C_ADDR

#define VEML7700_I2C_ADDR   (0x10)

Default I²C address for VEML7700 sensors.

◆ VEML7700_INTEGRATION_TIME_100MS

#define VEML7700_INTEGRATION_TIME_100MS   (0b0000)

100 ms

◆ VEML7700_INTEGRATION_TIME_200MS

#define VEML7700_INTEGRATION_TIME_200MS   (0b0001)

200 ms

◆ VEML7700_INTEGRATION_TIME_25MS

#define VEML7700_INTEGRATION_TIME_25MS   (0b1100)

25 ms

◆ VEML7700_INTEGRATION_TIME_400MS

#define VEML7700_INTEGRATION_TIME_400MS   (0b0010)

400 ms

◆ VEML7700_INTEGRATION_TIME_50MS

#define VEML7700_INTEGRATION_TIME_50MS   (0b1000)

50 ms

◆ VEML7700_INTEGRATION_TIME_800MS

#define VEML7700_INTEGRATION_TIME_800MS   (0b0011)

800 ms

◆ VEML7700_PERSISTENCE_PROTECTION_1

#define VEML7700_PERSISTENCE_PROTECTION_1   (0b00)

1 sample

◆ VEML7700_PERSISTENCE_PROTECTION_2

#define VEML7700_PERSISTENCE_PROTECTION_2   (0b01)

2 samples

◆ VEML7700_PERSISTENCE_PROTECTION_4

#define VEML7700_PERSISTENCE_PROTECTION_4   (0b10)

4 samples

◆ VEML7700_PERSISTENCE_PROTECTION_8

#define VEML7700_PERSISTENCE_PROTECTION_8   (0b11)

8 samples

◆ VEML7700_POWER_SAVING_MODE_1000MS

#define VEML7700_POWER_SAVING_MODE_1000MS   (0b01)

1000 ms interval

◆ VEML7700_POWER_SAVING_MODE_2000MS

#define VEML7700_POWER_SAVING_MODE_2000MS   (0b10)

2000 ms interval

◆ VEML7700_POWER_SAVING_MODE_4000MS

#define VEML7700_POWER_SAVING_MODE_4000MS   (0b11)

4000 ms interval

◆ VEML7700_POWER_SAVING_MODE_500MS

#define VEML7700_POWER_SAVING_MODE_500MS   (0b00)

500 ms interval

Typedef Documentation

◆ i2c_addr_t

typedef uint8_t i2c_addr_t

Type for I²C addresses.

◆ ill_lx_t

typedef uint32_t ill_lx_t

Type for illuminance [lx].

◆ veml7700_handle_t

typedef void* veml7700_handle_t

Opaque handle for a VEML7700 sensor.

Function Documentation

◆ veml7700_i2c_create()

veml7700_handle_t veml7700_i2c_create ( i2c_bus_handle_t bus,
i2c_addr_t dev_addr )

Create a VEML7700 device handle for I²C communication.

Allocates and initializes a device handle but does not configure the sensor.

Parameters
[in]busHandle to the I²C bus.
[in]dev_addrI²C address of the VEML7700 sensor.

@retvale veml7700_handle_t Handle to the sensor.

Return values
NULLOn failure.
Note
Must call veml7700_i2c_delete() to free resources later.
Warning
This function must run inside a critical section.

◆ veml7700_i2c_delete()

void veml7700_i2c_delete ( veml7700_handle_t sensor)

Deinitialize the VEML7700 sensor and free resources.

Parameters
[in,out]sensorThe sensor handle returned by veml7700_i2c_init() or veml7700_i2c_create().
Warning
This function must run inside a critical section.

◆ veml7700_i2c_init()

veml7700_handle_t veml7700_i2c_init ( i2c_bus_handle_t bus,
i2c_addr_t dev_addr )

Initialize the VEML7700 sensor over I²C.

Sets up default configuration and prepares the sensor for measurements.

  • SCL frequency is 100 kHz.
  • Gain is 1/8.
  • Integration time is 100 ms.
  • Persistance protection is 4 samples.
  • Interrupts are disabled.
  • Power saving mode is enabled.
  • The sleep time interval is 1000 ms.
Parameters
[in]busHandle to the I²C bus.
[in]dev_addrI²C address of the VEML7700 sensor.
Return values
veml7700_handle_tHandle to the sensor.
NULLOn failure.
Note
Must call veml7700_i2c_delete() to free resources later.
Warning
This function must run inside a critical section.

◆ veml7700_i2c_probe()

esp_err_t veml7700_i2c_probe ( veml7700_handle_t sensor)

Probe if the sensor exist on the I²C bus.

Parameters
[in]sensorThe sensor handle.
Return values
ESP_OKOn success.
ESP_ERR_INVALID_ARGIf any parameter is NULL.
ESP_FAILSending command error, slave doesn't ACK the transfer.
ESP_ERR_INVALID_STATEI²C driver not installed or not in master mode.
ESP_ERR_TIMEOUTOperation timeout because the bus is busy.

◆ veml7700_i2c_read_ambient_light()

esp_err_t veml7700_i2c_read_ambient_light ( veml7700_handle_t sensor,
ill_lx_t * val )

Read ambiant light value from the sensor.

Parameters
[in]sensorThe sensor handle.
[out]valPointer to store the ambiant light value.
Return values
ESP_OKOn success.
ESP_ERR_INVALID_ARGIf any parameter is NULL.
ESP_FAILSending command error, slave doesn't ACK the transfer.
ESP_ERR_INVALID_STATEI²C driver not installed or not in master mode.
ESP_ERR_TIMEOUTOperation timeout because the bus is busy.

◆ veml7700_i2c_read_config()

esp_err_t veml7700_i2c_read_config ( veml7700_handle_t sensor,
veml7700_config_t * cfg )

Read the sensor configuration.

Parameters
[in]sensorThe sensor handle.
[out]cfgPointer to store the configuration.
Return values
ESP_OKOn success.
ESP_ERR_INVALID_ARGIf any parameter is NULL.
ESP_FAILSending command error, slave doesn't ACK the transfer.
ESP_ERR_INVALID_STATEI²C driver not installed or not in master mode.
ESP_ERR_TIMEOUTOperation timeout because the bus is busy.

◆ veml7700_i2c_read_interrupt_status()

esp_err_t veml7700_i2c_read_interrupt_status ( veml7700_handle_t sensor,
bool * low,
bool * high )

Read the interrupt status from the sensor.

Parameters
[in]sensorThe sensor handle.
[out]lowPointer to store the low threshold passed indicator.
[out]highPointer to store the high threshold passed indicator.
Return values
ESP_OKOn success.
ESP_ERR_INVALID_ARGIf any parameter is NULL.
ESP_FAILSending command error, slave doesn't ACK the transfer.
ESP_ERR_INVALID_STATEI²C driver not installed or not in master mode.
ESP_ERR_TIMEOUTOperation timeout because the bus is busy.

◆ veml7700_i2c_read_white_channel()

esp_err_t veml7700_i2c_read_white_channel ( veml7700_handle_t sensor,
ill_lx_t * val )

Read white channel value from the sensor.

Parameters
[in]sensorThe sensor handle.
[out]valPointer to store the white channel value.
Return values
ESP_OKOn success.
ESP_ERR_INVALID_ARGIf any parameter is NULL.
ESP_FAILSending command error, slave doesn't ACK the transfer.
ESP_ERR_INVALID_STATEI²C driver not installed or not in master mode.
ESP_ERR_TIMEOUTOperation timeout because the bus is busy.

◆ veml7700_i2c_write_config()

esp_err_t veml7700_i2c_write_config ( veml7700_handle_t sensor,
veml7700_config_t * cfg )

Write the configuration to the sensor.

Parameters
[in]sensorThe sensor handle.
[in]cfgThe configuration descriptor.
Return values
ESP_OKOn success.
ESP_ERR_INVALID_ARGIf any parameter is NULL.
ESP_FAILSending command error, slave doesn't ACK the transfer.
ESP_ERR_INVALID_STATEI²C driver not installed or not in master mode.
ESP_ERR_TIMEOUTOperation timeout because the bus is busy.