Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
hmc5843_arch.c
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2010 Antoine Drouin <poinix@gmail.com>
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 #include "peripherals/hmc5843.h"
24 
25 #include <stm32/gpio.h>
26 #include <stm32/rcc.h>
27 #include <stm32/spi.h>
28 #include <stm32/exti.h>
29 #include <stm32/misc.h>
30 #include "mcu_periph/i2c.h"
31 
32 void exti9_5_irq_handler(void);
33 
34 void hmc5843_arch_init( void ) {
35  /* configure external interrupt exti5 on PB5( mag int ) */
36  GPIO_InitTypeDef GPIO_InitStructure;
37  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
38  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
39  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
40  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
41  GPIO_Init(GPIOB, &GPIO_InitStructure);
42 
43 #ifdef HMC5843_USE_INT
44  GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource5);
45  EXTI_InitTypeDef EXTI_InitStructure;
46  EXTI_InitStructure.EXTI_Line = EXTI_Line5;
47  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
48  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
49  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
50  EXTI_Init(&EXTI_InitStructure);
51 
52  NVIC_InitTypeDef NVIC_InitStructure;
53  NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
54  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
55  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
56  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
57  NVIC_Init(&NVIC_InitStructure);
58 #endif
59 }
60 
62 {
63  i2c2_er_irq_handler();
64 }
65 
66 void exti9_5_irq_handler(void) {
67 
68  /* clear EXTI */
69  if(EXTI_GetITStatus(EXTI_Line5) != RESET)
70  EXTI_ClearITPendingBit(EXTI_Line5);
71 
72 }
void hmc5843_arch_init(void)
Definition: hmc5843_arch.c:24
void exti9_5_irq_handler(void)
Definition: hmc5843_arch.c:66
void hmc5843_arch_reset(void)
Definition: hmc5843_arch.c:61
#define RESET
Definition: humid_sht.h:40