tmp006: optional raw values, low power mode, SAUL type
This commit is contained in:
parent
ce0a82fe34
commit
3dbe604d96
@ -94,6 +94,10 @@ ifneq (,$(filter encx24j600,$(USEMODULE)))
|
|||||||
USEMODULE += xtimer
|
USEMODULE += xtimer
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifneq (,$(filter tmp006,$(USEMODULE)))
|
||||||
|
USEMODULE += xtimer
|
||||||
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter ethos,$(USEMODULE)))
|
ifneq (,$(filter ethos,$(USEMODULE)))
|
||||||
USEMODULE += netdev_eth
|
USEMODULE += netdev_eth
|
||||||
USEMODULE += random
|
USEMODULE += random
|
||||||
|
|||||||
@ -91,6 +91,7 @@ enum {
|
|||||||
SAUL_SENSE_PRESS = 0x89, /**< sensor: pressure */
|
SAUL_SENSE_PRESS = 0x89, /**< sensor: pressure */
|
||||||
SAUL_SENSE_ANALOG = 0x8a, /**< sensor: raw analog value */
|
SAUL_SENSE_ANALOG = 0x8a, /**< sensor: raw analog value */
|
||||||
SAUL_SENSE_UV = 0x8b, /**< sensor: UV index */
|
SAUL_SENSE_UV = 0x8b, /**< sensor: UV index */
|
||||||
|
SAUL_SENSE_OBJTEMP = 0x8c, /**< sensor: object temperature */
|
||||||
SAUL_CLASS_ANY = 0xff /**< any device - wildcard */
|
SAUL_CLASS_ANY = 0xff /**< any device - wildcard */
|
||||||
/* extend this list as needed... */
|
/* extend this list as needed... */
|
||||||
};
|
};
|
||||||
|
|||||||
@ -100,6 +100,28 @@ extern "C"
|
|||||||
#define TMP006_CONVERSION_TIME (1E6)
|
#define TMP006_CONVERSION_TIME (1E6)
|
||||||
#endif
|
#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
|
* @name Conversion rate and AVG sampling configuration
|
||||||
* @{
|
* @{
|
||||||
|
|||||||
@ -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_COLOR: return "SENSE_COLOR";
|
||||||
case SAUL_SENSE_PRESS: return "SENSE_PRESS";
|
case SAUL_SENSE_PRESS: return "SENSE_PRESS";
|
||||||
case SAUL_SENSE_ANALOG: return "SENSE_ANALOG";
|
case SAUL_SENSE_ANALOG: return "SENSE_ANALOG";
|
||||||
|
case SAUL_SENSE_OBJTEMP:return "SENSE_OBJTEMP";
|
||||||
case SAUL_CLASS_ANY: return "CLASS_ANY";
|
case SAUL_CLASS_ANY: return "CLASS_ANY";
|
||||||
default: return "CLASS_UNKNOWN";
|
default: return "CLASS_UNKNOWN";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,9 @@
|
|||||||
#include "periph/i2c.h"
|
#include "periph/i2c.h"
|
||||||
#include "tmp006.h"
|
#include "tmp006.h"
|
||||||
#include "tmp006_regs.h"
|
#include "tmp006_regs.h"
|
||||||
|
#if TMP006_USE_LOW_POWER
|
||||||
|
#include "xtimer.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ENABLE_DEBUG (0)
|
#define ENABLE_DEBUG (0)
|
||||||
#include "debug.h"
|
#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)
|
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;
|
int16_t rawtemp, rawvolt;
|
||||||
float tamb, tobj;
|
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);
|
tmp006_read(dev, &rawvolt, &rawtemp, &drdy);
|
||||||
|
|
||||||
if (!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);
|
tmp006_convert(rawvolt, rawtemp, &tamb, &tobj);
|
||||||
*ta = (int16_t)(tamb*100);
|
*ta = (int16_t)(tamb*100);
|
||||||
*to = (int16_t)(tobj*100);
|
*to = (int16_t)(tobj*100);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if TMP006_USE_LOW_POWER
|
||||||
|
if (tmp006_set_standby(dev)) {
|
||||||
|
return TMP006_ERROR;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return TMP006_OK;
|
return TMP006_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,14 +30,18 @@ static int read_temp(const void *dev, phydat_t *res)
|
|||||||
return -ECANCELED;
|
return -ECANCELED;
|
||||||
}
|
}
|
||||||
res->val[2] = 0;
|
res->val[2] = 0;
|
||||||
|
#if TMP006_USE_RAW_VALUES
|
||||||
|
res->unit = UNIT_NONE;
|
||||||
|
res->scale = 0;
|
||||||
|
#else
|
||||||
res->unit = UNIT_TEMP_C;
|
res->unit = UNIT_TEMP_C;
|
||||||
res->scale = -2;
|
res->scale = -2;
|
||||||
|
#endif
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
const saul_driver_t tmp006_saul_driver = {
|
const saul_driver_t tmp006_saul_driver = {
|
||||||
.read = read_temp,
|
.read = read_temp,
|
||||||
.write = saul_notsup,
|
.write = saul_notsup,
|
||||||
.type = SAUL_SENSE_TEMP,
|
.type = SAUL_SENSE_OBJTEMP,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -60,7 +60,12 @@ void auto_init_tmp006(void)
|
|||||||
LOG_ERROR("[auto_init_saul] error set active tmp006 #%u\n", i);
|
LOG_ERROR("[auto_init_saul] error set active tmp006 #%u\n", i);
|
||||||
continue;
|
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].dev = &(tmp006_devs[i]);
|
||||||
saul_entries[i].name = tmp006_saul_info[i].name;
|
saul_entries[i].name = tmp006_saul_info[i].name;
|
||||||
saul_entries[i].driver = &tmp006_saul_driver;
|
saul_entries[i].driver = &tmp006_saul_driver;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user