Low voltage digital temperature sensor
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: X_NUCLEO_IKS01A3 X_NUCLEO_IKS01A3 X_NUCLEO_IKS01A3
stts751_reg.c@0:128dae13c732, 2019-03-06 (annotated)
- Committer:
- cparata
- Date:
- Wed Mar 06 10:18:41 2019 +0000
- Revision:
- 0:128dae13c732
- Child:
- 1:5859badee052
First version of STTS751 library
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 stts751_reg.c |
cparata | 0:128dae13c732 | 4 | * @author Sensors Software Solution Team |
cparata | 0:128dae13c732 | 5 | * @brief STTS751 driver file |
cparata | 0:128dae13c732 | 6 | ****************************************************************************** |
cparata | 0:128dae13c732 | 7 | * @attention |
cparata | 0:128dae13c732 | 8 | * |
cparata | 0:128dae13c732 | 9 | * <h2><center>© COPYRIGHT(c) 2018 STMicroelectronics</center></h2> |
cparata | 0:128dae13c732 | 10 | * |
cparata | 0:128dae13c732 | 11 | * Redistribution and use in source and binary forms, with or without |
cparata | 0:128dae13c732 | 12 | * modification, are permitted provided that the following conditions |
cparata | 0:128dae13c732 | 13 | * are met: |
cparata | 0:128dae13c732 | 14 | * 1. Redistributions of source code must retain the above copyright notice, |
cparata | 0:128dae13c732 | 15 | * this list of conditions and the following disclaimer. |
cparata | 0:128dae13c732 | 16 | * 2. Redistributions in binary form must reproduce the above copyright |
cparata | 0:128dae13c732 | 17 | * notice, this list of conditions and the following disclaimer in the |
cparata | 0:128dae13c732 | 18 | * documentation and/or other materials provided with the distribution. |
cparata | 0:128dae13c732 | 19 | * 3. Neither the name of STMicroelectronics nor the names of its |
cparata | 0:128dae13c732 | 20 | * contributors may be used to endorse or promote products derived from |
cparata | 0:128dae13c732 | 21 | * this software without specific prior written permission. |
cparata | 0:128dae13c732 | 22 | * |
cparata | 0:128dae13c732 | 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
cparata | 0:128dae13c732 | 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
cparata | 0:128dae13c732 | 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
cparata | 0:128dae13c732 | 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
cparata | 0:128dae13c732 | 27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
cparata | 0:128dae13c732 | 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
cparata | 0:128dae13c732 | 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
cparata | 0:128dae13c732 | 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
cparata | 0:128dae13c732 | 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
cparata | 0:128dae13c732 | 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
cparata | 0:128dae13c732 | 33 | * POSSIBILITY OF SUCH DAMAGE. |
cparata | 0:128dae13c732 | 34 | * |
cparata | 0:128dae13c732 | 35 | */ |
cparata | 0:128dae13c732 | 36 | |
cparata | 0:128dae13c732 | 37 | #include "stts751_reg.h" |
cparata | 0:128dae13c732 | 38 | |
cparata | 0:128dae13c732 | 39 | /** |
cparata | 0:128dae13c732 | 40 | * @defgroup STTS751 |
cparata | 0:128dae13c732 | 41 | * @brief This file provides a set of functions needed to drive the |
cparata | 0:128dae13c732 | 42 | * stts751 enhanced inertial module. |
cparata | 0:128dae13c732 | 43 | * @{ |
cparata | 0:128dae13c732 | 44 | * |
cparata | 0:128dae13c732 | 45 | */ |
cparata | 0:128dae13c732 | 46 | |
cparata | 0:128dae13c732 | 47 | /** |
cparata | 0:128dae13c732 | 48 | * @defgroup STTS751_Interfaces_Functions |
cparata | 0:128dae13c732 | 49 | * @brief This section provide a set of functions used to read and |
cparata | 0:128dae13c732 | 50 | * write a generic register of the device. |
cparata | 0:128dae13c732 | 51 | * MANDATORY: return 0 -> no Error. |
cparata | 0:128dae13c732 | 52 | * @{ |
cparata | 0:128dae13c732 | 53 | * |
cparata | 0:128dae13c732 | 54 | */ |
cparata | 0:128dae13c732 | 55 | |
cparata | 0:128dae13c732 | 56 | /** |
cparata | 0:128dae13c732 | 57 | * @brief Read generic device register |
cparata | 0:128dae13c732 | 58 | * |
cparata | 0:128dae13c732 | 59 | * @param ctx read / write interface definitions(ptr) |
cparata | 0:128dae13c732 | 60 | * @param reg register to read |
cparata | 0:128dae13c732 | 61 | * @param data pointer to buffer that store the data read(ptr) |
cparata | 0:128dae13c732 | 62 | * @param len number of consecutive register to read |
cparata | 0:128dae13c732 | 63 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 64 | * |
cparata | 0:128dae13c732 | 65 | */ |
cparata | 0:128dae13c732 | 66 | int32_t stts751_read_reg(stts751_ctx_t* ctx, uint8_t reg, uint8_t* data, |
cparata | 0:128dae13c732 | 67 | uint16_t len) |
cparata | 0:128dae13c732 | 68 | { |
cparata | 0:128dae13c732 | 69 | int32_t ret; |
cparata | 0:128dae13c732 | 70 | ret = ctx->read_reg(ctx->handle, reg, data, len); |
cparata | 0:128dae13c732 | 71 | return ret; |
cparata | 0:128dae13c732 | 72 | } |
cparata | 0:128dae13c732 | 73 | |
cparata | 0:128dae13c732 | 74 | /** |
cparata | 0:128dae13c732 | 75 | * @brief Write generic device register |
cparata | 0:128dae13c732 | 76 | * |
cparata | 0:128dae13c732 | 77 | * @param ctx read / write interface definitions(ptr) |
cparata | 0:128dae13c732 | 78 | * @param reg register to write |
cparata | 0:128dae13c732 | 79 | * @param data pointer to data to write in register reg(ptr) |
cparata | 0:128dae13c732 | 80 | * @param len number of consecutive register to write |
cparata | 0:128dae13c732 | 81 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 82 | * |
cparata | 0:128dae13c732 | 83 | */ |
cparata | 0:128dae13c732 | 84 | int32_t stts751_write_reg(stts751_ctx_t* ctx, uint8_t reg, uint8_t* data, |
cparata | 0:128dae13c732 | 85 | uint16_t len) |
cparata | 0:128dae13c732 | 86 | { |
cparata | 0:128dae13c732 | 87 | int32_t ret; |
cparata | 0:128dae13c732 | 88 | ret = ctx->write_reg(ctx->handle, reg, data, len); |
cparata | 0:128dae13c732 | 89 | return ret; |
cparata | 0:128dae13c732 | 90 | } |
cparata | 0:128dae13c732 | 91 | |
cparata | 0:128dae13c732 | 92 | /** |
cparata | 0:128dae13c732 | 93 | * @} |
cparata | 0:128dae13c732 | 94 | * |
cparata | 0:128dae13c732 | 95 | */ |
cparata | 0:128dae13c732 | 96 | |
cparata | 0:128dae13c732 | 97 | /** |
cparata | 0:128dae13c732 | 98 | * @defgroup STTS751_Sensitivity |
cparata | 0:128dae13c732 | 99 | * @brief These functions convert raw-data into engineering units and |
cparata | 0:128dae13c732 | 100 | * vice-versa . |
cparata | 0:128dae13c732 | 101 | * @{ |
cparata | 0:128dae13c732 | 102 | * |
cparata | 0:128dae13c732 | 103 | */ |
cparata | 0:128dae13c732 | 104 | |
cparata | 0:128dae13c732 | 105 | float stts751_from_lsb_to_celsius(int16_t lsb) |
cparata | 0:128dae13c732 | 106 | { |
cparata | 0:128dae13c732 | 107 | return ((float)lsb) / 256.0f; |
cparata | 0:128dae13c732 | 108 | } |
cparata | 0:128dae13c732 | 109 | |
cparata | 0:128dae13c732 | 110 | /** |
cparata | 0:128dae13c732 | 111 | * @} |
cparata | 0:128dae13c732 | 112 | * |
cparata | 0:128dae13c732 | 113 | */ |
cparata | 0:128dae13c732 | 114 | |
cparata | 0:128dae13c732 | 115 | /** |
cparata | 0:128dae13c732 | 116 | * @defgroup STTS751_Sensitivity_Reverse |
cparata | 0:128dae13c732 | 117 | * @brief This conversion is useful but not need by the driver. |
cparata | 0:128dae13c732 | 118 | * |
cparata | 0:128dae13c732 | 119 | * REMOVING this union you are compliant with: |
cparata | 0:128dae13c732 | 120 | * MISRA-C 2012 [Rule 10.8] -> " Explicit cast of composite |
cparata | 0:128dae13c732 | 121 | * expression " |
cparata | 0:128dae13c732 | 122 | * |
cparata | 0:128dae13c732 | 123 | * @{ |
cparata | 0:128dae13c732 | 124 | * |
cparata | 0:128dae13c732 | 125 | */ |
cparata | 0:128dae13c732 | 126 | |
cparata | 0:128dae13c732 | 127 | int16_t stts751_from_celsius_to_lsb(float celsius) |
cparata | 0:128dae13c732 | 128 | { |
cparata | 0:128dae13c732 | 129 | return (int16_t)(celsius * 256.0f); |
cparata | 0:128dae13c732 | 130 | } |
cparata | 0:128dae13c732 | 131 | |
cparata | 0:128dae13c732 | 132 | /** |
cparata | 0:128dae13c732 | 133 | * @} |
cparata | 0:128dae13c732 | 134 | * |
cparata | 0:128dae13c732 | 135 | */ |
cparata | 0:128dae13c732 | 136 | |
cparata | 0:128dae13c732 | 137 | /** |
cparata | 0:128dae13c732 | 138 | * @defgroup STTS751_Data_Generation |
cparata | 0:128dae13c732 | 139 | * @brief This section groups all the functions concerning |
cparata | 0:128dae13c732 | 140 | * data generation |
cparata | 0:128dae13c732 | 141 | * @{ |
cparata | 0:128dae13c732 | 142 | * |
cparata | 0:128dae13c732 | 143 | */ |
cparata | 0:128dae13c732 | 144 | |
cparata | 0:128dae13c732 | 145 | /** |
cparata | 0:128dae13c732 | 146 | * @brief Temperature sensor data rate selection.[set] |
cparata | 0:128dae13c732 | 147 | * |
cparata | 0:128dae13c732 | 148 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 149 | * @param val change the sensor data rate |
cparata | 0:128dae13c732 | 150 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 151 | * |
cparata | 0:128dae13c732 | 152 | */ |
cparata | 0:128dae13c732 | 153 | int32_t stts751_temp_data_rate_set(stts751_ctx_t *ctx, stts751_odr_t val) |
cparata | 0:128dae13c732 | 154 | { |
cparata | 0:128dae13c732 | 155 | stts751_configuration_t configuration; |
cparata | 0:128dae13c732 | 156 | stts751_conversion_rate_t conversion_rate; |
cparata | 0:128dae13c732 | 157 | uint8_t dummy_value = 0xAA; |
cparata | 0:128dae13c732 | 158 | int32_t ret; |
cparata | 0:128dae13c732 | 159 | |
cparata | 0:128dae13c732 | 160 | ret = stts751_read_reg(ctx, STTS751_CONVERSION_RATE, |
cparata | 0:128dae13c732 | 161 | (uint8_t*)&conversion_rate, 1); |
cparata | 0:128dae13c732 | 162 | if (ret == 0) { |
cparata | 0:128dae13c732 | 163 | conversion_rate.conv = (uint8_t)val & 0x0FU; |
cparata | 0:128dae13c732 | 164 | ret = stts751_write_reg(ctx, STTS751_CONVERSION_RATE, |
cparata | 0:128dae13c732 | 165 | (uint8_t*)&conversion_rate, 1); |
cparata | 0:128dae13c732 | 166 | } |
cparata | 0:128dae13c732 | 167 | if (ret == 0) { |
cparata | 0:128dae13c732 | 168 | ret = stts751_read_reg(ctx, STTS751_CONFIGURATION, |
cparata | 0:128dae13c732 | 169 | (uint8_t*)&configuration, 1); |
cparata | 0:128dae13c732 | 170 | } |
cparata | 0:128dae13c732 | 171 | if (ret == 0) { |
cparata | 0:128dae13c732 | 172 | configuration.stop = ((uint8_t)val & 0x80U) >> 7; |
cparata | 0:128dae13c732 | 173 | ret = stts751_write_reg(ctx, STTS751_CONFIGURATION, |
cparata | 0:128dae13c732 | 174 | (uint8_t*)&configuration, 1); |
cparata | 0:128dae13c732 | 175 | } |
cparata | 0:128dae13c732 | 176 | if ((ret == 0) && (val == STTS751_TEMP_ODR_ONE_SHOT)) { |
cparata | 0:128dae13c732 | 177 | ret = stts751_write_reg(ctx, STTS751_ONE_SHOT, &dummy_value, 1); |
cparata | 0:128dae13c732 | 178 | } |
cparata | 0:128dae13c732 | 179 | return ret; |
cparata | 0:128dae13c732 | 180 | } |
cparata | 0:128dae13c732 | 181 | |
cparata | 0:128dae13c732 | 182 | /** |
cparata | 0:128dae13c732 | 183 | * @brief Temperature sensor data rate selection.[get] |
cparata | 0:128dae13c732 | 184 | * |
cparata | 0:128dae13c732 | 185 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 186 | * @param val Get the sensor data rate |
cparata | 0:128dae13c732 | 187 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 188 | * |
cparata | 0:128dae13c732 | 189 | */ |
cparata | 0:128dae13c732 | 190 | int32_t stts751_temp_data_rate_get(stts751_ctx_t *ctx, stts751_odr_t *val) |
cparata | 0:128dae13c732 | 191 | { |
cparata | 0:128dae13c732 | 192 | stts751_conversion_rate_t conversion_rate; |
cparata | 0:128dae13c732 | 193 | stts751_configuration_t configuration; |
cparata | 0:128dae13c732 | 194 | int32_t ret; |
cparata | 0:128dae13c732 | 195 | |
cparata | 0:128dae13c732 | 196 | ret = stts751_read_reg(ctx, STTS751_CONVERSION_RATE, |
cparata | 0:128dae13c732 | 197 | (uint8_t*)&conversion_rate, 1); |
cparata | 0:128dae13c732 | 198 | if (ret == 0) { |
cparata | 0:128dae13c732 | 199 | ret = stts751_read_reg(ctx, STTS751_CONFIGURATION, |
cparata | 0:128dae13c732 | 200 | (uint8_t*)&configuration, 1); |
cparata | 0:128dae13c732 | 201 | } |
cparata | 0:128dae13c732 | 202 | switch ( (configuration.stop << 7) + conversion_rate.conv) { |
cparata | 0:128dae13c732 | 203 | case STTS751_TEMP_ODR_OFF: |
cparata | 0:128dae13c732 | 204 | *val = STTS751_TEMP_ODR_OFF; |
cparata | 0:128dae13c732 | 205 | break; |
cparata | 0:128dae13c732 | 206 | case STTS751_TEMP_ODR_ONE_SHOT: |
cparata | 0:128dae13c732 | 207 | *val = STTS751_TEMP_ODR_ONE_SHOT; |
cparata | 0:128dae13c732 | 208 | break; |
cparata | 0:128dae13c732 | 209 | case STTS751_TEMP_ODR_62mHz5: |
cparata | 0:128dae13c732 | 210 | *val = STTS751_TEMP_ODR_62mHz5; |
cparata | 0:128dae13c732 | 211 | break; |
cparata | 0:128dae13c732 | 212 | case STTS751_TEMP_ODR_125mHz: |
cparata | 0:128dae13c732 | 213 | *val = STTS751_TEMP_ODR_125mHz; |
cparata | 0:128dae13c732 | 214 | break; |
cparata | 0:128dae13c732 | 215 | case STTS751_TEMP_ODR_250mHz: |
cparata | 0:128dae13c732 | 216 | *val = STTS751_TEMP_ODR_250mHz; |
cparata | 0:128dae13c732 | 217 | break; |
cparata | 0:128dae13c732 | 218 | case STTS751_TEMP_ODR_500mHz: |
cparata | 0:128dae13c732 | 219 | *val = STTS751_TEMP_ODR_500mHz; |
cparata | 0:128dae13c732 | 220 | break; |
cparata | 0:128dae13c732 | 221 | case STTS751_TEMP_ODR_1Hz: |
cparata | 0:128dae13c732 | 222 | *val = STTS751_TEMP_ODR_1Hz; |
cparata | 0:128dae13c732 | 223 | break; |
cparata | 0:128dae13c732 | 224 | case STTS751_TEMP_ODR_2Hz: |
cparata | 0:128dae13c732 | 225 | *val = STTS751_TEMP_ODR_2Hz; |
cparata | 0:128dae13c732 | 226 | break; |
cparata | 0:128dae13c732 | 227 | case STTS751_TEMP_ODR_4Hz: |
cparata | 0:128dae13c732 | 228 | *val = STTS751_TEMP_ODR_4Hz; |
cparata | 0:128dae13c732 | 229 | break; |
cparata | 0:128dae13c732 | 230 | case STTS751_TEMP_ODR_8Hz: |
cparata | 0:128dae13c732 | 231 | *val = STTS751_TEMP_ODR_8Hz; |
cparata | 0:128dae13c732 | 232 | break; |
cparata | 0:128dae13c732 | 233 | case STTS751_TEMP_ODR_16Hz: |
cparata | 0:128dae13c732 | 234 | *val = STTS751_TEMP_ODR_16Hz; |
cparata | 0:128dae13c732 | 235 | break; |
cparata | 0:128dae13c732 | 236 | case STTS751_TEMP_ODR_32Hz: |
cparata | 0:128dae13c732 | 237 | *val = STTS751_TEMP_ODR_32Hz; |
cparata | 0:128dae13c732 | 238 | break; |
cparata | 0:128dae13c732 | 239 | default: |
cparata | 0:128dae13c732 | 240 | *val = STTS751_TEMP_ODR_OFF; |
cparata | 0:128dae13c732 | 241 | break; |
cparata | 0:128dae13c732 | 242 | } |
cparata | 0:128dae13c732 | 243 | return ret; |
cparata | 0:128dae13c732 | 244 | } |
cparata | 0:128dae13c732 | 245 | |
cparata | 0:128dae13c732 | 246 | /** |
cparata | 0:128dae13c732 | 247 | * @brief Temperature sensor resolution selection.[set] |
cparata | 0:128dae13c732 | 248 | * |
cparata | 0:128dae13c732 | 249 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 250 | * @param val change the values of tres in reg CONFIGURATION |
cparata | 0:128dae13c732 | 251 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 252 | * |
cparata | 0:128dae13c732 | 253 | */ |
cparata | 0:128dae13c732 | 254 | int32_t stts751_resolution_set(stts751_ctx_t *ctx, stts751_tres_t val) |
cparata | 0:128dae13c732 | 255 | { |
cparata | 0:128dae13c732 | 256 | stts751_configuration_t reg; |
cparata | 0:128dae13c732 | 257 | int32_t ret; |
cparata | 0:128dae13c732 | 258 | |
cparata | 0:128dae13c732 | 259 | ret = stts751_read_reg(ctx, STTS751_CONFIGURATION,(uint8_t*) ®, 1); |
cparata | 0:128dae13c732 | 260 | if (ret == 0) { |
cparata | 0:128dae13c732 | 261 | reg.tres = (uint8_t) val; |
cparata | 0:128dae13c732 | 262 | ret = stts751_write_reg(ctx, STTS751_CONFIGURATION,(uint8_t*) ®, 1); |
cparata | 0:128dae13c732 | 263 | } |
cparata | 0:128dae13c732 | 264 | return ret; |
cparata | 0:128dae13c732 | 265 | } |
cparata | 0:128dae13c732 | 266 | |
cparata | 0:128dae13c732 | 267 | /** |
cparata | 0:128dae13c732 | 268 | * @brief Temperature sensor resolution selection.[get] |
cparata | 0:128dae13c732 | 269 | * |
cparata | 0:128dae13c732 | 270 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 271 | * @param val Get the values of tres in reg CONFIGURATION |
cparata | 0:128dae13c732 | 272 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 273 | * |
cparata | 0:128dae13c732 | 274 | */ |
cparata | 0:128dae13c732 | 275 | int32_t stts751_resolution_get(stts751_ctx_t *ctx, stts751_tres_t *val) |
cparata | 0:128dae13c732 | 276 | { |
cparata | 0:128dae13c732 | 277 | stts751_configuration_t reg; |
cparata | 0:128dae13c732 | 278 | int32_t ret; |
cparata | 0:128dae13c732 | 279 | |
cparata | 0:128dae13c732 | 280 | ret = stts751_read_reg(ctx, STTS751_CONFIGURATION,(uint8_t*) ®, 1); |
cparata | 0:128dae13c732 | 281 | |
cparata | 0:128dae13c732 | 282 | switch (reg.tres) { |
cparata | 0:128dae13c732 | 283 | case STTS751_9bit: |
cparata | 0:128dae13c732 | 284 | *val = STTS751_9bit; |
cparata | 0:128dae13c732 | 285 | break; |
cparata | 0:128dae13c732 | 286 | case STTS751_10bit: |
cparata | 0:128dae13c732 | 287 | *val = STTS751_10bit; |
cparata | 0:128dae13c732 | 288 | break; |
cparata | 0:128dae13c732 | 289 | case STTS751_11bit: |
cparata | 0:128dae13c732 | 290 | *val = STTS751_11bit; |
cparata | 0:128dae13c732 | 291 | break; |
cparata | 0:128dae13c732 | 292 | case STTS751_12bit: |
cparata | 0:128dae13c732 | 293 | *val = STTS751_12bit; |
cparata | 0:128dae13c732 | 294 | break; |
cparata | 0:128dae13c732 | 295 | default: |
cparata | 0:128dae13c732 | 296 | *val = STTS751_9bit; |
cparata | 0:128dae13c732 | 297 | break; |
cparata | 0:128dae13c732 | 298 | } |
cparata | 0:128dae13c732 | 299 | return ret; |
cparata | 0:128dae13c732 | 300 | } |
cparata | 0:128dae13c732 | 301 | |
cparata | 0:128dae13c732 | 302 | /** |
cparata | 0:128dae13c732 | 303 | * @brief The STATUS_REG register of the device.[get] |
cparata | 0:128dae13c732 | 304 | * |
cparata | 0:128dae13c732 | 305 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 306 | * @param val union of registers from STATUS to |
cparata | 0:128dae13c732 | 307 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 308 | * |
cparata | 0:128dae13c732 | 309 | */ |
cparata | 0:128dae13c732 | 310 | int32_t stts751_status_reg_get(stts751_ctx_t *ctx, stts751_status_t *val) |
cparata | 0:128dae13c732 | 311 | { |
cparata | 0:128dae13c732 | 312 | int32_t ret; |
cparata | 0:128dae13c732 | 313 | ret = stts751_read_reg(ctx, STTS751_STATUS, (uint8_t*) val, 1); |
cparata | 0:128dae13c732 | 314 | return ret; |
cparata | 0:128dae13c732 | 315 | } |
cparata | 0:128dae13c732 | 316 | |
cparata | 0:128dae13c732 | 317 | /** |
cparata | 0:128dae13c732 | 318 | * @brief Temperature sensor "conversion on-going" flag.[get] |
cparata | 0:128dae13c732 | 319 | * |
cparata | 0:128dae13c732 | 320 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 321 | * @param val get the values of busy in reg STATUS |
cparata | 0:128dae13c732 | 322 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 323 | * |
cparata | 0:128dae13c732 | 324 | */ |
cparata | 0:128dae13c732 | 325 | int32_t stts751_flag_busy_get(stts751_ctx_t *ctx, uint8_t *val) |
cparata | 0:128dae13c732 | 326 | { |
cparata | 0:128dae13c732 | 327 | stts751_status_t reg; |
cparata | 0:128dae13c732 | 328 | int32_t ret; |
cparata | 0:128dae13c732 | 329 | |
cparata | 0:128dae13c732 | 330 | ret = stts751_read_reg(ctx, STTS751_STATUS, (uint8_t*)®, 1); |
cparata | 0:128dae13c732 | 331 | *val = reg.busy; |
cparata | 0:128dae13c732 | 332 | |
cparata | 0:128dae13c732 | 333 | return ret; |
cparata | 0:128dae13c732 | 334 | } |
cparata | 0:128dae13c732 | 335 | |
cparata | 0:128dae13c732 | 336 | /** |
cparata | 0:128dae13c732 | 337 | * @} |
cparata | 0:128dae13c732 | 338 | * |
cparata | 0:128dae13c732 | 339 | */ |
cparata | 0:128dae13c732 | 340 | |
cparata | 0:128dae13c732 | 341 | /** |
cparata | 0:128dae13c732 | 342 | * @defgroup STTS751_Data_Output |
cparata | 0:128dae13c732 | 343 | * @brief This section groups all the data output functions. |
cparata | 0:128dae13c732 | 344 | * @{ |
cparata | 0:128dae13c732 | 345 | * |
cparata | 0:128dae13c732 | 346 | */ |
cparata | 0:128dae13c732 | 347 | |
cparata | 0:128dae13c732 | 348 | /** |
cparata | 0:128dae13c732 | 349 | * @brief Temperature data output register (r). L and H registers |
cparata | 0:128dae13c732 | 350 | * together express a 16-bit word in two’s complement.[get] |
cparata | 0:128dae13c732 | 351 | * |
cparata | 0:128dae13c732 | 352 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 353 | * @param buff buffer that stores data read |
cparata | 0:128dae13c732 | 354 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 355 | * |
cparata | 0:128dae13c732 | 356 | */ |
cparata | 0:128dae13c732 | 357 | int32_t stts751_temperature_raw_get(stts751_ctx_t *ctx, int16_t *buff) |
cparata | 0:128dae13c732 | 358 | { |
cparata | 0:128dae13c732 | 359 | uint16_t temperature; |
cparata | 0:128dae13c732 | 360 | uint8_t temperature_low; |
cparata | 0:128dae13c732 | 361 | int32_t ret; |
cparata | 0:128dae13c732 | 362 | |
cparata | 0:128dae13c732 | 363 | ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_HIGH, |
cparata | 0:128dae13c732 | 364 | (uint8_t*)&temperature, 1); |
cparata | 0:128dae13c732 | 365 | if (ret == 0) { |
cparata | 0:128dae13c732 | 366 | ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_LOW, |
cparata | 0:128dae13c732 | 367 | &temperature_low, 1); |
cparata | 0:128dae13c732 | 368 | |
cparata | 0:128dae13c732 | 369 | temperature = (temperature << 8) + temperature_low; |
cparata | 0:128dae13c732 | 370 | *buff = (int16_t)temperature; |
cparata | 0:128dae13c732 | 371 | } |
cparata | 0:128dae13c732 | 372 | return ret; |
cparata | 0:128dae13c732 | 373 | } |
cparata | 0:128dae13c732 | 374 | |
cparata | 0:128dae13c732 | 375 | /** |
cparata | 0:128dae13c732 | 376 | * @} |
cparata | 0:128dae13c732 | 377 | * |
cparata | 0:128dae13c732 | 378 | */ |
cparata | 0:128dae13c732 | 379 | |
cparata | 0:128dae13c732 | 380 | /** |
cparata | 0:128dae13c732 | 381 | * @defgroup STTS751_Interrupt_Pins |
cparata | 0:128dae13c732 | 382 | * @brief This section groups all the functions that manage event pin |
cparata | 0:128dae13c732 | 383 | * @{ |
cparata | 0:128dae13c732 | 384 | * |
cparata | 0:128dae13c732 | 385 | */ |
cparata | 0:128dae13c732 | 386 | |
cparata | 0:128dae13c732 | 387 | /** |
cparata | 0:128dae13c732 | 388 | * @brief Route interrupt signal threshold on event pad.[set] |
cparata | 0:128dae13c732 | 389 | * |
cparata | 0:128dae13c732 | 390 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 391 | * @param val set mask1 bit in register CONFIGURATION. |
cparata | 0:128dae13c732 | 392 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 393 | * |
cparata | 0:128dae13c732 | 394 | */ |
cparata | 0:128dae13c732 | 395 | int32_t stts751_pin_event_route_set(stts751_ctx_t *ctx, uint8_t val) |
cparata | 0:128dae13c732 | 396 | { |
cparata | 0:128dae13c732 | 397 | stts751_configuration_t reg; |
cparata | 0:128dae13c732 | 398 | int32_t ret; |
cparata | 0:128dae13c732 | 399 | |
cparata | 0:128dae13c732 | 400 | ret = stts751_read_reg(ctx, STTS751_CONFIGURATION,(uint8_t*)®, 1); |
cparata | 0:128dae13c732 | 401 | if (ret == 0) { |
cparata | 0:128dae13c732 | 402 | reg.mask1 = val; |
cparata | 0:128dae13c732 | 403 | ret = stts751_write_reg(ctx, STTS751_CONFIGURATION, (uint8_t*)®, 1); |
cparata | 0:128dae13c732 | 404 | } |
cparata | 0:128dae13c732 | 405 | return ret; |
cparata | 0:128dae13c732 | 406 | } |
cparata | 0:128dae13c732 | 407 | |
cparata | 0:128dae13c732 | 408 | /** |
cparata | 0:128dae13c732 | 409 | * @brief Route interrupt signal threshold on event pad.[get] |
cparata | 0:128dae13c732 | 410 | * |
cparata | 0:128dae13c732 | 411 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 412 | * @param val get mask1 bit in register CONFIGURATION. |
cparata | 0:128dae13c732 | 413 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 414 | * |
cparata | 0:128dae13c732 | 415 | */ |
cparata | 0:128dae13c732 | 416 | int32_t stts751_pin_event_route_get(stts751_ctx_t *ctx, uint8_t *val) |
cparata | 0:128dae13c732 | 417 | { |
cparata | 0:128dae13c732 | 418 | stts751_configuration_t reg; |
cparata | 0:128dae13c732 | 419 | int32_t ret; |
cparata | 0:128dae13c732 | 420 | ret = stts751_read_reg(ctx, STTS751_CONFIGURATION, (uint8_t*)®, 1); |
cparata | 0:128dae13c732 | 421 | *val = reg.mask1; |
cparata | 0:128dae13c732 | 422 | return ret; |
cparata | 0:128dae13c732 | 423 | } |
cparata | 0:128dae13c732 | 424 | |
cparata | 0:128dae13c732 | 425 | /** |
cparata | 0:128dae13c732 | 426 | * @} |
cparata | 0:128dae13c732 | 427 | * |
cparata | 0:128dae13c732 | 428 | */ |
cparata | 0:128dae13c732 | 429 | |
cparata | 0:128dae13c732 | 430 | /** |
cparata | 0:128dae13c732 | 431 | * @defgroup STTS751_Interrupt_on_threshold |
cparata | 0:128dae13c732 | 432 | * @brief This section groups all the functions that manage interrupt |
cparata | 0:128dae13c732 | 433 | * on threshold event |
cparata | 0:128dae13c732 | 434 | * @{ |
cparata | 0:128dae13c732 | 435 | * |
cparata | 0:128dae13c732 | 436 | */ |
cparata | 0:128dae13c732 | 437 | |
cparata | 0:128dae13c732 | 438 | /** |
cparata | 0:128dae13c732 | 439 | * @brief high temperature theshold.[set] |
cparata | 0:128dae13c732 | 440 | * |
cparata | 0:128dae13c732 | 441 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 442 | * @param buff buffer that contains data to write |
cparata | 0:128dae13c732 | 443 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 444 | * |
cparata | 0:128dae13c732 | 445 | */ |
cparata | 0:128dae13c732 | 446 | int32_t stts751_high_temperature_threshold_set(stts751_ctx_t *ctx, |
cparata | 0:128dae13c732 | 447 | int16_t buff) |
cparata | 0:128dae13c732 | 448 | { |
cparata | 0:128dae13c732 | 449 | uint8_t *temperature_ptr; |
cparata | 0:128dae13c732 | 450 | int32_t ret; |
cparata | 0:128dae13c732 | 451 | |
cparata | 0:128dae13c732 | 452 | temperature_ptr = (uint8_t*)&buff; |
cparata | 0:128dae13c732 | 453 | ret = stts751_write_reg(ctx, STTS751_TEMPERATURE_HIGH_LIMIT_LOW, |
cparata | 0:128dae13c732 | 454 | (uint8_t*)temperature_ptr, 1); |
cparata | 0:128dae13c732 | 455 | |
cparata | 0:128dae13c732 | 456 | if (ret == 0) { |
cparata | 0:128dae13c732 | 457 | temperature_ptr++; |
cparata | 0:128dae13c732 | 458 | ret = stts751_write_reg(ctx, STTS751_TEMPERATURE_HIGH_LIMIT_HIGH, |
cparata | 0:128dae13c732 | 459 | (uint8_t*)temperature_ptr, 1); |
cparata | 0:128dae13c732 | 460 | } |
cparata | 0:128dae13c732 | 461 | |
cparata | 0:128dae13c732 | 462 | return ret; |
cparata | 0:128dae13c732 | 463 | } |
cparata | 0:128dae13c732 | 464 | |
cparata | 0:128dae13c732 | 465 | /** |
cparata | 0:128dae13c732 | 466 | * @brief high temperature theshold.[get] |
cparata | 0:128dae13c732 | 467 | * |
cparata | 0:128dae13c732 | 468 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 469 | * @param buff buffer that stores data read |
cparata | 0:128dae13c732 | 470 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 471 | * |
cparata | 0:128dae13c732 | 472 | */ |
cparata | 0:128dae13c732 | 473 | int32_t stts751_high_temperature_threshold_get(stts751_ctx_t *ctx, |
cparata | 0:128dae13c732 | 474 | int16_t *buff) |
cparata | 0:128dae13c732 | 475 | { |
cparata | 0:128dae13c732 | 476 | uint16_t temperature; |
cparata | 0:128dae13c732 | 477 | uint8_t temperature_low; |
cparata | 0:128dae13c732 | 478 | int32_t ret; |
cparata | 0:128dae13c732 | 479 | |
cparata | 0:128dae13c732 | 480 | ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_HIGH_LIMIT_HIGH, |
cparata | 0:128dae13c732 | 481 | (uint8_t*)&temperature, 1); |
cparata | 0:128dae13c732 | 482 | if (ret == 0) { |
cparata | 0:128dae13c732 | 483 | ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_HIGH_LIMIT_LOW, |
cparata | 0:128dae13c732 | 484 | &temperature_low, 1); |
cparata | 0:128dae13c732 | 485 | |
cparata | 0:128dae13c732 | 486 | temperature = (temperature << 8) + temperature_low; |
cparata | 0:128dae13c732 | 487 | *buff = (int16_t)temperature; |
cparata | 0:128dae13c732 | 488 | } |
cparata | 0:128dae13c732 | 489 | return ret; |
cparata | 0:128dae13c732 | 490 | } |
cparata | 0:128dae13c732 | 491 | |
cparata | 0:128dae13c732 | 492 | /** |
cparata | 0:128dae13c732 | 493 | * @brief low temperature theshold.[set] |
cparata | 0:128dae13c732 | 494 | * |
cparata | 0:128dae13c732 | 495 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 496 | * @param buff buffer that contains data to write |
cparata | 0:128dae13c732 | 497 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 498 | * |
cparata | 0:128dae13c732 | 499 | */ |
cparata | 0:128dae13c732 | 500 | int32_t stts751_low_temperature_threshold_set(stts751_ctx_t *ctx, |
cparata | 0:128dae13c732 | 501 | int16_t buff) |
cparata | 0:128dae13c732 | 502 | { |
cparata | 0:128dae13c732 | 503 | |
cparata | 0:128dae13c732 | 504 | uint8_t *temperature_ptr; |
cparata | 0:128dae13c732 | 505 | int32_t ret; |
cparata | 0:128dae13c732 | 506 | |
cparata | 0:128dae13c732 | 507 | temperature_ptr = (uint8_t*)&buff; |
cparata | 0:128dae13c732 | 508 | ret = stts751_write_reg(ctx, STTS751_TEMPERATURE_LOW_LIMIT_LOW, |
cparata | 0:128dae13c732 | 509 | (uint8_t*)temperature_ptr, 1); |
cparata | 0:128dae13c732 | 510 | |
cparata | 0:128dae13c732 | 511 | if (ret == 0) { |
cparata | 0:128dae13c732 | 512 | temperature_ptr++; |
cparata | 0:128dae13c732 | 513 | ret = stts751_write_reg(ctx, STTS751_TEMPERATURE_LOW_LIMIT_HIGH, |
cparata | 0:128dae13c732 | 514 | (uint8_t*)temperature_ptr, 1); |
cparata | 0:128dae13c732 | 515 | } |
cparata | 0:128dae13c732 | 516 | |
cparata | 0:128dae13c732 | 517 | return ret; |
cparata | 0:128dae13c732 | 518 | } |
cparata | 0:128dae13c732 | 519 | |
cparata | 0:128dae13c732 | 520 | /** |
cparata | 0:128dae13c732 | 521 | * @brief low temperature theshold.[get] |
cparata | 0:128dae13c732 | 522 | * |
cparata | 0:128dae13c732 | 523 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 524 | * @param buff buffer that stores data read |
cparata | 0:128dae13c732 | 525 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 526 | * |
cparata | 0:128dae13c732 | 527 | */ |
cparata | 0:128dae13c732 | 528 | int32_t stts751_low_temperature_threshold_get(stts751_ctx_t *ctx, |
cparata | 0:128dae13c732 | 529 | int16_t *buff) |
cparata | 0:128dae13c732 | 530 | { |
cparata | 0:128dae13c732 | 531 | uint16_t temperature; |
cparata | 0:128dae13c732 | 532 | uint8_t temperature_low; |
cparata | 0:128dae13c732 | 533 | int32_t ret; |
cparata | 0:128dae13c732 | 534 | |
cparata | 0:128dae13c732 | 535 | ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_LOW_LIMIT_HIGH, |
cparata | 0:128dae13c732 | 536 | (uint8_t*)&temperature, 1); |
cparata | 0:128dae13c732 | 537 | if (ret == 0) { |
cparata | 0:128dae13c732 | 538 | ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_LOW_LIMIT_LOW, |
cparata | 0:128dae13c732 | 539 | &temperature_low, 1); |
cparata | 0:128dae13c732 | 540 | |
cparata | 0:128dae13c732 | 541 | temperature = (temperature << 8) + temperature_low; |
cparata | 0:128dae13c732 | 542 | *buff = (int16_t)temperature; |
cparata | 0:128dae13c732 | 543 | } |
cparata | 0:128dae13c732 | 544 | |
cparata | 0:128dae13c732 | 545 | return ret; |
cparata | 0:128dae13c732 | 546 | } |
cparata | 0:128dae13c732 | 547 | |
cparata | 0:128dae13c732 | 548 | /** |
cparata | 0:128dae13c732 | 549 | * @} |
cparata | 0:128dae13c732 | 550 | * |
cparata | 0:128dae13c732 | 551 | */ |
cparata | 0:128dae13c732 | 552 | |
cparata | 0:128dae13c732 | 553 | |
cparata | 0:128dae13c732 | 554 | /** |
cparata | 0:128dae13c732 | 555 | * @defgroup STTS751 over temperature alarm |
cparata | 0:128dae13c732 | 556 | * @brief This section groups all the functions that manage |
cparata | 0:128dae13c732 | 557 | * over temperature alarm functionality. |
cparata | 0:128dae13c732 | 558 | * @{ |
cparata | 0:128dae13c732 | 559 | * |
cparata | 0:128dae13c732 | 560 | */ |
cparata | 0:128dae13c732 | 561 | |
cparata | 0:128dae13c732 | 562 | /** |
cparata | 0:128dae13c732 | 563 | * @brief Thermal Limit. 1 LSB = 1 degC (max 127 degC min -127 degC ).[set] |
cparata | 0:128dae13c732 | 564 | * |
cparata | 0:128dae13c732 | 565 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 566 | * @param val change the values of reg THERM_LIMIT |
cparata | 0:128dae13c732 | 567 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 568 | * |
cparata | 0:128dae13c732 | 569 | */ |
cparata | 0:128dae13c732 | 570 | int32_t stts751_ota_thermal_limit_set(stts751_ctx_t *ctx, int8_t val) |
cparata | 0:128dae13c732 | 571 | { |
cparata | 0:128dae13c732 | 572 | int32_t ret; |
cparata | 0:128dae13c732 | 573 | ret = stts751_write_reg(ctx, STTS751_THERM_LIMIT, (uint8_t*)&val, 1); |
cparata | 0:128dae13c732 | 574 | return ret; |
cparata | 0:128dae13c732 | 575 | } |
cparata | 0:128dae13c732 | 576 | |
cparata | 0:128dae13c732 | 577 | /** |
cparata | 0:128dae13c732 | 578 | * @brief Thermal Limit. 1 LSB = 1 degC (max 127 degC min -127 degC ).[get] |
cparata | 0:128dae13c732 | 579 | * |
cparata | 0:128dae13c732 | 580 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 581 | * @param val get the values of reg THERM_LIMIT |
cparata | 0:128dae13c732 | 582 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 583 | * |
cparata | 0:128dae13c732 | 584 | */ |
cparata | 0:128dae13c732 | 585 | int32_t stts751_ota_thermal_limit_get(stts751_ctx_t *ctx, int8_t *val) |
cparata | 0:128dae13c732 | 586 | { |
cparata | 0:128dae13c732 | 587 | int32_t ret; |
cparata | 0:128dae13c732 | 588 | |
cparata | 0:128dae13c732 | 589 | ret = stts751_read_reg(ctx, STTS751_THERM_LIMIT, (uint8_t*)val, 1); |
cparata | 0:128dae13c732 | 590 | return ret; |
cparata | 0:128dae13c732 | 591 | } |
cparata | 0:128dae13c732 | 592 | |
cparata | 0:128dae13c732 | 593 | /** |
cparata | 0:128dae13c732 | 594 | * @brief Thermal hysteresis. 1 LSB = 1 degC.[set] |
cparata | 0:128dae13c732 | 595 | * max 127 degC min -127 degC. |
cparata | 0:128dae13c732 | 596 | * |
cparata | 0:128dae13c732 | 597 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 598 | * @param val change the values of reg THERM_HYSTERESIS |
cparata | 0:128dae13c732 | 599 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 600 | * |
cparata | 0:128dae13c732 | 601 | */ |
cparata | 0:128dae13c732 | 602 | int32_t stts751_ota_thermal_hyst_set(stts751_ctx_t *ctx, int8_t val) |
cparata | 0:128dae13c732 | 603 | { |
cparata | 0:128dae13c732 | 604 | int32_t ret; |
cparata | 0:128dae13c732 | 605 | |
cparata | 0:128dae13c732 | 606 | ret = stts751_write_reg(ctx, STTS751_THERM_HYSTERESIS, (uint8_t*)&val, 1); |
cparata | 0:128dae13c732 | 607 | return ret; |
cparata | 0:128dae13c732 | 608 | } |
cparata | 0:128dae13c732 | 609 | |
cparata | 0:128dae13c732 | 610 | /** |
cparata | 0:128dae13c732 | 611 | * @brief Thermal hysteresis. 1 LSB = 1 degC.[get] |
cparata | 0:128dae13c732 | 612 | * max 127 degC min -127 degC. |
cparata | 0:128dae13c732 | 613 | * |
cparata | 0:128dae13c732 | 614 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 615 | * @param val get the values of reg THERM_HYSTERESIS |
cparata | 0:128dae13c732 | 616 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 617 | * |
cparata | 0:128dae13c732 | 618 | */ |
cparata | 0:128dae13c732 | 619 | int32_t stts751_ota_thermal_hyst_get(stts751_ctx_t *ctx, int8_t *val) |
cparata | 0:128dae13c732 | 620 | { |
cparata | 0:128dae13c732 | 621 | int32_t ret; |
cparata | 0:128dae13c732 | 622 | |
cparata | 0:128dae13c732 | 623 | ret = stts751_read_reg(ctx, STTS751_THERM_HYSTERESIS, (uint8_t*)val, 1); |
cparata | 0:128dae13c732 | 624 | return ret; |
cparata | 0:128dae13c732 | 625 | } |
cparata | 0:128dae13c732 | 626 | |
cparata | 0:128dae13c732 | 627 | /** |
cparata | 0:128dae13c732 | 628 | * @} |
cparata | 0:128dae13c732 | 629 | * |
cparata | 0:128dae13c732 | 630 | */ |
cparata | 0:128dae13c732 | 631 | |
cparata | 0:128dae13c732 | 632 | /** |
cparata | 0:128dae13c732 | 633 | * @defgroup STTS751_Common |
cparata | 0:128dae13c732 | 634 | * @brief This section groups common useful functions. |
cparata | 0:128dae13c732 | 635 | * @{ |
cparata | 0:128dae13c732 | 636 | * |
cparata | 0:128dae13c732 | 637 | */ |
cparata | 0:128dae13c732 | 638 | |
cparata | 0:128dae13c732 | 639 | /** |
cparata | 0:128dae13c732 | 640 | * @brief SMBus timeout.At power-up, the STTS751 is configured with an |
cparata | 0:128dae13c732 | 641 | * SMBus timeout of 25 to 35 milliseconds.[set] |
cparata | 0:128dae13c732 | 642 | * |
cparata | 0:128dae13c732 | 643 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 644 | * @param val set timeout bit in register SMBUS_TIMEOUT. |
cparata | 0:128dae13c732 | 645 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 646 | * |
cparata | 0:128dae13c732 | 647 | */ |
cparata | 0:128dae13c732 | 648 | int32_t stts751_smbus_timeout_set(stts751_ctx_t *ctx, uint8_t val) |
cparata | 0:128dae13c732 | 649 | { |
cparata | 0:128dae13c732 | 650 | stts751_smbus_timeout_t reg; |
cparata | 0:128dae13c732 | 651 | int32_t ret; |
cparata | 0:128dae13c732 | 652 | |
cparata | 0:128dae13c732 | 653 | ret = stts751_read_reg(ctx, STTS751_SMBUS_TIMEOUT,(uint8_t*)®, 1); |
cparata | 0:128dae13c732 | 654 | if (ret == 0) { |
cparata | 0:128dae13c732 | 655 | reg.timeout = val; |
cparata | 0:128dae13c732 | 656 | ret = stts751_write_reg(ctx, STTS751_SMBUS_TIMEOUT, (uint8_t*)®, 1); |
cparata | 0:128dae13c732 | 657 | } |
cparata | 0:128dae13c732 | 658 | return ret; |
cparata | 0:128dae13c732 | 659 | } |
cparata | 0:128dae13c732 | 660 | |
cparata | 0:128dae13c732 | 661 | /** |
cparata | 0:128dae13c732 | 662 | * @brief SMBus timeout.At power-up, the STTS751 is configured with an |
cparata | 0:128dae13c732 | 663 | * SMBus timeout of 25 to 35 milliseconds.[get] |
cparata | 0:128dae13c732 | 664 | * |
cparata | 0:128dae13c732 | 665 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 666 | * @param val get timeout bit in register SMBUS_TIMEOUT. |
cparata | 0:128dae13c732 | 667 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 668 | * |
cparata | 0:128dae13c732 | 669 | */ |
cparata | 0:128dae13c732 | 670 | int32_t stts751_smbus_timeout_get(stts751_ctx_t *ctx, uint8_t *val) |
cparata | 0:128dae13c732 | 671 | { |
cparata | 0:128dae13c732 | 672 | stts751_smbus_timeout_t reg; |
cparata | 0:128dae13c732 | 673 | int32_t ret; |
cparata | 0:128dae13c732 | 674 | ret = stts751_read_reg(ctx, STTS751_SMBUS_TIMEOUT, (uint8_t*)®, 1); |
cparata | 0:128dae13c732 | 675 | *val = reg.timeout; |
cparata | 0:128dae13c732 | 676 | return ret; |
cparata | 0:128dae13c732 | 677 | } |
cparata | 0:128dae13c732 | 678 | |
cparata | 0:128dae13c732 | 679 | /** |
cparata | 0:128dae13c732 | 680 | * @brief Device Who am I.[get] |
cparata | 0:128dae13c732 | 681 | * |
cparata | 0:128dae13c732 | 682 | * @param ctx read / write interface definitions |
cparata | 0:128dae13c732 | 683 | * @param buff buffer that stores data read |
cparata | 0:128dae13c732 | 684 | * @retval interface status (MANDATORY: return 0 -> no Error) |
cparata | 0:128dae13c732 | 685 | * |
cparata | 0:128dae13c732 | 686 | */ |
cparata | 0:128dae13c732 | 687 | int32_t stts751_device_id_get(stts751_ctx_t *ctx, stts751_id_t *buff) |
cparata | 0:128dae13c732 | 688 | { |
cparata | 0:128dae13c732 | 689 | int32_t ret; |
cparata | 0:128dae13c732 | 690 | ret = stts751_read_reg(ctx, STTS751_PRODUCT_ID, |
cparata | 0:128dae13c732 | 691 | (uint8_t*)&buff->product_id, 1); |
cparata | 0:128dae13c732 | 692 | if (ret == 0){ |
cparata | 0:128dae13c732 | 693 | ret = stts751_read_reg(ctx, STTS751_MANUFACTURER_ID, |
cparata | 0:128dae13c732 | 694 | (uint8_t*)&buff->manufacturer_id, 1); |
cparata | 0:128dae13c732 | 695 | } |
cparata | 0:128dae13c732 | 696 | if (ret == 0){ |
cparata | 0:128dae13c732 | 697 | ret = stts751_read_reg(ctx, STTS751_REVISION_ID, |
cparata | 0:128dae13c732 | 698 | (uint8_t*)&buff->revision_id, 1); |
cparata | 0:128dae13c732 | 699 | } |
cparata | 0:128dae13c732 | 700 | return ret; |
cparata | 0:128dae13c732 | 701 | } |
cparata | 0:128dae13c732 | 702 | |
cparata | 0:128dae13c732 | 703 | /** |
cparata | 0:128dae13c732 | 704 | * @} |
cparata | 0:128dae13c732 | 705 | * |
cparata | 0:128dae13c732 | 706 | */ |
cparata | 0:128dae13c732 | 707 | |
cparata | 0:128dae13c732 | 708 | /** |
cparata | 0:128dae13c732 | 709 | * @} |
cparata | 0:128dae13c732 | 710 | * |
cparata | 0:128dae13c732 | 711 | */ |
cparata | 0:128dae13c732 | 712 | |
cparata | 0:128dae13c732 | 713 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |