tsl2591 - Driver for light-to-digital converter TSL2591

group tsl2591

ESP-IDF driver for TSL2591 light-to-digital.

Copyright (C) 2020 Julian Doerner https://github.com/juliandoerner

MIT Licensed as described in the file LICENSE

Defines

TSL2591_I2C_ADDR

Enums

enum tsl2591_power_status_t

Power status.

The sensor measures only if ALS an Power is on.

Values:

enumerator TSL2591_POWER_OFF
enumerator TSL2591_POWER_ON

Default.

enum tsl2591_als_status_t

ALS status.

The sensor measures only if ALS and Power is on.

Values:

enumerator TSL2591_ALS_OFF
enumerator TSL2591_ALS_ON

Default.

enum tsl2591_interrupt_t

Interrupts.

TSL2591 has two interrupt sources. Check the datasheet for details.

Values:

enumerator TSL2591_INTR_OFF

Default.

enumerator TSL2591_ALS_INTR_ON
enumerator TSL2591_ALS_INTR_NP_ON
enumerator TSL2591_ALS_INTR_BOTH_ON
enum tsl2591_sleep_after_intr_t

Interrupt sleep setting.

Values:

enumerator TSL2591_SLEEP_AFTER_OFF

Default.

enumerator TSL2591_SLEEP_AFTER_ON
enum tsl2591_integration_time_t

Integration time.

Values:

enumerator TSL2591_INTEGRATION_100MS

Default.

enumerator TSL2591_INTEGRATION_200MS
enumerator TSL2591_INTEGRATION_300MS
enumerator TSL2591_INTEGRATION_400MS
enumerator TSL2591_INTEGRATION_500MS
enumerator TSL2591_INTEGRATION_600MS
enum tsl2591_gain_t

Gain.

Values:

enumerator TSL2591_GAIN_LOW

Default.

enumerator TSL2591_GAIN_MEDIUM
enumerator TSL2591_GAIN_HIGH
enumerator TSL2591_GAIN_MAX
enum tsl2591_persistence_filter_t

Persistence filter.

Values:

enumerator TSL2591_EVERY_CYCLE

Default.

enumerator TSL2591_NO_PERSIST
enumerator TSL2591_2_CYCLES
enumerator TSL2591_3_CYCLES
enumerator TSL2591_5_CYCLES
enumerator TSL2591_10_CYCLES
enumerator TSL2591_15_CYCLES
enumerator TSL2591_20_CYCLES
enumerator TSL2591_25_CYCLES
enumerator TSL2591_30_CYCLES
enumerator TSL2591_35_CYCLES
enumerator TSL2591_40_CYCLES
enumerator TSL2591_45_CYCLES
enumerator TSL2591_50_CYCLES
enumerator TSL2591_55_CYCLES
enumerator TSL2591_60_CYCLES

Functions

esp_err_t tsl2591_init_desc(tsl2591_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)

Initialize device descriptor.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • port: I2C port

  • sda_gpio: SDA GPIO pin

  • scl_gpio: SCL GPIO pin

esp_err_t tsl2591_free_desc(tsl2591_t *dev)

Free device descriptor.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

esp_err_t tsl2591_init(tsl2591_t *dev)

Initialize device.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

esp_err_t tsl2591_get_channel_data(tsl2591_t *dev, uint16_t *channel0, uint16_t *channel1)

Read channel data.

Parameters
  • dev: Device descriptor

  • [out] channel0: Channel 0 data

  • [out] channel1: Channel 1 data

esp_err_t tsl2591_calculate_lux(tsl2591_t *dev, uint16_t channel0, uint16_t channel1, float *lux)

Calculate light intensity from channels.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • channel0: Channel0 data

  • channel1: Channel1 data

  • [out] lux: Light intensity

esp_err_t tsl2591_get_lux(tsl2591_t *dev, float *lux)

Get and calculate light intensity.

Return

ESP_OK

Parameters
  • dev: Device descriptor

  • [out] lux: Light intensity

esp_err_t tsl2591_set_power_status(tsl2591_t *dev, tsl2591_power_status_t power_status)

Set device power status.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • power_status: Power status

esp_err_t tsl2591_get_power_status(tsl2591_t *dev, tsl2591_power_status_t *power_status)

Get device power status.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] power_status: Power status

