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

View File

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

View File

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

View File

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