LibDriver MAX30105
Loading...
Searching...
No Matches
driver_max30105_fifo_test.c
Go to the documentation of this file.
1
36
38
39static max30105_handle_t gs_handle;
40static volatile uint8_t gs_flag;
41static uint32_t gs_raw_red[32];
42static uint32_t gs_raw_ir[32];
43static uint32_t gs_raw_green[32];
44
53{
54 /* run irq handler */
55 if (max30105_irq_handler(&gs_handle) != 0)
56 {
57 return 1;
58 }
59 else
60 {
61 return 0;
62 }
63}
64
70static void a_max30105_interface_test_receive_callback(uint8_t type)
71{
72 switch (type)
73 {
75 {
76 uint8_t res;
77 uint8_t len;
78
79 /* read data */
80 len = 32;
81 res = max30105_read(&gs_handle, (uint32_t *)gs_raw_red, (uint32_t *)gs_raw_ir, (uint32_t *)gs_raw_green, (uint8_t *)&len);
82 if (res != 0)
83 {
84 max30105_interface_debug_print("max30105: read failed.\n");
85 }
86 max30105_interface_debug_print("max30105: irq fifo full with %d.\n", len);
87 gs_flag = 1;
88
89 break;
90 }
92 {
93 max30105_interface_debug_print("max30105: irq data rdy.\n");
94
95 break;
96 }
98 {
99 max30105_interface_debug_print("max30105: irq alc ovf.\n");
100
101 break;
102 }
104 {
105 max30105_interface_debug_print("max30105: irq proximity threshold.\n");
106
107 break;
108 }
110 {
111 max30105_interface_debug_print("max30105: irq pwr rdy.\n");
112
113 break;
114 }
116 {
117 max30105_interface_debug_print("max30105: irq die temp rdy.\n");
118
119 break;
120 }
121 default :
122 {
123 max30105_interface_debug_print("max30105: unknown code.\n");
124
125 break;
126 }
127 }
128}
129
138uint8_t max30105_fifo_test(uint32_t times)
139{
140 uint8_t res;
141 uint32_t timeout;
142 uint16_t raw;
143 uint8_t threshold;
144 float temp;
145 max30105_bool_t enable;
146 max30105_info_t info;
147
148 /* link interface function */
156 DRIVER_MAX30105_LINK_RECEIVE_CALLBACK(&gs_handle, a_max30105_interface_test_receive_callback);
157
158 /* get information */
159 res = max30105_info(&info);
160 if (res != 0)
161 {
162 max30105_interface_debug_print("max30105: get info failed.\n");
163
164 return 1;
165 }
166 else
167 {
168 /* print chip info */
169 max30105_interface_debug_print("max30105: chip is %s.\n", info.chip_name);
170 max30105_interface_debug_print("max30105: manufacturer is %s.\n", info.manufacturer_name);
171 max30105_interface_debug_print("max30105: interface is %s.\n", info.interface);
172 max30105_interface_debug_print("max30105: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
173 max30105_interface_debug_print("max30105: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
174 max30105_interface_debug_print("max30105: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
175 max30105_interface_debug_print("max30105: max current is %0.2fmA.\n", info.max_current_ma);
176 max30105_interface_debug_print("max30105: max temperature is %0.1fC.\n", info.temperature_max);
177 max30105_interface_debug_print("max30105: min temperature is %0.1fC.\n", info.temperature_min);
178 }
179
180 /* start read test */
181 max30105_interface_debug_print("max30105: start fifo test.\n");
182
183 /* init the max30105 */
184 res = max30105_init(&gs_handle);
185 if (res != 0)
186 {
187 max30105_interface_debug_print("max30105: init failed.\n");
188
189 return 1;
190 }
191
192 /* enable shutdown */
193 res = max30105_set_shutdown(&gs_handle, MAX30105_BOOL_TRUE);
194 if (res != 0)
195 {
196 max30105_interface_debug_print("max30105: set shutdown failed.\n");
197 (void)max30105_deinit(&gs_handle);
198
199 return 1;
200 }
201
202 /* set fifo sample averaging */
204 if (res != 0)
205 {
206 max30105_interface_debug_print("max30105: set fifo sample averaging failed.\n");
207 (void)max30105_deinit(&gs_handle);
208
209 return 1;
210 }
211
212 /* set fifo roll */
214 if (res != 0)
215 {
216 max30105_interface_debug_print("max30105: set fifo roll failed.\n");
217 (void)max30105_deinit(&gs_handle);
218
219 return 1;
220 }
221
222 /* set fifo almost full */
223 res = max30105_set_fifo_almost_full(&gs_handle, 0xF);
224 if (res != 0)
225 {
226 max30105_interface_debug_print("max30105: set fifo almost full failed.\n");
227 (void)max30105_deinit(&gs_handle);
228
229 return 1;
230 }
231
232 /* set mode */
234 if (res != 0)
235 {
236 max30105_interface_debug_print("max30105: set mode failed.\n");
237 (void)max30105_deinit(&gs_handle);
238
239 return 1;
240 }
241
242 /* set particle sensing adc range */
244 if (res != 0)
245 {
246 max30105_interface_debug_print("max30105: set particle sensing adc range failed.\n");
247 (void)max30105_deinit(&gs_handle);
248
249 return 1;
250 }
251
252 /* set particle sensing sample rate */
254 if (res != 0)
255 {
256 max30105_interface_debug_print("max30105: set particle sensing sample rate failed.\n");
257 (void)max30105_deinit(&gs_handle);
258
259 return 1;
260 }
261
262 /* set adc resolution */
264 if (res != 0)
265 {
266 max30105_interface_debug_print("max30105: set adc resolution failed.\n");
267 (void)max30105_deinit(&gs_handle);
268
269 return 1;
270 }
271
272 /* set led red pulse amplitude */
273 res = max30105_set_led_red_pulse_amplitude(&gs_handle, 0x7F);
274 if (res != 0)
275 {
276 max30105_interface_debug_print("max30105: set led red pulse amplitude failed.\n");
277 (void)max30105_deinit(&gs_handle);
278
279 return 1;
280 }
281
282 /* set led ir pulse amplitude */
283 res = max30105_set_led_ir_pulse_amplitude(&gs_handle, 0x7F);
284 if (res != 0)
285 {
286 max30105_interface_debug_print("max30105: set led ir pulse amplitude failed.\n");
287 (void)max30105_deinit(&gs_handle);
288
289 return 1;
290 }
291
292 /* set led green pulse amplitude */
293 res = max30105_set_led_green_pulse_amplitude(&gs_handle, 0x7F);
294 if (res != 0)
295 {
296 max30105_interface_debug_print("max30105: set led green pulse amplitude failed.\n");
297 (void)max30105_deinit(&gs_handle);
298
299 return 1;
300 }
301
302 /* set led proximity pulse amplitude */
303 res = max30105_set_led_proximity_pulse_amplitude(&gs_handle, 0x7F);
304 if (res != 0)
305 {
306 max30105_interface_debug_print("max30105: set led proximity pulse amplitude failed.\n");
307 (void)max30105_deinit(&gs_handle);
308
309 return 1;
310 }
311
312 /* convert the adc */
313 res = max30105_proximity_threshold_convert_to_register(&gs_handle, 1023, (uint8_t *)&threshold);
314 if (res != 0)
315 {
316 max30105_interface_debug_print("max30105: proximity threshold convert to register failed.\n");
317 (void)max30105_deinit(&gs_handle);
318
319 return 1;
320 }
321
322 /* set proximity interrupt threshold */
323 res = max30105_set_proximity_interrupt_threshold(&gs_handle, threshold);
324 if (res != 0)
325 {
326 max30105_interface_debug_print("max30105: set proximity interrupt threshold failed.\n");
327 (void)max30105_deinit(&gs_handle);
328
329 return 1;
330 }
331
332 /* set slot */
334 if (res != 0)
335 {
336 max30105_interface_debug_print("max30105: set slot failed.\n");
337 (void)max30105_deinit(&gs_handle);
338
339 return 1;
340 }
341
342 /* set slot */
344 if (res != 0)
345 {
346 max30105_interface_debug_print("max30105: set slot failed.\n");
347 (void)max30105_deinit(&gs_handle);
348
349 return 1;
350 }
351
352 /* set slot */
354 if (res != 0)
355 {
356 max30105_interface_debug_print("max30105: set slot failed.\n");
357 (void)max30105_deinit(&gs_handle);
358
359 return 1;
360 }
361
362 /* set slot */
364 if (res != 0)
365 {
366 max30105_interface_debug_print("max30105: set slot failed.\n");
367 (void)max30105_deinit(&gs_handle);
368
369 return 1;
370 }
371
372 /* disable die temperature */
374 if (res != 0)
375 {
376 max30105_interface_debug_print("max30105: set die temperature failed.\n");
377 (void)max30105_deinit(&gs_handle);
378
379 return 1;
380 }
381
382 /* set interrupt */
384 if (res != 0)
385 {
386 max30105_interface_debug_print("max30105: set interrupt failed.\n");
387 (void)max30105_deinit(&gs_handle);
388
389 return 1;
390 }
391
392 /* set interrupt */
394 if (res != 0)
395 {
396 max30105_interface_debug_print("max30105: set interrupt failed.\n");
397 (void)max30105_deinit(&gs_handle);
398
399 return 1;
400 }
401
402 /* set interrupt */
404 if (res != 0)
405 {
406 max30105_interface_debug_print("max30105: set interrupt failed.\n");
407 (void)max30105_deinit(&gs_handle);
408
409 return 1;
410 }
411
412 /* set interrupt */
414 if (res != 0)
415 {
416 max30105_interface_debug_print("max30105: set interrupt failed.\n");
417 (void)max30105_deinit(&gs_handle);
418
419 return 1;
420 }
421
422 /* set interrupt */
424 if (res != 0)
425 {
426 max30105_interface_debug_print("max30105: set interrupt failed.\n");
427 (void)max30105_deinit(&gs_handle);
428
429 return 1;
430 }
431
432 /* disable shutdown */
434 if (res != 0)
435 {
436 max30105_interface_debug_print("max30105: set shutdown failed.\n");
437 (void)max30105_deinit(&gs_handle);
438
439 return 1;
440 }
441
442 /* get status */
444 if (res != 0)
445 {
446 max30105_interface_debug_print("max30105: get interrupt status failed.\n");
447 (void)max30105_deinit(&gs_handle);
448
449 return 1;
450 }
451
452 /* get status */
454 if (res != 0)
455 {
456 max30105_interface_debug_print("max30105: get interrupt status failed.\n");
457 (void)max30105_deinit(&gs_handle);
458
459 return 1;
460 }
461
462 /* read temperature */
463 res = max30105_read_temperature(&gs_handle, (uint16_t *)&raw, (float *)&temp);
464 if (res != 0)
465 {
466 max30105_interface_debug_print("max30105: read temperature failed.\n");
467 (void)max30105_deinit(&gs_handle);
468
469 return 1;
470 }
471 max30105_interface_debug_print("max30105: temperature is %0.4fC.\n", temp);
472
473 /* read data */
474 gs_flag = 0;
475 timeout = 5000;
476 while (timeout != 0)
477 {
478 if (gs_flag != 0)
479 {
480 /* clear config */
481 gs_flag = 0;
482 timeout = 5000;
483 times--;
484 if (times == 0)
485 {
486 break;
487 }
488 }
490 timeout--;
491 }
492
493 /* check timeout */
494 if (timeout == 0)
495 {
496 max30105_interface_debug_print("max30105: read timeout failed.\n");
497 (void)max30105_deinit(&gs_handle);
498
499 return 1;
500 }
501
502 /* finish read test */
503 max30105_interface_debug_print("max30105: finish fifo test.\n");
504 (void)max30105_deinit(&gs_handle);
505
506 return 0;
507}
driver max30105 fifo test 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_info(max30105_info_t *info)
get chip's information
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
struct max30105_info_s max30105_info_t
max30105 information structure definition
uint8_t max30105_read_temperature(max30105_handle_t *handle, uint16_t *raw, float *temp)
read the temperature
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_ALC_OVF
@ MAX30105_INTERRUPT_STATUS_DIE_TEMP_RDY
@ MAX30105_INTERRUPT_STATUS_FIFO_FULL
@ MAX30105_INTERRUPT_STATUS_DATA_RDY
@ MAX30105_INTERRUPT_STATUS_PWR_RDY
@ MAX30105_INTERRUPT_STATUS_PROX_INT
@ MAX30105_PARTICLE_SENSING_SAMPLE_RATE_100_HZ
@ MAX30105_BOOL_TRUE
@ MAX30105_BOOL_FALSE
@ MAX30105_SAMPLE_AVERAGING_8
@ MAX30105_ADC_RESOLUTION_18_BIT
@ MAX30105_MODE_GREEN_RED_IR
@ MAX30105_SLOT_2
@ MAX30105_SLOT_4
@ MAX30105_SLOT_1
@ MAX30105_SLOT_3
@ MAX30105_PARTICLE_SENSING_ADC_RANGE_4096
@ MAX30105_LED_IR_LED2_PA
@ MAX30105_LED_RED_LED1_PA
@ MAX30105_LED_NONE
@ MAX30105_LED_GREEN_LED3_PA
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
uint8_t max30105_fifo_test_irq_handler(void)
fifo test irq handler
uint8_t max30105_fifo_test(uint32_t times)
fifo test
char manufacturer_name[32]