blob: 5af74e9a7c3ef50fdfcda3053937b5f8c431c31e [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;
Brian Silverman391beca2013-12-28 22:32:48 -080025 NVIC_DisableIRQ(TIM8_UP_TIM13_IRQn);
Brian Silverman18b01642013-12-13 21:12:25 -080026 memcpy(output, &gyro_output, sizeof(gyro_output));
Brian Silverman391beca2013-12-28 22:32:48 -080027 NVIC_EnableIRQ(TIM8_UP_TIM13_IRQn);
Brian Silverman18b01642013-12-13 21:12:25 -080028}
29
30#endif // GYRO_BOARD_SRC_USB_GYRO_H_