drivers: sensor: Migrate to new logger
Move all sensor drivers and samples to new logging system. Signed-off-by: Punit Vara <punit.vara@intel.com>
This commit is contained in:
parent
86e69ddd8b
commit
e5620a2b87
129 changed files with 928 additions and 798 deletions
|
@ -13,19 +13,9 @@ menuconfig SENSOR
|
||||||
|
|
||||||
if SENSOR
|
if SENSOR
|
||||||
|
|
||||||
config SYS_LOG_SENSOR_LEVEL
|
module = SENSOR
|
||||||
int "Sensor Log level"
|
module-str = sensor
|
||||||
depends on SYS_LOG
|
source "subsys/logging/Kconfig.template.log_config"
|
||||||
default 0
|
|
||||||
range 0 4
|
|
||||||
help
|
|
||||||
Sets log level for Sensor Device Drivers.
|
|
||||||
Levels are:
|
|
||||||
0 OFF, do not write
|
|
||||||
1 ERROR, only write SYS_LOG_ERR
|
|
||||||
2 WARNING, write SYS_LOG_WRN in addition to previous level
|
|
||||||
3 INFO, write SYS_LOG_INF in addition to previous levels
|
|
||||||
4 DEBUG, write SYS_LOG_DBG in addition to previous levels
|
|
||||||
|
|
||||||
config SENSOR_INIT_PRIORITY
|
config SENSOR_INIT_PRIORITY
|
||||||
int "Sensor init priority"
|
int "Sensor init priority"
|
||||||
|
|
|
@ -11,8 +11,13 @@
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
|
||||||
#include "adt7420.h"
|
#include "adt7420.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_REGISTER(ADT7420);
|
||||||
|
|
||||||
static int adt7420_temp_reg_read(struct device *dev, u8_t reg, s16_t *val)
|
static int adt7420_temp_reg_read(struct device *dev, u8_t reg, s16_t *val)
|
||||||
{
|
{
|
||||||
struct adt7420_data *drv_data = dev->driver_data;
|
struct adt7420_data *drv_data = dev->driver_data;
|
||||||
|
@ -71,7 +76,7 @@ static int adt7420_attr_set(struct device *dev,
|
||||||
ADT7420_REG_CONFIG,
|
ADT7420_REG_CONFIG,
|
||||||
ADT7420_CONFIG_OP_MODE(~0),
|
ADT7420_CONFIG_OP_MODE(~0),
|
||||||
ADT7420_CONFIG_OP_MODE(val8)) < 0) {
|
ADT7420_CONFIG_OP_MODE(val8)) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set attribute!");
|
LOG_DBG("Failed to set attribute!");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +97,7 @@ static int adt7420_attr_set(struct device *dev,
|
||||||
value = (value / ADT7420_TEMP_SCALE) << 1;
|
value = (value / ADT7420_TEMP_SCALE) << 1;
|
||||||
|
|
||||||
if (adt7420_temp_reg_write(dev, reg, value) < 0) {
|
if (adt7420_temp_reg_write(dev, reg, value) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set attribute!");
|
LOG_DBG("Failed to set attribute!");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +190,7 @@ static int adt7420_probe(struct device *dev)
|
||||||
|
|
||||||
#ifdef CONFIG_ADT7420_TRIGGER
|
#ifdef CONFIG_ADT7420_TRIGGER
|
||||||
if (adt7420_init_interrupt(dev) < 0) {
|
if (adt7420_init_interrupt(dev) < 0) {
|
||||||
SYS_LOG_ERR("Failed to initialize interrupt!");
|
LOG_ERR("Failed to initialize interrupt!");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -200,7 +205,7 @@ static int adt7420_init(struct device *dev)
|
||||||
|
|
||||||
drv_data->i2c = device_get_binding(cfg->i2c_port);
|
drv_data->i2c = device_get_binding(cfg->i2c_port);
|
||||||
if (drv_data->i2c == NULL) {
|
if (drv_data->i2c == NULL) {
|
||||||
SYS_LOG_DBG("Failed to get pointer to %s device!",
|
LOG_DBG("Failed to get pointer to %s device!",
|
||||||
cfg->i2c_port);
|
cfg->i2c_port);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,8 +97,5 @@ int adt7420_trigger_set(struct device *dev,
|
||||||
int adt7420_init_interrupt(struct device *dev);
|
int adt7420_init_interrupt(struct device *dev);
|
||||||
#endif /* CONFIG_ADT7420_TRIGGER */
|
#endif /* CONFIG_ADT7420_TRIGGER */
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "ADT7420"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_ADT7420_ADT7420_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_ADT7420_ADT7420_H_ */
|
||||||
|
|
|
@ -10,8 +10,13 @@
|
||||||
#include <misc/util.h>
|
#include <misc/util.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
|
|
||||||
#include "adt7420.h"
|
#include "adt7420.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(ADT7420);
|
||||||
|
|
||||||
static void adt7420_thread_cb(void *arg)
|
static void adt7420_thread_cb(void *arg)
|
||||||
{
|
{
|
||||||
struct device *dev = arg;
|
struct device *dev = arg;
|
||||||
|
@ -84,7 +89,7 @@ int adt7420_trigger_set(struct device *dev,
|
||||||
drv_data->th_handler = handler;
|
drv_data->th_handler = handler;
|
||||||
drv_data->th_trigger = *trig;
|
drv_data->th_trigger = *trig;
|
||||||
} else {
|
} else {
|
||||||
SYS_LOG_ERR("Unsupported sensor trigger");
|
LOG_ERR("Unsupported sensor trigger");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +105,7 @@ int adt7420_init_interrupt(struct device *dev)
|
||||||
|
|
||||||
drv_data->gpio = device_get_binding(cfg->gpio_port);
|
drv_data->gpio = device_get_binding(cfg->gpio_port);
|
||||||
if (drv_data->gpio == NULL) {
|
if (drv_data->gpio == NULL) {
|
||||||
SYS_LOG_DBG("Failed to get pointer to %s device!",
|
LOG_DBG("Failed to get pointer to %s device!",
|
||||||
cfg->gpio_port);
|
cfg->gpio_port);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -114,7 +119,7 @@ int adt7420_init_interrupt(struct device *dev)
|
||||||
BIT(cfg->int_gpio));
|
BIT(cfg->int_gpio));
|
||||||
|
|
||||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set gpio callback!");
|
LOG_DBG("Failed to set gpio callback!");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,12 @@
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
#include <spi.h>
|
#include <spi.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "adxl362.h"
|
#include "adxl362.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(ADXL362);
|
||||||
|
|
||||||
static struct adxl362_data adxl362_data;
|
static struct adxl362_data adxl362_data;
|
||||||
|
|
||||||
|
@ -213,7 +216,7 @@ static int axl362_acc_config(struct device *dev, enum sensor_channel chan,
|
||||||
|
|
||||||
range_reg = adxl362_range_to_reg_val(sensor_ms2_to_g(val));
|
range_reg = adxl362_range_to_reg_val(sensor_ms2_to_g(val));
|
||||||
if (range_reg < 0) {
|
if (range_reg < 0) {
|
||||||
SYS_LOG_DBG("invalid range requested.");
|
LOG_DBG("invalid range requested.");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +232,7 @@ static int axl362_acc_config(struct device *dev, enum sensor_channel chan,
|
||||||
out_rate = adxl362_freq_to_odr_val(val->val1,
|
out_rate = adxl362_freq_to_odr_val(val->val1,
|
||||||
val->val2 / 1000);
|
val->val2 / 1000);
|
||||||
if (out_rate < 0) {
|
if (out_rate < 0) {
|
||||||
SYS_LOG_DBG("invalid output rate.");
|
LOG_DBG("invalid output rate.");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +241,7 @@ static int axl362_acc_config(struct device *dev, enum sensor_channel chan,
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
SYS_LOG_DBG("Accel attribute not supported.");
|
LOG_DBG("Accel attribute not supported.");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +259,7 @@ static int adxl362_attr_set(struct device *dev, enum sensor_channel chan,
|
||||||
return axl362_acc_config(dev, chan, attr, val);
|
return axl362_acc_config(dev, chan, attr, val);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
SYS_LOG_DBG("attr_set() not supported on this channel.");
|
LOG_DBG("attr_set() not supported on this channel.");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,7 +576,7 @@ static int adxl362_init(struct device *dev)
|
||||||
|
|
||||||
data->spi = device_get_binding(CONFIG_ADXL362_SPI_DEV_NAME);
|
data->spi = device_get_binding(CONFIG_ADXL362_SPI_DEV_NAME);
|
||||||
if (!data->spi) {
|
if (!data->spi) {
|
||||||
SYS_LOG_DBG("spi device not found: %s",
|
LOG_DBG("spi device not found: %s",
|
||||||
CONFIG_ADXL362_SPI_DEV_NAME);
|
CONFIG_ADXL362_SPI_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,4 @@ struct adxl362_data {
|
||||||
# define ADXL362_DEFAULT_ODR_ACC ADXL362_ODR_400_HZ
|
# define ADXL362_DEFAULT_ODR_ACC ADXL362_ODR_400_HZ
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "ADXL362"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_ADXL362_ADXL362_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_ADXL362_ADXL362_H_ */
|
||||||
|
|
|
@ -14,9 +14,13 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <spi.h>
|
#include <spi.h>
|
||||||
#include <i2c.h>
|
#include <i2c.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "adxl372.h"
|
#include "adxl372.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(ADXL372);
|
||||||
|
|
||||||
static int adxl372_bus_access(struct device *dev, u8_t reg,
|
static int adxl372_bus_access(struct device *dev, u8_t reg,
|
||||||
void *data, size_t length)
|
void *data, size_t length)
|
||||||
{
|
{
|
||||||
|
@ -115,7 +119,7 @@ static int adxl372_reg_write(struct device *dev,
|
||||||
u8_t reg_addr,
|
u8_t reg_addr,
|
||||||
u8_t reg_data)
|
u8_t reg_data)
|
||||||
{
|
{
|
||||||
SYS_LOG_DBG("[0x%X] = 0x%X", reg_addr, reg_data);
|
LOG_DBG("[0x%X] = 0x%X", reg_addr, reg_data);
|
||||||
|
|
||||||
return adxl372_bus_access(dev, ADXL372_REG_WRITE(reg_addr),
|
return adxl372_bus_access(dev, ADXL372_REG_WRITE(reg_addr),
|
||||||
®_data, 1);
|
®_data, 1);
|
||||||
|
@ -664,7 +668,7 @@ static int adxl372_attr_set_thresh(struct device *dev, enum sensor_channel chan,
|
||||||
case SENSOR_CHAN_ACCEL_XYZ:
|
case SENSOR_CHAN_ACCEL_XYZ:
|
||||||
return adxl372_set_activity_threshold_xyz(dev, reg, &threshold);
|
return adxl372_set_activity_threshold_xyz(dev, reg, &threshold);
|
||||||
default:
|
default:
|
||||||
SYS_LOG_ERR("attr_set() not supported on this channel");
|
LOG_ERR("attr_set() not supported on this channel");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -759,7 +763,7 @@ static int adxl372_probe(struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev_id != ADXL372_DEVID_VAL || part_id != ADXL372_PARTID_VAL) {
|
if (dev_id != ADXL372_DEVID_VAL || part_id != ADXL372_PARTID_VAL) {
|
||||||
SYS_LOG_ERR("failed to read id (0x%X:0x%X)", dev_id, part_id);
|
LOG_ERR("failed to read id (0x%X:0x%X)", dev_id, part_id);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -770,7 +774,7 @@ static int adxl372_probe(struct device *dev)
|
||||||
*/
|
*/
|
||||||
adxl372_reg_read(dev, ADXL372_REVID, &dev_id);
|
adxl372_reg_read(dev, ADXL372_REVID, &dev_id);
|
||||||
if (dev_id < 3) {
|
if (dev_id < 3) {
|
||||||
SYS_LOG_WRN("The ADXL372 Rev %u only supports point to point I2C communication!",
|
LOG_WRN("The ADXL372 Rev %u only supports point to point I2C communication!",
|
||||||
dev_id);
|
dev_id);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -852,7 +856,7 @@ static int adxl372_probe(struct device *dev)
|
||||||
|
|
||||||
#ifdef CONFIG_ADXL372_TRIGGER
|
#ifdef CONFIG_ADXL372_TRIGGER
|
||||||
if (adxl372_init_interrupt(dev) < 0) {
|
if (adxl372_init_interrupt(dev) < 0) {
|
||||||
SYS_LOG_ERR("Failed to initialize interrupt!");
|
LOG_ERR("Failed to initialize interrupt!");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -878,7 +882,7 @@ static int adxl372_init(struct device *dev)
|
||||||
#ifdef CONFIG_ADXL372_I2C
|
#ifdef CONFIG_ADXL372_I2C
|
||||||
data->bus = device_get_binding(cfg->i2c_port);
|
data->bus = device_get_binding(cfg->i2c_port);
|
||||||
if (data->bus == NULL) {
|
if (data->bus == NULL) {
|
||||||
SYS_LOG_ERR("Failed to get pointer to %s device!",
|
LOG_ERR("Failed to get pointer to %s device!",
|
||||||
cfg->i2c_port);
|
cfg->i2c_port);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -886,7 +890,7 @@ static int adxl372_init(struct device *dev)
|
||||||
#ifdef CONFIG_ADXL372_SPI
|
#ifdef CONFIG_ADXL372_SPI
|
||||||
data->bus = device_get_binding(cfg->spi_port);
|
data->bus = device_get_binding(cfg->spi_port);
|
||||||
if (!data->bus) {
|
if (!data->bus) {
|
||||||
SYS_LOG_ERR("spi device not found: %s", cfg->spi_port);
|
LOG_ERR("spi device not found: %s", cfg->spi_port);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
/* CPOL=0, CPHA=0, max 10MHz */
|
/* CPOL=0, CPHA=0, max 10MHz */
|
||||||
|
@ -899,7 +903,7 @@ static int adxl372_init(struct device *dev)
|
||||||
|
|
||||||
data->adxl372_cs_ctrl.gpio_dev = device_get_binding(cfg->gpio_cs_port);
|
data->adxl372_cs_ctrl.gpio_dev = device_get_binding(cfg->gpio_cs_port);
|
||||||
if (!data->adxl372_cs_ctrl.gpio_dev) {
|
if (!data->adxl372_cs_ctrl.gpio_dev) {
|
||||||
SYS_LOG_ERR("Unable to get GPIO SPI CS device");
|
LOG_ERR("Unable to get GPIO SPI CS device");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -368,7 +368,4 @@ int adxl372_trigger_set(struct device *dev,
|
||||||
int adxl372_init_interrupt(struct device *dev);
|
int adxl372_init_interrupt(struct device *dev);
|
||||||
#endif /* CONFIG_ADT7420_TRIGGER */
|
#endif /* CONFIG_ADT7420_TRIGGER */
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "ADXL372"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_ADXL372_ADXL372_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_ADXL372_ADXL372_H_ */
|
||||||
|
|
|
@ -11,6 +11,10 @@
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
#include "adxl372.h"
|
#include "adxl372.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(ADXL372);
|
||||||
|
|
||||||
static void adxl372_thread_cb(void *arg)
|
static void adxl372_thread_cb(void *arg)
|
||||||
{
|
{
|
||||||
struct device *dev = arg;
|
struct device *dev = arg;
|
||||||
|
@ -109,7 +113,7 @@ int adxl372_trigger_set(struct device *dev,
|
||||||
int_mask = ADXL372_INT1_MAP_DATA_RDY_MSK;
|
int_mask = ADXL372_INT1_MAP_DATA_RDY_MSK;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SYS_LOG_ERR("Unsupported sensor trigger");
|
LOG_ERR("Unsupported sensor trigger");
|
||||||
ret = -ENOTSUP;
|
ret = -ENOTSUP;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -136,7 +140,7 @@ int adxl372_init_interrupt(struct device *dev)
|
||||||
|
|
||||||
drv_data->gpio = device_get_binding(cfg->gpio_port);
|
drv_data->gpio = device_get_binding(cfg->gpio_port);
|
||||||
if (drv_data->gpio == NULL) {
|
if (drv_data->gpio == NULL) {
|
||||||
SYS_LOG_ERR("Failed to get pointer to %s device!",
|
LOG_ERR("Failed to get pointer to %s device!",
|
||||||
cfg->gpio_port);
|
cfg->gpio_port);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -150,7 +154,7 @@ int adxl372_init_interrupt(struct device *dev)
|
||||||
BIT(cfg->int_gpio));
|
BIT(cfg->int_gpio));
|
||||||
|
|
||||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||||
SYS_LOG_ERR("Failed to set gpio callback!");
|
LOG_ERR("Failed to set gpio callback!");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,13 @@
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
#include <misc/util.h>
|
#include <misc/util.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "ak8975.h"
|
#include "ak8975.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(AK8975);
|
||||||
|
|
||||||
static int ak8975_sample_fetch(struct device *dev, enum sensor_channel chan)
|
static int ak8975_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
{
|
{
|
||||||
struct ak8975_data *drv_data = dev->driver_data;
|
struct ak8975_data *drv_data = dev->driver_data;
|
||||||
|
@ -23,7 +27,7 @@ static int ak8975_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
|
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, CONFIG_AK8975_I2C_ADDR,
|
if (i2c_reg_write_byte(drv_data->i2c, CONFIG_AK8975_I2C_ADDR,
|
||||||
AK8975_REG_CNTL, AK8975_MODE_MEASURE) < 0) {
|
AK8975_REG_CNTL, AK8975_MODE_MEASURE) < 0) {
|
||||||
SYS_LOG_ERR("Failed to start measurement.");
|
LOG_ERR("Failed to start measurement.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +35,7 @@ static int ak8975_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
|
|
||||||
if (i2c_burst_read(drv_data->i2c, CONFIG_AK8975_I2C_ADDR,
|
if (i2c_burst_read(drv_data->i2c, CONFIG_AK8975_I2C_ADDR,
|
||||||
AK8975_REG_DATA_START, buf, 6) < 0) {
|
AK8975_REG_DATA_START, buf, 6) < 0) {
|
||||||
SYS_LOG_ERR("Failed to read sample data.");
|
LOG_ERR("Failed to read sample data.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,13 +94,13 @@ static int ak8975_read_adjustment_data(struct ak8975_data *drv_data)
|
||||||
|
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, CONFIG_AK8975_I2C_ADDR,
|
if (i2c_reg_write_byte(drv_data->i2c, CONFIG_AK8975_I2C_ADDR,
|
||||||
AK8975_REG_CNTL, AK8975_MODE_FUSE_ACCESS) < 0) {
|
AK8975_REG_CNTL, AK8975_MODE_FUSE_ACCESS) < 0) {
|
||||||
SYS_LOG_ERR("Failed to set chip in fuse access mode.");
|
LOG_ERR("Failed to set chip in fuse access mode.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_burst_read(drv_data->i2c, CONFIG_AK8975_I2C_ADDR,
|
if (i2c_burst_read(drv_data->i2c, CONFIG_AK8975_I2C_ADDR,
|
||||||
AK8975_REG_ADJ_DATA_START, buf, 3) < 0) {
|
AK8975_REG_ADJ_DATA_START, buf, 3) < 0) {
|
||||||
SYS_LOG_ERR("Failed to read adjustment data.");
|
LOG_ERR("Failed to read adjustment data.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +118,7 @@ int ak8975_init(struct device *dev)
|
||||||
|
|
||||||
drv_data->i2c = device_get_binding(CONFIG_AK8975_I2C_MASTER_DEV_NAME);
|
drv_data->i2c = device_get_binding(CONFIG_AK8975_I2C_MASTER_DEV_NAME);
|
||||||
if (drv_data->i2c == NULL) {
|
if (drv_data->i2c == NULL) {
|
||||||
SYS_LOG_ERR("Failed to get pointer to %s device!",
|
LOG_ERR("Failed to get pointer to %s device!",
|
||||||
CONFIG_AK8975_I2C_MASTER_DEV_NAME);
|
CONFIG_AK8975_I2C_MASTER_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +128,7 @@ int ak8975_init(struct device *dev)
|
||||||
if (i2c_reg_update_byte(drv_data->i2c, MPU9150_I2C_ADDR,
|
if (i2c_reg_update_byte(drv_data->i2c, MPU9150_I2C_ADDR,
|
||||||
MPU9150_REG_PWR_MGMT1, MPU9150_SLEEP_EN,
|
MPU9150_REG_PWR_MGMT1, MPU9150_SLEEP_EN,
|
||||||
0) < 0) {
|
0) < 0) {
|
||||||
SYS_LOG_ERR("Failed to wake up MPU9150 chip.");
|
LOG_ERR("Failed to wake up MPU9150 chip.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +136,7 @@ int ak8975_init(struct device *dev)
|
||||||
if (i2c_reg_update_byte(drv_data->i2c, MPU9150_I2C_ADDR,
|
if (i2c_reg_update_byte(drv_data->i2c, MPU9150_I2C_ADDR,
|
||||||
MPU9150_REG_BYPASS_CFG, MPU9150_I2C_BYPASS_EN,
|
MPU9150_REG_BYPASS_CFG, MPU9150_I2C_BYPASS_EN,
|
||||||
MPU9150_I2C_BYPASS_EN) < 0) {
|
MPU9150_I2C_BYPASS_EN) < 0) {
|
||||||
SYS_LOG_ERR("Failed to enable pass-through mode for MPU9150.");
|
LOG_ERR("Failed to enable pass-through mode for MPU9150.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -140,12 +144,12 @@ int ak8975_init(struct device *dev)
|
||||||
/* check chip ID */
|
/* check chip ID */
|
||||||
if (i2c_reg_read_byte(drv_data->i2c, CONFIG_AK8975_I2C_ADDR,
|
if (i2c_reg_read_byte(drv_data->i2c, CONFIG_AK8975_I2C_ADDR,
|
||||||
AK8975_REG_CHIP_ID, &id) < 0) {
|
AK8975_REG_CHIP_ID, &id) < 0) {
|
||||||
SYS_LOG_ERR("Failed to read chip ID.");
|
LOG_ERR("Failed to read chip ID.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id != AK8975_CHIP_ID) {
|
if (id != AK8975_CHIP_ID) {
|
||||||
SYS_LOG_ERR("Invalid chip ID.");
|
LOG_ERR("Invalid chip ID.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,6 @@
|
||||||
|
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "AK8975"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#define AK8975_REG_CHIP_ID 0x00
|
#define AK8975_REG_CHIP_ID 0x00
|
||||||
#define AK8975_CHIP_ID 0x48
|
#define AK8975_CHIP_ID 0x48
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,13 @@
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "amg88xx.h"
|
#include "amg88xx.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(AMG88XX);
|
||||||
|
|
||||||
static int amg88xx_sample_fetch(struct device *dev, enum sensor_channel chan)
|
static int amg88xx_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
{
|
{
|
||||||
struct amg88xx_data *drv_data = dev->driver_data;
|
struct amg88xx_data *drv_data = dev->driver_data;
|
||||||
|
@ -63,11 +67,11 @@ static int amg88xx_init_device(struct device *dev)
|
||||||
u8_t tmp;
|
u8_t tmp;
|
||||||
|
|
||||||
if (amg88xx_reg_read(drv_data, AMG88XX_PCLT, &tmp)) {
|
if (amg88xx_reg_read(drv_data, AMG88XX_PCLT, &tmp)) {
|
||||||
SYS_LOG_ERR("Failed to read Power mode");
|
LOG_ERR("Failed to read Power mode");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_DBG("Power mode 0x%02x", tmp);
|
LOG_DBG("Power mode 0x%02x", tmp);
|
||||||
if (tmp != AMG88XX_PCLT_NORMAL_MODE) {
|
if (tmp != AMG88XX_PCLT_NORMAL_MODE) {
|
||||||
if (amg88xx_reg_write(drv_data, AMG88XX_PCLT,
|
if (amg88xx_reg_write(drv_data, AMG88XX_PCLT,
|
||||||
AMG88XX_PCLT_NORMAL_MODE)) {
|
AMG88XX_PCLT_NORMAL_MODE)) {
|
||||||
|
@ -87,7 +91,7 @@ static int amg88xx_init_device(struct device *dev)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_DBG("");
|
LOG_DBG("");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -98,20 +102,20 @@ int amg88xx_init(struct device *dev)
|
||||||
|
|
||||||
drv_data->i2c = device_get_binding(CONFIG_AMG88XX_I2C_MASTER_DEV_NAME);
|
drv_data->i2c = device_get_binding(CONFIG_AMG88XX_I2C_MASTER_DEV_NAME);
|
||||||
if (drv_data->i2c == NULL) {
|
if (drv_data->i2c == NULL) {
|
||||||
SYS_LOG_ERR("Failed to get pointer to %s device!",
|
LOG_ERR("Failed to get pointer to %s device!",
|
||||||
CONFIG_AMG88XX_I2C_MASTER_DEV_NAME);
|
CONFIG_AMG88XX_I2C_MASTER_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (amg88xx_init_device(dev) < 0) {
|
if (amg88xx_init_device(dev) < 0) {
|
||||||
SYS_LOG_ERR("Failed to initialize device!");
|
LOG_ERR("Failed to initialize device!");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef CONFIG_AMG88XX_TRIGGER
|
#ifdef CONFIG_AMG88XX_TRIGGER
|
||||||
if (amg88xx_init_interrupt(dev) < 0) {
|
if (amg88xx_init_interrupt(dev) < 0) {
|
||||||
SYS_LOG_ERR("Failed to initialize interrupt!");
|
LOG_ERR("Failed to initialize interrupt!");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -136,9 +136,4 @@ int amg88xx_trigger_set(struct device *dev,
|
||||||
int amg88xx_init_interrupt(struct device *dev);
|
int amg88xx_init_interrupt(struct device *dev);
|
||||||
#endif /* CONFIG_AMG88XX_TRIGGER */
|
#endif /* CONFIG_AMG88XX_TRIGGER */
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "AMG88XX"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
|
|
||||||
extern struct amg88xx_data amg88xx_driver;
|
extern struct amg88xx_data amg88xx_driver;
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(AMG88XX);
|
||||||
|
|
||||||
int amg88xx_attr_set(struct device *dev,
|
int amg88xx_attr_set(struct device *dev,
|
||||||
enum sensor_channel chan,
|
enum sensor_channel chan,
|
||||||
enum sensor_attribute attr,
|
enum sensor_attribute attr,
|
||||||
|
@ -30,7 +34,7 @@ int amg88xx_attr_set(struct device *dev,
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_DBG("set threshold to %d", int_level);
|
LOG_DBG("set threshold to %d", int_level);
|
||||||
|
|
||||||
if (attr == SENSOR_ATTR_UPPER_THRESH) {
|
if (attr == SENSOR_ATTR_UPPER_THRESH) {
|
||||||
intl_reg = AMG88XX_INTHL;
|
intl_reg = AMG88XX_INTHL;
|
||||||
|
@ -43,12 +47,12 @@ int amg88xx_attr_set(struct device *dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (amg88xx_reg_write(drv_data, intl_reg, (u8_t)int_level)) {
|
if (amg88xx_reg_write(drv_data, intl_reg, (u8_t)int_level)) {
|
||||||
SYS_LOG_DBG("Failed to set INTxL attribute!");
|
LOG_DBG("Failed to set INTxL attribute!");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (amg88xx_reg_write(drv_data, inth_reg, (u8_t)(int_level >> 8))) {
|
if (amg88xx_reg_write(drv_data, inth_reg, (u8_t)(int_level >> 8))) {
|
||||||
SYS_LOG_DBG("Failed to set INTxH attribute!");
|
LOG_DBG("Failed to set INTxH attribute!");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +133,7 @@ int amg88xx_trigger_set(struct device *dev,
|
||||||
drv_data->th_handler = handler;
|
drv_data->th_handler = handler;
|
||||||
drv_data->th_trigger = *trig;
|
drv_data->th_trigger = *trig;
|
||||||
} else {
|
} else {
|
||||||
SYS_LOG_ERR("Unsupported sensor trigger");
|
LOG_ERR("Unsupported sensor trigger");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +150,7 @@ int amg88xx_init_interrupt(struct device *dev)
|
||||||
/* setup gpio interrupt */
|
/* setup gpio interrupt */
|
||||||
drv_data->gpio = device_get_binding(CONFIG_AMG88XX_GPIO_DEV_NAME);
|
drv_data->gpio = device_get_binding(CONFIG_AMG88XX_GPIO_DEV_NAME);
|
||||||
if (drv_data->gpio == NULL) {
|
if (drv_data->gpio == NULL) {
|
||||||
SYS_LOG_DBG("Failed to get pointer to %s device!",
|
LOG_DBG("Failed to get pointer to %s device!",
|
||||||
CONFIG_AMG88XX_GPIO_DEV_NAME);
|
CONFIG_AMG88XX_GPIO_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -160,7 +164,7 @@ int amg88xx_init_interrupt(struct device *dev)
|
||||||
BIT(CONFIG_AMG88XX_GPIO_PIN_NUM));
|
BIT(CONFIG_AMG88XX_GPIO_PIN_NUM));
|
||||||
|
|
||||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set gpio callback!");
|
LOG_DBG("Failed to set gpio callback!");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,13 @@
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "apds9960.h"
|
#include "apds9960.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(APDS9960);
|
||||||
|
|
||||||
static void apds9960_gpio_callback(struct device *dev,
|
static void apds9960_gpio_callback(struct device *dev,
|
||||||
struct gpio_callback *cb, u32_t pins)
|
struct gpio_callback *cb, u32_t pins)
|
||||||
{
|
{
|
||||||
|
@ -41,7 +45,7 @@ static int apds9960_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
u8_t status;
|
u8_t status;
|
||||||
|
|
||||||
if (chan != SENSOR_CHAN_ALL) {
|
if (chan != SENSOR_CHAN_ALL) {
|
||||||
SYS_LOG_ERR("Unsupported sensor channel");
|
LOG_ERR("Unsupported sensor channel");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +57,7 @@ static int apds9960_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
APDS9960_ENABLE_REG,
|
APDS9960_ENABLE_REG,
|
||||||
APDS9960_ENABLE_PON | APDS9960_ENABLE_AIEN,
|
APDS9960_ENABLE_PON | APDS9960_ENABLE_AIEN,
|
||||||
APDS9960_ENABLE_PON | APDS9960_ENABLE_AIEN)) {
|
APDS9960_ENABLE_PON | APDS9960_ENABLE_AIEN)) {
|
||||||
SYS_LOG_ERR("Power on bit not set.");
|
LOG_ERR("Power on bit not set.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +69,7 @@ static int apds9960_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_DBG("status: 0x%x", status);
|
LOG_DBG("status: 0x%x", status);
|
||||||
if (status & APDS9960_STATUS_PINT) {
|
if (status & APDS9960_STATUS_PINT) {
|
||||||
if (i2c_reg_read_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_read_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_PDATA_REG, &data->pdata)) {
|
APDS9960_PDATA_REG, &data->pdata)) {
|
||||||
|
@ -141,21 +145,21 @@ static int apds9960_proxy_setup(struct device *dev, int gain)
|
||||||
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_POFFSET_UR_REG,
|
APDS9960_POFFSET_UR_REG,
|
||||||
APDS9960_DEFAULT_POFFSET_UR)) {
|
APDS9960_DEFAULT_POFFSET_UR)) {
|
||||||
SYS_LOG_ERR("Default offset UR not set ");
|
LOG_ERR("Default offset UR not set ");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_POFFSET_DL_REG,
|
APDS9960_POFFSET_DL_REG,
|
||||||
APDS9960_DEFAULT_POFFSET_DL)) {
|
APDS9960_DEFAULT_POFFSET_DL)) {
|
||||||
SYS_LOG_ERR("Default offset DL not set ");
|
LOG_ERR("Default offset DL not set ");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_PPULSE_REG,
|
APDS9960_PPULSE_REG,
|
||||||
APDS9960_DEFAULT_PROX_PPULSE)) {
|
APDS9960_DEFAULT_PROX_PPULSE)) {
|
||||||
SYS_LOG_ERR("Default pulse count not set ");
|
LOG_ERR("Default pulse count not set ");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,33 +167,33 @@ static int apds9960_proxy_setup(struct device *dev, int gain)
|
||||||
APDS9960_CONTROL_REG,
|
APDS9960_CONTROL_REG,
|
||||||
APDS9960_CONTROL_LDRIVE,
|
APDS9960_CONTROL_LDRIVE,
|
||||||
APDS9960_DEFAULT_LDRIVE)) {
|
APDS9960_DEFAULT_LDRIVE)) {
|
||||||
SYS_LOG_ERR("LED Drive Strength not set");
|
LOG_ERR("LED Drive Strength not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_update_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_update_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_CONTROL_REG, APDS9960_CONTROL_PGAIN,
|
APDS9960_CONTROL_REG, APDS9960_CONTROL_PGAIN,
|
||||||
(gain & APDS9960_PGAIN_8X))) {
|
(gain & APDS9960_PGAIN_8X))) {
|
||||||
SYS_LOG_ERR("Gain is not set");
|
LOG_ERR("Gain is not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_PILT_REG, APDS9960_DEFAULT_PILT)) {
|
APDS9960_PILT_REG, APDS9960_DEFAULT_PILT)) {
|
||||||
SYS_LOG_ERR("Low threshold not set");
|
LOG_ERR("Low threshold not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_PIHT_REG, APDS9960_DEFAULT_PIHT)) {
|
APDS9960_PIHT_REG, APDS9960_DEFAULT_PIHT)) {
|
||||||
SYS_LOG_ERR("High threshold not set");
|
LOG_ERR("High threshold not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_update_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_update_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_ENABLE_REG, APDS9960_ENABLE_PEN,
|
APDS9960_ENABLE_REG, APDS9960_ENABLE_PEN,
|
||||||
APDS9960_ENABLE_PEN)) {
|
APDS9960_ENABLE_PEN)) {
|
||||||
SYS_LOG_ERR("Proximity mode is not enabled");
|
LOG_ERR("Proximity mode is not enabled");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +208,7 @@ static int apds9960_ambient_setup(struct device *dev, int gain)
|
||||||
/* ADC value */
|
/* ADC value */
|
||||||
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_ATIME_REG, APDS9960_DEFAULT_ATIME)) {
|
APDS9960_ATIME_REG, APDS9960_DEFAULT_ATIME)) {
|
||||||
SYS_LOG_ERR("Default integration time not set for ADC");
|
LOG_ERR("Default integration time not set for ADC");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +217,7 @@ static int apds9960_ambient_setup(struct device *dev, int gain)
|
||||||
APDS9960_CONTROL_REG,
|
APDS9960_CONTROL_REG,
|
||||||
APDS9960_CONTROL_AGAIN,
|
APDS9960_CONTROL_AGAIN,
|
||||||
(gain & APDS9960_AGAIN_64X))) {
|
(gain & APDS9960_AGAIN_64X))) {
|
||||||
SYS_LOG_ERR("Ambient Gain is not set");
|
LOG_ERR("Ambient Gain is not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,7 +225,7 @@ static int apds9960_ambient_setup(struct device *dev, int gain)
|
||||||
if (i2c_burst_write(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_burst_write(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_INT_AILTL_REG,
|
APDS9960_INT_AILTL_REG,
|
||||||
(u8_t *)&th, sizeof(th))) {
|
(u8_t *)&th, sizeof(th))) {
|
||||||
SYS_LOG_ERR("ALS low threshold not set");
|
LOG_ERR("ALS low threshold not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +233,7 @@ static int apds9960_ambient_setup(struct device *dev, int gain)
|
||||||
if (i2c_burst_write(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_burst_write(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_INT_AIHTL_REG,
|
APDS9960_INT_AIHTL_REG,
|
||||||
(u8_t *)&th, sizeof(th))) {
|
(u8_t *)&th, sizeof(th))) {
|
||||||
SYS_LOG_ERR("ALS low threshold not set");
|
LOG_ERR("ALS low threshold not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +241,7 @@ static int apds9960_ambient_setup(struct device *dev, int gain)
|
||||||
if (i2c_reg_update_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_update_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_ENABLE_REG, APDS9960_ENABLE_AEN,
|
APDS9960_ENABLE_REG, APDS9960_ENABLE_AEN,
|
||||||
APDS9960_ENABLE_AEN)) {
|
APDS9960_ENABLE_AEN)) {
|
||||||
SYS_LOG_ERR("ALS is not enabled");
|
LOG_ERR("ALS is not enabled");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,19 +255,19 @@ static int apds9960_sensor_setup(struct device *dev)
|
||||||
|
|
||||||
if (i2c_reg_read_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_read_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_ID_REG, &chip_id)) {
|
APDS9960_ID_REG, &chip_id)) {
|
||||||
SYS_LOG_ERR("Failed reading chip id");
|
LOG_ERR("Failed reading chip id");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!((chip_id == APDS9960_ID_1) || (chip_id == APDS9960_ID_2))) {
|
if (!((chip_id == APDS9960_ID_1) || (chip_id == APDS9960_ID_2))) {
|
||||||
SYS_LOG_ERR("Invalid chip id 0x%x", chip_id);
|
LOG_ERR("Invalid chip id 0x%x", chip_id);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable all functions and interrupts */
|
/* Disable all functions and interrupts */
|
||||||
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_ENABLE_REG, 0)) {
|
APDS9960_ENABLE_REG, 0)) {
|
||||||
SYS_LOG_ERR("ENABLE register is not cleared");
|
LOG_ERR("ENABLE register is not cleared");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,51 +279,51 @@ static int apds9960_sensor_setup(struct device *dev)
|
||||||
/* Disable gesture interrupt */
|
/* Disable gesture interrupt */
|
||||||
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_GCONFIG4_REG, 0)) {
|
APDS9960_GCONFIG4_REG, 0)) {
|
||||||
SYS_LOG_ERR("GCONFIG4 register is not cleared");
|
LOG_ERR("GCONFIG4 register is not cleared");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_WTIME_REG, APDS9960_DEFAULT_WTIME)) {
|
APDS9960_WTIME_REG, APDS9960_DEFAULT_WTIME)) {
|
||||||
SYS_LOG_ERR("Default wait time not set");
|
LOG_ERR("Default wait time not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_CONFIG1_REG,
|
APDS9960_CONFIG1_REG,
|
||||||
APDS9960_DEFAULT_CONFIG1)) {
|
APDS9960_DEFAULT_CONFIG1)) {
|
||||||
SYS_LOG_ERR("Default WLONG not set");
|
LOG_ERR("Default WLONG not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_CONFIG2_REG,
|
APDS9960_CONFIG2_REG,
|
||||||
APDS9960_DEFAULT_CONFIG2)) {
|
APDS9960_DEFAULT_CONFIG2)) {
|
||||||
SYS_LOG_ERR("Configuration Register Two not set");
|
LOG_ERR("Configuration Register Two not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_CONFIG3_REG,
|
APDS9960_CONFIG3_REG,
|
||||||
APDS9960_DEFAULT_CONFIG3)) {
|
APDS9960_DEFAULT_CONFIG3)) {
|
||||||
SYS_LOG_ERR("Configuration Register Three not set");
|
LOG_ERR("Configuration Register Three not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
if (i2c_reg_write_byte(data->i2c, APDS9960_I2C_ADDRESS,
|
||||||
APDS9960_PERS_REG,
|
APDS9960_PERS_REG,
|
||||||
APDS9960_DEFAULT_PERS)) {
|
APDS9960_DEFAULT_PERS)) {
|
||||||
SYS_LOG_ERR("Interrupt persistence not set");
|
LOG_ERR("Interrupt persistence not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apds9960_proxy_setup(dev, APDS9960_DEFAULT_PGAIN)) {
|
if (apds9960_proxy_setup(dev, APDS9960_DEFAULT_PGAIN)) {
|
||||||
SYS_LOG_ERR("Failed to setup proximity functionality");
|
LOG_ERR("Failed to setup proximity functionality");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apds9960_ambient_setup(dev, APDS9960_DEFAULT_AGAIN)) {
|
if (apds9960_ambient_setup(dev, APDS9960_DEFAULT_AGAIN)) {
|
||||||
SYS_LOG_ERR("Failed to setup ambient light functionality");
|
LOG_ERR("Failed to setup ambient light functionality");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +337,7 @@ static int apds9960_init_interrupt(struct device *dev)
|
||||||
/* setup gpio interrupt */
|
/* setup gpio interrupt */
|
||||||
drv_data->gpio = device_get_binding(CONFIG_APDS9960_GPIO_DEV_NAME);
|
drv_data->gpio = device_get_binding(CONFIG_APDS9960_GPIO_DEV_NAME);
|
||||||
if (drv_data->gpio == NULL) {
|
if (drv_data->gpio == NULL) {
|
||||||
SYS_LOG_ERR("Failed to get pointer to %s device!",
|
LOG_ERR("Failed to get pointer to %s device!",
|
||||||
CONFIG_APDS9960_GPIO_DEV_NAME);
|
CONFIG_APDS9960_GPIO_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -348,7 +352,7 @@ static int apds9960_init_interrupt(struct device *dev)
|
||||||
BIT(CONFIG_APDS9960_GPIO_PIN_NUM));
|
BIT(CONFIG_APDS9960_GPIO_PIN_NUM));
|
||||||
|
|
||||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set gpio callback!");
|
LOG_DBG("Failed to set gpio callback!");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,7 +363,7 @@ static int apds9960_init_interrupt(struct device *dev)
|
||||||
APDS9960_ENABLE_REG,
|
APDS9960_ENABLE_REG,
|
||||||
APDS9960_ENABLE_PON,
|
APDS9960_ENABLE_PON,
|
||||||
APDS9960_ENABLE_PON)) {
|
APDS9960_ENABLE_PON)) {
|
||||||
SYS_LOG_ERR("Power on bit not set.");
|
LOG_ERR("Power on bit not set.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,7 +423,7 @@ static int apds9960_init(struct device *dev)
|
||||||
data->i2c = device_get_binding(CONFIG_APDS9960_I2C_DEV_NAME);
|
data->i2c = device_get_binding(CONFIG_APDS9960_I2C_DEV_NAME);
|
||||||
|
|
||||||
if (data->i2c == NULL) {
|
if (data->i2c == NULL) {
|
||||||
SYS_LOG_ERR("Failed to get pointer to %s device!",
|
LOG_ERR("Failed to get pointer to %s device!",
|
||||||
CONFIG_APDS9960_I2C_DEV_NAME);
|
CONFIG_APDS9960_I2C_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -430,7 +434,7 @@ static int apds9960_init(struct device *dev)
|
||||||
apds9960_sensor_setup(dev);
|
apds9960_sensor_setup(dev);
|
||||||
|
|
||||||
if (apds9960_init_interrupt(dev) < 0) {
|
if (apds9960_init_interrupt(dev) < 0) {
|
||||||
SYS_LOG_ERR("Failed to initialize interrupt!");
|
LOG_ERR("Failed to initialize interrupt!");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -248,8 +248,4 @@ int apds9960_trigger_set(struct device *dev,
|
||||||
sensor_trigger_handler_t handler);
|
sensor_trigger_handler_t handler);
|
||||||
#endif /* CONFIG_APDS9960_TRIGGER */
|
#endif /* CONFIG_APDS9960_TRIGGER */
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "APDS9960"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_APDS9960_APDS9960_H_*/
|
#endif /* ZEPHYR_DRIVERS_SENSOR_APDS9960_APDS9960_H_*/
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
|
|
||||||
extern struct apds9960_data apds9960_driver;
|
extern struct apds9960_data apds9960_driver;
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(APDS9960);
|
||||||
|
|
||||||
void apds9960_work_cb(struct k_work *work)
|
void apds9960_work_cb(struct k_work *work)
|
||||||
{
|
{
|
||||||
struct apds9960_data *data = CONTAINER_OF(work,
|
struct apds9960_data *data = CONTAINER_OF(work,
|
||||||
|
@ -85,7 +89,7 @@ int apds9960_trigger_set(struct device *dev,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SYS_LOG_ERR("Unsupported sensor trigger");
|
LOG_ERR("Unsupported sensor trigger");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,13 @@
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "bma280.h"
|
#include "bma280.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(BMA280);
|
||||||
|
|
||||||
static int bma280_sample_fetch(struct device *dev, enum sensor_channel chan)
|
static int bma280_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
{
|
{
|
||||||
struct bma280_data *drv_data = dev->driver_data;
|
struct bma280_data *drv_data = dev->driver_data;
|
||||||
|
@ -25,7 +29,7 @@ static int bma280_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
*/
|
*/
|
||||||
if (i2c_burst_read(drv_data->i2c, BMA280_I2C_ADDRESS,
|
if (i2c_burst_read(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||||
BMA280_REG_ACCEL_X_LSB, buf, 6) < 0) {
|
BMA280_REG_ACCEL_X_LSB, buf, 6) < 0) {
|
||||||
SYS_LOG_DBG("Could not read accel axis data");
|
LOG_DBG("Could not read accel axis data");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +45,7 @@ static int bma280_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
if (i2c_reg_read_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
if (i2c_reg_read_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||||
BMA280_REG_TEMP,
|
BMA280_REG_TEMP,
|
||||||
(u8_t *)&drv_data->temp_sample) < 0) {
|
(u8_t *)&drv_data->temp_sample) < 0) {
|
||||||
SYS_LOG_DBG("Could not read temperature data");
|
LOG_DBG("Could not read temperature data");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +119,7 @@ int bma280_init(struct device *dev)
|
||||||
|
|
||||||
drv_data->i2c = device_get_binding(CONFIG_BMA280_I2C_MASTER_DEV_NAME);
|
drv_data->i2c = device_get_binding(CONFIG_BMA280_I2C_MASTER_DEV_NAME);
|
||||||
if (drv_data->i2c == NULL) {
|
if (drv_data->i2c == NULL) {
|
||||||
SYS_LOG_DBG("Could not get pointer to %s device",
|
LOG_DBG("Could not get pointer to %s device",
|
||||||
CONFIG_BMA280_I2C_MASTER_DEV_NAME);
|
CONFIG_BMA280_I2C_MASTER_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -123,31 +127,31 @@ int bma280_init(struct device *dev)
|
||||||
/* read device ID */
|
/* read device ID */
|
||||||
if (i2c_reg_read_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
if (i2c_reg_read_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||||
BMA280_REG_CHIP_ID, &id) < 0) {
|
BMA280_REG_CHIP_ID, &id) < 0) {
|
||||||
SYS_LOG_DBG("Could not read chip id");
|
LOG_DBG("Could not read chip id");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id != BMA280_CHIP_ID) {
|
if (id != BMA280_CHIP_ID) {
|
||||||
SYS_LOG_DBG("Unexpected chip id (%x)", id);
|
LOG_DBG("Unexpected chip id (%x)", id);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
if (i2c_reg_write_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||||
BMA280_REG_PMU_BW, BMA280_PMU_BW) < 0) {
|
BMA280_REG_PMU_BW, BMA280_PMU_BW) < 0) {
|
||||||
SYS_LOG_DBG("Could not set data filter bandwidth");
|
LOG_DBG("Could not set data filter bandwidth");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set g-range */
|
/* set g-range */
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
if (i2c_reg_write_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||||
BMA280_REG_PMU_RANGE, BMA280_PMU_RANGE) < 0) {
|
BMA280_REG_PMU_RANGE, BMA280_PMU_RANGE) < 0) {
|
||||||
SYS_LOG_DBG("Could not set data g-range");
|
LOG_DBG("Could not set data g-range");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_BMA280_TRIGGER
|
#ifdef CONFIG_BMA280_TRIGGER
|
||||||
if (bma280_init_interrupt(dev) < 0) {
|
if (bma280_init_interrupt(dev) < 0) {
|
||||||
SYS_LOG_DBG("Could not initialize interrupts");
|
LOG_DBG("Could not initialize interrupts");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -155,7 +155,4 @@ int bma280_attr_set(struct device *dev,
|
||||||
int bma280_init_interrupt(struct device *dev);
|
int bma280_init_interrupt(struct device *dev);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "BMA280"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_BMA280_BMA280_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_BMA280_BMA280_H_ */
|
||||||
|
|
|
@ -12,6 +12,10 @@
|
||||||
|
|
||||||
#include "bma280.h"
|
#include "bma280.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(BMA280);
|
||||||
|
|
||||||
int bma280_attr_set(struct device *dev,
|
int bma280_attr_set(struct device *dev,
|
||||||
enum sensor_channel chan,
|
enum sensor_channel chan,
|
||||||
enum sensor_attribute attr,
|
enum sensor_attribute attr,
|
||||||
|
@ -31,7 +35,7 @@ int bma280_attr_set(struct device *dev,
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
if (i2c_reg_write_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||||
BMA280_REG_SLOPE_TH, (u8_t)slope_th)
|
BMA280_REG_SLOPE_TH, (u8_t)slope_th)
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_DBG("Could not set slope threshold");
|
LOG_DBG("Could not set slope threshold");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
} else if (attr == SENSOR_ATTR_SLOPE_DUR) {
|
} else if (attr == SENSOR_ATTR_SLOPE_DUR) {
|
||||||
|
@ -40,7 +44,7 @@ int bma280_attr_set(struct device *dev,
|
||||||
BMA280_SLOPE_DUR_MASK,
|
BMA280_SLOPE_DUR_MASK,
|
||||||
val->val1 << BMA280_SLOPE_DUR_SHIFT)
|
val->val1 << BMA280_SLOPE_DUR_SHIFT)
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_DBG("Could not set slope duration");
|
LOG_DBG("Could not set slope duration");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -100,7 +104,7 @@ static void bma280_thread_cb(void *arg)
|
||||||
BMA280_BIT_INT_LATCH_RESET);
|
BMA280_BIT_INT_LATCH_RESET);
|
||||||
|
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SYS_LOG_DBG("Could not update clear the interrupt");
|
LOG_DBG("Could not update clear the interrupt");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,7 +148,7 @@ int bma280_trigger_set(struct device *dev,
|
||||||
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||||
BMA280_REG_INT_EN_1,
|
BMA280_REG_INT_EN_1,
|
||||||
BMA280_BIT_DATA_EN, 0) < 0) {
|
BMA280_BIT_DATA_EN, 0) < 0) {
|
||||||
SYS_LOG_DBG("Could not disable data ready interrupt");
|
LOG_DBG("Could not disable data ready interrupt");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +163,7 @@ int bma280_trigger_set(struct device *dev,
|
||||||
BMA280_REG_INT_EN_1,
|
BMA280_REG_INT_EN_1,
|
||||||
BMA280_BIT_DATA_EN,
|
BMA280_BIT_DATA_EN,
|
||||||
BMA280_BIT_DATA_EN) < 0) {
|
BMA280_BIT_DATA_EN) < 0) {
|
||||||
SYS_LOG_DBG("Could not enable data ready interrupt");
|
LOG_DBG("Could not enable data ready interrupt");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
} else if (trig->type == SENSOR_TRIG_DELTA) {
|
} else if (trig->type == SENSOR_TRIG_DELTA) {
|
||||||
|
@ -167,7 +171,7 @@ int bma280_trigger_set(struct device *dev,
|
||||||
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||||
BMA280_REG_INT_EN_0,
|
BMA280_REG_INT_EN_0,
|
||||||
BMA280_SLOPE_EN_XYZ, 0) < 0) {
|
BMA280_SLOPE_EN_XYZ, 0) < 0) {
|
||||||
SYS_LOG_DBG("Could not disable data ready interrupt");
|
LOG_DBG("Could not disable data ready interrupt");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +186,7 @@ int bma280_trigger_set(struct device *dev,
|
||||||
BMA280_REG_INT_EN_0,
|
BMA280_REG_INT_EN_0,
|
||||||
BMA280_SLOPE_EN_XYZ,
|
BMA280_SLOPE_EN_XYZ,
|
||||||
BMA280_SLOPE_EN_XYZ) < 0) {
|
BMA280_SLOPE_EN_XYZ) < 0) {
|
||||||
SYS_LOG_DBG("Could not enable data ready interrupt");
|
LOG_DBG("Could not enable data ready interrupt");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -201,14 +205,14 @@ int bma280_init_interrupt(struct device *dev)
|
||||||
BMA280_REG_INT_RST_LATCH,
|
BMA280_REG_INT_RST_LATCH,
|
||||||
BMA280_BIT_INT_LATCH_RESET |
|
BMA280_BIT_INT_LATCH_RESET |
|
||||||
BMA280_INT_MODE_LATCH) < 0) {
|
BMA280_INT_MODE_LATCH) < 0) {
|
||||||
SYS_LOG_DBG("Could not set latched interrupts");
|
LOG_DBG("Could not set latched interrupts");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* setup data ready gpio interrupt */
|
/* setup data ready gpio interrupt */
|
||||||
drv_data->gpio = device_get_binding(CONFIG_BMA280_GPIO_DEV_NAME);
|
drv_data->gpio = device_get_binding(CONFIG_BMA280_GPIO_DEV_NAME);
|
||||||
if (drv_data->gpio == NULL) {
|
if (drv_data->gpio == NULL) {
|
||||||
SYS_LOG_DBG("Cannot get pointer to %s device",
|
LOG_DBG("Cannot get pointer to %s device",
|
||||||
CONFIG_BMA280_GPIO_DEV_NAME);
|
CONFIG_BMA280_GPIO_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -222,7 +226,7 @@ int bma280_init_interrupt(struct device *dev)
|
||||||
BIT(CONFIG_BMA280_GPIO_PIN_NUM));
|
BIT(CONFIG_BMA280_GPIO_PIN_NUM));
|
||||||
|
|
||||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||||
SYS_LOG_DBG("Could not set gpio callback");
|
LOG_DBG("Could not set gpio callback");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +235,7 @@ int bma280_init_interrupt(struct device *dev)
|
||||||
BMA280_REG_INT_MAP_1,
|
BMA280_REG_INT_MAP_1,
|
||||||
BMA280_INT_MAP_1_BIT_DATA,
|
BMA280_INT_MAP_1_BIT_DATA,
|
||||||
BMA280_INT_MAP_1_BIT_DATA) < 0) {
|
BMA280_INT_MAP_1_BIT_DATA) < 0) {
|
||||||
SYS_LOG_DBG("Could not map data ready interrupt pin");
|
LOG_DBG("Could not map data ready interrupt pin");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,14 +244,14 @@ int bma280_init_interrupt(struct device *dev)
|
||||||
BMA280_REG_INT_MAP_0,
|
BMA280_REG_INT_MAP_0,
|
||||||
BMA280_INT_MAP_0_BIT_SLOPE,
|
BMA280_INT_MAP_0_BIT_SLOPE,
|
||||||
BMA280_INT_MAP_0_BIT_SLOPE) < 0) {
|
BMA280_INT_MAP_0_BIT_SLOPE) < 0) {
|
||||||
SYS_LOG_DBG("Could not map any-motion interrupt pin");
|
LOG_DBG("Could not map any-motion interrupt pin");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||||
BMA280_REG_INT_EN_1,
|
BMA280_REG_INT_EN_1,
|
||||||
BMA280_BIT_DATA_EN, 0) < 0) {
|
BMA280_BIT_DATA_EN, 0) < 0) {
|
||||||
SYS_LOG_DBG("Could not disable data ready interrupt");
|
LOG_DBG("Could not disable data ready interrupt");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,7 +259,7 @@ int bma280_init_interrupt(struct device *dev)
|
||||||
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||||
BMA280_REG_INT_EN_0,
|
BMA280_REG_INT_EN_0,
|
||||||
BMA280_SLOPE_EN_XYZ, 0) < 0) {
|
BMA280_SLOPE_EN_XYZ, 0) < 0) {
|
||||||
SYS_LOG_DBG("Could not disable data ready interrupt");
|
LOG_DBG("Could not disable data ready interrupt");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,13 @@
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
|
||||||
#include <gpio.h>
|
#include <gpio.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "bmc150_magn.h"
|
#include "bmc150_magn.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(BMC150_MAGN)
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
int freq;
|
int freq;
|
||||||
u8_t reg_val;
|
u8_t reg_val;
|
||||||
|
@ -298,7 +302,7 @@ static int bmc150_magn_sample_fetch(struct device *dev,
|
||||||
if (i2c_burst_read(data->i2c_master, config->i2c_slave_addr,
|
if (i2c_burst_read(data->i2c_master, config->i2c_slave_addr,
|
||||||
BMC150_MAGN_REG_X_L, (u8_t *)values,
|
BMC150_MAGN_REG_X_L, (u8_t *)values,
|
||||||
sizeof(values)) < 0) {
|
sizeof(values)) < 0) {
|
||||||
SYS_LOG_ERR("failed to read sample");
|
LOG_ERR("failed to read sample");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,7 +448,7 @@ static int bmc150_magn_attr_set(struct device *dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->max_odr < val->val1) {
|
if (data->max_odr < val->val1) {
|
||||||
SYS_LOG_ERR("not supported with current oversampling");
|
LOG_ERR("not supported with current oversampling");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -489,24 +493,24 @@ static int bmc150_magn_init_chip(struct device *dev)
|
||||||
|
|
||||||
if (bmc150_magn_set_power_mode(dev, BMC150_MAGN_POWER_MODE_SUSPEND, 0)
|
if (bmc150_magn_set_power_mode(dev, BMC150_MAGN_POWER_MODE_SUSPEND, 0)
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_ERR("failed to bring up device from suspend mode");
|
LOG_ERR("failed to bring up device from suspend mode");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
if (i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
BMC150_MAGN_REG_CHIP_ID, &chip_id) < 0) {
|
BMC150_MAGN_REG_CHIP_ID, &chip_id) < 0) {
|
||||||
SYS_LOG_ERR("failed reading chip id");
|
LOG_ERR("failed reading chip id");
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
if (chip_id != BMC150_MAGN_CHIP_ID_VAL) {
|
if (chip_id != BMC150_MAGN_CHIP_ID_VAL) {
|
||||||
SYS_LOG_ERR("invalid chip id 0x%x", chip_id);
|
LOG_ERR("invalid chip id 0x%x", chip_id);
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
SYS_LOG_ERR("chip id 0x%x", chip_id);
|
LOG_ERR("chip id 0x%x", chip_id);
|
||||||
|
|
||||||
preset = bmc150_magn_presets_table[BMC150_MAGN_DEFAULT_PRESET];
|
preset = bmc150_magn_presets_table[BMC150_MAGN_DEFAULT_PRESET];
|
||||||
if (bmc150_magn_set_odr(dev, preset.odr) < 0) {
|
if (bmc150_magn_set_odr(dev, preset.odr) < 0) {
|
||||||
SYS_LOG_ERR("failed to set ODR to %d",
|
LOG_ERR("failed to set ODR to %d",
|
||||||
preset.odr);
|
preset.odr);
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
@ -515,7 +519,7 @@ static int bmc150_magn_init_chip(struct device *dev)
|
||||||
BMC150_MAGN_REG_REP_XY,
|
BMC150_MAGN_REG_REP_XY,
|
||||||
BMC150_MAGN_REPXY_TO_REGVAL(preset.rep_xy))
|
BMC150_MAGN_REPXY_TO_REGVAL(preset.rep_xy))
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_ERR("failed to set REP XY to %d",
|
LOG_ERR("failed to set REP XY to %d",
|
||||||
preset.rep_xy);
|
preset.rep_xy);
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
@ -523,21 +527,21 @@ static int bmc150_magn_init_chip(struct device *dev)
|
||||||
if (i2c_reg_write_byte(data->i2c_master, config->i2c_slave_addr,
|
if (i2c_reg_write_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
BMC150_MAGN_REG_REP_Z,
|
BMC150_MAGN_REG_REP_Z,
|
||||||
BMC150_MAGN_REPZ_TO_REGVAL(preset.rep_z)) < 0) {
|
BMC150_MAGN_REPZ_TO_REGVAL(preset.rep_z)) < 0) {
|
||||||
SYS_LOG_ERR("failed to set REP Z to %d",
|
LOG_ERR("failed to set REP Z to %d",
|
||||||
preset.rep_z);
|
preset.rep_z);
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bmc150_magn_set_power_mode(dev, BMC150_MAGN_POWER_MODE_NORMAL, 1)
|
if (bmc150_magn_set_power_mode(dev, BMC150_MAGN_POWER_MODE_NORMAL, 1)
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_ERR("failed to power on device");
|
LOG_ERR("failed to power on device");
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_burst_read(data->i2c_master, config->i2c_slave_addr,
|
if (i2c_burst_read(data->i2c_master, config->i2c_slave_addr,
|
||||||
BMC150_MAGN_REG_TRIM_START, (u8_t *)&data->tregs,
|
BMC150_MAGN_REG_TRIM_START, (u8_t *)&data->tregs,
|
||||||
sizeof(data->tregs)) < 0) {
|
sizeof(data->tregs)) < 0) {
|
||||||
SYS_LOG_ERR("failed to read trim regs");
|
LOG_ERR("failed to read trim regs");
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -571,19 +575,19 @@ static int bmc150_magn_init(struct device *dev)
|
||||||
|
|
||||||
data->i2c_master = device_get_binding(config->i2c_master_dev_name);
|
data->i2c_master = device_get_binding(config->i2c_master_dev_name);
|
||||||
if (!data->i2c_master) {
|
if (!data->i2c_master) {
|
||||||
SYS_LOG_ERR("i2c master not found: %s",
|
LOG_ERR("i2c master not found: %s",
|
||||||
config->i2c_master_dev_name);
|
config->i2c_master_dev_name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bmc150_magn_init_chip(dev) < 0) {
|
if (bmc150_magn_init_chip(dev) < 0) {
|
||||||
SYS_LOG_ERR("failed to initialize chip");
|
LOG_ERR("failed to initialize chip");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BMC150_MAGN_TRIGGER_DRDY)
|
#if defined(CONFIG_BMC150_MAGN_TRIGGER_DRDY)
|
||||||
if (bmc150_magn_init_interrupt(dev) < 0) {
|
if (bmc150_magn_init_interrupt(dev) < 0) {
|
||||||
SYS_LOG_ERR("failed to initialize interrupts");
|
LOG_ERR("failed to initialize interrupts");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -175,7 +175,4 @@ int bmc150_magn_trigger_set(struct device *dev,
|
||||||
int bmc150_magn_init_interrupt(struct device *dev);
|
int bmc150_magn_init_interrupt(struct device *dev);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "BMC150_MAGN"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_BMC150_MAGN_BMC150_MAGN_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_BMC150_MAGN_BMC150_MAGN_H_ */
|
||||||
|
|
|
@ -12,6 +12,10 @@
|
||||||
|
|
||||||
#include "bmc150_magn.h"
|
#include "bmc150_magn.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(BMC150_MAGN);
|
||||||
|
|
||||||
int bmc150_magn_trigger_set(struct device *dev,
|
int bmc150_magn_trigger_set(struct device *dev,
|
||||||
const struct sensor_trigger *trig,
|
const struct sensor_trigger *trig,
|
||||||
sensor_trigger_handler_t handler)
|
sensor_trigger_handler_t handler)
|
||||||
|
@ -40,7 +44,7 @@ int bmc150_magn_trigger_set(struct device *dev,
|
||||||
BMC150_MAGN_MASK_DRDY_EN,
|
BMC150_MAGN_MASK_DRDY_EN,
|
||||||
state << BMC150_MAGN_SHIFT_DRDY_EN)
|
state << BMC150_MAGN_SHIFT_DRDY_EN)
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_DBG("failed to set DRDY interrupt");
|
LOG_DBG("failed to set DRDY interrupt");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +88,7 @@ static void bmc150_magn_thread_main(void *arg1, void *arg2, void *arg3)
|
||||||
config->i2c_slave_addr,
|
config->i2c_slave_addr,
|
||||||
BMC150_MAGN_REG_INT_STATUS,
|
BMC150_MAGN_REG_INT_STATUS,
|
||||||
®_val) < 0) {
|
®_val) < 0) {
|
||||||
SYS_LOG_DBG("failed to clear data ready interrupt");
|
LOG_DBG("failed to clear data ready interrupt");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->handler_drdy) {
|
if (data->handler_drdy) {
|
||||||
|
@ -119,7 +123,7 @@ int bmc150_magn_init_interrupt(struct device *dev)
|
||||||
|
|
||||||
#if defined(CONFIG_BMC150_MAGN_TRIGGER_DRDY)
|
#if defined(CONFIG_BMC150_MAGN_TRIGGER_DRDY)
|
||||||
if (bmc150_magn_set_drdy_polarity(dev, 0) < 0) {
|
if (bmc150_magn_set_drdy_polarity(dev, 0) < 0) {
|
||||||
SYS_LOG_DBG("failed to set DR polarity");
|
LOG_DBG("failed to set DR polarity");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +131,7 @@ int bmc150_magn_init_interrupt(struct device *dev)
|
||||||
BMC150_MAGN_REG_INT_DRDY,
|
BMC150_MAGN_REG_INT_DRDY,
|
||||||
BMC150_MAGN_MASK_DRDY_EN,
|
BMC150_MAGN_MASK_DRDY_EN,
|
||||||
0 << BMC150_MAGN_SHIFT_DRDY_EN) < 0) {
|
0 << BMC150_MAGN_SHIFT_DRDY_EN) < 0) {
|
||||||
SYS_LOG_DBG("failed to set data ready interrupt enabled bit");
|
LOG_DBG("failed to set data ready interrupt enabled bit");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -143,7 +147,7 @@ int bmc150_magn_init_interrupt(struct device *dev)
|
||||||
|
|
||||||
data->gpio_drdy = device_get_binding(config->gpio_drdy_dev_name);
|
data->gpio_drdy = device_get_binding(config->gpio_drdy_dev_name);
|
||||||
if (!data->gpio_drdy) {
|
if (!data->gpio_drdy) {
|
||||||
SYS_LOG_DBG("gpio controller %s not found",
|
LOG_DBG("gpio controller %s not found",
|
||||||
config->gpio_drdy_dev_name);
|
config->gpio_drdy_dev_name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +161,7 @@ int bmc150_magn_init_interrupt(struct device *dev)
|
||||||
BIT(config->gpio_drdy_int_pin));
|
BIT(config->gpio_drdy_int_pin));
|
||||||
|
|
||||||
if (gpio_add_callback(data->gpio_drdy, &data->gpio_cb) < 0) {
|
if (gpio_add_callback(data->gpio_drdy, &data->gpio_cb) < 0) {
|
||||||
SYS_LOG_DBG("failed to set gpio callback");
|
LOG_DBG("failed to set gpio callback");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,15 @@
|
||||||
#elif defined CONFIG_BME280_DEV_TYPE_SPI
|
#elif defined CONFIG_BME280_DEV_TYPE_SPI
|
||||||
#include <spi.h>
|
#include <spi.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "bme280.h"
|
#include "bme280.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(BME280);
|
||||||
|
|
||||||
static int bm280_reg_read(struct bme280_data *data,
|
static int bm280_reg_read(struct bme280_data *data,
|
||||||
|
|
||||||
u8_t start, u8_t *buf, int size)
|
u8_t start, u8_t *buf, int size)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_BME280_DEV_TYPE_I2C
|
#ifdef CONFIG_BME280_DEV_TYPE_I2C
|
||||||
|
@ -58,7 +63,7 @@ static int bm280_reg_read(struct bme280_data *data,
|
||||||
|
|
||||||
ret = spi_transceive(data->spi, &data->spi_cfg, &tx, &rx);
|
ret = spi_transceive(data->spi, &data->spi_cfg, &tx, &rx);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
SYS_LOG_DBG("spi_transceive FAIL %d\n", ret);
|
LOG_DBG("spi_transceive FAIL %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +90,7 @@ static int bm280_reg_write(struct bme280_data *data, u8_t reg, u8_t val)
|
||||||
|
|
||||||
ret = spi_write(data->spi, &data->spi_cfg, &tx);
|
ret = spi_write(data->spi, &data->spi_cfg, &tx);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
SYS_LOG_DBG("spi_write FAIL %d\n", ret);
|
LOG_DBG("spi_write FAIL %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -293,12 +298,12 @@ static int bme280_chip_init(struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->chip_id == BME280_CHIP_ID) {
|
if (data->chip_id == BME280_CHIP_ID) {
|
||||||
SYS_LOG_DBG("BME280 chip detected");
|
LOG_DBG("BME280 chip detected");
|
||||||
} else if (data->chip_id == BMP280_CHIP_ID_MP ||
|
} else if (data->chip_id == BMP280_CHIP_ID_MP ||
|
||||||
data->chip_id == BMP280_CHIP_ID_SAMPLE_1) {
|
data->chip_id == BMP280_CHIP_ID_SAMPLE_1) {
|
||||||
SYS_LOG_DBG("BMP280 chip detected");
|
LOG_DBG("BMP280 chip detected");
|
||||||
} else {
|
} else {
|
||||||
SYS_LOG_DBG("bad chip id 0x%x", data->chip_id);
|
LOG_DBG("bad chip id 0x%x", data->chip_id);
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +338,7 @@ static inline int bme280_spi_init(struct bme280_data *data)
|
||||||
{
|
{
|
||||||
data->spi = device_get_binding(CONFIG_BME280_SPI_DEV_NAME);
|
data->spi = device_get_binding(CONFIG_BME280_SPI_DEV_NAME);
|
||||||
if (!data->spi) {
|
if (!data->spi) {
|
||||||
SYS_LOG_DBG("spi device not found: %s",
|
LOG_DBG("spi device not found: %s",
|
||||||
CONFIG_BME280_SPI_DEV_NAME);
|
CONFIG_BME280_SPI_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -354,7 +359,7 @@ int bme280_init(struct device *dev)
|
||||||
#ifdef CONFIG_BME280_DEV_TYPE_I2C
|
#ifdef CONFIG_BME280_DEV_TYPE_I2C
|
||||||
data->i2c_master = device_get_binding(CONFIG_BME280_I2C_MASTER_DEV_NAME);
|
data->i2c_master = device_get_binding(CONFIG_BME280_I2C_MASTER_DEV_NAME);
|
||||||
if (!data->i2c_master) {
|
if (!data->i2c_master) {
|
||||||
SYS_LOG_DBG("i2c master not found: %s",
|
LOG_DBG("i2c master not found: %s",
|
||||||
CONFIG_BME280_I2C_MASTER_DEV_NAME);
|
CONFIG_BME280_I2C_MASTER_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -362,7 +367,7 @@ int bme280_init(struct device *dev)
|
||||||
data->i2c_slave_addr = BME280_I2C_ADDR;
|
data->i2c_slave_addr = BME280_I2C_ADDR;
|
||||||
#elif defined CONFIG_BME280_DEV_TYPE_SPI
|
#elif defined CONFIG_BME280_DEV_TYPE_SPI
|
||||||
if (bme280_spi_init(data) < 0) {
|
if (bme280_spi_init(data) < 0) {
|
||||||
SYS_LOG_DBG("spi master not found: %s",
|
LOG_DBG("spi master not found: %s",
|
||||||
CONFIG_BME280_SPI_DEV_NAME);
|
CONFIG_BME280_SPI_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,4 @@ struct bme280_data {
|
||||||
u8_t chip_id;
|
u8_t chip_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "BME280"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_BME280_BME280_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_BME280_BME280_H_ */
|
||||||
|
|
|
@ -12,9 +12,13 @@
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "bmg160.h"
|
#include "bmg160.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(BMG160);
|
||||||
|
|
||||||
struct bmg160_device_data bmg160_data;
|
struct bmg160_device_data bmg160_data;
|
||||||
|
|
||||||
static inline int bmg160_bus_config(struct device *dev)
|
static inline int bmg160_bus_config(struct device *dev)
|
||||||
|
@ -275,19 +279,19 @@ int bmg160_init(struct device *dev)
|
||||||
|
|
||||||
bmg160->i2c = device_get_binding((char *)cfg->i2c_port);
|
bmg160->i2c = device_get_binding((char *)cfg->i2c_port);
|
||||||
if (!bmg160->i2c) {
|
if (!bmg160->i2c) {
|
||||||
SYS_LOG_DBG("I2C master controller not found!");
|
LOG_DBG("I2C master controller not found!");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
k_sem_init(&bmg160->sem, 1, UINT_MAX);
|
k_sem_init(&bmg160->sem, 1, UINT_MAX);
|
||||||
|
|
||||||
if (bmg160_read_byte(dev, BMG160_REG_CHIPID, &chip_id) < 0) {
|
if (bmg160_read_byte(dev, BMG160_REG_CHIPID, &chip_id) < 0) {
|
||||||
SYS_LOG_DBG("Failed to read chip id.");
|
LOG_DBG("Failed to read chip id.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chip_id != BMG160_CHIP_ID) {
|
if (chip_id != BMG160_CHIP_ID) {
|
||||||
SYS_LOG_DBG("Unsupported chip detected (0x%x)!", chip_id);
|
LOG_DBG("Unsupported chip detected (0x%x)!", chip_id);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,7 +302,7 @@ int bmg160_init(struct device *dev)
|
||||||
|
|
||||||
if (bmg160_write_byte(dev, BMG160_REG_RANGE,
|
if (bmg160_write_byte(dev, BMG160_REG_RANGE,
|
||||||
BMG160_DEFAULT_RANGE) < 0) {
|
BMG160_DEFAULT_RANGE) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set range.");
|
LOG_DBG("Failed to set range.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,13 +311,13 @@ int bmg160_init(struct device *dev)
|
||||||
bmg160->scale = BMG160_RANGE_TO_SCALE(range_dps);
|
bmg160->scale = BMG160_RANGE_TO_SCALE(range_dps);
|
||||||
|
|
||||||
if (bmg160_write_byte(dev, BMG160_REG_BW, BMG160_DEFAULT_ODR) < 0) {
|
if (bmg160_write_byte(dev, BMG160_REG_BW, BMG160_DEFAULT_ODR) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set sampling frequency.");
|
LOG_DBG("Failed to set sampling frequency.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* disable interrupts */
|
/* disable interrupts */
|
||||||
if (bmg160_write_byte(dev, BMG160_REG_INT_EN0, 0) < 0) {
|
if (bmg160_write_byte(dev, BMG160_REG_INT_EN0, 0) < 0) {
|
||||||
SYS_LOG_DBG("Failed to disable all interrupts.");
|
LOG_DBG("Failed to disable all interrupts.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -227,7 +227,4 @@ int bmg160_write_byte(struct device *dev, u8_t reg_addr, u8_t data);
|
||||||
int bmg160_slope_config(struct device *dev, enum sensor_attribute attr,
|
int bmg160_slope_config(struct device *dev, enum sensor_attribute attr,
|
||||||
const struct sensor_value *val);
|
const struct sensor_value *val);
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "BMG160"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_BMG160_BMG160_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_BMG160_BMG160_H_ */
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
|
|
||||||
extern struct bmg160_device_data bmg160_data;
|
extern struct bmg160_device_data bmg160_data;
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(BMG160);
|
||||||
|
|
||||||
static void bmg160_gpio_callback(struct device *port, struct gpio_callback *cb,
|
static void bmg160_gpio_callback(struct device *port, struct gpio_callback *cb,
|
||||||
u32_t pin)
|
u32_t pin)
|
||||||
{
|
{
|
||||||
|
@ -196,20 +200,20 @@ int bmg160_trigger_init(struct device *dev)
|
||||||
|
|
||||||
/* set INT1 pin to: push-pull, active low */
|
/* set INT1 pin to: push-pull, active low */
|
||||||
if (bmg160_write_byte(dev, BMG160_REG_INT_EN1, 0) < 0) {
|
if (bmg160_write_byte(dev, BMG160_REG_INT_EN1, 0) < 0) {
|
||||||
SYS_LOG_DBG("Failed to select interrupt pins type.");
|
LOG_DBG("Failed to select interrupt pins type.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set interrupt mode to non-latched */
|
/* set interrupt mode to non-latched */
|
||||||
if (bmg160_write_byte(dev, BMG160_REG_INT_RST_LATCH, 0) < 0) {
|
if (bmg160_write_byte(dev, BMG160_REG_INT_RST_LATCH, 0) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set the interrupt mode.");
|
LOG_DBG("Failed to set the interrupt mode.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* map anymotion and high rate interrupts to INT1 pin */
|
/* map anymotion and high rate interrupts to INT1 pin */
|
||||||
if (bmg160_write_byte(dev, BMG160_REG_INT_MAP0,
|
if (bmg160_write_byte(dev, BMG160_REG_INT_MAP0,
|
||||||
BMG160_INT1_ANY | BMG160_INT1_HIGH) < 0) {
|
BMG160_INT1_ANY | BMG160_INT1_HIGH) < 0) {
|
||||||
SYS_LOG_DBG("Unable to map interrupts.");
|
LOG_DBG("Unable to map interrupts.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,13 +221,13 @@ int bmg160_trigger_init(struct device *dev)
|
||||||
if (bmg160_write_byte(dev, BMG160_REG_INT_MAP1,
|
if (bmg160_write_byte(dev, BMG160_REG_INT_MAP1,
|
||||||
BMG160_INT1_DATA | BMG160_INT1_FIFO |
|
BMG160_INT1_DATA | BMG160_INT1_FIFO |
|
||||||
BMG160_INT1_FAST_OFFSET) < 0) {
|
BMG160_INT1_FAST_OFFSET) < 0) {
|
||||||
SYS_LOG_DBG("Unable to map interrupts.");
|
LOG_DBG("Unable to map interrupts.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
bmg160->gpio = device_get_binding((char *)cfg->gpio_port);
|
bmg160->gpio = device_get_binding((char *)cfg->gpio_port);
|
||||||
if (!bmg160->gpio) {
|
if (!bmg160->gpio) {
|
||||||
SYS_LOG_DBG("Gpio controller %s not found", cfg->gpio_port);
|
LOG_DBG("Gpio controller %s not found", cfg->gpio_port);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,13 @@
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "bmi160.h"
|
#include "bmi160.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(BMI160);
|
||||||
|
|
||||||
struct bmi160_device_data bmi160_data;
|
struct bmi160_device_data bmi160_data;
|
||||||
|
|
||||||
static int bmi160_transceive(struct device *dev, u8_t reg,
|
static int bmi160_transceive(struct device *dev, u8_t reg,
|
||||||
|
@ -426,7 +430,7 @@ static int bmi160_acc_config(struct device *dev, enum sensor_channel chan,
|
||||||
return bmi160_acc_slope_config(dev, attr, val);
|
return bmi160_acc_slope_config(dev, attr, val);
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
SYS_LOG_DBG("Accel attribute not supported.");
|
LOG_DBG("Accel attribute not supported.");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,7 +583,7 @@ static int bmi160_gyr_config(struct device *dev, enum sensor_channel chan,
|
||||||
return bmi160_gyr_calibrate(dev, chan);
|
return bmi160_gyr_calibrate(dev, chan);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
SYS_LOG_DBG("Gyro attribute not supported.");
|
LOG_DBG("Gyro attribute not supported.");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -606,7 +610,7 @@ static int bmi160_attr_set(struct device *dev, enum sensor_channel chan,
|
||||||
return bmi160_acc_config(dev, chan, attr, val);
|
return bmi160_acc_config(dev, chan, attr, val);
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
SYS_LOG_DBG("attr_set() not supported on this channel.");
|
LOG_DBG("attr_set() not supported on this channel.");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -770,7 +774,7 @@ static int bmi160_channel_get(struct device *dev,
|
||||||
case SENSOR_CHAN_DIE_TEMP:
|
case SENSOR_CHAN_DIE_TEMP:
|
||||||
return bmi160_temp_channel_get(dev, val);
|
return bmi160_temp_channel_get(dev, val);
|
||||||
default:
|
default:
|
||||||
SYS_LOG_DBG("Channel not supported.");
|
LOG_DBG("Channel not supported.");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -794,7 +798,7 @@ int bmi160_init(struct device *dev)
|
||||||
|
|
||||||
bmi160->spi = device_get_binding(CONFIG_BMI160_SPI_PORT_NAME);
|
bmi160->spi = device_get_binding(CONFIG_BMI160_SPI_PORT_NAME);
|
||||||
if (!bmi160->spi) {
|
if (!bmi160->spi) {
|
||||||
SYS_LOG_DBG("SPI master controller not found: %s.",
|
LOG_DBG("SPI master controller not found: %s.",
|
||||||
CONFIG_BMI160_SPI_PORT_NAME);
|
CONFIG_BMI160_SPI_PORT_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -805,7 +809,7 @@ int bmi160_init(struct device *dev)
|
||||||
|
|
||||||
/* reboot the chip */
|
/* reboot the chip */
|
||||||
if (bmi160_byte_write(dev, BMI160_REG_CMD, BMI160_CMD_SOFT_RESET) < 0) {
|
if (bmi160_byte_write(dev, BMI160_REG_CMD, BMI160_CMD_SOFT_RESET) < 0) {
|
||||||
SYS_LOG_DBG("Cannot reboot chip.");
|
LOG_DBG("Cannot reboot chip.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -813,19 +817,19 @@ int bmi160_init(struct device *dev)
|
||||||
|
|
||||||
/* do a dummy read from 0x7F to activate SPI */
|
/* do a dummy read from 0x7F to activate SPI */
|
||||||
if (bmi160_byte_read(dev, 0x7F, &val) < 0) {
|
if (bmi160_byte_read(dev, 0x7F, &val) < 0) {
|
||||||
SYS_LOG_DBG("Cannot read from 0x7F..");
|
LOG_DBG("Cannot read from 0x7F..");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
k_busy_wait(100);
|
k_busy_wait(100);
|
||||||
|
|
||||||
if (bmi160_byte_read(dev, BMI160_REG_CHIPID, &val) < 0) {
|
if (bmi160_byte_read(dev, BMI160_REG_CHIPID, &val) < 0) {
|
||||||
SYS_LOG_DBG("Failed to read chip id.");
|
LOG_DBG("Failed to read chip id.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (val != BMI160_CHIP_ID) {
|
if (val != BMI160_CHIP_ID) {
|
||||||
SYS_LOG_DBG("Unsupported chip detected (0x%x)!", val);
|
LOG_DBG("Unsupported chip detected (0x%x)!", val);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -842,14 +846,14 @@ int bmi160_init(struct device *dev)
|
||||||
* called.
|
* called.
|
||||||
*/
|
*/
|
||||||
if (bmi160_pmu_set(dev, &bmi160->pmu_sts) < 0) {
|
if (bmi160_pmu_set(dev, &bmi160->pmu_sts) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set power mode.");
|
LOG_DBG("Failed to set power mode.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set accelerometer default range */
|
/* set accelerometer default range */
|
||||||
if (bmi160_byte_write(dev, BMI160_REG_ACC_RANGE,
|
if (bmi160_byte_write(dev, BMI160_REG_ACC_RANGE,
|
||||||
BMI160_DEFAULT_RANGE_ACC) < 0) {
|
BMI160_DEFAULT_RANGE_ACC) < 0) {
|
||||||
SYS_LOG_DBG("Cannot set default range for accelerometer.");
|
LOG_DBG("Cannot set default range for accelerometer.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -860,7 +864,7 @@ int bmi160_init(struct device *dev)
|
||||||
/* set gyro default range */
|
/* set gyro default range */
|
||||||
if (bmi160_byte_write(dev, BMI160_REG_GYR_RANGE,
|
if (bmi160_byte_write(dev, BMI160_REG_GYR_RANGE,
|
||||||
BMI160_DEFAULT_RANGE_GYR) < 0) {
|
BMI160_DEFAULT_RANGE_GYR) < 0) {
|
||||||
SYS_LOG_DBG("Cannot set default range for gyroscope.");
|
LOG_DBG("Cannot set default range for gyroscope.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -872,7 +876,7 @@ int bmi160_init(struct device *dev)
|
||||||
BMI160_ACC_CONF_ODR_POS,
|
BMI160_ACC_CONF_ODR_POS,
|
||||||
BMI160_ACC_CONF_ODR_MASK,
|
BMI160_ACC_CONF_ODR_MASK,
|
||||||
BMI160_DEFAULT_ODR_ACC) < 0) {
|
BMI160_DEFAULT_ODR_ACC) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set accel's default ODR.");
|
LOG_DBG("Failed to set accel's default ODR.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -880,13 +884,13 @@ int bmi160_init(struct device *dev)
|
||||||
BMI160_GYR_CONF_ODR_POS,
|
BMI160_GYR_CONF_ODR_POS,
|
||||||
BMI160_GYR_CONF_ODR_MASK,
|
BMI160_GYR_CONF_ODR_MASK,
|
||||||
BMI160_DEFAULT_ODR_GYR) < 0) {
|
BMI160_DEFAULT_ODR_GYR) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set gyro's default ODR.");
|
LOG_DBG("Failed to set gyro's default ODR.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_BMI160_TRIGGER
|
#ifdef CONFIG_BMI160_TRIGGER
|
||||||
if (bmi160_trigger_mode_init(dev) < 0) {
|
if (bmi160_trigger_mode_init(dev) < 0) {
|
||||||
SYS_LOG_DBG("Cannot set up trigger mode.");
|
LOG_DBG("Cannot set up trigger mode.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -903,5 +907,7 @@ const struct bmi160_device_config bmi160_config = {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DEVICE_INIT(bmi160, CONFIG_BMI160_NAME, bmi160_init, &bmi160_data,
|
DEVICE_INIT(bmi160, CONFIG_BMI160_NAME, bmi160_init, &bmi160_data,
|
||||||
&bmi160_config, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY);
|
&bmi160_config, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY);
|
||||||
|
|
|
@ -478,7 +478,4 @@ int bmi160_acc_slope_config(struct device *dev, enum sensor_attribute attr,
|
||||||
s32_t bmi160_acc_reg_val_to_range(u8_t reg_val);
|
s32_t bmi160_acc_reg_val_to_range(u8_t reg_val);
|
||||||
s32_t bmi160_gyr_reg_val_to_range(u8_t reg_val);
|
s32_t bmi160_gyr_reg_val_to_range(u8_t reg_val);
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "BMI160"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_BMI160_BMI160_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_BMI160_BMI160_H_ */
|
||||||
|
|
|
@ -11,6 +11,10 @@
|
||||||
|
|
||||||
#include "bmi160.h"
|
#include "bmi160.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(BMI160);
|
||||||
|
|
||||||
static void bmi160_handle_anymotion(struct device *dev)
|
static void bmi160_handle_anymotion(struct device *dev)
|
||||||
{
|
{
|
||||||
struct bmi160_device_data *bmi160 = dev->driver_data;
|
struct bmi160_device_data *bmi160 = dev->driver_data;
|
||||||
|
@ -275,7 +279,7 @@ int bmi160_trigger_mode_init(struct device *dev)
|
||||||
|
|
||||||
bmi160->gpio = device_get_binding((char *)cfg->gpio_port);
|
bmi160->gpio = device_get_binding((char *)cfg->gpio_port);
|
||||||
if (!bmi160->gpio) {
|
if (!bmi160->gpio) {
|
||||||
SYS_LOG_DBG("Gpio controller %s not found.", cfg->gpio_port);
|
LOG_DBG("Gpio controller %s not found.", cfg->gpio_port);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +297,7 @@ int bmi160_trigger_mode_init(struct device *dev)
|
||||||
|
|
||||||
/* map all interrupts to INT1 pin */
|
/* map all interrupts to INT1 pin */
|
||||||
if (bmi160_word_write(dev, BMI160_REG_INT_MAP0, 0xf0ff) < 0) {
|
if (bmi160_word_write(dev, BMI160_REG_INT_MAP0, 0xf0ff) < 0) {
|
||||||
SYS_LOG_DBG("Failed to map interrupts.");
|
LOG_DBG("Failed to map interrupts.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,12 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <logging/log.h>
|
||||||
#include "bmm150.h"
|
#include "bmm150.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(BMM150);
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
int freq;
|
int freq;
|
||||||
u8_t reg_val;
|
u8_t reg_val;
|
||||||
|
@ -298,7 +302,7 @@ static int bmm150_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
if (i2c_burst_read(drv_data->i2c, config->i2c_slave_addr,
|
if (i2c_burst_read(drv_data->i2c, config->i2c_slave_addr,
|
||||||
BMM150_REG_X_L, (u8_t *)values,
|
BMM150_REG_X_L, (u8_t *)values,
|
||||||
sizeof(values)) < 0) {
|
sizeof(values)) < 0) {
|
||||||
SYS_LOG_ERR("failed to read sample");
|
LOG_ERR("failed to read sample");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,7 +455,7 @@ static int bmm150_attr_set(struct device *dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->max_odr < val->val1) {
|
if (data->max_odr < val->val1) {
|
||||||
SYS_LOG_ERR("not supported with current oversampling");
|
LOG_ERR("not supported with current oversampling");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -489,35 +493,35 @@ static int bmm150_init_chip(struct device *dev)
|
||||||
struct bmm150_preset preset;
|
struct bmm150_preset preset;
|
||||||
|
|
||||||
if (bmm150_set_power_mode(dev, BMM150_POWER_MODE_NORMAL, 0) < 0) {
|
if (bmm150_set_power_mode(dev, BMM150_POWER_MODE_NORMAL, 0) < 0) {
|
||||||
SYS_LOG_ERR("failed to bring up device from normal mode");
|
LOG_ERR("failed to bring up device from normal mode");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bmm150_set_power_mode(dev, BMM150_POWER_MODE_SUSPEND, 1) < 0) {
|
if (bmm150_set_power_mode(dev, BMM150_POWER_MODE_SUSPEND, 1) < 0) {
|
||||||
SYS_LOG_ERR("failed to bring up device in suspend mode");
|
LOG_ERR("failed to bring up device in suspend mode");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bmm150_set_power_mode(dev, BMM150_POWER_MODE_SUSPEND, 0)
|
if (bmm150_set_power_mode(dev, BMM150_POWER_MODE_SUSPEND, 0)
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_ERR("failed to bring up device from suspend mode");
|
LOG_ERR("failed to bring up device from suspend mode");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_read_byte(data->i2c, config->i2c_slave_addr,
|
if (i2c_reg_read_byte(data->i2c, config->i2c_slave_addr,
|
||||||
BMM150_REG_CHIP_ID, &chip_id) < 0) {
|
BMM150_REG_CHIP_ID, &chip_id) < 0) {
|
||||||
SYS_LOG_ERR("failed reading chip id");
|
LOG_ERR("failed reading chip id");
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chip_id != BMM150_CHIP_ID_VAL) {
|
if (chip_id != BMM150_CHIP_ID_VAL) {
|
||||||
SYS_LOG_ERR("invalid chip id 0x%x", chip_id);
|
LOG_ERR("invalid chip id 0x%x", chip_id);
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
preset = bmm150_presets_table[BMM150_DEFAULT_PRESET];
|
preset = bmm150_presets_table[BMM150_DEFAULT_PRESET];
|
||||||
if (bmm150_set_odr(dev, preset.odr) < 0) {
|
if (bmm150_set_odr(dev, preset.odr) < 0) {
|
||||||
SYS_LOG_ERR("failed to set ODR to %d",
|
LOG_ERR("failed to set ODR to %d",
|
||||||
preset.odr);
|
preset.odr);
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
@ -526,7 +530,7 @@ static int bmm150_init_chip(struct device *dev)
|
||||||
BMM150_REG_REP_XY,
|
BMM150_REG_REP_XY,
|
||||||
BMM150_REPXY_TO_REGVAL(preset.rep_xy))
|
BMM150_REPXY_TO_REGVAL(preset.rep_xy))
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_ERR("failed to set REP XY to %d",
|
LOG_ERR("failed to set REP XY to %d",
|
||||||
preset.rep_xy);
|
preset.rep_xy);
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
@ -534,20 +538,20 @@ static int bmm150_init_chip(struct device *dev)
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_slave_addr,
|
if (i2c_reg_write_byte(data->i2c, config->i2c_slave_addr,
|
||||||
BMM150_REG_REP_Z,
|
BMM150_REG_REP_Z,
|
||||||
BMM150_REPZ_TO_REGVAL(preset.rep_z)) < 0) {
|
BMM150_REPZ_TO_REGVAL(preset.rep_z)) < 0) {
|
||||||
SYS_LOG_ERR("failed to set REP Z to %d",
|
LOG_ERR("failed to set REP Z to %d",
|
||||||
preset.rep_z);
|
preset.rep_z);
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bmm150_set_power_mode(dev, BMM150_POWER_MODE_NORMAL, 1)
|
if (bmm150_set_power_mode(dev, BMM150_POWER_MODE_NORMAL, 1)
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_ERR("failed to power on device");
|
LOG_ERR("failed to power on device");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_burst_read(data->i2c, config->i2c_slave_addr,
|
if (i2c_burst_read(data->i2c, config->i2c_slave_addr,
|
||||||
BMM150_REG_TRIM_START, (u8_t *)&data->tregs,
|
BMM150_REG_TRIM_START, (u8_t *)&data->tregs,
|
||||||
sizeof(data->tregs)) < 0) {
|
sizeof(data->tregs)) < 0) {
|
||||||
SYS_LOG_ERR("failed to read trim regs");
|
LOG_ERR("failed to read trim regs");
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -581,13 +585,13 @@ static int bmm150_init(struct device *dev)
|
||||||
|
|
||||||
data->i2c = device_get_binding(config->i2c_master_dev_name);
|
data->i2c = device_get_binding(config->i2c_master_dev_name);
|
||||||
if (!data->i2c) {
|
if (!data->i2c) {
|
||||||
SYS_LOG_ERR("i2c master not found: %s",
|
LOG_ERR("i2c master not found: %s",
|
||||||
config->i2c_master_dev_name);
|
config->i2c_master_dev_name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bmm150_init_chip(dev) < 0) {
|
if (bmm150_init_chip(dev) < 0) {
|
||||||
SYS_LOG_ERR("failed to initialize chip");
|
LOG_ERR("failed to initialize chip");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
#include <gpio.h>
|
#include <gpio.h>
|
||||||
|
|
||||||
|
|
||||||
#define BMM150_REG_CHIP_ID 0x40
|
#define BMM150_REG_CHIP_ID 0x40
|
||||||
#define BMM150_CHIP_ID_VAL 0x32
|
#define BMM150_CHIP_ID_VAL 0x32
|
||||||
|
|
||||||
|
@ -158,7 +157,4 @@ enum bmm150_presets {
|
||||||
#define BMM150_DEFAULT_PRESET BMM150_HIGH_ACCURACY_PRESET
|
#define BMM150_DEFAULT_PRESET BMM150_HIGH_ACCURACY_PRESET
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "BMM150"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* __SENSOR_BMM150_H__ */
|
#endif /* __SENSOR_BMM150_H__ */
|
||||||
|
|
|
@ -12,9 +12,13 @@
|
||||||
#include <misc/util.h>
|
#include <misc/util.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "ccs811.h"
|
#include "ccs811.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(CCS811);
|
||||||
|
|
||||||
static int ccs811_sample_fetch(struct device *dev, enum sensor_channel chan)
|
static int ccs811_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
{
|
{
|
||||||
struct ccs811_data *drv_data = dev->driver_data;
|
struct ccs811_data *drv_data = dev->driver_data;
|
||||||
|
@ -26,7 +30,7 @@ static int ccs811_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
while (tries-- > 0) {
|
while (tries-- > 0) {
|
||||||
if (i2c_reg_read_byte(drv_data->i2c, CONFIG_CCS811_I2C_ADDR,
|
if (i2c_reg_read_byte(drv_data->i2c, CONFIG_CCS811_I2C_ADDR,
|
||||||
CCS811_REG_STATUS, &status) < 0) {
|
CCS811_REG_STATUS, &status) < 0) {
|
||||||
SYS_LOG_ERR("Failed to read Status register");
|
LOG_ERR("Failed to read Status register");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,13 +42,13 @@ static int ccs811_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(status & CCS811_STATUS_DATA_READY)) {
|
if (!(status & CCS811_STATUS_DATA_READY)) {
|
||||||
SYS_LOG_ERR("Sensor data not available");
|
LOG_ERR("Sensor data not available");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_burst_read(drv_data->i2c, CONFIG_CCS811_I2C_ADDR,
|
if (i2c_burst_read(drv_data->i2c, CONFIG_CCS811_I2C_ADDR,
|
||||||
CCS811_REG_ALG_RESULT_DATA, (u8_t *)buf, 8) < 0) {
|
CCS811_REG_ALG_RESULT_DATA, (u8_t *)buf, 8) < 0) {
|
||||||
SYS_LOG_ERR("Failed to read conversion data.");
|
LOG_ERR("Failed to read conversion data.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,40 +115,40 @@ static int switch_to_app_mode(struct device *i2c)
|
||||||
{
|
{
|
||||||
u8_t status, buf;
|
u8_t status, buf;
|
||||||
|
|
||||||
SYS_LOG_DBG("Switching to Application mode...");
|
LOG_DBG("Switching to Application mode...");
|
||||||
|
|
||||||
if (i2c_reg_read_byte(i2c, CONFIG_CCS811_I2C_ADDR,
|
if (i2c_reg_read_byte(i2c, CONFIG_CCS811_I2C_ADDR,
|
||||||
CCS811_REG_STATUS, &status) < 0) {
|
CCS811_REG_STATUS, &status) < 0) {
|
||||||
SYS_LOG_ERR("Failed to read Status register");
|
LOG_ERR("Failed to read Status register");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for the application firmware */
|
/* Check for the application firmware */
|
||||||
if (!(status & CCS811_STATUS_APP_VALID)) {
|
if (!(status & CCS811_STATUS_APP_VALID)) {
|
||||||
SYS_LOG_ERR("No Application firmware loaded");
|
LOG_ERR("No Application firmware loaded");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = CCS811_REG_APP_START;
|
buf = CCS811_REG_APP_START;
|
||||||
/* Set the device to application mode */
|
/* Set the device to application mode */
|
||||||
if (i2c_write(i2c, &buf, 1, CONFIG_CCS811_I2C_ADDR) < 0) {
|
if (i2c_write(i2c, &buf, 1, CONFIG_CCS811_I2C_ADDR) < 0) {
|
||||||
SYS_LOG_ERR("Failed to set Application mode");
|
LOG_ERR("Failed to set Application mode");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_read_byte(i2c, CONFIG_CCS811_I2C_ADDR,
|
if (i2c_reg_read_byte(i2c, CONFIG_CCS811_I2C_ADDR,
|
||||||
CCS811_REG_STATUS, &status) < 0) {
|
CCS811_REG_STATUS, &status) < 0) {
|
||||||
SYS_LOG_ERR("Failed to read Status register");
|
LOG_ERR("Failed to read Status register");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for application mode */
|
/* Check for application mode */
|
||||||
if (!(status & CCS811_STATUS_FW_MODE)) {
|
if (!(status & CCS811_STATUS_FW_MODE)) {
|
||||||
SYS_LOG_ERR("Failed to start Application firmware");
|
LOG_ERR("Failed to start Application firmware");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_DBG("CCS811 Application firmware started!");
|
LOG_DBG("CCS811 Application firmware started!");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +161,7 @@ int ccs811_init(struct device *dev)
|
||||||
|
|
||||||
drv_data->i2c = device_get_binding(CONFIG_CCS811_I2C_MASTER_DEV_NAME);
|
drv_data->i2c = device_get_binding(CONFIG_CCS811_I2C_MASTER_DEV_NAME);
|
||||||
if (drv_data->i2c == NULL) {
|
if (drv_data->i2c == NULL) {
|
||||||
SYS_LOG_ERR("Failed to get pointer to %s device!",
|
LOG_ERR("Failed to get pointer to %s device!",
|
||||||
CONFIG_CCS811_I2C_MASTER_DEV_NAME);
|
CONFIG_CCS811_I2C_MASTER_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -165,7 +169,7 @@ int ccs811_init(struct device *dev)
|
||||||
#if defined(CONFIG_CCS811_GPIO_WAKEUP) || defined(CONFIG_CCS811_GPIO_RESET)
|
#if defined(CONFIG_CCS811_GPIO_WAKEUP) || defined(CONFIG_CCS811_GPIO_RESET)
|
||||||
drv_data->gpio = device_get_binding(CONFIG_CCS811_GPIO_DEV_NAME);
|
drv_data->gpio = device_get_binding(CONFIG_CCS811_GPIO_DEV_NAME);
|
||||||
if (drv_data->gpio == NULL) {
|
if (drv_data->gpio == NULL) {
|
||||||
SYS_LOG_ERR("Failed to get pointer to %s device!",
|
LOG_ERR("Failed to get pointer to %s device!",
|
||||||
CONFIG_CCS811_GPIO_DEV_NAME);
|
CONFIG_CCS811_GPIO_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -200,12 +204,12 @@ int ccs811_init(struct device *dev)
|
||||||
/* Check Hardware ID */
|
/* Check Hardware ID */
|
||||||
if (i2c_reg_read_byte(drv_data->i2c, CONFIG_CCS811_I2C_ADDR,
|
if (i2c_reg_read_byte(drv_data->i2c, CONFIG_CCS811_I2C_ADDR,
|
||||||
CCS811_REG_HW_ID, &hw_id) < 0) {
|
CCS811_REG_HW_ID, &hw_id) < 0) {
|
||||||
SYS_LOG_ERR("Failed to read Hardware ID register");
|
LOG_ERR("Failed to read Hardware ID register");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hw_id != CCS881_HW_ID) {
|
if (hw_id != CCS881_HW_ID) {
|
||||||
SYS_LOG_ERR("Hardware ID mismatch!");
|
LOG_ERR("Hardware ID mismatch!");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,19 +217,19 @@ int ccs811_init(struct device *dev)
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, CONFIG_CCS811_I2C_ADDR,
|
if (i2c_reg_write_byte(drv_data->i2c, CONFIG_CCS811_I2C_ADDR,
|
||||||
CCS811_REG_MEAS_MODE,
|
CCS811_REG_MEAS_MODE,
|
||||||
CCS811_MODE_IAQ_1SEC) < 0) {
|
CCS811_MODE_IAQ_1SEC) < 0) {
|
||||||
SYS_LOG_ERR("Failed to set Measurement mode");
|
LOG_ERR("Failed to set Measurement mode");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for error */
|
/* Check for error */
|
||||||
if (i2c_reg_read_byte(drv_data->i2c, CONFIG_CCS811_I2C_ADDR,
|
if (i2c_reg_read_byte(drv_data->i2c, CONFIG_CCS811_I2C_ADDR,
|
||||||
CCS811_REG_STATUS, &status) < 0) {
|
CCS811_REG_STATUS, &status) < 0) {
|
||||||
SYS_LOG_ERR("Failed to read Status register");
|
LOG_ERR("Failed to read Status register");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status & CCS811_STATUS_ERROR) {
|
if (status & CCS811_STATUS_ERROR) {
|
||||||
SYS_LOG_ERR("Error occurred during sensor configuration");
|
LOG_ERR("Error occurred during sensor configuration");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,4 @@ struct ccs811_data {
|
||||||
u16_t resistance;
|
u16_t resistance;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "CCS811"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#endif /* _SENSOR_CCS811_ */
|
#endif /* _SENSOR_CCS811_ */
|
||||||
|
|
|
@ -11,9 +11,13 @@
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <zephyr.h>
|
#include <zephyr.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "dht.h"
|
#include "dht.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(DHT);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Measure duration of signal send by sensor
|
* @brief Measure duration of signal send by sensor
|
||||||
*
|
*
|
||||||
|
@ -141,7 +145,7 @@ static int dht_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
|
|
||||||
/* verify checksum */
|
/* verify checksum */
|
||||||
if (((buf[0] + buf[1] + buf[2] + buf[3]) & 0xFF) != buf[4]) {
|
if (((buf[0] + buf[1] + buf[2] + buf[3]) & 0xFF) != buf[4]) {
|
||||||
SYS_LOG_DBG("Invalid checksum in fetched sample");
|
LOG_DBG("Invalid checksum in fetched sample");
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
} else {
|
} else {
|
||||||
memcpy(drv_data->sample, buf, 4);
|
memcpy(drv_data->sample, buf, 4);
|
||||||
|
@ -216,7 +220,7 @@ static int dht_init(struct device *dev)
|
||||||
|
|
||||||
drv_data->gpio = device_get_binding(CONFIG_DHT_GPIO_DEV_NAME);
|
drv_data->gpio = device_get_binding(CONFIG_DHT_GPIO_DEV_NAME);
|
||||||
if (drv_data->gpio == NULL) {
|
if (drv_data->gpio == NULL) {
|
||||||
SYS_LOG_ERR("Failed to get GPIO device.");
|
LOG_ERR("Failed to get GPIO device.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,6 @@
|
||||||
|
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "DHT"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#define DHT_START_SIGNAL_DURATION 18000
|
#define DHT_START_SIGNAL_DURATION 18000
|
||||||
#define DHT_SIGNAL_MAX_WAIT_DURATION 100
|
#define DHT_SIGNAL_MAX_WAIT_DURATION 100
|
||||||
#define DHT_DATA_BITS_NUM 40
|
#define DHT_DATA_BITS_NUM 40
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
#include "fxas21002.h"
|
#include "fxas21002.h"
|
||||||
#include <misc/util.h>
|
#include <misc/util.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(FXAS21002);
|
||||||
|
|
||||||
/* Sample period in microseconds, indexed by output data rate encoding (DR) */
|
/* Sample period in microseconds, indexed by output data rate encoding (DR) */
|
||||||
static const u32_t sample_period[] = {
|
static const u32_t sample_period[] = {
|
||||||
|
@ -23,7 +27,7 @@ static int fxas21002_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (chan != SENSOR_CHAN_ALL) {
|
if (chan != SENSOR_CHAN_ALL) {
|
||||||
SYS_LOG_ERR("Unsupported sensor channel");
|
LOG_ERR("Unsupported sensor channel");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +36,7 @@ static int fxas21002_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
/* Read all the channels in one I2C transaction. */
|
/* Read all the channels in one I2C transaction. */
|
||||||
if (i2c_burst_read(data->i2c, config->i2c_address,
|
if (i2c_burst_read(data->i2c, config->i2c_address,
|
||||||
FXAS21002_REG_OUTXMSB, buffer, sizeof(buffer))) {
|
FXAS21002_REG_OUTXMSB, buffer, sizeof(buffer))) {
|
||||||
SYS_LOG_ERR("Could not fetch sample");
|
LOG_ERR("Could not fetch sample");
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +121,7 @@ static int fxas21002_channel_get(struct device *dev, enum sensor_channel chan,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
SYS_LOG_ERR("Unsupported sensor channel");
|
LOG_ERR("Unsupported sensor channel");
|
||||||
}
|
}
|
||||||
|
|
||||||
k_sem_give(&data->sem);
|
k_sem_give(&data->sem);
|
||||||
|
@ -134,7 +138,7 @@ int fxas21002_get_power(struct device *dev, enum fxas21002_power *power)
|
||||||
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
||||||
FXAS21002_REG_CTRLREG1,
|
FXAS21002_REG_CTRLREG1,
|
||||||
&val)) {
|
&val)) {
|
||||||
SYS_LOG_ERR("Could not get power setting");
|
LOG_ERR("Could not get power setting");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
val &= FXAS21002_CTRLREG1_POWER_MASK;
|
val &= FXAS21002_CTRLREG1_POWER_MASK;
|
||||||
|
@ -190,7 +194,7 @@ static int fxas21002_init(struct device *dev)
|
||||||
/* Get the I2C device */
|
/* Get the I2C device */
|
||||||
data->i2c = device_get_binding(config->i2c_name);
|
data->i2c = device_get_binding(config->i2c_name);
|
||||||
if (data->i2c == NULL) {
|
if (data->i2c == NULL) {
|
||||||
SYS_LOG_ERR("Could not find I2C device");
|
LOG_ERR("Could not find I2C device");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,12 +204,12 @@ static int fxas21002_init(struct device *dev)
|
||||||
*/
|
*/
|
||||||
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
||||||
FXAS21002_REG_WHOAMI, &whoami)) {
|
FXAS21002_REG_WHOAMI, &whoami)) {
|
||||||
SYS_LOG_ERR("Could not get WHOAMI value");
|
LOG_ERR("Could not get WHOAMI value");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (whoami != config->whoami) {
|
if (whoami != config->whoami) {
|
||||||
SYS_LOG_ERR("WHOAMI value received 0x%x, expected 0x%x",
|
LOG_ERR("WHOAMI value received 0x%x, expected 0x%x",
|
||||||
whoami, config->whoami);
|
whoami, config->whoami);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@ -222,7 +226,7 @@ static int fxas21002_init(struct device *dev)
|
||||||
do {
|
do {
|
||||||
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
||||||
FXAS21002_REG_CTRLREG1, &ctrlreg1)) {
|
FXAS21002_REG_CTRLREG1, &ctrlreg1)) {
|
||||||
SYS_LOG_ERR("Could not get ctrlreg1 value");
|
LOG_ERR("Could not get ctrlreg1 value");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
} while (ctrlreg1 & FXAS21002_CTRLREG1_RST_MASK);
|
} while (ctrlreg1 & FXAS21002_CTRLREG1_RST_MASK);
|
||||||
|
@ -232,7 +236,7 @@ static int fxas21002_init(struct device *dev)
|
||||||
FXAS21002_REG_CTRLREG0,
|
FXAS21002_REG_CTRLREG0,
|
||||||
FXAS21002_CTRLREG0_FS_MASK,
|
FXAS21002_CTRLREG0_FS_MASK,
|
||||||
config->range)) {
|
config->range)) {
|
||||||
SYS_LOG_ERR("Could not set range");
|
LOG_ERR("Could not set range");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +245,7 @@ static int fxas21002_init(struct device *dev)
|
||||||
FXAS21002_REG_CTRLREG1,
|
FXAS21002_REG_CTRLREG1,
|
||||||
FXAS21002_CTRLREG1_DR_MASK,
|
FXAS21002_CTRLREG1_DR_MASK,
|
||||||
config->dr << FXAS21002_CTRLREG1_DR_SHIFT)) {
|
config->dr << FXAS21002_CTRLREG1_DR_SHIFT)) {
|
||||||
SYS_LOG_ERR("Could not set output data rate");
|
LOG_ERR("Could not set output data rate");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,14 +253,14 @@ static int fxas21002_init(struct device *dev)
|
||||||
|
|
||||||
#if CONFIG_FXAS21002_TRIGGER
|
#if CONFIG_FXAS21002_TRIGGER
|
||||||
if (fxas21002_trigger_init(dev)) {
|
if (fxas21002_trigger_init(dev)) {
|
||||||
SYS_LOG_ERR("Could not initialize interrupts");
|
LOG_ERR("Could not initialize interrupts");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Set active */
|
/* Set active */
|
||||||
if (fxas21002_set_power(dev, FXAS21002_POWER_ACTIVE)) {
|
if (fxas21002_set_power(dev, FXAS21002_POWER_ACTIVE)) {
|
||||||
SYS_LOG_ERR("Could not set active");
|
LOG_ERR("Could not set active");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +271,7 @@ static int fxas21002_init(struct device *dev)
|
||||||
k_busy_wait(transition_time);
|
k_busy_wait(transition_time);
|
||||||
k_sem_give(&data->sem);
|
k_sem_give(&data->sem);
|
||||||
|
|
||||||
SYS_LOG_DBG("Init complete");
|
LOG_DBG("Init complete");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,6 @@
|
||||||
#include <i2c.h>
|
#include <i2c.h>
|
||||||
#include <gpio.h>
|
#include <gpio.h>
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "FXAS21002"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#define FXAS21002_REG_STATUS 0x00
|
#define FXAS21002_REG_STATUS 0x00
|
||||||
#define FXAS21002_REG_OUTXMSB 0x01
|
#define FXAS21002_REG_OUTXMSB 0x01
|
||||||
#define FXAS21002_REG_INT_SOURCE 0x0b
|
#define FXAS21002_REG_INT_SOURCE 0x0b
|
||||||
|
|
|
@ -4,8 +4,14 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "fxas21002.h"
|
#include "fxas21002.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(FXAS21002);
|
||||||
|
|
||||||
static void fxas21002_gpio_callback(struct device *dev,
|
static void fxas21002_gpio_callback(struct device *dev,
|
||||||
struct gpio_callback *cb,
|
struct gpio_callback *cb,
|
||||||
u32_t pin_mask)
|
u32_t pin_mask)
|
||||||
|
@ -54,7 +60,7 @@ static void fxas21002_handle_int(void *arg)
|
||||||
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
||||||
FXAS21002_REG_INT_SOURCE,
|
FXAS21002_REG_INT_SOURCE,
|
||||||
&int_source)) {
|
&int_source)) {
|
||||||
SYS_LOG_ERR("Could not read interrupt source");
|
LOG_ERR("Could not read interrupt source");
|
||||||
int_source = 0;
|
int_source = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +118,7 @@ int fxas21002_trigger_set(struct device *dev,
|
||||||
data->drdy_handler = handler;
|
data->drdy_handler = handler;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SYS_LOG_ERR("Unsupported sensor trigger");
|
LOG_ERR("Unsupported sensor trigger");
|
||||||
ret = -ENOTSUP;
|
ret = -ENOTSUP;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
@ -122,14 +128,14 @@ int fxas21002_trigger_set(struct device *dev,
|
||||||
* can restore it later.
|
* can restore it later.
|
||||||
*/
|
*/
|
||||||
if (fxas21002_get_power(dev, &power)) {
|
if (fxas21002_get_power(dev, &power)) {
|
||||||
SYS_LOG_ERR("Could not get power mode");
|
LOG_ERR("Could not get power mode");
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Put the sensor in ready mode */
|
/* Put the sensor in ready mode */
|
||||||
if (fxas21002_set_power(dev, FXAS21002_POWER_READY)) {
|
if (fxas21002_set_power(dev, FXAS21002_POWER_READY)) {
|
||||||
SYS_LOG_ERR("Could not set ready mode");
|
LOG_ERR("Could not set ready mode");
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
@ -139,14 +145,14 @@ int fxas21002_trigger_set(struct device *dev,
|
||||||
FXAS21002_REG_CTRLREG2,
|
FXAS21002_REG_CTRLREG2,
|
||||||
mask,
|
mask,
|
||||||
handler ? mask : 0)) {
|
handler ? mask : 0)) {
|
||||||
SYS_LOG_ERR("Could not configure interrupt");
|
LOG_ERR("Could not configure interrupt");
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restore the previous power mode */
|
/* Restore the previous power mode */
|
||||||
if (fxas21002_set_power(dev, power)) {
|
if (fxas21002_set_power(dev, power)) {
|
||||||
SYS_LOG_ERR("Could not restore power mode");
|
LOG_ERR("Could not restore power mode");
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
@ -188,14 +194,14 @@ int fxas21002_trigger_init(struct device *dev)
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
||||||
FXAS21002_REG_CTRLREG2, ctrl_reg2)) {
|
FXAS21002_REG_CTRLREG2, ctrl_reg2)) {
|
||||||
SYS_LOG_ERR("Could not configure interrupt pin routing");
|
LOG_ERR("Could not configure interrupt pin routing");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the GPIO device */
|
/* Get the GPIO device */
|
||||||
data->gpio = device_get_binding(config->gpio_name);
|
data->gpio = device_get_binding(config->gpio_name);
|
||||||
if (data->gpio == NULL) {
|
if (data->gpio == NULL) {
|
||||||
SYS_LOG_ERR("Could not find GPIO device");
|
LOG_ERR("Could not find GPIO device");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
#include "fxos8700.h"
|
#include "fxos8700.h"
|
||||||
#include <misc/util.h>
|
#include <misc/util.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(FXOS8700);
|
||||||
|
|
||||||
static int fxos8700_sample_fetch(struct device *dev, enum sensor_channel chan)
|
static int fxos8700_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
{
|
{
|
||||||
|
@ -19,7 +23,7 @@ static int fxos8700_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (chan != SENSOR_CHAN_ALL) {
|
if (chan != SENSOR_CHAN_ALL) {
|
||||||
SYS_LOG_ERR("Unsupported sensor channel");
|
LOG_ERR("Unsupported sensor channel");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +39,7 @@ static int fxos8700_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
|
|
||||||
if (i2c_burst_read(data->i2c, config->i2c_address, config->start_addr,
|
if (i2c_burst_read(data->i2c, config->i2c_address, config->start_addr,
|
||||||
buffer, num_bytes)) {
|
buffer, num_bytes)) {
|
||||||
SYS_LOG_ERR("Could not fetch sample");
|
LOG_ERR("Could not fetch sample");
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +61,7 @@ static int fxos8700_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
#ifdef CONFIG_FXOS8700_TEMP
|
#ifdef CONFIG_FXOS8700_TEMP
|
||||||
if (i2c_reg_read_byte(data->i2c, config->i2c_address, FXOS8700_REG_TEMP,
|
if (i2c_reg_read_byte(data->i2c, config->i2c_address, FXOS8700_REG_TEMP,
|
||||||
&data->temp)) {
|
&data->temp)) {
|
||||||
SYS_LOG_ERR("Could not fetch temperature");
|
LOG_ERR("Could not fetch temperature");
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
@ -224,7 +228,7 @@ static int fxos8700_channel_get(struct device *dev, enum sensor_channel chan,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
SYS_LOG_ERR("Unsupported sensor channel");
|
LOG_ERR("Unsupported sensor channel");
|
||||||
}
|
}
|
||||||
|
|
||||||
k_sem_give(&data->sem);
|
k_sem_give(&data->sem);
|
||||||
|
@ -241,7 +245,7 @@ int fxos8700_get_power(struct device *dev, enum fxos8700_power *power)
|
||||||
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
||||||
FXOS8700_REG_CTRLREG1,
|
FXOS8700_REG_CTRLREG1,
|
||||||
&val)) {
|
&val)) {
|
||||||
SYS_LOG_ERR("Could not get power setting");
|
LOG_ERR("Could not get power setting");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
val &= FXOS8700_M_CTRLREG1_MODE_MASK;
|
val &= FXOS8700_M_CTRLREG1_MODE_MASK;
|
||||||
|
@ -270,7 +274,7 @@ static int fxos8700_init(struct device *dev)
|
||||||
/* Get the I2C device */
|
/* Get the I2C device */
|
||||||
data->i2c = device_get_binding(config->i2c_name);
|
data->i2c = device_get_binding(config->i2c_name);
|
||||||
if (data->i2c == NULL) {
|
if (data->i2c == NULL) {
|
||||||
SYS_LOG_ERR("Could not find I2C device");
|
LOG_ERR("Could not find I2C device");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,12 +284,12 @@ static int fxos8700_init(struct device *dev)
|
||||||
*/
|
*/
|
||||||
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
||||||
FXOS8700_REG_WHOAMI, &whoami)) {
|
FXOS8700_REG_WHOAMI, &whoami)) {
|
||||||
SYS_LOG_ERR("Could not get WHOAMI value");
|
LOG_ERR("Could not get WHOAMI value");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (whoami != config->whoami) {
|
if (whoami != config->whoami) {
|
||||||
SYS_LOG_ERR("WHOAMI value received 0x%x, expected 0x%x",
|
LOG_ERR("WHOAMI value received 0x%x, expected 0x%x",
|
||||||
whoami, FXOS8700_REG_WHOAMI);
|
whoami, FXOS8700_REG_WHOAMI);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@ -308,7 +312,7 @@ static int fxos8700_init(struct device *dev)
|
||||||
FXOS8700_REG_M_CTRLREG1,
|
FXOS8700_REG_M_CTRLREG1,
|
||||||
FXOS8700_M_CTRLREG1_MODE_MASK,
|
FXOS8700_M_CTRLREG1_MODE_MASK,
|
||||||
config->mode)) {
|
config->mode)) {
|
||||||
SYS_LOG_ERR("Could not set mode");
|
LOG_ERR("Could not set mode");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,7 +323,7 @@ static int fxos8700_init(struct device *dev)
|
||||||
FXOS8700_REG_M_CTRLREG2,
|
FXOS8700_REG_M_CTRLREG2,
|
||||||
FXOS8700_M_CTRLREG2_AUTOINC_MASK,
|
FXOS8700_M_CTRLREG2_AUTOINC_MASK,
|
||||||
FXOS8700_M_CTRLREG2_AUTOINC_MASK)) {
|
FXOS8700_M_CTRLREG2_AUTOINC_MASK)) {
|
||||||
SYS_LOG_ERR("Could not set hybrid autoincrement");
|
LOG_ERR("Could not set hybrid autoincrement");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +332,7 @@ static int fxos8700_init(struct device *dev)
|
||||||
FXOS8700_REG_XYZ_DATA_CFG,
|
FXOS8700_REG_XYZ_DATA_CFG,
|
||||||
FXOS8700_XYZ_DATA_CFG_FS_MASK,
|
FXOS8700_XYZ_DATA_CFG_FS_MASK,
|
||||||
config->range)) {
|
config->range)) {
|
||||||
SYS_LOG_ERR("Could not set range");
|
LOG_ERR("Could not set range");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,19 +340,19 @@ static int fxos8700_init(struct device *dev)
|
||||||
|
|
||||||
#if CONFIG_FXOS8700_TRIGGER
|
#if CONFIG_FXOS8700_TRIGGER
|
||||||
if (fxos8700_trigger_init(dev)) {
|
if (fxos8700_trigger_init(dev)) {
|
||||||
SYS_LOG_ERR("Could not initialize interrupts");
|
LOG_ERR("Could not initialize interrupts");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Set active */
|
/* Set active */
|
||||||
if (fxos8700_set_power(dev, FXOS8700_POWER_ACTIVE)) {
|
if (fxos8700_set_power(dev, FXOS8700_POWER_ACTIVE)) {
|
||||||
SYS_LOG_ERR("Could not set active");
|
LOG_ERR("Could not set active");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
k_sem_give(&data->sem);
|
k_sem_give(&data->sem);
|
||||||
|
|
||||||
SYS_LOG_DBG("Init complete");
|
LOG_DBG("Init complete");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,6 @@
|
||||||
#include <i2c.h>
|
#include <i2c.h>
|
||||||
#include <gpio.h>
|
#include <gpio.h>
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "FXOS8700"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#define FXOS8700_REG_STATUS 0x00
|
#define FXOS8700_REG_STATUS 0x00
|
||||||
#define FXOS8700_REG_OUTXMSB 0x01
|
#define FXOS8700_REG_OUTXMSB 0x01
|
||||||
#define FXOS8700_REG_INT_SOURCE 0x0c
|
#define FXOS8700_REG_INT_SOURCE 0x0c
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
|
|
||||||
#include "fxos8700.h"
|
#include "fxos8700.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(FXOS8700);
|
||||||
|
|
||||||
static void fxos8700_gpio_callback(struct device *dev,
|
static void fxos8700_gpio_callback(struct device *dev,
|
||||||
struct gpio_callback *cb,
|
struct gpio_callback *cb,
|
||||||
u32_t pin_mask)
|
u32_t pin_mask)
|
||||||
|
@ -59,7 +63,7 @@ static int fxos8700_handle_pulse_int(struct device *dev)
|
||||||
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
||||||
FXOS8700_REG_PULSE_SRC,
|
FXOS8700_REG_PULSE_SRC,
|
||||||
&pulse_source)) {
|
&pulse_source)) {
|
||||||
SYS_LOG_ERR("Could not read pulse source");
|
LOG_ERR("Could not read pulse source");
|
||||||
}
|
}
|
||||||
|
|
||||||
k_sem_give(&data->sem);
|
k_sem_give(&data->sem);
|
||||||
|
@ -92,7 +96,7 @@ static void fxos8700_handle_int(void *arg)
|
||||||
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
||||||
FXOS8700_REG_INT_SOURCE,
|
FXOS8700_REG_INT_SOURCE,
|
||||||
&int_source)) {
|
&int_source)) {
|
||||||
SYS_LOG_ERR("Could not read interrupt source");
|
LOG_ERR("Could not read interrupt source");
|
||||||
int_source = 0;
|
int_source = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +168,7 @@ int fxos8700_trigger_set(struct device *dev,
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
SYS_LOG_ERR("Unsupported sensor trigger");
|
LOG_ERR("Unsupported sensor trigger");
|
||||||
ret = -ENOTSUP;
|
ret = -ENOTSUP;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
@ -174,14 +178,14 @@ int fxos8700_trigger_set(struct device *dev,
|
||||||
* later.
|
* later.
|
||||||
*/
|
*/
|
||||||
if (fxos8700_get_power(dev, &power)) {
|
if (fxos8700_get_power(dev, &power)) {
|
||||||
SYS_LOG_ERR("Could not get power mode");
|
LOG_ERR("Could not get power mode");
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Put the sensor in standby mode */
|
/* Put the sensor in standby mode */
|
||||||
if (fxos8700_set_power(dev, FXOS8700_POWER_STANDBY)) {
|
if (fxos8700_set_power(dev, FXOS8700_POWER_STANDBY)) {
|
||||||
SYS_LOG_ERR("Could not set standby mode");
|
LOG_ERR("Could not set standby mode");
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
@ -191,14 +195,14 @@ int fxos8700_trigger_set(struct device *dev,
|
||||||
FXOS8700_REG_CTRLREG4,
|
FXOS8700_REG_CTRLREG4,
|
||||||
mask,
|
mask,
|
||||||
handler ? mask : 0)) {
|
handler ? mask : 0)) {
|
||||||
SYS_LOG_ERR("Could not configure interrupt");
|
LOG_ERR("Could not configure interrupt");
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restore the previous power mode */
|
/* Restore the previous power mode */
|
||||||
if (fxos8700_set_power(dev, power)) {
|
if (fxos8700_set_power(dev, power)) {
|
||||||
SYS_LOG_ERR("Could not restore power mode");
|
LOG_ERR("Could not restore power mode");
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
@ -282,13 +286,13 @@ int fxos8700_trigger_init(struct device *dev)
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
||||||
FXOS8700_REG_CTRLREG5, ctrl_reg5)) {
|
FXOS8700_REG_CTRLREG5, ctrl_reg5)) {
|
||||||
SYS_LOG_ERR("Could not configure interrupt pin routing");
|
LOG_ERR("Could not configure interrupt pin routing");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_FXOS8700_PULSE
|
#ifdef CONFIG_FXOS8700_PULSE
|
||||||
if (fxos8700_pulse_init(dev)) {
|
if (fxos8700_pulse_init(dev)) {
|
||||||
SYS_LOG_ERR("Could not configure pulse");
|
LOG_ERR("Could not configure pulse");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -296,7 +300,7 @@ int fxos8700_trigger_init(struct device *dev)
|
||||||
/* Get the GPIO device */
|
/* Get the GPIO device */
|
||||||
data->gpio = device_get_binding(config->gpio_name);
|
data->gpio = device_get_binding(config->gpio_name);
|
||||||
if (data->gpio == NULL) {
|
if (data->gpio == NULL) {
|
||||||
SYS_LOG_ERR("Could not find GPIO device");
|
LOG_ERR("Could not find GPIO device");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,13 @@
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
#include <misc/util.h>
|
#include <misc/util.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "hdc1008.h"
|
#include "hdc1008.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(HDC1008);
|
||||||
|
|
||||||
static void hdc1008_gpio_callback(struct device *dev,
|
static void hdc1008_gpio_callback(struct device *dev,
|
||||||
struct gpio_callback *cb, u32_t pins)
|
struct gpio_callback *cb, u32_t pins)
|
||||||
{
|
{
|
||||||
|
@ -37,14 +41,14 @@ static int hdc1008_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
|
|
||||||
buf[0] = HDC1008_REG_TEMP;
|
buf[0] = HDC1008_REG_TEMP;
|
||||||
if (i2c_write(drv_data->i2c, buf, 1, CONFIG_HDC1008_I2C_ADDR) < 0) {
|
if (i2c_write(drv_data->i2c, buf, 1, CONFIG_HDC1008_I2C_ADDR) < 0) {
|
||||||
SYS_LOG_DBG("Failed to write address pointer");
|
LOG_DBG("Failed to write address pointer");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
k_sem_take(&drv_data->data_sem, K_FOREVER);
|
k_sem_take(&drv_data->data_sem, K_FOREVER);
|
||||||
|
|
||||||
if (i2c_read(drv_data->i2c, buf, 4, CONFIG_HDC1008_I2C_ADDR) < 0) {
|
if (i2c_read(drv_data->i2c, buf, 4, CONFIG_HDC1008_I2C_ADDR) < 0) {
|
||||||
SYS_LOG_DBG("Failed to read sample data");
|
LOG_DBG("Failed to read sample data");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +99,7 @@ static u16_t read16(struct device *dev, u8_t a, u8_t d)
|
||||||
{
|
{
|
||||||
u8_t buf[2];
|
u8_t buf[2];
|
||||||
if (i2c_burst_read(dev, a, d, (u8_t *)buf, 2) < 0) {
|
if (i2c_burst_read(dev, a, d, (u8_t *)buf, 2) < 0) {
|
||||||
SYS_LOG_ERR("Error reading register.");
|
LOG_ERR("Error reading register.");
|
||||||
}
|
}
|
||||||
return (buf[0] << 8 | buf[1]);
|
return (buf[0] << 8 | buf[1]);
|
||||||
}
|
}
|
||||||
|
@ -107,19 +111,19 @@ static int hdc1008_init(struct device *dev)
|
||||||
drv_data->i2c = device_get_binding(CONFIG_HDC1008_I2C_MASTER_DEV_NAME);
|
drv_data->i2c = device_get_binding(CONFIG_HDC1008_I2C_MASTER_DEV_NAME);
|
||||||
|
|
||||||
if (drv_data->i2c == NULL) {
|
if (drv_data->i2c == NULL) {
|
||||||
SYS_LOG_DBG("Failed to get pointer to %s device!",
|
LOG_DBG("Failed to get pointer to %s device!",
|
||||||
CONFIG_HDC1008_I2C_MASTER_DEV_NAME);
|
CONFIG_HDC1008_I2C_MASTER_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read16(drv_data->i2c, CONFIG_HDC1008_I2C_ADDR, HDC1000_MANUFID)
|
if (read16(drv_data->i2c, CONFIG_HDC1008_I2C_ADDR, HDC1000_MANUFID)
|
||||||
!= 0x5449) {
|
!= 0x5449) {
|
||||||
SYS_LOG_ERR("Failed to get correct manufacturer ID");
|
LOG_ERR("Failed to get correct manufacturer ID");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
if (read16(drv_data->i2c, CONFIG_HDC1008_I2C_ADDR, HDC1000_DEVICEID)
|
if (read16(drv_data->i2c, CONFIG_HDC1008_I2C_ADDR, HDC1000_DEVICEID)
|
||||||
!= 0x1000) {
|
!= 0x1000) {
|
||||||
SYS_LOG_ERR("Failed to get correct device ID");
|
LOG_ERR("Failed to get correct device ID");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +132,7 @@ static int hdc1008_init(struct device *dev)
|
||||||
/* setup data ready gpio interrupt */
|
/* setup data ready gpio interrupt */
|
||||||
drv_data->gpio = device_get_binding(CONFIG_HDC1008_GPIO_DEV_NAME);
|
drv_data->gpio = device_get_binding(CONFIG_HDC1008_GPIO_DEV_NAME);
|
||||||
if (drv_data->gpio == NULL) {
|
if (drv_data->gpio == NULL) {
|
||||||
SYS_LOG_DBG("Failed to get pointer to %s device",
|
LOG_DBG("Failed to get pointer to %s device",
|
||||||
CONFIG_HDC1008_GPIO_DEV_NAME);
|
CONFIG_HDC1008_GPIO_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -145,7 +149,7 @@ static int hdc1008_init(struct device *dev)
|
||||||
BIT(CONFIG_HDC1008_GPIO_PIN_NUM));
|
BIT(CONFIG_HDC1008_GPIO_PIN_NUM));
|
||||||
|
|
||||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set GPIO callback");
|
LOG_DBG("Failed to set GPIO callback");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,4 @@ struct hdc1008_data {
|
||||||
struct k_sem data_sem;
|
struct k_sem data_sem;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "HDC1008"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -10,9 +10,13 @@
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "hmc5883l.h"
|
#include "hmc5883l.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(HMC5883L);
|
||||||
|
|
||||||
static void hmc5883l_convert(struct sensor_value *val, s16_t raw_val,
|
static void hmc5883l_convert(struct sensor_value *val, s16_t raw_val,
|
||||||
u16_t divider)
|
u16_t divider)
|
||||||
{
|
{
|
||||||
|
@ -58,7 +62,7 @@ static int hmc5883l_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
/* fetch magnetometer sample */
|
/* fetch magnetometer sample */
|
||||||
if (i2c_burst_read(drv_data->i2c, HMC5883L_I2C_ADDR,
|
if (i2c_burst_read(drv_data->i2c, HMC5883L_I2C_ADDR,
|
||||||
HMC5883L_REG_DATA_START, (u8_t *)buf, 6) < 0) {
|
HMC5883L_REG_DATA_START, (u8_t *)buf, 6) < 0) {
|
||||||
SYS_LOG_ERR("Failed to fetch megnetometer sample.");
|
LOG_ERR("Failed to fetch megnetometer sample.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +88,7 @@ int hmc5883l_init(struct device *dev)
|
||||||
|
|
||||||
drv_data->i2c = device_get_binding(CONFIG_HMC5883L_I2C_MASTER_DEV_NAME);
|
drv_data->i2c = device_get_binding(CONFIG_HMC5883L_I2C_MASTER_DEV_NAME);
|
||||||
if (drv_data->i2c == NULL) {
|
if (drv_data->i2c == NULL) {
|
||||||
SYS_LOG_ERR("Failed to get pointer to %s device.",
|
LOG_ERR("Failed to get pointer to %s device.",
|
||||||
CONFIG_HMC5883L_I2C_MASTER_DEV_NAME);
|
CONFIG_HMC5883L_I2C_MASTER_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -92,13 +96,13 @@ int hmc5883l_init(struct device *dev)
|
||||||
/* check chip ID */
|
/* check chip ID */
|
||||||
if (i2c_burst_read(drv_data->i2c, HMC5883L_I2C_ADDR,
|
if (i2c_burst_read(drv_data->i2c, HMC5883L_I2C_ADDR,
|
||||||
HMC5883L_REG_CHIP_ID, id, 3) < 0) {
|
HMC5883L_REG_CHIP_ID, id, 3) < 0) {
|
||||||
SYS_LOG_ERR("Failed to read chip ID.");
|
LOG_ERR("Failed to read chip ID.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id[0] != HMC5883L_CHIP_ID_A || id[1] != HMC5883L_CHIP_ID_B ||
|
if (id[0] != HMC5883L_CHIP_ID_A || id[1] != HMC5883L_CHIP_ID_B ||
|
||||||
id[2] != HMC5883L_CHIP_ID_C) {
|
id[2] != HMC5883L_CHIP_ID_C) {
|
||||||
SYS_LOG_ERR("Invalid chip ID.");
|
LOG_ERR("Invalid chip ID.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +114,7 @@ int hmc5883l_init(struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idx == ARRAY_SIZE(hmc5883l_fs_strings)) {
|
if (idx == ARRAY_SIZE(hmc5883l_fs_strings)) {
|
||||||
SYS_LOG_ERR("Invalid full-scale range value.");
|
LOG_ERR("Invalid full-scale range value.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +128,7 @@ int hmc5883l_init(struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idx == ARRAY_SIZE(hmc5883l_odr_strings)) {
|
if (idx == ARRAY_SIZE(hmc5883l_odr_strings)) {
|
||||||
SYS_LOG_ERR("Invalid ODR value.");
|
LOG_ERR("Invalid ODR value.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,13 +139,13 @@ int hmc5883l_init(struct device *dev)
|
||||||
|
|
||||||
if (i2c_burst_write(drv_data->i2c, HMC5883L_I2C_ADDR,
|
if (i2c_burst_write(drv_data->i2c, HMC5883L_I2C_ADDR,
|
||||||
HMC5883L_REG_CONFIG_A, chip_cfg, 3) < 0) {
|
HMC5883L_REG_CONFIG_A, chip_cfg, 3) < 0) {
|
||||||
SYS_LOG_ERR("Failed to configure chip.");
|
LOG_ERR("Failed to configure chip.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_HMC5883L_TRIGGER
|
#ifdef CONFIG_HMC5883L_TRIGGER
|
||||||
if (hmc5883l_init_interrupt(dev) < 0) {
|
if (hmc5883l_init_interrupt(dev) < 0) {
|
||||||
SYS_LOG_ERR("Failed to initialize interrupts.");
|
LOG_ERR("Failed to initialize interrupts.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,10 +12,6 @@
|
||||||
#include <zephyr/types.h>
|
#include <zephyr/types.h>
|
||||||
#include <gpio.h>
|
#include <gpio.h>
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "HMC5883L"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#define HMC5883L_I2C_ADDR 0x1E
|
#define HMC5883L_I2C_ADDR 0x1E
|
||||||
|
|
||||||
#define HMC5883L_REG_CONFIG_A 0x00
|
#define HMC5883L_REG_CONFIG_A 0x00
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
|
|
||||||
#include "hmc5883l.h"
|
#include "hmc5883l.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(HMC5883L);
|
||||||
|
|
||||||
int hmc5883l_trigger_set(struct device *dev,
|
int hmc5883l_trigger_set(struct device *dev,
|
||||||
const struct sensor_trigger *trig,
|
const struct sensor_trigger *trig,
|
||||||
sensor_trigger_handler_t handler)
|
sensor_trigger_handler_t handler)
|
||||||
|
@ -97,7 +101,7 @@ int hmc5883l_init_interrupt(struct device *dev)
|
||||||
/* setup data ready gpio interrupt */
|
/* setup data ready gpio interrupt */
|
||||||
drv_data->gpio = device_get_binding(CONFIG_HMC5883L_GPIO_DEV_NAME);
|
drv_data->gpio = device_get_binding(CONFIG_HMC5883L_GPIO_DEV_NAME);
|
||||||
if (drv_data->gpio == NULL) {
|
if (drv_data->gpio == NULL) {
|
||||||
SYS_LOG_ERR("Failed to get pointer to %s device.",
|
LOG_ERR("Failed to get pointer to %s device.",
|
||||||
CONFIG_HMC5883L_GPIO_DEV_NAME);
|
CONFIG_HMC5883L_GPIO_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +115,7 @@ int hmc5883l_init_interrupt(struct device *dev)
|
||||||
BIT(CONFIG_HMC5883L_GPIO_PIN_NUM));
|
BIT(CONFIG_HMC5883L_GPIO_PIN_NUM));
|
||||||
|
|
||||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||||
SYS_LOG_ERR("Failed to set gpio callback.");
|
LOG_ERR("Failed to set gpio callback.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,14 @@
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <gpio.h>
|
#include <gpio.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "hp206c.h"
|
#include "hp206c.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(HP206C);
|
||||||
|
|
||||||
static inline int hp206c_bus_config(struct device *dev)
|
static inline int hp206c_bus_config(struct device *dev)
|
||||||
{
|
{
|
||||||
struct hp206c_device_data *hp206c = dev->driver_data;
|
struct hp206c_device_data *hp206c = dev->driver_data;
|
||||||
|
@ -284,13 +289,13 @@ static int hp206c_init(struct device *dev)
|
||||||
|
|
||||||
hp206c->i2c = device_get_binding(CONFIG_HP206C_I2C_PORT_NAME);
|
hp206c->i2c = device_get_binding(CONFIG_HP206C_I2C_PORT_NAME);
|
||||||
if (!hp206c->i2c) {
|
if (!hp206c->i2c) {
|
||||||
SYS_LOG_ERR("I2C master controller not found!");
|
LOG_ERR("I2C master controller not found!");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reset the chip */
|
/* reset the chip */
|
||||||
if (hp206c_cmd_send(dev, HP206C_CMD_SOFT_RST) < 0) {
|
if (hp206c_cmd_send(dev, HP206C_CMD_SOFT_RST) < 0) {
|
||||||
SYS_LOG_ERR("Cannot reset chip.");
|
LOG_ERR("Cannot reset chip.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +304,7 @@ static int hp206c_init(struct device *dev)
|
||||||
k_busy_wait(500);
|
k_busy_wait(500);
|
||||||
|
|
||||||
if (hp206c_osr_set(dev, HP206C_DEFAULT_OSR) < 0) {
|
if (hp206c_osr_set(dev, HP206C_DEFAULT_OSR) < 0) {
|
||||||
SYS_LOG_ERR("OSR value is not supported.");
|
LOG_ERR("OSR value is not supported.");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,4 @@ struct hp206c_device_data {
|
||||||
u8_t osr;
|
u8_t osr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "HP206C"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_HP206C_HP206C_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_HP206C_HP206C_H_ */
|
||||||
|
|
|
@ -10,9 +10,13 @@
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "hts221.h"
|
#include "hts221.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(HTS221);
|
||||||
|
|
||||||
static int hts221_channel_get(struct device *dev,
|
static int hts221_channel_get(struct device *dev,
|
||||||
enum sensor_channel chan,
|
enum sensor_channel chan,
|
||||||
struct sensor_value *val)
|
struct sensor_value *val)
|
||||||
|
@ -61,7 +65,7 @@ static int hts221_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
if (i2c_burst_read(drv_data->i2c, HTS221_I2C_ADDR,
|
if (i2c_burst_read(drv_data->i2c, HTS221_I2C_ADDR,
|
||||||
HTS221_REG_DATA_START | HTS221_AUTOINCREMENT_ADDR,
|
HTS221_REG_DATA_START | HTS221_AUTOINCREMENT_ADDR,
|
||||||
buf, 4) < 0) {
|
buf, 4) < 0) {
|
||||||
SYS_LOG_ERR("Failed to fetch data sample.");
|
LOG_ERR("Failed to fetch data sample.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +82,7 @@ static int hts221_read_conversion_data(struct hts221_data *drv_data)
|
||||||
if (i2c_burst_read(drv_data->i2c, HTS221_I2C_ADDR,
|
if (i2c_burst_read(drv_data->i2c, HTS221_I2C_ADDR,
|
||||||
HTS221_REG_CONVERSION_START |
|
HTS221_REG_CONVERSION_START |
|
||||||
HTS221_AUTOINCREMENT_ADDR, buf, 16) < 0) {
|
HTS221_AUTOINCREMENT_ADDR, buf, 16) < 0) {
|
||||||
SYS_LOG_ERR("Failed to read conversion data.");
|
LOG_ERR("Failed to read conversion data.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +113,7 @@ int hts221_init(struct device *dev)
|
||||||
|
|
||||||
drv_data->i2c = device_get_binding(CONFIG_HTS221_I2C_MASTER_DEV_NAME);
|
drv_data->i2c = device_get_binding(CONFIG_HTS221_I2C_MASTER_DEV_NAME);
|
||||||
if (drv_data->i2c == NULL) {
|
if (drv_data->i2c == NULL) {
|
||||||
SYS_LOG_ERR("Could not get pointer to %s device.",
|
LOG_ERR("Could not get pointer to %s device.",
|
||||||
CONFIG_HTS221_I2C_MASTER_DEV_NAME);
|
CONFIG_HTS221_I2C_MASTER_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -117,12 +121,12 @@ int hts221_init(struct device *dev)
|
||||||
/* check chip ID */
|
/* check chip ID */
|
||||||
if (i2c_reg_read_byte(drv_data->i2c, HTS221_I2C_ADDR,
|
if (i2c_reg_read_byte(drv_data->i2c, HTS221_I2C_ADDR,
|
||||||
HTS221_REG_WHO_AM_I, &id) < 0) {
|
HTS221_REG_WHO_AM_I, &id) < 0) {
|
||||||
SYS_LOG_ERR("Failed to read chip ID.");
|
LOG_ERR("Failed to read chip ID.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id != HTS221_CHIP_ID) {
|
if (id != HTS221_CHIP_ID) {
|
||||||
SYS_LOG_ERR("Invalid chip ID.");
|
LOG_ERR("Invalid chip ID.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,14 +138,14 @@ int hts221_init(struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idx == ARRAY_SIZE(hts221_odr_strings)) {
|
if (idx == ARRAY_SIZE(hts221_odr_strings)) {
|
||||||
SYS_LOG_ERR("Invalid ODR value.");
|
LOG_ERR("Invalid ODR value.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, HTS221_I2C_ADDR, HTS221_REG_CTRL1,
|
if (i2c_reg_write_byte(drv_data->i2c, HTS221_I2C_ADDR, HTS221_REG_CTRL1,
|
||||||
(idx + 1) << HTS221_ODR_SHIFT | HTS221_BDU_BIT |
|
(idx + 1) << HTS221_ODR_SHIFT | HTS221_BDU_BIT |
|
||||||
HTS221_PD_BIT) < 0) {
|
HTS221_PD_BIT) < 0) {
|
||||||
SYS_LOG_ERR("Failed to configure chip.");
|
LOG_ERR("Failed to configure chip.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,13 +156,13 @@ int hts221_init(struct device *dev)
|
||||||
k_sleep(3);
|
k_sleep(3);
|
||||||
|
|
||||||
if (hts221_read_conversion_data(drv_data) < 0) {
|
if (hts221_read_conversion_data(drv_data) < 0) {
|
||||||
SYS_LOG_ERR("Failed to read conversion data.");
|
LOG_ERR("Failed to read conversion data.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_HTS221_TRIGGER
|
#ifdef CONFIG_HTS221_TRIGGER
|
||||||
if (hts221_init_interrupt(dev) < 0) {
|
if (hts221_init_interrupt(dev) < 0) {
|
||||||
SYS_LOG_ERR("Failed to initialize interrupt.");
|
LOG_ERR("Failed to initialize interrupt.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,10 +12,6 @@
|
||||||
#include <zephyr/types.h>
|
#include <zephyr/types.h>
|
||||||
#include <gpio.h>
|
#include <gpio.h>
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "HTS221"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#define HTS221_I2C_ADDR 0x5F
|
#define HTS221_I2C_ADDR 0x5F
|
||||||
#define HTS221_AUTOINCREMENT_ADDR BIT(7)
|
#define HTS221_AUTOINCREMENT_ADDR BIT(7)
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
|
|
||||||
#include "hts221.h"
|
#include "hts221.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(HTS221);
|
||||||
|
|
||||||
int hts221_trigger_set(struct device *dev,
|
int hts221_trigger_set(struct device *dev,
|
||||||
const struct sensor_trigger *trig,
|
const struct sensor_trigger *trig,
|
||||||
sensor_trigger_handler_t handler)
|
sensor_trigger_handler_t handler)
|
||||||
|
@ -97,7 +101,7 @@ int hts221_init_interrupt(struct device *dev)
|
||||||
/* setup data ready gpio interrupt */
|
/* setup data ready gpio interrupt */
|
||||||
drv_data->gpio = device_get_binding(CONFIG_HTS221_GPIO_DEV_NAME);
|
drv_data->gpio = device_get_binding(CONFIG_HTS221_GPIO_DEV_NAME);
|
||||||
if (drv_data->gpio == NULL) {
|
if (drv_data->gpio == NULL) {
|
||||||
SYS_LOG_ERR("Cannot get pointer to %s device.",
|
LOG_ERR("Cannot get pointer to %s device.",
|
||||||
CONFIG_HTS221_GPIO_DEV_NAME);
|
CONFIG_HTS221_GPIO_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -111,14 +115,14 @@ int hts221_init_interrupt(struct device *dev)
|
||||||
BIT(CONFIG_HTS221_GPIO_PIN_NUM));
|
BIT(CONFIG_HTS221_GPIO_PIN_NUM));
|
||||||
|
|
||||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||||
SYS_LOG_ERR("Could not set gpio callback.");
|
LOG_ERR("Could not set gpio callback.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* enable data-ready interrupt */
|
/* enable data-ready interrupt */
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, HTS221_I2C_ADDR,
|
if (i2c_reg_write_byte(drv_data->i2c, HTS221_I2C_ADDR,
|
||||||
HTS221_REG_CTRL3, HTS221_DRDY_EN) < 0) {
|
HTS221_REG_CTRL3, HTS221_DRDY_EN) < 0) {
|
||||||
SYS_LOG_ERR("Could not enable data-ready interrupt.");
|
LOG_ERR("Could not enable data-ready interrupt.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,13 @@
|
||||||
#include <i2c.h>
|
#include <i2c.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "isl29035.h"
|
#include "isl29035.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(ISL29035);
|
||||||
|
|
||||||
static int isl29035_sample_fetch(struct device *dev, enum sensor_channel chan)
|
static int isl29035_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
{
|
{
|
||||||
struct isl29035_driver_data *drv_data = dev->driver_data;
|
struct isl29035_driver_data *drv_data = dev->driver_data;
|
||||||
|
@ -73,7 +77,7 @@ static int isl29035_init(struct device *dev)
|
||||||
|
|
||||||
drv_data->i2c = device_get_binding(CONFIG_ISL29035_I2C_MASTER_DEV_NAME);
|
drv_data->i2c = device_get_binding(CONFIG_ISL29035_I2C_MASTER_DEV_NAME);
|
||||||
if (drv_data->i2c == NULL) {
|
if (drv_data->i2c == NULL) {
|
||||||
SYS_LOG_DBG("Failed to get I2C device.");
|
LOG_DBG("Failed to get I2C device.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,20 +86,20 @@ static int isl29035_init(struct device *dev)
|
||||||
/* clear blownout status bit */
|
/* clear blownout status bit */
|
||||||
if (i2c_reg_update_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
if (i2c_reg_update_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||||
ISL29035_ID_REG, ISL29035_BOUT_MASK, 0) < 0) {
|
ISL29035_ID_REG, ISL29035_BOUT_MASK, 0) < 0) {
|
||||||
SYS_LOG_DBG("Failed to clear blownout status bit.");
|
LOG_DBG("Failed to clear blownout status bit.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set command registers to set default attributes */
|
/* set command registers to set default attributes */
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
if (i2c_reg_write_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||||
ISL29035_COMMAND_I_REG, 0) < 0) {
|
ISL29035_COMMAND_I_REG, 0) < 0) {
|
||||||
SYS_LOG_DBG("Failed to clear COMMAND-I.");
|
LOG_DBG("Failed to clear COMMAND-I.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
if (i2c_reg_write_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||||
ISL29035_COMMAND_II_REG, 0) < 0) {
|
ISL29035_COMMAND_II_REG, 0) < 0) {
|
||||||
SYS_LOG_DBG("Failed to clear COMMAND-II.");
|
LOG_DBG("Failed to clear COMMAND-II.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +108,7 @@ static int isl29035_init(struct device *dev)
|
||||||
ISL29035_COMMAND_I_REG,
|
ISL29035_COMMAND_I_REG,
|
||||||
ISL29035_OPMODE_MASK,
|
ISL29035_OPMODE_MASK,
|
||||||
ISL29035_ACTIVE_OPMODE_BITS) < 0) {
|
ISL29035_ACTIVE_OPMODE_BITS) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set opmode.");
|
LOG_DBG("Failed to set opmode.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +117,7 @@ static int isl29035_init(struct device *dev)
|
||||||
ISL29035_COMMAND_II_REG,
|
ISL29035_COMMAND_II_REG,
|
||||||
ISL29035_LUX_RANGE_MASK,
|
ISL29035_LUX_RANGE_MASK,
|
||||||
ISL29035_LUX_RANGE_BITS) < 0) {
|
ISL29035_LUX_RANGE_BITS) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set lux range.");
|
LOG_DBG("Failed to set lux range.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,13 +126,13 @@ static int isl29035_init(struct device *dev)
|
||||||
ISL29035_COMMAND_II_REG,
|
ISL29035_COMMAND_II_REG,
|
||||||
ISL29035_ADC_RES_MASK,
|
ISL29035_ADC_RES_MASK,
|
||||||
ISL29035_ADC_RES_BITS) < 0) {
|
ISL29035_ADC_RES_BITS) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set ADC resolution.");
|
LOG_DBG("Failed to set ADC resolution.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_ISL29035_TRIGGER
|
#ifdef CONFIG_ISL29035_TRIGGER
|
||||||
if (isl29035_init_interrupt(dev) < 0) {
|
if (isl29035_init_interrupt(dev) < 0) {
|
||||||
SYS_LOG_DBG("Failed to initialize interrupt.");
|
LOG_DBG("Failed to initialize interrupt.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -146,7 +146,4 @@ int isl29035_trigger_set(struct device *dev,
|
||||||
int isl29035_init_interrupt(struct device *dev);
|
int isl29035_init_interrupt(struct device *dev);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "ISL29035"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_ISL29035_ISL29035_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_ISL29035_ISL29035_H_ */
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
|
|
||||||
extern struct isl29035_driver_data isl29035_data;
|
extern struct isl29035_driver_data isl29035_data;
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(ISL29035);
|
||||||
|
|
||||||
static u16_t isl29035_lux_processed_to_raw(struct sensor_value const *val)
|
static u16_t isl29035_lux_processed_to_raw(struct sensor_value const *val)
|
||||||
{
|
{
|
||||||
u64_t raw_val;
|
u64_t raw_val;
|
||||||
|
@ -50,7 +54,7 @@ int isl29035_attr_set(struct device *dev,
|
||||||
lsb_reg, raw_val & 0xFF) < 0 ||
|
lsb_reg, raw_val & 0xFF) < 0 ||
|
||||||
i2c_reg_write_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
i2c_reg_write_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||||
msb_reg, raw_val >> 8) < 0) {
|
msb_reg, raw_val >> 8) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set attribute.");
|
LOG_DBG("Failed to set attribute.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,14 +146,14 @@ int isl29035_init_interrupt(struct device *dev)
|
||||||
ISL29035_COMMAND_I_REG,
|
ISL29035_COMMAND_I_REG,
|
||||||
ISL29035_INT_PRST_MASK,
|
ISL29035_INT_PRST_MASK,
|
||||||
ISL29035_INT_PRST_BITS) < 0) {
|
ISL29035_INT_PRST_BITS) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set interrupt persistence cycles.");
|
LOG_DBG("Failed to set interrupt persistence cycles.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* setup gpio interrupt */
|
/* setup gpio interrupt */
|
||||||
drv_data->gpio = device_get_binding(CONFIG_ISL29035_GPIO_DEV_NAME);
|
drv_data->gpio = device_get_binding(CONFIG_ISL29035_GPIO_DEV_NAME);
|
||||||
if (drv_data->gpio == NULL) {
|
if (drv_data->gpio == NULL) {
|
||||||
SYS_LOG_DBG("Failed to get GPIO device.");
|
LOG_DBG("Failed to get GPIO device.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +166,7 @@ int isl29035_init_interrupt(struct device *dev)
|
||||||
BIT(CONFIG_ISL29035_GPIO_PIN_NUM));
|
BIT(CONFIG_ISL29035_GPIO_PIN_NUM));
|
||||||
|
|
||||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set gpio callback.");
|
LOG_DBG("Failed to set gpio callback.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,10 @@
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(lis2dh);
|
||||||
|
|
||||||
#if defined(CONFIG_LIS2DH_BUS_SPI)
|
#if defined(CONFIG_LIS2DH_BUS_SPI)
|
||||||
int lis2dh_spi_access(struct lis2dh_data *ctx, u8_t cmd,
|
int lis2dh_spi_access(struct lis2dh_data *ctx, u8_t cmd,
|
||||||
|
@ -134,7 +138,7 @@ static int lis2dh_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
lis2dh->sample.raw,
|
lis2dh->sample.raw,
|
||||||
sizeof(lis2dh->sample.raw));
|
sizeof(lis2dh->sample.raw));
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
SYS_LOG_WRN("Could not read accel axis data");
|
LOG_WRN("Could not read accel axis data");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +149,7 @@ static int lis2dh_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
*sample = sys_le16_to_cpu(*sample);
|
*sample = sys_le16_to_cpu(*sample);
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_INF("status=0x%x x=%d y=%d z=%d", lis2dh->sample.status,
|
LOG_INF("status=0x%x x=%d y=%d z=%d", lis2dh->sample.status,
|
||||||
lis2dh->sample.xyz[0], lis2dh->sample.xyz[1],
|
lis2dh->sample.xyz[0], lis2dh->sample.xyz[1],
|
||||||
lis2dh->sample.xyz[2]);
|
lis2dh->sample.xyz[2]);
|
||||||
|
|
||||||
|
@ -273,7 +277,7 @@ static int lis2dh_acc_config(struct device *dev, enum sensor_channel chan,
|
||||||
return lis2dh_acc_slope_config(dev, attr, val);
|
return lis2dh_acc_slope_config(dev, attr, val);
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
SYS_LOG_DBG("Accel attribute not supported.");
|
LOG_DBG("Accel attribute not supported.");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,7 +295,7 @@ static int lis2dh_attr_set(struct device *dev, enum sensor_channel chan,
|
||||||
case SENSOR_CHAN_ACCEL_XYZ:
|
case SENSOR_CHAN_ACCEL_XYZ:
|
||||||
return lis2dh_acc_config(dev, chan, attr, val);
|
return lis2dh_acc_config(dev, chan, attr, val);
|
||||||
default:
|
default:
|
||||||
SYS_LOG_WRN("attr_set() not supported on this channel.");
|
LOG_WRN("attr_set() not supported on this channel.");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +333,7 @@ int lis2dh_init(struct device *dev)
|
||||||
status = lis2dh_burst_write(dev, LIS2DH_REG_CTRL1, raw,
|
status = lis2dh_burst_write(dev, LIS2DH_REG_CTRL1, raw,
|
||||||
sizeof(raw));
|
sizeof(raw));
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
SYS_LOG_ERR("Failed to reset ctrl registers.");
|
LOG_ERR("Failed to reset ctrl registers.");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,19 +342,19 @@ int lis2dh_init(struct device *dev)
|
||||||
status = lis2dh_reg_write_byte(dev, LIS2DH_REG_CTRL4,
|
status = lis2dh_reg_write_byte(dev, LIS2DH_REG_CTRL4,
|
||||||
LIS2DH_FS_BITS);
|
LIS2DH_FS_BITS);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
SYS_LOG_ERR("Failed to set full scale ctrl register.");
|
LOG_ERR("Failed to set full scale ctrl register.");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_LIS2DH_TRIGGER
|
#ifdef CONFIG_LIS2DH_TRIGGER
|
||||||
status = lis2dh_init_interrupt(dev);
|
status = lis2dh_init_interrupt(dev);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
SYS_LOG_ERR("Failed to initialize interrupts.");
|
LOG_ERR("Failed to initialize interrupts.");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SYS_LOG_INF("bus=%s fs=%d, odr=0x%x lp_en=0x%x scale=%d",
|
LOG_INF("bus=%s fs=%d, odr=0x%x lp_en=0x%x scale=%d",
|
||||||
LIS2DH_BUS_DEV_NAME, 1 << (LIS2DH_FS_IDX + 1),
|
LIS2DH_BUS_DEV_NAME, 1 << (LIS2DH_FS_IDX + 1),
|
||||||
LIS2DH_ODR_IDX, (u8_t)LIS2DH_LP_EN_BIT, lis2dh->scale);
|
LIS2DH_ODR_IDX, (u8_t)LIS2DH_LP_EN_BIT, lis2dh->scale);
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,9 @@
|
||||||
#include <gpio.h>
|
#include <gpio.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
#if defined(CONFIG_LIS2DH_BUS_SPI)
|
#if defined(CONFIG_LIS2DH_BUS_SPI)
|
||||||
#include <spi.h>
|
#include <spi.h>
|
||||||
|
|
||||||
|
@ -216,15 +218,44 @@ struct lis2dh_data {
|
||||||
#endif /* CONFIG_LIS2DH_TRIGGER */
|
#endif /* CONFIG_LIS2DH_TRIGGER */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "lis2dh"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#if defined(CONFIG_LIS2DH_BUS_SPI)
|
#if defined(CONFIG_LIS2DH_BUS_SPI)
|
||||||
int lis2dh_spi_access(struct lis2dh_data *ctx, u8_t cmd,
|
int lis2dh_spi_access(struct lis2dh_data *ctx, u8_t cmd,
|
||||||
void *data, size_t length);
|
void *data, size_t length);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static inline int lis2dh_bus_configure(struct device *dev)
|
||||||
|
{
|
||||||
|
struct lis2dh_data *lis2dh = dev->driver_data;
|
||||||
|
|
||||||
|
LOG_MODULE_DECLARE(lis2dh);
|
||||||
|
|
||||||
|
#if defined(CONFIG_LIS2DH_BUS_SPI)
|
||||||
|
lis2dh->spi = device_get_binding(LIS2DH_BUS_DEV_NAME);
|
||||||
|
if (lis2dh->spi == NULL) {
|
||||||
|
LOG_ERR("Could not get pointer to %s device",
|
||||||
|
LIS2DH_BUS_DEV_NAME);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
lis2dh->spi_cfg.operation = LIS2DH_SPI_CFG;
|
||||||
|
lis2dh->spi_cfg.frequency = CONFIG_LIS2DH_SPI_FREQUENCY;
|
||||||
|
lis2dh->spi_cfg.slave = LIS2DH_BUS_ADDRESS;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
#elif defined(CONFIG_LIS2DH_BUS_I2C)
|
||||||
|
lis2dh->bus = device_get_binding(LIS2DH_BUS_DEV_NAME);
|
||||||
|
if (lis2dh->bus == NULL) {
|
||||||
|
LOG_ERR("Could not get pointer to %s device",
|
||||||
|
LIS2DH_BUS_DEV_NAME);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
return -ENODEV;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static inline int lis2dh_burst_read(struct device *dev, u8_t start_addr,
|
static inline int lis2dh_burst_read(struct device *dev, u8_t start_addr,
|
||||||
u8_t *buf, u8_t num_bytes)
|
u8_t *buf, u8_t num_bytes)
|
||||||
{
|
{
|
||||||
|
@ -297,37 +328,6 @@ static inline int lis2dh_reg_write_byte(struct device *dev, u8_t reg_addr,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int lis2dh_bus_configure(struct device *dev)
|
|
||||||
{
|
|
||||||
struct lis2dh_data *lis2dh = dev->driver_data;
|
|
||||||
|
|
||||||
#if defined(CONFIG_LIS2DH_BUS_SPI)
|
|
||||||
lis2dh->spi = device_get_binding(LIS2DH_BUS_DEV_NAME);
|
|
||||||
if (lis2dh->spi == NULL) {
|
|
||||||
SYS_LOG_ERR("Could not get pointer to %s device",
|
|
||||||
LIS2DH_BUS_DEV_NAME);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
lis2dh->spi_cfg.operation = LIS2DH_SPI_CFG;
|
|
||||||
lis2dh->spi_cfg.frequency = CONFIG_LIS2DH_SPI_FREQUENCY;
|
|
||||||
lis2dh->spi_cfg.slave = LIS2DH_BUS_ADDRESS;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
#elif defined(CONFIG_LIS2DH_BUS_I2C)
|
|
||||||
lis2dh->bus = device_get_binding(LIS2DH_BUS_DEV_NAME);
|
|
||||||
if (lis2dh->bus == NULL) {
|
|
||||||
SYS_LOG_ERR("Could not get pointer to %s device",
|
|
||||||
LIS2DH_BUS_DEV_NAME);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
#else
|
|
||||||
return -ENODEV;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_LIS2DH_TRIGGER
|
#ifdef CONFIG_LIS2DH_TRIGGER
|
||||||
int lis2dh_trigger_set(struct device *dev,
|
int lis2dh_trigger_set(struct device *dev,
|
||||||
const struct sensor_trigger *trig,
|
const struct sensor_trigger *trig,
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
#define TRIGGED_INT1 BIT(4)
|
#define TRIGGED_INT1 BIT(4)
|
||||||
#define TRIGGED_INT2 BIT(5)
|
#define TRIGGED_INT2 BIT(5)
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(lis2dh);
|
||||||
|
|
||||||
static int lis2dh_trigger_drdy_set(struct device *dev, enum sensor_channel chan,
|
static int lis2dh_trigger_drdy_set(struct device *dev, enum sensor_channel chan,
|
||||||
sensor_trigger_handler_t handler)
|
sensor_trigger_handler_t handler)
|
||||||
{
|
{
|
||||||
|
@ -67,7 +71,7 @@ static int lis2dh_start_trigger_int1(struct device *dev)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_DBG("ctrl1=0x%x @tick=%u", ctrl1, k_cycle_get_32());
|
LOG_DBG("ctrl1=0x%x @tick=%u", ctrl1, k_cycle_get_32());
|
||||||
|
|
||||||
/* empty output data */
|
/* empty output data */
|
||||||
status = lis2dh_burst_read(dev, LIS2DH_REG_STATUS, raw, sizeof(raw));
|
status = lis2dh_burst_read(dev, LIS2DH_REG_STATUS, raw, sizeof(raw));
|
||||||
|
@ -134,7 +138,7 @@ static int lis2dh_start_trigger_int2(struct device *dev)
|
||||||
status = gpio_pin_enable_callback(lis2dh->gpio,
|
status = gpio_pin_enable_callback(lis2dh->gpio,
|
||||||
CONFIG_LIS2DH_INT2_GPIO_PIN);
|
CONFIG_LIS2DH_INT2_GPIO_PIN);
|
||||||
if (unlikely(status < 0)) {
|
if (unlikely(status < 0)) {
|
||||||
SYS_LOG_ERR("enable callback failed err=%d", status);
|
LOG_ERR("enable callback failed err=%d", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
return lis2dh_reg_write_byte(dev, LIS2DH_REG_INT2_CFG,
|
return lis2dh_reg_write_byte(dev, LIS2DH_REG_INT2_CFG,
|
||||||
|
@ -183,7 +187,7 @@ int lis2dh_acc_slope_config(struct device *dev, enum sensor_attribute attr,
|
||||||
/* 7 bit full range value */
|
/* 7 bit full range value */
|
||||||
reg_val = 128 / range_g * (slope_th_ums2 - 1) / SENSOR_G;
|
reg_val = 128 / range_g * (slope_th_ums2 - 1) / SENSOR_G;
|
||||||
|
|
||||||
SYS_LOG_INF("int2_ths=0x%x range_g=%d ums2=%u", reg_val,
|
LOG_INF("int2_ths=0x%x range_g=%d ums2=%u", reg_val,
|
||||||
range_g, slope_th_ums2 - 1);
|
range_g, slope_th_ums2 - 1);
|
||||||
|
|
||||||
status = lis2dh_reg_write_byte(dev, LIS2DH_REG_INT2_THS,
|
status = lis2dh_reg_write_byte(dev, LIS2DH_REG_INT2_THS,
|
||||||
|
@ -197,7 +201,7 @@ int lis2dh_acc_slope_config(struct device *dev, enum sensor_attribute attr,
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_INF("int2_dur=0x%x", val->val1);
|
LOG_INF("int2_dur=0x%x", val->val1);
|
||||||
|
|
||||||
status = lis2dh_reg_write_byte(dev, LIS2DH_REG_INT2_DUR,
|
status = lis2dh_reg_write_byte(dev, LIS2DH_REG_INT2_DUR,
|
||||||
val->val1);
|
val->val1);
|
||||||
|
@ -250,7 +254,7 @@ static void lis2dh_thread_cb(void *arg)
|
||||||
int status = lis2dh_start_trigger_int1(dev);
|
int status = lis2dh_start_trigger_int1(dev);
|
||||||
|
|
||||||
if (unlikely(status < 0)) {
|
if (unlikely(status < 0)) {
|
||||||
SYS_LOG_ERR("lis2dh_start_trigger_int1: %d", status);
|
LOG_ERR("lis2dh_start_trigger_int1: %d", status);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -260,7 +264,7 @@ static void lis2dh_thread_cb(void *arg)
|
||||||
int status = lis2dh_start_trigger_int2(dev);
|
int status = lis2dh_start_trigger_int2(dev);
|
||||||
|
|
||||||
if (unlikely(status < 0)) {
|
if (unlikely(status < 0)) {
|
||||||
SYS_LOG_ERR("lis2dh_start_trigger_int2: %d", status);
|
LOG_ERR("lis2dh_start_trigger_int2: %d", status);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -294,7 +298,7 @@ static void lis2dh_thread_cb(void *arg)
|
||||||
lis2dh->handler_anymotion(dev, &anym_trigger);
|
lis2dh->handler_anymotion(dev, &anym_trigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_DBG("@tick=%u int2_src=0x%x", k_cycle_get_32(),
|
LOG_DBG("@tick=%u int2_src=0x%x", k_cycle_get_32(),
|
||||||
reg_val);
|
reg_val);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -342,7 +346,7 @@ int lis2dh_init_interrupt(struct device *dev)
|
||||||
/* setup data ready gpio interrupt */
|
/* setup data ready gpio interrupt */
|
||||||
lis2dh->gpio = device_get_binding(CONFIG_LIS2DH_GPIO_DEV_NAME);
|
lis2dh->gpio = device_get_binding(CONFIG_LIS2DH_GPIO_DEV_NAME);
|
||||||
if (lis2dh->gpio == NULL) {
|
if (lis2dh->gpio == NULL) {
|
||||||
SYS_LOG_ERR("Cannot get pointer to %s device",
|
LOG_ERR("Cannot get pointer to %s device",
|
||||||
CONFIG_LIS2DH_GPIO_DEV_NAME);
|
CONFIG_LIS2DH_GPIO_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -351,7 +355,7 @@ int lis2dh_init_interrupt(struct device *dev)
|
||||||
status = gpio_pin_configure(lis2dh->gpio, CONFIG_LIS2DH_INT1_GPIO_PIN,
|
status = gpio_pin_configure(lis2dh->gpio, CONFIG_LIS2DH_INT1_GPIO_PIN,
|
||||||
LIS2DH_INT1_CFG);
|
LIS2DH_INT1_CFG);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
SYS_LOG_ERR("Could not configure gpio %d",
|
LOG_ERR("Could not configure gpio %d",
|
||||||
CONFIG_LIS2DH_INT1_GPIO_PIN);
|
CONFIG_LIS2DH_INT1_GPIO_PIN);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -362,7 +366,7 @@ int lis2dh_init_interrupt(struct device *dev)
|
||||||
|
|
||||||
status = gpio_add_callback(lis2dh->gpio, &lis2dh->gpio_int1_cb);
|
status = gpio_add_callback(lis2dh->gpio, &lis2dh->gpio_int1_cb);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
SYS_LOG_ERR("Could not add gpio int1 callback");
|
LOG_ERR("Could not add gpio int1 callback");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,7 +374,7 @@ int lis2dh_init_interrupt(struct device *dev)
|
||||||
status = gpio_pin_configure(lis2dh->gpio, CONFIG_LIS2DH_INT2_GPIO_PIN,
|
status = gpio_pin_configure(lis2dh->gpio, CONFIG_LIS2DH_INT2_GPIO_PIN,
|
||||||
LIS2DH_INT2_CFG);
|
LIS2DH_INT2_CFG);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
SYS_LOG_ERR("Could not configure gpio %d",
|
LOG_ERR("Could not configure gpio %d",
|
||||||
CONFIG_LIS2DH_INT2_GPIO_PIN);
|
CONFIG_LIS2DH_INT2_GPIO_PIN);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -382,7 +386,7 @@ int lis2dh_init_interrupt(struct device *dev)
|
||||||
/* callback is going to be enabled by trigger setting function */
|
/* callback is going to be enabled by trigger setting function */
|
||||||
status = gpio_add_callback(lis2dh->gpio, &lis2dh->gpio_int2_cb);
|
status = gpio_add_callback(lis2dh->gpio, &lis2dh->gpio_int2_cb);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
SYS_LOG_ERR("Could not add gpio int2 callback (%d)", status);
|
LOG_ERR("Could not add gpio int2 callback (%d)", status);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,7 +404,7 @@ int lis2dh_init_interrupt(struct device *dev)
|
||||||
/* disable interrupt 2 in case of warm (re)boot */
|
/* disable interrupt 2 in case of warm (re)boot */
|
||||||
status = lis2dh_reg_write_byte(dev, LIS2DH_REG_INT2_CFG, 0);
|
status = lis2dh_reg_write_byte(dev, LIS2DH_REG_INT2_CFG, 0);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
SYS_LOG_ERR("Interrupt 2 disable reg write failed (%d)",
|
LOG_ERR("Interrupt 2 disable reg write failed (%d)",
|
||||||
status);
|
status);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -408,7 +412,7 @@ int lis2dh_init_interrupt(struct device *dev)
|
||||||
(void)memset(raw, 0, sizeof(raw));
|
(void)memset(raw, 0, sizeof(raw));
|
||||||
status = lis2dh_burst_write(dev, LIS2DH_REG_INT2_THS, raw, sizeof(raw));
|
status = lis2dh_burst_write(dev, LIS2DH_REG_INT2_THS, raw, sizeof(raw));
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
SYS_LOG_ERR("Burst write to INT2 THS failed (%d)", status);
|
LOG_ERR("Burst write to INT2 THS failed (%d)", status);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,11 +420,11 @@ int lis2dh_init_interrupt(struct device *dev)
|
||||||
status = lis2dh_reg_write_byte(dev, LIS2DH_REG_CTRL5,
|
status = lis2dh_reg_write_byte(dev, LIS2DH_REG_CTRL5,
|
||||||
LIS2DH_EN_LIR_INT2);
|
LIS2DH_EN_LIR_INT2);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
SYS_LOG_ERR("INT2 latch enable reg write failed (%d)", status);
|
LOG_ERR("INT2 latch enable reg write failed (%d)", status);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_INF("int1 on pin=%d cfg=0x%x, int2 on pin=%d cfg=0x%x",
|
LOG_INF("int1 on pin=%d cfg=0x%x, int2 on pin=%d cfg=0x%x",
|
||||||
CONFIG_LIS2DH_INT1_GPIO_PIN, LIS2DH_INT1_CFG,
|
CONFIG_LIS2DH_INT1_GPIO_PIN, LIS2DH_INT1_CFG,
|
||||||
CONFIG_LIS2DH_INT2_GPIO_PIN, LIS2DH_INT2_CFG);
|
CONFIG_LIS2DH_INT2_GPIO_PIN, LIS2DH_INT2_CFG);
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,10 @@
|
||||||
|
|
||||||
struct lis2mdl_data lis2mdl_device_data;
|
struct lis2mdl_data lis2mdl_device_data;
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_REGISTER(LIS2MDL);
|
||||||
|
|
||||||
#ifdef CONFIG_LIS2MDL_MAG_ODR_RUNTIME
|
#ifdef CONFIG_LIS2MDL_MAG_ODR_RUNTIME
|
||||||
static const struct {
|
static const struct {
|
||||||
u16_t odr;
|
u16_t odr;
|
||||||
|
@ -161,7 +165,7 @@ static int lis2mdl_channel_get(struct device *dev, enum sensor_channel chan,
|
||||||
lis2mdl_channel_get_temp(dev, val);
|
lis2mdl_channel_get_temp(dev, val);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SYS_LOG_DBG("Channel not supported");
|
LOG_DBG("Channel not supported");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +184,7 @@ static int lis2mdl_config(struct device *dev, enum sensor_channel chan,
|
||||||
case SENSOR_ATTR_OFFSET:
|
case SENSOR_ATTR_OFFSET:
|
||||||
return lis2mdl_set_hard_iron(dev, chan, val);
|
return lis2mdl_set_hard_iron(dev, chan, val);
|
||||||
default:
|
default:
|
||||||
SYS_LOG_DBG("Mag attribute not supported");
|
LOG_DBG("Mag attribute not supported");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +203,7 @@ static int lis2mdl_attr_set(struct device *dev,
|
||||||
case SENSOR_CHAN_MAGN_XYZ:
|
case SENSOR_CHAN_MAGN_XYZ:
|
||||||
return lis2mdl_config(dev, chan, attr, val);
|
return lis2mdl_config(dev, chan, attr, val);
|
||||||
default:
|
default:
|
||||||
SYS_LOG_DBG("attr_set() not supported on %d channel", chan);
|
LOG_DBG("attr_set() not supported on %d channel", chan);
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,7 +225,7 @@ static int lis2mdl_sample_fetch_mag(struct device *dev)
|
||||||
if (i2c_burst_read(lis2mdl->i2c, lis2mdl->i2c_addr,
|
if (i2c_burst_read(lis2mdl->i2c, lis2mdl->i2c_addr,
|
||||||
LIS2MDL_OUT_REG, buf.raw,
|
LIS2MDL_OUT_REG, buf.raw,
|
||||||
sizeof(buf)) < 0) {
|
sizeof(buf)) < 0) {
|
||||||
SYS_LOG_DBG("Failed to fetch raw mag sample");
|
LOG_DBG("Failed to fetch raw mag sample");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +248,7 @@ static int lis2mdl_sample_fetch_temp(struct device *dev)
|
||||||
LIS2MDL_TEMP_OUT_L_REG,
|
LIS2MDL_TEMP_OUT_L_REG,
|
||||||
(u8_t *)&temp_raw, sizeof(temp_raw));
|
(u8_t *)&temp_raw, sizeof(temp_raw));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
SYS_LOG_DBG("Failed to fetch raw temp sample");
|
LOG_DBG("Failed to fetch raw temp sample");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,7 +299,7 @@ static int lis2mdl_init_interface(struct device *dev)
|
||||||
|
|
||||||
lis2mdl->i2c = device_get_binding(config->master_dev_name);
|
lis2mdl->i2c = device_get_binding(config->master_dev_name);
|
||||||
if (!lis2mdl->i2c) {
|
if (!lis2mdl->i2c) {
|
||||||
SYS_LOG_DBG("Could not get pointer to %s device",
|
LOG_DBG("Could not get pointer to %s device",
|
||||||
config->master_dev_name);
|
config->master_dev_name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -326,12 +330,12 @@ static int lis2mdl_init(struct device *dev)
|
||||||
/* check chip ID */
|
/* check chip ID */
|
||||||
if (i2c_reg_read_byte(lis2mdl->i2c, lis2mdl->i2c_addr,
|
if (i2c_reg_read_byte(lis2mdl->i2c, lis2mdl->i2c_addr,
|
||||||
LIS2MDL_WHO_AM_I_REG, &wai) < 0) {
|
LIS2MDL_WHO_AM_I_REG, &wai) < 0) {
|
||||||
SYS_LOG_DBG("Failed to read chip ID");
|
LOG_DBG("Failed to read chip ID");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wai != LIS2MDL_WHOAMI_VAL) {
|
if (wai != LIS2MDL_WHOAMI_VAL) {
|
||||||
SYS_LOG_DBG("Invalid chip ID");
|
LOG_DBG("Invalid chip ID");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,7 +366,7 @@ static int lis2mdl_init(struct device *dev)
|
||||||
|
|
||||||
#ifdef CONFIG_LIS2MDL_TRIGGER
|
#ifdef CONFIG_LIS2MDL_TRIGGER
|
||||||
if (lis2mdl_init_interrupt(dev) < 0) {
|
if (lis2mdl_init_interrupt(dev) < 0) {
|
||||||
SYS_LOG_DBG("Failed to initialize interrupts");
|
LOG_DBG("Failed to initialize interrupts");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,10 +13,6 @@
|
||||||
#include <misc/util.h>
|
#include <misc/util.h>
|
||||||
#include <i2c.h>
|
#include <i2c.h>
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "LIS2MDL"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#define LIS2MDL_EN_BIT 1
|
#define LIS2MDL_EN_BIT 1
|
||||||
#define LIS2MDL_DIS_BIT 0
|
#define LIS2MDL_DIS_BIT 0
|
||||||
#define LIS2MDL_I2C_ADDR(__x) (__x << 1)
|
#define LIS2MDL_I2C_ADDR(__x) (__x << 1)
|
||||||
|
|
|
@ -12,6 +12,10 @@
|
||||||
|
|
||||||
#include "lis2mdl.h"
|
#include "lis2mdl.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(LIS2MDL);
|
||||||
|
|
||||||
static int lis2mdl_enable_int(struct device *dev, int enable)
|
static int lis2mdl_enable_int(struct device *dev, int enable)
|
||||||
{
|
{
|
||||||
struct lis2mdl_data *lis2mdl = dev->driver_data;
|
struct lis2mdl_data *lis2mdl = dev->driver_data;
|
||||||
|
@ -118,7 +122,7 @@ int lis2mdl_init_interrupt(struct device *dev)
|
||||||
/* setup data ready gpio interrupt */
|
/* setup data ready gpio interrupt */
|
||||||
lis2mdl->gpio = device_get_binding(config->gpio_name);
|
lis2mdl->gpio = device_get_binding(config->gpio_name);
|
||||||
if (lis2mdl->gpio == NULL) {
|
if (lis2mdl->gpio == NULL) {
|
||||||
SYS_LOG_DBG("Cannot get pointer to %s device",
|
LOG_DBG("Cannot get pointer to %s device",
|
||||||
config->gpio_name);
|
config->gpio_name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +136,7 @@ int lis2mdl_init_interrupt(struct device *dev)
|
||||||
BIT(config->gpio_pin));
|
BIT(config->gpio_pin));
|
||||||
|
|
||||||
if (gpio_add_callback(lis2mdl->gpio, &lis2mdl->gpio_cb) < 0) {
|
if (gpio_add_callback(lis2mdl->gpio, &lis2mdl->gpio_cb) < 0) {
|
||||||
SYS_LOG_DBG("Could not set gpio callback");
|
LOG_DBG("Could not set gpio callback");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,13 @@
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "lis3dh.h"
|
#include "lis3dh.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(LIS3DH);
|
||||||
|
|
||||||
static void lis3dh_convert(struct sensor_value *val, s64_t raw_val)
|
static void lis3dh_convert(struct sensor_value *val, s64_t raw_val)
|
||||||
{
|
{
|
||||||
/* val = raw_val * LIS3DH_ACCEL_SCALE / (10^6 * (2^16 - 1)) */
|
/* val = raw_val * LIS3DH_ACCEL_SCALE / (10^6 * (2^16 - 1)) */
|
||||||
|
@ -63,7 +67,7 @@ int lis3dh_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
if (i2c_burst_read(drv_data->i2c, LIS3DH_I2C_ADDRESS,
|
if (i2c_burst_read(drv_data->i2c, LIS3DH_I2C_ADDRESS,
|
||||||
(LIS3DH_REG_ACCEL_X_LSB | LIS3DH_AUTOINCREMENT_ADDR),
|
(LIS3DH_REG_ACCEL_X_LSB | LIS3DH_AUTOINCREMENT_ADDR),
|
||||||
buf, 6) < 0) {
|
buf, 6) < 0) {
|
||||||
SYS_LOG_DBG("Could not read accel axis data");
|
LOG_DBG("Could not read accel axis data");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +92,7 @@ int lis3dh_init(struct device *dev)
|
||||||
|
|
||||||
drv_data->i2c = device_get_binding(CONFIG_LIS3DH_I2C_MASTER_DEV_NAME);
|
drv_data->i2c = device_get_binding(CONFIG_LIS3DH_I2C_MASTER_DEV_NAME);
|
||||||
if (drv_data->i2c == NULL) {
|
if (drv_data->i2c == NULL) {
|
||||||
SYS_LOG_DBG("Could not get pointer to %s device",
|
LOG_DBG("Could not get pointer to %s device",
|
||||||
CONFIG_LIS3DH_I2C_MASTER_DEV_NAME);
|
CONFIG_LIS3DH_I2C_MASTER_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -97,19 +101,19 @@ int lis3dh_init(struct device *dev)
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, LIS3DH_I2C_ADDRESS,
|
if (i2c_reg_write_byte(drv_data->i2c, LIS3DH_I2C_ADDRESS,
|
||||||
LIS3DH_REG_CTRL1, LIS3DH_ACCEL_EN_BITS |
|
LIS3DH_REG_CTRL1, LIS3DH_ACCEL_EN_BITS |
|
||||||
LIS3DH_LP_EN_BIT | LIS3DH_ODR_BITS) < 0) {
|
LIS3DH_LP_EN_BIT | LIS3DH_ODR_BITS) < 0) {
|
||||||
SYS_LOG_DBG("Failed to configure chip.");
|
LOG_DBG("Failed to configure chip.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set full scale range */
|
/* set full scale range */
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, LIS3DH_I2C_ADDRESS,
|
if (i2c_reg_write_byte(drv_data->i2c, LIS3DH_I2C_ADDRESS,
|
||||||
LIS3DH_REG_CTRL4, LIS3DH_FS_BITS) < 0) {
|
LIS3DH_REG_CTRL4, LIS3DH_FS_BITS) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set full scale range.");
|
LOG_DBG("Failed to set full scale range.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_LIS3DH_TRIGGER
|
#ifdef CONFIG_LIS3DH_TRIGGER
|
||||||
if (lis3dh_init_interrupt(dev) < 0) {
|
if (lis3dh_init_interrupt(dev) < 0) {
|
||||||
SYS_LOG_DBG("Failed to initialize interrupts.");
|
LOG_DBG("Failed to initialize interrupts.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -114,7 +114,4 @@ int lis3dh_sample_fetch(struct device *dev, enum sensor_channel chan);
|
||||||
int lis3dh_init_interrupt(struct device *dev);
|
int lis3dh_init_interrupt(struct device *dev);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "LIS3DH"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* __SENSOR_LIS3DH__ */
|
#endif /* __SENSOR_LIS3DH__ */
|
||||||
|
|
|
@ -9,9 +9,14 @@
|
||||||
#include <misc/util.h>
|
#include <misc/util.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "lis3dh.h"
|
#include "lis3dh.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(LIS3DH);
|
||||||
|
|
||||||
int lis3dh_trigger_set(struct device *dev,
|
int lis3dh_trigger_set(struct device *dev,
|
||||||
const struct sensor_trigger *trig,
|
const struct sensor_trigger *trig,
|
||||||
sensor_trigger_handler_t handler)
|
sensor_trigger_handler_t handler)
|
||||||
|
@ -97,7 +102,7 @@ int lis3dh_init_interrupt(struct device *dev)
|
||||||
/* setup data ready gpio interrupt */
|
/* setup data ready gpio interrupt */
|
||||||
drv_data->gpio = device_get_binding(CONFIG_LIS3DH_GPIO_DEV_NAME);
|
drv_data->gpio = device_get_binding(CONFIG_LIS3DH_GPIO_DEV_NAME);
|
||||||
if (drv_data->gpio == NULL) {
|
if (drv_data->gpio == NULL) {
|
||||||
SYS_LOG_DBG("Cannot get pointer to %s device",
|
LOG_DBG("Cannot get pointer to %s device",
|
||||||
CONFIG_LIS3DH_GPIO_DEV_NAME);
|
CONFIG_LIS3DH_GPIO_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -111,20 +116,20 @@ int lis3dh_init_interrupt(struct device *dev)
|
||||||
BIT(CONFIG_LIS3DH_GPIO_PIN_NUM));
|
BIT(CONFIG_LIS3DH_GPIO_PIN_NUM));
|
||||||
|
|
||||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||||
SYS_LOG_DBG("Could not set gpio callback");
|
LOG_DBG("Could not set gpio callback");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clear data ready interrupt line by reading sample data */
|
/* clear data ready interrupt line by reading sample data */
|
||||||
if (lis3dh_sample_fetch(dev, SENSOR_CHAN_ALL) < 0) {
|
if (lis3dh_sample_fetch(dev, SENSOR_CHAN_ALL) < 0) {
|
||||||
SYS_LOG_DBG("Could not clear data ready interrupt line.");
|
LOG_DBG("Could not clear data ready interrupt line.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* enable data ready interrupt on INT1 line */
|
/* enable data ready interrupt on INT1 line */
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, LIS3DH_I2C_ADDRESS,
|
if (i2c_reg_write_byte(drv_data->i2c, LIS3DH_I2C_ADDRESS,
|
||||||
LIS3DH_REG_CTRL3, LIS3DH_EN_DRDY1_INT1) < 0) {
|
LIS3DH_REG_CTRL3, LIS3DH_EN_DRDY1_INT1) < 0) {
|
||||||
SYS_LOG_DBG("Failed to enable data ready interrupt.");
|
LOG_DBG("Failed to enable data ready interrupt.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,13 @@
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "lis3mdl.h"
|
#include "lis3mdl.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(LIS3MDL);
|
||||||
|
|
||||||
static void lis3mdl_convert(struct sensor_value *val, s16_t raw_val,
|
static void lis3mdl_convert(struct sensor_value *val, s16_t raw_val,
|
||||||
u16_t divider)
|
u16_t divider)
|
||||||
{
|
{
|
||||||
|
@ -63,7 +67,7 @@ int lis3mdl_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
/* fetch magnetometer sample */
|
/* fetch magnetometer sample */
|
||||||
if (i2c_burst_read(drv_data->i2c, CONFIG_LIS3MDL_I2C_ADDR,
|
if (i2c_burst_read(drv_data->i2c, CONFIG_LIS3MDL_I2C_ADDR,
|
||||||
LIS3MDL_REG_SAMPLE_START, (u8_t *)buf, 8) < 0) {
|
LIS3MDL_REG_SAMPLE_START, (u8_t *)buf, 8) < 0) {
|
||||||
SYS_LOG_DBG("Failed to fetch megnetometer sample.");
|
LOG_DBG("Failed to fetch megnetometer sample.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +79,7 @@ int lis3mdl_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
if (i2c_burst_read(drv_data->i2c, CONFIG_LIS3MDL_I2C_ADDR,
|
if (i2c_burst_read(drv_data->i2c, CONFIG_LIS3MDL_I2C_ADDR,
|
||||||
LIS3MDL_REG_SAMPLE_START + 6,
|
LIS3MDL_REG_SAMPLE_START + 6,
|
||||||
(u8_t *)(buf + 3), 2) < 0) {
|
(u8_t *)(buf + 3), 2) < 0) {
|
||||||
SYS_LOG_DBG("Failed to fetch temperature sample.");
|
LOG_DBG("Failed to fetch temperature sample.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -104,7 +108,7 @@ int lis3mdl_init(struct device *dev)
|
||||||
drv_data->i2c = device_get_binding(CONFIG_LIS3MDL_I2C_MASTER_DEV_NAME);
|
drv_data->i2c = device_get_binding(CONFIG_LIS3MDL_I2C_MASTER_DEV_NAME);
|
||||||
|
|
||||||
if (drv_data->i2c == NULL) {
|
if (drv_data->i2c == NULL) {
|
||||||
SYS_LOG_ERR("Could not get pointer to %s device.",
|
LOG_ERR("Could not get pointer to %s device.",
|
||||||
CONFIG_LIS3MDL_I2C_MASTER_DEV_NAME);
|
CONFIG_LIS3MDL_I2C_MASTER_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -112,12 +116,12 @@ int lis3mdl_init(struct device *dev)
|
||||||
/* check chip ID */
|
/* check chip ID */
|
||||||
if (i2c_reg_read_byte(drv_data->i2c, CONFIG_LIS3MDL_I2C_ADDR,
|
if (i2c_reg_read_byte(drv_data->i2c, CONFIG_LIS3MDL_I2C_ADDR,
|
||||||
LIS3MDL_REG_WHO_AM_I, &id) < 0) {
|
LIS3MDL_REG_WHO_AM_I, &id) < 0) {
|
||||||
SYS_LOG_ERR("Failed to read chip ID.");
|
LOG_ERR("Failed to read chip ID.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id != LIS3MDL_CHIP_ID) {
|
if (id != LIS3MDL_CHIP_ID) {
|
||||||
SYS_LOG_ERR("Invalid chip ID.");
|
LOG_ERR("Invalid chip ID.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +133,7 @@ int lis3mdl_init(struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idx == ARRAY_SIZE(lis3mdl_odr_strings)) {
|
if (idx == ARRAY_SIZE(lis3mdl_odr_strings)) {
|
||||||
SYS_LOG_ERR("Invalid ODR value.");
|
LOG_ERR("Invalid ODR value.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,13 +149,13 @@ int lis3mdl_init(struct device *dev)
|
||||||
|
|
||||||
if (i2c_write(drv_data->i2c,
|
if (i2c_write(drv_data->i2c,
|
||||||
chip_cfg, 6, CONFIG_LIS3MDL_I2C_ADDR) < 0) {
|
chip_cfg, 6, CONFIG_LIS3MDL_I2C_ADDR) < 0) {
|
||||||
SYS_LOG_DBG("Failed to configure chip.");
|
LOG_DBG("Failed to configure chip.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_LIS3MDL_TRIGGER
|
#ifdef CONFIG_LIS3MDL_TRIGGER
|
||||||
if (lis3mdl_init_interrupt(dev) < 0) {
|
if (lis3mdl_init_interrupt(dev) < 0) {
|
||||||
SYS_LOG_DBG("Failed to initialize interrupts.");
|
LOG_DBG("Failed to initialize interrupts.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,10 +12,6 @@
|
||||||
#include <zephyr/types.h>
|
#include <zephyr/types.h>
|
||||||
#include <gpio.h>
|
#include <gpio.h>
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "LIS3MDL"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#define LIS3MDL_I2C_ADDR_BASE 0x1C
|
#define LIS3MDL_I2C_ADDR_BASE 0x1C
|
||||||
#define LIS3MDL_I2C_ADDR_MASK (~BIT(1))
|
#define LIS3MDL_I2C_ADDR_MASK (~BIT(1))
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
|
|
||||||
#include "lis3mdl.h"
|
#include "lis3mdl.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(LIS3MDL);
|
||||||
|
|
||||||
int lis3mdl_trigger_set(struct device *dev,
|
int lis3mdl_trigger_set(struct device *dev,
|
||||||
const struct sensor_trigger *trig,
|
const struct sensor_trigger *trig,
|
||||||
sensor_trigger_handler_t handler)
|
sensor_trigger_handler_t handler)
|
||||||
|
@ -97,7 +101,7 @@ int lis3mdl_init_interrupt(struct device *dev)
|
||||||
/* setup data ready gpio interrupt */
|
/* setup data ready gpio interrupt */
|
||||||
drv_data->gpio = device_get_binding(CONFIG_LIS3MDL_GPIO_DEV_NAME);
|
drv_data->gpio = device_get_binding(CONFIG_LIS3MDL_GPIO_DEV_NAME);
|
||||||
if (drv_data->gpio == NULL) {
|
if (drv_data->gpio == NULL) {
|
||||||
SYS_LOG_DBG("Cannot get pointer to %s device.",
|
LOG_DBG("Cannot get pointer to %s device.",
|
||||||
CONFIG_LIS3MDL_GPIO_DEV_NAME);
|
CONFIG_LIS3MDL_GPIO_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -111,20 +115,20 @@ int lis3mdl_init_interrupt(struct device *dev)
|
||||||
BIT(CONFIG_LIS3MDL_GPIO_PIN_NUM));
|
BIT(CONFIG_LIS3MDL_GPIO_PIN_NUM));
|
||||||
|
|
||||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||||
SYS_LOG_DBG("Could not set gpio callback.");
|
LOG_DBG("Could not set gpio callback.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clear data ready interrupt line by reading sample data */
|
/* clear data ready interrupt line by reading sample data */
|
||||||
if (lis3mdl_sample_fetch(dev, SENSOR_CHAN_ALL) < 0) {
|
if (lis3mdl_sample_fetch(dev, SENSOR_CHAN_ALL) < 0) {
|
||||||
SYS_LOG_DBG("Could not clear data ready interrupt line.");
|
LOG_DBG("Could not clear data ready interrupt line.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* enable interrupt */
|
/* enable interrupt */
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, CONFIG_LIS3MDL_I2C_ADDR,
|
if (i2c_reg_write_byte(drv_data->i2c, CONFIG_LIS3MDL_I2C_ADDR,
|
||||||
LIS3MDL_REG_INT_CFG, LIS3MDL_INT_XYZ_EN) < 0) {
|
LIS3MDL_REG_INT_CFG, LIS3MDL_INT_XYZ_EN) < 0) {
|
||||||
SYS_LOG_DBG("Could not enable interrupt.");
|
LOG_DBG("Could not enable interrupt.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,13 @@
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "lps22hb.h"
|
#include "lps22hb.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(LPS22HB);
|
||||||
|
|
||||||
static inline int lps22hb_set_odr_raw(struct device *dev, u8_t odr)
|
static inline int lps22hb_set_odr_raw(struct device *dev, u8_t odr)
|
||||||
{
|
{
|
||||||
struct lps22hb_data *data = dev->driver_data;
|
struct lps22hb_data *data = dev->driver_data;
|
||||||
|
@ -37,7 +41,7 @@ static int lps22hb_sample_fetch(struct device *dev,
|
||||||
|
|
||||||
if (i2c_burst_read(data->i2c_master, config->i2c_slave_addr,
|
if (i2c_burst_read(data->i2c_master, config->i2c_slave_addr,
|
||||||
LPS22HB_REG_PRESS_OUT_XL, out, 5) < 0) {
|
LPS22HB_REG_PRESS_OUT_XL, out, 5) < 0) {
|
||||||
SYS_LOG_DBG("Failed to read sample");
|
LOG_DBG("Failed to read sample");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,17 +102,17 @@ static int lps22hb_init_chip(struct device *dev)
|
||||||
|
|
||||||
if (i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
if (i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
LPS22HB_REG_WHO_AM_I, &chip_id) < 0) {
|
LPS22HB_REG_WHO_AM_I, &chip_id) < 0) {
|
||||||
SYS_LOG_DBG("Failed reading chip id");
|
LOG_DBG("Failed reading chip id");
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chip_id != LPS22HB_VAL_WHO_AM_I) {
|
if (chip_id != LPS22HB_VAL_WHO_AM_I) {
|
||||||
SYS_LOG_DBG("Invalid chip id 0x%x", chip_id);
|
LOG_DBG("Invalid chip id 0x%x", chip_id);
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lps22hb_set_odr_raw(dev, LPS22HB_DEFAULT_SAMPLING_RATE) < 0) {
|
if (lps22hb_set_odr_raw(dev, LPS22HB_DEFAULT_SAMPLING_RATE) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set sampling rate");
|
LOG_DBG("Failed to set sampling rate");
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +120,7 @@ static int lps22hb_init_chip(struct device *dev)
|
||||||
LPS22HB_REG_CTRL_REG1,
|
LPS22HB_REG_CTRL_REG1,
|
||||||
LPS22HB_MASK_CTRL_REG1_BDU,
|
LPS22HB_MASK_CTRL_REG1_BDU,
|
||||||
(1 << LPS22HB_SHIFT_CTRL_REG1_BDU)) < 0) {
|
(1 << LPS22HB_SHIFT_CTRL_REG1_BDU)) < 0) {
|
||||||
SYS_LOG_DBG("Failed to set BDU");
|
LOG_DBG("Failed to set BDU");
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,13 +138,13 @@ static int lps22hb_init(struct device *dev)
|
||||||
data->i2c_master = device_get_binding(config->i2c_master_dev_name);
|
data->i2c_master = device_get_binding(config->i2c_master_dev_name);
|
||||||
|
|
||||||
if (!data->i2c_master) {
|
if (!data->i2c_master) {
|
||||||
SYS_LOG_DBG("I2c master not found: %s",
|
LOG_DBG("I2c master not found: %s",
|
||||||
config->i2c_master_dev_name);
|
config->i2c_master_dev_name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lps22hb_init_chip(dev) < 0) {
|
if (lps22hb_init_chip(dev) < 0) {
|
||||||
SYS_LOG_DBG("Failed to initialize chip");
|
LOG_DBG("Failed to initialize chip");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,4 @@ struct lps22hb_data {
|
||||||
s16_t sample_temp;
|
s16_t sample_temp;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "LPS22HB"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_LPS22HB_LPS22HB_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_LPS22HB_LPS22HB_H_ */
|
||||||
|
|
|
@ -12,9 +12,13 @@
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "lps25hb.h"
|
#include "lps25hb.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(LPS25HB);
|
||||||
|
|
||||||
static inline int lps25hb_power_ctrl(struct device *dev, u8_t value)
|
static inline int lps25hb_power_ctrl(struct device *dev, u8_t value)
|
||||||
{
|
{
|
||||||
struct lps25hb_data *data = dev->driver_data;
|
struct lps25hb_data *data = dev->driver_data;
|
||||||
|
@ -51,7 +55,7 @@ static int lps25hb_sample_fetch(struct device *dev,
|
||||||
if (i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
if (i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
LPS25HB_REG_PRESS_OUT_XL + offset,
|
LPS25HB_REG_PRESS_OUT_XL + offset,
|
||||||
out + offset) < 0) {
|
out + offset) < 0) {
|
||||||
SYS_LOG_DBG("failed to read sample");
|
LOG_DBG("failed to read sample");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,7 +120,7 @@ static int lps25hb_init_chip(struct device *dev)
|
||||||
k_busy_wait(50 * USEC_PER_MSEC);
|
k_busy_wait(50 * USEC_PER_MSEC);
|
||||||
|
|
||||||
if (lps25hb_power_ctrl(dev, 1) < 0) {
|
if (lps25hb_power_ctrl(dev, 1) < 0) {
|
||||||
SYS_LOG_DBG("failed to power on device");
|
LOG_DBG("failed to power on device");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,19 +128,19 @@ static int lps25hb_init_chip(struct device *dev)
|
||||||
|
|
||||||
if (i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
if (i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
LPS25HB_REG_WHO_AM_I, &chip_id) < 0) {
|
LPS25HB_REG_WHO_AM_I, &chip_id) < 0) {
|
||||||
SYS_LOG_DBG("failed reading chip id");
|
LOG_DBG("failed reading chip id");
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
if (chip_id != LPS25HB_VAL_WHO_AM_I) {
|
if (chip_id != LPS25HB_VAL_WHO_AM_I) {
|
||||||
SYS_LOG_DBG("invalid chip id 0x%x", chip_id);
|
LOG_DBG("invalid chip id 0x%x", chip_id);
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_DBG("chip id 0x%x", chip_id);
|
LOG_DBG("chip id 0x%x", chip_id);
|
||||||
|
|
||||||
if (lps25hb_set_odr_raw(dev, LPS25HB_DEFAULT_SAMPLING_RATE)
|
if (lps25hb_set_odr_raw(dev, LPS25HB_DEFAULT_SAMPLING_RATE)
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_DBG("failed to set sampling rate");
|
LOG_DBG("failed to set sampling rate");
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +148,7 @@ static int lps25hb_init_chip(struct device *dev)
|
||||||
LPS25HB_REG_CTRL_REG1,
|
LPS25HB_REG_CTRL_REG1,
|
||||||
LPS25HB_MASK_CTRL_REG1_BDU,
|
LPS25HB_MASK_CTRL_REG1_BDU,
|
||||||
(1 << LPS25HB_SHIFT_CTRL_REG1_BDU)) < 0) {
|
(1 << LPS25HB_SHIFT_CTRL_REG1_BDU)) < 0) {
|
||||||
SYS_LOG_DBG("failed to set BDU");
|
LOG_DBG("failed to set BDU");
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,13 +166,13 @@ static int lps25hb_init(struct device *dev)
|
||||||
|
|
||||||
data->i2c_master = device_get_binding(config->i2c_master_dev_name);
|
data->i2c_master = device_get_binding(config->i2c_master_dev_name);
|
||||||
if (!data->i2c_master) {
|
if (!data->i2c_master) {
|
||||||
SYS_LOG_DBG("i2c master not found: %s",
|
LOG_DBG("i2c master not found: %s",
|
||||||
config->i2c_master_dev_name);
|
config->i2c_master_dev_name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lps25hb_init_chip(dev) < 0) {
|
if (lps25hb_init_chip(dev) < 0) {
|
||||||
SYS_LOG_DBG("failed to initialize chip");
|
LOG_DBG("failed to initialize chip");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,4 @@ struct lps25hb_data {
|
||||||
s16_t sample_temp;
|
s16_t sample_temp;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "LPS25HB"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_LPS25HB_LPS25HB_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_LPS25HB_LPS25HB_H_ */
|
||||||
|
|
|
@ -14,9 +14,13 @@
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "lsm6ds0.h"
|
#include "lsm6ds0.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(LSM6DS0);
|
||||||
|
|
||||||
static inline int lsm6ds0_reboot(struct device *dev)
|
static inline int lsm6ds0_reboot(struct device *dev)
|
||||||
{
|
{
|
||||||
struct lsm6ds0_data *data = dev->driver_data;
|
struct lsm6ds0_data *data = dev->driver_data;
|
||||||
|
@ -136,7 +140,7 @@ static int lsm6ds0_sample_fetch_accel(struct device *dev)
|
||||||
|
|
||||||
if (i2c_burst_read(data->i2c_master, config->i2c_slave_addr,
|
if (i2c_burst_read(data->i2c_master, config->i2c_slave_addr,
|
||||||
LSM6DS0_REG_OUT_X_L_XL, buf, sizeof(buf)) < 0) {
|
LSM6DS0_REG_OUT_X_L_XL, buf, sizeof(buf)) < 0) {
|
||||||
SYS_LOG_DBG("failed to read sample");
|
LOG_DBG("failed to read sample");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +168,7 @@ static int lsm6ds0_sample_fetch_gyro(struct device *dev)
|
||||||
|
|
||||||
if (i2c_burst_read(data->i2c_master, config->i2c_slave_addr,
|
if (i2c_burst_read(data->i2c_master, config->i2c_slave_addr,
|
||||||
LSM6DS0_REG_OUT_X_L_G, buf, sizeof(buf)) < 0) {
|
LSM6DS0_REG_OUT_X_L_G, buf, sizeof(buf)) < 0) {
|
||||||
SYS_LOG_DBG("failed to read sample");
|
LOG_DBG("failed to read sample");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +197,7 @@ static int lsm6ds0_sample_fetch_temp(struct device *dev)
|
||||||
|
|
||||||
if (i2c_burst_read(data->i2c_master, config->i2c_slave_addr,
|
if (i2c_burst_read(data->i2c_master, config->i2c_slave_addr,
|
||||||
LSM6DS0_REG_OUT_TEMP_L, buf, sizeof(buf)) < 0) {
|
LSM6DS0_REG_OUT_TEMP_L, buf, sizeof(buf)) < 0) {
|
||||||
SYS_LOG_DBG("failed to read sample");
|
LOG_DBG("failed to read sample");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,56 +410,56 @@ static int lsm6ds0_init_chip(struct device *dev)
|
||||||
u8_t chip_id;
|
u8_t chip_id;
|
||||||
|
|
||||||
if (lsm6ds0_reboot(dev) < 0) {
|
if (lsm6ds0_reboot(dev) < 0) {
|
||||||
SYS_LOG_DBG("failed to reboot device");
|
LOG_DBG("failed to reboot device");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
if (i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
LSM6DS0_REG_WHO_AM_I, &chip_id) < 0) {
|
LSM6DS0_REG_WHO_AM_I, &chip_id) < 0) {
|
||||||
SYS_LOG_DBG("failed reading chip id");
|
LOG_DBG("failed reading chip id");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
if (chip_id != LSM6DS0_VAL_WHO_AM_I) {
|
if (chip_id != LSM6DS0_VAL_WHO_AM_I) {
|
||||||
SYS_LOG_DBG("invalid chip id 0x%x", chip_id);
|
LOG_DBG("invalid chip id 0x%x", chip_id);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
SYS_LOG_DBG("chip id 0x%x", chip_id);
|
LOG_DBG("chip id 0x%x", chip_id);
|
||||||
|
|
||||||
if (lsm6ds0_accel_axis_ctrl(dev, LSM6DS0_ACCEL_ENABLE_X_AXIS,
|
if (lsm6ds0_accel_axis_ctrl(dev, LSM6DS0_ACCEL_ENABLE_X_AXIS,
|
||||||
LSM6DS0_ACCEL_ENABLE_Y_AXIS,
|
LSM6DS0_ACCEL_ENABLE_Y_AXIS,
|
||||||
LSM6DS0_ACCEL_ENABLE_Z_AXIS) < 0) {
|
LSM6DS0_ACCEL_ENABLE_Z_AXIS) < 0) {
|
||||||
SYS_LOG_DBG("failed to set accelerometer axis");
|
LOG_DBG("failed to set accelerometer axis");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm6ds0_accel_set_fs_raw(dev, LSM6DS0_DEFAULT_ACCEL_FULLSCALE)
|
if (lsm6ds0_accel_set_fs_raw(dev, LSM6DS0_DEFAULT_ACCEL_FULLSCALE)
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_DBG("failed to set accelerometer full-scale");
|
LOG_DBG("failed to set accelerometer full-scale");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm6ds0_accel_set_odr_raw(dev, LSM6DS0_DEFAULT_ACCEL_SAMPLING_RATE)
|
if (lsm6ds0_accel_set_odr_raw(dev, LSM6DS0_DEFAULT_ACCEL_SAMPLING_RATE)
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_DBG("failed to set accelerometer sampling rate");
|
LOG_DBG("failed to set accelerometer sampling rate");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm6ds0_gyro_axis_ctrl(dev, LSM6DS0_GYRO_ENABLE_X_AXIS,
|
if (lsm6ds0_gyro_axis_ctrl(dev, LSM6DS0_GYRO_ENABLE_X_AXIS,
|
||||||
LSM6DS0_GYRO_ENABLE_Y_AXIS,
|
LSM6DS0_GYRO_ENABLE_Y_AXIS,
|
||||||
LSM6DS0_GYRO_ENABLE_Z_AXIS) < 0) {
|
LSM6DS0_GYRO_ENABLE_Z_AXIS) < 0) {
|
||||||
SYS_LOG_DBG("failed to set gyroscope axis");
|
LOG_DBG("failed to set gyroscope axis");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm6ds0_gyro_set_fs_raw(dev, LSM6DS0_DEFAULT_GYRO_FULLSCALE)
|
if (lsm6ds0_gyro_set_fs_raw(dev, LSM6DS0_DEFAULT_GYRO_FULLSCALE)
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_DBG("failed to set gyroscope full-scale");
|
LOG_DBG("failed to set gyroscope full-scale");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm6ds0_gyro_set_odr_raw(dev, LSM6DS0_DEFAULT_GYRO_SAMPLING_RATE)
|
if (lsm6ds0_gyro_set_odr_raw(dev, LSM6DS0_DEFAULT_GYRO_SAMPLING_RATE)
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_DBG("failed to set gyroscope sampling rate");
|
LOG_DBG("failed to set gyroscope sampling rate");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,7 +472,7 @@ static int lsm6ds0_init_chip(struct device *dev)
|
||||||
(0 << LSM6DS0_SHIFT_CTRL_REG8_BLE) |
|
(0 << LSM6DS0_SHIFT_CTRL_REG8_BLE) |
|
||||||
(1 << LSM6DS0_SHIFT_CTRL_REG8_IF_ADD_INC))
|
(1 << LSM6DS0_SHIFT_CTRL_REG8_IF_ADD_INC))
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_DBG("failed to set BDU, BLE and burst");
|
LOG_DBG("failed to set BDU, BLE and burst");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,13 +486,13 @@ static int lsm6ds0_init(struct device *dev)
|
||||||
|
|
||||||
data->i2c_master = device_get_binding(config->i2c_master_dev_name);
|
data->i2c_master = device_get_binding(config->i2c_master_dev_name);
|
||||||
if (!data->i2c_master) {
|
if (!data->i2c_master) {
|
||||||
SYS_LOG_DBG("i2c master not found: %s",
|
LOG_DBG("i2c master not found: %s",
|
||||||
config->i2c_master_dev_name);
|
config->i2c_master_dev_name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm6ds0_init_chip(dev) < 0) {
|
if (lsm6ds0_init_chip(dev) < 0) {
|
||||||
SYS_LOG_DBG("failed to initialize chip");
|
LOG_DBG("failed to initialize chip");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -492,7 +492,4 @@ struct lsm6ds0_data {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "LSM6DS0"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_LSM6DS0_LSM6DS0_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_LSM6DS0_LSM6DS0_H_ */
|
||||||
|
|
|
@ -15,9 +15,13 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "lsm6dsl.h"
|
#include "lsm6dsl.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(LSM6DSL);
|
||||||
|
|
||||||
static const u16_t lsm6dsl_odr_map[] = {0, 12, 26, 52, 104, 208, 416, 833,
|
static const u16_t lsm6dsl_odr_map[] = {0, 12, 26, 52, 104, 208, 416, 833,
|
||||||
1660, 3330, 6660};
|
1660, 3330, 6660};
|
||||||
|
|
||||||
|
@ -179,7 +183,7 @@ static int lsm6dsl_accel_odr_set(struct device *dev, u16_t freq)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm6dsl_accel_set_odr_raw(dev, odr) < 0) {
|
if (lsm6dsl_accel_set_odr_raw(dev, odr) < 0) {
|
||||||
SYS_LOG_DBG("failed to set accelerometer sampling rate");
|
LOG_DBG("failed to set accelerometer sampling rate");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +203,7 @@ static int lsm6dsl_accel_range_set(struct device *dev, s32_t range)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm6dsl_accel_set_fs_raw(dev, fs) < 0) {
|
if (lsm6dsl_accel_set_fs_raw(dev, fs) < 0) {
|
||||||
SYS_LOG_DBG("failed to set accelerometer full-scale");
|
LOG_DBG("failed to set accelerometer full-scale");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +227,7 @@ static int lsm6dsl_accel_config(struct device *dev, enum sensor_channel chan,
|
||||||
return lsm6dsl_accel_odr_set(dev, val->val1);
|
return lsm6dsl_accel_odr_set(dev, val->val1);
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
SYS_LOG_DBG("Accel attribute not supported.");
|
LOG_DBG("Accel attribute not supported.");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +245,7 @@ static int lsm6dsl_gyro_odr_set(struct device *dev, u16_t freq)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm6dsl_gyro_set_odr_raw(dev, odr) < 0) {
|
if (lsm6dsl_gyro_set_odr_raw(dev, odr) < 0) {
|
||||||
SYS_LOG_DBG("failed to set gyroscope sampling rate");
|
LOG_DBG("failed to set gyroscope sampling rate");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +265,7 @@ static int lsm6dsl_gyro_range_set(struct device *dev, s32_t range)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm6dsl_gyro_set_fs_raw(dev, fs) < 0) {
|
if (lsm6dsl_gyro_set_fs_raw(dev, fs) < 0) {
|
||||||
SYS_LOG_DBG("failed to set gyroscope full-scale");
|
LOG_DBG("failed to set gyroscope full-scale");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +289,7 @@ static int lsm6dsl_gyro_config(struct device *dev, enum sensor_channel chan,
|
||||||
return lsm6dsl_gyro_odr_set(dev, val->val1);
|
return lsm6dsl_gyro_odr_set(dev, val->val1);
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
SYS_LOG_DBG("Gyro attribute not supported.");
|
LOG_DBG("Gyro attribute not supported.");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +306,7 @@ static int lsm6dsl_attr_set(struct device *dev, enum sensor_channel chan,
|
||||||
case SENSOR_CHAN_GYRO_XYZ:
|
case SENSOR_CHAN_GYRO_XYZ:
|
||||||
return lsm6dsl_gyro_config(dev, chan, attr, val);
|
return lsm6dsl_gyro_config(dev, chan, attr, val);
|
||||||
default:
|
default:
|
||||||
SYS_LOG_WRN("attr_set() not supported on this channel.");
|
LOG_WRN("attr_set() not supported on this channel.");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,7 +320,7 @@ static int lsm6dsl_sample_fetch_accel(struct device *dev)
|
||||||
|
|
||||||
if (data->hw_tf->read_data(data, LSM6DSL_REG_OUTX_L_XL,
|
if (data->hw_tf->read_data(data, LSM6DSL_REG_OUTX_L_XL,
|
||||||
buf, sizeof(buf)) < 0) {
|
buf, sizeof(buf)) < 0) {
|
||||||
SYS_LOG_DBG("failed to read sample");
|
LOG_DBG("failed to read sample");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,7 +341,7 @@ static int lsm6dsl_sample_fetch_gyro(struct device *dev)
|
||||||
|
|
||||||
if (data->hw_tf->read_data(data, LSM6DSL_REG_OUTX_L_G,
|
if (data->hw_tf->read_data(data, LSM6DSL_REG_OUTX_L_G,
|
||||||
buf, sizeof(buf)) < 0) {
|
buf, sizeof(buf)) < 0) {
|
||||||
SYS_LOG_DBG("failed to read sample");
|
LOG_DBG("failed to read sample");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,7 +363,7 @@ static int lsm6dsl_sample_fetch_temp(struct device *dev)
|
||||||
|
|
||||||
if (data->hw_tf->read_data(data, LSM6DSL_REG_OUT_TEMP_L,
|
if (data->hw_tf->read_data(data, LSM6DSL_REG_OUT_TEMP_L,
|
||||||
buf, sizeof(buf)) < 0) {
|
buf, sizeof(buf)) < 0) {
|
||||||
SYS_LOG_DBG("failed to read sample");
|
LOG_DBG("failed to read sample");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,7 +381,7 @@ static int lsm6dsl_sample_fetch_magn(struct device *dev)
|
||||||
u8_t buf[6];
|
u8_t buf[6];
|
||||||
|
|
||||||
if (lsm6dsl_shub_read_external_chip(dev, buf, sizeof(buf)) < 0) {
|
if (lsm6dsl_shub_read_external_chip(dev, buf, sizeof(buf)) < 0) {
|
||||||
SYS_LOG_DBG("failed to read ext mag sample");
|
LOG_DBG("failed to read ext mag sample");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,7 +402,7 @@ static int lsm6dsl_sample_fetch_press(struct device *dev)
|
||||||
u8_t buf[5];
|
u8_t buf[5];
|
||||||
|
|
||||||
if (lsm6dsl_shub_read_external_chip(dev, buf, sizeof(buf)) < 0) {
|
if (lsm6dsl_shub_read_external_chip(dev, buf, sizeof(buf)) < 0) {
|
||||||
SYS_LOG_DBG("failed to read ext press sample");
|
LOG_DBG("failed to read ext press sample");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -705,43 +709,43 @@ static int lsm6dsl_init_chip(struct device *dev)
|
||||||
u8_t chip_id;
|
u8_t chip_id;
|
||||||
|
|
||||||
if (lsm6dsl_reboot(dev) < 0) {
|
if (lsm6dsl_reboot(dev) < 0) {
|
||||||
SYS_LOG_DBG("failed to reboot device");
|
LOG_DBG("failed to reboot device");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->hw_tf->read_reg(data, LSM6DSL_REG_WHO_AM_I, &chip_id) < 0) {
|
if (data->hw_tf->read_reg(data, LSM6DSL_REG_WHO_AM_I, &chip_id) < 0) {
|
||||||
SYS_LOG_DBG("failed reading chip id");
|
LOG_DBG("failed reading chip id");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
if (chip_id != LSM6DSL_VAL_WHO_AM_I) {
|
if (chip_id != LSM6DSL_VAL_WHO_AM_I) {
|
||||||
SYS_LOG_DBG("invalid chip id 0x%x", chip_id);
|
LOG_DBG("invalid chip id 0x%x", chip_id);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_DBG("chip id 0x%x", chip_id);
|
LOG_DBG("chip id 0x%x", chip_id);
|
||||||
|
|
||||||
if (lsm6dsl_accel_set_fs_raw(dev,
|
if (lsm6dsl_accel_set_fs_raw(dev,
|
||||||
LSM6DSL_DEFAULT_ACCEL_FULLSCALE) < 0) {
|
LSM6DSL_DEFAULT_ACCEL_FULLSCALE) < 0) {
|
||||||
SYS_LOG_DBG("failed to set accelerometer full-scale");
|
LOG_DBG("failed to set accelerometer full-scale");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
data->accel_sensitivity = LSM6DSL_DEFAULT_ACCEL_SENSITIVITY;
|
data->accel_sensitivity = LSM6DSL_DEFAULT_ACCEL_SENSITIVITY;
|
||||||
|
|
||||||
data->accel_freq = lsm6dsl_odr_to_freq_val(CONFIG_LSM6DSL_ACCEL_ODR);
|
data->accel_freq = lsm6dsl_odr_to_freq_val(CONFIG_LSM6DSL_ACCEL_ODR);
|
||||||
if (lsm6dsl_accel_set_odr_raw(dev, CONFIG_LSM6DSL_ACCEL_ODR) < 0) {
|
if (lsm6dsl_accel_set_odr_raw(dev, CONFIG_LSM6DSL_ACCEL_ODR) < 0) {
|
||||||
SYS_LOG_DBG("failed to set accelerometer sampling rate");
|
LOG_DBG("failed to set accelerometer sampling rate");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm6dsl_gyro_set_fs_raw(dev, LSM6DSL_DEFAULT_GYRO_FULLSCALE) < 0) {
|
if (lsm6dsl_gyro_set_fs_raw(dev, LSM6DSL_DEFAULT_GYRO_FULLSCALE) < 0) {
|
||||||
SYS_LOG_DBG("failed to set gyroscope full-scale");
|
LOG_DBG("failed to set gyroscope full-scale");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
data->gyro_sensitivity = LSM6DSL_DEFAULT_GYRO_SENSITIVITY;
|
data->gyro_sensitivity = LSM6DSL_DEFAULT_GYRO_SENSITIVITY;
|
||||||
|
|
||||||
data->gyro_freq = lsm6dsl_odr_to_freq_val(CONFIG_LSM6DSL_GYRO_ODR);
|
data->gyro_freq = lsm6dsl_odr_to_freq_val(CONFIG_LSM6DSL_GYRO_ODR);
|
||||||
if (lsm6dsl_gyro_set_odr_raw(dev, CONFIG_LSM6DSL_GYRO_ODR) < 0) {
|
if (lsm6dsl_gyro_set_odr_raw(dev, CONFIG_LSM6DSL_GYRO_ODR) < 0) {
|
||||||
SYS_LOG_DBG("failed to set gyroscope sampling rate");
|
LOG_DBG("failed to set gyroscope sampling rate");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -749,7 +753,7 @@ static int lsm6dsl_init_chip(struct device *dev)
|
||||||
LSM6DSL_REG_FIFO_CTRL5,
|
LSM6DSL_REG_FIFO_CTRL5,
|
||||||
LSM6DSL_MASK_FIFO_CTRL5_FIFO_MODE,
|
LSM6DSL_MASK_FIFO_CTRL5_FIFO_MODE,
|
||||||
0 << LSM6DSL_SHIFT_FIFO_CTRL5_FIFO_MODE) < 0) {
|
0 << LSM6DSL_SHIFT_FIFO_CTRL5_FIFO_MODE) < 0) {
|
||||||
SYS_LOG_DBG("failed to set FIFO mode");
|
LOG_DBG("failed to set FIFO mode");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,7 +765,7 @@ static int lsm6dsl_init_chip(struct device *dev)
|
||||||
(1 << LSM6DSL_SHIFT_CTRL3_C_BDU) |
|
(1 << LSM6DSL_SHIFT_CTRL3_C_BDU) |
|
||||||
(0 << LSM6DSL_SHIFT_CTRL3_C_BLE) |
|
(0 << LSM6DSL_SHIFT_CTRL3_C_BLE) |
|
||||||
(1 << LSM6DSL_SHIFT_CTRL3_C_IF_INC)) < 0) {
|
(1 << LSM6DSL_SHIFT_CTRL3_C_IF_INC)) < 0) {
|
||||||
SYS_LOG_DBG("failed to set BDU, BLE and burst");
|
LOG_DBG("failed to set BDU, BLE and burst");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -783,7 +787,7 @@ static int lsm6dsl_init(struct device *dev)
|
||||||
|
|
||||||
data->comm_master = device_get_binding(config->comm_master_dev_name);
|
data->comm_master = device_get_binding(config->comm_master_dev_name);
|
||||||
if (!data->comm_master) {
|
if (!data->comm_master) {
|
||||||
SYS_LOG_DBG("master not found: %s",
|
LOG_DBG("master not found: %s",
|
||||||
config->comm_master_dev_name);
|
config->comm_master_dev_name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -796,19 +800,19 @@ static int lsm6dsl_init(struct device *dev)
|
||||||
|
|
||||||
#ifdef CONFIG_LSM6DSL_TRIGGER
|
#ifdef CONFIG_LSM6DSL_TRIGGER
|
||||||
if (lsm6dsl_init_interrupt(dev) < 0) {
|
if (lsm6dsl_init_interrupt(dev) < 0) {
|
||||||
SYS_LOG_ERR("Failed to initialize interrupt.");
|
LOG_ERR("Failed to initialize interrupt.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (lsm6dsl_init_chip(dev) < 0) {
|
if (lsm6dsl_init_chip(dev) < 0) {
|
||||||
SYS_LOG_DBG("failed to initialize chip");
|
LOG_DBG("failed to initialize chip");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_LSM6DSL_SENSORHUB
|
#ifdef CONFIG_LSM6DSL_SENSORHUB
|
||||||
if (lsm6dsl_shub_init_external_chip(dev) < 0) {
|
if (lsm6dsl_shub_init_external_chip(dev) < 0) {
|
||||||
SYS_LOG_DBG("failed to initialize external chip");
|
LOG_DBG("failed to initialize external chip");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#include <gpio.h>
|
#include <gpio.h>
|
||||||
#include <misc/util.h>
|
#include <misc/util.h>
|
||||||
|
|
||||||
|
|
||||||
#define LSM6DSL_REG_FUNC_CFG_ACCESS 0x01
|
#define LSM6DSL_REG_FUNC_CFG_ACCESS 0x01
|
||||||
#define LSM6DSL_MASK_FUNC_CFG_EN BIT(7)
|
#define LSM6DSL_MASK_FUNC_CFG_EN BIT(7)
|
||||||
#define LSM6DSL_SHIFT_FUNC_CFG_EN 7
|
#define LSM6DSL_SHIFT_FUNC_CFG_EN 7
|
||||||
|
@ -684,7 +683,4 @@ int lsm6dsl_trigger_set(struct device *dev,
|
||||||
int lsm6dsl_init_interrupt(struct device *dev);
|
int lsm6dsl_init_interrupt(struct device *dev);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "LSM6DSL"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_LSM6DSL_LSM6DSL_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_LSM6DSL_LSM6DSL_H_ */
|
||||||
|
|
|
@ -9,10 +9,15 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <i2c.h>
|
#include <i2c.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "lsm6dsl.h"
|
#include "lsm6dsl.h"
|
||||||
|
|
||||||
static u16_t lsm6dsl_i2c_slave_addr = CONFIG_LSM6DSL_I2C_ADDR;
|
static u16_t lsm6dsl_i2c_slave_addr = CONFIG_LSM6DSL_I2C_ADDR;
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_DECLARE(LSM6DSL);
|
||||||
|
|
||||||
static int lsm6dsl_i2c_read_data(struct lsm6dsl_data *data, u8_t reg_addr,
|
static int lsm6dsl_i2c_read_data(struct lsm6dsl_data *data, u8_t reg_addr,
|
||||||
u8_t *value, u8_t len)
|
u8_t *value, u8_t len)
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,9 +10,13 @@
|
||||||
#include <misc/util.h>
|
#include <misc/util.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "lsm6dsl.h"
|
#include "lsm6dsl.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_DECLARE(LSM6DSL);
|
||||||
|
|
||||||
#define LSM6DSL_EMBEDDED_SLV0_ADDR 0x02
|
#define LSM6DSL_EMBEDDED_SLV0_ADDR 0x02
|
||||||
#define LSM6DSL_EMBEDDED_SLV0_SUBADDR 0x03
|
#define LSM6DSL_EMBEDDED_SLV0_SUBADDR 0x03
|
||||||
#define LSM6DSL_EMBEDDED_SLV0_CONFIG 0x04
|
#define LSM6DSL_EMBEDDED_SLV0_CONFIG 0x04
|
||||||
|
@ -168,7 +172,7 @@ static int lsm6dsl_read_embedded_reg(struct lsm6dsl_data *data,
|
||||||
lsm6dsl_shub_embedded_en(data, true);
|
lsm6dsl_shub_embedded_en(data, true);
|
||||||
|
|
||||||
if (data->hw_tf->read_data(data, reg_addr, value, len) < 0) {
|
if (data->hw_tf->read_data(data, reg_addr, value, len) < 0) {
|
||||||
SYS_LOG_DBG("failed to read external reg: %02x", reg_addr);
|
LOG_DBG("failed to read external reg: %02x", reg_addr);
|
||||||
lsm6dsl_shub_embedded_en(data, false);
|
lsm6dsl_shub_embedded_en(data, false);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@ -186,7 +190,7 @@ static int lsm6dsl_shub_write_embedded_regs(struct lsm6dsl_data *data,
|
||||||
lsm6dsl_shub_embedded_en(data, true);
|
lsm6dsl_shub_embedded_en(data, true);
|
||||||
|
|
||||||
if (data->hw_tf->write_data(data, reg_addr, value, len) < 0) {
|
if (data->hw_tf->write_data(data, reg_addr, value, len) < 0) {
|
||||||
SYS_LOG_DBG("failed to write external reg: %02x", reg_addr);
|
LOG_DBG("failed to write external reg: %02x", reg_addr);
|
||||||
lsm6dsl_shub_embedded_en(data, false);
|
lsm6dsl_shub_embedded_en(data, false);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@ -253,7 +257,7 @@ static int lsm6dsl_shub_read_slave_reg(struct lsm6dsl_data *data,
|
||||||
|
|
||||||
if (lsm6dsl_shub_write_embedded_regs(data, LSM6DSL_EMBEDDED_SLV0_ADDR,
|
if (lsm6dsl_shub_write_embedded_regs(data, LSM6DSL_EMBEDDED_SLV0_ADDR,
|
||||||
slave, 3) < 0) {
|
slave, 3) < 0) {
|
||||||
SYS_LOG_DBG("error writing embedded reg");
|
LOG_DBG("error writing embedded reg");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +287,7 @@ static int lsm6dsl_shub_write_slave_reg(struct lsm6dsl_data *data,
|
||||||
if (lsm6dsl_shub_write_embedded_regs(data,
|
if (lsm6dsl_shub_write_embedded_regs(data,
|
||||||
LSM6DSL_EMBEDDED_SLV0_ADDR,
|
LSM6DSL_EMBEDDED_SLV0_ADDR,
|
||||||
slv_cfg, 2) < 0) {
|
slv_cfg, 2) < 0) {
|
||||||
SYS_LOG_DBG("error writing embedded reg");
|
LOG_DBG("error writing embedded reg");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,7 +295,7 @@ static int lsm6dsl_shub_write_slave_reg(struct lsm6dsl_data *data,
|
||||||
if (lsm6dsl_shub_write_embedded_regs(data,
|
if (lsm6dsl_shub_write_embedded_regs(data,
|
||||||
LSM6DSL_EMBEDDED_SLV0_DATAWRITE,
|
LSM6DSL_EMBEDDED_SLV0_DATAWRITE,
|
||||||
slv_cfg, 1) < 0) {
|
slv_cfg, 1) < 0) {
|
||||||
SYS_LOG_DBG("error writing embedded reg");
|
LOG_DBG("error writing embedded reg");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,7 +314,7 @@ static int lsm6dsl_shub_write_slave_reg(struct lsm6dsl_data *data,
|
||||||
if (lsm6dsl_shub_write_embedded_regs(data,
|
if (lsm6dsl_shub_write_embedded_regs(data,
|
||||||
LSM6DSL_EMBEDDED_SLV0_ADDR,
|
LSM6DSL_EMBEDDED_SLV0_ADDR,
|
||||||
slv_cfg, 3) < 0) {
|
slv_cfg, 3) < 0) {
|
||||||
SYS_LOG_DBG("error writing embedded reg");
|
LOG_DBG("error writing embedded reg");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,7 +340,7 @@ static int lsm6dsl_shub_set_data_channel(struct lsm6dsl_data *data)
|
||||||
if (lsm6dsl_shub_write_embedded_regs(data,
|
if (lsm6dsl_shub_write_embedded_regs(data,
|
||||||
LSM6DSL_EMBEDDED_SLV0_ADDR,
|
LSM6DSL_EMBEDDED_SLV0_ADDR,
|
||||||
slv_cfg, 3) < 0) {
|
slv_cfg, 3) < 0) {
|
||||||
SYS_LOG_DBG("error writing embedded reg");
|
LOG_DBG("error writing embedded reg");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,7 +351,7 @@ static int lsm6dsl_shub_set_data_channel(struct lsm6dsl_data *data)
|
||||||
if (lsm6dsl_shub_write_embedded_regs(data,
|
if (lsm6dsl_shub_write_embedded_regs(data,
|
||||||
LSM6DSL_EMBEDDED_SLV1_ADDR,
|
LSM6DSL_EMBEDDED_SLV1_ADDR,
|
||||||
slv_cfg, 3) < 0) {
|
slv_cfg, 3) < 0) {
|
||||||
SYS_LOG_DBG("error writing embedded reg");
|
LOG_DBG("error writing embedded reg");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,7 +394,7 @@ int lsm6dsl_shub_init_external_chip(struct device *dev)
|
||||||
if (lsm6dsl_shub_read_slave_reg(data, slv_i2c_addr,
|
if (lsm6dsl_shub_read_slave_reg(data, slv_i2c_addr,
|
||||||
slv_wai_addr,
|
slv_wai_addr,
|
||||||
&chip_id, 1) < 0) {
|
&chip_id, 1) < 0) {
|
||||||
SYS_LOG_DBG("failed reading external chip id");
|
LOG_DBG("failed reading external chip id");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
if (chip_id == lsm6dsl_shub_sens_list[0].wai_val) {
|
if (chip_id == lsm6dsl_shub_sens_list[0].wai_val) {
|
||||||
|
@ -399,10 +403,10 @@ int lsm6dsl_shub_init_external_chip(struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i >= ARRAY_SIZE(lsm6dsl_shub_sens_list[0].i2c_addr)) {
|
if (i >= ARRAY_SIZE(lsm6dsl_shub_sens_list[0].i2c_addr)) {
|
||||||
SYS_LOG_DBG("invalid chip id 0x%x", chip_id);
|
LOG_DBG("invalid chip id 0x%x", chip_id);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
SYS_LOG_DBG("Ext Device Chip Id: %02x", chip_id);
|
LOG_DBG("Ext Device Chip Id: %02x", chip_id);
|
||||||
ext_i2c_addr = i;
|
ext_i2c_addr = i;
|
||||||
|
|
||||||
/* init external device */
|
/* init external device */
|
||||||
|
|
|
@ -10,9 +10,13 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <spi.h>
|
#include <spi.h>
|
||||||
#include "lsm6dsl.h"
|
#include "lsm6dsl.h"
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#define LSM6DSL_SPI_READ (1 << 7)
|
#define LSM6DSL_SPI_READ (1 << 7)
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_DECLARE(LSM6DSL);
|
||||||
|
|
||||||
#if defined(CONFIG_LSM6DSL_SPI_GPIO_CS)
|
#if defined(CONFIG_LSM6DSL_SPI_GPIO_CS)
|
||||||
static struct spi_cs_control lsm6dsl_cs_ctrl;
|
static struct spi_cs_control lsm6dsl_cs_ctrl;
|
||||||
#endif
|
#endif
|
||||||
|
@ -147,7 +151,7 @@ int lsm6dsl_spi_init(struct device *dev)
|
||||||
lsm6dsl_cs_ctrl.gpio_dev = device_get_binding(
|
lsm6dsl_cs_ctrl.gpio_dev = device_get_binding(
|
||||||
CONFIG_LSM6DSL_SPI_GPIO_CS_DRV_NAME);
|
CONFIG_LSM6DSL_SPI_GPIO_CS_DRV_NAME);
|
||||||
if (!lsm6dsl_cs_ctrl.gpio_dev) {
|
if (!lsm6dsl_cs_ctrl.gpio_dev) {
|
||||||
SYS_LOG_ERR("Unable to get GPIO SPI CS device");
|
LOG_ERR("Unable to get GPIO SPI CS device");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +160,7 @@ int lsm6dsl_spi_init(struct device *dev)
|
||||||
|
|
||||||
lsm6dsl_spi_conf.cs = &lsm6dsl_cs_ctrl;
|
lsm6dsl_spi_conf.cs = &lsm6dsl_cs_ctrl;
|
||||||
|
|
||||||
SYS_LOG_DBG("SPI GPIO CS configured on %s:%u",
|
LOG_DBG("SPI GPIO CS configured on %s:%u",
|
||||||
CONFIG_LSM6DSL_SPI_GPIO_CS_DRV_NAME,
|
CONFIG_LSM6DSL_SPI_GPIO_CS_DRV_NAME,
|
||||||
CONFIG_LSM6DSL_SPI_GPIO_CS_PIN);
|
CONFIG_LSM6DSL_SPI_GPIO_CS_PIN);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
|
|
||||||
#include "lsm6dsl.h"
|
#include "lsm6dsl.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(LSM6DSL);
|
||||||
|
|
||||||
int lsm6dsl_trigger_set(struct device *dev,
|
int lsm6dsl_trigger_set(struct device *dev,
|
||||||
const struct sensor_trigger *trig,
|
const struct sensor_trigger *trig,
|
||||||
sensor_trigger_handler_t handler)
|
sensor_trigger_handler_t handler)
|
||||||
|
@ -97,7 +101,7 @@ int lsm6dsl_init_interrupt(struct device *dev)
|
||||||
/* setup data ready gpio interrupt */
|
/* setup data ready gpio interrupt */
|
||||||
drv_data->gpio = device_get_binding(CONFIG_LSM6DSL_GPIO_DEV_NAME);
|
drv_data->gpio = device_get_binding(CONFIG_LSM6DSL_GPIO_DEV_NAME);
|
||||||
if (drv_data->gpio == NULL) {
|
if (drv_data->gpio == NULL) {
|
||||||
SYS_LOG_ERR("Cannot get pointer to %s device.",
|
LOG_ERR("Cannot get pointer to %s device.",
|
||||||
CONFIG_LSM6DSL_GPIO_DEV_NAME);
|
CONFIG_LSM6DSL_GPIO_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +115,7 @@ int lsm6dsl_init_interrupt(struct device *dev)
|
||||||
BIT(CONFIG_LSM6DSL_GPIO_PIN_NUM));
|
BIT(CONFIG_LSM6DSL_GPIO_PIN_NUM));
|
||||||
|
|
||||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||||
SYS_LOG_ERR("Could not set gpio callback.");
|
LOG_ERR("Could not set gpio callback.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +126,7 @@ int lsm6dsl_init_interrupt(struct device *dev)
|
||||||
LSM6DSL_SHIFT_INT1_CTRL_DRDY_G,
|
LSM6DSL_SHIFT_INT1_CTRL_DRDY_G,
|
||||||
(1 << LSM6DSL_SHIFT_INT1_CTRL_DRDY_XL) |
|
(1 << LSM6DSL_SHIFT_INT1_CTRL_DRDY_XL) |
|
||||||
(1 << LSM6DSL_SHIFT_INT1_CTRL_DRDY_G)) < 0) {
|
(1 << LSM6DSL_SHIFT_INT1_CTRL_DRDY_G)) < 0) {
|
||||||
SYS_LOG_ERR("Could not enable data-ready interrupt.");
|
LOG_ERR("Could not enable data-ready interrupt.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,13 @@
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
|
||||||
#include <gpio.h>
|
#include <gpio.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "lsm9ds0_gyro.h"
|
#include "lsm9ds0_gyro.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(LSM9DS0_GYRO);
|
||||||
|
|
||||||
static inline int lsm9ds0_gyro_power_ctrl(struct device *dev, int power,
|
static inline int lsm9ds0_gyro_power_ctrl(struct device *dev, int power,
|
||||||
int x_en, int y_en, int z_en)
|
int x_en, int y_en, int z_en)
|
||||||
{
|
{
|
||||||
|
@ -135,7 +139,7 @@ static int lsm9ds0_gyro_sample_fetch(struct device *dev,
|
||||||
LSM9DS0_GYRO_REG_OUT_Z_L_G, &z_l) < 0 ||
|
LSM9DS0_GYRO_REG_OUT_Z_L_G, &z_l) < 0 ||
|
||||||
i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
LSM9DS0_GYRO_REG_OUT_Z_H_G, &z_h) < 0) {
|
LSM9DS0_GYRO_REG_OUT_Z_H_G, &z_h) < 0) {
|
||||||
SYS_LOG_DBG("failed to read sample");
|
LOG_DBG("failed to read sample");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +226,7 @@ static int lsm9ds0_gyro_attr_set(struct device *dev,
|
||||||
#if defined(CONFIG_LSM9DS0_GYRO_FULLSCALE_RUNTIME)
|
#if defined(CONFIG_LSM9DS0_GYRO_FULLSCALE_RUNTIME)
|
||||||
case SENSOR_ATTR_FULL_SCALE:
|
case SENSOR_ATTR_FULL_SCALE:
|
||||||
if (lsm9ds0_gyro_set_fs(dev, sensor_rad_to_degrees(val)) < 0) {
|
if (lsm9ds0_gyro_set_fs(dev, sensor_rad_to_degrees(val)) < 0) {
|
||||||
SYS_LOG_DBG("full-scale value not supported");
|
LOG_DBG("full-scale value not supported");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -230,7 +234,7 @@ static int lsm9ds0_gyro_attr_set(struct device *dev,
|
||||||
#if defined(CONFIG_LSM9DS0_GYRO_SAMPLING_RATE_RUNTIME)
|
#if defined(CONFIG_LSM9DS0_GYRO_SAMPLING_RATE_RUNTIME)
|
||||||
case SENSOR_ATTR_SAMPLING_FREQUENCY:
|
case SENSOR_ATTR_SAMPLING_FREQUENCY:
|
||||||
if (lsm9ds0_gyro_set_odr(dev, val->val1) < 0) {
|
if (lsm9ds0_gyro_set_odr(dev, val->val1) < 0) {
|
||||||
SYS_LOG_DBG("sampling frequency value not supported");
|
LOG_DBG("sampling frequency value not supported");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -261,34 +265,34 @@ static int lsm9ds0_gyro_init_chip(struct device *dev)
|
||||||
u8_t chip_id;
|
u8_t chip_id;
|
||||||
|
|
||||||
if (lsm9ds0_gyro_power_ctrl(dev, 0, 0, 0, 0) < 0) {
|
if (lsm9ds0_gyro_power_ctrl(dev, 0, 0, 0, 0) < 0) {
|
||||||
SYS_LOG_DBG("failed to power off device");
|
LOG_DBG("failed to power off device");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm9ds0_gyro_power_ctrl(dev, 1, 1, 1, 1) < 0) {
|
if (lsm9ds0_gyro_power_ctrl(dev, 1, 1, 1, 1) < 0) {
|
||||||
SYS_LOG_DBG("failed to power on device");
|
LOG_DBG("failed to power on device");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
if (i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
LSM9DS0_GYRO_REG_WHO_AM_I_G, &chip_id) < 0) {
|
LSM9DS0_GYRO_REG_WHO_AM_I_G, &chip_id) < 0) {
|
||||||
SYS_LOG_DBG("failed reading chip id");
|
LOG_DBG("failed reading chip id");
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
if (chip_id != LSM9DS0_GYRO_VAL_WHO_AM_I_G) {
|
if (chip_id != LSM9DS0_GYRO_VAL_WHO_AM_I_G) {
|
||||||
SYS_LOG_DBG("invalid chip id 0x%x", chip_id);
|
LOG_DBG("invalid chip id 0x%x", chip_id);
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
SYS_LOG_DBG("chip id 0x%x", chip_id);
|
LOG_DBG("chip id 0x%x", chip_id);
|
||||||
|
|
||||||
if (lsm9ds0_gyro_set_fs_raw(dev, LSM9DS0_GYRO_DEFAULT_FULLSCALE) < 0) {
|
if (lsm9ds0_gyro_set_fs_raw(dev, LSM9DS0_GYRO_DEFAULT_FULLSCALE) < 0) {
|
||||||
SYS_LOG_DBG("failed to set full-scale");
|
LOG_DBG("failed to set full-scale");
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm9ds0_gyro_set_odr_raw(dev, LSM9DS0_GYRO_DEFAULT_SAMPLING_RATE)
|
if (lsm9ds0_gyro_set_odr_raw(dev, LSM9DS0_GYRO_DEFAULT_SAMPLING_RATE)
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_DBG("failed to set sampling rate");
|
LOG_DBG("failed to set sampling rate");
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +303,7 @@ static int lsm9ds0_gyro_init_chip(struct device *dev)
|
||||||
(1 << LSM9DS0_GYRO_SHIFT_CTRL_REG4_G_BDU) |
|
(1 << LSM9DS0_GYRO_SHIFT_CTRL_REG4_G_BDU) |
|
||||||
(0 << LSM9DS0_GYRO_SHIFT_CTRL_REG4_G_BLE))
|
(0 << LSM9DS0_GYRO_SHIFT_CTRL_REG4_G_BLE))
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_DBG("failed to set BDU and BLE");
|
LOG_DBG("failed to set BDU and BLE");
|
||||||
goto err_poweroff;
|
goto err_poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,19 +322,19 @@ static int lsm9ds0_gyro_init(struct device *dev)
|
||||||
|
|
||||||
data->i2c_master = device_get_binding(config->i2c_master_dev_name);
|
data->i2c_master = device_get_binding(config->i2c_master_dev_name);
|
||||||
if (!data->i2c_master) {
|
if (!data->i2c_master) {
|
||||||
SYS_LOG_DBG("i2c master not found: %s",
|
LOG_DBG("i2c master not found: %s",
|
||||||
config->i2c_master_dev_name);
|
config->i2c_master_dev_name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm9ds0_gyro_init_chip(dev) < 0) {
|
if (lsm9ds0_gyro_init_chip(dev) < 0) {
|
||||||
SYS_LOG_DBG("failed to initialize chip");
|
LOG_DBG("failed to initialize chip");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_LSM9DS0_GYRO_TRIGGER_DRDY)
|
#if defined(CONFIG_LSM9DS0_GYRO_TRIGGER_DRDY)
|
||||||
if (lsm9ds0_gyro_init_interrupt(dev) < 0) {
|
if (lsm9ds0_gyro_init_interrupt(dev) < 0) {
|
||||||
SYS_LOG_DBG("failed to initialize interrupts");
|
LOG_DBG("failed to initialize interrupts");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -255,7 +255,4 @@ int lsm9ds0_gyro_trigger_set(struct device *dev,
|
||||||
int lsm9ds0_gyro_init_interrupt(struct device *dev);
|
int lsm9ds0_gyro_init_interrupt(struct device *dev);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "LSM9DS0_GYRO"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_LSM9DS0_GYRO_LSM9DS0_GYRO_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_LSM9DS0_GYRO_LSM9DS0_GYRO_H_ */
|
||||||
|
|
|
@ -18,6 +18,10 @@
|
||||||
|
|
||||||
extern struct lsm9ds0_gyro_data lsm9ds0_gyro_data;
|
extern struct lsm9ds0_gyro_data lsm9ds0_gyro_data;
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(LSM9DS0_GYRO);
|
||||||
|
|
||||||
int lsm9ds0_gyro_trigger_set(struct device *dev,
|
int lsm9ds0_gyro_trigger_set(struct device *dev,
|
||||||
const struct sensor_trigger *trig,
|
const struct sensor_trigger *trig,
|
||||||
sensor_trigger_handler_t handler)
|
sensor_trigger_handler_t handler)
|
||||||
|
@ -45,7 +49,7 @@ int lsm9ds0_gyro_trigger_set(struct device *dev,
|
||||||
LSM9DS0_GYRO_MASK_CTRL_REG3_G_I2_DRDY,
|
LSM9DS0_GYRO_MASK_CTRL_REG3_G_I2_DRDY,
|
||||||
state << LSM9DS0_GYRO_SHIFT_CTRL_REG3_G_I2_DRDY)
|
state << LSM9DS0_GYRO_SHIFT_CTRL_REG3_G_I2_DRDY)
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_DBG("failed to set DRDY interrupt");
|
LOG_DBG("failed to set DRDY interrupt");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +108,7 @@ int lsm9ds0_gyro_init_interrupt(struct device *dev)
|
||||||
|
|
||||||
data->gpio_drdy = device_get_binding(config->gpio_drdy_dev_name);
|
data->gpio_drdy = device_get_binding(config->gpio_drdy_dev_name);
|
||||||
if (!data->gpio_drdy) {
|
if (!data->gpio_drdy) {
|
||||||
SYS_LOG_DBG("gpio controller %s not found",
|
LOG_DBG("gpio controller %s not found",
|
||||||
config->gpio_drdy_dev_name);
|
config->gpio_drdy_dev_name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -118,7 +122,7 @@ int lsm9ds0_gyro_init_interrupt(struct device *dev)
|
||||||
BIT(config->gpio_drdy_int_pin));
|
BIT(config->gpio_drdy_int_pin));
|
||||||
|
|
||||||
if (gpio_add_callback(data->gpio_drdy, &data->gpio_cb) < 0) {
|
if (gpio_add_callback(data->gpio_drdy, &data->gpio_cb) < 0) {
|
||||||
SYS_LOG_DBG("failed to set gpio callback");
|
LOG_DBG("failed to set gpio callback");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,14 @@
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <i2c.h>
|
#include <i2c.h>
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
|
|
||||||
#include <gpio.h>
|
#include <gpio.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "lsm9ds0_mfd.h"
|
#include "lsm9ds0_mfd.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(LSM9DS0_MFD);
|
||||||
|
|
||||||
static inline int lsm9ds0_mfd_reboot_memory(struct device *dev)
|
static inline int lsm9ds0_mfd_reboot_memory(struct device *dev)
|
||||||
{
|
{
|
||||||
struct lsm9ds0_mfd_data *data = dev->driver_data;
|
struct lsm9ds0_mfd_data *data = dev->driver_data;
|
||||||
|
@ -223,7 +226,7 @@ static inline int lsm9ds0_mfd_sample_fetch_accel(struct device *dev)
|
||||||
LSM9DS0_MFD_REG_OUT_X_L_A, &out_l) < 0 ||
|
LSM9DS0_MFD_REG_OUT_X_L_A, &out_l) < 0 ||
|
||||||
i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
LSM9DS0_MFD_REG_OUT_X_H_A, &out_h) < 0) {
|
LSM9DS0_MFD_REG_OUT_X_H_A, &out_h) < 0) {
|
||||||
SYS_LOG_DBG("failed to read accel sample (X axis)");
|
LOG_DBG("failed to read accel sample (X axis)");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +239,7 @@ static inline int lsm9ds0_mfd_sample_fetch_accel(struct device *dev)
|
||||||
LSM9DS0_MFD_REG_OUT_Y_L_A, &out_l) < 0 ||
|
LSM9DS0_MFD_REG_OUT_Y_L_A, &out_l) < 0 ||
|
||||||
i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
LSM9DS0_MFD_REG_OUT_Y_H_A, &out_h) < 0) {
|
LSM9DS0_MFD_REG_OUT_Y_H_A, &out_h) < 0) {
|
||||||
SYS_LOG_DBG("failed to read accel sample (Y axis)");
|
LOG_DBG("failed to read accel sample (Y axis)");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +252,7 @@ static inline int lsm9ds0_mfd_sample_fetch_accel(struct device *dev)
|
||||||
LSM9DS0_MFD_REG_OUT_Z_L_A, &out_l) < 0 ||
|
LSM9DS0_MFD_REG_OUT_Z_L_A, &out_l) < 0 ||
|
||||||
i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
LSM9DS0_MFD_REG_OUT_Z_H_A, &out_h) < 0) {
|
LSM9DS0_MFD_REG_OUT_Z_H_A, &out_h) < 0) {
|
||||||
SYS_LOG_DBG("failed to read accel sample (Z axis)");
|
LOG_DBG("failed to read accel sample (Z axis)");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +279,7 @@ static inline int lsm9ds0_mfd_sample_fetch_magn(struct device *dev)
|
||||||
LSM9DS0_MFD_REG_OUT_X_L_M, &out_l) < 0 ||
|
LSM9DS0_MFD_REG_OUT_X_L_M, &out_l) < 0 ||
|
||||||
i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
LSM9DS0_MFD_REG_OUT_X_H_M, &out_h) < 0) {
|
LSM9DS0_MFD_REG_OUT_X_H_M, &out_h) < 0) {
|
||||||
SYS_LOG_DBG("failed to read magn sample (X axis)");
|
LOG_DBG("failed to read magn sample (X axis)");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,7 +290,7 @@ static inline int lsm9ds0_mfd_sample_fetch_magn(struct device *dev)
|
||||||
LSM9DS0_MFD_REG_OUT_Y_L_M, &out_l) < 0 ||
|
LSM9DS0_MFD_REG_OUT_Y_L_M, &out_l) < 0 ||
|
||||||
i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
LSM9DS0_MFD_REG_OUT_Y_H_M, &out_h) < 0) {
|
LSM9DS0_MFD_REG_OUT_Y_H_M, &out_h) < 0) {
|
||||||
SYS_LOG_DBG("failed to read magn sample (Y axis)");
|
LOG_DBG("failed to read magn sample (Y axis)");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,7 +301,7 @@ static inline int lsm9ds0_mfd_sample_fetch_magn(struct device *dev)
|
||||||
LSM9DS0_MFD_REG_OUT_Z_L_M, &out_l) < 0 ||
|
LSM9DS0_MFD_REG_OUT_Z_L_M, &out_l) < 0 ||
|
||||||
i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
LSM9DS0_MFD_REG_OUT_Z_H_M, &out_h) < 0) {
|
LSM9DS0_MFD_REG_OUT_Z_H_M, &out_h) < 0) {
|
||||||
SYS_LOG_DBG("failed to read magn sample (Z axis)");
|
LOG_DBG("failed to read magn sample (Z axis)");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +327,7 @@ static inline int lsm9ds0_mfd_sample_fetch_temp(struct device *dev)
|
||||||
LSM9DS0_MFD_REG_OUT_TEMP_L_XM, &out_l) < 0 ||
|
LSM9DS0_MFD_REG_OUT_TEMP_L_XM, &out_l) < 0 ||
|
||||||
i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
LSM9DS0_MFD_REG_OUT_TEMP_H_XM, &out_h) < 0) {
|
LSM9DS0_MFD_REG_OUT_TEMP_H_XM, &out_h) < 0) {
|
||||||
SYS_LOG_DBG("failed to read temperature sample\n");
|
LOG_DBG("failed to read temperature sample\n");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -668,22 +671,22 @@ static int lsm9ds0_mfd_init_chip(struct device *dev)
|
||||||
u8_t chip_id;
|
u8_t chip_id;
|
||||||
|
|
||||||
if (lsm9ds0_mfd_reboot_memory(dev) < 0) {
|
if (lsm9ds0_mfd_reboot_memory(dev) < 0) {
|
||||||
SYS_LOG_DBG("failed to reset device");
|
LOG_DBG("failed to reset device");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
if (i2c_reg_read_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
LSM9DS0_MFD_REG_WHO_AM_I_XM, &chip_id) < 0) {
|
LSM9DS0_MFD_REG_WHO_AM_I_XM, &chip_id) < 0) {
|
||||||
SYS_LOG_DBG("failed reading chip id");
|
LOG_DBG("failed reading chip id");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chip_id != LSM9DS0_MFD_VAL_WHO_AM_I_XM) {
|
if (chip_id != LSM9DS0_MFD_VAL_WHO_AM_I_XM) {
|
||||||
SYS_LOG_DBG("invalid chip id 0x%x", chip_id);
|
LOG_DBG("invalid chip id 0x%x", chip_id);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_DBG("chip id 0x%x", chip_id);
|
LOG_DBG("chip id 0x%x", chip_id);
|
||||||
|
|
||||||
#if !defined(LSM9DS0_MFD_ACCEL_DISABLED)
|
#if !defined(LSM9DS0_MFD_ACCEL_DISABLED)
|
||||||
if (i2c_reg_update_byte(data->i2c_master, config->i2c_slave_addr,
|
if (i2c_reg_update_byte(data->i2c_master, config->i2c_slave_addr,
|
||||||
|
@ -693,12 +696,12 @@ static int lsm9ds0_mfd_init_chip(struct device *dev)
|
||||||
(1 << LSM9DS0_MFD_SHIFT_CTRL_REG1_XM_BDU) |
|
(1 << LSM9DS0_MFD_SHIFT_CTRL_REG1_XM_BDU) |
|
||||||
(LSM9DS0_MFD_ACCEL_DEFAULT_AODR <<
|
(LSM9DS0_MFD_ACCEL_DEFAULT_AODR <<
|
||||||
LSM9DS0_MFD_SHIFT_CTRL_REG1_XM_AODR))) {
|
LSM9DS0_MFD_SHIFT_CTRL_REG1_XM_AODR))) {
|
||||||
SYS_LOG_DBG("failed to set AODR and BDU");
|
LOG_DBG("failed to set AODR and BDU");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm9ds0_mfd_accel_set_fs_raw(dev, LSM9DS0_MFD_ACCEL_DEFAULT_FS)) {
|
if (lsm9ds0_mfd_accel_set_fs_raw(dev, LSM9DS0_MFD_ACCEL_DEFAULT_FS)) {
|
||||||
SYS_LOG_DBG("failed to set accelerometer full-scale");
|
LOG_DBG("failed to set accelerometer full-scale");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -713,7 +716,7 @@ static int lsm9ds0_mfd_init_chip(struct device *dev)
|
||||||
LSM9DS0_MFD_SHIFT_CTRL_REG1_XM_AYEN) |
|
LSM9DS0_MFD_SHIFT_CTRL_REG1_XM_AYEN) |
|
||||||
(LSM9DS0_MFD_ACCEL_ENABLE_Z <<
|
(LSM9DS0_MFD_ACCEL_ENABLE_Z <<
|
||||||
LSM9DS0_MFD_SHIFT_CTRL_REG1_XM_AZEN)) < 0) {
|
LSM9DS0_MFD_SHIFT_CTRL_REG1_XM_AZEN)) < 0) {
|
||||||
SYS_LOG_DBG("failed to set accelerometer axis enable bits\n");
|
LOG_DBG("failed to set accelerometer axis enable bits\n");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -723,7 +726,7 @@ static int lsm9ds0_mfd_init_chip(struct device *dev)
|
||||||
LSM9DS0_MFD_MASK_CTRL_REG1_XM_BDU,
|
LSM9DS0_MFD_MASK_CTRL_REG1_XM_BDU,
|
||||||
1 << LSM9DS0_MFD_SHIFT_CTRL_REG1_XM_BDU)
|
1 << LSM9DS0_MFD_SHIFT_CTRL_REG1_XM_BDU)
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_DBG("failed to set BDU\n");
|
LOG_DBG("failed to set BDU\n");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -734,17 +737,17 @@ static int lsm9ds0_mfd_init_chip(struct device *dev)
|
||||||
LSM9DS0_MFD_MASK_CTRL_REG7_XM_MD,
|
LSM9DS0_MFD_MASK_CTRL_REG7_XM_MD,
|
||||||
(0 << LSM9DS0_MFD_SHIFT_CTRL_REG7_XM_MD))
|
(0 << LSM9DS0_MFD_SHIFT_CTRL_REG7_XM_MD))
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_DBG("failed to power on magnetometer");
|
LOG_DBG("failed to power on magnetometer");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm9ds0_mfd_magn_set_odr_raw(dev, LSM9DS0_MFD_MAGN_DEFAULT_M_ODR)) {
|
if (lsm9ds0_mfd_magn_set_odr_raw(dev, LSM9DS0_MFD_MAGN_DEFAULT_M_ODR)) {
|
||||||
SYS_LOG_DBG("failed to set magnetometer sampling rate");
|
LOG_DBG("failed to set magnetometer sampling rate");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm9ds0_mfd_magn_set_fs_raw(dev, LSM9DS0_MFD_MAGN_DEFAULT_FS)) {
|
if (lsm9ds0_mfd_magn_set_fs_raw(dev, LSM9DS0_MFD_MAGN_DEFAULT_FS)) {
|
||||||
SYS_LOG_DBG("failed to set magnetometer full-scale");
|
LOG_DBG("failed to set magnetometer full-scale");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -755,7 +758,7 @@ static int lsm9ds0_mfd_init_chip(struct device *dev)
|
||||||
LSM9DS0_MFD_MASK_CTRL_REG5_XM_TEMP_EN,
|
LSM9DS0_MFD_MASK_CTRL_REG5_XM_TEMP_EN,
|
||||||
1 << LSM9DS0_MFD_SHIFT_CTRL_REG5_XM_TEMP_EN)
|
1 << LSM9DS0_MFD_SHIFT_CTRL_REG5_XM_TEMP_EN)
|
||||||
< 0) {
|
< 0) {
|
||||||
SYS_LOG_DBG("failed to power on temperature sensor");
|
LOG_DBG("failed to power on temperature sensor");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -771,13 +774,13 @@ int lsm9ds0_mfd_init(struct device *dev)
|
||||||
|
|
||||||
data->i2c_master = device_get_binding(config->i2c_master_dev_name);
|
data->i2c_master = device_get_binding(config->i2c_master_dev_name);
|
||||||
if (!data->i2c_master) {
|
if (!data->i2c_master) {
|
||||||
SYS_LOG_DBG("i2c master not found: %s",
|
LOG_DBG("i2c master not found: %s",
|
||||||
config->i2c_master_dev_name);
|
config->i2c_master_dev_name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsm9ds0_mfd_init_chip(dev) < 0) {
|
if (lsm9ds0_mfd_init_chip(dev) < 0) {
|
||||||
SYS_LOG_DBG("failed to initialize chip");
|
LOG_DBG("failed to initialize chip");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -557,7 +557,4 @@ struct lsm9ds0_mfd_data {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "LSM9DS0_MFD"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_LSM9DS0_MFD_LSM9DS0_MFD_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_LSM9DS0_MFD_LSM9DS0_MFD_H_ */
|
||||||
|
|
|
@ -4,8 +4,13 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "max30101.h"
|
#include "max30101.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(MAX30101);
|
||||||
|
|
||||||
static int max30101_sample_fetch(struct device *dev, enum sensor_channel chan)
|
static int max30101_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
{
|
{
|
||||||
struct max30101_data *data = dev->driver_data;
|
struct max30101_data *data = dev->driver_data;
|
||||||
|
@ -19,7 +24,7 @@ static int max30101_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
num_bytes = data->num_channels * MAX30101_BYTES_PER_CHANNEL;
|
num_bytes = data->num_channels * MAX30101_BYTES_PER_CHANNEL;
|
||||||
if (i2c_burst_read(data->i2c, MAX30101_I2C_ADDRESS,
|
if (i2c_burst_read(data->i2c, MAX30101_I2C_ADDRESS,
|
||||||
MAX30101_REG_FIFO_DATA, buffer, num_bytes)) {
|
MAX30101_REG_FIFO_DATA, buffer, num_bytes)) {
|
||||||
SYS_LOG_ERR("Could not fetch sample");
|
LOG_ERR("Could not fetch sample");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +63,7 @@ static int max30101_channel_get(struct device *dev, enum sensor_channel chan,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
SYS_LOG_ERR("Unsupported sensor channel");
|
LOG_ERR("Unsupported sensor channel");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +73,7 @@ static int max30101_channel_get(struct device *dev, enum sensor_channel chan,
|
||||||
*/
|
*/
|
||||||
fifo_chan = data->map[led_chan];
|
fifo_chan = data->map[led_chan];
|
||||||
if (fifo_chan >= MAX30101_MAX_NUM_CHANNELS) {
|
if (fifo_chan >= MAX30101_MAX_NUM_CHANNELS) {
|
||||||
SYS_LOG_ERR("Inactive sensor channel");
|
LOG_ERR("Inactive sensor channel");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,18 +101,18 @@ static int max30101_init(struct device *dev)
|
||||||
/* Get the I2C device */
|
/* Get the I2C device */
|
||||||
data->i2c = device_get_binding(CONFIG_MAX30101_I2C_NAME);
|
data->i2c = device_get_binding(CONFIG_MAX30101_I2C_NAME);
|
||||||
if (!data->i2c) {
|
if (!data->i2c) {
|
||||||
SYS_LOG_ERR("Could not find I2C device");
|
LOG_ERR("Could not find I2C device");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check the part id to make sure this is MAX30101 */
|
/* Check the part id to make sure this is MAX30101 */
|
||||||
if (i2c_reg_read_byte(data->i2c, MAX30101_I2C_ADDRESS,
|
if (i2c_reg_read_byte(data->i2c, MAX30101_I2C_ADDRESS,
|
||||||
MAX30101_REG_PART_ID, &part_id)) {
|
MAX30101_REG_PART_ID, &part_id)) {
|
||||||
SYS_LOG_ERR("Could not get Part ID");
|
LOG_ERR("Could not get Part ID");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
if (part_id != MAX30101_PART_ID) {
|
if (part_id != MAX30101_PART_ID) {
|
||||||
SYS_LOG_ERR("Got Part ID 0x%02x, expected 0x%02x",
|
LOG_ERR("Got Part ID 0x%02x, expected 0x%02x",
|
||||||
part_id, MAX30101_PART_ID);
|
part_id, MAX30101_PART_ID);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +128,7 @@ static int max30101_init(struct device *dev)
|
||||||
do {
|
do {
|
||||||
if (i2c_reg_read_byte(data->i2c, MAX30101_I2C_ADDRESS,
|
if (i2c_reg_read_byte(data->i2c, MAX30101_I2C_ADDRESS,
|
||||||
MAX30101_REG_MODE_CFG, &mode_cfg)) {
|
MAX30101_REG_MODE_CFG, &mode_cfg)) {
|
||||||
SYS_LOG_ERR("Could read mode cfg after reset");
|
LOG_ERR("Could read mode cfg after reset");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
} while (mode_cfg & MAX30101_MODE_CFG_RESET_MASK);
|
} while (mode_cfg & MAX30101_MODE_CFG_RESET_MASK);
|
||||||
|
|
|
@ -8,10 +8,6 @@
|
||||||
#include <i2c.h>
|
#include <i2c.h>
|
||||||
#include <gpio.h>
|
#include <gpio.h>
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "MAX30101"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#define MAX30101_I2C_ADDRESS 0x57
|
#define MAX30101_I2C_ADDRESS 0x57
|
||||||
|
|
||||||
#define MAX30101_REG_INT_STS1 0x00
|
#define MAX30101_REG_INT_STS1 0x00
|
||||||
|
|
|
@ -8,10 +8,15 @@
|
||||||
#include <i2c.h>
|
#include <i2c.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "max44009.h"
|
#include "max44009.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(MAX44009);
|
||||||
|
|
||||||
static int max44009_reg_read(struct max44009_data *drv_data, u8_t reg,
|
static int max44009_reg_read(struct max44009_data *drv_data, u8_t reg,
|
||||||
|
|
||||||
u8_t *val, bool send_stop)
|
u8_t *val, bool send_stop)
|
||||||
{
|
{
|
||||||
struct i2c_msg msgs[2] = {
|
struct i2c_msg msgs[2] = {
|
||||||
|
@ -92,7 +97,7 @@ static int max44009_attr_set(struct device *dev, enum sensor_channel chan,
|
||||||
if (max44009_reg_update(drv_data, MAX44009_REG_CONFIG,
|
if (max44009_reg_update(drv_data, MAX44009_REG_CONFIG,
|
||||||
MAX44009_SAMPLING_CONTROL_BIT,
|
MAX44009_SAMPLING_CONTROL_BIT,
|
||||||
value) != 0) {
|
value) != 0) {
|
||||||
SYS_LOG_DBG("Failed to set attribute!");
|
LOG_DBG("Failed to set attribute!");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +174,7 @@ int max44009_init(struct device *dev)
|
||||||
|
|
||||||
drv_data->i2c = device_get_binding(CONFIG_MAX44009_I2C_DEV_NAME);
|
drv_data->i2c = device_get_binding(CONFIG_MAX44009_I2C_DEV_NAME);
|
||||||
if (drv_data->i2c == NULL) {
|
if (drv_data->i2c == NULL) {
|
||||||
SYS_LOG_DBG("Failed to get pointer to %s device!",
|
LOG_DBG("Failed to get pointer to %s device!",
|
||||||
CONFIG_MAX44009_I2C_DEV_NAME);
|
CONFIG_MAX44009_I2C_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,6 @@
|
||||||
|
|
||||||
#include <misc/util.h>
|
#include <misc/util.h>
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "MAX44009"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#define MAX44009_I2C_ADDRESS CONFIG_MAX44009_I2C_ADDR
|
#define MAX44009_I2C_ADDRESS CONFIG_MAX44009_I2C_ADDR
|
||||||
|
|
||||||
#define MAX44009_SAMPLING_CONTROL_BIT BIT(7)
|
#define MAX44009_SAMPLING_CONTROL_BIT BIT(7)
|
||||||
|
|
|
@ -13,9 +13,12 @@
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
#include <misc/__assert.h>
|
#include <misc/__assert.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "mcp9808.h"
|
#include "mcp9808.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(MCP9808);
|
||||||
|
|
||||||
int mcp9808_reg_read(struct mcp9808_data *data, u8_t reg, u16_t *val)
|
int mcp9808_reg_read(struct mcp9808_data *data, u8_t reg, u16_t *val)
|
||||||
{
|
{
|
||||||
|
@ -83,7 +86,7 @@ int mcp9808_init(struct device *dev)
|
||||||
|
|
||||||
data->i2c_master = device_get_binding(CONFIG_MCP9808_I2C_DEV_NAME);
|
data->i2c_master = device_get_binding(CONFIG_MCP9808_I2C_DEV_NAME);
|
||||||
if (!data->i2c_master) {
|
if (!data->i2c_master) {
|
||||||
SYS_LOG_DBG("mcp9808: i2c master not found: %s",
|
LOG_DBG("mcp9808: i2c master not found: %s",
|
||||||
CONFIG_MCP9808_I2C_DEV_NAME);
|
CONFIG_MCP9808_I2C_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,4 @@ static void mcp9808_setup_interrupt(struct device *dev)
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_MCP9808_TRIGGER */
|
#endif /* CONFIG_MCP9808_TRIGGER */
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "MCP9808"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#endif /* ZEPHYR_DRIVERS_SENSOR_MCP9808_MCP9808_H_ */
|
#endif /* ZEPHYR_DRIVERS_SENSOR_MCP9808_MCP9808_H_ */
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
|
|
||||||
#include "mcp9808.h"
|
#include "mcp9808.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(MCP9808);
|
||||||
|
|
||||||
static int mcp9808_reg_write(struct mcp9808_data *data, u8_t reg, u16_t val)
|
static int mcp9808_reg_write(struct mcp9808_data *data, u8_t reg, u16_t val)
|
||||||
{
|
{
|
||||||
u16_t be_val = sys_cpu_to_be16(val);
|
u16_t be_val = sys_cpu_to_be16(val);
|
||||||
|
|
|
@ -10,9 +10,13 @@
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <misc/util.h>
|
#include <misc/util.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "mma8451q.h"
|
#include "mma8451q.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(MMA8451Q);
|
||||||
|
|
||||||
/* Data-sheet: https://www.nxp.com/docs/en/data-sheet/MMA8451Q.pdf */
|
/* Data-sheet: https://www.nxp.com/docs/en/data-sheet/MMA8451Q.pdf */
|
||||||
|
|
||||||
static int mma8451q_sample_fetch(struct device *dev, enum sensor_channel chan)
|
static int mma8451q_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
|
@ -25,7 +29,7 @@ static int mma8451q_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
/* Read data from all three axes at the same time. */
|
/* Read data from all three axes at the same time. */
|
||||||
if (i2c_burst_read(data->i2c, config->i2c_address,
|
if (i2c_burst_read(data->i2c, config->i2c_address,
|
||||||
MMA8451Q_OUT_X_MSB, buf, 6) < 0) {
|
MMA8451Q_OUT_X_MSB, buf, 6) < 0) {
|
||||||
SYS_LOG_ERR("Could not read accelerometer data");
|
LOG_ERR("Could not read accelerometer data");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +112,7 @@ int mma8451q_init(struct device *dev)
|
||||||
|
|
||||||
data->i2c = device_get_binding(config->i2c_name);
|
data->i2c = device_get_binding(config->i2c_name);
|
||||||
if (data->i2c == NULL) {
|
if (data->i2c == NULL) {
|
||||||
SYS_LOG_ERR("Failed to get pointer to %s device!",
|
LOG_ERR("Failed to get pointer to %s device!",
|
||||||
config->i2c_name);
|
config->i2c_name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -117,47 +121,47 @@ int mma8451q_init(struct device *dev)
|
||||||
|
|
||||||
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
||||||
MMA8451Q_REG_WHOAMI, &whoami)) {
|
MMA8451Q_REG_WHOAMI, &whoami)) {
|
||||||
SYS_LOG_ERR("Could not get WHOAMI value");
|
LOG_ERR("Could not get WHOAMI value");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (whoami != config->whoami) {
|
if (whoami != config->whoami) {
|
||||||
SYS_LOG_ERR("WHOAMI value received 0x%x, expected 0x%x",
|
LOG_ERR("WHOAMI value received 0x%x, expected 0x%x",
|
||||||
whoami, MMA8451Q_REG_WHOAMI);
|
whoami, MMA8451Q_REG_WHOAMI);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
||||||
MMA8451Q_CTRL_REG1, 0) < 0) {
|
MMA8451Q_CTRL_REG1, 0) < 0) {
|
||||||
SYS_LOG_ERR("Could not set accel in config mode");
|
LOG_ERR("Could not set accel in config mode");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
||||||
MMA8451Q_XYZ_DATA_CFG, config->range) < 0) {
|
MMA8451Q_XYZ_DATA_CFG, config->range) < 0) {
|
||||||
SYS_LOG_ERR("Could not set range");
|
LOG_ERR("Could not set range");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
||||||
MMA8451Q_CTRL_REG2, 0) < 0) {
|
MMA8451Q_CTRL_REG2, 0) < 0) {
|
||||||
SYS_LOG_ERR("Could not set to normal mode");
|
LOG_ERR("Could not set to normal mode");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
||||||
MMA8451Q_CTRL_REG3, 0) < 0) {
|
MMA8451Q_CTRL_REG3, 0) < 0) {
|
||||||
SYS_LOG_ERR("Could not set to low polarity, push-pull output");
|
LOG_ERR("Could not set to low polarity, push-pull output");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
||||||
MMA8451Q_CTRL_REG1, 0x09) < 0) {
|
MMA8451Q_CTRL_REG1, 0x09) < 0) {
|
||||||
SYS_LOG_ERR("Could not set data rate to 800Hz");
|
LOG_ERR("Could not set data rate to 800Hz");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_DBG("Init complete");
|
LOG_DBG("Init complete");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,8 +52,4 @@ struct mma8451q_data {
|
||||||
s16_t z;
|
s16_t z;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "MMA8451Q"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#endif /* _SENSOR_MMA8451Q_ */
|
#endif /* _SENSOR_MMA8451Q_ */
|
||||||
|
|
|
@ -8,9 +8,13 @@
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include "mpu6050.h"
|
#include "mpu6050.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
LOG_MODULE_REGISTER(MPU6050);
|
||||||
|
|
||||||
/* see "Accelerometer Measurements" section from register map description */
|
/* see "Accelerometer Measurements" section from register map description */
|
||||||
static void mpu6050_convert_accel(struct sensor_value *val, s16_t raw_val,
|
static void mpu6050_convert_accel(struct sensor_value *val, s16_t raw_val,
|
||||||
u16_t sensitivity_shift)
|
u16_t sensitivity_shift)
|
||||||
|
@ -111,7 +115,7 @@ static int mpu6050_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
|
|
||||||
if (i2c_burst_read(drv_data->i2c, CONFIG_MPU6050_I2C_ADDR,
|
if (i2c_burst_read(drv_data->i2c, CONFIG_MPU6050_I2C_ADDR,
|
||||||
MPU6050_REG_DATA_START, (u8_t *)buf, 14) < 0) {
|
MPU6050_REG_DATA_START, (u8_t *)buf, 14) < 0) {
|
||||||
SYS_LOG_ERR("Failed to read data sample.");
|
LOG_ERR("Failed to read data sample.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +145,7 @@ int mpu6050_init(struct device *dev)
|
||||||
|
|
||||||
drv_data->i2c = device_get_binding(CONFIG_MPU6050_I2C_MASTER_DEV_NAME);
|
drv_data->i2c = device_get_binding(CONFIG_MPU6050_I2C_MASTER_DEV_NAME);
|
||||||
if (drv_data->i2c == NULL) {
|
if (drv_data->i2c == NULL) {
|
||||||
SYS_LOG_ERR("Failed to get pointer to %s device",
|
LOG_ERR("Failed to get pointer to %s device",
|
||||||
CONFIG_MPU6050_I2C_MASTER_DEV_NAME);
|
CONFIG_MPU6050_I2C_MASTER_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -149,12 +153,12 @@ int mpu6050_init(struct device *dev)
|
||||||
/* check chip ID */
|
/* check chip ID */
|
||||||
if (i2c_reg_read_byte(drv_data->i2c, CONFIG_MPU6050_I2C_ADDR,
|
if (i2c_reg_read_byte(drv_data->i2c, CONFIG_MPU6050_I2C_ADDR,
|
||||||
MPU6050_REG_CHIP_ID, &id) < 0) {
|
MPU6050_REG_CHIP_ID, &id) < 0) {
|
||||||
SYS_LOG_ERR("Failed to read chip ID.");
|
LOG_ERR("Failed to read chip ID.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id != MPU6050_CHIP_ID) {
|
if (id != MPU6050_CHIP_ID) {
|
||||||
SYS_LOG_ERR("Invalid chip ID.");
|
LOG_ERR("Invalid chip ID.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +166,7 @@ int mpu6050_init(struct device *dev)
|
||||||
if (i2c_reg_update_byte(drv_data->i2c, CONFIG_MPU6050_I2C_ADDR,
|
if (i2c_reg_update_byte(drv_data->i2c, CONFIG_MPU6050_I2C_ADDR,
|
||||||
MPU6050_REG_PWR_MGMT1, MPU6050_SLEEP_EN,
|
MPU6050_REG_PWR_MGMT1, MPU6050_SLEEP_EN,
|
||||||
0) < 0) {
|
0) < 0) {
|
||||||
SYS_LOG_ERR("Failed to wake up chip.");
|
LOG_ERR("Failed to wake up chip.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,14 +178,14 @@ int mpu6050_init(struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == 4) {
|
if (i == 4) {
|
||||||
SYS_LOG_ERR("Invalid value for accel full-scale range.");
|
LOG_ERR("Invalid value for accel full-scale range.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, CONFIG_MPU6050_I2C_ADDR,
|
if (i2c_reg_write_byte(drv_data->i2c, CONFIG_MPU6050_I2C_ADDR,
|
||||||
MPU6050_REG_ACCEL_CFG,
|
MPU6050_REG_ACCEL_CFG,
|
||||||
i << MPU6050_ACCEL_FS_SHIFT) < 0) {
|
i << MPU6050_ACCEL_FS_SHIFT) < 0) {
|
||||||
SYS_LOG_ERR("Failed to write accel full-scale range.");
|
LOG_ERR("Failed to write accel full-scale range.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,14 +199,14 @@ int mpu6050_init(struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == 4) {
|
if (i == 4) {
|
||||||
SYS_LOG_ERR("Invalid value for gyro full-scale range.");
|
LOG_ERR("Invalid value for gyro full-scale range.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, CONFIG_MPU6050_I2C_ADDR,
|
if (i2c_reg_write_byte(drv_data->i2c, CONFIG_MPU6050_I2C_ADDR,
|
||||||
MPU6050_REG_GYRO_CFG,
|
MPU6050_REG_GYRO_CFG,
|
||||||
i << MPU6050_GYRO_FS_SHIFT) < 0) {
|
i << MPU6050_GYRO_FS_SHIFT) < 0) {
|
||||||
SYS_LOG_ERR("Failed to write gyro full-scale range.");
|
LOG_ERR("Failed to write gyro full-scale range.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +214,7 @@ int mpu6050_init(struct device *dev)
|
||||||
|
|
||||||
#ifdef CONFIG_MPU6050_TRIGGER
|
#ifdef CONFIG_MPU6050_TRIGGER
|
||||||
if (mpu6050_init_interrupt(dev) < 0) {
|
if (mpu6050_init_interrupt(dev) < 0) {
|
||||||
SYS_LOG_DBG("Failed to initialize interrupts.");
|
LOG_DBG("Failed to initialize interrupts.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,10 +12,6 @@
|
||||||
#include <misc/util.h>
|
#include <misc/util.h>
|
||||||
#include <zephyr/types.h>
|
#include <zephyr/types.h>
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "MPU6050"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#define MPU6050_REG_CHIP_ID 0x75
|
#define MPU6050_REG_CHIP_ID 0x75
|
||||||
#define MPU6050_CHIP_ID 0x68
|
#define MPU6050_CHIP_ID 0x68
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,10 @@
|
||||||
|
|
||||||
#include "mpu6050.h"
|
#include "mpu6050.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(MPU6050);
|
||||||
|
|
||||||
int mpu6050_trigger_set(struct device *dev,
|
int mpu6050_trigger_set(struct device *dev,
|
||||||
const struct sensor_trigger *trig,
|
const struct sensor_trigger *trig,
|
||||||
sensor_trigger_handler_t handler)
|
sensor_trigger_handler_t handler)
|
||||||
|
@ -98,7 +102,7 @@ int mpu6050_init_interrupt(struct device *dev)
|
||||||
/* setup data ready gpio interrupt */
|
/* setup data ready gpio interrupt */
|
||||||
drv_data->gpio = device_get_binding(CONFIG_MPU6050_GPIO_DEV_NAME);
|
drv_data->gpio = device_get_binding(CONFIG_MPU6050_GPIO_DEV_NAME);
|
||||||
if (drv_data->gpio == NULL) {
|
if (drv_data->gpio == NULL) {
|
||||||
SYS_LOG_ERR("Failed to get pointer to %s device",
|
LOG_ERR("Failed to get pointer to %s device",
|
||||||
CONFIG_MPU6050_GPIO_DEV_NAME);
|
CONFIG_MPU6050_GPIO_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -112,14 +116,14 @@ int mpu6050_init_interrupt(struct device *dev)
|
||||||
BIT(CONFIG_MPU6050_GPIO_PIN_NUM));
|
BIT(CONFIG_MPU6050_GPIO_PIN_NUM));
|
||||||
|
|
||||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||||
SYS_LOG_ERR("Failed to set gpio callback");
|
LOG_ERR("Failed to set gpio callback");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* enable data ready interrupt */
|
/* enable data ready interrupt */
|
||||||
if (i2c_reg_write_byte(drv_data->i2c, CONFIG_MPU6050_I2C_ADDR,
|
if (i2c_reg_write_byte(drv_data->i2c, CONFIG_MPU6050_I2C_ADDR,
|
||||||
MPU6050_REG_INT_EN, MPU6050_DRDY_EN) < 0) {
|
MPU6050_REG_INT_EN, MPU6050_DRDY_EN) < 0) {
|
||||||
SYS_LOG_ERR("Failed to enable data ready interrupt.");
|
LOG_ERR("Failed to enable data ready interrupt.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
|
|
||||||
#include "ms5837.h"
|
#include "ms5837.h"
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_REGISTER(MS5837);
|
||||||
|
|
||||||
static int ms5837_get_measurement(struct device *i2c_master,
|
static int ms5837_get_measurement(struct device *i2c_master,
|
||||||
const u8_t i2c_address, u32_t *val,
|
const u8_t i2c_address, u32_t *val,
|
||||||
u8_t cmd, const u8_t delay)
|
u8_t cmd, const u8_t delay)
|
||||||
|
@ -187,7 +191,7 @@ static int ms5837_attr_set(struct device *dev, enum sensor_channel chan,
|
||||||
conv_delay = 1;
|
conv_delay = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SYS_LOG_ERR("invalid oversampling rate %d", val->val1);
|
LOG_ERR("invalid oversampling rate %d", val->val1);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,7 +259,7 @@ static int ms5837_init(struct device *dev)
|
||||||
|
|
||||||
data->i2c_master = device_get_binding(cfg->i2c_name);
|
data->i2c_master = device_get_binding(cfg->i2c_name);
|
||||||
if (data->i2c_master == NULL) {
|
if (data->i2c_master == NULL) {
|
||||||
SYS_LOG_ERR("i2c master %s not found",
|
LOG_ERR("i2c master %s not found",
|
||||||
CONFIG_MS5837_I2C_MASTER_DEV_NAME);
|
CONFIG_MS5837_I2C_MASTER_DEV_NAME);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,8 +77,4 @@ struct ms5837_config {
|
||||||
u8_t i2c_address;
|
u8_t i2c_address;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "MS5837"
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#endif /* __SENSOR_MS5837_H__ */
|
#endif /* __SENSOR_MS5837_H__ */
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
#include <clock_control.h>
|
#include <clock_control.h>
|
||||||
|
#include <logging/log.h>
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "TEMPNRF5"
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
LOG_MODULE_REGISTER(TEMPNRF5);
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#include "nrf.h"
|
#include "nrf.h"
|
||||||
#include "nrf_common.h"
|
#include "nrf_common.h"
|
||||||
|
@ -34,7 +34,7 @@ static int temp_nrf5_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
struct temp_nrf5_data *data = dev->driver_data;
|
struct temp_nrf5_data *data = dev->driver_data;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
SYS_LOG_DBG("");
|
LOG_DBG("");
|
||||||
|
|
||||||
if (chan != SENSOR_CHAN_ALL && chan != SENSOR_CHAN_DIE_TEMP) {
|
if (chan != SENSOR_CHAN_ALL && chan != SENSOR_CHAN_DIE_TEMP) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
|
@ -67,7 +67,7 @@ static int temp_nrf5_channel_get(struct device *dev,
|
||||||
struct temp_nrf5_data *data = dev->driver_data;
|
struct temp_nrf5_data *data = dev->driver_data;
|
||||||
s32_t uval;
|
s32_t uval;
|
||||||
|
|
||||||
SYS_LOG_DBG("");
|
LOG_DBG("");
|
||||||
|
|
||||||
if (chan != SENSOR_CHAN_DIE_TEMP) {
|
if (chan != SENSOR_CHAN_DIE_TEMP) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
|
@ -109,7 +109,7 @@ static int temp_nrf5_init(struct device *dev)
|
||||||
volatile NRF_TEMP_Type *temp = NRF_TEMP;
|
volatile NRF_TEMP_Type *temp = NRF_TEMP;
|
||||||
struct temp_nrf5_data *data = dev->driver_data;
|
struct temp_nrf5_data *data = dev->driver_data;
|
||||||
|
|
||||||
SYS_LOG_DBG("");
|
LOG_DBG("");
|
||||||
|
|
||||||
data->clk_m16_dev =
|
data->clk_m16_dev =
|
||||||
device_get_binding(CONFIG_CLOCK_CONTROL_NRF5_M16SRC_DRV_NAME);
|
device_get_binding(CONFIG_CLOCK_CONTROL_NRF5_M16SRC_DRV_NAME);
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue