4 #if (RI_DPS310_ENABLED || DOXYGEN)
14 static void dps_sleep (
const uint32_t ms)
20 static uint8_t spi_comm_handle;
21 static dps310_ctx_t singleton_ctx_spi =
26 .comm_ctx = &spi_comm_handle
29 static const char *
const name =
"DPS310";
33 .datas.pressure_pa = 1
35 static float last_values[2];
38 static __attribute__ ( (nonnull))
void
39 dps310_singleton_spi_setup (
rd_sensor_t *
const p_sensor,
42 p_sensor->
p_ctx = &singleton_ctx_spi;
43 spi_comm_handle = handle;
46 static __attribute__ ( (nonnull))
70 dps310_status_t dps_status = DPS310_SUCCESS;
83 p_sensor->
name = name;
85 if (NULL == p_sensor->
p_ctx)
89 dps310_singleton_spi_setup (p_sensor, handle);
103 dps_status = dps310_init (p_sensor->
p_ctx);
105 if (DPS310_SUCCESS == dps_status)
107 dps310_fp_setup (p_sensor);
108 p_sensor->
name = name;
110 memset (&last_data, 0,
sizeof (last_data));
133 (void) dps310_uninit (sensor->
p_ctx);
143 dps310_status_t dps_status = DPS310_SUCCESS;
145 if (NULL == samplerate)
149 else if (DPS310_READY != singleton_ctx_spi.device_status)
159 dps_status |= dps310_config_temp (&singleton_ctx_spi,
161 singleton_ctx_spi.temp_osr);
162 dps_status |= dps310_config_pres (&singleton_ctx_spi,
164 singleton_ctx_spi.pres_osr);
168 dps_status |= dps310_config_temp (&singleton_ctx_spi,
170 singleton_ctx_spi.temp_osr);
171 dps_status |= dps310_config_pres (&singleton_ctx_spi,
173 singleton_ctx_spi.pres_osr);
177 dps_status |= dps310_config_temp (&singleton_ctx_spi,
179 singleton_ctx_spi.temp_osr);
180 dps_status |= dps310_config_pres (&singleton_ctx_spi,
182 singleton_ctx_spi.pres_osr);
184 else if (2U == *samplerate)
186 dps_status |= dps310_config_temp (&singleton_ctx_spi,
188 singleton_ctx_spi.temp_osr);
189 dps_status |= dps310_config_pres (&singleton_ctx_spi,
191 singleton_ctx_spi.pres_osr);
193 else if (4U >= *samplerate)
195 dps_status |= dps310_config_temp (&singleton_ctx_spi,
197 singleton_ctx_spi.temp_osr);
198 dps_status |= dps310_config_pres (&singleton_ctx_spi,
200 singleton_ctx_spi.pres_osr);
202 else if (8U >= *samplerate)
204 dps_status |= dps310_config_temp (&singleton_ctx_spi,
206 singleton_ctx_spi.temp_osr);
207 dps_status |= dps310_config_pres (&singleton_ctx_spi,
209 singleton_ctx_spi.pres_osr);
211 else if (16U >= *samplerate)
213 dps_status |= dps310_config_temp (&singleton_ctx_spi,
215 singleton_ctx_spi.temp_osr);
216 dps_status |= dps310_config_pres (&singleton_ctx_spi,
218 singleton_ctx_spi.pres_osr);
220 else if (32U >= *samplerate)
222 dps_status |= dps310_config_temp (&singleton_ctx_spi,
224 singleton_ctx_spi.temp_osr);
225 dps_status |= dps310_config_pres (&singleton_ctx_spi,
227 singleton_ctx_spi.pres_osr);
229 else if (64U >= *samplerate)
231 dps_status |= dps310_config_temp (&singleton_ctx_spi,
233 singleton_ctx_spi.temp_osr);
234 dps_status |= dps310_config_pres (&singleton_ctx_spi,
236 singleton_ctx_spi.pres_osr);
238 else if (128U >= *samplerate)
240 dps_status |= dps310_config_temp (&singleton_ctx_spi,
242 singleton_ctx_spi.temp_osr);
243 dps_status |= dps310_config_pres (&singleton_ctx_spi,
245 singleton_ctx_spi.pres_osr);
252 if ( (DPS310_SUCCESS == dps_status) && (
RD_SUCCESS == err_code))
268 static uint8_t dps310_mr_to_samplerate (
const dps310_mr_t mr)
319 if (NULL == samplerate)
327 rate = dps310_mr_to_samplerate (singleton_ctx_spi.temp_mr);
346 if (NULL == resolution)
350 else if (DPS310_READY != singleton_ctx_spi.device_status)
374 if (NULL == resolution)
394 else if (DPS310_READY != singleton_ctx_spi.device_status)
433 dps310_status_t dps_status = DPS310_SUCCESS;
435 if ( (NULL == dsp) || (NULL == parameter))
439 else if (DPS310_READY != singleton_ctx_spi.device_status)
446 dps_status |= dps310_config_temp (&singleton_ctx_spi,
447 singleton_ctx_spi.temp_mr,
449 dps_status |= dps310_config_pres (&singleton_ctx_spi,
450 singleton_ctx_spi.pres_mr,
461 dps_status |= dps310_config_temp (&singleton_ctx_spi,
462 singleton_ctx_spi.temp_mr,
464 dps_status |= dps310_config_pres (&singleton_ctx_spi,
465 singleton_ctx_spi.pres_mr,
470 dps_status |= dps310_config_temp (&singleton_ctx_spi,
471 singleton_ctx_spi.temp_mr,
473 dps_status |= dps310_config_pres (&singleton_ctx_spi,
474 singleton_ctx_spi.pres_mr,
479 dps_status |= dps310_config_temp (&singleton_ctx_spi,
480 singleton_ctx_spi.temp_mr,
482 dps_status |= dps310_config_pres (&singleton_ctx_spi,
483 singleton_ctx_spi.pres_mr,
486 else if (2U == *parameter)
488 dps_status |= dps310_config_temp (&singleton_ctx_spi,
489 singleton_ctx_spi.temp_mr,
491 dps_status |= dps310_config_pres (&singleton_ctx_spi,
492 singleton_ctx_spi.pres_mr,
495 else if (4U >= *parameter)
497 dps_status |= dps310_config_temp (&singleton_ctx_spi,
498 singleton_ctx_spi.temp_mr,
500 dps_status |= dps310_config_pres (&singleton_ctx_spi,
501 singleton_ctx_spi.pres_mr,
504 else if (8U >= *parameter)
506 dps_status |= dps310_config_temp (&singleton_ctx_spi,
507 singleton_ctx_spi.temp_mr,
509 dps_status |= dps310_config_pres (&singleton_ctx_spi,
510 singleton_ctx_spi.pres_mr,
513 else if (16U >= *parameter)
515 dps_status |= dps310_config_temp (&singleton_ctx_spi,
516 singleton_ctx_spi.temp_mr,
518 dps_status |= dps310_config_pres (&singleton_ctx_spi,
519 singleton_ctx_spi.pres_mr,
522 else if (32U >= *parameter)
524 dps_status |= dps310_config_temp (&singleton_ctx_spi,
525 singleton_ctx_spi.temp_mr,
527 dps_status |= dps310_config_pres (&singleton_ctx_spi,
528 singleton_ctx_spi.pres_mr,
531 else if (64U >= *parameter)
533 dps_status |= dps310_config_temp (&singleton_ctx_spi,
534 singleton_ctx_spi.temp_mr,
536 dps_status |= dps310_config_pres (&singleton_ctx_spi,
537 singleton_ctx_spi.pres_mr,
540 else if (128U >= *parameter)
542 dps_status |= dps310_config_temp (&singleton_ctx_spi,
543 singleton_ctx_spi.temp_mr,
545 dps_status |= dps310_config_pres (&singleton_ctx_spi,
546 singleton_ctx_spi.pres_mr,
555 if (DPS310_SUCCESS == dps_status)
567 static uint8_t dps310_os_to_samplerate (
const dps310_os_t os)
616 uint8_t sampling = 0;
620 if ( (NULL == dsp) || (NULL == parameter))
624 else if (singleton_ctx_spi.temp_osr > DPS310_OS_1)
626 sampling = dps310_os_to_samplerate (singleton_ctx_spi.temp_osr);
631 *parameter = sampling;
638 else if (singleton_ctx_spi.temp_osr == DPS310_OS_1)
651 static void last_sample_update (
const float temp,
const float pres,
const uint64_t ts)
653 memset (&last_data, 0,
sizeof (last_data));
655 last_data.
data = last_values;
664 dps310_status_t dps_status = DPS310_SUCCESS;
673 dps_status = dps310_standby (&singleton_ctx_spi);
675 else if (DPS310_READY != singleton_ctx_spi.device_status)
683 dps_status |= dps310_measure_temp_once_sync (&singleton_ctx_spi, &temperature);
684 dps_status |= dps310_measure_pres_once_sync (&singleton_ctx_spi, &pressure);
689 dps_status |= dps310_measure_continuous_async (&singleton_ctx_spi);
696 if (DPS310_SUCCESS != dps_status)
715 switch (singleton_ctx_spi.device_status)
721 case DPS310_CONTINUOUS:
752 dps310_status_t dps_status = dps310_get_last_result (&singleton_ctx_spi,
753 &temperature, &pressure);
757 if (DPS310_SUCCESS != dps_status)
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)
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.