diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2015-02-12 12:21:05 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2015-02-12 12:21:05 -0600 |
commit | 573890a3a6b4f2cccfbe269e800023d8f6289410 (patch) | |
tree | 16e5872222becf205d46bc5080f8b10aee174fc7 /nuttx/drivers | |
parent | 50e19250285c8ae06104d04a74e89d0a2c62e93a (diff) | |
download | px4-nuttx-573890a3a6b4f2cccfbe269e800023d8f6289410.tar.gz px4-nuttx-573890a3a6b4f2cccfbe269e800023d8f6289410.tar.bz2 px4-nuttx-573890a3a6b4f2cccfbe269e800023d8f6289410.zip |
Update ChangeLog
Diffstat (limited to 'nuttx/drivers')
-rw-r--r-- | nuttx/drivers/sensors/Kconfig | 7 | ||||
-rw-r--r-- | nuttx/drivers/sensors/Make.defs | 6 | ||||
-rw-r--r-- | nuttx/drivers/sensors/README.txt | 6 | ||||
-rw-r--r-- | nuttx/drivers/sensors/mpl115a.c | 53 |
4 files changed, 52 insertions, 20 deletions
diff --git a/nuttx/drivers/sensors/Kconfig b/nuttx/drivers/sensors/Kconfig index cedb9ac5c..f27d52baf 100644 --- a/nuttx/drivers/sensors/Kconfig +++ b/nuttx/drivers/sensors/Kconfig @@ -8,6 +8,13 @@ config LIS331DL default n select I2C +config MPL115A + bool "Freescale MPL115A Barometer Sensor support" + default n + select SPI + ---help--- + Enable driver support for the Freescale MPL115A barometer sensor. + config SENSORS_ADXL345 bool "AnalogDevices ADXL345 Driver" default n diff --git a/nuttx/drivers/sensors/Make.defs b/nuttx/drivers/sensors/Make.defs index 8a358f070..4fc8e84cf 100644 --- a/nuttx/drivers/sensors/Make.defs +++ b/nuttx/drivers/sensors/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # drivers/sensors/Make.defs # -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2011-2012, 2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without @@ -64,6 +64,10 @@ ifeq ($(CONFIG_SPI),y) ifeq ($(CONFIG_ADXL345_SPI),y) CSRCS += adxl345_spi.c endif + +ifeq ($(CONFIG_MPL115A),y) + CSRCS += mpl115a.c +endif endif # CONFIG_SPI # Quadrature encoder upper half diff --git a/nuttx/drivers/sensors/README.txt b/nuttx/drivers/sensors/README.txt index 4f6c0072c..e0df3d629 100644 --- a/nuttx/drivers/sensors/README.txt +++ b/nuttx/drivers/sensors/README.txt @@ -8,3 +8,9 @@ In order to operate in SPI mode CS need to use connected to microcontroller, it cannot leave unconnected. In SPI mode it works with clock polarity (CPOL) = 1 and clock phase (CPHA) = 1. + +MPL115A +======= + +This driver has support only for MPL115A1 (SPI), but support to MPL115A2 (I2C) can +be added easily. diff --git a/nuttx/drivers/sensors/mpl115a.c b/nuttx/drivers/sensors/mpl115a.c index b507b3343..b5d64b117 100644 --- a/nuttx/drivers/sensors/mpl115a.c +++ b/nuttx/drivers/sensors/mpl115a.c @@ -2,7 +2,7 @@ * drivers/sensors/mpl115a.c * Character driver for the Freescale MPL115A1 Barometer Sensor * - * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -71,7 +71,6 @@ struct mpl115a_dev_s uint16_t mpl115a_pressure; }; - /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -95,15 +94,16 @@ static ssize_t mpl115a_write(FAR struct file *filep, FAR const char *buffer, siz static const struct file_operations g_mpl115afops = { - mpl115a_open, - mpl115a_close, - mpl115a_read, - mpl115a_write, - 0, - 0 + mpl115a_open, /* open */ + mpl115a_close, /* close */ + mpl115a_read, /* read */ + mpl115a_write, /* write */ + 0, /* seek */ + 0, /* ioctl */ #ifndef CONFIG_DISABLE_POLL - , 0 + 0, /* poll */ #endif + 0 /* unlink */ }; /**************************************************************************** @@ -176,26 +176,28 @@ static uint8_t mpl115a_getreg8(FAR struct mpl115a_dev_s *priv, uint8_t regaddr) static void mpl115a_updatecaldata(FAR struct mpl115a_dev_s *priv) { /* Get a0 coefficient */ + priv->mpl115a_cal_a0 = mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_A0_MSB << 1)) << 8; priv->mpl115a_cal_a0 |= mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_A0_LSB << 1)); sndbg("a0 = %d\n", priv->mpl115a_cal_a0); /* Get b1 coefficient */ + priv->mpl115a_cal_b1 = mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_B1_MSB << 1)) << 8; priv->mpl115a_cal_b1 |= mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_B1_LSB << 1)); sndbg("b1 = %d\n", priv->mpl115a_cal_b1); /* Get b2 coefficient */ + priv->mpl115a_cal_b2 = mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_B2_MSB << 1)) << 8; priv->mpl115a_cal_b2 |= mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_B2_LSB << 1)); sndbg("b2 = %d\n", priv->mpl115a_cal_b2); /* Get c12 coefficient */ + priv->mpl115a_cal_c12 = mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_C12_MSB << 1)) << 8; priv->mpl115a_cal_c12 |= mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_C12_LSB << 1)); sndbg("c12 = %d\n", priv->mpl115a_cal_c12); - - return; } /**************************************************************************** @@ -204,15 +206,19 @@ static void mpl115a_updatecaldata(FAR struct mpl115a_dev_s *priv) * Description: * Read raw pressure and temperature from MPL115A and store it in the * mpl115a_dev_s structure. - */ + * + ****************************************************************************/ + static void mpl115a_read_press_temp(FAR struct mpl115a_dev_s *priv) { uint16_t pressure; - /* Start a new convertion */ + /* Start a new conversion */ + mpl115a_getreg8(priv, (MPL115A_CONVERT << 1)); /* Delay 5ms */ + usleep(5000); priv->mpl115a_pressure = mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_PADC_MSB << 1)) << 8; @@ -232,8 +238,8 @@ static void mpl115a_read_press_temp(FAR struct mpl115a_dev_s *priv) * Name: mpl115a_getpressure * * Description: - * Calculate the Barometrc Pressure using the temperature compensated - * See Freescale AN3785 and MPL115A1 datasheet for details + * Calculate the Barometric Pressure using the temperature compensated + * See Freescale AN3785 and MPL115A1 data sheet for details * ****************************************************************************/ @@ -243,6 +249,7 @@ static int mpl115a_getpressure(FAR struct mpl115a_dev_s *priv) uint16_t padc, tadc, pressure; /* Check if coefficient data were read correctly */ + if ( (priv->mpl115a_cal_a0 == 0) || (priv->mpl115a_cal_b1 == 0) || (priv->mpl115a_cal_b2 == 0) || (priv->mpl115a_cal_c12 == 0) ) { @@ -250,11 +257,13 @@ static int mpl115a_getpressure(FAR struct mpl115a_dev_s *priv) } /* Read temperature and pressure */ + mpl115a_read_press_temp(priv); padc = priv->mpl115a_pressure; tadc = priv->mpl115a_temperature; /* These code are from Freescale AN3785 */ + c12x2 = ((int32_t)priv->mpl115a_cal_c12 * tadc) >> 11; a1 = (int32_t) (priv->mpl115a_cal_b1 + c12x2); a1x1 = a1 * padc; @@ -263,11 +272,13 @@ static int mpl115a_getpressure(FAR struct mpl115a_dev_s *priv) pcomp = (y1 + a2x2) >> 9; /* Calculate the pressure in 1/16 kPa from compensated */ + pressure = (((((int32_t)pcomp) * 1041) >> 14) + 800); /* Note that the final pressure value is reported with 4 bit fractional * This may be eliminated by right shifting the result 4 bits. */ + sndbg("Final Pressure = %d\n", pressure >> 4); return pressure; } @@ -321,9 +332,11 @@ static ssize_t mpl115a_read(FAR struct file *filep, FAR char *buffer, size_t buf } /* Get the pressure compensated */ + *press = mpl115a_getpressure(priv); /* Return size of uint16_t (2 bytes) */ + return 2; } @@ -349,10 +362,11 @@ static ssize_t mpl115a_write(FAR struct file *filep, FAR const char *buffer, * * Input Parameters: * devpath - The full path to the driver to register. E.g., "/dev/temp0" - * i2c - An instance of the I2C interface to use to communicate with MPL115A - * addr - The I2C address of the LM-75. The base I2C address of the MPL115A - * is 0x48. Bits 0-3 can be controlled to get 8 unique addresses from 0x48 - * through 0x4f. + * i2c - An instance of the I2C interface to use to communicate with + * MPL115A + * addr - The I2C address of the LM-75. The base I2C address of the + * MPL115A is 0x48. Bits 0-3 can be controlled to get 8 unique + * addresses from 0x48 through 0x4f. * * Returned Value: * Zero (OK) on success; a negated errno value on failure. @@ -380,6 +394,7 @@ int mpl115a_register(FAR const char *devpath, FAR struct spi_dev_s *spi) priv->mpl115a_cal_c12 = 0; /* Read the coefficient value */ + mpl115a_updatecaldata(priv); /* Register the character driver */ |