blob: 455a1c07652f98560a7698fc95420eda8904ce25 [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) {
Brian Silvermanc47182f2014-02-16 21:43:36 -080020 // Digital input 6.
21 gpio_setup_alt(GPIOB, 9, 3);
Brian Silverman78670262014-01-17 23:40:47 -080022 RCC->APB2ENR |= RCC_APB2ENR_TIM11EN;
23 TIM11->CR1 = TIM_CR1_URS;
24 TIM11->SMCR = 5 << 4 /* TI1 */ |
25 4 << 0 /* reset and start on edge */;
26 TIM11->DIER = TIM_DIER_CC1IE;
27 TIM11->CCMR1 = TIM_CCMR1_CC1S_0 /* input pin 1 -> timer input 1 */;
28 TIM11->CCER = TIM_CCER_CC1P /* go on falling edge */;
29 TIM11->EGR = TIM_EGR_UG;
30 TIM11->PSC = 1200 - 1; // 100kHZ timer
31 TIM11->CR1 |= TIM_CR1_CEN;
32 NVIC_SetPriority(TIM1_TRG_COM_TIM11_IRQn, 3);
33 NVIC_EnableIRQ(TIM1_TRG_COM_TIM11_IRQn);
34}
35
36void robot_fill_packet(struct DataStruct *packet) {
37}