48 #if RUUVI_NRF5_SDK15_NRF52832_ENVIRONMENTAL_ENABLED
59 #define NRF52_TEMP_SENSOR_RESOLUTION (10U)
60 #define NRF52_TEMP_FIXED_SCALE (128U)
63 static inline __attribute__ ( (nonnull))
80 static inline __attribute__ ( (nonnull))
96 static bool autorefresh =
false;
97 static float temperature;
98 static uint64_t tsample;
99 static const char m_tmp_name[] =
"nRF5TMP";
101 static void nrf52832_temperature_sample (
void)
104 int32_t raw_temp = 0;
106 sd_softdevice_is_enabled (&sd_enabled);
111 sd_temp_get (&raw_temp);
116 NRF_TEMP->TASKS_START = 1;
120 while (NRF_TEMP->EVENTS_DATARDY == 0)
125 NRF_TEMP->EVENTS_DATARDY = 0;
127 raw_temp = nrf_temp_read();
129 NRF_TEMP->TASKS_STOP = 1;
132 temperature = raw_temp / 4.0F;
140 UNUSED_PARAMETER (bus);
141 UNUSED_PARAMETER (handle);
175 sensor->
name = m_tmp_name;
187 UNUSED_PARAMETER (bus);
188 UNUSED_PARAMETER (handle);
206 uint8_t * samplerate)
210 if (NULL == samplerate)
214 else if (
RD_SUCCESS == environmental_mcu_sensor_sleep())
216 uint8_t original = *samplerate;
218 err_code = success_on_valid (original);
229 uint8_t * samplerate)
233 if (NULL == samplerate)
248 uint8_t * resolution)
251 uint8_t original = *resolution;
253 if (NULL == resolution)
257 else if (
RD_SUCCESS == environmental_mcu_sensor_sleep())
259 *resolution = NRF52_TEMP_SENSOR_RESOLUTION;
260 err_code = success_on_valid (original);
271 uint8_t * resolution)
275 if (NULL == resolution)
281 *resolution = NRF52_TEMP_SENSOR_RESOLUTION;
291 uint8_t original = *scale;
297 else if (
RD_SUCCESS == environmental_mcu_sensor_sleep())
299 *scale = NRF52_TEMP_FIXED_SCALE;
300 err_code = success_on_valid (original);
320 *scale = NRF52_TEMP_FIXED_SCALE;
331 uint8_t original = *dsp;
333 if ( (NULL == dsp) || (NULL == parameter))
337 else if (
RD_SUCCESS == environmental_mcu_sensor_sleep())
341 err_code = success_on_valid (original);
378 uint8_t current_mode;
392 nrf52832_temperature_sample();
417 else if (autorefresh)
421 else if (!autorefresh)
446 nrf52832_temperature_sample();
449 if (!isnan (temperature))
454 env_values[0] = temperature;
456 d_environmental.
data = env_values;
457 d_environmental.
valid = env_fields;
458 d_environmental.
fields = env_fields;
rd_status_t ri_environmental_mcu_mode_set(uint8_t *)
rd_sensor_setup_fp
rd_status_t ri_environmental_mcu_scale_set(uint8_t *scale)
rd_sensor_setup_fp
rd_status_t ri_environmental_mcu_mode_get(uint8_t *)
rd_sensor_setup_fp
rd_status_t ri_environmental_mcu_init(rd_sensor_t *environmental_sensor, rd_bus_t bus, uint8_t handle)
rd_sensor_init_fp
rd_status_t ri_environmental_mcu_resolution_get(uint8_t *resolution)
rd_sensor_setup_fp
rd_status_t ri_environmental_mcu_samplerate_get(uint8_t *samplerate)
rd_sensor_setup_fp
rd_status_t ri_environmental_mcu_samplerate_set(uint8_t *samplerate)
rd_sensor_setup_fp
rd_status_t ri_environmental_mcu_resolution_set(uint8_t *resolution)
rd_sensor_setup_fp
rd_status_t ri_environmental_mcu_dsp_get(uint8_t *dsp, uint8_t *parameter)
rd_sensor_dsp_fp
rd_status_t ri_environmental_mcu_dsp_set(uint8_t *dsp, uint8_t *parameter)
rd_sensor_dsp_fp
rd_status_t ri_environmental_mcu_data_get(rd_sensor_data_t *const data)
rd_sensor_data_fp
rd_status_t ri_environmental_mcu_uninit(rd_sensor_t *environmental_sensor, rd_bus_t bus, uint8_t handle)
rd_sensor_init_fp
rd_status_t ri_environmental_mcu_scale_get(uint8_t *scale)
rd_sensor_setup_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_FLOAT_INVALID
Signal that value should not be used.
#define RD_ERROR_NOT_SUPPORTED
Not supported.
#define RD_SUCCESS
Internal Error.
#define RD_UINT64_INVALID
Signal that value should not be used.
#define RD_ERROR_INVALID_STATE
Invalid state, operation disallowed in this state.
#define RD_SENSOR_DSP_LAST
Return last value from sensor. Parameter: No effect. Use default.
#define RD_SENSOR_ERR_NOT_SUPPORTED
Error code, given parameter is not supported by sensor.
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...
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.
#define RD_SENSOR_ERR_INVALID
Error code, given parameter is invalid.
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_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.
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 NRF_SDH_ENABLED
Required by SDK BLE module conditional compilation.
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
Ruuvi sensor interface Lifecycle: Beta
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 valid
Listing of valid data in this sample.
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
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.
uint32_t bitfield
Bitfield used to access sensor data.
rd_sensor_data_bitfield_t datas
Structured data field.