Low voltage digital temperature sensor
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: X_NUCLEO_IKS01A3 X_NUCLEO_IKS01A3 X_NUCLEO_IKS01A3
STTS751Sensor.h@2:2ea2e88ce467, 2020-05-05 (annotated)
- Committer:
- cparata
- Date:
- Tue May 05 13:50:14 2020 +0000
- Revision:
- 2:2ea2e88ce467
- Parent:
- 1:5859badee052
Fix bug get_temp_limit_status
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cparata | 0:128dae13c732 | 1 | /** |
cparata | 0:128dae13c732 | 2 | ****************************************************************************** |
cparata | 0:128dae13c732 | 3 | * @file STTS751Sensor.h |
cparata | 0:128dae13c732 | 4 | * @author SRA |
cparata | 0:128dae13c732 | 5 | * @version V1.0.0 |
cparata | 0:128dae13c732 | 6 | * @date February 2018 |
cparata | 0:128dae13c732 | 7 | * @brief Abstract Class of a STTS751 temperature sensor. |
cparata | 0:128dae13c732 | 8 | ****************************************************************************** |
cparata | 0:128dae13c732 | 9 | * @attention |
cparata | 0:128dae13c732 | 10 | * |
cparata | 0:128dae13c732 | 11 | * <h2><center>© COPYRIGHT(c) 2019 STMicroelectronics</center></h2> |
cparata | 0:128dae13c732 | 12 | * |
cparata | 0:128dae13c732 | 13 | * Redistribution and use in source and binary forms, with or without modification, |
cparata | 0:128dae13c732 | 14 | * are permitted provided that the following conditions are met: |
cparata | 0:128dae13c732 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
cparata | 0:128dae13c732 | 16 | * this list of conditions and the following disclaimer. |
cparata | 0:128dae13c732 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
cparata | 0:128dae13c732 | 18 | * this list of conditions and the following disclaimer in the documentation |
cparata | 0:128dae13c732 | 19 | * and/or other materials provided with the distribution. |
cparata | 0:128dae13c732 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
cparata | 0:128dae13c732 | 21 | * may be used to endorse or promote products derived from this software |
cparata | 0:128dae13c732 | 22 | * without specific prior written permission. |
cparata | 0:128dae13c732 | 23 | * |
cparata | 0:128dae13c732 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
cparata | 0:128dae13c732 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
cparata | 0:128dae13c732 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
cparata | 0:128dae13c732 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
cparata | 0:128dae13c732 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
cparata | 0:128dae13c732 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
cparata | 0:128dae13c732 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
cparata | 0:128dae13c732 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
cparata | 0:128dae13c732 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
cparata | 0:128dae13c732 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
cparata | 0:128dae13c732 | 34 | * |
cparata | 0:128dae13c732 | 35 | ****************************************************************************** |
cparata | 0:128dae13c732 | 36 | */ |
cparata | 0:128dae13c732 | 37 | |
cparata | 0:128dae13c732 | 38 | |
cparata | 0:128dae13c732 | 39 | /* Prevent recursive inclusion -----------------------------------------------*/ |
cparata | 0:128dae13c732 | 40 | |
cparata | 0:128dae13c732 | 41 | #ifndef __STTS751Sensor_H__ |
cparata | 0:128dae13c732 | 42 | #define __STTS751Sensor_H__ |
cparata | 0:128dae13c732 | 43 | |
cparata | 0:128dae13c732 | 44 | |
cparata | 0:128dae13c732 | 45 | /* Includes ------------------------------------------------------------------*/ |
cparata | 0:128dae13c732 | 46 | |
cparata | 0:128dae13c732 | 47 | #include "DevI2C.h" |
cparata | 0:128dae13c732 | 48 | #include "stts751_reg.h" |
cparata | 0:128dae13c732 | 49 | #include "TempSensor.h" |
cparata | 0:128dae13c732 | 50 | #include <assert.h> |
cparata | 0:128dae13c732 | 51 | |
cparata | 0:128dae13c732 | 52 | /* Defines -------------------------------------------------------------------*/ |
cparata | 0:128dae13c732 | 53 | /* Typedefs ------------------------------------------------------------------*/ |
cparata | 0:128dae13c732 | 54 | /* Class Declaration ---------------------------------------------------------*/ |
cparata | 1:5859badee052 | 55 | |
cparata | 0:128dae13c732 | 56 | /** |
cparata | 0:128dae13c732 | 57 | * Abstract class of a STTS751 temperature sensor. |
cparata | 0:128dae13c732 | 58 | */ |
cparata | 1:5859badee052 | 59 | class STTS751Sensor : public TempSensor { |
cparata | 1:5859badee052 | 60 | public: |
cparata | 1:5859badee052 | 61 | |
cparata | 1:5859badee052 | 62 | STTS751Sensor(DevI2C *i2c, uint8_t address = STTS751_0xxxx_ADD_7K5, PinName int_pin = NC); |
cparata | 0:128dae13c732 | 63 | virtual int init(void *init); |
cparata | 0:128dae13c732 | 64 | virtual int read_id(uint8_t *id); |
cparata | 0:128dae13c732 | 65 | virtual int get_temperature(float *value); |
cparata | 0:128dae13c732 | 66 | int enable(void); |
cparata | 0:128dae13c732 | 67 | int disable(void); |
cparata | 0:128dae13c732 | 68 | int get_odr(float *odr); |
cparata | 0:128dae13c732 | 69 | int set_odr(float odr); |
cparata | 0:128dae13c732 | 70 | int read_reg(uint8_t reg, uint8_t *data); |
cparata | 0:128dae13c732 | 71 | int write_reg(uint8_t reg, uint8_t data); |
cparata | 0:128dae13c732 | 72 | int get_temp_drdy_status(uint8_t *status); |
cparata | 0:128dae13c732 | 73 | int set_low_temp_thr(float value); |
cparata | 0:128dae13c732 | 74 | int set_high_temp_thr(float value); |
cparata | 0:128dae13c732 | 75 | int get_temp_limit_status(uint8_t *high_limit, uint8_t *low_limit, uint8_t *therm_limit); |
cparata | 0:128dae13c732 | 76 | int set_event_pin(uint8_t enable); |
cparata | 0:128dae13c732 | 77 | int set_one_shot(); |
cparata | 0:128dae13c732 | 78 | int get_one_shot_status(uint8_t *status); |
cparata | 0:128dae13c732 | 79 | |
cparata | 0:128dae13c732 | 80 | /** |
cparata | 0:128dae13c732 | 81 | * @brief Attaching an interrupt handler to the INT interrupt. |
cparata | 0:128dae13c732 | 82 | * @param fptr an interrupt handler. |
cparata | 0:128dae13c732 | 83 | * @retval None. |
cparata | 0:128dae13c732 | 84 | */ |
cparata | 0:128dae13c732 | 85 | void attach_int_irq(void (*fptr)(void)) |
cparata | 0:128dae13c732 | 86 | { |
cparata | 0:128dae13c732 | 87 | _int_irq.fall(fptr); |
cparata | 0:128dae13c732 | 88 | } |
cparata | 0:128dae13c732 | 89 | |
cparata | 0:128dae13c732 | 90 | /** |
cparata | 0:128dae13c732 | 91 | * @brief Enabling the INT interrupt handling. |
cparata | 0:128dae13c732 | 92 | * @param None. |
cparata | 0:128dae13c732 | 93 | * @retval None. |
cparata | 0:128dae13c732 | 94 | */ |
cparata | 0:128dae13c732 | 95 | void enable_int_irq(void) |
cparata | 0:128dae13c732 | 96 | { |
cparata | 0:128dae13c732 | 97 | _int_irq.enable_irq(); |
cparata | 0:128dae13c732 | 98 | } |
cparata | 1:5859badee052 | 99 | |
cparata | 0:128dae13c732 | 100 | /** |
cparata | 0:128dae13c732 | 101 | * @brief Disabling the INT interrupt handling. |
cparata | 0:128dae13c732 | 102 | * @param None. |
cparata | 0:128dae13c732 | 103 | * @retval None. |
cparata | 0:128dae13c732 | 104 | */ |
cparata | 0:128dae13c732 | 105 | void disable_int_irq(void) |
cparata | 0:128dae13c732 | 106 | { |
cparata | 0:128dae13c732 | 107 | _int_irq.disable_irq(); |
cparata | 0:128dae13c732 | 108 | } |
cparata | 0:128dae13c732 | 109 | |
cparata | 0:128dae13c732 | 110 | |
cparata | 0:128dae13c732 | 111 | /** |
cparata | 0:128dae13c732 | 112 | * @brief Utility function to read data. |
cparata | 0:128dae13c732 | 113 | * @param pBuffer: pointer to data to be read. |
cparata | 0:128dae13c732 | 114 | * @param RegisterAddr: specifies internal address register to be read. |
cparata | 0:128dae13c732 | 115 | * @param NumByteToRead: number of bytes to be read. |
cparata | 0:128dae13c732 | 116 | * @retval 0 if ok, an error code otherwise. |
cparata | 0:128dae13c732 | 117 | */ |
cparata | 1:5859badee052 | 118 | uint8_t io_read(uint8_t *pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) |
cparata | 1:5859badee052 | 119 | { |
cparata | 1:5859badee052 | 120 | if (_dev_i2c) { |
cparata | 1:5859badee052 | 121 | return (uint8_t) _dev_i2c->i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead); |
cparata | 1:5859badee052 | 122 | } |
cparata | 0:128dae13c732 | 123 | return 1; |
cparata | 0:128dae13c732 | 124 | } |
cparata | 1:5859badee052 | 125 | |
cparata | 0:128dae13c732 | 126 | /** |
cparata | 0:128dae13c732 | 127 | * @brief Utility function to write data. |
cparata | 0:128dae13c732 | 128 | * @param pBuffer: pointer to data to be written. |
cparata | 0:128dae13c732 | 129 | * @param RegisterAddr: specifies internal address register to be written. |
cparata | 0:128dae13c732 | 130 | * @param NumByteToWrite: number of bytes to write. |
cparata | 0:128dae13c732 | 131 | * @retval 0 if ok, an error code otherwise. |
cparata | 0:128dae13c732 | 132 | */ |
cparata | 1:5859badee052 | 133 | uint8_t io_write(uint8_t *pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) |
cparata | 0:128dae13c732 | 134 | { |
cparata | 1:5859badee052 | 135 | if (_dev_i2c) { |
cparata | 1:5859badee052 | 136 | return (uint8_t) _dev_i2c->i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite); |
cparata | 1:5859badee052 | 137 | } |
cparata | 0:128dae13c732 | 138 | return 1; |
cparata | 0:128dae13c732 | 139 | } |
cparata | 0:128dae13c732 | 140 | |
cparata | 1:5859badee052 | 141 | private: |
cparata | 0:128dae13c732 | 142 | |
cparata | 0:128dae13c732 | 143 | /* Helper classes. */ |
cparata | 0:128dae13c732 | 144 | DevI2C *_dev_i2c; |
cparata | 1:5859badee052 | 145 | |
cparata | 0:128dae13c732 | 146 | /* Configuration */ |
cparata | 0:128dae13c732 | 147 | uint8_t _address; |
cparata | 1:5859badee052 | 148 | InterruptIn _int_irq; |
cparata | 1:5859badee052 | 149 | |
cparata | 0:128dae13c732 | 150 | uint8_t _is_enabled; |
cparata | 0:128dae13c732 | 151 | float _last_odr; |
cparata | 1:5859badee052 | 152 | |
cparata | 0:128dae13c732 | 153 | stts751_ctx_t _reg_ctx; |
cparata | 0:128dae13c732 | 154 | }; |
cparata | 0:128dae13c732 | 155 | |
cparata | 0:128dae13c732 | 156 | #ifdef __cplusplus |
cparata | 1:5859badee052 | 157 | extern "C" { |
cparata | 0:128dae13c732 | 158 | #endif |
cparata | 1:5859badee052 | 159 | int32_t STTS751_io_write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite); |
cparata | 1:5859badee052 | 160 | int32_t STTS751_io_read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead); |
cparata | 0:128dae13c732 | 161 | #ifdef __cplusplus |
cparata | 1:5859badee052 | 162 | } |
cparata | 0:128dae13c732 | 163 | #endif |
cparata | 0:128dae13c732 | 164 | |
cparata | 0:128dae13c732 | 165 | #endif |