mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
HMC5883: Update driver for F2. Move to STM32F2xx directory since it is device
dependent. Abstract configuration out of board.h file into a standard board.c structure.
This commit is contained in:
parent
784c7b2646
commit
6310f46705
@ -101,11 +101,11 @@ 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
|
||||
|
||||
## PIOS Hardware (Common)
|
||||
SRC += $(PIOSCOMMON)/pios_com.c
|
||||
SRC += $(PIOSCOMMON)/printf-stdarg.c
|
||||
SRC += $(PIOSCOMMON)/pios_hmc5883.c
|
||||
SRC += $(PIOSCOMMON)/pios_bmp085.c
|
||||
SRC += $(PIOSCOMMON)/pios_imu3000.c
|
||||
SRC += $(PIOSCOMMON)/pios_bl_helper.c
|
||||
|
@ -543,12 +543,50 @@ void PIOS_I2C_gyro_adapter_er_irq_handler(void)
|
||||
#endif /* PIOS_INCLUDE_I2C */
|
||||
|
||||
|
||||
|
||||
extern const struct pios_com_driver pios_usart_com_driver;
|
||||
|
||||
uint32_t pios_com_aux_id;
|
||||
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 = {
|
||||
.drdy = {
|
||||
.gpio = GPIOB,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_8,
|
||||
.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_Line8, // matches above GPIO pin
|
||||
.EXTI_Mode = EXTI_Mode_Interrupt,
|
||||
.EXTI_Trigger = EXTI_Trigger_Rising,
|
||||
.EXTI_LineCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.eoc_irq = {
|
||||
.init = {
|
||||
.NVIC_IRQChannel = EXTI9_5_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
|
||||
@ -595,7 +633,7 @@ void PIOS_Board_Init(void) {
|
||||
PIOS_BMP085_Init();
|
||||
#endif /* PIOS_INCLUDE_BMP085 */
|
||||
#if defined (PIOS_INCLUDE_HMC5883)
|
||||
PIOS_HMC5883_Init();
|
||||
PIOS_HMC5883_Init(&pios_hmc5883_mag_cfg);
|
||||
#endif /* PIOS_INCLUDE_HMC5883 */
|
||||
|
||||
#if defined(PIOS_INCLUDE_IMU3000)
|
||||
|
@ -186,18 +186,6 @@ extern uint32_t pios_com_aux_id;
|
||||
#define PIOS_BMA180_DRDY_PRIO PIOS_IRQ_PRIO_LOW
|
||||
|
||||
|
||||
//------------------------
|
||||
// PIOS_HMC5883
|
||||
//------------------------
|
||||
#define PIOS_HMC5883_DRDY_GPIO_PORT GPIOB
|
||||
#define PIOS_HMC5883_DRDY_GPIO_PIN GPIO_Pin_8
|
||||
#define PIOS_HMC5883_DRDY_PORT_SOURCE GPIO_PortSourceGPIOB
|
||||
#define PIOS_HMC5883_DRDY_PIN_SOURCE GPIO_PinSource8
|
||||
#define PIOS_HMC5883_DRDY_CLK RCC_APB2Periph_GPIOB
|
||||
#define PIOS_HMC5883_DRDY_EXTI_LINE EXTI_Line8
|
||||
#define PIOS_HMC5883_DRDY_IRQn EXTI9_5_IRQn
|
||||
#define PIOS_HMC5883_DRDY_PRIO PIOS_IRQ_PRIO_LOW
|
||||
|
||||
//------------------------
|
||||
// PIOS_IMU3000
|
||||
//------------------------
|
||||
|
@ -56,34 +56,21 @@ static bool PIOS_HMC5883_Write(uint8_t address, uint8_t buffer);
|
||||
* @brief Initialize the HMC5883 magnetometer sensor.
|
||||
* @return none
|
||||
*/
|
||||
void PIOS_HMC5883_Init(void)
|
||||
void PIOS_HMC5883_Init(const struct pios_hmc5883_cfg * cfg)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
EXTI_InitTypeDef EXTI_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
/* Enable DRDY GPIO clock */
|
||||
RCC_APB2PeriphClockCmd(PIOS_HMC5883_DRDY_CLK | RCC_APB2Periph_AFIO, ENABLE);
|
||||
// Started by pios_sys.c
|
||||
// RCC_APB2PeriphClockCmd(PIOS_HMC5883_DRDY_CLK | RCC_APB2Periph_AFIO, ENABLE);
|
||||
|
||||
/* Configure EOC pin as input floating */
|
||||
GPIO_InitStructure.GPIO_Pin = PIOS_HMC5883_DRDY_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_Init(PIOS_HMC5883_DRDY_GPIO_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_Init(cfg->drdy, &cfg->drdy.init);
|
||||
|
||||
/* Configure the End Of Conversion (EOC) interrupt */
|
||||
GPIO_EXTILineConfig(PIOS_HMC5883_DRDY_PORT_SOURCE, PIOS_HMC5883_DRDY_PIN_SOURCE);
|
||||
EXTI_InitStructure.EXTI_Line = PIOS_HMC5883_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);
|
||||
|
||||
//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_HMC5883_DRDY_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PIOS_HMC5883_DRDY_PRIO;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
NVIC_Init(&cfg->eoc_irq.init);
|
||||
|
||||
/* Configure the HMC5883 Sensor */
|
||||
PIOS_HMC5883_ConfigTypeDef HMC5883_InitStructure;
|
@ -32,6 +32,8 @@
|
||||
#ifndef PIOS_HMC5883_H
|
||||
#define PIOS_HMC5883_H
|
||||
|
||||
#include <pios_stm32.h>
|
||||
|
||||
/* HMC5883 Addresses */
|
||||
#define PIOS_HMC5883_I2C_ADDR 0x1E
|
||||
#define PIOS_HMC5883_I2C_READ_ADDR 0x3D
|
||||
@ -90,8 +92,15 @@
|
||||
#define PIOS_HMC5883_Sensitivity_5_6Ga 330 // LSB/Ga
|
||||
#define PIOS_HMC5883_Sensitivity_8_1Ga 230 // LSB/Ga --> NOT RECOMMENDED
|
||||
|
||||
|
||||
struct pios_hmc5883_cfg {
|
||||
struct stm32_gpio drdy;
|
||||
struct stm32_exti eoc_exti;
|
||||
struct stm32_irq eoc_irq;
|
||||
};
|
||||
|
||||
/* Public Functions */
|
||||
extern void PIOS_HMC5883_Init(void);
|
||||
extern void PIOS_HMC5883_Init(const struct pios_hmc5883_cfg * cfg);
|
||||
extern bool PIOS_HMC5883_NewDataAvailable(void);
|
||||
extern void PIOS_HMC5883_ReadMag(int16_t out[3]);
|
||||
extern void PIOS_HMC5883_ReadID(uint8_t out[4]);
|
||||
|
@ -58,6 +58,12 @@ struct stm32_gpio {
|
||||
GPIO_InitTypeDef init;
|
||||
};
|
||||
|
||||
struct stm32_exti {
|
||||
uint8_t pin_source;
|
||||
uint8_t port_source;
|
||||
EXTI_InitTypeDef init;
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
@ -2856,10 +2856,13 @@
|
||||
65C35EA812F0A834004811C2 /* eventdispatcher.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = eventdispatcher.c; sourceTree = "<group>"; };
|
||||
65C35F6612F0DC2D004811C2 /* attitude.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = attitude.c; sourceTree = "<group>"; };
|
||||
65C35F6812F0DC2D004811C2 /* attitude.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = attitude.h; sourceTree = "<group>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
65DEA78613F1118400095B06 /* pios_bma180.h */ = {isa = PBXFileReference; fileEncoding = 4; path = pios_bma180.h; sourceTree = "<group>"; };
|
||||
65DEA78613F1118400095B06 /* pios_bma180.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_bma180.h; sourceTree = "<group>"; };
|
||||
65DEA78813F111EA00095B06 /* pios_bma180.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_bma180.c; sourceTree = "<group>"; };
|
||||
65E410AE12F65AEA00725888 /* attitudesettings.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = attitudesettings.xml; sourceTree = "<group>"; };
|
||||
65E6DF7112E02E8E00058553 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
|
||||
@ -3727,6 +3730,7 @@
|
||||
6560A37E13EE26B700105DA5 /* pios_delay.c */,
|
||||
6560A37F13EE26B700105DA5 /* pios_exti.c */,
|
||||
6560A38013EE26B700105DA5 /* pios_gpio.c */,
|
||||
65D1FBD613F50CD5006374A6 /* pios_hmc5883.c */,
|
||||
6560A38113EE26B700105DA5 /* pios_i2c.c */,
|
||||
6560A38213EE26B700105DA5 /* pios_iap.c */,
|
||||
6560A38313EE26B700105DA5 /* pios_irq.c */,
|
||||
@ -4050,6 +4054,7 @@
|
||||
65632DF41251650300469B77 /* Boards */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
65D1FBD313F4FF1D006374A6 /* STM32F2xx_INS.h */,
|
||||
65632DF51251650300469B77 /* pios_board.h */,
|
||||
65632DF71251650300469B77 /* STM3210E_OP.h */,
|
||||
65632DF61251650300469B77 /* STM32103CB_AHRS.h */,
|
||||
@ -8197,6 +8202,7 @@
|
||||
65FF4D61137EFA4F00146BE4 /* pios_flashfs_objlist.h */,
|
||||
65E8F04111EFF25C00BBF654 /* pios_gpio.h */,
|
||||
65E8F04211EFF25C00BBF654 /* pios_hmc5843.h */,
|
||||
65D1FBD413F504C9006374A6 /* pios_hmc5883.h */,
|
||||
65E8F04311EFF25C00BBF654 /* pios_i2c.h */,
|
||||
6526645A122DF972006F9A3C /* pios_i2c_priv.h */,
|
||||
65E8F04411EFF25C00BBF654 /* pios_irq.h */,
|
||||
|
Loading…
Reference in New Issue
Block a user