1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

PiOS F2: Move IMU3000 to device dependent :(. Now they all are. Need to

abstract as much as possible out since init is almost identicalc and protocol
COULD be device independent.
This commit is contained in:
James Cotton 2011-08-12 03:23:20 -05:00
parent 8c1dd7b929
commit f247112090
6 changed files with 75 additions and 73 deletions

View File

@ -55,10 +55,10 @@ PIOS = ../PiOS
PIOSINC = $(PIOS)/inc
FLIGHTLIB = ../Libraries
FLIGHTLIBINC = ../Libraries/inc
PIOSSTM32FXX = $(PIOS)/STM32F2xx
PIOSSTM32F2XX = $(PIOS)/STM32F2xx
PIOSCOMMON = $(PIOS)/Common
PIOSBOARDS = $(PIOS)/Boards
APPLIBDIR = $(PIOSSTM32FXX)/Libraries
APPLIBDIR = $(PIOSSTM32F2XX)/Libraries
STMLIBDIR = $(APPLIBDIR)
STMSPDDIR = $(STMLIBDIR)/STM32F2xx_StdPeriph_Driver
STMSPDSRCDIR = $(STMSPDDIR)/src
@ -89,25 +89,26 @@ SRC += $(BOOT)/ahrs_slave_test.c
SRC += $(BOOT)/ahrs_spi_program.c
## PIOS Hardware (STM32F2xx)
SRC += $(PIOSSTM32FXX)/pios_sys.c
SRC += $(PIOSSTM32FXX)/pios_led.c
SRC += $(PIOSSTM32FXX)/pios_delay.c
SRC += $(PIOSSTM32FXX)/pios_usart.c
SRC += $(PIOSSTM32FXX)/pios_irq.c
SRC += $(PIOSSTM32FXX)/pios_i2c.c
SRC += $(PIOSSTM32FXX)/pios_debug.c
SRC += $(PIOSSTM32FXX)/pios_gpio.c
SRC += $(PIOSSTM32FXX)/pios_spi.c
#SRC += $(PIOSSTM32FXX)/pios_exti.c
SRC += $(PIOSSTM32FXX)/pios_iap.c
SRC += $(PIOSSTM32FXX)/pios_bma180.c
SRC += $(PIOSSTM32FXX)/pios_hmc5883.c
SRC += $(PIOSSTM32FXX)/pios_bmp085.c
SRC += $(PIOSSTM32F2XX)/pios_sys.c
SRC += $(PIOSSTM32F2XX)/pios_led.c
SRC += $(PIOSSTM32F2XX)/pios_delay.c
SRC += $(PIOSSTM32F2XX)/pios_usart.c
SRC += $(PIOSSTM32F2XX)/pios_irq.c
SRC += $(PIOSSTM32F2XX)/pios_i2c.c
SRC += $(PIOSSTM32F2XX)/pios_debug.c
#SRC += $(PIOSSTM32F2XX)/pios_gpio.c
SRC += $(PIOSSTM32F2XX)/pios_spi.c
#SRC += $(PIOSSTM32F2XX)/pios_exti.c
SRC += $(PIOSSTM32F2XX)/pios_iap.c
SRC += $(PIOSSTM32F2XX)/pios_bma180.c
SRC += $(PIOSSTM32F2XX)/pios_hmc5883.c
SRC += $(PIOSSTM32F2XX)/pios_bmp085.c
SRC += $(PIOSSTM32F2XX)/pios_imu3000.c
## PIOS Hardware (Common)
SRC += $(PIOSCOMMON)/pios_com.c
SRC += $(PIOSCOMMON)/printf-stdarg.c
SRC += $(PIOSCOMMON)/pios_imu3000.c
SRC += $(PIOSCOMMON)/pios_bl_helper.c
## CMSIS for STM32
@ -151,7 +152,7 @@ CPPSRCARM =
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC = $(PIOSSTM32FXX)/startup_stm32f2xx.S
ASRC = $(PIOSSTM32F2XX)/startup_stm32f2xx.S
# List Assembler source files here which must be assembled in ARM-Mode..
ASRCARM =
@ -161,7 +162,7 @@ ASRCARM =
EXTRAINCDIRS += $(PIOS)
EXTRAINCDIRS += $(PIOSINC)
EXTRAINCDIRS += $(FLIGHTLIBINC)
EXTRAINCDIRS += $(PIOSSTM32FXX)
EXTRAINCDIRS += $(PIOSSTM32F2XX)
EXTRAINCDIRS += $(PIOSCOMMON)
EXTRAINCDIRS += $(PIOSBOARDS)
EXTRAINCDIRS += $(STMSPDINCDIR)

View File

@ -616,6 +616,38 @@ static const struct pios_bma180_cfg pios_bma180_cfg = {
},
};
#include "pios_imu3000.h"
static const struct pios_imu3000_cfg pios_imu3000_cfg = {
.drdy = {
.gpio = GPIOB,
.init = {
.GPIO_Pin = GPIO_Pin_1,
.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_PinSource1,
// .port_source = GPIO_PortSourceGPIOB,
.init = {
.EXTI_Line = EXTI_Line1, // matches above GPIO pin
.EXTI_Mode = EXTI_Mode_Interrupt,
.EXTI_Trigger = EXTI_Trigger_Rising,
.EXTI_LineCmd = ENABLE,
},
},
.eoc_irq = {
.init = {
.NVIC_IRQChannel = EXTI1_IRQn,
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
.NVIC_IRQChannelSubPriority = 0,
.NVIC_IRQChannelCmd = ENABLE,
},
},
};
#include "pios_bmp085.h"
static const struct pios_bmp085_cfg pios_bmp085_cfg = {
.drdy = {
@ -707,7 +739,7 @@ void PIOS_Board_Init(void) {
if (PIOS_I2C_Init(&pios_i2c_gyro_adapter_id, &pios_i2c_gyro_adapter_cfg)) {
PIOS_DEBUG_Assert(0);
}
PIOS_IMU3000_Init();
PIOS_IMU3000_Init(&pios_imu3000_cfg);
/* Set up the SPI interface to the accelerometer*/
if (PIOS_SPI_Init(&pios_spi_accel_id, &pios_spi_accel_cfg)) {

View File

@ -143,32 +143,6 @@ extern uint32_t pios_com_aux_id;
//-------------------------
//-------------------------
// GPIO
// Not used, but pios_gpio.c expects something
//-------------------------
#define PIOS_GPIO_1_PORT GPIOA
#define PIOS_GPIO_1_PIN GPIO_Pin_1
#define PIOS_GPIO_1_GPIO_CLK RCC_APB2Periph_GPIOA
#define PIOS_GPIO_PORTS { PIOS_GPIO_1_PORT }
#define PIOS_GPIO_PINS { PIOS_GPIO_1_PIN }
#define PIOS_GPIO_CLKS { PIOS_GPIO_1_GPIO_CLK }
#define PIOS_GPIO_NUM 1
//------------------------
// PIOS_IMU3000
//------------------------
#define PIOS_IMU3000_INT_GPIO_PORT GPIOB
#define PIOS_IMU3000_INT_GPIO_PIN GPIO_Pin_1
#define PIOS_IMU3000_INT_PORT_SOURCE GPIO_PortSourceGPIOB
#define PIOS_IMU3000_INT_PIN_SOURCE GPIO_PinSource1
#define PIOS_IMU3000_INT_CLK RCC_APB2Periph_GPIOB
#define PIOS_IMU3000_INT_EXTI_LINE EXTI_Line1
#define PIOS_IMU3000_INT_IRQn EXTI1_IRQn
#define PIOS_IMU3000_INT_PRIO PIOS_IRQ_PRIO_HIGH
#endif /* STM3210E_INS_H_ */

View File

@ -57,34 +57,17 @@ static int32_t PIOS_IMU3000_Write(uint8_t address, uint8_t buffer);
* @brief Initialize the IMU3000 3-axis gyro sensor.
* @return none
*/
void PIOS_IMU3000_Init(void)
void PIOS_IMU3000_Init(const struct pios_imu3000_cfg * cfg)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable INT GPIO clock */
RCC_APB2PeriphClockCmd(PIOS_IMU3000_INT_CLK | RCC_APB2Periph_AFIO, ENABLE);
/* Configure IMU3000 interrupt pin as input floating */
GPIO_InitStructure.GPIO_Pin = PIOS_IMU3000_INT_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(PIOS_IMU3000_INT_GPIO_PORT, &GPIO_InitStructure);
/* Configure EOC pin as input floating */
GPIO_Init(cfg->drdy.gpio, &cfg->drdy.init);
/* Configure the End Of Conversion (EOC) interrupt */
GPIO_EXTILineConfig(PIOS_IMU3000_INT_PORT_SOURCE, PIOS_IMU3000_INT_PIN_SOURCE);
EXTI_InitStructure.EXTI_Line = PIOS_IMU3000_INT_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);
//GPIO_EXTILineConfig(cfg->eoc_exit.port_source, cfg->eoc_exit.pin_source);
EXTI_Init(&cfg->eoc_exti.init);
/* Enable and set EOC EXTI Interrupt to the lowest priority */
NVIC_InitStructure.NVIC_IRQChannel = PIOS_IMU3000_INT_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PIOS_IMU3000_INT_PRIO;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_Init(&cfg->eoc_irq.init);
/* Configure the IMU3000 Sensor */
PIOS_IMU3000_ConfigTypeDef IMU3000_InitStructure;

View File

@ -33,6 +33,8 @@
#ifndef PIOS_IMU3000_H
#define PIOS_IMU3000_H
#include "pios.h"
/* IMU3000 Addresses */
#define PIOS_IMU3000_I2C_ADDR 0x69
#define PIOS_IMU3000_I2C_READ_ADDR 0xD2
@ -116,8 +118,14 @@ struct pios_imu3000_data {
int16_t z;
};
struct pios_imu3000_cfg {
struct stm32_gpio drdy;
struct stm32_exti eoc_exti;
struct stm32_irq eoc_irq;
};
/* Public Functions */
extern void PIOS_IMU3000_Init(void);
extern void PIOS_IMU3000_Init(const struct pios_imu3000_cfg * cfg);
extern bool PIOS_IMU3000_NewDataAvailable(void);
extern int32_t PIOS_IMU3000_ReadFifo(uint8_t * buffer, uint16_t len);
extern int32_t PIOS_IMU3000_ReadGyros(int16_t * data);

View File

@ -2861,6 +2861,8 @@
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>"; };
65D1FBD913F51AB7006374A6 /* pios_imu3000.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_imu3000.c; sourceTree = "<group>"; };
65D1FBDA13F51AE1006374A6 /* pios_imu3000.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_imu3000.h; 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>"; };
@ -3734,6 +3736,7 @@
6560A38013EE26B700105DA5 /* pios_gpio.c */,
65D1FBD613F50CD5006374A6 /* pios_hmc5883.c */,
6560A38113EE26B700105DA5 /* pios_i2c.c */,
65D1FBD913F51AB7006374A6 /* pios_imu3000.c */,
6560A38213EE26B700105DA5 /* pios_iap.c */,
6560A38313EE26B700105DA5 /* pios_irq.c */,
6560A38413EE26B700105DA5 /* pios_led.c */,
@ -4056,11 +4059,11 @@
65632DF41251650300469B77 /* Boards */ = {
isa = PBXGroup;
children = (
65D1FBD313F4FF1D006374A6 /* STM32F2xx_INS.h */,
65632DF51251650300469B77 /* pios_board.h */,
65632DF71251650300469B77 /* STM3210E_OP.h */,
65632DF61251650300469B77 /* STM32103CB_AHRS.h */,
65E6E06112E031E300058553 /* STM32103CB_CC_Rev1.h */,
65D1FBD313F4FF1D006374A6 /* STM32F2xx_INS.h */,
65E6E06212E031E300058553 /* STM32103CB_PIPXTREME_Rev1.h */,
);
path = Boards;
@ -8206,6 +8209,7 @@
65D1FBD413F504C9006374A6 /* pios_hmc5883.h */,
65E8F04311EFF25C00BBF654 /* pios_i2c.h */,
6526645A122DF972006F9A3C /* pios_i2c_priv.h */,
65D1FBDA13F51AE1006374A6 /* pios_imu3000.h */,
65E8F04411EFF25C00BBF654 /* pios_irq.h */,
65E8F04511EFF25C00BBF654 /* pios_led.h */,
65E8F04611EFF25C00BBF654 /* pios_opahrs.h */,