diff --git a/drivers/Makefile.dep b/drivers/Makefile.dep index 2d18519ac898c94592e147c6e865f45f937ae007..f5eff23f14be1687052ba609c8b8ac39af5a32e0 100644 --- a/drivers/Makefile.dep +++ b/drivers/Makefile.dep @@ -94,6 +94,10 @@ ifneq (,$(filter encx24j600,$(USEMODULE))) USEMODULE += xtimer endif +ifneq (,$(filter tmp006,$(USEMODULE))) + USEMODULE += xtimer +endif + ifneq (,$(filter ethos,$(USEMODULE))) USEMODULE += netdev_eth USEMODULE += random diff --git a/drivers/include/saul.h b/drivers/include/saul.h index 588251c0d4b36c1df864e17e18e31a9ecc3c2362..b9badb05b78f211cc123536d27fbe4135545468f 100644 --- a/drivers/include/saul.h +++ b/drivers/include/saul.h @@ -91,6 +91,7 @@ enum { SAUL_SENSE_PRESS = 0x89, /**< sensor: pressure */ SAUL_SENSE_ANALOG = 0x8a, /**< sensor: raw analog value */ SAUL_SENSE_UV = 0x8b, /**< sensor: UV index */ + SAUL_SENSE_OBJTEMP = 0x8c, /**< sensor: object temperature */ SAUL_CLASS_ANY = 0xff /**< any device - wildcard */ /* extend this list as needed... */ }; diff --git a/drivers/include/tmp006.h b/drivers/include/tmp006.h index c8de83b7509f810290fd6edaabf6ffeb8c4a709d..e37ccf0c0a0540bb9336b676cbf2f6f860293dcd 100644 --- a/drivers/include/tmp006.h +++ b/drivers/include/tmp006.h @@ -100,6 +100,28 @@ extern "C" #define TMP006_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 TMP006_CONVERSION_TIME us delay to each measurement call + * for bringing the device out of standby. + */ +#ifndef TMP006_USE_LOW_POWER +#define TMP006_USE_LOW_POWER (0) +#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. + */ +#ifndef TMP006_USE_RAW_VALUES +#define TMP006_USE_RAW_VALUES (0) +#endif + /** * @name Conversion rate and AVG sampling configuration * @{ diff --git a/drivers/saul/saul_str.c b/drivers/saul/saul_str.c index d912dec952efd8ae9f1b97653a32aa0c0bab45c2..0a10064394376f7a8199ce1a531697ba67606431 100644 --- a/drivers/saul/saul_str.c +++ b/drivers/saul/saul_str.c @@ -47,6 +47,7 @@ const char *saul_class_to_str(const uint8_t class_id) case SAUL_SENSE_COLOR: return "SENSE_COLOR"; case SAUL_SENSE_PRESS: return "SENSE_PRESS"; case SAUL_SENSE_ANALOG: return "SENSE_ANALOG"; + case SAUL_SENSE_OBJTEMP:return "SENSE_OBJTEMP"; case SAUL_CLASS_ANY: return "CLASS_ANY"; default: return "CLASS_UNKNOWN"; } diff --git a/drivers/tmp006/tmp006.c b/drivers/tmp006/tmp006.c index 131453de8da99c5b026559393dd6028f766907cf..6395ebe66a8cc9667c59cc8236e70fff980c38bc 100644 --- a/drivers/tmp006/tmp006.c +++ b/drivers/tmp006/tmp006.c @@ -31,6 +31,9 @@ #include "periph/i2c.h" #include "tmp006.h" #include "tmp006_regs.h" +#if TMP006_USE_LOW_POWER +#include "xtimer.h" +#endif #define ENABLE_DEBUG (0) #include "debug.h" @@ -226,9 +229,27 @@ void tmp006_convert(int16_t rawv, int16_t rawt, float *tamb, float *tobj) int tmp006_read_temperature(const tmp006_t *dev, int16_t *ta, int16_t *to) { + + uint8_t drdy; +#if (!TMP006_USE_RAW_VALUES) int16_t rawtemp, rawvolt; float tamb, tobj; - uint8_t drdy; +#endif + +#if TMP006_USE_LOW_POWER + if (tmp006_set_active(dev)) { + return TMP006_ERROR; + } + xtimer_usleep(TMP006_CONVERSION_TIME); +#endif + +#if TMP006_USE_RAW_VALUES + tmp006_read(dev, to, ta, &drdy); + + if (!drdy) { + return TMP006_ERROR; + } +#else tmp006_read(dev, &rawvolt, &rawtemp, &drdy); if (!drdy) { @@ -237,6 +258,13 @@ int tmp006_read_temperature(const tmp006_t *dev, int16_t *ta, int16_t *to) tmp006_convert(rawvolt, rawtemp, &tamb, &tobj); *ta = (int16_t)(tamb*100); *to = (int16_t)(tobj*100); +#endif + +#if TMP006_USE_LOW_POWER + if (tmp006_set_standby(dev)) { + return TMP006_ERROR; + } +#endif return TMP006_OK; } diff --git a/drivers/tmp006/tmp006_saul.c b/drivers/tmp006/tmp006_saul.c index 35274e9b3b5d24337fbcc165af7d1e5ce7096a82..03342b0392106fd650451f89da088ebd530311cc 100644 --- a/drivers/tmp006/tmp006_saul.c +++ b/drivers/tmp006/tmp006_saul.c @@ -30,14 +30,18 @@ static int read_temp(const void *dev, phydat_t *res) return -ECANCELED; } res->val[2] = 0; +#if TMP006_USE_RAW_VALUES + res->unit = UNIT_NONE; + res->scale = 0; +#else res->unit = UNIT_TEMP_C; res->scale = -2; - +#endif return 2; } const saul_driver_t tmp006_saul_driver = { .read = read_temp, .write = saul_notsup, - .type = SAUL_SENSE_TEMP, + .type = SAUL_SENSE_OBJTEMP, }; diff --git a/sys/auto_init/saul/auto_init_tmp006.c b/sys/auto_init/saul/auto_init_tmp006.c index fe8ec267e7e5a1aecf6129ff02f9285c6708a223..13f9219b3ae8ba1190d208e51ab4f7d19eab8203 100644 --- a/sys/auto_init/saul/auto_init_tmp006.c +++ b/sys/auto_init/saul/auto_init_tmp006.c @@ -60,7 +60,12 @@ void auto_init_tmp006(void) LOG_ERROR("[auto_init_saul] error set active tmp006 #%u\n", i); continue; } - +#if TMP006_USE_LOW_POWER + if (tmp006_set_standby(&tmp006_devs[i]) != TMP006_OK) { + LOG_ERROR("[auto_init_saul] error set standby tmp006 #%u\n", i); + continue; + } +#endif saul_entries[i].dev = &(tmp006_devs[i]); saul_entries[i].name = tmp006_saul_info[i].name; saul_entries[i].driver = &tmp006_saul_driver;