ruuvi.drivers.c ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
Loading...
Searching...
No Matches
ruuvi_interface_dps310.c
Go to the documentation of this file.
2
3
4#if (RI_DPS310_ENABLED || DOXYGEN)
6#include "dps310.h"
11#include <stdint.h>
12#include <string.h>
13
14static void dps_sleep (const uint32_t ms)
15{
16 (void) ri_delay_ms (ms);
17}
18
19// Singleton access for compatibility with other driver implementations.
20static uint8_t spi_comm_handle;
21static dps310_ctx_t singleton_ctx_spi =
22{
23 .write = &ri_spi_dps310_write,
24 .read = &ri_spi_dps310_read,
25 .sleep = &dps_sleep,
26 .comm_ctx = &spi_comm_handle
27};
28
29static const char * const name = "DPS310";
31{
33 .datas.pressure_pa = 1
34};
35static float last_values[2];
36static rd_sensor_data_t last_data;
37
38static __attribute__ ( (nonnull)) void
39dps310_singleton_spi_setup (rd_sensor_t * const p_sensor,
40 const uint8_t handle)
41{
42 p_sensor->p_ctx = &singleton_ctx_spi;
43 spi_comm_handle = handle;
44}
45
46static __attribute__ ( (nonnull))
47void dps310_fp_setup (rd_sensor_t * const p_sensor)
48{
49 p_sensor->init = &ri_dps310_init;
50 p_sensor->uninit = &ri_dps310_uninit;
55 p_sensor->scale_set = &ri_dps310_scale_set;
56 p_sensor->scale_get = &ri_dps310_scale_get;
57 p_sensor->dsp_set = &ri_dps310_dsp_set;
58 p_sensor->dsp_get = &ri_dps310_dsp_get;
59 p_sensor->mode_set = &ri_dps310_mode_set;
60 p_sensor->mode_get = &ri_dps310_mode_get;
61 p_sensor->data_get = &ri_dps310_data_get;
64 return;
65}
66
67rd_status_t ri_dps310_init (rd_sensor_t * p_sensor, rd_bus_t bus, uint8_t handle)
68{
69 rd_status_t err_code = RD_SUCCESS;
70 dps310_status_t dps_status = DPS310_SUCCESS;
71
72 if (NULL == p_sensor)
73 {
74 err_code |= RD_ERROR_NULL;
75 }
76 else if (rd_sensor_is_init (p_sensor))
77 {
78 err_code |= RD_ERROR_INVALID_STATE;
79 }
80 else
81 {
82 rd_sensor_initialize (p_sensor);
83 p_sensor->name = name;
84
85 if (NULL == p_sensor->p_ctx)
86 {
87 if (RD_BUS_SPI == bus)
88 {
89 dps310_singleton_spi_setup (p_sensor, handle);
90 }
91 else if (RD_BUS_I2C == bus)
92 {
93 err_code |= RD_ERROR_NOT_IMPLEMENTED;
94 }
95 else
96 {
97 err_code |= RD_ERROR_NOT_SUPPORTED;
98 }
99 }
100
101 if (RD_SUCCESS == err_code)
102 {
103 dps_status = dps310_init (p_sensor->p_ctx);
104
105 if (DPS310_SUCCESS == dps_status)
106 {
107 dps310_fp_setup (p_sensor);
108 p_sensor->name = name;
109 p_sensor->provides = dps_fields;
110 memset (&last_data, 0, sizeof (last_data));
111 }
112 else
113 {
114 err_code |= RD_ERROR_NOT_FOUND;
115 }
116 }
117 }
118
119 return err_code;
120}
121
122rd_status_t ri_dps310_uninit (rd_sensor_t * sensor, rd_bus_t bus, uint8_t handle)
123{
124 rd_status_t err_code = RD_SUCCESS;
125
126 if (NULL == sensor)
127 {
128 err_code |= RD_ERROR_NULL;
129 }
130 else
131 {
132 // Error code can be ignored.
133 (void) dps310_uninit (sensor->p_ctx);
134 rd_sensor_uninitialize (sensor);
135 }
136
137 return err_code;
138}
139
141{
142 rd_status_t err_code = RD_SUCCESS;
143 dps310_status_t dps_status = DPS310_SUCCESS;
144
145 if (NULL == samplerate)
146 {
147 err_code |= RD_ERROR_NULL;
148 }
149 else if (DPS310_READY != singleton_ctx_spi.device_status)
150 {
151 err_code |= RD_ERROR_INVALID_STATE;
152 }
153 else if (RD_SENSOR_CFG_NO_CHANGE == *samplerate)
154 {
155 // No action needed.
156 }
157 else if (RD_SENSOR_CFG_DEFAULT == *samplerate)
158 {
159 dps_status |= dps310_config_temp (&singleton_ctx_spi,
160 DPS310_DEFAULT_MR,
161 singleton_ctx_spi.temp_osr);
162 dps_status |= dps310_config_pres (&singleton_ctx_spi,
163 DPS310_DEFAULT_MR,
164 singleton_ctx_spi.pres_osr);
165 }
166 else if ( (RD_SENSOR_CFG_MIN == *samplerate) || (1U == *samplerate))
167 {
168 dps_status |= dps310_config_temp (&singleton_ctx_spi,
169 DPS310_MR_1,
170 singleton_ctx_spi.temp_osr);
171 dps_status |= dps310_config_pres (&singleton_ctx_spi,
172 DPS310_MR_1,
173 singleton_ctx_spi.pres_osr);
174 }
175 else if (RD_SENSOR_CFG_MAX == *samplerate)
176 {
177 dps_status |= dps310_config_temp (&singleton_ctx_spi,
178 DPS310_MR_128,
179 singleton_ctx_spi.temp_osr);
180 dps_status |= dps310_config_pres (&singleton_ctx_spi,
181 DPS310_MR_128,
182 singleton_ctx_spi.pres_osr);
183 }
184 else if (2U == *samplerate)
185 {
186 dps_status |= dps310_config_temp (&singleton_ctx_spi,
187 DPS310_MR_2,
188 singleton_ctx_spi.temp_osr);
189 dps_status |= dps310_config_pres (&singleton_ctx_spi,
190 DPS310_MR_2,
191 singleton_ctx_spi.pres_osr);
192 }
193 else if (4U >= *samplerate)
194 {
195 dps_status |= dps310_config_temp (&singleton_ctx_spi,
196 DPS310_MR_4,
197 singleton_ctx_spi.temp_osr);
198 dps_status |= dps310_config_pres (&singleton_ctx_spi,
199 DPS310_MR_4,
200 singleton_ctx_spi.pres_osr);
201 }
202 else if (8U >= *samplerate)
203 {
204 dps_status |= dps310_config_temp (&singleton_ctx_spi,
205 DPS310_MR_8,
206 singleton_ctx_spi.temp_osr);
207 dps_status |= dps310_config_pres (&singleton_ctx_spi,
208 DPS310_MR_8,
209 singleton_ctx_spi.pres_osr);
210 }
211 else if (16U >= *samplerate)
212 {
213 dps_status |= dps310_config_temp (&singleton_ctx_spi,
214 DPS310_MR_16,
215 singleton_ctx_spi.temp_osr);
216 dps_status |= dps310_config_pres (&singleton_ctx_spi,
217 DPS310_MR_16,
218 singleton_ctx_spi.pres_osr);
219 }
220 else if (32U >= *samplerate)
221 {
222 dps_status |= dps310_config_temp (&singleton_ctx_spi,
223 DPS310_MR_32,
224 singleton_ctx_spi.temp_osr);
225 dps_status |= dps310_config_pres (&singleton_ctx_spi,
226 DPS310_MR_32,
227 singleton_ctx_spi.pres_osr);
228 }
229 else if (64U >= *samplerate)
230 {
231 dps_status |= dps310_config_temp (&singleton_ctx_spi,
232 DPS310_MR_64,
233 singleton_ctx_spi.temp_osr);
234 dps_status |= dps310_config_pres (&singleton_ctx_spi,
235 DPS310_MR_64,
236 singleton_ctx_spi.pres_osr);
237 }
238 else if (128U >= *samplerate)
239 {
240 dps_status |= dps310_config_temp (&singleton_ctx_spi,
241 DPS310_MR_128,
242 singleton_ctx_spi.temp_osr);
243 dps_status |= dps310_config_pres (&singleton_ctx_spi,
244 DPS310_MR_128,
245 singleton_ctx_spi.pres_osr);
246 }
247 else
248 {
249 err_code |= RD_ERROR_NOT_SUPPORTED;
250 }
251
252 if ( (DPS310_SUCCESS == dps_status) && (RD_SUCCESS == err_code))
253 {
254 err_code |= ri_dps310_samplerate_get (samplerate);
255 }
256 else if (RD_SUCCESS == err_code)
257 {
258 err_code |= RD_ERROR_INTERNAL;
259 }
260 else
261 {
262 // No action needed.
263 }
264
265 return err_code;
266}
267
268static uint8_t dps310_mr_to_samplerate (const dps310_mr_t mr)
269{
270 uint8_t rate;
271
272 switch (mr)
273 {
274 case DPS310_MR_1:
275 rate = 1U;
276 break;
277
278 case DPS310_MR_2:
279 rate = 2U;
280 break;
281
282 case DPS310_MR_4:
283 rate = 4U;
284 break;
285
286 case DPS310_MR_8:
287 rate = 8U;
288 break;
289
290 case DPS310_MR_16:
291 rate = 16U;
292 break;
293
294 case DPS310_MR_32:
295 rate = 32U;
296 break;
297
298 case DPS310_MR_64:
299 rate = 64U;
300 break;
301
302 case DPS310_MR_128:
303 rate = 128U;
304 break;
305
306 default:
307 rate = 0U;
308 break;
309 }
310
311 return rate;
312}
313
315{
316 rd_status_t err_code = RD_SUCCESS;
317 uint8_t rate = 0U;
318
319 if (NULL == samplerate)
320 {
321 err_code |= RD_ERROR_NULL;
322 }
323 else
324 {
325 // Separate rates for temperature and pressure aren't supported
326 // by interface, so can check only temperature rate.
327 rate = dps310_mr_to_samplerate (singleton_ctx_spi.temp_mr);
328
329 if (0U == rate)
330 {
331 err_code |= RD_ERROR_INTERNAL;
332 }
333 else
334 {
335 *samplerate = rate;
336 }
337 }
338
339 return err_code;
340}
341
343{
344 rd_status_t err_code = RD_SUCCESS;
345
346 if (NULL == resolution)
347 {
348 err_code |= RD_ERROR_NULL;
349 }
350 else if (DPS310_READY != singleton_ctx_spi.device_status)
351 {
352 err_code |= RD_ERROR_INVALID_STATE;
353 }
354 else if ( (RD_SENSOR_CFG_DEFAULT == *resolution)
355 || (RD_SENSOR_CFG_MIN == *resolution)
356 || (RD_SENSOR_CFG_MAX == *resolution)
357 || (RD_SENSOR_CFG_NO_CHANGE == *resolution))
358 {
359 // No action needed.
360 }
361 else
362 {
363 err_code |= RD_ERROR_NOT_SUPPORTED;
364 }
365
366 err_code |= ri_dps310_resolution_get (resolution);
367 return err_code;
368}
369
371{
372 rd_status_t err_code = RD_SUCCESS;
373
374 if (NULL == resolution)
375 {
376 err_code |= RD_ERROR_NULL;
377 }
378 else
379 {
380 *resolution = RD_SENSOR_CFG_DEFAULT;
381 }
382
383 return err_code;
384}
385
387{
388 rd_status_t err_code = RD_SUCCESS;
389
390 if (NULL == scale)
391 {
392 err_code |= RD_ERROR_NULL;
393 }
394 else if (DPS310_READY != singleton_ctx_spi.device_status)
395 {
396 err_code |= RD_ERROR_INVALID_STATE;
397 }
398 else if ( (RD_SENSOR_CFG_DEFAULT == *scale)
399 || (RD_SENSOR_CFG_MIN == *scale)
400 || (RD_SENSOR_CFG_MAX == *scale)
401 || (RD_SENSOR_CFG_NO_CHANGE == *scale))
402 {
403 // No action needed.
404 }
405 else
406 {
407 err_code |= RD_ERROR_NOT_SUPPORTED;
408 }
409
410 err_code |= ri_dps310_scale_get (scale);
411 return err_code;
412}
413
415{
416 rd_status_t err_code = RD_SUCCESS;
417
418 if (NULL == scale)
419 {
420 err_code |= RD_ERROR_NULL;
421 }
422 else
423 {
424 *scale = RD_SENSOR_CFG_DEFAULT;
425 }
426
427 return err_code;
428}
429
430rd_status_t ri_dps310_dsp_set (uint8_t * dsp, uint8_t * parameter)
431{
432 rd_status_t err_code = RD_SUCCESS;
433 dps310_status_t dps_status = DPS310_SUCCESS;
434
435 if ( (NULL == dsp) || (NULL == parameter))
436 {
437 err_code |= RD_ERROR_NULL;
438 }
439 else if (DPS310_READY != singleton_ctx_spi.device_status)
440 {
441 err_code |= RD_ERROR_INVALID_STATE;
442 }
443 else if ( (RD_SENSOR_DSP_LAST == *dsp)
444 || (RD_SENSOR_CFG_DEFAULT == *dsp))
445 {
446 dps_status |= dps310_config_temp (&singleton_ctx_spi,
447 singleton_ctx_spi.temp_mr,
448 DPS310_OS_1);
449 dps_status |= dps310_config_pres (&singleton_ctx_spi,
450 singleton_ctx_spi.pres_mr,
451 DPS310_OS_1);
452 }
453 else if (RD_SENSOR_DSP_OS == *dsp)
454 {
455 if (RD_SENSOR_CFG_NO_CHANGE == *parameter)
456 {
457 // No action needed.
458 }
459 else if (RD_SENSOR_CFG_DEFAULT == *parameter)
460 {
461 dps_status |= dps310_config_temp (&singleton_ctx_spi,
462 singleton_ctx_spi.temp_mr,
463 DPS310_DEFAULT_OS);
464 dps_status |= dps310_config_pres (&singleton_ctx_spi,
465 singleton_ctx_spi.pres_mr,
466 DPS310_DEFAULT_OS);
467 }
468 else if ( (RD_SENSOR_CFG_MIN == *parameter) || (1U == *parameter))
469 {
470 dps_status |= dps310_config_temp (&singleton_ctx_spi,
471 singleton_ctx_spi.temp_mr,
472 DPS310_OS_1);
473 dps_status |= dps310_config_pres (&singleton_ctx_spi,
474 singleton_ctx_spi.pres_mr,
475 DPS310_OS_1);
476 }
477 else if (RD_SENSOR_CFG_MAX == *parameter)
478 {
479 dps_status |= dps310_config_temp (&singleton_ctx_spi,
480 singleton_ctx_spi.temp_mr,
481 DPS310_OS_128);
482 dps_status |= dps310_config_pres (&singleton_ctx_spi,
483 singleton_ctx_spi.pres_mr,
484 DPS310_OS_128);
485 }
486 else if (2U == *parameter)
487 {
488 dps_status |= dps310_config_temp (&singleton_ctx_spi,
489 singleton_ctx_spi.temp_mr,
490 DPS310_OS_2);
491 dps_status |= dps310_config_pres (&singleton_ctx_spi,
492 singleton_ctx_spi.pres_mr,
493 DPS310_OS_2);
494 }
495 else if (4U >= *parameter)
496 {
497 dps_status |= dps310_config_temp (&singleton_ctx_spi,
498 singleton_ctx_spi.temp_mr,
499 DPS310_OS_4);
500 dps_status |= dps310_config_pres (&singleton_ctx_spi,
501 singleton_ctx_spi.pres_mr,
502 DPS310_OS_4);
503 }
504 else if (8U >= *parameter)
505 {
506 dps_status |= dps310_config_temp (&singleton_ctx_spi,
507 singleton_ctx_spi.temp_mr,
508 DPS310_OS_8);
509 dps_status |= dps310_config_pres (&singleton_ctx_spi,
510 singleton_ctx_spi.pres_mr,
511 DPS310_OS_8);
512 }
513 else if (16U >= *parameter)
514 {
515 dps_status |= dps310_config_temp (&singleton_ctx_spi,
516 singleton_ctx_spi.temp_mr,
517 DPS310_OS_16);
518 dps_status |= dps310_config_pres (&singleton_ctx_spi,
519 singleton_ctx_spi.pres_mr,
520 DPS310_OS_16);
521 }
522 else if (32U >= *parameter)
523 {
524 dps_status |= dps310_config_temp (&singleton_ctx_spi,
525 singleton_ctx_spi.temp_mr,
526 DPS310_OS_32);
527 dps_status |= dps310_config_pres (&singleton_ctx_spi,
528 singleton_ctx_spi.pres_mr,
529 DPS310_OS_32);
530 }
531 else if (64U >= *parameter)
532 {
533 dps_status |= dps310_config_temp (&singleton_ctx_spi,
534 singleton_ctx_spi.temp_mr,
535 DPS310_OS_64);
536 dps_status |= dps310_config_pres (&singleton_ctx_spi,
537 singleton_ctx_spi.pres_mr,
538 DPS310_OS_64);
539 }
540 else if (128U >= *parameter)
541 {
542 dps_status |= dps310_config_temp (&singleton_ctx_spi,
543 singleton_ctx_spi.temp_mr,
544 DPS310_OS_128);
545 dps_status |= dps310_config_pres (&singleton_ctx_spi,
546 singleton_ctx_spi.pres_mr,
547 DPS310_OS_128);
548 }
549 else
550 {
551 err_code |= RD_ERROR_NOT_SUPPORTED;
552 }
553 }
554
555 if (DPS310_SUCCESS == dps_status)
556 {
557 err_code |= ri_dps310_dsp_get (dsp, parameter);
558 }
559 else
560 {
561 err_code |= RD_ERROR_INTERNAL;
562 }
563
564 return err_code;
565}
566
567static uint8_t dps310_os_to_samplerate (const dps310_os_t os)
568{
569 uint8_t rate;
570
571 switch (os)
572 {
573 case DPS310_OS_1:
574 rate = 1U;
575 break;
576
577 case DPS310_OS_2:
578 rate = 2U;
579 break;
580
581 case DPS310_OS_4:
582 rate = 4U;
583 break;
584
585 case DPS310_OS_8:
586 rate = 8U;
587 break;
588
589 case DPS310_OS_16:
590 rate = 16U;
591 break;
592
593 case DPS310_OS_32:
594 rate = 32U;
595 break;
596
597 case DPS310_OS_64:
598 rate = 64U;
599 break;
600
601 case DPS310_OS_128:
602 rate = 128U;
603 break;
604
605 default:
606 rate = 0U;
607 break;
608 }
609
610 return rate;
611}
612
613rd_status_t ri_dps310_dsp_get (uint8_t * dsp, uint8_t * parameter)
614{
615 rd_status_t err_code = RD_SUCCESS;
616 uint8_t sampling = 0;
617
618 // Separate rates for temperature and pressure aren't supported
619 // by interface, so can check only temperature rate.
620 if ( (NULL == dsp) || (NULL == parameter))
621 {
622 err_code |= RD_ERROR_NULL;
623 }
624 else if (singleton_ctx_spi.temp_osr > DPS310_OS_1)
625 {
626 sampling = dps310_os_to_samplerate (singleton_ctx_spi.temp_osr);
627
628 if (sampling > 1)
629 {
630 *dsp = RD_SENSOR_DSP_OS;
631 *parameter = sampling;
632 }
633 else
634 {
635 err_code = RD_ERROR_INTERNAL;
636 }
637 }
638 else if (singleton_ctx_spi.temp_osr == DPS310_OS_1)
639 {
641 *parameter = 1U;
642 }
643 else
644 {
645 err_code = RD_ERROR_INTERNAL;
646 }
647
648 return err_code;
649}
650
651static void last_sample_update (const float temp, const float pres, const uint64_t ts)
652{
653 memset (&last_data, 0, sizeof (last_data));
654 last_data.fields = dps_fields;
655 last_data.data = last_values;
656 last_data.timestamp_ms = ts;
657 rd_sensor_data_set (&last_data, RD_SENSOR_PRES_FIELD, pres);
658 rd_sensor_data_set (&last_data, RD_SENSOR_TEMP_FIELD, temp);
659}
660
662{
663 rd_status_t err_code = RD_SUCCESS;
664 dps310_status_t dps_status = DPS310_SUCCESS;
665
666 if (NULL == mode)
667 {
668 err_code |= RD_ERROR_NULL;
669 }
670 else if ( (RD_SENSOR_CFG_SLEEP == *mode)
671 || (RD_SENSOR_CFG_DEFAULT == *mode))
672 {
673 dps_status = dps310_standby (&singleton_ctx_spi);
674 }
675 else if (DPS310_READY != singleton_ctx_spi.device_status)
676 {
677 err_code |= RD_ERROR_INVALID_STATE;
678 }
679 else if (RD_SENSOR_CFG_SINGLE == *mode)
680 {
681 float temperature;
682 float pressure;
683 dps_status |= dps310_measure_temp_once_sync (&singleton_ctx_spi, &temperature);
684 dps_status |= dps310_measure_pres_once_sync (&singleton_ctx_spi, &pressure);
685 last_sample_update (temperature, pressure, rd_sensor_timestamp_get());
686 }
687 else if (RD_SENSOR_CFG_CONTINUOUS == *mode)
688 {
689 dps_status |= dps310_measure_continuous_async (&singleton_ctx_spi);
690 }
691 else
692 {
693 err_code |= RD_ERROR_INVALID_PARAM;
694 }
695
696 if (DPS310_SUCCESS != dps_status)
697 {
698 err_code |= RD_ERROR_INTERNAL;
699 }
700
701 err_code |= ri_dps310_mode_get (mode);
702 return err_code;
703}
704
706{
707 rd_status_t err_code = RD_SUCCESS;
708
709 if (NULL == mode)
710 {
711 err_code |= RD_ERROR_NULL;
712 }
713 else
714 {
715 switch (singleton_ctx_spi.device_status)
716 {
717 case DPS310_READY:
718 *mode = RD_SENSOR_CFG_SLEEP;
719 break;
720
721 case DPS310_CONTINUOUS:
723 break;
724
725 default:
726 err_code |= RD_ERROR_INVALID_STATE;
727 }
728 }
729
730 return err_code;
731}
732
734{
735 rd_status_t err_code = RD_SUCCESS;
736 uint8_t mode = RD_SENSOR_CFG_DEFAULT;
737 (void) ri_dps310_mode_get (&mode);
738
739 if (NULL == data)
740 {
741 err_code |= RD_ERROR_NULL;
742 }
743 // Use cached last value if sensor is sleeping, verify there is a valid sample.
744 else if ( (mode == RD_SENSOR_CFG_SLEEP) && (last_data.timestamp_ms > 0))
745 {
746 rd_sensor_data_populate (data, &last_data, dps_fields);
747 }
748 else if (mode == RD_SENSOR_CFG_CONTINUOUS)
749 {
750 float temperature;
751 float pressure;
752 dps310_status_t dps_status = dps310_get_last_result (&singleton_ctx_spi,
753 &temperature, &pressure);
754 last_sample_update (temperature, pressure, rd_sensor_timestamp_get());
755 rd_sensor_data_populate (data, &last_data, dps_fields);
756
757 if (DPS310_SUCCESS != dps_status)
758 {
759 err_code |= RD_ERROR_INTERNAL;
760 }
761 }
762 else
763 {
764 // No action needed.
765 }
766
767 return err_code;
768}
769
770#endif
rd_status_t ri_dps310_data_get(rd_sensor_data_t *const data)
rd_sensor_data_fp
rd_status_t ri_dps310_scale_set(uint8_t *scale)
rd_sensor_setup_fp
rd_status_t ri_dps310_scale_get(uint8_t *scale)
rd_sensor_setup_fp
rd_status_t ri_dps310_mode_set(uint8_t *mode)
rd_sensor_setup_fp
rd_status_t ri_dps310_mode_get(uint8_t *mode)
rd_sensor_setup_fp
rd_status_t ri_dps310_resolution_get(uint8_t *resolution)
rd_sensor_setup_fp
rd_status_t ri_dps310_resolution_set(uint8_t *resolution)
rd_sensor_setup_fp
rd_status_t ri_dps310_dsp_set(uint8_t *dsp, uint8_t *parameter)
rd_sensor_dsp_fp
rd_status_t ri_dps310_samplerate_get(uint8_t *samplerate)
rd_sensor_setup_fp
rd_status_t ri_dps310_uninit(rd_sensor_t *sensor, rd_bus_t bus, uint8_t handle)
rd_sensor_init_fp
rd_status_t ri_dps310_dsp_get(uint8_t *dsp, uint8_t *parameter)
rd_sensor_dsp_fp
rd_status_t ri_dps310_samplerate_set(uint8_t *samplerate)
rd_sensor_setup_fp
rd_status_t ri_dps310_init(rd_sensor_t *p_sensor, rd_bus_t bus, uint8_t handle)
rd_sensor_init_fp
#define RD_ERROR_INVALID_PARAM
Invalid Parameter.
#define RD_ERROR_NULL
Null Pointer.
uint32_t rd_status_t
bitfield for representing errors
#define RD_ERROR_NOT_IMPLEMENTED
Not implemented yet.
#define RD_ERROR_NOT_SUPPORTED
Not supported.
#define RD_SUCCESS
Internal Error.
#define RD_ERROR_NOT_FOUND
Not found.
#define RD_ERROR_INVALID_STATE
Invalid state, operation disallowed in this state.
#define RD_ERROR_INTERNAL
Internal Error.
uint32_t ri_spi_dps310_read(const void *const comm_ctx, const uint8_t reg_addr, uint8_t *const p_reg_data, const uint8_t data_len)
SPI Read function for DPS310.
uint32_t ri_spi_dps310_write(const void *const comm_ctx, const uint8_t reg_addr, const uint8_t *const p_reg_data, const uint8_t data_len)
SPI write function for DPS310.
#define RD_SENSOR_DSP_LAST
Return last value from sensor. Parameter: No effect. Use default.
bool rd_sensor_is_init(const rd_sensor_t *const sensor)
Check if given sensor structure is already initialized.
#define RD_SENSOR_CFG_SLEEP
Sensor should go to sleep immediately.
#define RD_SENSOR_CFG_MAX
Configure largest supported and implemented value.
#define RD_SENSOR_CFG_DEFAULT
Default value, always valid for the sensor.
void rd_sensor_uninitialize(rd_sensor_t *const p_sensor)
Mark sensor as uninitialized by calling the generic initialization. Will not clear the name of the se...
#define RD_SENSOR_DSP_OS
Oversample sensor values. Parameter: Number of samples.
rd_status_t rd_sensor_configuration_get(const rd_sensor_t *sensor, rd_sensor_configuration_t *config)
Implementation of ref rd_configuration_fp.
void rd_sensor_initialize(rd_sensor_t *const p_sensor)
Initialize sensor struct with non-null pointers which return RD_ERROR_NOT_INITIALIZED.
void rd_sensor_data_populate(rd_sensor_data_t *const target, const rd_sensor_data_t *const provided, const rd_sensor_data_fields_t requested)
Populate given target data with data provided by sensor as requested.
rd_status_t rd_sensor_configuration_set(const rd_sensor_t *sensor, rd_sensor_configuration_t *config)
Implementation of ref rd_configuration_fp.
#define RD_SENSOR_PRES_FIELD
Shorthand for calling rd_sensor_data_parse(p_data, FIELD)
#define RD_SENSOR_CFG_MIN
Configure smallest supported and implemented value.
#define RD_SENSOR_CFG_CONTINUOUS
Sensor will keep sampling at defined sample rate.
#define RD_SENSOR_CFG_NO_CHANGE
Do not change configured value.
rd_bus_t
Type of bus sensor uses.
void rd_sensor_data_set(rd_sensor_data_t *const target, const rd_sensor_data_fields_t field, const float value)
Set a desired value to target data.
uint64_t rd_sensor_timestamp_get(void)
Calls the timestamp function and returns its value.
#define RD_SENSOR_CFG_SINGLE
Sensor should go to sleep after single measurement.
#define RD_SENSOR_TEMP_FIELD
Shorthand for calling rd_sensor_data_parse(p_data, FIELD)
@ RD_BUS_SPI
SPI bus.
@ RD_BUS_I2C
I2C bus.
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
Ruuvi sensor interface Lifecycle: Beta
const rd_sensor_data_fields_t dps_fields
SPI read/write functions for Infineon DPS310.
rd_status_t ri_delay_ms(uint32_t time)
Delay a given number of milliseconds.
unsigned int temperature_c
Temperature, celcius.
Generic sensor data struct.
float * data
Data of sensor. Must contain as many elements as fields has bits set.
uint64_t timestamp_ms
Timestamp of the event, rd_sensor_timestamp_get.
rd_sensor_data_fields_t fields
Description of datafields which may be contained in this sample.
Interface to sensor. Some sensors can implement additional functions. The additional functions are de...
rd_sensor_data_fp data_get
rd_sensor_data_fp
rd_configuration_fp configuration_set
rd_configuration_fp
rd_sensor_setup_fp samplerate_get
rd_sensor_setup_fp
rd_sensor_setup_fp resolution_get
rd_sensor_setup_fp
rd_sensor_init_fp uninit
rd_sensor_init_fp
rd_configuration_fp configuration_get
rd_configuration_fp
void * p_ctx
handle for sensor internal context
rd_sensor_dsp_fp dsp_get
rd_sensor_dsp_fp
rd_sensor_data_fields_t provides
Description of data fields the sensor is able to provide.
rd_sensor_dsp_fp dsp_set
rd_sensor_dsp_fp
rd_sensor_setup_fp mode_set
rd_sensor_setup_fp
const char * name
Sensor human-readable name. Should be at most 8 bytes long.
rd_sensor_setup_fp mode_get
rd_sensor_setup_fp
rd_sensor_setup_fp samplerate_set
rd_sensor_setup_fp
rd_sensor_init_fp init
rd_sensor_init_fp
rd_sensor_setup_fp scale_set
rd_sensor_setup_fp
rd_sensor_setup_fp resolution_set
rd_sensor_setup_fp
rd_sensor_setup_fp scale_get
rd_sensor_setup_fp
Union to access sensor data.
rd_sensor_data_bitfield_t datas
Structured data field.