voilier-team-1/driver-siyo/timerdriver.h

39 lines
1.1 KiB
C

#ifndef TIMERDRIVER_H
#define TIMERDRIVER_H
#include "stm32f10x.h"
#include "gpiodriver.h"
#define CEN 0x0
#define UIE 0x0
#define UIF 0x0
#define MOE 0xF
#define OC13M_START 0x4
#define OC24M_START 0xC
#define PWMMode_1 0x6
typedef struct {
TIM_TypeDef * Timer; //TIM1 -> TIM4
unsigned short ARR;
unsigned short PSC;
} MyTimer_Struct_TypeDef;
typedef struct {
TIM_TypeDef * Timer; //TIM1 -> TIM4
uint8_t channel;
uint16_t CCR;
} MyPWM_Struct_TypeDef;
void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer);
int TimerX2Int(TIM_TypeDef * TimerX);
uint8_t TimerIT2UInt(TIM_TypeDef * TimerX);
void MyTimer_ActiveIT(TIM_TypeDef * TimerX, uint8_t Prio);
void Init_Periph (void (* ptrFonction)(void));
void MyTimer_PWM_Init(MyPWM_Struct_TypeDef * PWM);
MyGPIO_Struct_TypeDef GPIOFromPWM(MyPWM_Struct_TypeDef PWM);
#define MyTimer_Base_Start(Timer) (Timer->CR1 |= (0x01<<CEN))
#define MyTimer_Base_Stop(Timer) (Timer->CR1 &= ~(0x01<<CEN))
#define MyPWM_Base_Start(Timer) (Timer->BDTR |= (1<<MOE)) //Main output enable
#define MyPWM_Base_Stop(Timer) (Timer->BDTR &= ~(1<<MOE)) //Main output enable
#endif