drivers/sensors: Add driver for ST LPS25H pressure sensor

This commit is contained in:
Juha Niskanen
2017-03-31 05:53:43 -06:00
committed by Gregory Nutt
parent 916bd8a48f
commit b5b148fef8
6 changed files with 951 additions and 24 deletions
+24 -7
View File
@@ -33,11 +33,11 @@ config BMP180
Enable driver support for the Bosch BMP180 barometer sensor.
config HTS221
bool "ST HTS221 humidity sensor"
bool "STMicro HTS221 humidity sensor"
default n
select I2C
---help---
Enable driver support for the ST HTS221 humidity sensor.
Enable driver support for the STMicro HTS221 humidity sensor.
if HTS221
@@ -56,11 +56,11 @@ config HTS221_NPOLLWAITERS
endif # HTS221
config SENSORS_L3GD20
bool "ST L3GD20 Gyroscope Sensor support"
bool "STMicro L3GD20 Gyroscope Sensor support"
default n
select SPI
---help---
Enable driver support for the ST L3GD20 gyroscope sensor.
Enable driver support for the STMicro L3GD20 gyroscope sensor.
config SENSOR_KXTJ9
bool "Kionix KXTJ9 Accelerometer support"
@@ -83,7 +83,7 @@ config LIS3DSH
Enable driver support for the STMicro LIS3DSH 3-Axis acclerometer.
config LIS331DL
bool "ST LIS331DL device support"
bool "STMicro LIS331DL device support"
default n
select I2C
@@ -106,6 +106,23 @@ config LSM9DS1_I2C_FREQUENCY
range 1 400000
depends on SN_LSM9DS1
config LPS25H
bool "STMicro LPS25H pressure sensor"
default n
select I2C
---help---
Enable driver support for the STMicro LPS25H barometer sensor.
if LPS25H
config DEBUG_LPS25H
bool "Debug support for the LPS25H"
default n
---help---
Enables debug features for the LPS25H
endif # LPS25H
config MB7040
bool "MaxBotix MB7040 Sonar support"
default n
@@ -209,7 +226,7 @@ endif # SENSORS_ADXL345
config MAX31855
bool "Maxim MAX31855 Driver"
default n
select SPI
select SPI
---help---
Enables support for the MAX31855 driver
@@ -229,7 +246,7 @@ config LIS3MDL
default n
select SPI
---help---
Enable driver support for the ST LIS3MDL 3-axis magnetometer.
Enable driver support for the STMicro LIS3MDL 3-axis magnetometer.
config LM75
bool "STMicro LM-75 Temperature Sensor support"
+5 -1
View File
@@ -1,7 +1,7 @@
############################################################################
# drivers/sensors/Make.defs
#
# Copyright (C) 2011-2012, 2015-2016 Gregory Nutt. All rights reserved.
# Copyright (C) 2011-2012, 2015-2017 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -65,6 +65,10 @@ ifeq ($(CONFIG_SN_LSM9DS1),y)
CSRCS += lsm9ds1.c
endif
ifeq ($(CONFIG_LPS25H),y)
CSRCS += lps25h.c
endif
ifeq ($(CONFIG_ADXL345_I2C),y)
CSRCS += adxl345_i2c.c
endif
+16 -16
View File
@@ -178,7 +178,7 @@ static const struct file_operations g_humidityops =
* Private Functions
****************************************************************************/
static int hts221_do_transfer(FAR struct hts221_dev_s *dev,
static int hts221_do_transfer(FAR struct hts221_dev_s *priv,
FAR struct i2c_msg_s *msgv,
size_t nmsg)
{
@@ -187,7 +187,7 @@ static int hts221_do_transfer(FAR struct hts221_dev_s *dev,
for (retries = 0; retries < HTS221_I2C_RETRIES; retries++)
{
ret = I2C_TRANSFER(dev->i2c, msgv, nmsg);
ret = I2C_TRANSFER(priv->i2c, msgv, nmsg);
if (ret >= 0)
{
return 0;
@@ -201,7 +201,7 @@ static int hts221_do_transfer(FAR struct hts221_dev_s *dev,
break;
}
ret = up_i2creset(dev->i2c);
ret = up_i2creset(priv->i2c);
if (ret < 0)
{
hts221_dbg("up_i2creset failed: %d\n", ret);
@@ -215,51 +215,51 @@ static int hts221_do_transfer(FAR struct hts221_dev_s *dev,
return ret;
}
static int32_t hts221_write_reg8(FAR struct hts221_dev_s *dev,
static int32_t hts221_write_reg8(FAR struct hts221_dev_s *priv,
const uint8_t *command)
{
struct i2c_msg_s msgv[2] =
{
{
.addr = dev->addr,
.addr = priv->addr,
.flags = 0,
.buffer = (FAR void *)&command[0],
.length = 1
},
{
.addr = dev->addr,
.addr = priv->addr,
.flags = I2C_M_NORESTART,
.buffer = (FAR void *)&command[1],
.length = 1
}
};
return hts221_do_transfer(dev, msgv, 2);
return hts221_do_transfer(priv, msgv, 2);
}
static int hts221_read_reg(FAR struct hts221_dev_s *dev,
static int hts221_read_reg(FAR struct hts221_dev_s *priv,
FAR const uint8_t *command, FAR uint8_t *value)
{
struct i2c_msg_s msgv[2] =
{
{
.addr = dev->addr,
.addr = priv->addr,
.flags = 0,
.buffer = (FAR void *)command,
.length = 1
},
{
.addr = dev->addr,
.addr = priv->addr,
.flags = I2C_M_READ,
.buffer = value,
.length = 1
}
};
return hts221_do_transfer(dev, msgv, 2);
return hts221_do_transfer(priv, msgv, 2);
}
static int hts221_get_id(FAR struct hts221_dev_s *priv, uint8_t * value)
static int hts221_get_id(FAR struct hts221_dev_s *priv, uint8_t *value)
{
int ret = OK;
uint8_t cmd = HTS221_WHO_AM_I;
@@ -360,7 +360,7 @@ static int hts221_config_ctrl_reg2(FAR struct hts221_dev_s *priv,
}
static int hts221_config_ctrl_reg1(FAR struct hts221_dev_s *priv,
FAR hts221_settings_t * settings)
FAR hts221_settings_t *settings)
{
int ret = OK;
uint8_t regval = 0;
@@ -418,7 +418,7 @@ static int hts221_power_on_off(FAR struct hts221_dev_s *priv, bool on)
}
static int hts221_config(FAR struct hts221_dev_s *priv,
FAR hts221_settings_t * cfgr)
FAR hts221_settings_t *cfgr)
{
int ret = OK;
@@ -475,7 +475,7 @@ static int hts221_start_conversion(FAR struct hts221_dev_s *priv)
}
static int hts221_check_status(FAR struct hts221_dev_s *priv,
FAR hts221_status_t * status)
FAR hts221_status_t *status)
{
int ret = OK;
uint8_t addr = HTS221_STATUS_REG;
@@ -496,7 +496,7 @@ static int hts221_check_status(FAR struct hts221_dev_s *priv,
}
static int hts221_read_raw_data(FAR struct hts221_dev_s *priv,
FAR hts221_raw_data_t * data)
FAR hts221_raw_data_t *data)
{
int ret = OK;
uint8_t addr_humid_low = HTS221_HUM_OUT_L;
File diff suppressed because it is too large Load Diff
+8
View File
@@ -125,4 +125,12 @@
#define SNIOC_READ_CONVERT_DATA _SNIOC(0x002f)
#define SNIOC_DUMP_REGS _SNIOC(0x0030)
/* IOCTL commands unique to the LPS25H */
#define SNIOC_GET_DEV_ID _SNIOC(0x0031)
#define SNIOC_CFGR _SNIOC(0x0032)
#define SNIOC_TEMPERATURE_OUT _SNIOC(0x0033)
#define SNIOC_PRESSURE_OUT _SNIOC(0x0034)
#define SNIOC_SENSOR_OFF _SNIOC(0x0035)
#endif /* __INCLUDE_NUTTX_SENSORS_IOCTL_H */
+105
View File
@@ -0,0 +1,105 @@
/****************************************************************************
* include/nuttx/sensors/lps25h.h
*
* Copyright (C) 2014, 2017 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_LPS25H_H
#define __INCLUDE_NUTT_SENSORS_LPS25H_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/sensors/ioctl.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define LPS25H_TEMPER_DIVIDER 1000
#define LPS25H_VALID_WHO_AM_I 0xbd
/****************************************************************************
* Public Types
****************************************************************************/
typedef struct lps25h_temper_data_s
{
int32_t int_temper; /* int_temper value must be divided by
* LPS25H_TEMPER_DIVIDER in your app code */
int16_t raw_data;
} lps25h_temper_data_t;
typedef struct lps25h_pressure_data_s
{
uint32_t pressure_int_hP;
uint32_t pressure_Pa;
uint32_t raw_data;
} lps25h_pressure_data_t;
typedef struct lps25h_who_am_i_data
{
uint8_t who_am_i;
} lps25h_who_am_i_data;
typedef struct lps25h_config_s
{
/* Device characterization */
int irq; /* IRQ number received by interrupt handler. */
/* IRQ/GPIO access callbacks. These operations all hidden behind callbacks
* to isolate the driver from differences in GPIO interrupt handling
* by varying boards and MCUs.
* irq_attach - Attach the interrupt handler to the GPIO interrupt
* irq_enable - Enable or disable the GPIO
* irq_clear - Acknowledge/clear any pending GPIO interrupt
* set_power - Ask board to turn on regulator
*/
CODE int (*irq_attach)(FAR struct lps25h_config_s *state, xcpt_t isr,
FAR void *arg);
CODE void (*irq_enable)(FAR const struct lps25h_config_s *state,
bool enable);
CODE void (*irq_clear)(FAR const struct lps25h_config_s *state);
CODE int (*set_power)(FAR const struct lps25h_config_s *state, bool on);
} lps25h_config_t;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
int lps25h_register(FAR const char *devpath, FAR struct i2c_master_s *i2c,
uint8_t addr, FAR lps25h_config_t *config);
#endif /* __INCLUDE_NUTT_SENSORS_LPS25H_H */