Low voltage digital temperature sensor
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: X_NUCLEO_IKS01A3 X_NUCLEO_IKS01A3 X_NUCLEO_IKS01A3
STTS751Sensor.h
00001 /** 00002 ****************************************************************************** 00003 * @file STTS751Sensor.h 00004 * @author SRA 00005 * @version V1.0.0 00006 * @date February 2018 00007 * @brief Abstract Class of a STTS751 temperature sensor. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2019 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 00039 /* Prevent recursive inclusion -----------------------------------------------*/ 00040 00041 #ifndef __STTS751Sensor_H__ 00042 #define __STTS751Sensor_H__ 00043 00044 00045 /* Includes ------------------------------------------------------------------*/ 00046 00047 #include "DevI2C.h" 00048 #include "stts751_reg.h" 00049 #include "TempSensor.h" 00050 #include <assert.h> 00051 00052 /* Defines -------------------------------------------------------------------*/ 00053 /* Typedefs ------------------------------------------------------------------*/ 00054 /* Class Declaration ---------------------------------------------------------*/ 00055 00056 /** 00057 * Abstract class of a STTS751 temperature sensor. 00058 */ 00059 class STTS751Sensor : public TempSensor { 00060 public: 00061 00062 STTS751Sensor(DevI2C *i2c, uint8_t address = STTS751_0xxxx_ADD_7K5, PinName int_pin = NC); 00063 virtual int init(void *init); 00064 virtual int read_id(uint8_t *id); 00065 virtual int get_temperature(float *value); 00066 int enable(void); 00067 int disable(void); 00068 int get_odr(float *odr); 00069 int set_odr(float odr); 00070 int read_reg(uint8_t reg, uint8_t *data); 00071 int write_reg(uint8_t reg, uint8_t data); 00072 int get_temp_drdy_status(uint8_t *status); 00073 int set_low_temp_thr(float value); 00074 int set_high_temp_thr(float value); 00075 int get_temp_limit_status(uint8_t *high_limit, uint8_t *low_limit, uint8_t *therm_limit); 00076 int set_event_pin(uint8_t enable); 00077 int set_one_shot(); 00078 int get_one_shot_status(uint8_t *status); 00079 00080 /** 00081 * @brief Attaching an interrupt handler to the INT interrupt. 00082 * @param fptr an interrupt handler. 00083 * @retval None. 00084 */ 00085 void attach_int_irq(void (*fptr)(void)) 00086 { 00087 _int_irq.fall(fptr); 00088 } 00089 00090 /** 00091 * @brief Enabling the INT interrupt handling. 00092 * @param None. 00093 * @retval None. 00094 */ 00095 void enable_int_irq(void) 00096 { 00097 _int_irq.enable_irq(); 00098 } 00099 00100 /** 00101 * @brief Disabling the INT interrupt handling. 00102 * @param None. 00103 * @retval None. 00104 */ 00105 void disable_int_irq(void) 00106 { 00107 _int_irq.disable_irq(); 00108 } 00109 00110 00111 /** 00112 * @brief Utility function to read data. 00113 * @param pBuffer: pointer to data to be read. 00114 * @param RegisterAddr: specifies internal address register to be read. 00115 * @param NumByteToRead: number of bytes to be read. 00116 * @retval 0 if ok, an error code otherwise. 00117 */ 00118 uint8_t io_read(uint8_t *pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) 00119 { 00120 if (_dev_i2c) { 00121 return (uint8_t) _dev_i2c->i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead); 00122 } 00123 return 1; 00124 } 00125 00126 /** 00127 * @brief Utility function to write data. 00128 * @param pBuffer: pointer to data to be written. 00129 * @param RegisterAddr: specifies internal address register to be written. 00130 * @param NumByteToWrite: number of bytes to write. 00131 * @retval 0 if ok, an error code otherwise. 00132 */ 00133 uint8_t io_write(uint8_t *pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) 00134 { 00135 if (_dev_i2c) { 00136 return (uint8_t) _dev_i2c->i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite); 00137 } 00138 return 1; 00139 } 00140 00141 private: 00142 00143 /* Helper classes. */ 00144 DevI2C *_dev_i2c; 00145 00146 /* Configuration */ 00147 uint8_t _address; 00148 InterruptIn _int_irq; 00149 00150 uint8_t _is_enabled; 00151 float _last_odr; 00152 00153 stts751_ctx_t _reg_ctx; 00154 }; 00155 00156 #ifdef __cplusplus 00157 extern "C" { 00158 #endif 00159 int32_t STTS751_io_write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite); 00160 int32_t STTS751_io_read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead); 00161 #ifdef __cplusplus 00162 } 00163 #endif 00164 00165 #endif
Generated on Fri Jul 15 2022 18:33:31 by 1.7.2