forked from simondlevy/BreezySTM32
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdrv_mb1030.c
35 lines (30 loc) · 971 Bytes
/
drv_mb1030.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include "stm32f10x_conf.h"
#include "core_cm3.h"
#include "drv_gpio.h"
#include "drv_timer.h"
#include "drv_pwm.h"
typedef struct{
TIM_TypeDef *tim;
GPIO_TypeDef *gpio;
uint32_t pin;
uint8_t channel;
uint8_t irq;
} sonar_t;
static sonar_t sonar_hardware[6] = {
{ TIM2, GPIOA, Pin_1, TIM_Channel_2, TIM2_IRQn }, // RC2
{ TIM2, GPIOA, Pin_2, TIM_Channel_3, TIM2_IRQn }, // RC3
{ TIM2, GPIOA, Pin_3, TIM_Channel_4, TIM2_IRQn }, // RC4
{ TIM3, GPIOA, Pin_6, TIM_Channel_1, TIM3_IRQn }, // RC5
{ TIM3, GPIOA, Pin_7, TIM_Channel_2, TIM3_IRQn }, // RC6
{ TIM3, GPIOB, Pin_0, TIM_Channel_3, TIM3_IRQn }, // RC7
};
void mb1030_init()
{
for(int i = 0; i < 6; i++)
{
pwmGPIOConfig(sonar_hardware[i].gpio, sonar_hardware[i].pin, Mode_IPD);
pwmICConfig(sonar_hardware[i].tim, sonar_hardware[i].channel, TIM_ICPolarity_Rising);
}