1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

hmc5843: Add support for DRDY signal from magnetometer

The DRDY signal from the magnetometer is connected to PB8
on the STM32.  This pin is now configured as an external
interrupt and is now used to signal when new data is
available from the magnetometer.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1628 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
stac 2010-09-15 14:21:02 +00:00 committed by stac
parent 4ac001553d
commit 0e7a801e9e
6 changed files with 83 additions and 12 deletions

View File

@ -104,6 +104,7 @@ SRC += $(PIOSSTM32F10X)/pios_irq.c
SRC += $(PIOSSTM32F10X)/pios_i2c.c
SRC += $(PIOSSTM32F10X)/pios_gpio.c
SRC += $(PIOSSTM32F10X)/pios_spi.c
SRC += $(PIOSSTM32F10X)/pios_exti.c
## PIOS Hardware (Common)
SRC += $(PIOSCOMMON)/pios_com.c

View File

@ -219,4 +219,16 @@ TIM8 | | | |
#define SET_ACCEL_2G PIOS_GPIO_On(0);
#define SET_ACCEL_6G PIOS_GPIO_Off(0)
//------------------------
// PIOS_HMC5843
//------------------------
#define PIOS_HMC5843_DRDY_GPIO_PORT GPIOB
#define PIOS_HMC5843_DRDY_GPIO_PIN GPIO_Pin_8
#define PIOS_HMC5843_DRDY_PORT_SOURCE GPIO_PortSourceGPIOB
#define PIOS_HMC5843_DRDY_PIN_SOURCE GPIO_PinSource8
#define PIOS_HMC5843_DRDY_CLK RCC_APB2Periph_GPIOB
#define PIOS_HMC5843_DRDY_EXTI_LINE EXTI_Line8
#define PIOS_HMC5843_DRDY_IRQn EXTI9_5_IRQn
#define PIOS_HMC5843_DRDY_PRIO PIOS_IRQ_PRIO_HIGH
#endif /* PIOS_BOARD_H */

View File

@ -40,6 +40,7 @@
#define PIOS_INCLUDE_COM
#define PIOS_INCLUDE_HMC5843
#define PIOS_INCLUDE_GPIO
#define PIOS_INCLUDE_EXTI
#endif /* PIOS_CONFIG_H */

View File

@ -34,18 +34,45 @@
#if defined(PIOS_INCLUDE_HMC5843)
/* Glocal Variables */
/* Global Variables */
/* Local Variables */
static bool pios_hmc5843_data_ready;
/**
* @brieft Initialise the HMC5843 sensor
*/
void PIOS_HMC5843_Init(void)
{
// Nothing to do here
// If we were using the DRDY (data ready) interrupt input, we would set it up here
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable DRDY GPIO clock */
RCC_APB2PeriphClockCmd(PIOS_HMC5843_DRDY_CLK | RCC_APB2Periph_AFIO, ENABLE);
/* Configure EOC pin as input floating */
GPIO_InitStructure.GPIO_Pin = PIOS_HMC5843_DRDY_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(PIOS_HMC5843_DRDY_GPIO_PORT, &GPIO_InitStructure);
/* Configure the End Of Conversion (EOC) interrupt */
GPIO_EXTILineConfig(PIOS_HMC5843_DRDY_PORT_SOURCE, PIOS_HMC5843_DRDY_PIN_SOURCE);
EXTI_InitStructure.EXTI_Line = PIOS_HMC5843_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);
/* Enable and set EOC EXTI Interrupt to the lowest priority */
NVIC_InitStructure.NVIC_IRQChannel = PIOS_HMC5843_DRDY_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PIOS_HMC5843_DRDY_PRIO;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
pios_hmc5843_data_ready = false;
}
/**
@ -133,6 +160,8 @@ void PIOS_HMC5843_ReadMag(int16_t out[3])
uint8_t buffer[6];
uint8_t crtlB;
pios_hmc5843_data_ready = false;
while(!PIOS_HMC5843_Read(PIOS_HMC5843_CONFIG_REG_B, &crtlB, 1));
while(!PIOS_HMC5843_Read(PIOS_HMC5843_DATAOUT_XMSB_REG, buffer, 6));
@ -197,6 +226,12 @@ void PIOS_HMC5843_ReadID(uint8_t out[4])
out[3] = '\0';
}
bool PIOS_HMC5843_NewDataAvailable(void)
{
return(pios_hmc5843_data_ready);
}
/**
* Reads one or more bytes into a buffer
* \param[in] address HMC5843 register address (depends on size)
@ -260,6 +295,12 @@ bool PIOS_HMC5843_Write(uint8_t address, uint8_t buffer)
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list));
}
void PIOS_HMC5843_IRQHandler(void)
{
pios_hmc5843_data_ready = true;
}
#endif
/**

View File

@ -36,16 +36,15 @@
#if defined(PIOS_INCLUDE_EXTI)
/* Local Variables */
static portBASE_TYPE xHigherPriorityTaskWoken;
/**
* Handle external lines 15 to 10 interrupt requests
*/
void EXTI15_10_IRQHandler(void)
{
#if defined(PIOS_INCLUDE_FREERTOS)
portBASE_TYPE xHigherPriorityTaskWoken;
#endif
#if defined(PIOS_INCLUDE_BMP085)
if(EXTI_GetITStatus(PIOS_BMP085_EOC_EXTI_LINE) != RESET) {
/* Read the ADC Value */
@ -53,14 +52,30 @@ void EXTI15_10_IRQHandler(void)
/* Clear the EXTI line pending bit */
EXTI_ClearITPendingBit(PIOS_BMP085_EOC_EXTI_LINE);
/* Yield From ISR if needed */
portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);
}
#endif
#if defined(PIOS_INCLUDE_FREERTOS)
/* Yield From ISR if needed */
portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);
#endif
}
/**
* Handle external lines 9 to 5 interrupt requests
*/
extern void PIOS_HMC5843_IRQHandler(void);
void EXTI9_5_IRQHandler(void)
{
#if defined(PIOS_INCLUDE_HMC5843)
if(EXTI_GetITStatus(PIOS_HMC5843_DRDY_EXTI_LINE) != RESET) {
PIOS_HMC5843_IRQHandler();
EXTI_ClearITPendingBit(PIOS_HMC5843_DRDY_EXTI_LINE);
}
#endif
}
/**
* Handle external line 4 interrupt requests
*/

View File

@ -31,7 +31,7 @@
#ifndef PIOS_HMC5843_H
#define PIOS_HMC5843_H
/* BMP085 Addresses */
/* HMC5843 Addresses */
#define PIOS_HMC5843_I2C_ADDR 0x1E
#define PIOS_HMC5843_CONFIG_REG_A (uint8_t)0x00
#define PIOS_HMC5843_CONFIG_REG_B (uint8_t)0x01
@ -101,6 +101,7 @@ typedef struct {
/* Public Functions */
extern void PIOS_HMC5843_Init(void);
extern void PIOS_HMC5843_Config(PIOS_HMC5843_ConfigTypeDef *HMC5843_Config_Struct);
extern bool PIOS_HMC5843_NewDataAvailable(void);
extern void PIOS_HMC5843_ReadMag(int16_t out[3]);
extern void PIOS_HMC5843_ReadID(uint8_t out[4]);
extern bool PIOS_HMC5843_Read(uint8_t address, uint8_t *buffer, uint8_t len);