3 #if (RI_TMP117_ENABLED || DOXYGEN)
28 #define TMP117_CC_RETRIES_MAX (5U)
29 #define TMP117_CC_RETRY_DELAY_MS (10U)
31 static uint8_t m_address;
32 static uint16_t ms_per_sample;
33 static uint16_t ms_per_cc;
34 static float m_temperature;
35 static uint64_t m_timestamp;
36 static const char m_sensor_name[] =
"TMP117";
37 static bool m_continuous =
false;
39 static inline bool param_is_valid (
const uint8_t param)
57 static rd_status_t tmp117_validate_id (
const uint8_t handle)
72 static inline rd_status_t os_1_set (uint16_t *
const reg_val)
86 static inline rd_status_t os_8_set (uint16_t *
const reg_val)
100 static inline rd_status_t os_32_set (uint16_t *
const reg_val)
114 static inline rd_status_t os_64_set (uint16_t *
const reg_val)
128 static rd_status_t tmp117_oversampling_set (
const uint8_t num_os)
139 reg_val |= os_1_set (®_val);
143 reg_val |= os_8_set (®_val);
147 reg_val |= os_32_set (®_val);
151 reg_val |= os_64_set (®_val);
164 tmp117_cc_check (uint16_t *
const reg,
const uint16_t ts,
const uint16_t reg_val)
168 if (ts < ms_per_sample)
181 static rd_status_t tmp117_samplerate_set (
const uint16_t num_os)
247 uint16_t reg_val = 0;
272 static rd_status_t tmp117_read (
float *
const temperature)
277 int32_t dec_temperature;
279 if (reg_val > 0x7FFFU)
281 dec_temperature = (int32_t) reg_val - 0xFFFF;
285 dec_temperature = reg_val;
288 *temperature = (0.0078125F * dec_temperature);
303 if (NULL == environmental_sensor)
314 environmental_sensor->
name = m_sensor_name;
319 err_code |= tmp117_validate_id (handle);
329 err_code |= tmp117_soft_reset();
350 m_continuous =
false;
374 m_continuous =
false;
385 if (NULL == samplerate)
389 else if (m_continuous)
398 || (1 >= *samplerate))
403 else if (2 >= *samplerate)
408 else if (4 >= *samplerate)
413 else if (8 >= *samplerate)
418 else if (64 >= *samplerate ||
449 uint16_t reg_val = 0;
451 if (NULL == samplerate)
507 if (NULL == resolution)
511 else if (m_continuous)
515 else if (! param_is_valid (*resolution))
531 if (NULL == resolution)
551 else if (m_continuous)
555 else if (!param_is_valid (*scale))
587 if ( (NULL == dsp) || (NULL == parameter))
591 else if (m_continuous)
614 else if (8 >= *parameter)
619 else if (32 >= *parameter)
624 else if (64 >= *parameter)
657 if ( (NULL == dsp) || (NULL == parameter))
663 uint16_t reg_val = 0;
702 static rd_status_t tmp117_poll_drdy (
bool *
const drdy)
712 static rd_status_t tmp117_wait_for_sample (
const uint16_t initial_delay_ms)
721 err_code |= tmp117_poll_drdy (&drdy);
739 tmp117_take_single_sample (uint8_t *
const mode)
750 err_code |= tmp117_sample ();
754 err_code |= tmp117_wait_for_sample (ms_per_sample);
759 err_code |= tmp117_read (&m_temperature);
781 err_code |= tmp117_continuous();
786 err_code |= tmp117_take_single_sample (mode);
790 err_code |= tmp117_sleep();
791 m_continuous =
false;
811 else if (m_continuous)
834 err_code |= tmp117_read (&m_temperature);
839 && !isnan (m_temperature))
#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_SUPPORTED
Not supported.
#define RD_SUCCESS
Internal Error.
#define RD_ERROR_TIMEOUT
Operation timed out.
#define RD_ERROR_NOT_FOUND
Not found.
#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_ERROR_INTERNAL
Internal Error.
rd_status_t ri_i2c_tmp117_write(const uint8_t dev_id, const uint8_t reg_addr, const uint16_t reg_val)
I2C write function for TMP117.
rd_status_t ri_i2c_tmp117_read(const uint8_t dev_id, const uint8_t reg_addr, uint16_t *const reg_val)
I2C Read function for TMP117.
#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.
#define RD_SENSOR_CFG_CUSTOM_3
Configuration range is 0...200, i.e. 0 ... 0xC8. Use C9 ... CF as sensor-specific values.
#define RD_SENSOR_CFG_CUSTOM_1
Configuration range is 0...200, i.e. 0 ... 0xC8. Use C9 ... CF as sensor-specific values.
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.
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.
#define UNUSED_VARIABLE(X)
#define RD_SENSOR_CFG_CUSTOM_2
Configuration range is 0...200, i.e. 0 ... 0xC8. Use C9 ... CF as sensor-specific values.
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 TMP117_VALUE_CC_500_MS
rd_status_t ri_tmp117_resolution_set(uint8_t *resolution)
rd_sensor_setup_fp
rd_status_t ri_tmp117_dsp_get(uint8_t *dsp, uint8_t *parameter)
rd_sensor_dsp_fp
#define TMP117_OS_8_TSAMPLE_MS
rd_status_t ri_tmp117_data_get(rd_sensor_data_t *const data)
rd_sensor_data_fp
#define TMP117_VALUE_CC_8000_MS
rd_status_t ri_tmp117_resolution_get(uint8_t *resolution)
rd_sensor_setup_fp
#define TMP117_OS_64_TSAMPLE_MS
rd_status_t ri_tmp117_uninit(rd_sensor_t *sensor, rd_bus_t bus, uint8_t handle)
rd_sensor_init_fp
rd_status_t ri_tmp117_scale_get(uint8_t *scale)
rd_sensor_setup_fp
#define TMP117_VALUE_CC_16000_MS
#define TMP117_CC_RESET_DELAY_MS
#define TMP117_VALUE_OS_8
#define TMP117_VALUE_CC_125_MS
rd_status_t ri_tmp117_samplerate_get(uint8_t *samplerate)
rd_sensor_setup_fp
#define TMP117_VALUE_OS_32
rd_status_t ri_tmp117_scale_set(uint8_t *scale)
rd_sensor_setup_fp
rd_status_t ri_tmp117_mode_set(uint8_t *mode)
rd_sensor_setup_fp
#define TMP117_VALUE_CC_16_MS
#define TMP117_REG_TEMP_RESULT
#define TMP117_VALUE_CC_250_MS
#define TMP117_OS_1_TSAMPLE_MS
rd_status_t ri_tmp117_dsp_set(uint8_t *dsp, uint8_t *parameter)
rd_sensor_dsp_fp
rd_status_t ri_tmp117_mode_get(uint8_t *mode)
rd_sensor_setup_fp
#define TMP117_REG_DEVICE_ID
#define TMP117_VALUE_OS_1
#define TMP117_VALUE_OS_64
#define TMP117_VALUE_TEMP_NA
#define TMP117_MASK_RESET
#define TMP117_REG_CONFIGURATION
#define TMP117_VALUE_MODE_SINGLE
rd_status_t ri_tmp117_samplerate_set(uint8_t *samplerate)
rd_sensor_setup_fp
#define TMP117_OS_32_TSAMPLE_MS
#define TMP117_VALUE_MODE_CONT
#define TMP117_CC_RETRIES_MAX
#define TMP117_VALUE_MODE_SLEEP
rd_status_t ri_tmp117_init(rd_sensor_t *environmental_sensor, rd_bus_t bus, uint8_t handle)
rd_sensor_init_fp
#define TMP117_VALUE_CC_4000_MS
#define TMP117_CC_RETRY_DELAY_MS
#define TMP117_VALUE_CC_1000_MS
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
Ruuvi sensor interface Lifecycle: Beta
I2C read/write functions for TI TMP117.
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.
uint64_t timestamp_ms
Timestamp of the event, rd_sensor_timestamp_get.
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.