Brian Silverman | 18b0164 | 2013-12-13 21:12:25 -0800 | [diff] [blame] | 1 | #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. |
| 11 | void gyro_init(void); |
| 12 | |
| 13 | struct 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. |
| 23 | static inline void gyro_get_output(struct GyroOutput *output) { |
| 24 | extern struct GyroOutput gyro_output; |
Brian Silverman | 391beca | 2013-12-28 22:32:48 -0800 | [diff] [blame] | 25 | NVIC_DisableIRQ(TIM8_UP_TIM13_IRQn); |
Brian Silverman | 18b0164 | 2013-12-13 21:12:25 -0800 | [diff] [blame] | 26 | memcpy(output, &gyro_output, sizeof(gyro_output)); |
Brian Silverman | 391beca | 2013-12-28 22:32:48 -0800 | [diff] [blame] | 27 | NVIC_EnableIRQ(TIM8_UP_TIM13_IRQn); |
Brian Silverman | 18b0164 | 2013-12-13 21:12:25 -0800 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | #endif // GYRO_BOARD_SRC_USB_GYRO_H_ |