LibDriver TSL2561
Loading...
Searching...
No Matches
driver_tsl2561_interrupt.c
Go to the documentation of this file.
1
37
39
40static tsl2561_handle_t gs_handle;
41
54 uint16_t ch0_low_threshold, uint16_t ch0_high_threshold)
55{
56 uint8_t res;
57
58 /* link interface function */
66
67 /* set iic address */
68 res = tsl2561_set_addr_pin(&gs_handle, addr_pin);
69 if (res != 0)
70 {
71 tsl2561_interface_debug_print("tsl2561: set addr pin failed.\n");
72
73 return 1;
74 }
75
76 /* tsl2561 init */
77 res = tsl2561_init(&gs_handle);
78 if (res != 0)
79 {
80 tsl2561_interface_debug_print("tsl2561: init failed.\n");
81
82 return 1;
83 }
84
85 /* wake up */
86 res = tsl2561_wake_up(&gs_handle);
87 if (res != 0)
88 {
89 tsl2561_interface_debug_print("tsl2561: wake up failed.\n");
90 (void)tsl2561_deinit(&gs_handle);
91
92 return 1;
93 }
94
95 /* set gain */
97 if (res != 0)
98 {
99 tsl2561_interface_debug_print("tsl2561: set gain failed.\n");
100 (void)tsl2561_deinit(&gs_handle);
101
102 return 1;
103 }
104
105 /* set integration time */
107 if (res != 0)
108 {
109 tsl2561_interface_debug_print("tsl2561: set integration time failed.\n");
110 (void)tsl2561_deinit(&gs_handle);
111
112 return 1;
113 }
114
115 /* set interrupt mode */
116 res =tsl2561_set_interrupt_mode(&gs_handle, mode);
117 if (res != 0)
118 {
119 tsl2561_interface_debug_print("tsl2561: set interrupt mode failed.\n");
120 (void)tsl2561_deinit(&gs_handle);
121
122 return 1;
123 }
124
125 /* set interrupt */
126 res = tsl2561_set_interrupt(&gs_handle, TSL2561_BOOL_TRUE);
127 if (res != 0)
128 {
129 tsl2561_interface_debug_print("tsl2561: disable interrupt failed.\n");
130 (void)tsl2561_deinit(&gs_handle);
131
132 return 1;
133 }
134
135 /* set interrupt high threshold */
136 res = tsl2561_set_interrupt_high_threshold(&gs_handle, ch0_high_threshold);
137 if (res != 0)
138 {
139 tsl2561_interface_debug_print("tsl2561: set interrupt high threshold failed.\n");
140 (void)tsl2561_deinit(&gs_handle);
141
142 return 1;
143 }
144
145 /* set interrupt low threshold */
146 res = tsl2561_set_interrupt_low_threshold(&gs_handle, ch0_low_threshold);
147 if (res != 0)
148 {
149 tsl2561_interface_debug_print("tsl2561: set interrupt low threshold failed.\n");
150 (void)tsl2561_deinit(&gs_handle);
151
152 return 1;
153 }
154
155 return 0;
156}
157
166uint8_t tsl2561_interrupt_read(uint32_t *lux)
167{
168 uint16_t channel_0_raw;
169 uint16_t channel_1_raw;
170
171 /* read data */
172 if (tsl2561_read(&gs_handle, (uint16_t *)&channel_0_raw, (uint16_t *)&channel_1_raw, lux) != 0)
173 {
174 return 1;
175 }
176 else
177 {
178 return 0;
179 }
180}
181
190{
191 /* close tsl2561 */
192 if (tsl2561_deinit(&gs_handle) != 0)
193 {
194 return 1;
195 }
196 else
197 {
198 return 0;
199 }
200}
driver tsl2561 interrupt 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
@ TSL2561_BOOL_TRUE
uint8_t tsl2561_interrupt_deinit(void)
interrupt example deinit
#define TSL2561_INTERRUPT_DEFAULT_INTEGRATION_TIME
#define TSL2561_INTERRUPT_DEFAULT_GAIN
tsl2561 interrupt example default definition
uint8_t tsl2561_interrupt_init(tsl2561_address_t addr_pin, tsl2561_interrupt_mode_t mode, uint16_t ch0_low_threshold, uint16_t ch0_high_threshold)
interrupt example init
uint8_t tsl2561_interrupt_read(uint32_t *lux)
interrupt example read
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
tsl2561_interrupt_mode_t
tsl2561 interrupt mode enumeration definition
uint8_t tsl2561_set_interrupt(tsl2561_handle_t *handle, tsl2561_bool_t enable)
enable or disable the chip interrupt