esp32-tsl2561
ESP32-compatible C library for TSL2561 Light to Digital Converter.
|
Interface definitions for the ESP32-compatible TSL2561 Light to Digital Converter component. More...
#include <stdbool.h>
#include "smbus.h"
Go to the source code of this file.
Data Structures | |
struct | tsl2561_info_t |
Structure containing information related to the SMBus protocol. More... | |
Typedefs | |
typedef uint8_t | tsl2561_revision_t |
The type of the IC's revision value. | |
typedef uint16_t | tsl2561_visible_t |
The type of a visible light measurement value. | |
typedef uint16_t | tsl2561_infrared_t |
The type of an infrared light measurement value. | |
Enumerations | |
enum | tsl2561_device_type_t { TSL2561_DEVICE_TYPE_INVALID = 0b1111, TSL2561_DEVICE_TYPE_TSL2560CS = 0b0000, TSL2561_DEVICE_TYPE_TSL2561CS = 0b0001, TSL2561_DEVICE_TYPE_TSL2560T_FN_CL = 0b0100, TSL2561_DEVICE_TYPE_TSL2561T_FN_CL = 0b0101 } |
Enum for recognised TSL256x devices. More... | |
enum | tsl2561_integration_time_t { TSL2561_INTEGRATION_TIME_13MS = 0x00, TSL2561_INTEGRATION_TIME_101MS = 0x01, TSL2561_INTEGRATION_TIME_402MS = 0x02 } |
Enum for supported integration durations. These durations assume the default internal oscillator frequency of 735 kHz. More... | |
enum | tsl2561_gain_t { TSL2561_GAIN_1X = 0x00, TSL2561_GAIN_16X = 0x10 } |
Enum for supported gain values. | |
Functions | |
tsl2561_info_t * | tsl2561_malloc (void) |
Construct a new TSL2561 info instance. New instance should be initialised before calling other functions. More... | |
void | tsl2561_free (tsl2561_info_t **tsl2561_info) |
Delete an existing TSL2561 info instance. More... | |
esp_err_t | tsl2561_init (tsl2561_info_t *tsl2561_info, smbus_info_t *smbus_info) |
Initialise a TSL2561 info instance with the specified SMBus information. More... | |
esp_err_t | tsl2561_device_id (const tsl2561_info_t *tsl2561_info, tsl2561_device_type_t *device, tsl2561_revision_t *revision) |
Retrieve the Device Type ID and Revision number from the device. More... | |
esp_err_t | tsl2561_set_integration_time_and_gain (tsl2561_info_t *tsl2561_info, tsl2561_integration_time_t integration_time, tsl2561_gain_t gain) |
Set the integration time and gain. These values are set together as they are programmed via the same register. More... | |
esp_err_t | tsl2561_read (tsl2561_info_t *tsl2561_info, tsl2561_visible_t *visible, tsl2561_infrared_t *infrared) |
Retrieve a visible and infrared light measurement from the device. This function will sleep until the integration time has passed. More... | |
uint32_t | tsl2561_compute_lux (const tsl2561_info_t *tsl2561_info, tsl2561_visible_t visible, tsl2561_infrared_t infrared) |
Compute the Lux approximation from a visible and infrared light measurement. The calculation is performed according to the procedure given in the datasheet. More... | |
Interface definitions for the ESP32-compatible TSL2561 Light to Digital Converter component.
This component provides structures and functions that are useful for communicating with the device.
Technically, the TSL2561 device is an I2C not SMBus device, however the datasheet makes it clear that most SMBus operations are compatible with this device, so it makes sense to use an SMBus interface to manage communication.
Enum for recognised TSL256x devices.
Enum for supported integration durations. These durations assume the default internal oscillator frequency of 735 kHz.
tsl2561_info_t* tsl2561_malloc | ( | void | ) |
Construct a new TSL2561 info instance. New instance should be initialised before calling other functions.
void tsl2561_free | ( | tsl2561_info_t ** | tsl2561_info | ) |
Delete an existing TSL2561 info instance.
[in,out] | tsl2561_info | Pointer to TSL2561 info instance that will be freed and set to NULL. |
esp_err_t tsl2561_init | ( | tsl2561_info_t * | tsl2561_info, |
smbus_info_t * | smbus_info | ||
) |
Initialise a TSL2561 info instance with the specified SMBus information.
[in] | tsl2561_info | Pointer to TSL2561 info instance. |
[in] | smbus_info | Pointer to SMBus info instance. |
esp_err_t tsl2561_device_id | ( | const tsl2561_info_t * | tsl2561_info, |
tsl2561_device_type_t * | device, | ||
tsl2561_revision_t * | revision | ||
) |
Retrieve the Device Type ID and Revision number from the device.
[in] | tsl2561_info | Pointer to initialised TSL2561 info instance. |
[out] | device | The retrieved Device Type ID. |
[out] | revision | The retrieved Device Revision number. |
esp_err_t tsl2561_set_integration_time_and_gain | ( | tsl2561_info_t * | tsl2561_info, |
tsl2561_integration_time_t | integration_time, | ||
tsl2561_gain_t | gain | ||
) |
Set the integration time and gain. These values are set together as they are programmed via the same register.
[in] | tsl2561_info | Pointer to initialised TSL2561 info instance. |
[out] | integration_time | The integration time to use for the next measurement. |
[out] | infrared | The gain setting to use for the next measurement. |
esp_err_t tsl2561_read | ( | tsl2561_info_t * | tsl2561_info, |
tsl2561_visible_t * | visible, | ||
tsl2561_infrared_t * | infrared | ||
) |
Retrieve a visible and infrared light measurement from the device. This function will sleep until the integration time has passed.
[in] | tsl2561_info | Pointer to initialised TSL2561 info instance. |
[out] | visible | The resultant visible light measurement. |
[out] | infrared | The resultant infrared light measurement. |
uint32_t tsl2561_compute_lux | ( | const tsl2561_info_t * | tsl2561_info, |
tsl2561_visible_t | visible, | ||
tsl2561_infrared_t | infrared | ||
) |
Compute the Lux approximation from a visible and infrared light measurement. The calculation is performed according to the procedure given in the datasheet.
[in] | tsl2561_info | Pointer to initialised TSL2561 info instance. |
[in] | visible | The visible light measurement. |
[in] | infrared | The infrared light measurement. |