esp_err_t tsl2591_set_als_status(tsl2591_t *dev, tsl2591_als_status_t als_status)

Set device ALS status.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • als_status: Als status

esp_err_t tsl2591_get_als_status(tsl2591_t *dev, tsl2591_als_status_t *als_status)

Get device ALS status.

Return

ESP_OK

Parameters
  • dev: Device descriptor

  • [out] als_status: Als status

esp_err_t tsl2591_set_interrupt(tsl2591_t *dev, tsl2591_interrupt_t interrupt)

Set device interrupt mode.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • interrupt: interrupt mode

esp_err_t tsl2591_get_interrupt(tsl2591_t *dev, tsl2591_interrupt_t *interrupt)

Get device interrupt mode.

Return

ESP_OK

Parameters
  • dev: Device descriptor

  • [out] interrupt: interrupt mode

esp_err_t tsl2591_set_sleep_after_intr(tsl2591_t *dev, tsl2591_sleep_after_intr_t sleep_after_intr)

Set sleeping after interrupt.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • sleep_after_intr: Sleeping after interrupt

esp_err_t tsl2591_get_sleep_after_intr(tsl2591_t *dev, tsl2591_sleep_after_intr_t *sleep_after_intr)

Get sleeping after interrupt setting.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] sleep_after_intr: Sleeping after interrupt

esp_err_t tsl2591_set_integration_time(tsl2591_t *dev, tsl2591_integration_time_t integration_time)

Set device integration time.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • integration_time: Integration time

esp_err_t tsl2591_get_integration_time(tsl2591_t *dev, tsl2591_integration_time_t *integration_time)

Get device integration time.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] integration_time: Integration time

esp_err_t tsl2591_set_gain(tsl2591_t *dev, tsl2591_gain_t gain)

Set device gain.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • gain: Gain

esp_err_t tsl2591_get_gain(tsl2591_t *dev, tsl2591_gain_t *gain)

Get device gain.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] gain: Gain

esp_err_t tsl2591_set_persistence_filter(tsl2591_t *dev, tsl2591_persistence_filter_t filter)

Set device persistence filter.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • filter: Persistence filter

esp_err_t tsl2591_get_persistence_filter(tsl2591_t *dev, tsl2591_persistence_filter_t *filter)

Get device persistence filter.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] filter: Persistence filter

esp_err_t tsl2591_als_set_low_threshold(tsl2591_t *dev, uint16_t low_threshold)

Set ALS interrupt low threshold.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • low_threshold: Low threshold

esp_err_t tsl2591_als_set_high_threshold(tsl2591_t *dev, uint16_t high_threshold)

Set ALS interrupt high threshold.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • high_threshold: High threshold

esp_err_t tsl2591_no_persist_set_low_threshold(tsl2591_t *dev, uint16_t low_threshold)

Set no persist ALS interrupt low threshold.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • low_threshold: Low threshold

esp_err_t tsl2591_no_persist_set_high_threshold(tsl2591_t *dev, uint16_t high_threshold)

Set no persist ALS interrupt high threshold.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • high_threshold: High threshold

esp_err_t tsl2591_set_test_intr(tsl2591_t *dev)

Set interrupt.

At least on interrupt must be enabled.

Return

ESP_PK on success

Parameters
  • dev: Device descriptor

esp_err_t tsl2591_clear_als_intr(tsl2591_t *dev)

Clear ALS interrupt.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

esp_err_t tsl2591_clear_als_np_intr(tsl2591_t *dev)

Clear ALS no persist interrupt.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

esp_err_t tsl2591_clear_both_intr(tsl2591_t *dev)

Clear both interrupts.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

esp_err_t tsl2591_get_np_intr_flag(tsl2591_t *dev, bool *flag)

Get ALS no persist interrupt flag.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] flag: Interrupt flag

esp_err_t tsl2591_get_als_intr_flag(tsl2591_t *dev, bool *flag)

Get ALS interrupt flag.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] flag: Interrupt flag

esp_err_t tsl2591_get_als_valid_flag(tsl2591_t *dev, bool *flag)

Get ALS validity flag.

This flag is set when integration cycle is completed after enabling ALS.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] flag: Validity flag

struct tsl2591_settings_t
#include <tsl2591.h>

Device settings.

struct tsl2591_t
#include <tsl2591.h>

Device descriptor.