drivers/sensors: Add driver for ST HTS221 humidity sensor

This commit is contained in:
Juha Niskanen 2017-03-30 09:34:03 -06:00 committed by Gregory Nutt
parent 332c747bca
commit 9e2b3da3e8
6 changed files with 1327 additions and 1 deletions

View File

@ -32,6 +32,29 @@ config BMP180
---help---
Enable driver support for the Bosch BMP180 barometer sensor.
config HTS221
bool "ST HTS221 humidity sensor"
default n
select I2C
---help---
Enable driver support for the ST HTS221 humidity sensor.
if HTS221
config DEBUG_HTS221
bool "Debug support for the HTS221"
default n
---help---
Enables debug features for the HTS221
config HTS221_NPOLLWAITERS
int "Number of waiters to poll"
default 1
---help---
Number of waiters to poll
endif # HTS221
config SENSORS_L3GD20
bool "ST L3GD20 Gyroscope Sensor support"
default n

View File

@ -81,6 +81,10 @@ ifeq ($(CONFIG_BMP180),y)
CSRCS += bmp180.c
endif
ifeq ($(CONFIG_HTS221),y)
CSRCS += hts221.c
endif
ifeq ($(CONFIG_I2C_LM75),y)
CSRCS += lm75.c
endif

1131
drivers/sensors/hts221.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -65,7 +65,7 @@
#ifndef CONFIG_CRYPTO_RANDOM_POOL
# define up_rngaddint(k, x) ((void)(k),(void)(x))
# define up_rngaddentropy(k, buf, n) ((void)(k),(void)(buf),(void)(x))
# define up_rngaddentropy(k, buf, x) ((void)(k),(void)(buf),(void)(x))
#endif
/****************************************************************************

View File

@ -0,0 +1,158 @@
/****************************************************************************
* include/nuttx/sensors/hts221.h
*
* Copyright (C) 2014 Haltian Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_NUTT_SENSORS_HTS221_H
#define __INCLUDE_NUTT_SENSORS_HTS221_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/sensors/ioctl.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define HTS221_TEMPERATURE_PRECISION 100
#define HTS221_HUMIDITY_PRECISION 10
/****************************************************************************
* Public Types
****************************************************************************/
/* Number of temperature samples */
typedef enum hts221_avrg_temp_e
{
HTS221_AVGT2 = 0,
HTS221_AVGT4,
HTS221_AVGT8,
HTS221_AVGT16, /* Default value */
HTS221_AVGT32,
HTS221_AVGT64,
HTS221_AVGT128,
HTS221_AVGT256
} hts221_avrg_temp_t;
/* Number of humidity samples */
typedef enum hts221_avrg_humid_e
{
HTS221_AVGH4 = 0,
HTS221_AVGH8,
HTS221_AVGH16,
HTS221_AVGH32, /* Default value */
HTS221_AVGH64,
HTS221_AVGH128,
HTS221_AVGH256,
HTS221_AVGH512
}hts221_avrg_humid_t;
/* Output data rate configuration */
typedef enum hts221_odr_e
{
HTS221_ODR_ONESHOT = 0,
HTS221_ODR_1HZ,
HTS221_ODR_7HZ,
HTS221_ODR_12_5HZ
} hts221_odr_t;
/* Configuration structure */
typedef struct hts221_settings_s
{
hts221_avrg_temp_t temp_resol; /* Temperature resolution. The more
* samples sensor takes, the more power
* it uses */
hts221_avrg_humid_t humid_resol; /* Humidity resolution. The more
* samples sensor takes, the more power
* it uses */
hts221_odr_t odr; /* Output data rate */
bool is_bdu; /* If read operation is not faster than output
* operation, then this variable must be set to true */
bool is_data_rdy; /* Must be set to true, if interrupt needed.
* Default is 0, disabled */
bool is_high_edge; /* High or low interrupt signal from device.
* Default is high, 0 */
bool is_open_drain; /* Open drain or push-pull on data-ready pin.
* Default is push-pull, 0 */
bool is_boot; /* Refresh the content of the internal registers */
} hts221_settings_t;
/* Interrupt configuration data structure */
typedef struct hts221_config_s
{
int irq;
CODE int (*irq_attach)(FAR struct hts221_config_s * state, xcpt_t isr);
CODE void (*irq_enable)(FAR const struct hts221_config_s * state,
bool enable);
CODE void (*irq_clear)(FAR const struct hts221_config_s * state);
CODE int (*set_power)(FAR const struct hts221_config_s *state, bool on);
} hts221_config_t;
/* Raw data structure */
typedef struct hts221_raw_data_s
{
uint8_t humid_low_bits;
uint8_t humid_high_bits;
uint8_t temp_low_bits;
uint8_t temp_high_bits;
} hts221_raw_data_t;
typedef struct hts221_conv_data_s
{
int temperature;
unsigned int humidity;
} hts221_conv_data_t;
/* Status register data */
typedef struct hts221_status_s
{
bool is_humid_ready;
bool is_temp_ready;
} hts221_status_t;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
int hts221_register(FAR const char *devpath, FAR struct i2c_master_s *i2c,
uint8_t addr, hts221_config_t * config);
#endif /* __INCLUDE_NUTT_SENSORS_HTS221_H */

View File

@ -115,4 +115,14 @@
#define SNIOC_RESET _SNIOC(0x0028) /* Arg: None */
#define SNIOC_OVERSAMPLING _SNIOC(0x0029) /* Arg: uint16_t value */
/* IOCTL commands unique to the HTS221 */
#define SNIOC_GET_DEV_ID _SNIOC(0x002a)
#define SNIOC_CFGR _SNIOC(0x002b)
#define SNIOC_START_CONVERSION _SNIOC(0x002c)
#define SNIOC_CHECK_STATUS_REG _SNIOC(0x002d)
#define SNIOC_READ_RAW_DATA _SNIOC(0x002e)
#define SNIOC_READ_CONVERT_DATA _SNIOC(0x002f)
#define SNIOC_DUMP_REGS _SNIOC(0x0030)
#endif /* __INCLUDE_NUTTX_SENSORS_IOCTL_H */