LibDriver TSL2561
Loading...
Searching...
No Matches
driver_tsl2561.h
Go to the documentation of this file.
1
37
38#ifndef DRIVER_TSL2561_H
39#define DRIVER_TSL2561_H
40
41#include <stdio.h>
42#include <stdint.h>
43#include <string.h>
44
45#ifdef __cplusplus
46extern "C"{
47#endif
48
54
59
69
73typedef enum
74{
78
82typedef enum
83{
87
97
101
106
129
133
138
142typedef struct tsl2561_handle_s
143{
144 uint8_t iic_addr;
145 uint8_t (*iic_init)(void);
146 uint8_t (*iic_deinit)(void);
147 uint8_t (*iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len);
148 uint8_t (*iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len);
149 void (*delay_ms)(uint32_t ms);
150 void (*debug_print)(const char *const fmt, ...);
151 uint8_t inited;
153
169
173
180
187#define DRIVER_TSL2561_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
188
195#define DRIVER_TSL2561_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC
196
203#define DRIVER_TSL2561_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC
204
211#define DRIVER_TSL2561_LINK_IIC_READ(HANDLE, FUC) (HANDLE)->iic_read = FUC
212
219#define DRIVER_TSL2561_LINK_IIC_WRITE(HANDLE, FUC) (HANDLE)->iic_write = FUC
220
227#define DRIVER_TSL2561_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
228
235#define DRIVER_TSL2561_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
236
240
247
256uint8_t tsl2561_info(tsl2561_info_t *info);
257
269
281
292uint8_t tsl2561_init(tsl2561_handle_t *handle);
293
304uint8_t tsl2561_deinit(tsl2561_handle_t *handle);
305
319uint8_t tsl2561_read(tsl2561_handle_t *handle, uint16_t *channel_0_raw, uint16_t *channel_1_raw, uint32_t *lux);
320
331uint8_t tsl2561_power_down(tsl2561_handle_t *handle);
332
343uint8_t tsl2561_wake_up(tsl2561_handle_t *handle);
344
356
367uint8_t tsl2561_get_gain(tsl2561_handle_t *handle, tsl2561_gain_t *gain);
368
380
392
396
403
415
427
439
451
462uint8_t tsl2561_set_interrupt_high_threshold(tsl2561_handle_t *handle, uint16_t ch0_raw);
463
474uint8_t tsl2561_get_interrupt_high_threshold(tsl2561_handle_t *handle, uint16_t *ch0_raw);
475
486uint8_t tsl2561_set_interrupt_low_threshold(tsl2561_handle_t *handle, uint16_t ch0_raw);
487
498uint8_t tsl2561_get_interrupt_low_threshold(tsl2561_handle_t *handle, uint16_t *ch0_raw);
499
503
510
524uint8_t tsl2561_set_reg(tsl2561_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len);
525
539uint8_t tsl2561_get_reg(tsl2561_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len);
540
544
548
549#ifdef __cplusplus
550}
551#endif
552
553#endif
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
@ TSL2561_BOOL_TRUE
@ TSL2561_BOOL_FALSE
@ TSL2561_ADDRESS_VCC
@ TSL2561_ADDRESS_FLOAT
@ TSL2561_ADDRESS_GND
@ TSL2561_GAIN_16
@ TSL2561_GAIN_1
@ TSL2561_INTEGRATION_TIME_402MS
@ TSL2561_INTEGRATION_TIME_101MS
@ TSL2561_INTEGRATION_TIME_13MS
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
@ TSL2561_INTERRUPT_MODE_EVERY_ADC_CYCLE
@ TSL2561_INTERRUPT_MODE_11_INTEGRATION_TIME_OUT_OF_RANGE
@ TSL2561_INTERRUPT_MODE_9_INTEGRATION_TIME_OUT_OF_RANGE
@ TSL2561_INTERRUPT_MODE_3_INTEGRATION_TIME_OUT_OF_RANGE
@ TSL2561_INTERRUPT_MODE_10_INTEGRATION_TIME_OUT_OF_RANGE
@ TSL2561_INTERRUPT_MODE_2_INTEGRATION_TIME_OUT_OF_RANGE
@ TSL2561_INTERRUPT_MODE_13_INTEGRATION_TIME_OUT_OF_RANGE
@ TSL2561_INTERRUPT_MODE_12_INTEGRATION_TIME_OUT_OF_RANGE
@ TSL2561_INTERRUPT_MODE_6_INTEGRATION_TIME_OUT_OF_RANGE
@ TSL2561_INTERRUPT_MODE_7_INTEGRATION_TIME_OUT_OF_RANGE
@ TSL2561_INTERRUPT_MODE_14_INTEGRATION_TIME_OUT_OF_RANGE
@ TSL2561_INTERRUPT_MODE_ANY_VALUE_OUT_OF_THRESHOLD_RANGE
@ TSL2561_INTERRUPT_MODE_4_INTEGRATION_TIME_OUT_OF_RANGE
@ TSL2561_INTERRUPT_MODE_8_INTEGRATION_TIME_OUT_OF_RANGE
@ TSL2561_INTERRUPT_MODE_15_INTEGRATION_TIME_OUT_OF_RANGE
@ TSL2561_INTERRUPT_MODE_5_INTEGRATION_TIME_OUT_OF_RANGE
tsl2561 handle structure definition
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)
tsl2561 information structure definition
uint32_t driver_version
char manufacturer_name[32]