#include <stddef.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_log.h"
#include "tsl2561.h"
|
#define | REG_CONTROL 0x00 |
|
#define | REG_TIMING 0x01 |
|
#define | REG_THRESHLOWLOW 0x02 |
|
#define | REG_THRESHLOWHIGH 0x03 |
|
#define | REG_THRESHHIGHLOW 0x04 |
|
#define | REG_THRESHHIGHHIGH 0x05 |
|
#define | REG_INTERRUPT 0x06 |
|
#define | REG_ID 0x0A |
|
#define | REG_DATA0LOW 0x0C |
|
#define | REG_DATA0HIGH 0x0D |
|
#define | REG_DATA1LOW 0x0E |
|
#define | REG_DATA1HIGH 0x0F |
|
#define | SMB_BLOCK 0x10 |
|
#define | SMB_WORD 0x20 |
|
#define | SMB_CLEAR 0x40 |
|
#define | SMB_COMMAND 0x80 |
|
#define | TSL2561_CONTROL_POWER_UP 0x03 |
|
#define | TSL2561_CONTROL_POWER_DOWN 0x00 |
|
#define | DEFAULT_INTEGRATION_TIME TSL2561_INTEGRATION_TIME_402MS |
|
#define | DEFAULT_GAIN TSL2561_GAIN_1X |
|
#define | CH_SCALE 10 |
|
#define | CH_SCALE_TINT0 0x7517 |
|
#define | CH_SCALE_TINT1 0x0FE7 |
|
#define | RATIO_SCALE 9 |
|
#define | LUX_SCALE 14 |
|
#define | TSL2561_K1T 0x0040 |
|
#define | TSL2561_B1T 0x01F2 |
|
#define | TSL2561_M1T 0x01BE |
|
#define | TSL2561_K2T 0x0080 |
|
#define | TSL2561_B2T 0x0214 |
|
#define | TSL2561_M2T 0x02D1 |
|
#define | TSL2561_K3T 0x00C0 |
|
#define | TSL2561_B3T 0x023F |
|
#define | TSL2561_M3T 0x037B |
|
#define | TSL2561_K4T 0x0100 |
|
#define | TSL2561_B4T 0x0270 |
|
#define | TSL2561_M4T 0x03FE |
|
#define | TSL2561_K5T 0x0138 |
|
#define | TSL2561_B5T 0x016F |
|
#define | TSL2561_M5T 0x01fC |
|
#define | TSL2561_K6T 0x019A |
|
#define | TSL2561_B6T 0x00D2 |
|
#define | TSL2561_M6T 0x00FB |
|
#define | TSL2561_K7T 0x029A |
|
#define | TSL2561_B7T 0x0018 |
|
#define | TSL2561_M7T 0x0012 |
|
#define | TSL2561_K8T 0x029A |
|
#define | TSL2561_B8T 0x0000 |
|
#define | TSL2561_M8T 0x0000 |
|
#define | TSL2561_K1C 0x0043 |
|
#define | TSL2561_B1C 0x0204 |
|
#define | TSL2561_M1C 0x01AD |
|
#define | TSL2561_K2C 0x0085 |
|
#define | TSL2561_B2C 0x0228 |
|
#define | TSL2561_M2C 0x02C1 |
|
#define | TSL2561_K3C 0x00C8 |
|
#define | TSL2561_B3C 0x0253 |
|
#define | TSL2561_M3C 0x0363 |
|
#define | TSL2561_K4C 0x010A |
|
#define | TSL2561_B4C 0x0282 |
|
#define | TSL2561_M4C 0x03DF |
|
#define | TSL2561_K5C 0x014D |
|
#define | TSL2561_B5C 0x0177 |
|
#define | TSL2561_M5C 0x01DD |
|
#define | TSL2561_K6C 0x019A |
|
#define | TSL2561_B6C 0x0101 |
|
#define | TSL2561_M6C 0x0127 |
|
#define | TSL2561_K7C 0x029A |
|
#define | TSL2561_B7C 0x0037 |
|
#define | TSL2561_M7C 0x002B |
|
#define | TSL2561_K8C 0x029A |
|
#define | TSL2561_B8C 0x0000 |
|
#define | TSL2561_M8C 0x0000 |
|
Acknowledgements to Kevin Townsend for the Adafruit TSL2561 driver: https://github.com/adafruit/Adafruit_TSL2561 Acknowledgements to https://github.com/lexruee/tsl2561 for a working reference.
Construct a new TSL2561 info instance. New instance should be initialised before calling other functions.
- Returns
- Pointer to new device info instance, or NULL if it cannot be created.
Delete an existing TSL2561 info instance.
- Parameters
-
[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.
- Parameters
-
[in] | tsl2561_info | Pointer to TSL2561 info instance. |
[in] | smbus_info | Pointer to SMBus info instance. |
Retrieve the Device Type ID and Revision number from the device.
- Parameters
-
[in] | tsl2561_info | Pointer to initialised TSL2561 info instance. |
[out] | device | The retrieved Device Type ID. |
[out] | revision | The retrieved Device Revision number. |
- Returns
- ESP_OK if successful, ESP_FAIL or ESP_ERR_* if an error occurred.
Retrieve a visible and infrared light measurement from the device. This function will sleep until the integration time has passed.
- Parameters
-
[in] | tsl2561_info | Pointer to initialised TSL2561 info instance. |
[out] | visible | The resultant visible light measurement. |
[out] | infrared | The resultant infrared light measurement. |
- Returns
- ESP_OK if successful, ESP_FAIL or ESP_ERR_* if an error occurred.
Set the integration time and gain. These values are set together as they are programmed via the same register.
- Parameters
-
[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. |
- Returns
- ESP_OK if successful, ESP_FAIL or ESP_ERR_* if an error occurred.
Compute the Lux approximation from a visible and infrared light measurement. The calculation is performed according to the procedure given in the datasheet.
- Parameters
-
[in] | tsl2561_info | Pointer to initialised TSL2561 info instance. |
[in] | visible | The visible light measurement. |
[in] | infrared | The infrared light measurement. |
- Returns
- The resulting approximation of the light measurement in Lux.