mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
Make BMP085 driver device dependent and update to new driver style.
This commit is contained in:
parent
9d76efa2aa
commit
8c1dd7b929
@ -351,6 +351,49 @@ static const struct stm32_gpio pios_debug_pins[] = {
|
||||
|
||||
#endif /* PIOS_ENABLE_DEBUG_PINS */
|
||||
|
||||
#include "pios_bmp085.h"
|
||||
static const struct pios_bmp085_cfg pios_bmp085_cfg = {
|
||||
.drdy = {
|
||||
.gpio = GPIOC,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_2,
|
||||
.GPIO_Speed = GPIO_Speed_100MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IN,
|
||||
.GPIO_OType = GPIO_OType_OD,
|
||||
.GPIO_PuPd = GPIO_PuPd_NOPULL,
|
||||
},
|
||||
},
|
||||
.eoc_exti = {
|
||||
// .pin_source = GPIO_PinSource2,
|
||||
// .port_source = GPIO_PortSourceGPIOC,
|
||||
.init = {
|
||||
.EXTI_Line = EXTI_Line2, // matches above GPIO pin
|
||||
.EXTI_Mode = EXTI_Mode_Interrupt,
|
||||
.EXTI_Trigger = EXTI_Trigger_Rising,
|
||||
.EXTI_LineCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.eoc_irq = {
|
||||
.init = {
|
||||
.NVIC_IRQChannel = EXTI15_10_IRQn,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.xclr = {
|
||||
.gpio = GPIOC,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_1,
|
||||
.GPIO_Speed = GPIO_Speed_100MHz,
|
||||
.GPIO_Mode = GPIO_Mode_OUT,
|
||||
.GPIO_OType = GPIO_OType_PP,
|
||||
.GPIO_PuPd = GPIO_PuPd_NOPULL,
|
||||
},
|
||||
},
|
||||
.oversampling = 3,
|
||||
};
|
||||
|
||||
extern const struct pios_com_driver pios_usart_com_driver;
|
||||
|
||||
uint32_t pios_com_aux_id;
|
||||
@ -413,6 +456,8 @@ void PIOS_Board_Init(void) {
|
||||
PIOS_HMC5843_Init();
|
||||
#endif
|
||||
|
||||
PIOS_BMP085_Init(&pios_bmp085_cfg);
|
||||
|
||||
#if defined(PIOS_INCLUDE_SPI)
|
||||
#include "ahrs_spi_comm.h"
|
||||
AhrsInitComms();
|
||||
|
@ -102,11 +102,11 @@ SRC += $(PIOSSTM32FXX)/pios_spi.c
|
||||
SRC += $(PIOSSTM32FXX)/pios_iap.c
|
||||
SRC += $(PIOSSTM32FXX)/pios_bma180.c
|
||||
SRC += $(PIOSSTM32FXX)/pios_hmc5883.c
|
||||
SRC += $(PIOSSTM32FXX)/pios_bmp085.c
|
||||
|
||||
## PIOS Hardware (Common)
|
||||
SRC += $(PIOSCOMMON)/pios_com.c
|
||||
SRC += $(PIOSCOMMON)/printf-stdarg.c
|
||||
SRC += $(PIOSCOMMON)/pios_bmp085.c
|
||||
SRC += $(PIOSCOMMON)/pios_imu3000.c
|
||||
SRC += $(PIOSCOMMON)/pios_bl_helper.c
|
||||
|
||||
|
@ -552,10 +552,8 @@ uint32_t pios_com_gps_id;
|
||||
/**
|
||||
* Sensor configurations
|
||||
*/
|
||||
#if defined (PIOS_INCLUDE_HMC5883)
|
||||
#include "pios_hmc5883.h"
|
||||
|
||||
static const struct pios_hmc5883_cfg pios_hmc5883_mag_cfg = {
|
||||
static const struct pios_hmc5883_cfg pios_hmc5883_cfg = {
|
||||
.drdy = {
|
||||
.gpio = GPIOB,
|
||||
.init = {
|
||||
@ -585,11 +583,8 @@ static const struct pios_hmc5883_cfg pios_hmc5883_mag_cfg = {
|
||||
},
|
||||
},
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined (PIOS_INCLUDE_BMA180)
|
||||
#include "pios_bma180.h"
|
||||
|
||||
static const struct pios_bma180_cfg pios_bma180_cfg = {
|
||||
.drdy = {
|
||||
.gpio = GPIOC,
|
||||
@ -602,8 +597,8 @@ static const struct pios_bma180_cfg pios_bma180_cfg = {
|
||||
},
|
||||
},
|
||||
.eoc_exti = {
|
||||
// .pin_source = GPIO_PinSource8,
|
||||
// .port_source = GPIO_PortSourceGPIOB,
|
||||
// .pin_source = GPIO_PinSource4,
|
||||
// .port_source = GPIO_PortSourceGPIOC,
|
||||
.init = {
|
||||
.EXTI_Line = EXTI_Line4, // matches above GPIO pin
|
||||
.EXTI_Mode = EXTI_Mode_Interrupt,
|
||||
@ -620,7 +615,49 @@ static const struct pios_bma180_cfg pios_bma180_cfg = {
|
||||
},
|
||||
},
|
||||
};
|
||||
#endif
|
||||
|
||||
#include "pios_bmp085.h"
|
||||
static const struct pios_bmp085_cfg pios_bmp085_cfg = {
|
||||
.drdy = {
|
||||
.gpio = GPIOC,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_2,
|
||||
.GPIO_Speed = GPIO_Speed_100MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IN,
|
||||
.GPIO_OType = GPIO_OType_OD,
|
||||
.GPIO_PuPd = GPIO_PuPd_NOPULL,
|
||||
},
|
||||
},
|
||||
.eoc_exti = {
|
||||
// .pin_source = GPIO_PinSource2,
|
||||
// .port_source = GPIO_PortSourceGPIOC,
|
||||
.init = {
|
||||
.EXTI_Line = EXTI_Line2, // matches above GPIO pin
|
||||
.EXTI_Mode = EXTI_Mode_Interrupt,
|
||||
.EXTI_Trigger = EXTI_Trigger_Rising,
|
||||
.EXTI_LineCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.eoc_irq = {
|
||||
.init = {
|
||||
.NVIC_IRQChannel = EXTI15_10_IRQn,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.xclr = {
|
||||
.gpio = GPIOC,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_1,
|
||||
.GPIO_Speed = GPIO_Speed_100MHz,
|
||||
.GPIO_Mode = GPIO_Mode_OUT,
|
||||
.GPIO_OType = GPIO_OType_PP,
|
||||
.GPIO_PuPd = GPIO_PuPd_NOPULL,
|
||||
},
|
||||
},
|
||||
.oversampling = 3,
|
||||
};
|
||||
|
||||
/**
|
||||
* PIOS_Board_Init()
|
||||
@ -664,8 +701,8 @@ void PIOS_Board_Init(void) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
|
||||
PIOS_BMP085_Init();
|
||||
PIOS_HMC5883_Init(&pios_hmc5883_mag_cfg);
|
||||
PIOS_BMP085_Init(&pios_bmp085_cfg);
|
||||
PIOS_HMC5883_Init(&pios_hmc5883_cfg);
|
||||
|
||||
if (PIOS_I2C_Init(&pios_i2c_gyro_adapter_id, &pios_i2c_gyro_adapter_cfg)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
|
@ -180,12 +180,12 @@ SRC += $(PIOSSTM32F10X)/pios_usb_hid_desc.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_prop.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_bmp085.c
|
||||
|
||||
## PIOS Hardware (Common)
|
||||
SRC += $(PIOSCOMMON)/pios_crc.c
|
||||
SRC += $(PIOSCOMMON)/pios_sdcard.c
|
||||
SRC += $(PIOSCOMMON)/pios_com.c
|
||||
SRC += $(PIOSCOMMON)/pios_bmp085.c
|
||||
SRC += $(PIOSCOMMON)/pios_hcsr04.c
|
||||
SRC += $(PIOSCOMMON)/pios_i2c_esc.c
|
||||
SRC += $(PIOSCOMMON)/pios_bl_helper.c
|
||||
|
@ -105,21 +105,6 @@ extern uint32_t pios_i2c_pres_mag_adapter_id;
|
||||
extern uint32_t pios_i2c_gyro_adapter_id;
|
||||
#define PIOS_I2C_GYRO_ADAPTER (pios_i2c_gyro_adapter_id)
|
||||
|
||||
//------------------------
|
||||
// PIOS_BMP085
|
||||
//------------------------
|
||||
#define PIOS_BMP085_EOC_GPIO_PORT GPIOC
|
||||
#define PIOS_BMP085_EOC_GPIO_PIN GPIO_Pin_2
|
||||
#define PIOS_BMP085_EOC_PORT_SOURCE GPIO_PortSourceGPIOC
|
||||
#define PIOS_BMP085_EOC_PIN_SOURCE GPIO_PinSource2
|
||||
#define PIOS_BMP085_EOC_CLK RCC_APB2Periph_GPIOC
|
||||
#define PIOS_BMP085_EOC_EXTI_LINE EXTI_Line2
|
||||
#define PIOS_BMP085_EOC_IRQn EXTI15_10_IRQn
|
||||
#define PIOS_BMP085_EOC_PRIO PIOS_IRQ_PRIO_LOW
|
||||
#define PIOS_BMP085_XCLR_GPIO_PORT GPIOC
|
||||
#define PIOS_BMP085_XCLR_GPIO_PIN GPIO_Pin_1
|
||||
#define PIOS_BMP085_OVERSAMPLING 3
|
||||
|
||||
//-------------------------
|
||||
// PIOS_USART
|
||||
//
|
||||
|
@ -61,11 +61,8 @@ static int32_t PIOS_BMP085_Write(uint8_t address, uint8_t buffer);
|
||||
/**
|
||||
* Initialise the BMP085 sensor
|
||||
*/
|
||||
void PIOS_BMP085_Init(void)
|
||||
void PIOS_BMP085_Init(const struct pios_bmp085_cfg * cfg)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
EXTI_InitTypeDef EXTI_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
/* Semaphore used by ISR to signal End-Of-Conversion */
|
||||
@ -80,24 +77,13 @@ void PIOS_BMP085_Init(void)
|
||||
RCC_APB2PeriphClockCmd(PIOS_BMP085_EOC_CLK | RCC_APB2Periph_AFIO, ENABLE);
|
||||
|
||||
/* Configure EOC pin as input floating */
|
||||
GPIO_InitStructure.GPIO_Pin = PIOS_BMP085_EOC_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_Init(PIOS_BMP085_EOC_GPIO_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_Init(cfg->drdy.gpio, &cfg->drdy.init);
|
||||
|
||||
/* Configure the End Of Conversion (EOC) interrupt */
|
||||
GPIO_EXTILineConfig(PIOS_BMP085_EOC_PORT_SOURCE, PIOS_BMP085_EOC_PIN_SOURCE);
|
||||
EXTI_InitStructure.EXTI_Line = PIOS_BMP085_EOC_EXTI_LINE;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
|
||||
EXTI_Init(&cfg->eoc_exti.init);
|
||||
|
||||
/* Enable and set EOC EXTI Interrupt to the lowest priority */
|
||||
NVIC_InitStructure.NVIC_IRQChannel = PIOS_BMP085_EOC_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PIOS_BMP085_EOC_PRIO;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
NVIC_Init(&cfg->eoc_irq.init);
|
||||
|
||||
/* Configure XCLR pin as push/pull alternate funtion output */
|
||||
GPIO_InitStructure.GPIO_Pin = PIOS_BMP085_XCLR_GPIO_PIN;
|
293
flight/PiOS/STM32F2xx/pios_bmp085.c
Normal file
293
flight/PiOS/STM32F2xx/pios_bmp085.c
Normal file
@ -0,0 +1,293 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
* @addtogroup PIOS_BMP085 BMP085 Functions
|
||||
* @brief Hardware functions to deal with the altitude pressure sensor
|
||||
* @{
|
||||
*
|
||||
* @file pios_bmp085.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief BMP085 Pressure Sensor Routines
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
******************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* Project Includes */
|
||||
// TODO: Clean this up. Getting around old constant.
|
||||
#define PIOS_BMP085_OVERSAMPLING oversampling
|
||||
|
||||
#include "pios.h"
|
||||
|
||||
#if defined(PIOS_INCLUDE_BMP085)
|
||||
#if !defined(PIOS_INCLUDE_EXTI)
|
||||
#error PIOS_EXTI Must be included in the project!
|
||||
#endif /* PIOS_INCLUDE_EXTI */
|
||||
|
||||
/* Glocal Variables */
|
||||
ConversionTypeTypeDef CurrentRead;
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
xSemaphoreHandle PIOS_BMP085_EOC;
|
||||
#else
|
||||
int32_t PIOS_BMP085_EOC;
|
||||
#endif
|
||||
|
||||
/* Local Variables */
|
||||
static BMP085CalibDataTypeDef CalibData;
|
||||
|
||||
/* Straight from the datasheet */
|
||||
static int32_t X1, X2, X3, B3, B5, B6, P;
|
||||
static uint32_t B4, B7;
|
||||
static volatile uint16_t RawTemperature;
|
||||
static volatile uint32_t RawPressure;
|
||||
static volatile uint32_t Pressure;
|
||||
static volatile uint16_t Temperature;
|
||||
|
||||
static int32_t PIOS_BMP085_Read(uint8_t address, uint8_t * buffer, uint8_t len);
|
||||
static int32_t PIOS_BMP085_Write(uint8_t address, uint8_t buffer);
|
||||
|
||||
// Move into proper driver structure with cfg stored
|
||||
static uint32_t oversampling;
|
||||
|
||||
/**
|
||||
* Initialise the BMP085 sensor
|
||||
*/
|
||||
void PIOS_BMP085_Init(const struct pios_bmp085_cfg * cfg)
|
||||
{
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
/* Semaphore used by ISR to signal End-Of-Conversion */
|
||||
vSemaphoreCreateBinary(PIOS_BMP085_EOC);
|
||||
/* Must start off empty so that first transfer waits for EOC */
|
||||
xSemaphoreTake(PIOS_BMP085_EOC, portMAX_DELAY);
|
||||
#else
|
||||
PIOS_BMP085_EOC = 0;
|
||||
#endif
|
||||
|
||||
/* Configure EOC pin as input floating */
|
||||
GPIO_Init(cfg->drdy.gpio, &cfg->drdy.init);
|
||||
|
||||
/* Configure the End Of Conversion (EOC) interrupt */
|
||||
EXTI_Init(&cfg->eoc_exti.init);
|
||||
|
||||
/* Enable and set EOC EXTI Interrupt to the lowest priority */
|
||||
NVIC_Init(&cfg->eoc_irq.init);
|
||||
|
||||
oversampling = cfg->oversampling;
|
||||
|
||||
/* Configure anothing GPIO pin pin as input floating */
|
||||
/* WHAT DID THIS DO?
|
||||
GPIO_Init(cfg->drdy.gpio, &cfg->drdy.init);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = PIOS_BMP085_XCLR_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init(PIOS_BMP085_XCLR_GPIO_PORT, &GPIO_InitStructure);
|
||||
*/
|
||||
/* Read all 22 bytes of calibration data in one transfer, this is a very optimized way of doing things */
|
||||
uint8_t Data[BMP085_CALIB_LEN];
|
||||
while (PIOS_BMP085_Read(BMP085_CALIB_ADDR, Data, BMP085_CALIB_LEN) != 0)
|
||||
continue;
|
||||
|
||||
/* Parameters AC1-AC6 */
|
||||
CalibData.AC1 = (Data[0] << 8) | Data[1];
|
||||
CalibData.AC2 = (Data[2] << 8) | Data[3];
|
||||
CalibData.AC3 = (Data[4] << 8) | Data[5];
|
||||
CalibData.AC4 = (Data[6] << 8) | Data[7];
|
||||
CalibData.AC5 = (Data[8] << 8) | Data[9];
|
||||
CalibData.AC6 = (Data[10] << 8) | Data[11];
|
||||
|
||||
/* Parameters B1, B2 */
|
||||
CalibData.B1 = (Data[12] << 8) | Data[13];
|
||||
CalibData.B2 = (Data[14] << 8) | Data[15];
|
||||
|
||||
/* Parameters MB, MC, MD */
|
||||
CalibData.MB = (Data[16] << 8) | Data[17];
|
||||
CalibData.MC = (Data[18] << 8) | Data[19];
|
||||
CalibData.MD = (Data[20] << 8) | Data[21];
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the ADC conversion
|
||||
* \param[in] PresOrTemp BMP085_PRES_ADDR or BMP085_TEMP_ADDR
|
||||
* \return Raw ADC value
|
||||
*/
|
||||
void PIOS_BMP085_StartADC(ConversionTypeTypeDef Type)
|
||||
{
|
||||
/* Start the conversion */
|
||||
if (Type == TemperatureConv) {
|
||||
while (PIOS_BMP085_Write(BMP085_CTRL_ADDR, BMP085_TEMP_ADDR) != 0)
|
||||
continue;
|
||||
} else if (Type == PressureConv) {
|
||||
while (PIOS_BMP085_Write(BMP085_CTRL_ADDR, BMP085_PRES_ADDR) != 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
CurrentRead = Type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the ADC conversion value (once ADC conversion has completed)
|
||||
* \param[in] PresOrTemp BMP085_PRES_ADDR or BMP085_TEMP_ADDR
|
||||
* \return Raw ADC value
|
||||
*/
|
||||
void PIOS_BMP085_ReadADC(void)
|
||||
{
|
||||
uint8_t Data[3];
|
||||
Data[0] = 0;
|
||||
Data[1] = 0;
|
||||
Data[2] = 0;
|
||||
|
||||
/* Read and store the 16bit result */
|
||||
if (CurrentRead == TemperatureConv) {
|
||||
/* Read the temperature conversion */
|
||||
while (PIOS_BMP085_Read(BMP085_ADC_MSB, Data, 2) != 0)
|
||||
continue;
|
||||
RawTemperature = ((Data[0] << 8) | Data[1]);
|
||||
|
||||
X1 = (RawTemperature - CalibData.AC6) * CalibData.AC5 >> 15;
|
||||
X2 = ((int32_t) CalibData.MC << 11) / (X1 + CalibData.MD);
|
||||
B5 = X1 + X2;
|
||||
Temperature = (B5 + 8) >> 4;
|
||||
} else {
|
||||
/* Read the pressure conversion */
|
||||
while (PIOS_BMP085_Read(BMP085_ADC_MSB, Data, 3) != 0)
|
||||
continue;
|
||||
RawPressure = ((Data[0] << 16) | (Data[1] << 8) | Data[2]) >> (8 - oversampling);
|
||||
|
||||
B6 = B5 - 4000;
|
||||
X1 = (CalibData.B2 * (B6 * B6 >> 12)) >> 11;
|
||||
X2 = CalibData.AC2 * B6 >> 11;
|
||||
X3 = X1 + X2;
|
||||
B3 = ((((int32_t) CalibData.AC1 * 4 + X3) << oversampling) + 2) >> 2;
|
||||
X1 = CalibData.AC3 * B6 >> 13;
|
||||
X2 = (CalibData.B1 * (B6 * B6 >> 12)) >> 16;
|
||||
X3 = ((X1 + X2) + 2) >> 2;
|
||||
B4 = (CalibData.AC4 * (uint32_t) (X3 + 32768)) >> 15;
|
||||
B7 = ((uint32_t) RawPressure - B3) * (50000 >> oversampling);
|
||||
P = B7 < 0x80000000 ? (B7 * 2) / B4 : (B7 / B4) * 2;
|
||||
|
||||
X1 = (P >> 8) * (P >> 8);
|
||||
X1 = (X1 * 3038) >> 16;
|
||||
X2 = (-7357 * P) >> 16;
|
||||
Pressure = P + ((X1 + X2 + 3791) >> 4);
|
||||
}
|
||||
}
|
||||
|
||||
int16_t PIOS_BMP085_GetTemperature(void)
|
||||
{
|
||||
return Temperature;
|
||||
}
|
||||
|
||||
int32_t PIOS_BMP085_GetPressure(void)
|
||||
{
|
||||
return Pressure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads one or more bytes into a buffer
|
||||
* \param[in] address BMP085 register address (depends on size)
|
||||
* \param[out] buffer destination buffer
|
||||
* \param[in] len number of bytes which should be read
|
||||
* \return 0 if operation was successful
|
||||
* \return -1 if error during I2C transfer
|
||||
*/
|
||||
int32_t PIOS_BMP085_Read(uint8_t address, uint8_t * buffer, uint8_t len)
|
||||
{
|
||||
uint8_t addr_buffer[] = {
|
||||
address,
|
||||
};
|
||||
|
||||
const struct pios_i2c_txn txn_list[] = {
|
||||
{
|
||||
.info = __func__,
|
||||
.addr = BMP085_I2C_ADDR,
|
||||
.rw = PIOS_I2C_TXN_WRITE,
|
||||
.len = sizeof(addr_buffer),
|
||||
.buf = addr_buffer,
|
||||
}
|
||||
,
|
||||
{
|
||||
.info = __func__,
|
||||
.addr = BMP085_I2C_ADDR,
|
||||
.rw = PIOS_I2C_TXN_READ,
|
||||
.len = len,
|
||||
.buf = buffer,
|
||||
}
|
||||
};
|
||||
|
||||
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)) ? 0 : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes one or more bytes to the BMP085
|
||||
* \param[in] address Register address
|
||||
* \param[in] buffer source buffer
|
||||
* \return 0 if operation was successful
|
||||
* \return -1 if error during I2C transfer
|
||||
*/
|
||||
int32_t PIOS_BMP085_Write(uint8_t address, uint8_t buffer)
|
||||
{
|
||||
uint8_t data[] = {
|
||||
address,
|
||||
buffer,
|
||||
};
|
||||
|
||||
const struct pios_i2c_txn txn_list[] = {
|
||||
{
|
||||
.info = __func__,
|
||||
.addr = BMP085_I2C_ADDR,
|
||||
.rw = PIOS_I2C_TXN_WRITE,
|
||||
.len = sizeof(data),
|
||||
.buf = data,
|
||||
}
|
||||
,
|
||||
};
|
||||
|
||||
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)) ? 0 : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Run self-test operation.
|
||||
* \return 0 if self-test succeed, -1 if failed
|
||||
*/
|
||||
int32_t PIOS_BMP085_Test()
|
||||
{
|
||||
// TODO: Is there a better way to test this than just checking that pressure/temperature has changed?
|
||||
int32_t cur_value = 0;
|
||||
|
||||
if(PIOS_BMP085_Read(BMP085_ADC_MSB, (uint8_t *) &cur_value, 1) != 0)
|
||||
return -1;
|
||||
return 0;
|
||||
|
||||
cur_value = Temperature;
|
||||
PIOS_BMP085_StartADC(TemperatureConv);
|
||||
PIOS_DELAY_WaitmS(5);
|
||||
PIOS_BMP085_ReadADC();
|
||||
if (cur_value == Temperature)
|
||||
return -1;
|
||||
|
||||
cur_value=Pressure;
|
||||
PIOS_BMP085_StartADC(PressureConv);
|
||||
PIOS_DELAY_WaitmS(26);
|
||||
PIOS_BMP085_ReadADC();
|
||||
if (cur_value == Pressure)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* PIOS_INCLUDE_BMP085 */
|
@ -31,6 +31,8 @@
|
||||
#ifndef PIOS_BMP085_H
|
||||
#define PIOS_BMP085_H
|
||||
|
||||
#include <pios.h>
|
||||
|
||||
/* BMP085 Addresses */
|
||||
#define BMP085_I2C_ADDR 0x77
|
||||
#define BMP085_CALIB_ADDR 0xAA
|
||||
@ -69,8 +71,17 @@ extern xSemaphoreHandle PIOS_BMP085_EOC;
|
||||
extern int32_t PIOS_BMP085_EOC;
|
||||
#endif
|
||||
|
||||
|
||||
struct pios_bmp085_cfg {
|
||||
struct stm32_gpio drdy;
|
||||
struct stm32_gpio xclr;
|
||||
struct stm32_exti eoc_exti;
|
||||
struct stm32_irq eoc_irq;
|
||||
uint32_t oversampling;
|
||||
};
|
||||
|
||||
/* Public Functions */
|
||||
extern void PIOS_BMP085_Init(void);
|
||||
extern void PIOS_BMP085_Init(const struct pios_bmp085_cfg * cfg);
|
||||
extern void PIOS_BMP085_StartADC(ConversionTypeTypeDef Type);
|
||||
extern void PIOS_BMP085_ReadADC(void);
|
||||
extern int16_t PIOS_BMP085_GetTemperature(void);
|
||||
|
@ -2859,6 +2859,8 @@
|
||||
65D1FBD313F4FF1D006374A6 /* STM32F2xx_INS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STM32F2xx_INS.h; sourceTree = "<group>"; };
|
||||
65D1FBD413F504C9006374A6 /* pios_hmc5883.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_hmc5883.h; sourceTree = "<group>"; };
|
||||
65D1FBD613F50CD5006374A6 /* pios_hmc5883.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_hmc5883.c; sourceTree = "<group>"; };
|
||||
65D1FBD713F5146F006374A6 /* pios_bmp085.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_bmp085.c; sourceTree = "<group>"; };
|
||||
65D1FBD813F51865006374A6 /* pios_bmp085.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_bmp085.c; sourceTree = "<group>"; };
|
||||
65D2CA841248F9A400B1E7D6 /* mixersettings.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = mixersettings.xml; sourceTree = "<group>"; };
|
||||
65D2CA851248F9A400B1E7D6 /* mixerstatus.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = mixerstatus.xml; sourceTree = "<group>"; };
|
||||
65DEA78513F0FE6000095B06 /* stm32f2xx_conf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = stm32f2xx_conf.h; sourceTree = "<group>"; };
|
||||
@ -2932,7 +2934,6 @@
|
||||
65E8EF6B11EEA61E00BBF654 /* test_cpuload.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = test_cpuload.c; path = ../../OpenPilot/Tests/test_cpuload.c; sourceTree = SOURCE_ROOT; };
|
||||
65E8EF6C11EEA61E00BBF654 /* test_i2c_PCF8570.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = test_i2c_PCF8570.c; path = ../../OpenPilot/Tests/test_i2c_PCF8570.c; sourceTree = SOURCE_ROOT; };
|
||||
65E8EF6D11EEA61E00BBF654 /* test_uavobjects.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = test_uavobjects.c; path = ../../OpenPilot/Tests/test_uavobjects.c; sourceTree = SOURCE_ROOT; };
|
||||
65E8F03111EFF25C00BBF654 /* pios_bmp085.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pios_bmp085.c; path = ../../PiOS/Common/pios_bmp085.c; sourceTree = SOURCE_ROOT; };
|
||||
65E8F03211EFF25C00BBF654 /* pios_com.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pios_com.c; path = ../../PiOS/Common/pios_com.c; sourceTree = SOURCE_ROOT; };
|
||||
65E8F03311EFF25C00BBF654 /* pios_hmc5843.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pios_hmc5843.c; path = ../../PiOS/Common/pios_hmc5843.c; sourceTree = SOURCE_ROOT; };
|
||||
65E8F03411EFF25C00BBF654 /* pios_opahrs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pios_opahrs.c; path = ../../PiOS/Common/pios_opahrs.c; sourceTree = SOURCE_ROOT; };
|
||||
@ -3726,6 +3727,7 @@
|
||||
6560A37B13EE26B700105DA5 /* link_STM32F2xx_INS_sections.ld */,
|
||||
6560A37C13EE26B700105DA5 /* pios_adc.c */,
|
||||
65DEA78813F111EA00095B06 /* pios_bma180.c */,
|
||||
65D1FBD713F5146F006374A6 /* pios_bmp085.c */,
|
||||
6560A37D13EE26B700105DA5 /* pios_debug.c */,
|
||||
6560A37E13EE26B700105DA5 /* pios_delay.c */,
|
||||
6560A37F13EE26B700105DA5 /* pios_exti.c */,
|
||||
@ -8166,7 +8168,6 @@
|
||||
65E8F03011EFF25C00BBF654 /* Common */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
65E8F03111EFF25C00BBF654 /* pios_bmp085.c */,
|
||||
65E8F03211EFF25C00BBF654 /* pios_com.c */,
|
||||
65E8F03311EFF25C00BBF654 /* pios_hmc5843.c */,
|
||||
65E8F03411EFF25C00BBF654 /* pios_opahrs.c */,
|
||||
@ -8240,6 +8241,7 @@
|
||||
65E8F05811EFF25C00BBF654 /* STM32F10x */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
65D1FBD813F51865006374A6 /* pios_bmp085.c */,
|
||||
6560A39D13EE277E00105DA5 /* pios_iap.c */,
|
||||
6560A39E13EE277E00105DA5 /* pios_sbus.c */,
|
||||
6560A38E13EE270C00105DA5 /* link_STM3210E_INS_BL_sections.ld */,
|
||||
|
Loading…
Reference in New Issue
Block a user