Low voltage digital temperature sensor

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   X_NUCLEO_IKS01A3 X_NUCLEO_IKS01A3 X_NUCLEO_IKS01A3

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stts751_reg.c Source File

stts751_reg.c

00001 /*
00002  ******************************************************************************
00003  * @file    stts751_reg.c
00004  * @author  Sensors Software Solution Team
00005  * @brief   STTS751 driver file
00006  ******************************************************************************
00007  * @attention
00008  *
00009  * <h2><center>&copy; COPYRIGHT(c) 2018 STMicroelectronics</center></h2>
00010  *
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions
00013  * are met:
00014  *   1. Redistributions of source code must retain the above copyright notice,
00015  *      this list of conditions and the following disclaimer.
00016  *   2. Redistributions in binary form must reproduce the above copyright
00017  *      notice, this list of conditions and the following disclaimer in the
00018  *      documentation and/or other materials provided with the distribution.
00019  *   3. Neither the name of STMicroelectronics nor the names of its
00020  *      contributors may be used to endorse or promote products derived from
00021  *      this software without specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  * POSSIBILITY OF SUCH DAMAGE.
00034  *
00035 */
00036 
00037 #include "stts751_reg.h"
00038 
00039 /**
00040   * @defgroup  STTS751
00041   * @brief     This file provides a set of functions needed to drive the
00042   *            stts751 enhanced inertial module.
00043   * @{
00044   *
00045   */
00046 
00047 /**
00048   * @defgroup  STTS751_Interfaces_Functions
00049   * @brief     This section provide a set of functions used to read and
00050   *            write a generic register of the device.
00051   *            MANDATORY: return 0 -> no Error.
00052   * @{
00053   *
00054   */
00055 
00056 /**
00057   * @brief  Read generic device register
00058   *
00059   * @param  ctx   read / write interface definitions(ptr)
00060   * @param  reg   register to read
00061   * @param  data  pointer to buffer that store the data read(ptr)
00062   * @param  len   number of consecutive register to read
00063   * @retval          interface status (MANDATORY: return 0 -> no Error)
00064   *
00065   */
00066 int32_t stts751_read_reg(stts751_ctx_t *ctx, uint8_t reg, uint8_t *data,
00067                          uint16_t len)
00068 {
00069     int32_t ret;
00070     ret = ctx->read_reg(ctx->handle, reg, data, len);
00071     return ret;
00072 }
00073 
00074 /**
00075   * @brief  Write generic device register
00076   *
00077   * @param  ctx   read / write interface definitions(ptr)
00078   * @param  reg   register to write
00079   * @param  data  pointer to data to write in register reg(ptr)
00080   * @param  len   number of consecutive register to write
00081   * @retval          interface status (MANDATORY: return 0 -> no Error)
00082   *
00083   */
00084 int32_t stts751_write_reg(stts751_ctx_t *ctx, uint8_t reg, uint8_t *data,
00085                           uint16_t len)
00086 {
00087     int32_t ret;
00088     ret = ctx->write_reg(ctx->handle, reg, data, len);
00089     return ret;
00090 }
00091 
00092 /**
00093   * @}
00094   *
00095   */
00096 
00097 /**
00098   * @defgroup    STTS751_Sensitivity
00099   * @brief       These functions convert raw-data into engineering units and
00100   *              vice-versa .
00101   * @{
00102   *
00103   */
00104 
00105 float stts751_from_lsb_to_celsius(int16_t lsb)
00106 {
00107     return ((float)lsb) / 256.0f;
00108 }
00109 
00110 /**
00111   * @}
00112   *
00113   */
00114 
00115 /**
00116   * @defgroup STTS751_Sensitivity_Reverse
00117   * @brief    This conversion is useful but not need by the driver.
00118   *
00119   *           REMOVING this union you are compliant with:
00120   *           MISRA-C 2012 [Rule 10.8] -> " Explicit cast of composite
00121   *                                         expression "
00122   *
00123   * @{
00124   *
00125   */
00126 
00127 int16_t stts751_from_celsius_to_lsb(float celsius)
00128 {
00129     return (int16_t)(celsius * 256.0f);
00130 }
00131 
00132 /**
00133   * @}
00134   *
00135   */
00136 
00137 /**
00138   * @defgroup  STTS751_Data_Generation
00139   * @brief     This section groups all the functions concerning
00140   *            data generation
00141   * @{
00142   *
00143   */
00144 
00145 /**
00146   * @brief  Temperature sensor data rate selection.[set]
00147   *
00148   * @param  ctx      read / write interface definitions
00149   * @param  val      change the sensor data rate
00150   * @retval          interface status (MANDATORY: return 0 -> no Error)
00151   *
00152   */
00153 int32_t stts751_temp_data_rate_set(stts751_ctx_t *ctx, stts751_odr_t val)
00154 {
00155     stts751_configuration_t configuration;
00156     stts751_conversion_rate_t conversion_rate;
00157     uint8_t dummy_value = 0xAA;
00158     int32_t ret;
00159 
00160     ret = stts751_read_reg(ctx, STTS751_CONVERSION_RATE,
00161                            (uint8_t *)&conversion_rate, 1);
00162     if (ret == 0) {
00163         conversion_rate.conv = (uint8_t)val & 0x0FU;
00164         ret = stts751_write_reg(ctx, STTS751_CONVERSION_RATE,
00165                                 (uint8_t *)&conversion_rate, 1);
00166     }
00167     if (ret == 0) {
00168         ret = stts751_read_reg(ctx, STTS751_CONFIGURATION,
00169                                (uint8_t *)&configuration, 1);
00170     }
00171     if (ret == 0) {
00172         configuration.stop = ((uint8_t)val & 0x80U) >> 7;
00173         ret = stts751_write_reg(ctx, STTS751_CONFIGURATION,
00174                                 (uint8_t *)&configuration, 1);
00175     }
00176     if ((ret == 0) && (val == STTS751_TEMP_ODR_ONE_SHOT)) {
00177         ret = stts751_write_reg(ctx, STTS751_ONE_SHOT, &dummy_value, 1);
00178     }
00179     return ret;
00180 }
00181 
00182 /**
00183   * @brief  Temperature sensor data rate selection.[get]
00184   *
00185   * @param  ctx      read / write interface definitions
00186   * @param  val      Get the sensor data rate
00187   * @retval          interface status (MANDATORY: return 0 -> no Error)
00188   *
00189   */
00190 int32_t stts751_temp_data_rate_get(stts751_ctx_t *ctx, stts751_odr_t *val)
00191 {
00192     stts751_conversion_rate_t conversion_rate;
00193     stts751_configuration_t configuration;
00194     int32_t ret;
00195 
00196     ret = stts751_read_reg(ctx, STTS751_CONVERSION_RATE,
00197                            (uint8_t *)&conversion_rate, 1);
00198     if (ret == 0) {
00199         ret = stts751_read_reg(ctx, STTS751_CONFIGURATION,
00200                                (uint8_t *)&configuration, 1);
00201     }
00202     switch ((configuration.stop << 7) + conversion_rate.conv) {
00203         case STTS751_TEMP_ODR_OFF:
00204             *val = STTS751_TEMP_ODR_OFF;
00205             break;
00206         case STTS751_TEMP_ODR_ONE_SHOT:
00207             *val = STTS751_TEMP_ODR_ONE_SHOT;
00208             break;
00209         case STTS751_TEMP_ODR_62mHz5:
00210             *val = STTS751_TEMP_ODR_62mHz5;
00211             break;
00212         case STTS751_TEMP_ODR_125mHz:
00213             *val = STTS751_TEMP_ODR_125mHz;
00214             break;
00215         case STTS751_TEMP_ODR_250mHz:
00216             *val = STTS751_TEMP_ODR_250mHz;
00217             break;
00218         case STTS751_TEMP_ODR_500mHz:
00219             *val = STTS751_TEMP_ODR_500mHz;
00220             break;
00221         case STTS751_TEMP_ODR_1Hz:
00222             *val = STTS751_TEMP_ODR_1Hz;
00223             break;
00224         case STTS751_TEMP_ODR_2Hz:
00225             *val = STTS751_TEMP_ODR_2Hz;
00226             break;
00227         case STTS751_TEMP_ODR_4Hz:
00228             *val = STTS751_TEMP_ODR_4Hz;
00229             break;
00230         case STTS751_TEMP_ODR_8Hz:
00231             *val = STTS751_TEMP_ODR_8Hz;
00232             break;
00233         case STTS751_TEMP_ODR_16Hz:
00234             *val = STTS751_TEMP_ODR_16Hz;
00235             break;
00236         case STTS751_TEMP_ODR_32Hz:
00237             *val = STTS751_TEMP_ODR_32Hz;
00238             break;
00239         default:
00240             *val = STTS751_TEMP_ODR_OFF;
00241             break;
00242     }
00243     return ret;
00244 }
00245 
00246 /**
00247   * @brief  Temperature sensor resolution selection.[set]
00248   *
00249   * @param  ctx      read / write interface definitions
00250   * @param  val      change the values of tres in reg CONFIGURATION
00251   * @retval          interface status (MANDATORY: return 0 -> no Error)
00252   *
00253   */
00254 int32_t stts751_resolution_set(stts751_ctx_t *ctx, stts751_tres_t val)
00255 {
00256     stts751_configuration_t reg;
00257     int32_t ret;
00258 
00259     ret = stts751_read_reg(ctx, STTS751_CONFIGURATION, (uint8_t *) &reg, 1);
00260     if (ret == 0) {
00261         reg.tres = (uint8_t) val;
00262         ret = stts751_write_reg(ctx, STTS751_CONFIGURATION, (uint8_t *) &reg, 1);
00263     }
00264     return ret;
00265 }
00266 
00267 /**
00268   * @brief Temperature sensor resolution selection.[get]
00269   *
00270   * @param  ctx      read / write interface definitions
00271   * @param  val      Get the values of tres in reg CONFIGURATION
00272   * @retval          interface status (MANDATORY: return 0 -> no Error)
00273   *
00274   */
00275 int32_t stts751_resolution_get(stts751_ctx_t *ctx, stts751_tres_t *val)
00276 {
00277     stts751_configuration_t reg;
00278     int32_t ret;
00279 
00280     ret = stts751_read_reg(ctx, STTS751_CONFIGURATION, (uint8_t *) &reg, 1);
00281 
00282     switch (reg.tres) {
00283         case STTS751_9bit:
00284             *val = STTS751_9bit;
00285             break;
00286         case STTS751_10bit:
00287             *val = STTS751_10bit;
00288             break;
00289         case STTS751_11bit:
00290             *val = STTS751_11bit;
00291             break;
00292         case STTS751_12bit:
00293             *val = STTS751_12bit;
00294             break;
00295         default:
00296             *val = STTS751_9bit;
00297             break;
00298     }
00299     return ret;
00300 }
00301 
00302 /**
00303   * @brief  The STATUS_REG register of the device.[get]
00304   *
00305   * @param  ctx      read / write interface definitions
00306   * @param  val      union of registers from STATUS to
00307   * @retval          interface status (MANDATORY: return 0 -> no Error)
00308   *
00309   */
00310 int32_t stts751_status_reg_get(stts751_ctx_t *ctx, stts751_status_t *val)
00311 {
00312     int32_t ret;
00313     ret = stts751_read_reg(ctx, STTS751_STATUS, (uint8_t *) val, 1);
00314     return ret;
00315 }
00316 
00317 /**
00318   * @brief  Temperature sensor "conversion on-going" flag.[get]
00319   *
00320   * @param  ctx      read / write interface definitions
00321   * @param  val      get the values of busy in reg STATUS
00322   * @retval          interface status (MANDATORY: return 0 -> no Error)
00323   *
00324   */
00325 int32_t stts751_flag_busy_get(stts751_ctx_t *ctx, uint8_t *val)
00326 {
00327     stts751_status_t reg;
00328     int32_t ret;
00329 
00330     ret = stts751_read_reg(ctx, STTS751_STATUS, (uint8_t *)&reg, 1);
00331     *val = reg.busy;
00332 
00333     return ret;
00334 }
00335 
00336 /**
00337   * @}
00338   *
00339   */
00340 
00341 /**
00342   * @defgroup  STTS751_Data_Output
00343   * @brief     This section groups all the data output functions.
00344   * @{
00345   *
00346   */
00347 
00348 /**
00349   * @brief  Temperature data output register (r). L and H registers
00350   *         together express a 16-bit word in two’s complement.[get]
00351   *
00352   * @param  ctx      read / write interface definitions
00353   * @param  buff     buffer that stores data read
00354   * @retval          interface status (MANDATORY: return 0 -> no Error)
00355   *
00356   */
00357 int32_t stts751_temperature_raw_get(stts751_ctx_t *ctx, int16_t *buff)
00358 {
00359     uint16_t temperature;
00360     uint8_t temperature_low;
00361     int32_t ret;
00362 
00363     ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_HIGH,
00364                            (uint8_t *)&temperature, 1);
00365     if (ret == 0) {
00366         ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_LOW,
00367                                &temperature_low, 1);
00368 
00369         temperature  = (temperature << 8) + temperature_low;
00370         *buff = (int16_t)temperature;
00371     }
00372     return ret;
00373 }
00374 
00375 /**
00376   * @}
00377   *
00378   */
00379 
00380 /**
00381   * @defgroup  STTS751_Interrupt_Pins
00382   * @brief     This section groups all the functions that manage event pin
00383   * @{
00384   *
00385   */
00386 
00387 /**
00388   * @brief  Route interrupt signal threshold on event pad.[set]
00389   *
00390   * @param  ctx      read / write interface definitions
00391   * @param  val      set mask1 bit in register CONFIGURATION.
00392   * @retval          interface status (MANDATORY: return 0 -> no Error)
00393   *
00394   */
00395 int32_t stts751_pin_event_route_set(stts751_ctx_t *ctx, uint8_t val)
00396 {
00397     stts751_configuration_t reg;
00398     int32_t ret;
00399 
00400     ret = stts751_read_reg(ctx, STTS751_CONFIGURATION, (uint8_t *)&reg, 1);
00401     if (ret == 0) {
00402         reg.mask1 = val;
00403         ret = stts751_write_reg(ctx, STTS751_CONFIGURATION, (uint8_t *)&reg, 1);
00404     }
00405     return ret;
00406 }
00407 
00408 /**
00409   * @brief  Route interrupt signal threshold on event pad.[get]
00410   *
00411   * @param  ctx      read / write interface definitions
00412   * @param  val      get mask1 bit in register CONFIGURATION.
00413   * @retval          interface status (MANDATORY: return 0 -> no Error)
00414   *
00415   */
00416 int32_t stts751_pin_event_route_get(stts751_ctx_t *ctx, uint8_t *val)
00417 {
00418     stts751_configuration_t reg;
00419     int32_t ret;
00420     ret = stts751_read_reg(ctx, STTS751_CONFIGURATION, (uint8_t *)&reg, 1);
00421     *val = reg.mask1;
00422     return ret;
00423 }
00424 
00425 /**
00426   * @}
00427   *
00428   */
00429 
00430 /**
00431   * @defgroup  STTS751_Interrupt_on_threshold
00432   * @brief     This section groups all the functions that manage interrupt
00433   *            on threshold event
00434   * @{
00435   *
00436   */
00437 
00438 /**
00439   * @brief  high temperature theshold.[set]
00440   *
00441   * @param  ctx      read / write interface definitions
00442   * @param  buff     buffer that contains data to write
00443   * @retval          interface status (MANDATORY: return 0 -> no Error)
00444   *
00445   */
00446 int32_t stts751_high_temperature_threshold_set(stts751_ctx_t *ctx,
00447                                                int16_t buff)
00448 {
00449     uint8_t *temperature_ptr;
00450     int32_t ret;
00451 
00452     temperature_ptr = (uint8_t *)&buff;
00453     ret = stts751_write_reg(ctx, STTS751_TEMPERATURE_HIGH_LIMIT_LOW,
00454                             (uint8_t *)temperature_ptr, 1);
00455 
00456     if (ret == 0) {
00457         temperature_ptr++;
00458         ret = stts751_write_reg(ctx, STTS751_TEMPERATURE_HIGH_LIMIT_HIGH,
00459                                 (uint8_t *)temperature_ptr, 1);
00460     }
00461 
00462     return ret;
00463 }
00464 
00465 /**
00466   * @brief  high temperature theshold.[get]
00467   *
00468   * @param  ctx      read / write interface definitions
00469   * @param  buff     buffer that stores data read
00470   * @retval          interface status (MANDATORY: return 0 -> no Error)
00471   *
00472   */
00473 int32_t stts751_high_temperature_threshold_get(stts751_ctx_t *ctx,
00474                                                int16_t *buff)
00475 {
00476     uint16_t temperature;
00477     uint8_t temperature_low;
00478     int32_t ret;
00479 
00480     ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_HIGH_LIMIT_HIGH,
00481                            (uint8_t *)&temperature, 1);
00482     if (ret == 0) {
00483         ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_HIGH_LIMIT_LOW,
00484                                &temperature_low, 1);
00485 
00486         temperature  = (temperature << 8) + temperature_low;
00487         *buff = (int16_t)temperature;
00488     }
00489     return ret;
00490 }
00491 
00492 /**
00493   * @brief  low temperature theshold.[set]
00494   *
00495   * @param  ctx      read / write interface definitions
00496   * @param  buff     buffer that contains data to write
00497   * @retval          interface status (MANDATORY: return 0 -> no Error)
00498   *
00499   */
00500 int32_t stts751_low_temperature_threshold_set(stts751_ctx_t *ctx,
00501                                               int16_t buff)
00502 {
00503 
00504     uint8_t *temperature_ptr;
00505     int32_t ret;
00506 
00507     temperature_ptr = (uint8_t *)&buff;
00508     ret = stts751_write_reg(ctx, STTS751_TEMPERATURE_LOW_LIMIT_LOW,
00509                             (uint8_t *)temperature_ptr, 1);
00510 
00511     if (ret == 0) {
00512         temperature_ptr++;
00513         ret = stts751_write_reg(ctx, STTS751_TEMPERATURE_LOW_LIMIT_HIGH,
00514                                 (uint8_t *)temperature_ptr, 1);
00515     }
00516 
00517     return ret;
00518 }
00519 
00520 /**
00521   * @brief  low temperature theshold.[get]
00522   *
00523   * @param  ctx      read / write interface definitions
00524   * @param  buff     buffer that stores data read
00525   * @retval          interface status (MANDATORY: return 0 -> no Error)
00526   *
00527   */
00528 int32_t stts751_low_temperature_threshold_get(stts751_ctx_t *ctx,
00529                                               int16_t *buff)
00530 {
00531     uint16_t temperature;
00532     uint8_t temperature_low;
00533     int32_t ret;
00534 
00535     ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_LOW_LIMIT_HIGH,
00536                            (uint8_t *)&temperature, 1);
00537     if (ret == 0) {
00538         ret = stts751_read_reg(ctx, STTS751_TEMPERATURE_LOW_LIMIT_LOW,
00539                                &temperature_low, 1);
00540 
00541         temperature  = (temperature << 8) + temperature_low;
00542         *buff = (int16_t)temperature;
00543     }
00544 
00545     return ret;
00546 }
00547 
00548 /**
00549   * @}
00550   *
00551   */
00552 
00553 
00554 /**
00555 * @defgroup  STTS751 over temperature alarm
00556 * @brief     This section groups all the functions that manage
00557 *            over temperature alarm functionality.
00558 * @{
00559 *
00560 */
00561 
00562 /**
00563   * @brief  Thermal Limit. 1 LSB = 1 degC (max 127 degC min -127 degC ).[set]
00564   *
00565   * @param  ctx      read / write interface definitions
00566   * @param  val      change the values of reg THERM_LIMIT
00567   * @retval          interface status (MANDATORY: return 0 -> no Error)
00568   *
00569   */
00570 int32_t stts751_ota_thermal_limit_set(stts751_ctx_t *ctx, int8_t val)
00571 {
00572     int32_t ret;
00573     ret = stts751_write_reg(ctx, STTS751_THERM_LIMIT, (uint8_t *)&val, 1);
00574     return ret;
00575 }
00576 
00577 /**
00578   * @brief  Thermal Limit. 1 LSB = 1 degC (max 127 degC min -127 degC ).[get]
00579   *
00580   * @param  ctx      read / write interface definitions
00581   * @param  val      get the values of reg THERM_LIMIT
00582   * @retval          interface status (MANDATORY: return 0 -> no Error)
00583   *
00584   */
00585 int32_t stts751_ota_thermal_limit_get(stts751_ctx_t *ctx, int8_t *val)
00586 {
00587     int32_t ret;
00588 
00589     ret = stts751_read_reg(ctx, STTS751_THERM_LIMIT, (uint8_t *)val, 1);
00590     return ret;
00591 }
00592 
00593 /**
00594   * @brief  Thermal hysteresis. 1 LSB = 1 degC.[set]
00595   *         max 127 degC min -127 degC.
00596   *
00597   * @param  ctx      read / write interface definitions
00598   * @param  val      change the values of reg THERM_HYSTERESIS
00599   * @retval          interface status (MANDATORY: return 0 -> no Error)
00600   *
00601   */
00602 int32_t stts751_ota_thermal_hyst_set(stts751_ctx_t *ctx, int8_t val)
00603 {
00604     int32_t ret;
00605 
00606     ret = stts751_write_reg(ctx, STTS751_THERM_HYSTERESIS, (uint8_t *)&val, 1);
00607     return ret;
00608 }
00609 
00610 /**
00611   * @brief  Thermal hysteresis. 1 LSB = 1 degC.[get]
00612   *         max 127 degC min -127 degC.
00613   *
00614   * @param  ctx      read / write interface definitions
00615   * @param  val      get the values of reg THERM_HYSTERESIS
00616   * @retval          interface status (MANDATORY: return 0 -> no Error)
00617   *
00618   */
00619 int32_t stts751_ota_thermal_hyst_get(stts751_ctx_t *ctx, int8_t *val)
00620 {
00621     int32_t ret;
00622 
00623     ret = stts751_read_reg(ctx, STTS751_THERM_HYSTERESIS, (uint8_t *)val, 1);
00624     return ret;
00625 }
00626 
00627 /**
00628   * @}
00629   *
00630   */
00631 
00632 /**
00633   * @defgroup  STTS751_Common
00634   * @brief     This section groups common useful functions.
00635   * @{
00636   *
00637   */
00638 
00639 /**
00640   * @brief  SMBus timeout.At power-up, the STTS751 is configured with an
00641   *         SMBus timeout of 25 to 35 milliseconds.[set]
00642   *
00643   * @param  ctx      read / write interface definitions
00644   * @param  val      set timeout bit in register SMBUS_TIMEOUT.
00645   * @retval          interface status (MANDATORY: return 0 -> no Error)
00646   *
00647   */
00648 int32_t stts751_smbus_timeout_set(stts751_ctx_t *ctx, uint8_t val)
00649 {
00650     stts751_smbus_timeout_t reg;
00651     int32_t ret;
00652 
00653     ret = stts751_read_reg(ctx, STTS751_SMBUS_TIMEOUT, (uint8_t *)&reg, 1);
00654     if (ret == 0) {
00655         reg.timeout = val;
00656         ret = stts751_write_reg(ctx, STTS751_SMBUS_TIMEOUT, (uint8_t *)&reg, 1);
00657     }
00658     return ret;
00659 }
00660 
00661 /**
00662   * @brief  SMBus timeout.At power-up, the STTS751 is configured with an
00663   *         SMBus timeout of 25 to 35 milliseconds.[get]
00664   *
00665   * @param  ctx      read / write interface definitions
00666   * @param  val      get timeout bit in register SMBUS_TIMEOUT.
00667   * @retval          interface status (MANDATORY: return 0 -> no Error)
00668   *
00669   */
00670 int32_t stts751_smbus_timeout_get(stts751_ctx_t *ctx, uint8_t *val)
00671 {
00672     stts751_smbus_timeout_t reg;
00673     int32_t ret;
00674     ret = stts751_read_reg(ctx, STTS751_SMBUS_TIMEOUT, (uint8_t *)&reg, 1);
00675     *val = reg.timeout;
00676     return ret;
00677 }
00678 
00679 /**
00680   * @brief  Device Who am I.[get]
00681   *
00682   * @param  ctx      read / write interface definitions
00683   * @param  buff     buffer that stores data read
00684   * @retval          interface status (MANDATORY: return 0 -> no Error)
00685   *
00686   */
00687 int32_t stts751_device_id_get(stts751_ctx_t *ctx, stts751_id_t *buff)
00688 {
00689     int32_t ret;
00690     ret = stts751_read_reg(ctx, STTS751_PRODUCT_ID,
00691                            (uint8_t *)&buff->product_id, 1);
00692     if (ret == 0) {
00693         ret = stts751_read_reg(ctx, STTS751_MANUFACTURER_ID,
00694                                (uint8_t *)&buff->manufacturer_id, 1);
00695     }
00696     if (ret == 0) {
00697         ret = stts751_read_reg(ctx, STTS751_REVISION_ID,
00698                                (uint8_t *)&buff->revision_id, 1);
00699     }
00700     return ret;
00701 }
00702 
00703 /**
00704   * @}
00705   *
00706   */
00707 
00708 /**
00709   * @}
00710   *
00711   */
00712 
00713 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/