Low voltage digital temperature sensor
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: X_NUCLEO_IKS01A3 X_NUCLEO_IKS01A3 X_NUCLEO_IKS01A3
Revision 0:128dae13c732, committed 2019-03-06
- Comitter:
- cparata
- Date:
- Wed Mar 06 10:18:41 2019 +0000
- Child:
- 1:5859badee052
- Commit message:
- First version of STTS751 library
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/STTS751Sensor.cpp Wed Mar 06 10:18:41 2019 +0000
@@ -0,0 +1,500 @@
+/**
+ ******************************************************************************
+ * @file STTS751Sensor.cpp
+ * @author SRA
+ * @version V1.0.0
+ * @date February 2019
+ * @brief Implementation of a STTS751 temperature sensor.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2019 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+
+/* Includes ------------------------------------------------------------------*/
+
+#include "STTS751Sensor.h"
+
+
+/* Class Implementation ------------------------------------------------------*/
+
+/** Constructor
+ * @param i2c object of an helper class which handles the I2C peripheral
+ * @param address the address of the component's instance
+ * @param int_pin the interrupt pin
+ */
+STTS751Sensor::STTS751Sensor(DevI2C *i2c, uint8_t address, PinName int_pin) : _dev_i2c(i2c), _address(address), _int_irq(int_pin)
+{
+ assert (i2c);
+ _reg_ctx.write_reg = STTS751_io_write;
+ _reg_ctx.read_reg = STTS751_io_read;
+ _reg_ctx.handle = (void *)this;
+}
+
+/**
+ * @brief Initializing the component
+ * @param init pointer to device specific initalization structure
+ * @retval 0 in case of success, an error code otherwise
+ */
+int STTS751Sensor::init(void *init)
+{
+ /* Disable EVENT pin of SMBus. */
+ if (stts751_pin_event_route_set(&_reg_ctx, PROPERTY_ENABLE) != 0)
+ {
+ return 1;
+ }
+
+ /* Set default ODR */
+ _last_odr = 1.0f;
+
+ /* Set the resolution to the maximum allowed value */
+ if (stts751_resolution_set(&_reg_ctx, STTS751_12bit) != 0)
+ {
+ return 1;
+ }
+
+ /* Put the component in standby mode. */
+ if (stts751_temp_data_rate_set(&_reg_ctx, STTS751_TEMP_ODR_OFF) != 0)
+ {
+ return 1;
+ }
+
+ _is_enabled = 0;
+
+ return 0;
+}
+
+/**
+ * @brief Get WHO_AM_I value
+ * @param id the WHO_AM_I value
+ * @retval 0 in case of success, an error code otherwise
+ */
+int STTS751Sensor::read_id(uint8_t *id)
+{
+ stts751_id_t buf;
+
+ if (stts751_device_id_get(&_reg_ctx, &buf) != 0)
+ {
+ return 1;
+ }
+
+ *id = buf.manufacturer_id;
+
+ return 0;
+}
+
+/**
+ * @brief Enable the STTS751 temperature sensor
+ * @retval 0 in case of success, an error code otherwise
+ */
+int STTS751Sensor::enable()
+{
+ /* Check if the component is already enabled */
+ if (_is_enabled == 1U)
+ {
+ return 0;
+ }
+
+ /* Power on the component and set the odr. */
+ if (set_odr(_last_odr) != 0)
+ {
+ return 1;
+ }
+
+ _is_enabled = 1;
+
+ return 0;
+}
+
+/**
+ * @brief Disable the STTS751 temperature sensor
+ * @retval 0 in case of success, an error code otherwise
+ */
+int STTS751Sensor::disable()
+{
+ /* Check if the component is already disabled */
+ if (_is_enabled == 0U)
+ {
+ return 0;
+ }
+
+ /* Save the current odr. */
+ if (get_odr(&_last_odr) != 0)
+ {
+ return 1;
+ }
+
+ /* Put the component in standby mode. */
+ if (stts751_temp_data_rate_set(&_reg_ctx, STTS751_TEMP_ODR_OFF) != 0)
+ {
+ return 1;
+ }
+
+ _is_enabled = 0;
+
+ return 0;
+}
+
+/**
+ * @brief Get the STTS751 temperature sensor output data rate
+ * @param odr pointer where the output data rate is written
+ * @retval 0 in case of success, an error code otherwise
+ */
+int STTS751Sensor::get_odr(float *odr)
+{
+ int ret = 0;
+ stts751_odr_t odr_low_level;
+
+ if (stts751_temp_data_rate_get(&_reg_ctx, &odr_low_level) != 0)
+ {
+ return 1;
+ }
+
+ switch (odr_low_level)
+ {
+ case STTS751_TEMP_ODR_OFF:
+ case STTS751_TEMP_ODR_ONE_SHOT:
+ *odr = 0.0f;
+ break;
+
+ case STTS751_TEMP_ODR_62mHz5:
+ *odr = 0.0625f;
+ break;
+
+ case STTS751_TEMP_ODR_125mHz:
+ *odr = 0.125f;
+ break;
+
+ case STTS751_TEMP_ODR_250mHz:
+ *odr = 0.250f;
+ break;
+
+ case STTS751_TEMP_ODR_500mHz:
+ *odr = 0.500f;
+ break;
+
+ case STTS751_TEMP_ODR_1Hz:
+ *odr = 1.0f;
+ break;
+
+ case STTS751_TEMP_ODR_2Hz:
+ *odr = 2.0f;
+ break;
+
+ case STTS751_TEMP_ODR_4Hz:
+ *odr = 4.0f;
+ break;
+
+ case STTS751_TEMP_ODR_8Hz:
+ *odr = 8.0f;
+ break;
+
+ case STTS751_TEMP_ODR_16Hz:
+ *odr = 16.0f;
+ break;
+
+ case STTS751_TEMP_ODR_32Hz:
+ *odr = 32.0f;
+ break;
+
+ default:
+ ret = 1;
+ break;
+ }
+
+ return ret;
+}
+
+/**
+ * @brief Set the STTS751 temperature sensor output data rate
+ * @param odr the output data rate value to be set
+ * @retval 0 in case of success, an error code otherwise
+ */
+int STTS751Sensor::set_odr(float odr)
+{
+ stts751_odr_t new_odr;
+ stts751_tres_t res;
+
+ /* Get the current resolution */
+ if (stts751_resolution_get(&_reg_ctx, &res) != 0)
+ {
+ return 1;
+ }
+
+ /* If the requested odr is 16Hz we cannot use the 12 bits resolution */
+ if(odr == 16.0f && res == STTS751_12bit)
+ {
+ /* We force resolution to the maximum allowed value */
+ if (stts751_resolution_set(&_reg_ctx, STTS751_11bit) != 0)
+ {
+ return 1;
+ }
+ }
+
+ /* If the requested odr is 32Hz we cannot use the 12 bits and 11 bits resolutions */
+ if(odr == 32.0f && (res == STTS751_12bit || res == STTS751_11bit))
+ {
+ /* We force resolution to the maximum allowed value */
+ if (stts751_resolution_set(&_reg_ctx, STTS751_10bit) != 0)
+ {
+ return 1;
+ }
+ }
+
+ new_odr = (odr <= 0.0625f) ? STTS751_TEMP_ODR_62mHz5
+ : (odr <= 0.125f ) ? STTS751_TEMP_ODR_125mHz
+ : (odr <= 0.25f ) ? STTS751_TEMP_ODR_250mHz
+ : (odr <= 0.5f ) ? STTS751_TEMP_ODR_500mHz
+ : (odr <= 1.0f ) ? STTS751_TEMP_ODR_1Hz
+ : (odr <= 2.0f ) ? STTS751_TEMP_ODR_2Hz
+ : (odr <= 4.0f ) ? STTS751_TEMP_ODR_4Hz
+ : (odr <= 8.0f ) ? STTS751_TEMP_ODR_8Hz
+ : (odr <= 16.0f ) ? STTS751_TEMP_ODR_16Hz
+ : STTS751_TEMP_ODR_32Hz;
+
+ if (stts751_temp_data_rate_set(&_reg_ctx, new_odr) != 0)
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+/**
+ * @brief Get the STTS751 temperature value
+ * @param value pointer where the temperature value is written
+ * @retval 0 in case of success, an error code otherwise
+ */
+int STTS751Sensor::get_temperature(float *value)
+{
+ int16_t raw_value = 0;
+
+ /* Get the temperature */
+ if (stts751_temperature_raw_get(&_reg_ctx, &raw_value) != 0)
+ {
+ return 1;
+ }
+
+ *value = stts751_from_lsb_to_celsius(raw_value);
+
+ return 0;
+}
+
+/**
+ * @brief Get the STTS751 temperature data ready bit value
+ * @param status the status of data ready bit
+ * @retval 0 in case of success, an error code otherwise
+ */
+int STTS751Sensor::get_temp_drdy_status(uint8_t *status)
+{
+ uint8_t val;
+
+ if (stts751_flag_busy_get(&_reg_ctx, &val) != 0)
+ {
+ return 1;
+ }
+
+ if(val)
+ {
+ *status = 0;
+ } else
+ {
+ *status = 1;
+ }
+
+ return 0;
+}
+
+/**
+ * @brief Set the STTS751 low temperature threshold value
+ * @param value the low temperature threshold to be set
+ * @retval 0 in case of success, an error code otherwise
+ */
+int STTS751Sensor::set_low_temp_thr(float value)
+{
+ int16_t raw_value;
+
+ raw_value = stts751_from_celsius_to_lsb(value);
+
+ /* Set the temperature threshold */
+ if (stts751_low_temperature_threshold_set(&_reg_ctx, raw_value) != 0)
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+/**
+ * @brief Set the STTS751 high temperature threshold value
+ * @param value the high temperature threshold to be set
+ * @retval 0 in case of success, an error code otherwise
+ */
+int STTS751Sensor::set_high_temp_thr(float value)
+{
+ int16_t raw_value;
+
+ raw_value = stts751_from_celsius_to_lsb(value);
+
+ /* Set the temperature threshold */
+ if (stts751_high_temperature_threshold_set(&_reg_ctx, raw_value) != 0)
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+/**
+ * @brief Get the STTS751 temperature limits status
+ * @param high_limit indicates that high temperature limit has been exceeded
+ * @param low_limit indicates that low temperature limit has been exceeded
+ * @param therm_limit indicates that therm temperature limit has been exceeded
+ * @retval 0 in case of success, an error code otherwise
+ */
+int STTS751Sensor::get_temp_limit_status(uint8_t *high_limit, uint8_t *low_limit, uint8_t *therm_limit)
+{
+ stts751_status_t status;
+
+ /* Read status register */
+ if (stts751_status_reg_get(&_reg_ctx, &status) != 0)
+ {
+ return 1;
+ }
+
+ *high_limit = status.t_high;
+ *low_limit = status.t_low;
+ *therm_limit = status.thrm;
+
+ return 0;
+}
+
+/**
+ * @brief Enable or disable interrupt on EVENT pin
+ * @param enable 0 disable the EVENT pin, 1 enable EVENT pin
+ * @retval 0 in case of success, an error code otherwise
+ */
+int STTS751Sensor::set_event_pin(uint8_t enable)
+{
+ uint8_t state;
+
+ /* The MASK1 bit in configuration register has inverted logic */
+ if (enable == 0) state = PROPERTY_ENABLE; else state = PROPERTY_DISABLE;
+
+ if (stts751_pin_event_route_set(&_reg_ctx, state) != 0)
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+/**
+ * @brief Get the STTS751 register value
+ * @param reg address to be read
+ * @param data pointer where the value is written
+ * @retval 0 in case of success, an error code otherwise
+ */
+int STTS751Sensor::read_reg(uint8_t reg, uint8_t *data)
+{
+ if (stts751_read_reg(&_reg_ctx, reg, data, 1) != 0)
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+/**
+ * @brief Set the STTS751 register value
+ * @param reg address to be written
+ * @param data value to be written
+ * @retval 0 in case of success, an error code otherwise
+ */
+int STTS751Sensor::write_reg(uint8_t reg, uint8_t data)
+{
+ if (stts751_write_reg(&_reg_ctx, reg, &data, 1) != 0)
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+/**
+ * @brief Set the STTS751 One Shot Mode
+ * @retval 0 in case of success, an error code otherwise
+ */
+int STTS751Sensor::set_one_shot()
+{
+ /* Start One Shot Measurement */
+ if(stts751_temp_data_rate_set(&_reg_ctx, STTS751_TEMP_ODR_ONE_SHOT) != 0)
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+/**
+ * @brief Get the STTS751 One Shot Status
+ * @param status pointer to the one shot status (1 means measurements available, 0 means measurements not available yet)
+ * @retval 0 in case of success, an error code otherwise
+ */
+int STTS751Sensor::get_one_shot_status(uint8_t *status)
+{
+ uint8_t busy;
+
+ /* Get Busy flag */
+ if(stts751_flag_busy_get(&_reg_ctx, &busy) != 0)
+ {
+ return 1;
+ }
+
+ if(busy)
+ {
+ *status = 0;
+ }
+ else
+ {
+ *status = 1;
+ }
+
+ return 0;
+}
+
+
+int32_t STTS751_io_write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite)
+{
+ return ((STTS751Sensor *)handle)->io_write(pBuffer, WriteAddr, nBytesToWrite);
+}
+
+int32_t STTS751_io_read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead)
+{
+ return ((STTS751Sensor *)handle)->io_read(pBuffer, ReadAddr, nBytesToRead);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/STTS751Sensor.h Wed Mar 06 10:18:41 2019 +0000
@@ -0,0 +1,162 @@
+/**
+ ******************************************************************************
+ * @file STTS751Sensor.h
+ * @author SRA
+ * @version V1.0.0
+ * @date February 2018
+ * @brief Abstract Class of a STTS751 temperature sensor.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2019 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+
+/* Prevent recursive inclusion -----------------------------------------------*/
+
+#ifndef __STTS751Sensor_H__
+#define __STTS751Sensor_H__
+
+
+/* Includes ------------------------------------------------------------------*/
+
+#include "DevI2C.h"
+#include "stts751_reg.h"
+#include "TempSensor.h"
+#include <assert.h>
+
+/* Defines -------------------------------------------------------------------*/
+/* Typedefs ------------------------------------------------------------------*/
+/* Class Declaration ---------------------------------------------------------*/
+
+/**
+ * Abstract class of a STTS751 temperature sensor.
+ */
+class STTS751Sensor : public TempSensor
+{
+ public:
+
+ STTS751Sensor(DevI2C *i2c, uint8_t address=STTS751_0xxxx_ADD_7K5, PinName int_pin=NC);
+ virtual int init(void *init);
+ virtual int read_id(uint8_t *id);
+ virtual int get_temperature(float *value);
+ int enable(void);
+ int disable(void);
+ int get_odr(float *odr);
+ int set_odr(float odr);
+ int read_reg(uint8_t reg, uint8_t *data);
+ int write_reg(uint8_t reg, uint8_t data);
+ int get_temp_drdy_status(uint8_t *status);
+ int set_low_temp_thr(float value);
+ int set_high_temp_thr(float value);
+ int get_temp_limit_status(uint8_t *high_limit, uint8_t *low_limit, uint8_t *therm_limit);
+ int set_event_pin(uint8_t enable);
+ int set_one_shot();
+ int get_one_shot_status(uint8_t *status);
+
+ /**
+ * @brief Attaching an interrupt handler to the INT interrupt.
+ * @param fptr an interrupt handler.
+ * @retval None.
+ */
+ void attach_int_irq(void (*fptr)(void))
+ {
+ _int_irq.fall(fptr);
+ }
+
+ /**
+ * @brief Enabling the INT interrupt handling.
+ * @param None.
+ * @retval None.
+ */
+ void enable_int_irq(void)
+ {
+ _int_irq.enable_irq();
+ }
+
+ /**
+ * @brief Disabling the INT interrupt handling.
+ * @param None.
+ * @retval None.
+ */
+ void disable_int_irq(void)
+ {
+ _int_irq.disable_irq();
+ }
+
+
+ /**
+ * @brief Utility function to read data.
+ * @param pBuffer: pointer to data to be read.
+ * @param RegisterAddr: specifies internal address register to be read.
+ * @param NumByteToRead: number of bytes to be read.
+ * @retval 0 if ok, an error code otherwise.
+ */
+ uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead)
+ {
+ if (_dev_i2c) return (uint8_t) _dev_i2c->i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead);
+ return 1;
+ }
+
+ /**
+ * @brief Utility function to write data.
+ * @param pBuffer: pointer to data to be written.
+ * @param RegisterAddr: specifies internal address register to be written.
+ * @param NumByteToWrite: number of bytes to write.
+ * @retval 0 if ok, an error code otherwise.
+ */
+ uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite)
+ {
+ if (_dev_i2c) return (uint8_t) _dev_i2c->i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite);
+ return 1;
+ }
+
+ private:
+
+ /* Helper classes. */
+ DevI2C *_dev_i2c;
+
+ /* Configuration */
+ uint8_t _address;
+ InterruptIn _int_irq;
+
+ uint8_t _is_enabled;
+ float _last_odr;
+
+ stts751_ctx_t _reg_ctx;
+};
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+int32_t STTS751_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite );
+int32_t STTS751_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead );
+#ifdef __cplusplus
+ }
+#endif
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST_INTERFACES.lib Wed Mar 06 10:18:41 2019 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#d3c9b33b992c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_COMMON.lib Wed Mar 06 10:18:41 2019 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/X_NUCLEO_COMMON/#21096473f63e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/stts751_reg.c Wed Mar 06 10:18:41 2019 +0000
@@ -0,0 +1,713 @@
+/*
+ ******************************************************************************
+ * @file stts751_reg.c
+ * @author Sensors Software Solution Team
+ * @brief STTS751 driver file
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2018 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+#include "stts751_reg.h"
+
+/**
+ * @defgroup STTS751
+ * @brief This file provides a set of functions needed to drive the
+ * stts751 enhanced inertial module.
+ * @{
+ *
+ */
+
+/**
+ * @defgroup STTS751_Interfaces_Functions
+ * @brief This section provide a set of functions used to read and
+ * write a generic register of the device.
+ * MANDATORY: return 0 -> no Error.
+ * @{
+ *
+ */
+
+/**
+ * @brief Read generic device register
+ *
+ * @param ctx read / write interface definitions(ptr)
+ * @param reg register to read
+ * @param data pointer to buffer that store the data read(ptr)
+ * @param len number of consecutive register to read
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_read_reg(stts751_ctx_t* ctx, uint8_t reg, uint8_t* data,
+ uint16_t len)
+{
+ int32_t ret;
+ ret = ctx->read_reg(ctx->handle, reg, data, len);
+ return ret;
+}
+
+/**
+ * @brief Write generic device register
+ *
+ * @param ctx read / write interface definitions(ptr)
+ * @param reg register to write
+ * @param data pointer to data to write in register reg(ptr)
+ * @param len number of consecutive register to write
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_write_reg(stts751_ctx_t* ctx, uint8_t reg, uint8_t* data,
+ uint16_t len)
+{
+ int32_t ret;
+ ret = ctx->write_reg(ctx->handle, reg, data, len);
+ return ret;
+}
+
+/**
+ * @}
+ *
+ */
+
+/**
+ * @defgroup STTS751_Sensitivity
+ * @brief These functions convert raw-data into engineering units and
+ * vice-versa .
+ * @{
+ *
+ */
+
+float stts751_from_lsb_to_celsius(int16_t lsb)
+{
+ return ((float)lsb) / 256.0f;
+}
+
+/**
+ * @}
+ *
+ */
+
+/**
+ * @defgroup STTS751_Sensitivity_Reverse
+ * @brief This conversion is useful but not need by the driver.
+ *
+ * REMOVING this union you are compliant with:
+ * MISRA-C 2012 [Rule 10.8] -> " Explicit cast of composite
+ * expression "
+ *
+ * @{
+ *
+ */
+
+int16_t stts751_from_celsius_to_lsb(float celsius)
+{
+ return (int16_t)(celsius * 256.0f);
+}
+
+/**
+ * @}
+ *
+ */
+
+/**
+ * @defgroup STTS751_Data_Generation
+ * @brief This section groups all the functions concerning
+ * data generation
+ * @{
+ *
+ */
+
+/**
+ * @brief Temperature sensor data rate selection.[set]
+ *
+ * @param ctx read / write interface definitions
+ * @param val change the sensor data rate
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_temp_data_rate_set(stts751_ctx_t *ctx, stts751_odr_t val)
+{
+ stts751_configuration_t configuration;
+ stts751_conversion_rate_t conversion_rate;
+ uint8_t dummy_value = 0xAA;
+ int32_t ret;
+
+ ret = stts751_read_reg(ctx, STTS751_CONVERSION_RATE,
+ (uint8_t*)&conversion_rate, 1);
+ if (ret == 0) {
+ conversion_rate.conv = (uint8_t)val & 0x0FU;
+ ret = stts751_write_reg(ctx, STTS751_CONVERSION_RATE,
+ (uint8_t*)&conversion_rate, 1);
+ }
+ if (ret == 0) {
+ ret = stts751_read_reg(ctx, STTS751_CONFIGURATION,
+ (uint8_t*)&configuration, 1);
+ }
+ if (ret == 0) {
+ configuration.stop = ((uint8_t)val & 0x80U) >> 7;
+ ret = stts751_write_reg(ctx, STTS751_CONFIGURATION,
+ (uint8_t*)&configuration, 1);
+ }
+ if ((ret == 0) && (val == STTS751_TEMP_ODR_ONE_SHOT)) {
+ ret = stts751_write_reg(ctx, STTS751_ONE_SHOT, &dummy_value, 1);
+ }
+ return ret;
+}
+
+/**
+ * @brief Temperature sensor data rate selection.[get]
+ *
+ * @param ctx read / write interface definitions
+ * @param val Get the sensor data rate
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_temp_data_rate_get(stts751_ctx_t *ctx, stts751_odr_t *val)
+{
+ stts751_conversion_rate_t conversion_rate;
+ stts751_configuration_t configuration;
+ int32_t ret;
+
+ ret = stts751_read_reg(ctx, STTS751_CONVERSION_RATE,
+ (uint8_t*)&conversion_rate, 1);
+ if (ret == 0) {
+ ret = stts751_read_reg(ctx, STTS751_CONFIGURATION,
+ (uint8_t*)&configuration, 1);
+ }
+ switch ( (configuration.stop << 7) + conversion_rate.conv) {
+ case STTS751_TEMP_ODR_OFF:
+ *val = STTS751_TEMP_ODR_OFF;
+ break;
+ case STTS751_TEMP_ODR_ONE_SHOT:
+ *val = STTS751_TEMP_ODR_ONE_SHOT;
+ break;
+ case STTS751_TEMP_ODR_62mHz5:
+ *val = STTS751_TEMP_ODR_62mHz5;
+ break;
+ case STTS751_TEMP_ODR_125mHz:
+ *val = STTS751_TEMP_ODR_125mHz;
+ break;
+ case STTS751_TEMP_ODR_250mHz:
+ *val = STTS751_TEMP_ODR_250mHz;
+ break;
+ case STTS751_TEMP_ODR_500mHz:
+ *val = STTS751_TEMP_ODR_500mHz;
+ break;
+ case STTS751_TEMP_ODR_1Hz:
+ *val = STTS751_TEMP_ODR_1Hz;
+ break;
+ case STTS751_TEMP_ODR_2Hz:
+ *val = STTS751_TEMP_ODR_2Hz;
+ break;
+ case STTS751_TEMP_ODR_4Hz:
+ *val = STTS751_TEMP_ODR_4Hz;
+ break;
+ case STTS751_TEMP_ODR_8Hz:
+ *val = STTS751_TEMP_ODR_8Hz;
+ break;
+ case STTS751_TEMP_ODR_16Hz:
+ *val = STTS751_TEMP_ODR_16Hz;
+ break;
+ case STTS751_TEMP_ODR_32Hz:
+ *val = STTS751_TEMP_ODR_32Hz;
+ break;
+ default:
+ *val = STTS751_TEMP_ODR_OFF;
+ break;
+ }
+ return ret;
+}
+
+/**
+ * @brief Temperature sensor resolution selection.[set]
+ *
+ * @param ctx read / write interface definitions
+ * @param val change the values of tres in reg CONFIGURATION
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_resolution_set(stts751_ctx_t *ctx, stts751_tres_t val)
+{
+ stts751_configuration_t reg;
+ int32_t ret;
+
+ ret = stts751_read_reg(ctx, STTS751_CONFIGURATION,(uint8_t*) ®, 1);
+ if (ret == 0) {
+ reg.tres = (uint8_t) val;
+ ret = stts751_write_reg(ctx, STTS751_CONFIGURATION,(uint8_t*) ®, 1);
+ }
+ return ret;
+}
+
+/**
+ * @brief Temperature sensor resolution selection.[get]
+ *
+ * @param ctx read / write interface definitions
+ * @param val Get the values of tres in reg CONFIGURATION
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_resolution_get(stts751_ctx_t *ctx, stts751_tres_t *val)
+{
+ stts751_configuration_t reg;
+ int32_t ret;
+
+ ret = stts751_read_reg(ctx, STTS751_CONFIGURATION,(uint8_t*) ®, 1);
+
+ switch (reg.tres) {
+ case STTS751_9bit:
+ *val = STTS751_9bit;
+ break;
+ case STTS751_10bit:
+ *val = STTS751_10bit;
+ break;
+ case STTS751_11bit:
+ *val = STTS751_11bit;
+ break;
+ case STTS751_12bit:
+ *val = STTS751_12bit;
+ break;
+ default:
+ *val = STTS751_9bit;
+ break;
+ }
+ return ret;
+}
+
+/**
+ * @brief The STATUS_REG register of the device.[get]
+ *
+ * @param ctx read / write interface definitions
+ * @param val union of registers from STATUS to
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_status_reg_get(stts751_ctx_t *ctx, stts751_status_t *val)
+{
+ int32_t ret;
+ ret = stts751_read_reg(ctx, STTS751_STATUS, (uint8_t*) val, 1);
+ return ret;
+}
+
+/**
+ * @brief Temperature sensor "conversion on-going" flag.[get]
+ *
+ * @param ctx read / write interface definitions
+ * @param val get the values of busy in reg STATUS
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_flag_busy_get(stts751_ctx_t *ctx, uint8_t *val)
+{
+ stts751_status_t reg;
+ int32_t ret;
+
+ ret = stts751_read_reg(ctx, STTS751_STATUS, (uint8_t*)®, 1);
+ *val = reg.busy;
+
+ return ret;
+}
+
+/**
+ * @}
+ *
+ */
+
+/**
+ * @defgroup STTS751_Data_Output
+ * @brief This section groups all the data output functions.
+ * @{
+ *
+ */
+
+/**
+ * @brief Temperature data output register (r). L and H registers
+ * together express a 16-bit word in two’s complement.[get]
+ *
+ * @param ctx read / write interface definitions
+ * @param buff buffer that stores data read
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_temperature_raw_get(stts751_ctx_t *ctx, int16_t *buff)
+{
+ uint16_t temperature;
+ uint8_t temperature_low;
+ int32_t ret;
+
+ ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_HIGH,
+ (uint8_t*)&temperature, 1);
+ if (ret == 0) {
+ ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_LOW,
+ &temperature_low, 1);
+
+ temperature = (temperature << 8) + temperature_low;
+ *buff = (int16_t)temperature;
+ }
+ return ret;
+}
+
+/**
+ * @}
+ *
+ */
+
+/**
+ * @defgroup STTS751_Interrupt_Pins
+ * @brief This section groups all the functions that manage event pin
+ * @{
+ *
+ */
+
+/**
+ * @brief Route interrupt signal threshold on event pad.[set]
+ *
+ * @param ctx read / write interface definitions
+ * @param val set mask1 bit in register CONFIGURATION.
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_pin_event_route_set(stts751_ctx_t *ctx, uint8_t val)
+{
+ stts751_configuration_t reg;
+ int32_t ret;
+
+ ret = stts751_read_reg(ctx, STTS751_CONFIGURATION,(uint8_t*)®, 1);
+ if (ret == 0) {
+ reg.mask1 = val;
+ ret = stts751_write_reg(ctx, STTS751_CONFIGURATION, (uint8_t*)®, 1);
+ }
+ return ret;
+}
+
+/**
+ * @brief Route interrupt signal threshold on event pad.[get]
+ *
+ * @param ctx read / write interface definitions
+ * @param val get mask1 bit in register CONFIGURATION.
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_pin_event_route_get(stts751_ctx_t *ctx, uint8_t *val)
+{
+ stts751_configuration_t reg;
+ int32_t ret;
+ ret = stts751_read_reg(ctx, STTS751_CONFIGURATION, (uint8_t*)®, 1);
+ *val = reg.mask1;
+ return ret;
+}
+
+/**
+ * @}
+ *
+ */
+
+/**
+ * @defgroup STTS751_Interrupt_on_threshold
+ * @brief This section groups all the functions that manage interrupt
+ * on threshold event
+ * @{
+ *
+ */
+
+/**
+ * @brief high temperature theshold.[set]
+ *
+ * @param ctx read / write interface definitions
+ * @param buff buffer that contains data to write
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_high_temperature_threshold_set(stts751_ctx_t *ctx,
+ int16_t buff)
+{
+ uint8_t *temperature_ptr;
+ int32_t ret;
+
+ temperature_ptr = (uint8_t*)&buff;
+ ret = stts751_write_reg(ctx, STTS751_TEMPERATURE_HIGH_LIMIT_LOW,
+ (uint8_t*)temperature_ptr, 1);
+
+ if (ret == 0) {
+ temperature_ptr++;
+ ret = stts751_write_reg(ctx, STTS751_TEMPERATURE_HIGH_LIMIT_HIGH,
+ (uint8_t*)temperature_ptr, 1);
+ }
+
+ return ret;
+}
+
+/**
+ * @brief high temperature theshold.[get]
+ *
+ * @param ctx read / write interface definitions
+ * @param buff buffer that stores data read
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_high_temperature_threshold_get(stts751_ctx_t *ctx,
+ int16_t *buff)
+{
+ uint16_t temperature;
+ uint8_t temperature_low;
+ int32_t ret;
+
+ ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_HIGH_LIMIT_HIGH,
+ (uint8_t*)&temperature, 1);
+ if (ret == 0) {
+ ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_HIGH_LIMIT_LOW,
+ &temperature_low, 1);
+
+ temperature = (temperature << 8) + temperature_low;
+ *buff = (int16_t)temperature;
+ }
+ return ret;
+}
+
+/**
+ * @brief low temperature theshold.[set]
+ *
+ * @param ctx read / write interface definitions
+ * @param buff buffer that contains data to write
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_low_temperature_threshold_set(stts751_ctx_t *ctx,
+ int16_t buff)
+{
+
+ uint8_t *temperature_ptr;
+ int32_t ret;
+
+ temperature_ptr = (uint8_t*)&buff;
+ ret = stts751_write_reg(ctx, STTS751_TEMPERATURE_LOW_LIMIT_LOW,
+ (uint8_t*)temperature_ptr, 1);
+
+ if (ret == 0) {
+ temperature_ptr++;
+ ret = stts751_write_reg(ctx, STTS751_TEMPERATURE_LOW_LIMIT_HIGH,
+ (uint8_t*)temperature_ptr, 1);
+ }
+
+ return ret;
+}
+
+/**
+ * @brief low temperature theshold.[get]
+ *
+ * @param ctx read / write interface definitions
+ * @param buff buffer that stores data read
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_low_temperature_threshold_get(stts751_ctx_t *ctx,
+ int16_t *buff)
+{
+ uint16_t temperature;
+ uint8_t temperature_low;
+ int32_t ret;
+
+ ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_LOW_LIMIT_HIGH,
+ (uint8_t*)&temperature, 1);
+ if (ret == 0) {
+ ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_LOW_LIMIT_LOW,
+ &temperature_low, 1);
+
+ temperature = (temperature << 8) + temperature_low;
+ *buff = (int16_t)temperature;
+ }
+
+ return ret;
+}
+
+/**
+ * @}
+ *
+ */
+
+
+ /**
+ * @defgroup STTS751 over temperature alarm
+ * @brief This section groups all the functions that manage
+ * over temperature alarm functionality.
+ * @{
+ *
+ */
+
+/**
+ * @brief Thermal Limit. 1 LSB = 1 degC (max 127 degC min -127 degC ).[set]
+ *
+ * @param ctx read / write interface definitions
+ * @param val change the values of reg THERM_LIMIT
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_ota_thermal_limit_set(stts751_ctx_t *ctx, int8_t val)
+{
+ int32_t ret;
+ ret = stts751_write_reg(ctx, STTS751_THERM_LIMIT, (uint8_t*)&val, 1);
+ return ret;
+}
+
+/**
+ * @brief Thermal Limit. 1 LSB = 1 degC (max 127 degC min -127 degC ).[get]
+ *
+ * @param ctx read / write interface definitions
+ * @param val get the values of reg THERM_LIMIT
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_ota_thermal_limit_get(stts751_ctx_t *ctx, int8_t *val)
+{
+ int32_t ret;
+
+ ret = stts751_read_reg(ctx, STTS751_THERM_LIMIT, (uint8_t*)val, 1);
+ return ret;
+}
+
+/**
+ * @brief Thermal hysteresis. 1 LSB = 1 degC.[set]
+ * max 127 degC min -127 degC.
+ *
+ * @param ctx read / write interface definitions
+ * @param val change the values of reg THERM_HYSTERESIS
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_ota_thermal_hyst_set(stts751_ctx_t *ctx, int8_t val)
+{
+ int32_t ret;
+
+ ret = stts751_write_reg(ctx, STTS751_THERM_HYSTERESIS, (uint8_t*)&val, 1);
+ return ret;
+}
+
+/**
+ * @brief Thermal hysteresis. 1 LSB = 1 degC.[get]
+ * max 127 degC min -127 degC.
+ *
+ * @param ctx read / write interface definitions
+ * @param val get the values of reg THERM_HYSTERESIS
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_ota_thermal_hyst_get(stts751_ctx_t *ctx, int8_t *val)
+{
+ int32_t ret;
+
+ ret = stts751_read_reg(ctx, STTS751_THERM_HYSTERESIS, (uint8_t*)val, 1);
+ return ret;
+}
+
+/**
+ * @}
+ *
+ */
+
+/**
+ * @defgroup STTS751_Common
+ * @brief This section groups common useful functions.
+ * @{
+ *
+ */
+
+/**
+ * @brief SMBus timeout.At power-up, the STTS751 is configured with an
+ * SMBus timeout of 25 to 35 milliseconds.[set]
+ *
+ * @param ctx read / write interface definitions
+ * @param val set timeout bit in register SMBUS_TIMEOUT.
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_smbus_timeout_set(stts751_ctx_t *ctx, uint8_t val)
+{
+ stts751_smbus_timeout_t reg;
+ int32_t ret;
+
+ ret = stts751_read_reg(ctx, STTS751_SMBUS_TIMEOUT,(uint8_t*)®, 1);
+ if (ret == 0) {
+ reg.timeout = val;
+ ret = stts751_write_reg(ctx, STTS751_SMBUS_TIMEOUT, (uint8_t*)®, 1);
+ }
+ return ret;
+}
+
+/**
+ * @brief SMBus timeout.At power-up, the STTS751 is configured with an
+ * SMBus timeout of 25 to 35 milliseconds.[get]
+ *
+ * @param ctx read / write interface definitions
+ * @param val get timeout bit in register SMBUS_TIMEOUT.
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_smbus_timeout_get(stts751_ctx_t *ctx, uint8_t *val)
+{
+ stts751_smbus_timeout_t reg;
+ int32_t ret;
+ ret = stts751_read_reg(ctx, STTS751_SMBUS_TIMEOUT, (uint8_t*)®, 1);
+ *val = reg.timeout;
+ return ret;
+}
+
+/**
+ * @brief Device Who am I.[get]
+ *
+ * @param ctx read / write interface definitions
+ * @param buff buffer that stores data read
+ * @retval interface status (MANDATORY: return 0 -> no Error)
+ *
+ */
+int32_t stts751_device_id_get(stts751_ctx_t *ctx, stts751_id_t *buff)
+{
+ int32_t ret;
+ ret = stts751_read_reg(ctx, STTS751_PRODUCT_ID,
+ (uint8_t*)&buff->product_id, 1);
+ if (ret == 0){
+ ret = stts751_read_reg(ctx, STTS751_MANUFACTURER_ID,
+ (uint8_t*)&buff->manufacturer_id, 1);
+ }
+ if (ret == 0){
+ ret = stts751_read_reg(ctx, STTS751_REVISION_ID,
+ (uint8_t*)&buff->revision_id, 1);
+ }
+ return ret;
+}
+
+/**
+ * @}
+ *
+ */
+
+/**
+ * @}
+ *
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/stts751_reg.h Wed Mar 06 10:18:41 2019 +0000
@@ -0,0 +1,325 @@
+/*
+ ******************************************************************************
+ * @file stts751_reg.h
+ * @author Sensors Software Solution Team
+ * @brief This file contains all the functions prototypes for the
+ * stts751_reg.c driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2018 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef STTS751_REGS_H
+#define STTS751_REGS_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include <stdint.h>
+#include <math.h>
+
+/** @addtogroup STTS751
+ * @{
+ *
+ */
+
+/** @defgroup STTS751_sensors_common_types
+ * @{
+ *
+ */
+
+#ifndef MEMS_SHARED_TYPES
+#define MEMS_SHARED_TYPES
+
+/**
+ * @defgroup axisXbitXX_t
+ * @brief These unions are useful to represent different sensors data type.
+ * These unions are not need by the driver.
+ *
+ * REMOVING the unions you are compliant with:
+ * MISRA-C 2012 [Rule 19.2] -> " Union are not allowed "
+ *
+ * @{
+ *
+ */
+
+typedef union{
+ int16_t i16bit[3];
+ uint8_t u8bit[6];
+} axis3bit16_t;
+
+typedef union{
+ int16_t i16bit;
+ uint8_t u8bit[2];
+} axis1bit16_t;
+
+typedef union{
+ int32_t i32bit[3];
+ uint8_t u8bit[12];
+} axis3bit32_t;
+
+typedef union{
+ int32_t i32bit;
+ uint8_t u8bit[4];
+} axis1bit32_t;
+
+/**
+ * @}
+ *
+ */
+
+typedef struct{
+ uint8_t bit0 : 1;
+ uint8_t bit1 : 1;
+ uint8_t bit2 : 1;
+ uint8_t bit3 : 1;
+ uint8_t bit4 : 1;
+ uint8_t bit5 : 1;
+ uint8_t bit6 : 1;
+ uint8_t bit7 : 1;
+} bitwise_t;
+
+#define PROPERTY_DISABLE (0U)
+#define PROPERTY_ENABLE (1U)
+
+#endif /* MEMS_SHARED_TYPES */
+
+/**
+ * @}
+ *
+ */
+
+/** @addtogroup STTS751_Interfaces_Functions
+ * @brief This section provide a set of functions used to read and
+ * write a generic register of the device.
+ * MANDATORY: return 0 -> no Error.
+ * @{
+ *
+ */
+
+typedef int32_t (*stts751_write_ptr)(void *, uint8_t, uint8_t*, uint16_t);
+typedef int32_t (*stts751_read_ptr) (void *, uint8_t, uint8_t*, uint16_t);
+
+typedef struct {
+ /** Component mandatory fields **/
+ stts751_write_ptr write_reg;
+ stts751_read_ptr read_reg;
+ /** Customizable optional pointer **/
+ void *handle;
+} stts751_ctx_t;
+
+/**
+ * @}
+ *
+ */
+
+/** @defgroup STTS751_Infos
+ * @{
+ *
+ */
+
+/** I2C Device Address 8 bit format **/
+#define STTS751_0xxxx_ADD_7K5 0x91U
+#define STTS751_0xxxx_ADD_12K 0x93U
+#define STTS751_0xxxx_ADD_20K 0x71U
+#define STTS751_0xxxx_ADD_33K 0x73U
+
+#define STTS751_1xxxx_ADD_7K5 0x95U
+#define STTS751_1xxxx_ADD_12K 0x97U
+#define STTS751_1xxxx_ADD_20K 0x75U
+#define STTS751_1xxxx_ADD_33K 0x77U
+
+/** Device Identification **/
+/* Product ID */
+#define STTS751_ID_0xxxx 0x00U
+#define STTS751_ID_1xxxx 0x01U
+/* Manufacturer ID */
+#define STTS751_ID_MAN 0x53U
+/* Revision number */
+#define STTS751_REV 0x01U
+
+/**
+ * @}
+ *
+ */
+
+#define STTS751_TEMPERATURE_HIGH 0x00U
+#define STTS751_STATUS 0x01U
+typedef struct {
+ uint8_t thrm : 1;
+ uint8_t not_used_01 : 4;
+ uint8_t t_low : 1;
+ uint8_t t_high : 1;
+ uint8_t busy : 1;
+} stts751_status_t;
+
+#define STTS751_TEMPERATURE_LOW 0x02U
+#define STTS751_CONFIGURATION 0x03U
+typedef struct {
+ uint8_t not_used_01 : 2;
+ uint8_t tres : 2;
+ uint8_t not_used_02 : 2;
+ uint8_t stop : 1;
+ uint8_t mask1 : 1;
+} stts751_configuration_t;
+
+#define STTS751_CONVERSION_RATE 0x04U
+typedef struct {
+ uint8_t conv : 4;
+ uint8_t not_used_01 : 4;
+} stts751_conversion_rate_t;
+
+#define STTS751_TEMPERATURE_HIGH_LIMIT_HIGH 0x05U
+#define STTS751_TEMPERATURE_HIGH_LIMIT_LOW 0x06U
+#define STTS751_TEMPERATURE_LOW_LIMIT_HIGH 0x07U
+#define STTS751_TEMPERATURE_LOW_LIMIT_LOW 0x08U
+#define STTS751_ONE_SHOT 0x0FU
+#define STTS751_THERM_LIMIT 0x20U
+#define STTS751_THERM_HYSTERESIS 0x21U
+#define STTS751_SMBUS_TIMEOUT 0x22U
+typedef struct {
+ uint8_t not_used_01 : 7;
+ uint8_t timeout : 1;
+} stts751_smbus_timeout_t;
+
+#define STTS751_PRODUCT_ID 0xFDU
+#define STTS751_MANUFACTURER_ID 0xFEU
+#define STTS751_REVISION_ID 0xFFU
+
+/**
+ * @defgroup STTS751_Register_Union
+ * @brief This union group all the registers that has a bitfield
+ * description.
+ * This union is useful but not need by the driver.
+ *
+ * REMOVING this union you are compliant with:
+ * MISRA-C 2012 [Rule 19.2] -> " Union are not allowed "
+ *
+ * @{
+ *
+ */
+typedef union{
+ stts751_status_t status;
+ stts751_configuration_t configuration;
+ stts751_conversion_rate_t conversion_rate;
+ stts751_smbus_timeout_t smbus_timeout;
+ bitwise_t bitwise;
+ uint8_t byte;
+} stts751_reg_t;
+
+/**
+ * @}
+ *
+ */
+
+int32_t stts751_read_reg(stts751_ctx_t *ctx, uint8_t reg, uint8_t* data,
+ uint16_t len);
+int32_t stts751_write_reg(stts751_ctx_t *ctx, uint8_t reg, uint8_t* data,
+ uint16_t len);
+
+extern float stts751_from_lsb_to_celsius(int16_t lsb);
+extern int16_t stts751_from_celsius_to_lsb(float celsius);
+
+typedef enum {
+ STTS751_TEMP_ODR_OFF = 0x80,
+ STTS751_TEMP_ODR_ONE_SHOT = 0x90,
+ STTS751_TEMP_ODR_62mHz5 = 0x00,
+ STTS751_TEMP_ODR_125mHz = 0x01,
+ STTS751_TEMP_ODR_250mHz = 0x02,
+ STTS751_TEMP_ODR_500mHz = 0x03,
+ STTS751_TEMP_ODR_1Hz = 0x04,
+ STTS751_TEMP_ODR_2Hz = 0x05,
+ STTS751_TEMP_ODR_4Hz = 0x06,
+ STTS751_TEMP_ODR_8Hz = 0x07,
+ STTS751_TEMP_ODR_16Hz = 0x08, /* 9, 10, or 11-bit resolutions only */
+ STTS751_TEMP_ODR_32Hz = 0x09, /* 9 or 10-bit resolutions only */
+} stts751_odr_t;
+int32_t stts751_temp_data_rate_set(stts751_ctx_t *ctx, stts751_odr_t val);
+int32_t stts751_temp_data_rate_get(stts751_ctx_t *ctx, stts751_odr_t *val);
+
+typedef enum {
+ STTS751_9bit = 2,
+ STTS751_10bit = 0,
+ STTS751_11bit = 1,
+ STTS751_12bit = 3,
+} stts751_tres_t;
+int32_t stts751_resolution_set(stts751_ctx_t *ctx, stts751_tres_t val);
+int32_t stts751_resolution_get(stts751_ctx_t *ctx, stts751_tres_t *val);
+
+int32_t stts751_status_reg_get(stts751_ctx_t *ctx, stts751_status_t *val);
+
+int32_t stts751_flag_busy_get(stts751_ctx_t *ctx, uint8_t *val);
+
+int32_t stts751_temperature_raw_get(stts751_ctx_t *ctx, int16_t *buff);
+
+int32_t stts751_pin_event_route_set(stts751_ctx_t *ctx, uint8_t val);
+int32_t stts751_pin_event_route_get(stts751_ctx_t *ctx, uint8_t *val);
+
+
+int32_t stts751_high_temperature_threshold_set(stts751_ctx_t *ctx,
+ int16_t buff);
+int32_t stts751_high_temperature_threshold_get(stts751_ctx_t *ctx,
+ int16_t *buff);
+
+int32_t stts751_low_temperature_threshold_set(stts751_ctx_t *ctx,
+ int16_t buff);
+int32_t stts751_low_temperature_threshold_get(stts751_ctx_t *ctx,
+ int16_t *buff);
+
+int32_t stts751_ota_thermal_limit_set(stts751_ctx_t *ctx, int8_t val);
+int32_t stts751_ota_thermal_limit_get(stts751_ctx_t *ctx, int8_t *val);
+
+int32_t stts751_ota_thermal_hyst_set(stts751_ctx_t *ctx, int8_t val);
+int32_t stts751_ota_thermal_hyst_get(stts751_ctx_t *ctx, int8_t *val);
+
+int32_t stts751_smbus_timeout_set(stts751_ctx_t *ctx, uint8_t val);
+int32_t stts751_smbus_timeout_get(stts751_ctx_t *ctx, uint8_t *val);
+
+typedef struct {
+ uint8_t product_id;
+ uint8_t manufacturer_id;
+ uint8_t revision_id;
+} stts751_id_t;
+int32_t stts751_device_id_get(stts751_ctx_t *ctx, stts751_id_t *buff);
+
+/**
+ * @}
+ *
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*STTS751_REGS_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/