blob: 1536718c1e5780f301f7db3b000d1ab76fb06e71 [file] [log] [blame]
Brian Silverman18b01642013-12-13 21:12:25 -08001#ifndef GYRO_BOARD_SRC_USB_GYRO_H_
2#define GYRO_BOARD_SRC_USB_GYRO_H_
3
4#include <stdint.h>
5#include <string.h>
6
7#include <STM32F2XX.h>
8
9// Does everything to set up the gyro code, including starting a timer which
10// triggers reads and integrates the gyro values and blinks the LEDs etc.
11void gyro_init(void);
12
13struct GyroOutput {
14 int64_t angle;
15 int last_reading_bad;
16 int gyro_bad;
17 int initialized;
18 int zeroed;
19};
20
21// Reads the most recent output value and avoids race conditions.
22// Must be called from a lower-priority ISR than TIM10's.
23static inline void gyro_get_output(struct GyroOutput *output) {
24 extern struct GyroOutput gyro_output;
25 NVIC_DisableIRQ(TIM1_UP_TIM10_IRQn);
26 memcpy(output, &gyro_output, sizeof(gyro_output));
27 NVIC_EnableIRQ(TIM1_UP_TIM10_IRQn);
28}
29
30#endif // GYRO_BOARD_SRC_USB_GYRO_H_