blob: bf417e981a2c0f7b6ed2079b0d2072b7d27c5ebb [file] [log] [blame]
Brian Silverman78670262014-01-17 23:40:47 -08001#include "cape/robot.h"
2
3#include <STM32F2XX.h>
4
5#include "cape/encoder.h"
6#include "cape/analog.h"
7#include "cape/digital.h"
8#include "cape/util.h"
9
10// TIM11.1 on PB9
11
12static volatile uint32_t ultrasonic_pulse_length = 0;
13
14void TIM1_TRG_COM_TIM11_IRQHandler(void) {
15 TIM11->SR = ~TIM_SR_CC1IF;
16 ultrasonic_pulse_length = TIM11->CCR1;
17}
18
19void robot_init(void) {
20 gpio_setup_alt(GPIOB, 11, 3);
21 RCC->APB2ENR |= RCC_APB2ENR_TIM11EN;
22 TIM11->CR1 = TIM_CR1_URS;
23 TIM11->SMCR = 5 << 4 /* TI1 */ |
24 4 << 0 /* reset and start on edge */;
25 TIM11->DIER = TIM_DIER_CC1IE;
26 TIM11->CCMR1 = TIM_CCMR1_CC1S_0 /* input pin 1 -> timer input 1 */;
27 TIM11->CCER = TIM_CCER_CC1P /* go on falling edge */;
28 TIM11->EGR = TIM_EGR_UG;
29 TIM11->PSC = 1200 - 1; // 100kHZ timer
30 TIM11->CR1 |= TIM_CR1_CEN;
31 NVIC_SetPriority(TIM1_TRG_COM_TIM11_IRQn, 3);
32 NVIC_EnableIRQ(TIM1_TRG_COM_TIM11_IRQn);
33}
34
35void robot_fill_packet(struct DataStruct *packet) {
36}