Browse Source
- cleaned up interface - made read functions return phyical values - made resolution configurable at initialization time - added default parameter configuration file - added SAUL support for the driverpr/spi.typo

7 changed files with 353 additions and 192 deletions
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Freie Universität Berlin |
||||
* |
||||
* This file is subject to the terms and conditions of the GNU Lesser |
||||
* General Public License v2.1. See the file LICENSE in the top level |
||||
* directory for more details. |
||||
*/ |
||||
|
||||
/**
|
||||
* @ingroup driver_hdc1000 |
||||
* @{ |
||||
* |
||||
* @file |
||||
* @brief HDC1000 adaption to the RIOT actuator/sensor interface |
||||
* |
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de> |
||||
* |
||||
* @} |
||||
*/ |
||||
|
||||
#include <string.h> |
||||
|
||||
#include "saul.h" |
||||
#include "hdc1000.h" |
||||
|
||||
static int read_temp(void *dev, phydat_t *res) |
||||
{ |
||||
hdc1000_t *d = (hdc1000_t *)dev; |
||||
|
||||
hdc1000_read(d, &(res->val[0]), NULL); |
||||
memset(&(res->val[1]), 0, 2 * sizeof(int16_t)); |
||||
res->unit = UNIT_TEMP_C; |
||||
res->scale = -2; |
||||
|
||||
return 1; |
||||
} |
||||
|
||||
static int read_hum(void *dev, phydat_t *res) |
||||
{ |
||||
hdc1000_t *d = (hdc1000_t *)dev; |
||||
|
||||
hdc1000_read(d, NULL, &(res->val[0])); |
||||
memset(&(res->val[1]), 0, 2 * sizeof(int16_t)); |
||||
res->unit = UNIT_PERCENT; |
||||
res->scale = -2; |
||||
|
||||
return 1; |
||||
} |
||||
|
||||
const saul_driver_t hdc1000_saul_temp_driver = { |
||||
.read = read_temp, |
||||
.write = saul_notsup, |
||||
.type = SAUL_SENSE_TEMP, |
||||
}; |
||||
|
||||
const saul_driver_t hdc1000_saul_hum_driver = { |
||||
.read = read_hum, |
||||
.write = saul_notsup, |
||||
.type = SAUL_SENSE_HUM, |
||||
}; |
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Freie Universität Berlin |
||||
* |
||||
* This file is subject to the terms and conditions of the GNU Lesser |
||||
* General Public License v2.1. See the file LICENSE in the top level |
||||
* directory for more details. |
||||
*/ |
||||
|
||||
/**
|
||||
* @ingroup drivers_hdc1000 |
||||
* |
||||
* @{ |
||||
* @file |
||||
* @brief Default configuration for HDC1000 devices |
||||
* |
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de> |
||||
*/ |
||||
|
||||
#ifndef HDC1000_PARAMS_H |
||||
#define HDC1000_PARAMS_H |
||||
|
||||
#include "board.h" |
||||
#include "hdc1000.h" |
||||
#include "saul_reg.h" |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Set default configuration parameters for the HDC1000 driver |
||||
* @{ |
||||
*/ |
||||
#ifndef HDC1000_PARAM_I2C |
||||
#define HDC1000_PARAM_I2C I2C_DEV(0) |
||||
#endif |
||||
#ifndef HDC1000_PARAM_ADDR |
||||
#define HDC1000_PARAM_ADDR (HDC1000_I2C_ADDRESS) |
||||
#endif |
||||
#ifndef HDC1000_PARAM_RES |
||||
#define HDC1000_PARAM_RES HDC1000_14BIT |
||||
#endif |
||||
|
||||
#define HDC1000_PARAMS_DEFAULT { .i2c = HDC1000_PARAM_I2C, \ |
||||
.addr = HDC1000_PARAM_ADDR, \
|
||||
.res = HDC1000_PARAM_RES } |
||||
/**@}*/ |
||||
|
||||
/**
|
||||
* @brief HDC1000 configuration |
||||
*/ |
||||
static const hdc1000_params_t hdc1000_params[] = |
||||
{ |
||||
#ifdef HDC1000_PARAMS_BOARD |
||||
HDC1000_PARAMS_BOARD, |
||||
#else |
||||
HDC1000_PARAMS_DEFAULT, |
||||
#endif |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Additional meta information to keep in the SAUL registry |
||||
*/ |
||||
static const saul_reg_info_t hdc1000_saul_info[] = |
||||
{ |
||||
{ |
||||
.name = "hdc1000", |
||||
}, |
||||
}; |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* HDC1000_PARAMS_H */ |
||||
/** @} */ |
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2014 PHYTEC Messtechnik GmbH |
||||
* 2017 Freie Universität Berlin |
||||
* |
||||
* This file is subject to the terms and conditions of the GNU Lesser |
||||
* General Public License v2.1. See the file LICENSE in the top level |
||||
* directory for more details. |
||||
*/ |
||||
|
||||
/**
|
||||
* @ingroup drivers_hdc1000 |
||||
* @{ |
||||
* |
||||
* @file |
||||
* @brief Register definitions for HDC1000 devices |
||||
* |
||||
* @author Johann Fischer <j.fischer@phytec.de> |
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de> |
||||
*/ |
||||
|
||||
#ifndef HDC1000_REGS_H_ |
||||
#define HDC1000_REGS_H_ |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" |
||||
{ |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Manufacturer and Device IDs |
||||
* @{ |
||||
*/ |
||||
#define HDC1000_MID_VALUE 0x5449 |
||||
#define HDC1000_DID_VALUE 0x1000 |
||||
/** @} */ |
||||
|
||||
/**
|
||||
* @brief Register Map |
||||
* @{ |
||||
*/ |
||||
#define HDC1000_TEMPERATURE (0x00) |
||||
#define HDC1000_HUMIDITY (0x01) |
||||
#define HDC1000_CONFIG (0x02) |
||||
#define HDC1000_SID1 (0xFB) |
||||
#define HDC1000_SID2 (0xFC) |
||||
#define HDC1000_SID3 (0xFD) |
||||
#define HDC1000_MANUFACTURER_ID (0xFE) |
||||
#define HDC1000_DEVICE_ID (0xFF) |
||||
/** @} */ |
||||
|
||||
/**
|
||||
* @brief Configuration register bitmap |
||||
* @{ |
||||
*/ |
||||
#define HDC1000_RST (1 << 15) |
||||
#define HDC1000_HEAT (1 << 13) |
||||
#define HDC1000_SEQ_MOD (1 << 12) |
||||
#define HDC1000_BTST_LOW (1 << 11) |
||||
#define HDC1000_TRES_MSK (1 << 10) |
||||
#define HDC1000_TRES11 (1 << 10) |
||||
#define HDC1000_TRES14 (0) |
||||
#define HDC1000_HRES_MSK (1 << 9 | 1 << 8) |
||||
#define HDC1000_HRES14 (0) |
||||
#define HDC1000_HRES11 (1 << 8) |
||||
#define HDC1000_HRES8 (1 << 9) |
||||
/** @} */ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* HDC1000_REGS_H_ */ |
||||
/** @} */ |
Loading…
Reference in new issue