Skip to content

Commit

Permalink
drivers/tmp00x : Model as bool
Browse files Browse the repository at this point in the history
Model CONFIG_TMP00X_USE_LOW_POWER and CONFIG_TMP00X_USE_RAW_VALUES
as bool
  • Loading branch information
akshaim committed Apr 30, 2020
1 parent a6aa921 commit 02a68cd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 35 deletions.
23 changes: 12 additions & 11 deletions drivers/include/tmp00x.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "periph/i2c.h"
#include "kernel_defines.h"

#ifdef __cplusplus
extern "C"
Expand Down Expand Up @@ -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
/** @} */

Expand Down
13 changes: 7 additions & 6 deletions drivers/saul/init_devs/auto_init_tmp00x.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "tmp00x.h"
#include "tmp00x_params.h"
#include "kernel_defines.h"

/**
* @brief Define the number of configured sensors
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 13 additions & 11 deletions drivers/tmp00x/tmp00x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -202,26 +204,26 @@ 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;
}
xtimer_usleep(CONFIG_TMP00X_CONVERSION_TIME);
#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;
Expand All @@ -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;
Expand All @@ -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;
}
16 changes: 9 additions & 7 deletions drivers/tmp00x/tmp00x_saul.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "saul.h"
#include "tmp00x.h"
#include "kernel_defines.h"

static int read_temp(const void *dev, phydat_t *res)
{
Expand All @@ -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;
}

Expand Down

0 comments on commit 02a68cd

Please sign in to comment.