mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-21 13:28:58 +01:00
Move BMA180 driver to common architecture style.
This commit is contained in:
parent
1dc08e5cf7
commit
9d76efa2aa
@ -587,6 +587,41 @@ 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,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_4,
|
||||
.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_PinSource8,
|
||||
// .port_source = GPIO_PortSourceGPIOB,
|
||||
.init = {
|
||||
.EXTI_Line = EXTI_Line4, // matches above GPIO pin
|
||||
.EXTI_Mode = EXTI_Mode_Interrupt,
|
||||
.EXTI_Trigger = EXTI_Trigger_Rising,
|
||||
.EXTI_LineCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.eoc_irq = {
|
||||
.init = {
|
||||
.NVIC_IRQChannel = EXTI4_IRQn,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* PIOS_Board_Init()
|
||||
* initializes all the core subsystems on this specific hardware
|
||||
@ -625,33 +660,24 @@ void PIOS_Board_Init(void) {
|
||||
#endif /* PIOS_INCLUDE_COM_AUX */
|
||||
#endif /* PIOS_INCLUDE_COM */
|
||||
|
||||
#if defined (PIOS_INCLUDE_I2C)
|
||||
if (PIOS_I2C_Init(&pios_i2c_pres_mag_adapter_id, &pios_i2c_pres_mag_adapter_cfg)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
#if defined (PIOS_INCLUDE_BMP085)
|
||||
|
||||
PIOS_BMP085_Init();
|
||||
#endif /* PIOS_INCLUDE_BMP085 */
|
||||
#if defined (PIOS_INCLUDE_HMC5883)
|
||||
PIOS_HMC5883_Init(&pios_hmc5883_mag_cfg);
|
||||
#endif /* PIOS_INCLUDE_HMC5883 */
|
||||
|
||||
#if defined(PIOS_INCLUDE_IMU3000)
|
||||
if (PIOS_I2C_Init(&pios_i2c_gyro_adapter_id, &pios_i2c_gyro_adapter_cfg)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
PIOS_IMU3000_Init();
|
||||
#endif /* PIOS_INCLUDE_IMU3000 */
|
||||
#endif /* PIOS_INCLUDE_I2C */
|
||||
|
||||
#if defined(PIOS_INCLUDE_SPI)
|
||||
/* Set up the SPI interface to the accelerometer*/
|
||||
if (PIOS_SPI_Init(&pios_spi_accel_id, &pios_spi_accel_cfg)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
|
||||
PIOS_BMA180_Attach(pios_spi_accel_id);
|
||||
PIOS_BMA180_Init();
|
||||
PIOS_BMA180_Init(&pios_bma180_cfg);
|
||||
|
||||
|
||||
/* Set up the SPI interface to the OP board */
|
||||
@ -662,7 +688,6 @@ void PIOS_Board_Init(void) {
|
||||
}
|
||||
|
||||
AhrsConnect(pios_spi_op_id);
|
||||
#endif /* PIOS_INCLUDE_SPI */
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,21 +171,6 @@ extern uint32_t pios_com_aux_id;
|
||||
#define PIOS_GPIO_CLKS { PIOS_GPIO_1_GPIO_CLK }
|
||||
#define PIOS_GPIO_NUM 1
|
||||
|
||||
//------------------------
|
||||
// BMA180
|
||||
//------------------------
|
||||
#define PIOS_BMA180_ENABLE PIOS_SPI_RC_PinSet(PIOS_SPI_ACCEL,0)
|
||||
#define PIOS_BMA180_DISABLE PIOS_SPI_RC_PinSet(PIOS_SPI_ACCEL,1)
|
||||
#define PIOS_BMA180_DRDY_GPIO_PORT GPIOC
|
||||
#define PIOS_BMA180_DRDY_GPIO_PIN GPIO_Pin_4
|
||||
#define PIOS_BMA180_DRDY_PORT_SOURCE GPIO_PortSourceGPIOC
|
||||
#define PIOS_BMA180_DRDY_PIN_SOURCE GPIO_PinSource4
|
||||
#define PIOS_BMA180_DRDY_CLK RCC_APB2Periph_GPIOC
|
||||
#define PIOS_BMA180_DRDY_EXTI_LINE EXTI_Line4
|
||||
#define PIOS_BMA180_DRDY_IRQn EXTI4_IRQn
|
||||
#define PIOS_BMA180_DRDY_PRIO PIOS_IRQ_PRIO_LOW
|
||||
|
||||
|
||||
//------------------------
|
||||
// PIOS_IMU3000
|
||||
//------------------------
|
||||
|
@ -47,39 +47,20 @@ volatile bool pios_bma180_data_ready = false;
|
||||
static int16_t pios_bma180_buffer[PIOS_BMA180_MAX_DOWNSAMPLE * 3];
|
||||
static t_fifo_buffer pios_bma180_fifo;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize with good default settings
|
||||
*/
|
||||
void PIOS_BMA180_Init()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
EXTI_InitTypeDef EXTI_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
/* Enable DRDY GPIO clock */
|
||||
RCC_APB2PeriphClockCmd(PIOS_BMA180_DRDY_CLK | RCC_APB2Periph_AFIO, ENABLE);
|
||||
|
||||
void PIOS_BMA180_Init(const struct pios_bma180_cfg * cfg)
|
||||
{
|
||||
/* Configure EOC pin as input floating */
|
||||
GPIO_InitStructure.GPIO_Pin = PIOS_BMA180_DRDY_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(PIOS_BMA180_DRDY_GPIO_PORT, &GPIO_InitStructure);
|
||||
GPIO_Init(cfg->drdy.gpio, &cfg->drdy.init);
|
||||
|
||||
/* Configure the End Of Conversion (EOC) interrupt */
|
||||
GPIO_EXTILineConfig(PIOS_BMA180_DRDY_PORT_SOURCE, PIOS_BMA180_DRDY_PIN_SOURCE);
|
||||
EXTI_InitStructure.EXTI_Line = PIOS_BMA180_DRDY_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_BMA180_DRDY_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PIOS_BMA180_DRDY_PRIO;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
NVIC_Init(&cfg->eoc_irq.init);
|
||||
|
||||
pios_bma180_data_ready = false;
|
||||
|
||||
@ -100,7 +81,7 @@ int32_t PIOS_BMA180_ClaimBus()
|
||||
{
|
||||
if(PIOS_SPI_ClaimBus(PIOS_SPI_ACCEL) != 0)
|
||||
return -1;
|
||||
PIOS_BMA180_ENABLE;
|
||||
PIOS_SPI_RC_PinSet(PIOS_SPI_ACCEL,0,0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -110,7 +91,7 @@ int32_t PIOS_BMA180_ClaimBus()
|
||||
*/
|
||||
int32_t PIOS_BMA180_ReleaseBus()
|
||||
{
|
||||
PIOS_BMA180_DISABLE;
|
||||
PIOS_SPI_RC_PinSet(PIOS_SPI_ACCEL,0,1);
|
||||
return PIOS_SPI_ReleaseBus(PIOS_SPI_ACCEL);
|
||||
}
|
||||
|
||||
|
@ -86,9 +86,16 @@ struct pios_bma180_data {
|
||||
int16_t z;
|
||||
};
|
||||
|
||||
|
||||
struct pios_bma180_cfg {
|
||||
struct stm32_gpio drdy;
|
||||
struct stm32_exti eoc_exti;
|
||||
struct stm32_irq eoc_irq;
|
||||
};
|
||||
|
||||
/* Public Functions */
|
||||
void PIOS_BMA180_Init(const struct pios_bma180_cfg * cfg);
|
||||
void PIOS_BMA180_Attach(uint32_t spi_id);
|
||||
void PIOS_BMA180_Init();
|
||||
float PIOS_BMA180_GetScale();
|
||||
int32_t PIOS_BMA180_ReadAccels(int16_t * data);
|
||||
int32_t PIOS_BMA180_Test();
|
||||
|
@ -8186,12 +8186,12 @@
|
||||
65E8F03811EFF25C00BBF654 /* inc */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
65DEA78613F1118400095B06 /* pios_bma180.h */,
|
||||
65DEA78513F0FE6000095B06 /* stm32f2xx_conf.h */,
|
||||
6528CCE212E40F6700CF5144 /* pios_adxl345.h */,
|
||||
65E8C745139A6D1A00E1F979 /* pios_crc.h */,
|
||||
65E8F03A11EFF25C00BBF654 /* pios_adc.h */,
|
||||
65E6E09912E037C800058553 /* pios_adc_priv.h */,
|
||||
65DEA78613F1118400095B06 /* pios_bma180.h */,
|
||||
65E8F03B11EFF25C00BBF654 /* pios_bmp085.h */,
|
||||
65E8F03C11EFF25C00BBF654 /* pios_com.h */,
|
||||
65E8F03D11EFF25C00BBF654 /* pios_com_priv.h */,
|
||||
|
Loading…
x
Reference in New Issue
Block a user