sensors: mx5611: Add support for MS5607
MS5607 has few differences between MS5611. Signed-off-by: Takumi Ando <t-ando@advaly.co.jp>
This commit is contained in:
parent
6dfe1bf58c
commit
3353bd3ced
@ -188,8 +188,8 @@ if(CONFIG_SENSORS)
|
||||
list(APPEND SRCS mlx90614.c)
|
||||
endif()
|
||||
|
||||
if(CONFIG_SENSORS_MS5611)
|
||||
list(APPEND SRCS ms5611_uorb.c)
|
||||
if(CONFIG_SENSORS_MS56XX)
|
||||
list(APPEND SRCS ms56xx_uorb.c)
|
||||
endif()
|
||||
|
||||
if(CONFIG_SENSORS_MS58XX)
|
||||
|
@ -737,45 +737,45 @@ config MCP9844_I2C_FREQUENCY
|
||||
range 1 400000
|
||||
depends on SENSORS_MCP9844
|
||||
|
||||
config SENSORS_MS5611
|
||||
bool "MS5611 Barometric Pressure Sensor support"
|
||||
config SENSORS_MS56XX
|
||||
bool "MS56XX Barometric Pressure Sensor support"
|
||||
default n
|
||||
---help---
|
||||
Enable driver support for MEAS MS5511 barometer.
|
||||
|
||||
if SENSORS_MS5611
|
||||
if SENSORS_MS56XX
|
||||
|
||||
choice
|
||||
prompt "MS5611 Interface"
|
||||
default MS5611_I2C
|
||||
prompt "MS56XX Interface"
|
||||
default MS56XX_I2C
|
||||
|
||||
config MS5611_I2C
|
||||
bool "MS5611 I2C Interface"
|
||||
config MS56XX_I2C
|
||||
bool "MS56XX I2C Interface"
|
||||
select I2C
|
||||
---help---
|
||||
Enables support for the I2C interface
|
||||
|
||||
config MS5611_SPI
|
||||
bool "MS5611 SPI Interface"
|
||||
config MS56XX_SPI
|
||||
bool "MS56XX SPI Interface"
|
||||
select SPI
|
||||
---help---
|
||||
Enables support for the SPI interface.
|
||||
|
||||
endchoice
|
||||
|
||||
config MS5611_THREAD_STACKSIZE
|
||||
config MS56XX_THREAD_STACKSIZE
|
||||
int "Worker thread stack size"
|
||||
default 1024
|
||||
---help---
|
||||
The stack size for the worker thread
|
||||
|
||||
config MS5611_I2C_FREQUENCY
|
||||
int "MS5611 I2C frequency"
|
||||
config MS56XX_I2C_FREQUENCY
|
||||
int "MS56XX I2C frequency"
|
||||
default 400000
|
||||
range 1 400000
|
||||
depends on MS5611_I2C
|
||||
depends on MS56XX_I2C
|
||||
|
||||
endif # SENSORS_MS5611
|
||||
endif # SENSORS_MS56XX
|
||||
|
||||
config SENSORS_MS58XX
|
||||
bool "MEAS MS58XX Altimeter support"
|
||||
|
@ -210,8 +210,8 @@ ifeq ($(CONFIG_SENSORS_MLX90614),y)
|
||||
CSRCS += mlx90614.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_MS5611),y)
|
||||
CSRCS += ms5611_uorb.c
|
||||
ifeq ($(CONFIG_SENSORS_MS56XX),y)
|
||||
CSRCS += ms56xx_uorb.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_MS58XX),y)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* drivers/sensors/ms5611_uorb.c
|
||||
* drivers/sensors/ms56xx_uorb.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
@ -39,36 +39,36 @@
|
||||
#include <nuttx/semaphore.h>
|
||||
#include <nuttx/i2c/i2c_master.h>
|
||||
#include <nuttx/sensors/sensor.h>
|
||||
#include <nuttx/sensors/ms5611.h>
|
||||
#include <nuttx/sensors/ms56xx.h>
|
||||
#include <nuttx/sensors/msxxxx_crc4.h>
|
||||
|
||||
#if defined(CONFIG_SENSORS_MS5611) && \
|
||||
#if defined(CONFIG_SENSORS_MS56XX) && \
|
||||
(defined(CONFIG_I2C) || defined(CONFIG_SPI))
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define MS5611_CMD_RESET 0x1e
|
||||
#define MS5611_CMD_START_ADC_READ 0x00
|
||||
#define MS5611_CMD_CONV_D1_OSR_256 0x40 /* D1 = uncompensated pressure */
|
||||
#define MS5611_CMD_CONV_D1_OSR_512 0x42
|
||||
#define MS5611_CMD_CONV_D1_OSR_1024 0x44
|
||||
#define MS5611_CMD_CONV_D1_OSR_2048 0x46
|
||||
#define MS5611_CMD_CONV_D1_OSR_4096 0x48
|
||||
#define MS5611_CMD_CONV_D2_OSR_256 0x50 /* D2 = uncompensated pressure */
|
||||
#define MS5611_CMD_CONV_D2_OSR_512 0x52
|
||||
#define MS5611_CMD_CONV_D2_OSR_1024 0x54
|
||||
#define MS5611_CMD_CONV_D2_OSR_2048 0x56
|
||||
#define MS5611_CMD_CONV_D2_OSR_4096 0x58
|
||||
#define MS5611_CMD_ADC_READ 0x00
|
||||
#define MS5611_CMD_ADC_PROM_READ(i) (0xa0 + (i)*2) /* 0xA0 - 0xAE */
|
||||
#define MS56XX_CMD_RESET 0x1e
|
||||
#define MS56XX_CMD_START_ADC_READ 0x00
|
||||
#define MS56XX_CMD_CONV_D1_OSR_256 0x40 /* D1 = uncompensated pressure */
|
||||
#define MS56XX_CMD_CONV_D1_OSR_512 0x42
|
||||
#define MS56XX_CMD_CONV_D1_OSR_1024 0x44
|
||||
#define MS56XX_CMD_CONV_D1_OSR_2048 0x46
|
||||
#define MS56XX_CMD_CONV_D1_OSR_4096 0x48
|
||||
#define MS56XX_CMD_CONV_D2_OSR_256 0x50 /* D2 = uncompensated pressure */
|
||||
#define MS56XX_CMD_CONV_D2_OSR_512 0x52
|
||||
#define MS56XX_CMD_CONV_D2_OSR_1024 0x54
|
||||
#define MS56XX_CMD_CONV_D2_OSR_2048 0x56
|
||||
#define MS56XX_CMD_CONV_D2_OSR_4096 0x58
|
||||
#define MS56XX_CMD_ADC_READ 0x00
|
||||
#define MS56XX_CMD_ADC_PROM_READ(i) (0xa0 + (i)*2) /* 0xA0 - 0xAE */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
struct ms5611_calib_s
|
||||
struct ms56xx_calib_s
|
||||
{
|
||||
uint16_t reversed;
|
||||
uint16_t c1;
|
||||
@ -80,23 +80,24 @@ struct ms5611_calib_s
|
||||
uint16_t crc;
|
||||
};
|
||||
|
||||
struct ms5611_dev_s
|
||||
struct ms56xx_dev_s
|
||||
{
|
||||
FAR struct sensor_lowerhalf_s sensor_lower;
|
||||
|
||||
#ifdef CONFIG_MS5611_I2C
|
||||
#ifdef CONFIG_MS56XX_I2C
|
||||
FAR struct i2c_master_s *i2c; /* I2C interface */
|
||||
uint8_t addr; /* I2C address */
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MS5611_SPI
|
||||
#ifdef CONFIG_MS56XX_SPI
|
||||
FAR struct spi_dev_s *spi; /* SPI interface */
|
||||
#endif
|
||||
|
||||
enum ms56xx_model_e model; /* Model of MS56XX */
|
||||
uint32_t freq; /* Bus Frequency I2C/SPI */
|
||||
struct ms5611_calib_s calib; /* Calib. params from ROM */
|
||||
struct ms56xx_calib_s calib; /* Calib. params from ROM */
|
||||
unsigned long interval; /* Polling interval */
|
||||
bool enabled; /* Enable/Disable MS5611 */
|
||||
bool enabled; /* Enable/Disable MS56XX */
|
||||
sem_t run; /* Locks measure cycle */
|
||||
mutex_t lock; /* Manages exclusive to device */
|
||||
};
|
||||
@ -105,30 +106,30 @@ struct ms5611_dev_s
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static int ms5611_sendcmd(FAR struct ms5611_dev_s *priv,
|
||||
static int ms56xx_sendcmd(FAR struct ms56xx_dev_s *priv,
|
||||
uint8_t cmd);
|
||||
static int ms5611_read16(FAR struct ms5611_dev_s *priv,
|
||||
static int ms56xx_read16(FAR struct ms56xx_dev_s *priv,
|
||||
FAR uint8_t *regval);
|
||||
static int ms5611_read24(FAR struct ms5611_dev_s *priv,
|
||||
static int ms56xx_read24(FAR struct ms56xx_dev_s *priv,
|
||||
FAR uint8_t *regval);
|
||||
|
||||
static int32_t ms5611_compensate_temp(FAR struct ms5611_dev_s *priv,
|
||||
static int32_t ms56xx_compensate_temp(FAR struct ms56xx_dev_s *priv,
|
||||
uint32_t temp, int32_t *deltat);
|
||||
static uint32_t ms5611_compensate_press(FAR struct ms5611_dev_s *priv,
|
||||
static uint32_t ms56xx_compensate_press(FAR struct ms56xx_dev_s *priv,
|
||||
uint32_t press, uint32_t dt);
|
||||
|
||||
static unsigned long ms5611_curtime(void);
|
||||
static unsigned long ms56xx_curtime(void);
|
||||
|
||||
/* Sensor methods */
|
||||
|
||||
static int ms5611_set_interval(FAR struct sensor_lowerhalf_s *lower,
|
||||
static int ms56xx_set_interval(FAR struct sensor_lowerhalf_s *lower,
|
||||
FAR struct file *filep,
|
||||
FAR unsigned long *period_us);
|
||||
static int ms5611_activate(FAR struct sensor_lowerhalf_s *lower,
|
||||
static int ms56xx_activate(FAR struct sensor_lowerhalf_s *lower,
|
||||
FAR struct file *filep, bool enable);
|
||||
|
||||
#if 0 /* Please read below */
|
||||
static int ms5611_fetch(FAR struct sensor_lowerhalf_s *lower,
|
||||
static int ms56xx_fetch(FAR struct sensor_lowerhalf_s *lower,
|
||||
FAR char *buffer, size_t buflen);
|
||||
#endif
|
||||
|
||||
@ -138,9 +139,9 @@ static int ms5611_fetch(FAR struct sensor_lowerhalf_s *lower,
|
||||
|
||||
static const struct sensor_ops_s g_sensor_ops =
|
||||
{
|
||||
.activate = ms5611_activate,
|
||||
.fetch = NULL, /* ms5611_fetch */
|
||||
.set_interval = ms5611_set_interval,
|
||||
.activate = ms56xx_activate,
|
||||
.fetch = NULL, /* ms56xx_fetch */
|
||||
.set_interval = ms56xx_set_interval,
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@ -148,7 +149,7 @@ static const struct sensor_ops_s g_sensor_ops =
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ms5611_curtime
|
||||
* Name: ms56xx_curtime
|
||||
*
|
||||
* Description: Helper to get current timestamp.
|
||||
*
|
||||
@ -156,7 +157,7 @@ static const struct sensor_ops_s g_sensor_ops =
|
||||
* Timestamp in microseconds
|
||||
****************************************************************************/
|
||||
|
||||
static unsigned long ms5611_curtime(void)
|
||||
static unsigned long ms56xx_curtime(void)
|
||||
{
|
||||
struct timespec ts;
|
||||
|
||||
@ -165,14 +166,14 @@ static unsigned long ms5611_curtime(void)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ms5611_sendcmd
|
||||
* Name: ms56xx_sendcmd
|
||||
*
|
||||
* Description:
|
||||
* Send a command (8-bit) to MS5611
|
||||
* Send a command (8-bit) to MS56XX
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int ms5611_sendcmd(FAR struct ms5611_dev_s *priv, uint8_t cmd)
|
||||
static int ms56xx_sendcmd(FAR struct ms56xx_dev_s *priv, uint8_t cmd)
|
||||
{
|
||||
struct i2c_msg_s msg;
|
||||
int ret;
|
||||
@ -194,14 +195,14 @@ static int ms5611_sendcmd(FAR struct ms5611_dev_s *priv, uint8_t cmd)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ms5611_read16
|
||||
* Name: ms56xx_read16
|
||||
*
|
||||
* Description:
|
||||
* Read 16-bit from a MS5611 register
|
||||
* Read 16-bit from a MS56XX register
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int ms5611_read16(FAR struct ms5611_dev_s *priv, FAR uint8_t *regval)
|
||||
static int ms56xx_read16(FAR struct ms56xx_dev_s *priv, FAR uint8_t *regval)
|
||||
{
|
||||
struct i2c_msg_s msg;
|
||||
int ret;
|
||||
@ -223,14 +224,14 @@ static int ms5611_read16(FAR struct ms5611_dev_s *priv, FAR uint8_t *regval)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ms5611_read24
|
||||
* Name: ms56xx_read24
|
||||
*
|
||||
* Description:
|
||||
* Read 24-bit from a MS5611 register
|
||||
* Read 24-bit from a MS56XX register
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int ms5611_read24(FAR struct ms5611_dev_s *priv, uint8_t *regval)
|
||||
static int ms56xx_read24(FAR struct ms56xx_dev_s *priv, uint8_t *regval)
|
||||
{
|
||||
struct i2c_msg_s msg;
|
||||
int ret;
|
||||
@ -251,7 +252,7 @@ static int ms5611_read24(FAR struct ms5611_dev_s *priv, uint8_t *regval)
|
||||
return OK;
|
||||
}
|
||||
|
||||
static inline void baro_measure_read(FAR struct ms5611_dev_s *priv,
|
||||
static inline void baro_measure_read(FAR struct ms56xx_dev_s *priv,
|
||||
FAR struct sensor_baro *baro)
|
||||
{
|
||||
uint32_t press;
|
||||
@ -270,10 +271,10 @@ static inline void baro_measure_read(FAR struct ms5611_dev_s *priv,
|
||||
|
||||
/* Send command to start a D1 (pressure) conversion */
|
||||
|
||||
ret = ms5611_sendcmd(priv, MS5611_CMD_CONV_D1_OSR_4096);
|
||||
ret = ms56xx_sendcmd(priv, MS56XX_CMD_CONV_D1_OSR_4096);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("Fail to send cmd MS5611_CMD_CONV_D1_OSR_4096!\n");
|
||||
snerr("Fail to send cmd MS56XX_CMD_CONV_D1_OSR_4096!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -283,10 +284,10 @@ static inline void baro_measure_read(FAR struct ms5611_dev_s *priv,
|
||||
|
||||
/* Send command to start a read sequence */
|
||||
|
||||
ret = ms5611_sendcmd(priv, MS5611_CMD_START_ADC_READ);
|
||||
ret = ms56xx_sendcmd(priv, MS56XX_CMD_START_ADC_READ);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("Fail to send cmd MS5611_CMD_START_ADC_READ!\n");
|
||||
snerr("Fail to send cmd MS56XX_CMD_START_ADC_READ!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -294,7 +295,7 @@ static inline void baro_measure_read(FAR struct ms5611_dev_s *priv,
|
||||
|
||||
up_udelay(4000);
|
||||
|
||||
ret = ms5611_read24(priv, buffer);
|
||||
ret = ms56xx_read24(priv, buffer);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("Fail to read pressure!\n");
|
||||
@ -307,10 +308,10 @@ static inline void baro_measure_read(FAR struct ms5611_dev_s *priv,
|
||||
|
||||
/* Send command to start a D2 (temperature) conversion */
|
||||
|
||||
ret = ms5611_sendcmd(priv, MS5611_CMD_CONV_D2_OSR_4096);
|
||||
ret = ms56xx_sendcmd(priv, MS56XX_CMD_CONV_D2_OSR_4096);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("Fail to send cmd MS5611_CMD_CONV_D2_OSR_4096!\n");
|
||||
snerr("Fail to send cmd MS56XX_CMD_CONV_D2_OSR_4096!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -320,10 +321,10 @@ static inline void baro_measure_read(FAR struct ms5611_dev_s *priv,
|
||||
|
||||
/* Send command to start a read sequence */
|
||||
|
||||
ret = ms5611_sendcmd(priv, MS5611_CMD_START_ADC_READ);
|
||||
ret = ms56xx_sendcmd(priv, MS56XX_CMD_START_ADC_READ);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("Fail to send cmd MS5611_CMD_START_ADC_READ!\n");
|
||||
snerr("Fail to send cmd MS56XX_CMD_START_ADC_READ!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -331,7 +332,7 @@ static inline void baro_measure_read(FAR struct ms5611_dev_s *priv,
|
||||
|
||||
up_udelay(4000);
|
||||
|
||||
ret = ms5611_read24(priv, buffer);
|
||||
ret = ms56xx_read24(priv, buffer);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("Fail to read temperature!\n");
|
||||
@ -348,16 +349,16 @@ static inline void baro_measure_read(FAR struct ms5611_dev_s *priv,
|
||||
|
||||
/* Compensate the temp/press with calibration data */
|
||||
|
||||
temp = ms5611_compensate_temp(priv, temp, &deltat);
|
||||
press = ms5611_compensate_press(priv, press, deltat);
|
||||
temp = ms56xx_compensate_temp(priv, temp, &deltat);
|
||||
press = ms56xx_compensate_press(priv, press, deltat);
|
||||
|
||||
baro->timestamp = ms5611_curtime();
|
||||
baro->timestamp = ms56xx_curtime();
|
||||
baro->pressure = press / 100.0f;
|
||||
baro->temperature = temp / 100.0f;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ms5611_thread
|
||||
* Name: ms56xx_thread
|
||||
*
|
||||
* Description: Thread for performing interval measurement cycle and data
|
||||
* read.
|
||||
@ -367,9 +368,9 @@ static inline void baro_measure_read(FAR struct ms5611_dev_s *priv,
|
||||
* argv - Pointer to argument list
|
||||
****************************************************************************/
|
||||
|
||||
static int ms5611_thread(int argc, char **argv)
|
||||
static int ms56xx_thread(int argc, char **argv)
|
||||
{
|
||||
FAR struct ms5611_dev_s *priv = (FAR struct ms5611_dev_s *)
|
||||
FAR struct ms56xx_dev_s *priv = (FAR struct ms56xx_dev_s *)
|
||||
((uintptr_t)strtoul(argv[1], NULL, 16));
|
||||
|
||||
struct sensor_baro baro_data;
|
||||
@ -403,14 +404,14 @@ static int ms5611_thread(int argc, char **argv)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ms5611_initialize
|
||||
* Name: ms56xx_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize MS5611 device
|
||||
* Initialize MS56XX device
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int ms5611_initialize(FAR struct ms5611_dev_s *priv)
|
||||
static int ms56xx_initialize(FAR struct ms56xx_dev_s *priv)
|
||||
{
|
||||
uint16_t prom[8];
|
||||
uint8_t data[2];
|
||||
@ -420,10 +421,10 @@ static int ms5611_initialize(FAR struct ms5611_dev_s *priv)
|
||||
|
||||
/* Get calibration data. */
|
||||
|
||||
ret = ms5611_sendcmd(priv, MS5611_CMD_RESET);
|
||||
ret = ms56xx_sendcmd(priv, MS56XX_CMD_RESET);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ms5611 reset failed\n");
|
||||
snerr("ms56xx reset failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -433,17 +434,17 @@ static int ms5611_initialize(FAR struct ms5611_dev_s *priv)
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
ret = ms5611_sendcmd(priv, MS5611_CMD_ADC_PROM_READ(i));
|
||||
ret = ms56xx_sendcmd(priv, MS56XX_CMD_ADC_PROM_READ(i));
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ms5611_sendcmd failed\n");
|
||||
snerr("ms56xx_sendcmd failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = ms5611_read16(priv, data);
|
||||
ret = ms56xx_read16(priv, data);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ms5611_read16 failed\n");
|
||||
snerr("ms56xx_read16 failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -475,7 +476,7 @@ static int ms5611_initialize(FAR struct ms5611_dev_s *priv)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ms5611_compensate_temp
|
||||
* Name: ms56xx_compensate_temp
|
||||
*
|
||||
* Description:
|
||||
* calculate compensate temperature
|
||||
@ -488,10 +489,10 @@ static int ms5611_initialize(FAR struct ms5611_dev_s *priv)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int32_t ms5611_compensate_temp(FAR struct ms5611_dev_s *priv,
|
||||
static int32_t ms56xx_compensate_temp(FAR struct ms56xx_dev_s *priv,
|
||||
uint32_t temp, int32_t *deltat)
|
||||
{
|
||||
struct ms5611_calib_s *c = &priv->calib;
|
||||
struct ms56xx_calib_s *c = &priv->calib;
|
||||
int32_t dt;
|
||||
|
||||
/* dt = d1 - c5 * 256 */
|
||||
@ -510,7 +511,7 @@ static int32_t ms5611_compensate_temp(FAR struct ms5611_dev_s *priv,
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ms5611_compensate_press
|
||||
* Name: ms56xx_compensate_press
|
||||
*
|
||||
* Description:
|
||||
* calculate compensate pressure
|
||||
@ -523,30 +524,41 @@ static int32_t ms5611_compensate_temp(FAR struct ms5611_dev_s *priv,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static uint32_t ms5611_compensate_press(FAR struct ms5611_dev_s *priv,
|
||||
static uint32_t ms56xx_compensate_press(FAR struct ms56xx_dev_s *priv,
|
||||
uint32_t press, uint32_t dt)
|
||||
{
|
||||
struct ms5611_calib_s *c = &priv->calib;
|
||||
int64_t off;
|
||||
int64_t sens;
|
||||
struct ms56xx_calib_s *c = &priv->calib;
|
||||
int64_t off = 0;
|
||||
int64_t sens = 0;
|
||||
|
||||
off = ((int64_t) c->c2 * 65536) + ((int64_t) (c->c4 * dt) / 128);
|
||||
sens = ((int64_t) c->c1 * 32768) + ((int64_t) (c->c3 * dt) / 256);
|
||||
press = (((press * sens) / 2097152) - off) / 32768;
|
||||
switch (priv->model)
|
||||
{
|
||||
case MS56XX_MODEL_MS5607:
|
||||
off = ((int64_t) c->c2 << 17) + ((int64_t) (c->c4 * dt) >> 6);
|
||||
sens = ((int64_t) c->c1 << 16) + ((int64_t) (c->c3 * dt) >> 7);
|
||||
break;
|
||||
|
||||
case MS56XX_MODEL_MS5611:
|
||||
off = ((int64_t) c->c2 << 16) + ((int64_t) (c->c4 * dt) >> 7);
|
||||
sens = ((int64_t) c->c1 << 15) + ((int64_t) (c->c3 * dt) >> 8);
|
||||
break;
|
||||
}
|
||||
|
||||
press = (((press * sens) >> 21) - off) >> 15;
|
||||
|
||||
return press;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ms5611_set_interval
|
||||
* Name: ms56xx_set_interval
|
||||
****************************************************************************/
|
||||
|
||||
static int ms5611_set_interval(FAR struct sensor_lowerhalf_s *lower,
|
||||
static int ms56xx_set_interval(FAR struct sensor_lowerhalf_s *lower,
|
||||
FAR struct file *filep,
|
||||
FAR unsigned long *period_us)
|
||||
{
|
||||
FAR struct ms5611_dev_s *priv = container_of(lower,
|
||||
FAR struct ms5611_dev_s,
|
||||
FAR struct ms56xx_dev_s *priv = container_of(lower,
|
||||
FAR struct ms56xx_dev_s,
|
||||
sensor_lower);
|
||||
|
||||
priv->interval = *period_us;
|
||||
@ -554,14 +566,14 @@ static int ms5611_set_interval(FAR struct sensor_lowerhalf_s *lower,
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ms5611_activate
|
||||
* Name: ms56xx_activate
|
||||
****************************************************************************/
|
||||
|
||||
static int ms5611_activate(FAR struct sensor_lowerhalf_s *lower,
|
||||
static int ms56xx_activate(FAR struct sensor_lowerhalf_s *lower,
|
||||
FAR struct file *filep, bool enable)
|
||||
{
|
||||
bool start_thread = false;
|
||||
struct ms5611_dev_s *priv = (FAR struct ms5611_dev_s *)lower;
|
||||
struct ms56xx_dev_s *priv = (FAR struct ms56xx_dev_s *)lower;
|
||||
|
||||
if (enable)
|
||||
{
|
||||
@ -584,7 +596,7 @@ static int ms5611_activate(FAR struct sensor_lowerhalf_s *lower,
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ms5611_fetch
|
||||
* Name: ms56xx_fetch
|
||||
****************************************************************************/
|
||||
|
||||
/* N.B. When fetch is enabled the sensortest doesn't respect the
|
||||
@ -593,11 +605,11 @@ static int ms5611_activate(FAR struct sensor_lowerhalf_s *lower,
|
||||
*/
|
||||
|
||||
#if 0
|
||||
static int ms5611_fetch(FAR struct sensor_lowerhalf_s *lower,
|
||||
static int ms56xx_fetch(FAR struct sensor_lowerhalf_s *lower,
|
||||
FAR char *buffer, size_t buflen)
|
||||
{
|
||||
FAR struct ms5611_dev_s *priv = container_of(lower,
|
||||
FAR struct ms5611_dev_s,
|
||||
FAR struct ms56xx_dev_s *priv = container_of(lower,
|
||||
FAR struct ms56xx_dev_s,
|
||||
sensor_lower);
|
||||
struct sensor_baro baro_data;
|
||||
|
||||
@ -619,33 +631,35 @@ static int ms5611_fetch(FAR struct sensor_lowerhalf_s *lower,
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ms5611_register
|
||||
* Name: ms56xx_register
|
||||
*
|
||||
* Description:
|
||||
* Register the MS5611 character device
|
||||
* Register the MS56XX character device
|
||||
*
|
||||
* Input Parameters:
|
||||
* i2c - An instance of the I2C interface to use to communicate with
|
||||
* MS5611
|
||||
* MS56XX
|
||||
* devno - Instance number for driver
|
||||
* addr - The I2C address of the MS5611.
|
||||
* addr - The I2C address of the MS56XX.
|
||||
* model - The MS56XX model.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int ms5611_register(FAR struct i2c_master_s *i2c, int devno, uint8_t addr)
|
||||
int ms56xx_register(FAR struct i2c_master_s *i2c, int devno, uint8_t addr,
|
||||
enum ms56xx_model_e model)
|
||||
{
|
||||
FAR struct ms5611_dev_s *priv;
|
||||
FAR struct ms56xx_dev_s *priv;
|
||||
FAR char *argv[2];
|
||||
char arg1[32];
|
||||
|
||||
int ret;
|
||||
|
||||
/* Initialize the MS5611 device structure */
|
||||
/* Initialize the MS56XX device structure */
|
||||
|
||||
priv = kmm_zalloc(sizeof(struct ms5611_dev_s));
|
||||
priv = kmm_zalloc(sizeof(struct ms56xx_dev_s));
|
||||
if (priv == NULL)
|
||||
{
|
||||
snerr("Failed to allocate instance\n");
|
||||
@ -654,7 +668,8 @@ int ms5611_register(FAR struct i2c_master_s *i2c, int devno, uint8_t addr)
|
||||
|
||||
priv->i2c = i2c;
|
||||
priv->addr = addr;
|
||||
priv->freq = CONFIG_MS5611_I2C_FREQUENCY;
|
||||
priv->model = model;
|
||||
priv->freq = CONFIG_MS56XX_I2C_FREQUENCY;
|
||||
priv->interval = 1000000; /* Default interval 1s */
|
||||
|
||||
nxsem_init(&priv->run, 0, 0);
|
||||
@ -663,10 +678,10 @@ int ms5611_register(FAR struct i2c_master_s *i2c, int devno, uint8_t addr)
|
||||
priv->sensor_lower.ops = &g_sensor_ops;
|
||||
priv->sensor_lower.type = SENSOR_TYPE_BAROMETER;
|
||||
|
||||
ret = ms5611_initialize(priv);
|
||||
ret = ms56xx_initialize(priv);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("Failed to initialize physical device ms5611:%d\n", ret);
|
||||
snerr("Failed to initialize physical device ms56xx:%d\n", ret);
|
||||
nxmutex_destroy(&priv->lock);
|
||||
nxsem_destroy(&priv->run);
|
||||
kmm_free(priv);
|
||||
@ -690,9 +705,9 @@ int ms5611_register(FAR struct i2c_master_s *i2c, int devno, uint8_t addr)
|
||||
snprintf(arg1, 16, "%p", priv);
|
||||
argv[0] = arg1;
|
||||
argv[1] = NULL;
|
||||
ret = kthread_create("ms5611_thread", SCHED_PRIORITY_DEFAULT,
|
||||
CONFIG_MS5611_THREAD_STACKSIZE,
|
||||
ms5611_thread, argv);
|
||||
ret = kthread_create("ms56xx_thread", SCHED_PRIORITY_DEFAULT,
|
||||
CONFIG_MS56XX_THREAD_STACKSIZE,
|
||||
ms56xx_thread, argv);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("Failed to create the notification kthread!\n");
|
||||
@ -703,7 +718,7 @@ int ms5611_register(FAR struct i2c_master_s *i2c, int devno, uint8_t addr)
|
||||
return ret;
|
||||
}
|
||||
|
||||
sninfo("MS5611 driver loaded successfully!\n");
|
||||
sninfo("MS56XX driver loaded successfully!\n");
|
||||
return OK;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/sensors/ms5611.h
|
||||
* include/nuttx/sensors/ms56xx.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
@ -18,8 +18,8 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_SENSORS_MS5611_H
|
||||
#define __INCLUDE_NUTTX_SENSORS_MS5611_H
|
||||
#ifndef __INCLUDE_NUTTX_SENSORS_MS56XX_H
|
||||
#define __INCLUDE_NUTTX_SENSORS_MS56XX_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
@ -28,7 +28,7 @@
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/sensors/ioctl.h>
|
||||
|
||||
#if defined(CONFIG_I2C) && defined(CONFIG_SENSORS_MS5611)
|
||||
#if defined(CONFIG_I2C) && defined(CONFIG_SENSORS_MS56XX)
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@ -39,20 +39,26 @@
|
||||
*
|
||||
* CONFIG_I2C
|
||||
* Enables support for I2C drivers
|
||||
* CONFIG_SENSORS_MS5611
|
||||
* Enables support for the MS5611 driver
|
||||
* CONFIG_SENSORS_MS56XX
|
||||
* Enables support for the MS56XX driver
|
||||
*/
|
||||
|
||||
/* I2C Address **************************************************************/
|
||||
|
||||
#define MS5611_ADDR0 0x77
|
||||
#define MS5611_ADDR1 0x76
|
||||
#define MS56XX_ADDR0 0x77
|
||||
#define MS56XX_ADDR1 0x76
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct ms5611_measure_s
|
||||
enum ms56xx_model_e
|
||||
{
|
||||
MS56XX_MODEL_MS5607 = 0,
|
||||
MS56XX_MODEL_MS5611 = 1,
|
||||
};
|
||||
|
||||
struct ms56xx_measure_s
|
||||
{
|
||||
int32_t temperature; /* in Degree x100 */
|
||||
int32_t pressure; /* in mBar x10 */
|
||||
@ -73,27 +79,29 @@ extern "C"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ms5611_register
|
||||
* Name: ms56xx_register
|
||||
*
|
||||
* Description:
|
||||
* Register the MS5611 character device as 'devpath'.
|
||||
* Register the MS56XX character device as 'devpath'.
|
||||
*
|
||||
* Input Parameters:
|
||||
* i2c - An I2C driver instance.
|
||||
* devno - Number of device (i.e. baro0, baro1, ...)
|
||||
* addr - The I2C address of the MS5611.
|
||||
* addr - The I2C address of the MS56XX.
|
||||
* model - The MS56XX model.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int ms5611_register(FAR struct i2c_master_s *i2c, int devno, uint8_t addr);
|
||||
int ms56xx_register(FAR struct i2c_master_s *i2c, int devno, uint8_t addr,
|
||||
enum ms56xx_model_e model);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_I2C && CONFIG_SENSORS_MS5611 */
|
||||
#endif /* __INCLUDE_NUTTX_SENSORS_MS5611_H */
|
||||
#endif /* CONFIG_I2C && CONFIG_SENSORS_MS56XX */
|
||||
#endif /* __INCLUDE_NUTTX_SENSORS_MS56XX_H */
|
Loading…
Reference in New Issue
Block a user