43#define CHIP_NAME "AMS TSL2561"
44#define MANUFACTURER_NAME "AMS"
45#define SUPPLY_VOLTAGE_MIN 2.7f
46#define SUPPLY_VOLTAGE_MAX 3.6f
47#define MAX_CURRENT 0.60f
48#define TEMPERATURE_MIN -40.0f
49#define TEMPERATURE_MAX 85.0f
50#define DRIVER_VERSION 2000
55#define TSL2561_REG_CONTROL 0x80
56#define TSL2561_REG_TIMING 0x81
57#define TSL2561_REG_THRESHLOWLOW 0xA2
58#define TSL2561_REG_THRESHLOWHIGH 0xA3
59#define TSL2561_REG_THRESHHIGHLOW 0xA4
60#define TSL2561_REG_THRESHHIGHHIGH 0xA5
61#define TSL2561_REG_INTERRUPT 0x86
62#define TSL2561_REG_ID 0x8A
63#define TSL2561_REG_DATA0LOW 0xEC
64#define TSL2561_REG_DATA0HIGH 0xED
65#define TSL2561_REG_DATA1LOW 0xEE
66#define TSL2561_REG_DATA1HIGH 0xEF
71#define TSL2561_CONTROL_POWERON 0x03
72#define TSL2561_CONTROL_POWEROFF 0x00
73#define TSL2561_LUX_LUXSCALE 14
74#define TSL2561_LUX_RATIOSCALE 9
75#define TSL2561_LUX_CHSCALE 10
76#define TSL2561_LUX_CHSCALE_TINT0 0x7517U
77#define TSL2561_LUX_CHSCALE_TINT1 0x0FE7U
78#define TSL2561_LUX_K1T 0x0040U
79#define TSL2561_LUX_B1T 0x01F2U
80#define TSL2561_LUX_M1T 0x01BEU
81#define TSL2561_LUX_K2T 0x0080U
82#define TSL2561_LUX_B2T 0x0214U
83#define TSL2561_LUX_M2T 0x02D1U
84#define TSL2561_LUX_K3T 0x00C0U
85#define TSL2561_LUX_B3T 0x023FU
86#define TSL2561_LUX_M3T 0x037BU
87#define TSL2561_LUX_K4T 0x0100U
88#define TSL2561_LUX_B4T 0x0270U
89#define TSL2561_LUX_M4T 0x03FEU
90#define TSL2561_LUX_K5T 0x0138U
91#define TSL2561_LUX_B5T 0x016FU
92#define TSL2561_LUX_M5T 0x01FCU
93#define TSL2561_LUX_K6T 0x019AU
94#define TSL2561_LUX_B6T 0x00D2U
95#define TSL2561_LUX_M6T 0x00FBU
96#define TSL2561_LUX_K7T 0x029AU
97#define TSL2561_LUX_B7T 0x0018U
98#define TSL2561_LUX_M7T 0x0012U
99#define TSL2561_LUX_K8T 0x029AU
100#define TSL2561_LUX_B8T 0x0000U
101#define TSL2561_LUX_M8T 0x0000U
102#define TSL2561_GAIN_0X 0x00
103#define TSL2561_GAIN_16X 0x10
114static uint32_t a_tsl2561_calculate_lux(uint16_t gain, uint16_t t, uint16_t ch0, uint16_t ch1)
148 ch_scale = ch_scale << 4;
156 ratio = (ratio1 + 1) >> 1;
197 temp = ((channel_0 * b) - (channel_1 * m));
228 handle->
debug_print(
"tsl2561: iic_init is null.\n");
234 handle->
debug_print(
"tsl2561: iic_deinit is null.\n");
240 handle->
debug_print(
"tsl2561: iic_read is null.\n");
246 handle->
debug_print(
"tsl2561: iic_write is null.\n");
252 handle->
debug_print(
"tsl2561: delay_ms is null.\n");
259 handle->
debug_print(
"tsl2561: iic init failed.\n");
272 if (!(
id == 0x10 ||
id == 0x50))
310 handle->
debug_print(
"tsl2561: power down failed.\n");
316 handle->
debug_print(
"tsl2561: iic deinit failed.\n");
342 handle->
iic_addr = (uint8_t)addr_pin;
396 memset(buf, 0,
sizeof(uint8_t) * 2);
403 *channel_0_raw = ((uint16_t)buf[1] << 8) | buf[0];
404 memset(buf, 0,
sizeof(uint8_t) * 2);
411 *channel_1_raw = ((uint16_t)buf[1] << 8) | buf[0];
418 *lux = a_tsl2561_calculate_lux((prev & 0x10) >> 4, prev & 0x03, *channel_0_raw, *channel_1_raw);
766 buf[0] = ch0_raw & 0xFF;
767 buf[1] = (ch0_raw >> 8) & 0xFF;
804 memset(buf, 0,
sizeof(uint8_t) * 2);
812 *ch0_raw = ((uint16_t)buf[1] << 8) | buf[0];
840 buf[0] = ch0_raw & 0xFF;
841 buf[1] = (ch0_raw >> 8) & 0xFF;
878 memset(buf, 0,
sizeof(uint8_t) * 2);
886 *ch0_raw = ((uint16_t)buf[1] << 8) | buf[0];
#define TSL2561_REG_DATA0LOW
#define TSL2561_REG_THRESHLOWLOW
#define TSL2561_CONTROL_POWERON
command definition
#define TSL2561_LUX_RATIOSCALE
#define TSL2561_REG_DATA1LOW
#define TSL2561_REG_THRESHHIGHLOW
#define TSL2561_LUX_CHSCALE_TINT0
#define TSL2561_LUX_LUXSCALE
#define SUPPLY_VOLTAGE_MAX
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define TSL2561_LUX_CHSCALE_TINT1
#define TSL2561_REG_INTERRUPT
#define TSL2561_REG_TIMING
#define TSL2561_REG_CONTROL
chip register definition
#define CHIP_NAME
chip information definition
#define TSL2561_CONTROL_POWEROFF
#define TSL2561_LUX_CHSCALE
driver tsl2561 header file
uint8_t tsl2561_read(tsl2561_handle_t *handle, uint16_t *channel_0_raw, uint16_t *channel_1_raw, uint32_t *lux)
read data from the chip
uint8_t tsl2561_deinit(tsl2561_handle_t *handle)
close the chip
uint8_t tsl2561_power_down(tsl2561_handle_t *handle)
power down the chip
uint8_t tsl2561_get_integration_time(tsl2561_handle_t *handle, tsl2561_integration_time_t *t)
get the integration time
uint8_t tsl2561_set_addr_pin(tsl2561_handle_t *handle, tsl2561_address_t addr_pin)
set the iic address pin
uint8_t tsl2561_init(tsl2561_handle_t *handle)
initialize the chip
tsl2561_bool_t
tsl2561 bool enumeration definition
uint8_t tsl2561_get_addr_pin(tsl2561_handle_t *handle, tsl2561_address_t *addr_pin)
get the iic address pin
uint8_t tsl2561_info(tsl2561_info_t *info)
get chip's information
tsl2561_address_t
tsl2561 address enumeration definition
uint8_t tsl2561_set_gain(tsl2561_handle_t *handle, tsl2561_gain_t gain)
set the adc gain
struct tsl2561_handle_s tsl2561_handle_t
tsl2561 handle structure definition
uint8_t tsl2561_get_gain(tsl2561_handle_t *handle, tsl2561_gain_t *gain)
get the adc gain
uint8_t tsl2561_set_integration_time(tsl2561_handle_t *handle, tsl2561_integration_time_t t)
set the integration time
tsl2561_gain_t
tsl2561 gain enumeration definition
struct tsl2561_info_s tsl2561_info_t
tsl2561 information structure definition
tsl2561_integration_time_t
tsl2561 integration time enumeration definition
uint8_t tsl2561_wake_up(tsl2561_handle_t *handle)
wake up the chip
uint8_t tsl2561_get_reg(tsl2561_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t tsl2561_set_reg(tsl2561_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t tsl2561_set_interrupt_mode(tsl2561_handle_t *handle, tsl2561_interrupt_mode_t mode)
set the interrupt mode
uint8_t tsl2561_set_interrupt_low_threshold(tsl2561_handle_t *handle, uint16_t ch0_raw)
set the interrupt low threshold
uint8_t tsl2561_set_interrupt_high_threshold(tsl2561_handle_t *handle, uint16_t ch0_raw)
set the interrupt high threshold
tsl2561_interrupt_mode_t
tsl2561 interrupt mode enumeration definition
uint8_t tsl2561_get_interrupt_low_threshold(tsl2561_handle_t *handle, uint16_t *ch0_raw)
get the interrupt low threshold
uint8_t tsl2561_get_interrupt(tsl2561_handle_t *handle, tsl2561_bool_t *enable)
get the chip interrupt
uint8_t tsl2561_set_interrupt(tsl2561_handle_t *handle, tsl2561_bool_t enable)
enable or disable the chip interrupt
uint8_t tsl2561_get_interrupt_mode(tsl2561_handle_t *handle, tsl2561_interrupt_mode_t *mode)
get the interrupt mode
uint8_t tsl2561_get_interrupt_high_threshold(tsl2561_handle_t *handle, uint16_t *ch0_raw)
get the interrupt high threshold
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v