Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces 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 
19 #ifdef ASPIRIN_USE_GYRO_INT
20  nvic_set_priority(NVIC_EXTI15_10_IRQ, 0x0F);
21  nvic_enable_irq(NVIC_EXTI15_10_IRQ);
22 #endif
23 
24  nvic_set_priority(NVIC_EXTI2_IRQ, 0x0F);
25  nvic_enable_irq(NVIC_EXTI2_IRQ);
26 
27  // should not be needed anymore, handled by the spi driver
28 #if 0
29  /* Enable DMA1 channel4 IRQ Channel ( SPI RX) */
30  nvic_set_priority(NVIC_DMA1_CHANNEL4_IRQ, 0);
31  nvic_enable_irq(NVIC_DMA1_CHANNEL4_IRQ);
32 #endif
33 }
34 
36 {
37 
38 #ifdef ASPIRIN_USE_GYRO_INT
39  nvic_disable_irq(NVIC_EXTI15_10_IRQ);
40 #endif
41 
42  nvic_disable_irq(NVIC_EXTI2_IRQ);
43 
44  // should not be needed anymore, handled by the spi driver
45 #if 0
46  /* Enable DMA1 channel4 IRQ Channel ( SPI RX) */
47  nvic_disable_irq(NVIC_DMA1_CHANNEL4_IRQ);
48 #endif
49 }
50 
52 {
53 
54  // This was needed for Lisa/L????
55 #if 0
56  /* Set "mag ss" and "mag reset" as floating inputs ------------------------*/
57  /* "mag ss" (PC12) is shorted to I2C2 SDA */
58  /* "mag reset" (PC13) is shorted to I2C2 SCL */
59  rcc_periph_clock_enable(RCC_GPIOC);
60  gpio_set_mode(GPIOC, GPIO_MODE_INPUT,
61  GPIO_CNF_INPUT_FLOAT, GPIO12 | GPIO13);
62 #endif
63 
64  /* Gyro --------------------------------------------------------------------*/
65  /* configure external interrupt exti15_10 on PC14( gyro int ) */
66  rcc_periph_clock_enable(RCC_GPIOC);
67  rcc_periph_clock_enable(RCC_AFIO);
68  gpio_set_mode(GPIOC, GPIO_MODE_INPUT,
69  GPIO_CNF_INPUT_FLOAT, GPIO14);
70 
71 #ifdef ASPIRIN_USE_GYRO_INT
72  exti_select_source(EXTI14, GPIOC);
73  exti_set_trigger(EXTI14, EXTI_TRIGGER_FALLING);
74  exti_enable_request(EXTI14);
75 #endif
76 
77  /* configure external interrupt exti2 on PB2( accel int ) */
78  rcc_periph_clock_enable(RCC_GPIOB);
79  gpio_set_mode(GPIOB, GPIO_MODE_INPUT,
80  GPIO_CNF_INPUT_FLOAT, GPIO2);
81  exti_select_source(EXTI2, GPIOB);
82  exti_set_trigger(EXTI2, EXTI_TRIGGER_FALLING);
83  exti_enable_request(EXTI2);
84 
85 }
86 
87 
88 /****** the interrupts should be handled in the peripheral drivers *******/
89 
90 /*
91  * Gyro data ready
92  */
93 void exti15_10_isr(void)
94 {
95 
96  /* clear EXTI */
97  exti_reset_request(EXTI14);
98 
99 #ifdef ASPIRIN_USE_GYRO_INT
100  imu_aspirin.gyro_eoc = true;
101  imu_aspirin.status = AspirinStatusReadingGyro;
102 #endif
103 
104 }
105 
106 /*
107  * Accel data ready
108  */
109 void exti2_isr(void)
110 {
111 
112  /* clear EXTI */
113  exti_reset_request(EXTI2);
114 
115  //adxl345_start_reading_data();
116 }
117 
struct ImuAspirin imu_aspirin
Definition: imu_aspirin.c:66
void imu_aspirin_arch_init(void)
void exti2_isr(void)
#define GPIO13
Definition: gpio_def.h:44
#define GPIOC
Definition: gpio_arch.h:34
#define GPIOB
Definition: gpio_arch.h:35
void imu_aspirin_arch_int_disable(void)
Inertial Measurement Unit interface.
void exti15_10_isr(void)
void imu_aspirin_arch_int_enable(void)
#define GPIO2
Definition: gpio_def.h:33
#define GPIO14
Definition: gpio_def.h:45
#define GPIO12
Definition: gpio_def.h:43
Architecture independent I2C (Inter-Integrated Circuit Bus) API.