Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
imu_aspirin_arch.c
Go to the documentation of this file.
1 #include "subsystems/imu.h"
2 
3 #include <libopencm3/stm32/gpio.h>
4 #include <libopencm3/stm32/rcc.h>
5 #include <libopencm3/stm32/exti.h>
6 #include <libopencm3/stm32/spi.h>
7 #include <libopencm3/stm32/dma.h>
8 #include <libopencm3/cm3/nvic.h>
9 
10 #include "mcu_periph/i2c.h"
11 
12 #ifndef STM32F1
13 #error "imu_aspirin_arch arch currently only implemented for STM32F1"
14 #endif
15 
17 
18 #ifdef ASPIRIN_USE_GYRO_INT
19  nvic_set_priority(NVIC_EXTI15_10_IRQ, 0x0F);
20  nvic_enable_irq(NVIC_EXTI15_10_IRQ);
21 #endif
22 
23  nvic_set_priority(NVIC_EXTI2_IRQ, 0x0F);
24  nvic_enable_irq(NVIC_EXTI2_IRQ);
25 
26  // should not be needed anymore, handled by the spi driver
27 #if 0
28  /* Enable DMA1 channel4 IRQ Channel ( SPI RX) */
29  nvic_set_priority(NVIC_DMA1_CHANNEL4_IRQ, 0);
30  nvic_enable_irq(NVIC_DMA1_CHANNEL4_IRQ);
31 #endif
32 }
33 
35 
36 #ifdef ASPIRIN_USE_GYRO_INT
37  nvic_disable_irq(NVIC_EXTI15_10_IRQ);
38 #endif
39 
40  nvic_disable_irq(NVIC_EXTI2_IRQ);
41 
42  // should not be needed anymore, handled by the spi driver
43 #if 0
44  /* Enable DMA1 channel4 IRQ Channel ( SPI RX) */
45  nvic_disable_irq(NVIC_DMA1_CHANNEL4_IRQ);
46 #endif
47 }
48 
50 
51  // This was needed for Lisa/L????
52 #if 0
53  /* Set "mag ss" and "mag reset" as floating inputs ------------------------*/
54  /* "mag ss" (PC12) is shorted to I2C2 SDA */
55  /* "mag reset" (PC13) is shorted to I2C2 SCL */
56  rcc_periph_clock_enable(RCC_GPIOC);
57  gpio_set_mode(GPIOC, GPIO_MODE_INPUT,
58  GPIO_CNF_INPUT_FLOAT, GPIO12 | GPIO13);
59 #endif
60 
61  /* Gyro --------------------------------------------------------------------*/
62  /* configure external interrupt exti15_10 on PC14( gyro int ) */
63  rcc_periph_clock_enable(RCC_GPIOC);
64  rcc_periph_clock_enable(RCC_AFIO);
65  gpio_set_mode(GPIOC, GPIO_MODE_INPUT,
66  GPIO_CNF_INPUT_FLOAT, GPIO14);
67 
68 #ifdef ASPIRIN_USE_GYRO_INT
69  exti_select_source(EXTI14, GPIOC);
70  exti_set_trigger(EXTI14, EXTI_TRIGGER_FALLING);
71  exti_enable_request(EXTI14);
72 #endif
73 
74  /* configure external interrupt exti2 on PB2( accel int ) */
75  rcc_periph_clock_enable(RCC_GPIOB);
76  gpio_set_mode(GPIOB, GPIO_MODE_INPUT,
77  GPIO_CNF_INPUT_FLOAT, GPIO2);
78  exti_select_source(EXTI2, GPIOB);
79  exti_set_trigger(EXTI2, EXTI_TRIGGER_FALLING);
80  exti_enable_request(EXTI2);
81 
82 }
83 
84 
85 /****** the interrupts should be handled in the peripheral drivers *******/
86 
87 /*
88  * Gyro data ready
89  */
90 void exti15_10_isr(void) {
91 
92  /* clear EXTI */
93  exti_reset_request(EXTI14);
94 
95 #ifdef ASPIRIN_USE_GYRO_INT
96  imu_aspirin.gyro_eoc = TRUE;
97  imu_aspirin.status = AspirinStatusReadingGyro;
98 #endif
99 
100 }
101 
102 /*
103  * Accel data ready
104  */
105 void exti2_isr(void) {
106 
107  /* clear EXTI */
108  exti_reset_request(EXTI2);
109 
110  //adxl345_start_reading_data();
111 }
112 
struct ImuAspirin imu_aspirin
Definition: imu_aspirin.c:66
void imu_aspirin_arch_init(void)
void exti2_isr(void)
#define GPIO13
Definition: gpio_arch.h:50
#define GPIOC
Definition: gpio_arch.h:34
#define GPIOB
Definition: gpio_arch.h:35
#define GPIO2
Definition: gpio_arch.h:39
void imu_aspirin_arch_int_disable(void)
Inertial Measurement Unit interface.
#define GPIO14
Definition: gpio_arch.h:51
#define GPIO12
Definition: gpio_arch.h:49
#define TRUE
Definition: imu_chimu.h:144
void exti15_10_isr(void)
#define NVIC_EXTI2_IRQ
void imu_aspirin_arch_int_enable(void)
#define NVIC_EXTI15_10_IRQ
Architecture independent I2C (Inter-Integrated Circuit Bus) API.