LibDriver TSL2561
Loading...
Searching...
No Matches
driver_tsl2561_basic.c
Go to the documentation of this file.
1
37
39
40static tsl2561_handle_t gs_handle;
41
51{
52 uint8_t res;
53
54 /* link interface function */
62
63 /* set iic address */
64 res = tsl2561_set_addr_pin(&gs_handle, addr_pin);
65 if (res != 0)
66 {
67 tsl2561_interface_debug_print("tsl2561: set addr pin failed.\n");
68
69 return 1;
70 }
71
72 /* tsl2561 init */
73 res = tsl2561_init(&gs_handle);
74 if (res != 0)
75 {
76 tsl2561_interface_debug_print("tsl2561: init failed.\n");
77
78 return 1;
79 }
80
81 /* wake up */
82 res = tsl2561_wake_up(&gs_handle);
83 if (res != 0)
84 {
85 tsl2561_interface_debug_print("tsl2561: wake up failed.\n");
86 (void)tsl2561_deinit(&gs_handle);
87
88 return 1;
89 }
90
91 /* set gain */
93 if (res != 0)
94 {
95 tsl2561_interface_debug_print("tsl2561: set gain failed.\n");
96 (void)tsl2561_deinit(&gs_handle);
97
98 return 1;
99 }
100
101 /* set integration time */
103 if (res != 0)
104 {
105 tsl2561_interface_debug_print("tsl2561: set integration time failed.\n");
106 (void)tsl2561_deinit(&gs_handle);
107
108 return 1;
109 }
110
111 /* set interrupt mode */
113 if (res != 0)
114 {
115 tsl2561_interface_debug_print("tsl2561: set interrupt mode failed.\n");
116 (void)tsl2561_deinit(&gs_handle);
117
118 return 1;
119 }
120
121 /* set interrupt */
123 if (res != 0)
124 {
125 tsl2561_interface_debug_print("tsl2561: disable interrupt failed.\n");
126 (void)tsl2561_deinit(&gs_handle);
127
128 return 1;
129 }
130
131 /* set interrupt high threshold */
133 if (res != 0)
134 {
135 tsl2561_interface_debug_print("tsl2561: set interrupt high threshold failed.\n");
136 (void)tsl2561_deinit(&gs_handle);
137
138 return 1;
139 }
140
141 /* set interrupt low threshold */
143 if (res != 0)
144 {
145 tsl2561_interface_debug_print("tsl2561: set interrupt low threshold failed.\n");
146 (void)tsl2561_deinit(&gs_handle);
147
148 return 1;
149 }
150
151 return 0;
152}
153
162uint8_t tsl2561_basic_read(uint32_t *lux)
163{
164 uint16_t channel_0_raw;
165 uint16_t channel_1_raw;
166
167 /* read data */
168 if (tsl2561_read(&gs_handle, (uint16_t *)&channel_0_raw, (uint16_t *)&channel_1_raw, lux) != 0)
169 {
170 return 1;
171 }
172 else
173 {
174 return 0;
175 }
176}
177
186{
187 /* close tsl2561 */
188 if (tsl2561_deinit(&gs_handle) != 0)
189 {
190 return 1;
191 }
192 else
193 {
194 return 0;
195 }
196}
driver tsl2561 basic 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_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_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_set_integration_time(tsl2561_handle_t *handle, tsl2561_integration_time_t t)
set the integration time
uint8_t tsl2561_wake_up(tsl2561_handle_t *handle)
wake up the chip
#define TSL2561_BASIC_DEFAULT_GAIN
tsl2561 basic example default definition
#define TSL2561_BASIC_DEFAULT_INTERRUPT
#define TSL2561_BASIC_DEFAULT_INTERRUPT_LOW_THRESHOLD
#define TSL2561_BASIC_DEFAULT_INTERRUPT_HIGH_THRESHOLD
#define TSL2561_BASIC_DEFAULT_INTERRUPT_MODE
#define TSL2561_BASIC_DEFAULT_INTEGRATION_TIME
uint8_t tsl2561_basic_read(uint32_t *lux)
basic example read
uint8_t tsl2561_basic_init(tsl2561_address_t addr_pin)
basic example init
uint8_t tsl2561_basic_deinit(void)
basic example deinit
uint8_t tsl2561_interface_iic_init(void)
interface iic bus init
uint8_t tsl2561_interface_iic_deinit(void)
interface iic bus deinit
void tsl2561_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t tsl2561_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t tsl2561_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void tsl2561_interface_delay_ms(uint32_t ms)
interface delay ms
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
uint8_t tsl2561_set_interrupt(tsl2561_handle_t *handle, tsl2561_bool_t enable)
enable or disable the chip interrupt