ruuvi.drivers.c
${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
|
Functions for setting up and using sensors. More...
Files | |
file | ruuvi_driver_sensor.h |
Ruuvi sensor interface Lifecycle: Beta | |
Data Structures | |
struct | rd_sensor_configuration_t |
All sensors must implement configuration functions which accept this struct. More... | |
struct | rd_sensor_data_bitfield_t |
Bitfield to describe related sensor data. More... | |
union | rd_sensor_data_fields_t |
Union to access sensor data. More... | |
struct | rd_sensor_data_t |
Generic sensor data struct. More... | |
struct | rd_sensor_t |
Interface to sensor. Some sensors can implement additional functions. The additional functions are defined in the interface of the sensor. More... | |
Macros | |
#define | RD_SENSOR_INVALID_VALUE RD_FLOAT_INVALID |
Signal this sensor value is erroneous. More... | |
#define | RD_SENSOR_INVALID_TIMSTAMP RD_UINT64_INVALID |
Signal this timestamp value is erroneous. More... | |
#define | RD_SENSOR_CFG_DEFAULT (0U) |
Default value, always valid for the sensor. More... | |
#define | RD_SENSOR_CFG_CUSTOM_1 (0xC9U) |
Configuration range is 0...200, i.e. 0 ... 0xC8. Use C9 ... CF as sensor-specific values. More... | |
#define | RD_SENSOR_CFG_CUSTOM_2 (0xCAU) |
Configuration range is 0...200, i.e. 0 ... 0xC8. Use C9 ... CF as sensor-specific values. More... | |
#define | RD_SENSOR_CFG_CUSTOM_3 (0xCBU) |
Configuration range is 0...200, i.e. 0 ... 0xC8. Use C9 ... CF as sensor-specific values. More... | |
#define | RD_SENSOR_CFG_CUSTOM_4 (0xCCU) |
Configuration range is 0...200, i.e. 0 ... 0xC8. Use C9 ... CF as sensor-specific values. More... | |
#define | RD_SENSOR_CFG_CUSTOM_5 (0xCDU) |
Configuration range is 0...200, i.e. 0 ... 0xC8. Use C9 ... CF as sensor-specific values. More... | |
#define | RD_SENSOR_CFG_CUSTOM_6 (0xCEU) |
Configuration range is 0...200, i.e. 0 ... 0xC8. Use C9 ... CF as sensor-specific values. More... | |
#define | RD_SENSOR_ERR_INVALID (0xE0U) |
Error code, given parameter is invalid. More... | |
#define | RD_SENSOR_ERR_NOT_IMPLEMENTED (0xE1U) |
Error code, given parameter is not implemented (todo) More... | |
#define | RD_SENSOR_ERR_NOT_SUPPORTED (0xE2U) |
Error code, given parameter is not supported by sensor. More... | |
#define | RD_SENSOR_CFG_MIN (0xF0U) |
Configure smallest supported and implemented value. More... | |
#define | RD_SENSOR_CFG_MAX (0xF1U) |
Configure largest supported and implemented value. More... | |
#define | RD_SENSOR_CFG_SLEEP (0xF2U) |
Sensor should go to sleep immediately. More... | |
#define | RD_SENSOR_CFG_SINGLE (0xF3U) |
Sensor should go to sleep after single measurement. More... | |
#define | RD_SENSOR_CFG_CONTINUOUS (0xF4U) |
Sensor will keep sampling at defined sample rate. More... | |
#define | RD_SENSOR_CFG_NO_CHANGE (0xFFU) |
Do not change configured value. More... | |
#define | RD_SENSOR_DSP_LAST (0U) |
Return last value from sensor. Parameter: No effect. Use default. More... | |
#define | RD_SENSOR_DSP_LOW_PASS (1U<<1U) |
Low pass sensor values Parameter: coefficient. More... | |
#define | RD_SENSOR_DSP_HIGH_PASS (1U<<2U) |
High pass sensor values Parameter: coefficient. More... | |
#define | RD_SENSOR_DSP_OS (1U<<3U) |
Oversample sensor values. Parameter: Number of samples. More... | |
#define | RD_GPIO_TO_HANDLE(handle) ((((handle) >> 3U) & 0xE0U) + ((handle) & 0x1FU)) |
convert Ruuvi GPIO into uint8_t More... | |
#define | RD_HANDLE_TO_GPIO(handle) ((((handle) & 0xE0U) << 3U) + ((handle) & 0x1FU)) |
convert uint8_t into Ruuvi GPIO More... | |
#define | RD_HANDLE_UNUSED (0xFFU) |
Mark sensor as unused with this handle. More... | |
#define | UNUSED_VARIABLE(X) ((void)(X)) |
#define | RD_SENSOR_ACC_X_FIELD ((rd_sensor_data_fields_t){.datas.acceleration_x_g=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD) More... | |
#define | RD_SENSOR_ACC_Y_FIELD ((rd_sensor_data_fields_t){.datas.acceleration_y_g=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD) More... | |
#define | RD_SENSOR_ACC_Z_FIELD ((rd_sensor_data_fields_t){.datas.acceleration_z_g=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD) More... | |
#define | RD_SENSOR_GYR_X_FIELD ((rd_sensor_data_fields_t){.datas.gyro_x_dps=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD) More... | |
#define | RD_SENSOR_GYR_Y_FIELD ((rd_sensor_data_fields_t){.datas.gyro_y_dps=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD) More... | |
#define | RD_SENSOR_GYR_Z_FIELD ((rd_sensor_data_fields_t){.datas.gyro_z_dps=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD) More... | |
#define | RD_SENSOR_HUMI_FIELD ((rd_sensor_data_fields_t){.datas.humidity_rh=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD) More... | |
#define | RD_SENSOR_PRES_FIELD ((rd_sensor_data_fields_t){.datas.pressure_pa=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD) More... | |
#define | RD_SENSOR_TEMP_FIELD ((rd_sensor_data_fields_t){.datas.temperature_c=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD) More... | |
Typedefs | |
typedef struct rd_sensor_data_t | rd_sensor_data_t |
Generic sensor data struct. More... | |
typedef struct rd_sensor_t | rd_sensor_t |
Forward declare type definition of sensor structure. More... | |
typedef rd_status_t(* | rd_sensor_init_fp) (rd_sensor_t *const p_sensor, const rd_bus_t bus, const uint8_t handle) |
Initialize and uninitialize sensor. Init and uninit will setup sensor with function pointers. The sensor wil be initialized to lowest power state possible. More... | |
typedef rd_status_t(* | rd_sensor_setup_fp) (uint8_t *parameter) |
Setup a parameter of a sensor. The function will modify the pointed data to the actual value which was written. More... | |
typedef rd_status_t(* | rd_sensor_dsp_fp) (uint8_t *dsp_function, uint8_t *dsp_parameter) |
Configure sensor digital signal processing. Takes DSP function and a DSP parameter as input, configured value or error code as output. Modifies input parameters to actual values written on the sensor. DSP functions are run on the sensor HW, not in the platform FW. More... | |
typedef rd_status_t(* | rd_sensor_data_fp) (rd_sensor_data_t *const p_data) |
Read latest data from sensor registers Return latest data from sensor. Does not take a new sample, calling this function twice in a row returns same data. Configure sensor in a single-shot mode to take a new sample or leave sensor in a continuous mode to get updated data. More... | |
typedef rd_status_t(* | rd_configuration_fp) (const rd_sensor_t *const p_sensor, rd_sensor_configuration_t *const p_configuration) |
Convenience function to write/read entire configuration in one call. Modifies input parameters to actual values written on the sensor. More... | |
typedef rd_status_t(* | rd_sensor_fifo_read_fp) (size_t *const num_elements, rd_sensor_data_t *const data) |
Read First-in-first-out (FIFO) buffer in sensor. Reads up to num_elements data points from FIFO and populates pointer data with them. More... | |
typedef rd_status_t(* | rd_sensor_fifo_enable_fp) (const bool enable) |
Enable FIFO or FIFO interrupt full interrupt on sensor. FIFO interrupt Triggers an interrupt once FIFO is filled. It is responsibility of application to know the routing of and polarity of GPIO pins and configure the GPIO to register interrupts. More... | |
typedef rd_status_t(* | rd_sensor_level_interrupt_use_fp) (const bool enable, float *limit_g) |
Enable level interrupt on sensor. More... | |
typedef uint64_t(* | rd_sensor_timestamp_fp) (void) |
Return number of milliseconds since the start of RTC. More... | |
Enumerations | |
enum | rd_bus_t { RD_BUS_NONE = 0U , RD_BUS_SPI = 1U , RD_BUS_I2C = 2U , RD_BUS_UART = 3U , RD_BUS_PDM = 4U , RD_BUS_FAIL = 5U } |
Type of bus sensor uses. More... | |
Functions | |
rd_status_t | rd_sensor_configuration_set (const rd_sensor_t *sensor, rd_sensor_configuration_t *config) |
Implementation of ref rd_configuration_fp. More... | |
rd_status_t | rd_sensor_configuration_get (const rd_sensor_t *sensor, rd_sensor_configuration_t *config) |
Implementation of ref rd_configuration_fp. More... | |
rd_status_t | rd_sensor_timestamp_function_set (const rd_sensor_timestamp_fp timestamp_fp) |
Setup timestamping. Set to NULL to disable timestamps. More... | |
uint64_t | rd_sensor_timestamp_get (void) |
Calls the timestamp function and returns its value. More... | |
void | rd_sensor_initialize (rd_sensor_t *const p_sensor) |
Initialize sensor struct with non-null pointers which return RD_ERROR_NOT_INITIALIZED. More... | |
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 sensor. More... | |
bool | rd_sensor_is_init (const rd_sensor_t *const sensor) |
Check if given sensor structure is already initialized. More... | |
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. More... | |
float | rd_sensor_data_parse (const rd_sensor_data_t *const provided, const rd_sensor_data_fields_t requested) |
Parse data from provided struct. More... | |
uint8_t | rd_sensor_data_fieldcount (const rd_sensor_data_t *const target) |
Count number of floats required for this data structure. More... | |
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. More... | |
rd_status_t | validate_default_input_set (uint8_t *const input, const uint8_t mode) |
Validate that given setting can be set on a sensor which supports only default value. More... | |
rd_status_t | validate_default_input_get (uint8_t *const input) |
Validate and get input when only allowed value is default. More... | |
bool | rd_sensor_has_valid_data (const rd_sensor_data_t *const target, const uint8_t index) |
Check if sensor has valid data at given index. More... | |
rd_sensor_data_bitfield_t | rd_sensor_field_type (const rd_sensor_data_t *const target, const uint8_t index) |
Check the type of data at given index. More... | |
Functions for setting up and using sensors.
#define RD_GPIO_TO_HANDLE | ( | handle | ) | ((((handle) >> 3U) & 0xE0U) + ((handle) & 0x1FU)) |
convert Ruuvi GPIO into uint8_t
Definition at line 91 of file ruuvi_driver_sensor.h.
#define RD_HANDLE_TO_GPIO | ( | handle | ) | ((((handle) & 0xE0U) << 3U) + ((handle) & 0x1FU)) |
convert uint8_t into Ruuvi GPIO
Definition at line 93 of file ruuvi_driver_sensor.h.
#define RD_HANDLE_UNUSED (0xFFU) |
Mark sensor as unused with this handle.
Definition at line 95 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_ACC_X_FIELD ((rd_sensor_data_fields_t){.datas.acceleration_x_g=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD)
C99 Standard 6.7.8.21 If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration.
Definition at line 170 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_ACC_Y_FIELD ((rd_sensor_data_fields_t){.datas.acceleration_y_g=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD)
Definition at line 172 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_ACC_Z_FIELD ((rd_sensor_data_fields_t){.datas.acceleration_z_g=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD)
Definition at line 174 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_CFG_CONTINUOUS (0xF4U) |
Sensor will keep sampling at defined sample rate.
Definition at line 81 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_CFG_CUSTOM_1 (0xC9U) |
Configuration range is 0...200, i.e. 0 ... 0xC8. Use C9 ... CF as sensor-specific values.
Definition at line 68 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_CFG_CUSTOM_2 (0xCAU) |
Configuration range is 0...200, i.e. 0 ... 0xC8. Use C9 ... CF as sensor-specific values.
Definition at line 69 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_CFG_CUSTOM_3 (0xCBU) |
Configuration range is 0...200, i.e. 0 ... 0xC8. Use C9 ... CF as sensor-specific values.
Definition at line 70 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_CFG_CUSTOM_4 (0xCCU) |
Configuration range is 0...200, i.e. 0 ... 0xC8. Use C9 ... CF as sensor-specific values.
Definition at line 71 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_CFG_CUSTOM_5 (0xCDU) |
Configuration range is 0...200, i.e. 0 ... 0xC8. Use C9 ... CF as sensor-specific values.
Definition at line 72 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_CFG_CUSTOM_6 (0xCEU) |
Configuration range is 0...200, i.e. 0 ... 0xC8. Use C9 ... CF as sensor-specific values.
Definition at line 73 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_CFG_DEFAULT (0U) |
Default value, always valid for the sensor.
Definition at line 67 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_CFG_MAX (0xF1U) |
Configure largest supported and implemented value.
Definition at line 78 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_CFG_MIN (0xF0U) |
Configure smallest supported and implemented value.
Definition at line 77 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_CFG_NO_CHANGE (0xFFU) |
Do not change configured value.
Definition at line 82 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_CFG_SINGLE (0xF3U) |
Sensor should go to sleep after single measurement.
Definition at line 80 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_CFG_SLEEP (0xF2U) |
Sensor should go to sleep immediately.
Definition at line 79 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_DSP_HIGH_PASS (1U<<2U) |
High pass sensor values Parameter: coefficient.
Definition at line 87 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_DSP_LAST (0U) |
Return last value from sensor. Parameter: No effect. Use default.
Definition at line 85 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_DSP_LOW_PASS (1U<<1U) |
Low pass sensor values Parameter: coefficient.
Definition at line 86 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_DSP_OS (1U<<3U) |
Oversample sensor values. Parameter: Number of samples.
Definition at line 88 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_ERR_INVALID (0xE0U) |
Error code, given parameter is invalid.
Definition at line 74 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_ERR_NOT_IMPLEMENTED (0xE1U) |
Error code, given parameter is not implemented (todo)
Definition at line 75 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_ERR_NOT_SUPPORTED (0xE2U) |
Error code, given parameter is not supported by sensor.
Definition at line 76 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_GYR_X_FIELD ((rd_sensor_data_fields_t){.datas.gyro_x_dps=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD)
Definition at line 176 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_GYR_Y_FIELD ((rd_sensor_data_fields_t){.datas.gyro_y_dps=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD)
Definition at line 178 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_GYR_Z_FIELD ((rd_sensor_data_fields_t){.datas.gyro_z_dps=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD)
Definition at line 180 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_HUMI_FIELD ((rd_sensor_data_fields_t){.datas.humidity_rh=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD)
Definition at line 182 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_INVALID_TIMSTAMP RD_UINT64_INVALID |
Signal this timestamp value is erroneous.
Definition at line 64 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_INVALID_VALUE RD_FLOAT_INVALID |
Signal this sensor value is erroneous.
Definition at line 63 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_PRES_FIELD ((rd_sensor_data_fields_t){.datas.pressure_pa=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD)
Definition at line 184 of file ruuvi_driver_sensor.h.
#define RD_SENSOR_TEMP_FIELD ((rd_sensor_data_fields_t){.datas.temperature_c=1}) |
Shorthand for calling rd_sensor_data_parse(p_data, FIELD)
Definition at line 186 of file ruuvi_driver_sensor.h.
#define UNUSED_VARIABLE | ( | X | ) | ((void)(X)) |
Definition at line 98 of file ruuvi_driver_sensor.h.
typedef rd_status_t(* rd_configuration_fp) (const rd_sensor_t *const p_sensor, rd_sensor_configuration_t *const p_configuration) |
Convenience function to write/read entire configuration in one call. Modifies input parameters to actual values written on the sensor.
[in] | p_sensor | sensor to configure |
[in,out] | p_configuration | Input: desired configuration. Output: configuration written to sensot. |
RD_SUCCESS | if sensor was configured successfully. |
RD_ERROR_NULL | if one of parameters is NULL |
Definition at line 304 of file ruuvi_driver_sensor.h.
typedef rd_status_t(* rd_sensor_data_fp) (rd_sensor_data_t *const p_data) |
Read latest data from sensor registers Return latest data from sensor. Does not take a new sample, calling this function twice in a row returns same data. Configure sensor in a single-shot mode to take a new sample or leave sensor in a continuous mode to get updated data.
p_data may contain, some, none or all of fields sensor is able to provide. Fields which are already marked as valid will not be overwritten, filled fields will get marked as valid.
[out] | p_data | Pointer to sensor data rd_sensor_data_t . |
NULL
. Definition at line 291 of file ruuvi_driver_sensor.h.
typedef struct rd_sensor_data_t rd_sensor_data_t |
Generic sensor data struct.
The data sensor struct contains a timestamp relative to sensor boot, a list of fields contained within the sensor data and a pointer to array of floats which contain the actual data.
typedef rd_status_t(* rd_sensor_dsp_fp) (uint8_t *dsp_function, uint8_t *dsp_parameter) |
Configure sensor digital signal processing. Takes DSP function and a DSP parameter as input, configured value or error code as output. Modifies input parameters to actual values written on the sensor. DSP functions are run on the sensor HW, not in the platform FW.
[in,out] | dsp_function | DSP function to run on sensor. Can be a combination of several functions. |
[in,out] | dsp_parameter | Parameter to DSP function(s) |
Definition at line 273 of file ruuvi_driver_sensor.h.
typedef rd_status_t(* rd_sensor_fifo_enable_fp) (const bool enable) |
Enable FIFO or FIFO interrupt full interrupt on sensor. FIFO interrupt Triggers an interrupt once FIFO is filled. It is responsibility of application to know the routing of and polarity of GPIO pins and configure the GPIO to register interrupts.
[in] | enable | True to enable interrupt, false to disable interrupt |
Definition at line 333 of file ruuvi_driver_sensor.h.
typedef rd_status_t(* rd_sensor_fifo_read_fp) (size_t *const num_elements, rd_sensor_data_t *const data) |
Read First-in-first-out (FIFO) buffer in sensor. Reads up to num_elements data points from FIFO and populates pointer data with them.
[in,out] | num_elements | Input: number of elements in data. Output: Number of elements placed in data. |
[out] | data | array of with num_elements slots. |
RD_SUCCESS | on success. |
RD_ERROR_NULL | if either parameter is NULL. |
RD_ERROR_INVALID_STATE | if FIFO is not in use. |
RD_ERROR_NOT_SUPPORTED | if the sensor does not have FIFO. |
Definition at line 321 of file ruuvi_driver_sensor.h.
typedef rd_status_t(* rd_sensor_init_fp) (rd_sensor_t *const p_sensor, const rd_bus_t bus, const uint8_t handle) |
Initialize and uninitialize sensor. Init and uninit will setup sensor with function pointers. The sensor wil be initialized to lowest power state possible.
[in,out] | p_sensor | pointer to sensor structure |
[in] | bus | bus to use, i.r. I2C or SPI |
[in] | handle | for the sensor, for example I2C address or SPI chip select pin |
RD_SUCCESS
on success RD_ERROR_NULL
if p_sensor is NULL RD_ERROR_NOT_FOUND
if there is no response from sensor or if ID of a sensor read over bus does not match expected value RD_ERROR_SELFTEST
if sensor is found but it does not pass selftest RD_ERROR_INVALID_STATE
if trying to initialize sensor which already has been initialized. Definition at line 243 of file ruuvi_driver_sensor.h.
typedef rd_status_t(* rd_sensor_level_interrupt_use_fp) (const bool enable, float *limit_g) |
Enable level interrupt on sensor.
Triggers as ACTIVE HIGH interrupt while detected data is above threshold.
Trigger is symmetric, i.e. threshold is valid for above positive or below negative of given value.
On accelerometer data is high-passed to filter out gravity. Axes are examined individually, compound data won't trigger the interrupt. e.g. accelerometer showing 0.8 G along X, Y, Z axes won't trigger at threshold of 1 G, even though the vector sum of axes is larger than 1 G.
It is responsibility of application to know the GPIO routing and register GPIO interrupts.
[in] | enable | True to enable interrupt, false to disable interrupt |
[in,out] | limit_g | Input: Desired acceleration to trigger the interrupt. Is considered as "at least", the acceleration is rounded up to next value. Output: written with value that was set to interrupt |
RD_SUCCESS | on success. |
RD_INVALID_STATE | if data limit is higher than maximum scale. |
Definition at line 361 of file ruuvi_driver_sensor.h.
typedef rd_status_t(* rd_sensor_setup_fp) (uint8_t *parameter) |
Setup a parameter of a sensor. The function will modify the pointed data to the actual value which was written.
[in,out] | parameter | value to write to sensor configuration. Actual value written to sensor as output |
Definition at line 256 of file ruuvi_driver_sensor.h.
typedef struct rd_sensor_t rd_sensor_t |
Forward declare type definition of sensor structure.
Interface to sensor. Some sensors can implement additional functions. The additional functions are defined in the interface of the sensor.
Definition at line 1 of file ruuvi_driver_sensor.h.
typedef uint64_t(* rd_sensor_timestamp_fp) (void) |
Return number of milliseconds since the start of RTC.
Definition at line 370 of file ruuvi_driver_sensor.h.
enum rd_bus_t |
Type of bus sensor uses.
Enumerator | |
---|---|
RD_BUS_NONE | No bus, internal to IC. |
RD_BUS_SPI | SPI bus. |
RD_BUS_I2C | I2C bus. |
RD_BUS_UART | UART bus. |
RD_BUS_PDM | PDM bus. |
RD_BUS_FAIL | Test behaviour on invalid bus with this value. |
Definition at line 120 of file ruuvi_driver_sensor.h.
rd_status_t rd_sensor_configuration_get | ( | const rd_sensor_t * | sensor, |
rd_sensor_configuration_t * | config | ||
) |
Implementation of ref rd_configuration_fp.
Definition at line 29 of file ruuvi_driver_sensor.c.
rd_status_t rd_sensor_configuration_set | ( | const rd_sensor_t * | sensor, |
rd_sensor_configuration_t * | config | ||
) |
Implementation of ref rd_configuration_fp.
Definition at line 10 of file ruuvi_driver_sensor.c.
|
inline |
Count number of floats required for this data structure.
[in] | target | Structure to count number of fields from. |
Definition at line 333 of file ruuvi_driver_sensor.c.
float rd_sensor_data_parse | ( | const rd_sensor_data_t *const | provided, |
const rd_sensor_data_fields_t | requested | ||
) |
Parse data from provided struct.
[in] | provided | Data to be parsed. |
[in] | requested | One data field to be parsed. |
Definition at line 175 of file ruuvi_driver_sensor.c.
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.
This function looks up the appropriate assigments on each data field in given target and populates it with provided data if caller requested the field to be populated. Populated fields are marked as valid.
Example: Board can have these sensors in this order of priority:
If a target with fields for temperature, humidity, pressure and acceleration is created and populated from data of the sensors end result will be:
-> Temperature, timestamp from TMP117 -> Humidity from SHTC3 -> Pressure from DPS310 -> Acceleration from LIS2DH12
If same firmware is run on a board with only LIS2DH12 populated, end result will be
-> Temperature, timestamp, acceleration from LIS2DH12 -> RD_FLOAT_INVALID on humidity and pressure.
[out] | target | Data to be populated. Fields must be initially populated with RD_FLOAT_INVALID. |
[in] | provided | Data provided by sensor. |
[in] | requested | Fields to be filled if possible. |
Definition at line 290 of file ruuvi_driver_sensor.c.
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.
This function looks up the appropriate assigments on each data field in given target and populates it with provided data. Does nothing if there is no appropriate slot in target data.
This is a shorthand for rd_sensor_data_populate for only one data field, without setting timestamp.
[out] | target | |
[in] | field | Quantity to set, exactly one must be set to true. |
[in] | value | Value of quantity, |
Definition at line 191 of file ruuvi_driver_sensor.c.
rd_sensor_data_bitfield_t rd_sensor_field_type | ( | const rd_sensor_data_t *const | target, |
const uint8_t | index | ||
) |
Check the type of data at given index.
This function is used to determine what type of data given index has.
Typical usage:
[in] | target | Data to check |
[in] | index | Index of field to check. |
Definition at line 254 of file ruuvi_driver_sensor.c.
bool rd_sensor_has_valid_data | ( | const rd_sensor_data_t *const | target, |
const uint8_t | index | ||
) |
Check if sensor has valid data at given index.
Data is considered valid if target->fields and target->valid both are set. Index is referred to number of fields.
Typical usage:
[in] | target | Pointer to data to check. |
[in] | index | index of data to check. |
true | If data at target->data[index] has a valid value. |
false | If target is NULL, index is higher than fields in data or data at index is not marked as valid. |
Definition at line 218 of file ruuvi_driver_sensor.c.
void rd_sensor_initialize | ( | rd_sensor_t *const | p_sensor | ) |
Initialize sensor struct with non-null pointers which return RD_ERROR_NOT_INITIALIZED.
This function is to ensure that NULL function pointers won't be called. If name was NULL before calling this, name will point to "NOTINIT". If name was already set, it won't be changed.
[out] | p_sensor | pointer to sensor struct to initialize. |
Definition at line 114 of file ruuvi_driver_sensor.c.
bool rd_sensor_is_init | ( | const rd_sensor_t *const | sensor | ) |
Check if given sensor structure is already initialized.
[in] | sensor | Sensor interface to check. |
Definition at line 397 of file ruuvi_driver_sensor.c.
rd_status_t rd_sensor_timestamp_function_set | ( | const rd_sensor_timestamp_fp | timestamp_fp | ) |
Setup timestamping. Set to NULL
to disable timestamps.
[in] | timestamp_fp | Function pointer to rd_sensor_timestamp_fp implementation |
RD_SUCCESS. |
Definition at line 48 of file ruuvi_driver_sensor.c.
uint64_t rd_sensor_timestamp_get | ( | void | ) |
Calls the timestamp function and returns its value.
RD_UINT64_INVALID | if timestamp function is NULL |
Definition at line 56 of file ruuvi_driver_sensor.c.
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 sensor.
[out] | p_sensor | pointer to sensor struct to uninitialize. |
Definition at line 143 of file ruuvi_driver_sensor.c.
rd_status_t validate_default_input_get | ( | uint8_t *const | input | ) |
Validate and get input when only allowed value is default.
[out] | input | Setting of sensor to get. Will be RD_SENSOR_CFG_DEFAULT. |
RD_SUCCESS | if input is not NULL. |
RD_ERROR_NULL | if input is NULL. |
Definition at line 381 of file ruuvi_driver_sensor.c.
rd_status_t validate_default_input_set | ( | uint8_t *const | input, |
const uint8_t | mode | ||
) |
Validate that given setting can be set on a sensor which supports only default value.
[in,out] | input | Input: Must be RD_SENSOR_CFG_DEFAULT, _NO_CHANGE, _MIN or _MAX. Output: _DEFAULT |
[in] | mode | Mode sensor is currently in. Must be sleep to configure sensor. |
Definition at line 338 of file ruuvi_driver_sensor.c.