1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:32:45 +01:00

drivers/tmp00x : Model as bool

Model CONFIG_TMP00X_USE_LOW_POWER and CONFIG_TMP00X_USE_RAW_VALUES
as bool
This commit is contained in:
Akshai M 2020-04-30 15:01:30 +05:30
parent 94d6b898fc
commit 414fae5b0c
4 changed files with 41 additions and 35 deletions

View File

@ -83,6 +83,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "periph/i2c.h"
#include "kernel_defines.h"
#ifdef __cplusplus
extern "C"
@ -111,29 +112,29 @@ extern "C"
* @brief Default Conversion Time in us
*/
#ifndef CONFIG_TMP00X_CONVERSION_TIME
#define CONFIG_TMP00X_CONVERSION_TIME (1E6)
#define CONFIG_TMP00X_CONVERSION_TIME (1E6)
#endif
/**
* @brief Default low power mode
*
* If set to 0, the device will be always-on
* If set to 1, the device will be put in low power mode between measurements.
* This adds a @c CONFIG_TMP00X_CONVERSION_TIME us delay to each measurement call
* for bringing the device out of standby.
* Set this to 1 to put the device in low power mode between measurements
* otherwise the device will always be on.
* Enabling this adds a @c CONFIG_TMP00X_CONVERSION_TIME us delay to each
* measurement call for bringing the device out of standby.
*/
#ifndef CONFIG_TMP00X_USE_LOW_POWER
#define CONFIG_TMP00X_USE_LOW_POWER (0)
#ifdef DOXYGEN
#define CONFIG_TMP00X_USE_LOW_POWER
#endif
/**
* @brief Default raw value mode
*
* If set to 0, measurements will be converted to Celsius.
* If set to 1, raw adc readings will be returned.
* Set this to 1 to return raw adc readings otherwise
* measurements will be converted to Celsius.
*/
#ifndef CONFIG_TMP00X_USE_RAW_VALUES
#define CONFIG_TMP00X_USE_RAW_VALUES (0)
#ifdef DOXYGEN
#define CONFIG_TMP00X_USE_RAW_VALUES
#endif
/** @} */

View File

@ -28,6 +28,7 @@
#include "tmp00x.h"
#include "tmp00x_params.h"
#include "kernel_defines.h"
/**
* @brief Define the number of configured sensors
@ -69,12 +70,12 @@ void auto_init_tmp00x(void)
LOG_ERROR("[auto_init_saul] error set active tmp00x #%u\n", i);
continue;
}
#if TMP00X_USE_LOW_POWER
if (tmp00x_set_standby(&tmp00x_devs[i]) != TMP00X_OK) {
LOG_ERROR("[auto_init_saul] error set standby tmp00x #%u\n", i);
continue;
}
#endif
if (IS_ACTIVE(CONFIG_TMP00X_USE_LOW_POWER)) {
if (tmp00x_set_standby(&tmp00x_devs[i]) != TMP00X_OK) {
LOG_ERROR("[auto_init_saul] error set standby tmp00x #%u\n", i);
continue;
}
}
saul_entries[i].dev = &(tmp00x_devs[i]);
saul_entries[i].name = tmp00x_saul_info[i].name;
saul_entries[i].driver = &tmp00x_saul_driver;

View File

@ -32,10 +32,12 @@
#include "periph/i2c.h"
#include "tmp00x.h"
#include "tmp00x_regs.h"
#if TMP00X_USE_LOW_POWER
#include "byteorder.h"
#include "kernel_defines.h"
#if IS_ACTIVE(CONFIG_TMP00X_USE_LOW_POWER)
#include "xtimer.h"
#endif
#include "byteorder.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
@ -202,12 +204,12 @@ int tmp00x_read_temperature(const tmp00x_t *dev, int16_t *ta, int16_t *to)
{
uint16_t drdy;
#if (!TMP00X_USE_RAW_VALUES)
#if (!IS_ACTIVE(CONFIG_TMP00X_USE_RAW_VALUES))
int16_t rawtemp, rawvolt;
float tamb, tobj;
#endif
#if TMP00X_USE_LOW_POWER
#if IS_ACTIVE(CONFIG_TMP00X_USE_LOW_POWER)
if (tmp00x_set_active(dev)) {
return TMP00X_ERROR;
}
@ -215,13 +217,13 @@ int tmp00x_read_temperature(const tmp00x_t *dev, int16_t *ta, int16_t *to)
#endif
int ret;
#if TMP00X_USE_RAW_VALUES
#if IS_ACTIVE(CONFIG_TMP00X_USE_RAW_VALUES)
if ((ret = tmp00x_read(dev, to, ta, &drdy)) < 0) {
return ret;
}
if (!drdy) {
#if TMP00X_USE_LOW_POWER
#if IS_ACTIVE(CONFIG_TMP00X_USE_LOW_POWER)
tmp00x_set_standby(dev);
#endif
return -TMP00X_ERROR;
@ -232,7 +234,7 @@ int ret;
}
if (!drdy) {
#if TMP00X_USE_LOW_POWER
#if IS_ACTIVE(CONFIG_TMP00X_USE_LOW_POWER)
tmp00x_set_standby(dev);
#endif
return -TMP00X_ERROR;
@ -243,11 +245,11 @@ int ret;
*to = (int16_t)(tobj*100);
#endif
#if TMP00X_USE_LOW_POWER
if (tmp00x_set_standby(dev)) {
return -TMP00X_ERROR;
if (IS_ACTIVE(CONFIG_TMP00X_USE_LOW_POWER)) {
if (tmp00x_set_standby(dev)) {
return -TMP00X_ERROR;
}
}
#endif
return TMP00X_OK;
}

View File

@ -22,6 +22,7 @@
#include "saul.h"
#include "tmp00x.h"
#include "kernel_defines.h"
static int read_temp(const void *dev, phydat_t *res)
{
@ -30,13 +31,14 @@ static int read_temp(const void *dev, phydat_t *res)
return -ECANCELED;
}
res->val[2] = 0;
#if TMP00X_USE_RAW_VALUES
res->unit = UNIT_NONE;
res->scale = 0;
#else
res->unit = UNIT_TEMP_C;
res->scale = -2;
#endif
if (IS_ACTIVE(CONFIG_TMP00X_USE_RAW_VALUES)) {
res->unit = UNIT_NONE;
res->scale = 0;
}
else {
res->unit = UNIT_TEMP_C;
res->scale = -2;
}
return 2;
}