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