LibDriver MAX44009
Loading...
Searching...
No Matches
driver_max44009_interrupt.c
Go to the documentation of this file.
1
36
38
39static max44009_handle_t gs_handle;
40
52uint8_t max44009_interrupt_init(max44009_address_t addr_pin, float low_threshold_lux, float high_threshold_lux, float time_ms)
53{
54 uint8_t res;
55 uint8_t reg;
56
57 /* link interface function */
65
66 /* set the addr pin */
67 res = max44009_set_addr_pin(&gs_handle, addr_pin);
68 if (res != 0)
69 {
70 max44009_interface_debug_print("max44009: set addr pin failed.\n");
71
72 return 1;
73 }
74
75 /* init */
76 res = max44009_init(&gs_handle);
77 if (res != 0)
78 {
79 max44009_interface_debug_print("max44009: init failed.\n");
80
81 return 1;
82 }
83
84 /* set default auto range */
86 if (res != 0)
87 {
88 max44009_interface_debug_print("max44009: set auto range failed.\n");
89 (void)max44009_deinit(&gs_handle);
90
91 return 1;
92 }
93
94 /* set default continuous mode */
96 if (res != 0)
97 {
98 max44009_interface_debug_print("max44009: set continuous mode failed.\n");
99 (void)max44009_deinit(&gs_handle);
100
101 return 1;
102 }
103
104#if (MAX44009_BASIC_DEFAULT_AUTO_RANGE != MAX44009_BOOL_FALSE)
105 /* set default current div 8 */
107 if (res != 0)
108 {
109 max44009_interface_debug_print("max44009: set current div 8 failed.\n");
110 (void)max44009_deinit(&gs_handle);
111
112 return 1;
113 }
114
115 /* set default integration time */
117 if (res != 0)
118 {
119 max44009_interface_debug_print("max44009: set integration time failed.\n");
120 (void)max44009_deinit(&gs_handle);
121
122 return 1;
123 }
124#endif
125
126 /* threshold convert to register */
127 res = max44009_threshold_convert_to_register(&gs_handle, low_threshold_lux, &reg);
128 if (res != 0)
129 {
130 max44009_interface_debug_print("max44009: threshold convert to register failed.\n");
131 (void)max44009_deinit(&gs_handle);
132
133 return 1;
134 }
135
136 /* set interrupt low threshold */
137 res = max44009_set_interrupt_low_threshold(&gs_handle, reg);
138 if (res != 0)
139 {
140 max44009_interface_debug_print("max44009: set interrupt low threshold failed.\n");
141 (void)max44009_deinit(&gs_handle);
142
143 return 1;
144 }
145
146 /* threshold convert to register */
147 res = max44009_threshold_convert_to_register(&gs_handle, high_threshold_lux, &reg);
148 if (res != 0)
149 {
150 max44009_interface_debug_print("max44009: threshold convert to register failed.\n");
151 (void)max44009_deinit(&gs_handle);
152
153 return 1;
154 }
155
156 /* set interrupt high threshold */
157 res = max44009_set_interrupt_high_threshold(&gs_handle, reg);
158 if (res != 0)
159 {
160 max44009_interface_debug_print("max44009: set interrupt high threshold failed.\n");
161 (void)max44009_deinit(&gs_handle);
162
163 return 1;
164 }
165
166 /* timer convert to register */
167 res = max44009_timer_convert_to_register(&gs_handle, time_ms, &reg);
168 if (res != 0)
169 {
170 max44009_interface_debug_print("max44009: timer convert to register failed.\n");
171 (void)max44009_deinit(&gs_handle);
172
173 return 1;
174 }
175
176 /* set threshold timer */
177 res = max44009_set_threshold_timer(&gs_handle, reg);
178 if (res != 0)
179 {
180 max44009_interface_debug_print("max44009: set threshold timer failed.\n");
181 (void)max44009_deinit(&gs_handle);
182
183 return 1;
184 }
185
186 /* enable interrupt */
188 if (res != 0)
189 {
190 max44009_interface_debug_print("max44009: set interrupt failed.\n");
191 (void)max44009_deinit(&gs_handle);
192
193 return 1;
194 }
195
196 return 0;
197}
198
207uint8_t max44009_interrupt_read(float *lux)
208{
209 uint8_t res;
210 uint16_t raw;
211
212 /* read */
213 res = max44009_read(&gs_handle, &raw, lux);
214 if (res != 0)
215 {
216 return 1;
217 }
218
219 return 0;
220}
221
230{
231 uint8_t res;
232
233 /* deinit */
234 res = max44009_deinit(&gs_handle);
235 if (res != 0)
236 {
237 return 1;
238 }
239
240 return 0;
241}
driver max44009 interrupt header file
uint8_t max44009_read(max44009_handle_t *handle, uint16_t *raw, float *lux)
read data
uint8_t max44009_set_integration_time(max44009_handle_t *handle, max44009_integration_time_t t)
set integration time
uint8_t max44009_set_current_div_8(max44009_handle_t *handle, max44009_bool_t enable)
enable or disable current div 8
uint8_t max44009_set_interrupt_high_threshold(max44009_handle_t *handle, uint8_t threshold)
set interrupt high threshold
struct max44009_handle_s max44009_handle_t
max44009 handle structure definition
uint8_t max44009_threshold_convert_to_register(max44009_handle_t *handle, float lux, uint8_t *reg)
convert the threshold to the register raw data
uint8_t max44009_set_addr_pin(max44009_handle_t *handle, max44009_address_t addr_pin)
set the address pin
uint8_t max44009_set_interrupt_low_threshold(max44009_handle_t *handle, uint8_t threshold)
set interrupt low threshold
uint8_t max44009_set_continuous_mode(max44009_handle_t *handle, max44009_bool_t enable)
enable or disable continuous mode
max44009_address_t
max44009 address enumeration definition
uint8_t max44009_set_interrupt(max44009_handle_t *handle, max44009_bool_t enable)
enable or disable interrupt
uint8_t max44009_deinit(max44009_handle_t *handle)
close the chip
uint8_t max44009_init(max44009_handle_t *handle)
initialize the chip
uint8_t max44009_set_auto_range(max44009_handle_t *handle, max44009_bool_t enable)
enable or disable auto range
uint8_t max44009_set_threshold_timer(max44009_handle_t *handle, uint8_t t)
set threshold timer
uint8_t max44009_timer_convert_to_register(max44009_handle_t *handle, float ms, uint8_t *reg)
convert the timer to the register raw data
@ MAX44009_BOOL_TRUE
uint8_t max44009_interrupt_init(max44009_address_t addr_pin, float low_threshold_lux, float high_threshold_lux, float time_ms)
interrupt example init
#define MAX44009_INTERRUPT_DEFAULT_AUTO_RANGE
max44009 interrupt example default definition
#define MAX44009_INTERRUPT_DEFAULT_INTEGRATION_TIME
uint8_t max44009_interrupt_read(float *lux)
interrupt example read
#define MAX44009_INTERRUPT_DEFAULT_CONTINUOUS_MODE
uint8_t max44009_interrupt_deinit(void)
interrupt example deinit
#define MAX44009_INTERRUPT_DEFAULT_CURRENT_DIV_8
void max44009_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t max44009_interface_iic_init(void)
interface iic bus init
uint8_t max44009_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t max44009_interface_iic_deinit(void)
interface iic bus deinit
uint8_t max44009_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void max44009_interface_delay_ms(uint32_t ms)
interface delay ms