3 #if (RI_ADC_NTC_ENABLED || DOXYGEN)
26 #ifdef RI_ADC_NTC_CHANNEL
27 #define ADC_NTC_USE_CHANNEL RI_ADC_NTC_CHANNEL
29 #define ADC_NTC_USE_CHANNEL 1
32 #ifdef RI_ADC_NTC_DIVIDER
33 #define ADC_NTC_USE_DIVIDER RI_ADC_NTC_DIVIDER
35 #define ADC_NTC_USE_DIVIDER 1.00f
39 #define ADC_NTC_USE_VDD RI_ADC_NTC_VDD
41 #define ADC_NTC_USE_VDD 3.60f
44 #ifdef RI_ADC_NTC_BALANCE
45 #define ADC_NTC_BALANCE RI_ADC_NTC_BALANCE
47 #define ADC_NTC_BALANCE 10000.00f
50 #ifdef RI_ADC_NTC_DEFAULT_RES
51 #define ADC_NTC_DEFAULT_RES RI_ADC_NTC_DEFAULT_RES
53 #define ADC_NTC_DEFAULT_RES 10000.00f
56 #ifdef RI_ADC_NTC_DEFAULT_TEMP
57 #define ADC_NTC_DEFAULT_TEMP RI_ADC_NTC_DEFAULT_TEMP
59 #define ADC_NTC_DEFAULT_TEMP 25.00f
62 #ifdef RI_ADC_NTC_DEFAULT_BETA
63 #define ADC_NTC_DEFAULT_BETA RI_ADC_NTC_DEFAULT_BETA
65 #define ADC_NTC_DEFAULT_BETA 3974.0f
68 #define ADC_NTC_DATA_COUNTER 1
69 #define ADC_NTC_DEFAULT_BITFIELD 0
70 #define ADC_NTC_ENABLE_BYTE 1
71 #define ADC_K_TO_C_CONST 273.15f
72 #define ADC_NTC_DEFAULT_TEMP_K (ADC_NTC_DEFAULT_TEMP + ADC_K_TO_C_CONST)
77 #ifdef RI_ADC_ADV_CONFIG
78 .p_pin.resistor = RI_ADC_RESISTOR_DISABLED,
86 #ifdef RI_ADC_ADV_CONFIG
88 .acqtime = RI_ADC_ACQTIME_10US,
98 static uint64_t m_tsample;
99 static bool m_autorefresh;
101 static bool m_is_init;
102 static const char m_sensor_name[] =
"NTC";
111 static float ratio_to_temperature (
const float *
const ratio)
120 if ( (NULL != ratio) && (*ratio >= 0.0F) && (*ratio <= 1.0F))
123 Rt = (Rb * *ratio) / (1.0F - *ratio);
125 result = 1.0F / ( (1 / T0) + ( (1 / beta) * log (Rt / R0)));
205 environmental_sensor,
rd_bus_t bus, uint8_t handle)
209 if (NULL == environmental_sensor)
222 environmental_sensor->
name = m_sensor_name;
226 &adc_ntc_pins_config,
270 m_autorefresh =
false;
290 m_autorefresh =
false;
297 m_autorefresh =
true;
303 uint8_t current_mode;
313 m_autorefresh =
false;
315 err_code = get_data();
360 err_code = get_data();
371 d_environmental.
data = &env_values;
372 d_environmental.
valid = env_fields;
373 d_environmental.
fields = env_fields;
#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_CFG_SLEEP
Sensor should go to sleep immediately.
#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.
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.
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_CONTINUOUS
Sensor will keep sampling at defined sample rate.
rd_bus_t
Type of bus sensor uses.
uint64_t rd_sensor_timestamp_get(void)
Calls the timestamp function and returns its value.
rd_status_t validate_default_input_get(uint8_t *const input)
Validate and get input when only allowed value is default.
#define RD_SENSOR_CFG_SINGLE
Sensor should go to sleep after single measurement.
Header to enable and disable module compilation.
#define RI_ADC_NTC_DEFAULT_RES
NTC at default temp.
Ruuvi error codes and error check function.
Ruuvi sensor interface Lifecycle: Beta
Interface for controlling ADC onboard MCU.
@ RI_ADC_MODE_SINGLE
Single ended mode.
@ RI_ADC_VREF_EXTERNAL
External voltage reference.
rd_status_t ri_adc_get_data_ratio(uint8_t channel_num, ri_adc_get_data_t *p_config, float *p_data)
Get ADC data in volts.
@ RI_ADC_GND
GND of device.
rd_status_t ri_adc_stop(uint8_t channel_num)
Stop use ADC channel.
rd_status_t ri_adc_configure(uint8_t channel_num, ri_adc_pins_config_t *p_pins, ri_adc_channel_config_t *p_config)
Configure ADC channel.
rd_status_t ri_adc_init(ri_adc_config_t *p_config)
Initialization of ADC.
rd_status_t ri_adc_ntc_dsp_set(uint8_t *dsp, uint8_t *parameter)
rd_sensor_dsp_fp
rd_status_t ri_adc_ntc_mode_set(uint8_t *mode)
rd_sensor_setup_fp
#define ADC_NTC_USE_CHANNEL
float m_temperture
Last measured temperature.
rd_status_t ri_adc_ntc_data_get(rd_sensor_data_t *const p_data)
rd_sensor_data_fp
rd_status_t ri_adc_ntc_resolution_set(uint8_t *resolution)
rd_sensor_setup_fp
rd_status_t ri_adc_ntc_uninit(rd_sensor_t *sensor, rd_bus_t bus, uint8_t handle)
rd_sensor_init_fp
#define ADC_NTC_DATA_COUNTER
rd_status_t ri_adc_ntc_dsp_get(uint8_t *dsp, uint8_t *parameter)
rd_sensor_dsp_fp
#define ADC_NTC_USE_DIVIDER
rd_status_t ri_adc_ntc_init(rd_sensor_t *environmental_sensor, rd_bus_t bus, uint8_t handle)
rd_sensor_init_fp
#define ADC_NTC_DEFAULT_BITFIELD
#define ADC_NTC_DEFAULT_BETA
rd_status_t ri_adc_ntc_scale_set(uint8_t *scale)
rd_sensor_setup_fp
rd_status_t ri_adc_ntc_samplerate_set(uint8_t *samplerate)
rd_sensor_setup_fp
#define ADC_NTC_ENABLE_BYTE
rd_status_t ri_adc_ntc_mode_get(uint8_t *mode)
rd_sensor_setup_fp
#define ADC_NTC_DEFAULT_TEMP_K
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
ri_adc_pin_config_t p_pin
Union to access sensor data.
uint32_t bitfield
Bitfield used to access sensor data.
rd_sensor_data_bitfield_t datas
Structured data field.