LibDriver MAX30105
Loading...
Searching...
No Matches
driver_max30105_fifo.c
Go to the documentation of this file.
1
36
38
39static max30105_handle_t gs_handle;
40
49{
50 /* run irq handler */
51 if (max30105_irq_handler(&gs_handle) != 0)
52 {
53 return 1;
54 }
55 else
56 {
57 return 0;
58 }
59}
60
69uint8_t max30105_fifo_init(void (*fifo_receive_callback)(uint8_t type))
70{
71 uint8_t res;
72 uint8_t threshold;
73 max30105_bool_t enable;
74
75 /* link interface function */
83 DRIVER_MAX30105_LINK_RECEIVE_CALLBACK(&gs_handle, fifo_receive_callback);
84
85 /* init the max30105 */
86 res = max30105_init(&gs_handle);
87 if (res != 0)
88 {
89 max30105_interface_debug_print("max30105: init failed.\n");
90
91 return 1;
92 }
93
94 /* enable shutdown */
96 if (res != 0)
97 {
98 max30105_interface_debug_print("max30105: set shutdown failed.\n");
99 (void)max30105_deinit(&gs_handle);
100
101 return 1;
102 }
103
104 /* set fifo sample averaging */
106 if (res != 0)
107 {
108 max30105_interface_debug_print("max30105: set fifo sample averaging failed.\n");
109 (void)max30105_deinit(&gs_handle);
110
111 return 1;
112 }
113
114 /* set fifo roll */
116 if (res != 0)
117 {
118 max30105_interface_debug_print("max30105: set fifo roll failed.\n");
119 (void)max30105_deinit(&gs_handle);
120
121 return 1;
122 }
123
124 /* set fifo almost full */
126 if (res != 0)
127 {
128 max30105_interface_debug_print("max30105: set fifo almost full failed.\n");
129 (void)max30105_deinit(&gs_handle);
130
131 return 1;
132 }
133
134 /* set mode */
136 if (res != 0)
137 {
138 max30105_interface_debug_print("max30105: set mode failed.\n");
139 (void)max30105_deinit(&gs_handle);
140
141 return 1;
142 }
143
144 /* set particle sensing adc range */
146 if (res != 0)
147 {
148 max30105_interface_debug_print("max30105: set particle sensing adc range failed.\n");
149 (void)max30105_deinit(&gs_handle);
150
151 return 1;
152 }
153
154 /* set particle sensing sample rate */
156 if (res != 0)
157 {
158 max30105_interface_debug_print("max30105: set particle sensing sample rate failed.\n");
159 (void)max30105_deinit(&gs_handle);
160
161 return 1;
162 }
163
164 /* set adc resolution */
166 if (res != 0)
167 {
168 max30105_interface_debug_print("max30105: set adc resolution failed.\n");
169 (void)max30105_deinit(&gs_handle);
170
171 return 1;
172 }
173
174 /* set led red pulse amplitude */
176 if (res != 0)
177 {
178 max30105_interface_debug_print("max30105: set led red pulse amplitude failed.\n");
179 (void)max30105_deinit(&gs_handle);
180
181 return 1;
182 }
183
184 /* set led ir pulse amplitude */
186 if (res != 0)
187 {
188 max30105_interface_debug_print("max30105: set led ir pulse amplitude failed.\n");
189 (void)max30105_deinit(&gs_handle);
190
191 return 1;
192 }
193
194 /* set led green pulse amplitude */
196 if (res != 0)
197 {
198 max30105_interface_debug_print("max30105: set led green pulse amplitude failed.\n");
199 (void)max30105_deinit(&gs_handle);
200
201 return 1;
202 }
203
204 /* set led proximity pulse amplitude */
206 if (res != 0)
207 {
208 max30105_interface_debug_print("max30105: set led proximity pulse amplitude failed.\n");
209 (void)max30105_deinit(&gs_handle);
210
211 return 1;
212 }
213
214 /* convert the adc */
216 if (res != 0)
217 {
218 max30105_interface_debug_print("max30105: proximity threshold convert to register failed.\n");
219 (void)max30105_deinit(&gs_handle);
220
221 return 1;
222 }
223
224 /* set proximity interrupt threshold */
225 res = max30105_set_proximity_interrupt_threshold(&gs_handle, threshold);
226 if (res != 0)
227 {
228 max30105_interface_debug_print("max30105: set proximity interrupt threshold failed.\n");
229 (void)max30105_deinit(&gs_handle);
230
231 return 1;
232 }
233
234 /* set slot */
236 if (res != 0)
237 {
238 max30105_interface_debug_print("max30105: set slot failed.\n");
239 (void)max30105_deinit(&gs_handle);
240
241 return 1;
242 }
243
244 /* set slot */
246 if (res != 0)
247 {
248 max30105_interface_debug_print("max30105: set slot failed.\n");
249 (void)max30105_deinit(&gs_handle);
250
251 return 1;
252 }
253
254 /* set slot */
256 if (res != 0)
257 {
258 max30105_interface_debug_print("max30105: set slot failed.\n");
259 (void)max30105_deinit(&gs_handle);
260
261 return 1;
262 }
263
264 /* set slot */
266 if (res != 0)
267 {
268 max30105_interface_debug_print("max30105: set slot failed.\n");
269 (void)max30105_deinit(&gs_handle);
270
271 return 1;
272 }
273
274 /* set die temperature */
276 if (res != 0)
277 {
278 max30105_interface_debug_print("max30105: set die temperature failed.\n");
279 (void)max30105_deinit(&gs_handle);
280
281 return 1;
282 }
283
284 /* set interrupt */
286 if (res != 0)
287 {
288 max30105_interface_debug_print("max30105: set interrupt failed.\n");
289 (void)max30105_deinit(&gs_handle);
290
291 return 1;
292 }
293
294 /* set interrupt */
296 if (res != 0)
297 {
298 max30105_interface_debug_print("max30105: set interrupt failed.\n");
299 (void)max30105_deinit(&gs_handle);
300
301 return 1;
302 }
303
304 /* set interrupt */
306 if (res != 0)
307 {
308 max30105_interface_debug_print("max30105: set interrupt failed.\n");
309 (void)max30105_deinit(&gs_handle);
310
311 return 1;
312 }
313
314 /* set interrupt */
316 if (res != 0)
317 {
318 max30105_interface_debug_print("max30105: set interrupt failed.\n");
319 (void)max30105_deinit(&gs_handle);
320
321 return 1;
322 }
323
324 /* set interrupt */
326 if (res != 0)
327 {
328 max30105_interface_debug_print("max30105: set interrupt failed.\n");
329 (void)max30105_deinit(&gs_handle);
330
331 return 1;
332 }
333
334 /* disable shutdown */
336 if (res != 0)
337 {
338 max30105_interface_debug_print("max30105: set shutdown failed.\n");
339 (void)max30105_deinit(&gs_handle);
340
341 return 1;
342 }
343
344 /* get status */
346 if (res != 0)
347 {
348 max30105_interface_debug_print("max30105: get interrupt status failed.\n");
349 (void)max30105_deinit(&gs_handle);
350
351 return 1;
352 }
353
354 return 0;
355}
356
365{
366 uint8_t res;
367
368 res = max30105_deinit(&gs_handle);
369 if (res != 0)
370 {
371 return 1;
372 }
373 else
374 {
375 return 0;
376 }
377}
378
390uint8_t max30105_fifo_read(uint32_t *raw_red, uint32_t *raw_ir, uint32_t *raw_green, uint8_t *len)
391{
392 uint8_t res;
393
394 res = max30105_read(&gs_handle, raw_red, raw_ir, raw_green, len);
395 if (res != 0)
396 {
397 return 1;
398 }
399 else
400 {
401 return 0;
402 }
403}
driver max30105 fifo header file
uint8_t max30105_init(max30105_handle_t *handle)
initialize the chip
uint8_t max30105_read(max30105_handle_t *handle, uint32_t *raw_red, uint32_t *raw_ir, uint32_t *raw_green, uint8_t *len)
read the data
uint8_t max30105_irq_handler(max30105_handle_t *handle)
irq handler
uint8_t max30105_set_fifo_sample_averaging(max30105_handle_t *handle, max30105_sample_averaging_t sample)
set the fifo sample averaging
uint8_t max30105_set_fifo_almost_full(max30105_handle_t *handle, uint8_t value)
set the fifo almost full value
uint8_t max30105_set_led_red_pulse_amplitude(max30105_handle_t *handle, uint8_t amp)
set the red led pulse amplitude
uint8_t max30105_set_shutdown(max30105_handle_t *handle, max30105_bool_t enable)
set the shutdown
struct max30105_handle_s max30105_handle_t
max30105 handle structure definition
uint8_t max30105_proximity_threshold_convert_to_register(max30105_handle_t *handle, uint32_t adc, uint8_t *reg)
convert the proximity threshold to the register raw data
uint8_t max30105_set_mode(max30105_handle_t *handle, max30105_mode_t mode)
set the mode
uint8_t max30105_set_fifo_roll(max30105_handle_t *handle, max30105_bool_t enable)
enable or disable the fifo roll
max30105_bool_t
max30105 bool enumeration definition
uint8_t max30105_set_led_proximity_pulse_amplitude(max30105_handle_t *handle, uint8_t amp)
set the proximity led pulse amplitude
uint8_t max30105_set_interrupt(max30105_handle_t *handle, max30105_interrupt_t type, max30105_bool_t enable)
set the interrupt bool
uint8_t max30105_set_led_green_pulse_amplitude(max30105_handle_t *handle, uint8_t amp)
set the green led pulse amplitude
uint8_t max30105_set_adc_resolution(max30105_handle_t *handle, max30105_adc_resolution_t resolution)
set the adc resolution
uint8_t max30105_set_particle_sensing_adc_range(max30105_handle_t *handle, max30105_particle_sensing_adc_range_t range)
set the particle sensing adc range
uint8_t max30105_set_proximity_interrupt_threshold(max30105_handle_t *handle, uint8_t threshold)
set the proximity interrupt threshold
uint8_t max30105_set_particle_sensing_sample_rate(max30105_handle_t *handle, max30105_particle_sensing_sample_rate_t rate)
set the particle sensing sample rate
uint8_t max30105_get_interrupt_status(max30105_handle_t *handle, max30105_interrupt_status_t status, max30105_bool_t *enable)
get the interrupt status
uint8_t max30105_deinit(max30105_handle_t *handle)
close the chip
uint8_t max30105_set_led_ir_pulse_amplitude(max30105_handle_t *handle, uint8_t amp)
set the ir led pulse amplitude
uint8_t max30105_set_die_temperature(max30105_handle_t *handle, max30105_bool_t enable)
enable or disable die temperature
uint8_t max30105_set_slot(max30105_handle_t *handle, max30105_slot_t slot, max30105_led_t led)
set the led slot
@ MAX30105_INTERRUPT_FIFO_FULL_EN
@ MAX30105_INTERRUPT_DIE_TEMP_RDY_EN
@ MAX30105_INTERRUPT_ALC_OVF_EN
@ MAX30105_INTERRUPT_DATA_RDY_EN
@ MAX30105_INTERRUPT_PROX_INT_EN
@ MAX30105_INTERRUPT_STATUS_FIFO_FULL
@ MAX30105_BOOL_TRUE
@ MAX30105_BOOL_FALSE
@ MAX30105_SLOT_2
@ MAX30105_SLOT_4
@ MAX30105_SLOT_1
@ MAX30105_SLOT_3
#define MAX30105_FIFO_DEFAULT_LED_GREEN_PULSE_AMPLITUDE
#define MAX30105_FIFO_DEFAULT_PROXIMITY_THRESHOLD
#define MAX30105_FIFO_DEFAULT_FIFO_ALMOST_FULL
#define MAX30105_FIFO_DEFAULT_SLOT4
#define MAX30105_FIFO_DEFAULT_FIFO_ROLL
#define MAX30105_FIFO_DEFAULT_INTERRUPT_DATA_RDY_EN
#define MAX30105_FIFO_DEFAULT_ADC_RESOLUTION
#define MAX30105_FIFO_DEFAULT_SLOT3
#define MAX30105_FIFO_DEFAULT_LED_IR_PULSE_AMPLITUDE
#define MAX30105_FIFO_DEFAULT_PARTICLE_SENSING_ADC_RANGE
#define MAX30105_FIFO_DEFAULT_LED_RED_PULSE_AMPLITUDE
uint8_t max30105_fifo_deinit(void)
fifo example deinit
#define MAX30105_FIFO_DEFAULT_LED_PROXIMITY_PULSE_AMPLITUDE
#define MAX30105_FIFO_DEFAULT_MODE
#define MAX30105_FIFO_DEFAULT_SLOT1
#define MAX30105_FIFO_DEFAULT_DIE_TEMPERATURE
#define MAX30105_FIFO_DEFAULT_SLOT2
uint8_t max30105_fifo_init(void(*fifo_receive_callback)(uint8_t type))
fifo example init
#define MAX30105_FIFO_DEFAULT_INTERRUPT_ALC_OVF_EN
#define MAX30105_FIFO_DEFAULT_INTERRUPT_DIE_TEMP_RDY_EN
uint8_t max30105_fifo_irq_handler(void)
fifo example irq handler
#define MAX30105_FIFO_DEFAULT_PARTICLE_SENSING_SAMPLE_RATE
#define MAX30105_FIFO_DEFAULT_SAMPLE_AVERAGING
max30105 fifo example default definition
uint8_t max30105_fifo_read(uint32_t *raw_red, uint32_t *raw_ir, uint32_t *raw_green, uint8_t *len)
read the data
void max30105_interface_delay_ms(uint32_t ms)
interface delay ms
void max30105_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t max30105_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t max30105_interface_iic_deinit(void)
interface iic bus deinit
uint8_t max30105_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t max30105_interface_iic_init(void)
interface iic bus init