mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-02 19:29:15 +01:00
Copy the BMP085 back from next
This commit is contained in:
parent
b01d5c6b87
commit
2524662475
@ -111,7 +111,7 @@ static const struct pios_exti_cfg pios_exti_bmp085_cfg __exti_config = {
|
|||||||
/**
|
/**
|
||||||
* Initialise the BMP085 sensor
|
* Initialise the BMP085 sensor
|
||||||
*/
|
*/
|
||||||
void PIOS_BMP085_Init(const struct pios_bmp085_cfg * cfg)
|
void PIOS_BMP085_Init(void)
|
||||||
{
|
{
|
||||||
#ifdef PIOS_BMP085_HAS_GPIOS
|
#ifdef PIOS_BMP085_HAS_GPIOS
|
||||||
|
|
||||||
@ -137,9 +137,11 @@ void PIOS_BMP085_Init(const struct pios_bmp085_cfg * cfg)
|
|||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||||
GPIO_Init(PIOS_BMP085_XCLR_GPIO_PORT, &GPIO_InitStructure);
|
GPIO_Init(PIOS_BMP085_XCLR_GPIO_PORT, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
#endif /* PIOS_BMP085_HAS_GPIOS */
|
||||||
|
|
||||||
/* Read all 22 bytes of calibration data in one transfer, this is a very optimized way of doing things */
|
/* 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];
|
uint8_t Data[BMP085_CALIB_LEN];
|
||||||
while (PIOS_BMP085_Read(BMP085_CALIB_ADDR, Data, BMP085_CALIB_LEN) != 0)
|
while (!PIOS_BMP085_Read(BMP085_CALIB_ADDR, Data, BMP085_CALIB_LEN))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Parameters AC1-AC6 */
|
/* Parameters AC1-AC6 */
|
||||||
@ -169,10 +171,10 @@ void PIOS_BMP085_StartADC(ConversionTypeTypeDef Type)
|
|||||||
{
|
{
|
||||||
/* Start the conversion */
|
/* Start the conversion */
|
||||||
if (Type == TemperatureConv) {
|
if (Type == TemperatureConv) {
|
||||||
while (PIOS_BMP085_Write(BMP085_CTRL_ADDR, BMP085_TEMP_ADDR) != 0)
|
while (!PIOS_BMP085_Write(BMP085_CTRL_ADDR, BMP085_TEMP_ADDR))
|
||||||
continue;
|
continue;
|
||||||
} else if (Type == PressureConv) {
|
} else if (Type == PressureConv) {
|
||||||
while (PIOS_BMP085_Write(BMP085_CTRL_ADDR, BMP085_PRES_ADDR) != 0)
|
while (!PIOS_BMP085_Write(BMP085_CTRL_ADDR, BMP085_PRES_ADDR))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +196,7 @@ void PIOS_BMP085_ReadADC(void)
|
|||||||
/* Read and store the 16bit result */
|
/* Read and store the 16bit result */
|
||||||
if (CurrentRead == TemperatureConv) {
|
if (CurrentRead == TemperatureConv) {
|
||||||
/* Read the temperature conversion */
|
/* Read the temperature conversion */
|
||||||
while (PIOS_BMP085_Read(BMP085_ADC_MSB, Data, 2) != 0)
|
while (!PIOS_BMP085_Read(BMP085_ADC_MSB, Data, 2))
|
||||||
continue;
|
continue;
|
||||||
RawTemperature = ((Data[0] << 8) | Data[1]);
|
RawTemperature = ((Data[0] << 8) | Data[1]);
|
||||||
|
|
||||||
@ -204,7 +206,7 @@ void PIOS_BMP085_ReadADC(void)
|
|||||||
Temperature = (B5 + 8) >> 4;
|
Temperature = (B5 + 8) >> 4;
|
||||||
} else {
|
} else {
|
||||||
/* Read the pressure conversion */
|
/* Read the pressure conversion */
|
||||||
while (PIOS_BMP085_Read(BMP085_ADC_MSB, Data, 3) != 0)
|
while (!PIOS_BMP085_Read(BMP085_ADC_MSB, Data, 3))
|
||||||
continue;
|
continue;
|
||||||
RawPressure = ((Data[0] << 16) | (Data[1] << 8) | Data[2]) >> (8 - BMP085_OVERSAMPLING);
|
RawPressure = ((Data[0] << 16) | (Data[1] << 8) | Data[2]) >> (8 - BMP085_OVERSAMPLING);
|
||||||
|
|
||||||
@ -244,8 +246,10 @@ int32_t PIOS_BMP085_GetPressure(void)
|
|||||||
* \param[in] len number of bytes which should be read
|
* \param[in] len number of bytes which should be read
|
||||||
* \return 0 if operation was successful
|
* \return 0 if operation was successful
|
||||||
* \return -1 if error during I2C transfer
|
* \return -1 if error during I2C transfer
|
||||||
|
* \return -2 if BMP085 blocked by another task (retry it!)
|
||||||
|
* \return -4 if invalid length
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_BMP085_Read(uint8_t address, uint8_t * buffer, uint8_t len)
|
bool PIOS_BMP085_Read(uint8_t address, uint8_t * buffer, uint8_t len)
|
||||||
{
|
{
|
||||||
uint8_t addr_buffer[] = {
|
uint8_t addr_buffer[] = {
|
||||||
address,
|
address,
|
||||||
@ -269,7 +273,7 @@ int32_t PIOS_BMP085_Read(uint8_t address, uint8_t * buffer, uint8_t len)
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list));
|
return PIOS_I2C_Transfer(PIOS_I2C_BMP085_ADAPTER, txn_list, NELEMENTS(txn_list));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -278,8 +282,9 @@ int32_t PIOS_BMP085_Read(uint8_t address, uint8_t * buffer, uint8_t len)
|
|||||||
* \param[in] buffer source buffer
|
* \param[in] buffer source buffer
|
||||||
* \return 0 if operation was successful
|
* \return 0 if operation was successful
|
||||||
* \return -1 if error during I2C transfer
|
* \return -1 if error during I2C transfer
|
||||||
|
* \return -2 if BMP085 blocked by another task (retry it!)
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_BMP085_Write(uint8_t address, uint8_t buffer)
|
bool PIOS_BMP085_Write(uint8_t address, uint8_t buffer)
|
||||||
{
|
{
|
||||||
uint8_t data[] = {
|
uint8_t data[] = {
|
||||||
address,
|
address,
|
||||||
@ -297,37 +302,35 @@ int32_t PIOS_BMP085_Write(uint8_t address, uint8_t buffer)
|
|||||||
,
|
,
|
||||||
};
|
};
|
||||||
|
|
||||||
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list));
|
return PIOS_I2C_Transfer(PIOS_I2C_BMP085_ADAPTER, txn_list, NELEMENTS(txn_list));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Run self-test operation.
|
* @brief Run self-test operation.
|
||||||
* \return 0 if self-test succeed, -1 if failed
|
* \return 0 if self-test failed
|
||||||
|
* \return any non-0 number if test passed
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_BMP085_Test()
|
int32_t PIOS_BMP085_Test()
|
||||||
{
|
{
|
||||||
// TODO: Is there a better way to test this than just checking that pressure/temperature has changed?
|
// TODO: Is there a better way to test this than just checking that pressure/temperature has changed?
|
||||||
|
int32_t passed = 1;
|
||||||
int32_t cur_value = 0;
|
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;
|
cur_value = Temperature;
|
||||||
PIOS_BMP085_StartADC(TemperatureConv);
|
PIOS_BMP085_StartADC(TemperatureConv);
|
||||||
PIOS_DELAY_WaitmS(5);
|
PIOS_DELAY_WaitmS(5);
|
||||||
PIOS_BMP085_ReadADC();
|
PIOS_BMP085_ReadADC();
|
||||||
if (cur_value == Temperature)
|
if (cur_value == Temperature)
|
||||||
return -1;
|
passed = 0;
|
||||||
|
|
||||||
cur_value=Pressure;
|
cur_value=Pressure;
|
||||||
PIOS_BMP085_StartADC(PressureConv);
|
PIOS_BMP085_StartADC(PressureConv);
|
||||||
PIOS_DELAY_WaitmS(26);
|
PIOS_DELAY_WaitmS(26);
|
||||||
PIOS_BMP085_ReadADC();
|
PIOS_BMP085_ReadADC();
|
||||||
if (cur_value == Pressure)
|
if (cur_value == Pressure)
|
||||||
return -1;
|
passed = 0;
|
||||||
|
|
||||||
return 0;
|
return passed;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* PIOS_INCLUDE_BMP085 */
|
#endif /* PIOS_INCLUDE_BMP085 */
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* @{
|
* @{
|
||||||
*
|
*
|
||||||
* @file pios_bmp085.h
|
* @file pios_bmp085.h
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
* @brief BMP085 functions header.
|
* @brief BMP085 functions header.
|
||||||
* @see The GNU Public License (GPL) Version 3
|
* @see The GNU Public License (GPL) Version 3
|
||||||
*
|
*
|
||||||
@ -31,8 +31,6 @@
|
|||||||
#ifndef PIOS_BMP085_H
|
#ifndef PIOS_BMP085_H
|
||||||
#define PIOS_BMP085_H
|
#define PIOS_BMP085_H
|
||||||
|
|
||||||
#include <pios.h>
|
|
||||||
|
|
||||||
/* BMP085 Addresses */
|
/* BMP085 Addresses */
|
||||||
#define BMP085_I2C_ADDR 0x77
|
#define BMP085_I2C_ADDR 0x77
|
||||||
#define BMP085_CALIB_ADDR 0xAA
|
#define BMP085_CALIB_ADDR 0xAA
|
||||||
@ -71,18 +69,14 @@ extern xSemaphoreHandle PIOS_BMP085_EOC;
|
|||||||
extern int32_t PIOS_BMP085_EOC;
|
extern int32_t PIOS_BMP085_EOC;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
struct pios_bmp085_cfg {
|
|
||||||
static const struct pios_exti_cfg * exti_cfg; /* Pointer to the EXTI configuration */
|
|
||||||
uint32_t oversampling;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Public Functions */
|
/* Public Functions */
|
||||||
extern void PIOS_BMP085_Init(const struct pios_bmp085_cfg * cfg);
|
extern void PIOS_BMP085_Init(void);
|
||||||
extern int32_t PIOS_BMP085_StartADC(ConversionTypeTypeDef Type);
|
extern void PIOS_BMP085_StartADC(ConversionTypeTypeDef Type);
|
||||||
extern int32_t PIOS_BMP085_ReadADC(void);
|
extern void PIOS_BMP085_ReadADC(void);
|
||||||
extern int16_t PIOS_BMP085_GetTemperature(void);
|
extern int16_t PIOS_BMP085_GetTemperature(void);
|
||||||
extern int32_t PIOS_BMP085_GetPressure(void);
|
extern int32_t PIOS_BMP085_GetPressure(void);
|
||||||
|
extern bool PIOS_BMP085_Read(uint8_t address, uint8_t * buffer, uint8_t len);
|
||||||
|
extern bool PIOS_BMP085_Write(uint8_t address, uint8_t buffer);
|
||||||
extern int32_t PIOS_BMP085_Test();
|
extern int32_t PIOS_BMP085_Test();
|
||||||
|
|
||||||
#endif /* PIOS_BMP085_H */
|
#endif /* PIOS_BMP085_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user