LibDriver MAX30102
Loading...
Searching...
No Matches
driver_max30102_fifo_test.c
Go to the documentation of this file.
1
36
38
39static max30102_handle_t gs_handle;
40static volatile uint8_t gs_flag;
41static uint32_t gs_raw_red[32];
42static uint32_t gs_raw_ir[32];
43
52{
53 /* run irq handler */
54 if (max30102_irq_handler(&gs_handle) != 0)
55 {
56 return 1;
57 }
58 else
59 {
60 return 0;
61 }
62}
63
69static void a_max30102_interface_test_receive_callback(uint8_t type)
70{
71 switch (type)
72 {
74 {
75 uint8_t res;
76 uint8_t len;
77
78 /* read data */
79 len = 32;
80 res = max30102_read(&gs_handle, (uint32_t *)gs_raw_red, (uint32_t *)gs_raw_ir, (uint8_t *)&len);
81 if (res != 0)
82 {
83 max30102_interface_debug_print("max30102: read failed.\n");
84 }
85 max30102_interface_debug_print("max30102: irq fifo full with %d.\n", len);
86 gs_flag = 1;
87
88 break;
89 }
91 {
92 max30102_interface_debug_print("max30102: irq ppg rdy.\n");
93
94 break;
95 }
97 {
98 max30102_interface_debug_print("max30102: irq alc ovf.\n");
99
100 break;
101 }
103 {
104 max30102_interface_debug_print("max30102: irq pwr rdy.\n");
105
106 break;
107 }
109 {
110 max30102_interface_debug_print("max30102: irq die temp rdy.\n");
111
112 break;
113 }
114 default :
115 {
116 max30102_interface_debug_print("max30102: unknown code.\n");
117
118 break;
119 }
120 }
121}
122
131uint8_t max30102_fifo_test(uint32_t times)
132{
133 uint8_t res;
134 uint32_t timeout;
135 uint16_t raw;
136 float temp;
137 max30102_bool_t enable;
138 max30102_info_t info;
139
140 /* link interface function */
148 DRIVER_MAX30102_LINK_RECEIVE_CALLBACK(&gs_handle, a_max30102_interface_test_receive_callback);
149
150 /* get information */
151 res = max30102_info(&info);
152 if (res != 0)
153 {
154 max30102_interface_debug_print("max30102: get info failed.\n");
155
156 return 1;
157 }
158 else
159 {
160 /* print chip info */
161 max30102_interface_debug_print("max30102: chip is %s.\n", info.chip_name);
162 max30102_interface_debug_print("max30102: manufacturer is %s.\n", info.manufacturer_name);
163 max30102_interface_debug_print("max30102: interface is %s.\n", info.interface);
164 max30102_interface_debug_print("max30102: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
165 max30102_interface_debug_print("max30102: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
166 max30102_interface_debug_print("max30102: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
167 max30102_interface_debug_print("max30102: max current is %0.2fmA.\n", info.max_current_ma);
168 max30102_interface_debug_print("max30102: max temperature is %0.1fC.\n", info.temperature_max);
169 max30102_interface_debug_print("max30102: min temperature is %0.1fC.\n", info.temperature_min);
170 }
171
172 /* start read test */
173 max30102_interface_debug_print("max30102: start fifo test.\n");
174
175 /* init the max30102 */
176 res = max30102_init(&gs_handle);
177 if (res != 0)
178 {
179 max30102_interface_debug_print("max30102: init failed.\n");
180
181 return 1;
182 }
183
184 /* enable shutdown */
185 res = max30102_set_shutdown(&gs_handle, MAX30102_BOOL_TRUE);
186 if (res != 0)
187 {
188 max30102_interface_debug_print("max30102: set shutdown failed.\n");
189 (void)max30102_deinit(&gs_handle);
190
191 return 1;
192 }
193
194 /* set fifo sample averaging */
196 if (res != 0)
197 {
198 max30102_interface_debug_print("max30102: set fifo sample averaging failed.\n");
199 (void)max30102_deinit(&gs_handle);
200
201 return 1;
202 }
203
204 /* set fifo roll */
206 if (res != 0)
207 {
208 max30102_interface_debug_print("max30102: set fifo roll failed.\n");
209 (void)max30102_deinit(&gs_handle);
210
211 return 1;
212 }
213
214 /* set fifo almost full */
215 res = max30102_set_fifo_almost_full(&gs_handle, 0xF);
216 if (res != 0)
217 {
218 max30102_interface_debug_print("max30102: set fifo almost full failed.\n");
219 (void)max30102_deinit(&gs_handle);
220
221 return 1;
222 }
223
224 /* set mode */
225 res = max30102_set_mode(&gs_handle, MAX30102_MODE_SPO2);
226 if (res != 0)
227 {
228 max30102_interface_debug_print("max30102: set mode failed.\n");
229 (void)max30102_deinit(&gs_handle);
230
231 return 1;
232 }
233
234 /* set spo2 adc range */
236 if (res != 0)
237 {
238 max30102_interface_debug_print("max30102: set spo2 adc range failed.\n");
239 (void)max30102_deinit(&gs_handle);
240
241 return 1;
242 }
243
244 /* set spo2 sample rate */
246 if (res != 0)
247 {
248 max30102_interface_debug_print("max30102: set spo2 sample rate failed.\n");
249 (void)max30102_deinit(&gs_handle);
250
251 return 1;
252 }
253
254 /* set adc resolution */
256 if (res != 0)
257 {
258 max30102_interface_debug_print("max30102: set adc resolution failed.\n");
259 (void)max30102_deinit(&gs_handle);
260
261 return 1;
262 }
263
264 /* set led red pulse amplitude */
265 res = max30102_set_led_red_pulse_amplitude(&gs_handle, 0x7F);
266 if (res != 0)
267 {
268 max30102_interface_debug_print("max30102: set led red pulse amplitude failed.\n");
269 (void)max30102_deinit(&gs_handle);
270
271 return 1;
272 }
273
274 /* set led ir pulse amplitude */
275 res = max30102_set_led_ir_pulse_amplitude(&gs_handle, 0x7F);
276 if (res != 0)
277 {
278 max30102_interface_debug_print("max30102: set led ir pulse amplitude failed.\n");
279 (void)max30102_deinit(&gs_handle);
280
281 return 1;
282 }
283
284 /* set slot */
286 if (res != 0)
287 {
288 max30102_interface_debug_print("max30102: set slot failed.\n");
289 (void)max30102_deinit(&gs_handle);
290
291 return 1;
292 }
293
294 /* set slot */
296 if (res != 0)
297 {
298 max30102_interface_debug_print("max30102: set slot failed.\n");
299 (void)max30102_deinit(&gs_handle);
300
301 return 1;
302 }
303
304 /* set slot */
306 if (res != 0)
307 {
308 max30102_interface_debug_print("max30102: set slot failed.\n");
309 (void)max30102_deinit(&gs_handle);
310
311 return 1;
312 }
313
314 /* set slot */
316 if (res != 0)
317 {
318 max30102_interface_debug_print("max30102: set slot failed.\n");
319 (void)max30102_deinit(&gs_handle);
320
321 return 1;
322 }
323
324 /* disable die temperature */
326 if (res != 0)
327 {
328 max30102_interface_debug_print("max30102: set die temperature failed.\n");
329 (void)max30102_deinit(&gs_handle);
330
331 return 1;
332 }
333
334 /* set interrupt */
336 if (res != 0)
337 {
338 max30102_interface_debug_print("max30102: set interrupt failed.\n");
339 (void)max30102_deinit(&gs_handle);
340
341 return 1;
342 }
343
344 /* set interrupt */
346 if (res != 0)
347 {
348 max30102_interface_debug_print("max30102: set interrupt failed.\n");
349 (void)max30102_deinit(&gs_handle);
350
351 return 1;
352 }
353
354 /* set interrupt */
356 if (res != 0)
357 {
358 max30102_interface_debug_print("max30102: set interrupt failed.\n");
359 (void)max30102_deinit(&gs_handle);
360
361 return 1;
362 }
363
364 /* set interrupt */
366 if (res != 0)
367 {
368 max30102_interface_debug_print("max30102: set interrupt failed.\n");
369 (void)max30102_deinit(&gs_handle);
370
371 return 1;
372 }
373
374 /* disable shutdown */
376 if (res != 0)
377 {
378 max30102_interface_debug_print("max30102: set shutdown failed.\n");
379 (void)max30102_deinit(&gs_handle);
380
381 return 1;
382 }
383
384 /* get status */
386 if (res != 0)
387 {
388 max30102_interface_debug_print("max30102: get interrupt status failed.\n");
389 (void)max30102_deinit(&gs_handle);
390
391 return 1;
392 }
393
394 /* get status */
396 if (res != 0)
397 {
398 max30102_interface_debug_print("max30102: get interrupt status failed.\n");
399 (void)max30102_deinit(&gs_handle);
400
401 return 1;
402 }
403
404 /* read temperature */
405 res = max30102_read_temperature(&gs_handle, (uint16_t *)&raw, (float *)&temp);
406 if (res)
407 {
408 max30102_interface_debug_print("max30102: read temperature failed.\n");
409 max30102_deinit(&gs_handle);
410
411 return 1;
412 }
413 max30102_interface_debug_print("max30102: temperature is %0.4fC.\n", temp);
414
415 /* read data */
416 gs_flag = 0;
417 timeout = 5000;
418 while (timeout != 0)
419 {
420 if (gs_flag != 0)
421 {
422 /* clear config */
423 gs_flag = 0;
424 timeout = 5000;
425 times--;
426 if (times == 0)
427 {
428 break;
429 }
430 }
432 timeout--;
433 }
434
435 /* check timeout */
436 if (timeout == 0)
437 {
438 max30102_interface_debug_print("max30102: read timeout failed.\n");
439 (void)max30102_deinit(&gs_handle);
440
441 return 1;
442 }
443
444 /* finish read test */
445 max30102_interface_debug_print("max30102: finish fifo test.\n");
446 (void)max30102_deinit(&gs_handle);
447
448 return 0;
449}
driver max30102 fifo test header file
uint8_t max30102_set_slot(max30102_handle_t *handle, max30102_slot_t slot, max30102_led_t led)
set the led slot
uint8_t max30102_set_die_temperature(max30102_handle_t *handle, max30102_bool_t enable)
enable or disable die temperature
max30102_bool_t
max30102 bool enumeration definition
uint8_t max30102_set_fifo_roll(max30102_handle_t *handle, max30102_bool_t enable)
enable or disable the fifo roll
uint8_t max30102_get_interrupt_status(max30102_handle_t *handle, max30102_interrupt_status_t status, max30102_bool_t *enable)
get the interrupt status
uint8_t max30102_set_fifo_almost_full(max30102_handle_t *handle, uint8_t value)
set the fifo almost full value
uint8_t max30102_info(max30102_info_t *info)
get chip's information
uint8_t max30102_set_fifo_sample_averaging(max30102_handle_t *handle, max30102_sample_averaging_t sample)
set the fifo sample averaging
uint8_t max30102_read_temperature(max30102_handle_t *handle, uint16_t *raw, float *temp)
read the temperature
uint8_t max30102_set_led_red_pulse_amplitude(max30102_handle_t *handle, uint8_t amp)
set the red led pulse amplitude
uint8_t max30102_set_mode(max30102_handle_t *handle, max30102_mode_t mode)
set the mode
uint8_t max30102_set_shutdown(max30102_handle_t *handle, max30102_bool_t enable)
set the shutdown
uint8_t max30102_read(max30102_handle_t *handle, uint32_t *raw_red, uint32_t *raw_ir, uint8_t *len)
read the data
uint8_t max30102_deinit(max30102_handle_t *handle)
close the chip
uint8_t max30102_set_spo2_adc_range(max30102_handle_t *handle, max30102_spo2_adc_range_t range)
set the spo2 adc range
uint8_t max30102_set_spo2_sample_rate(max30102_handle_t *handle, max30102_spo2_sample_rate_t rate)
set the spo2 sample rate
uint8_t max30102_set_interrupt(max30102_handle_t *handle, max30102_interrupt_t type, max30102_bool_t enable)
set the interrupt bool
uint8_t max30102_set_led_ir_pulse_amplitude(max30102_handle_t *handle, uint8_t amp)
set the ir led pulse amplitude
struct max30102_info_s max30102_info_t
max30102 information structure definition
uint8_t max30102_init(max30102_handle_t *handle)
initialize the chip
struct max30102_handle_s max30102_handle_t
max30102 handle structure definition
uint8_t max30102_irq_handler(max30102_handle_t *handle)
irq handler
uint8_t max30102_set_adc_resolution(max30102_handle_t *handle, max30102_adc_resolution_t resolution)
set the adc resolution
@ MAX30102_SLOT_1
@ MAX30102_SLOT_4
@ MAX30102_SLOT_2
@ MAX30102_SLOT_3
@ MAX30102_BOOL_FALSE
@ MAX30102_BOOL_TRUE
@ MAX30102_SPO2_ADC_RANGE_4096
@ MAX30102_INTERRUPT_DIE_TEMP_RDY_EN
@ MAX30102_INTERRUPT_PPG_RDY_EN
@ MAX30102_INTERRUPT_FIFO_FULL_EN
@ MAX30102_INTERRUPT_ALC_OVF_EN
@ MAX30102_SPO2_SAMPLE_RATE_100_HZ
@ MAX30102_SAMPLE_AVERAGING_8
@ MAX30102_INTERRUPT_STATUS_FIFO_FULL
@ MAX30102_INTERRUPT_STATUS_ALC_OVF
@ MAX30102_INTERRUPT_STATUS_DIE_TEMP_RDY
@ MAX30102_INTERRUPT_STATUS_PPG_RDY
@ MAX30102_INTERRUPT_STATUS_PWR_RDY
@ MAX30102_LED_RED
@ MAX30102_LED_NONE
@ MAX30102_LED_IR
@ MAX30102_ADC_RESOLUTION_18_BIT
@ MAX30102_MODE_SPO2
uint8_t max30102_interface_iic_init(void)
interface iic bus init
void max30102_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t max30102_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t max30102_interface_iic_deinit(void)
interface iic bus deinit
void max30102_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t max30102_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t max30102_fifo_test(uint32_t times)
fifo test
uint8_t max30102_fifo_test_irq_handler(void)
fifo test irq handler
char manufacturer_name[32]